2015-08-28 14:21:11 -06:00
|
|
|
#include "Console.h"
|
|
|
|
#include "Core.h"
|
|
|
|
#include "DataDefs.h"
|
|
|
|
#include "Export.h"
|
|
|
|
#include "PluginManager.h"
|
|
|
|
#include "modules/Screen.h"
|
|
|
|
#include "modules/Renderer.h"
|
|
|
|
|
|
|
|
#include "df/enabler.h"
|
|
|
|
#include "df/renderer.h"
|
|
|
|
|
|
|
|
//#include "df/world.h"
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
DFHACK_PLUGIN("renderer-msg");
|
|
|
|
DFHACK_PLUGIN_IS_ENABLED(is_enabled);
|
|
|
|
REQUIRE_GLOBAL(enabler);
|
|
|
|
REQUIRE_GLOBAL(gps);
|
|
|
|
|
|
|
|
struct scdata {
|
|
|
|
uint8_t ch, fg, bg, bold;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct renderer_msg : public Renderer::renderer_wrap {
|
2022-08-06 10:33:25 -06:00
|
|
|
bool message_dirty = true; // force redraw when renderer is installed
|
|
|
|
|
2022-08-06 10:22:27 -06:00
|
|
|
virtual void update_tile(int32_t x, int32_t y) override {
|
|
|
|
draw_message();
|
|
|
|
renderer_wrap::update_tile(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void update_all() override {
|
|
|
|
draw_message();
|
|
|
|
renderer_wrap::update_all();
|
|
|
|
}
|
|
|
|
|
2022-08-06 10:33:25 -06:00
|
|
|
virtual void render() override {
|
|
|
|
message_dirty = true;
|
|
|
|
renderer_wrap::render();
|
|
|
|
}
|
|
|
|
|
2022-08-06 10:22:27 -06:00
|
|
|
void draw_message() {
|
2022-08-06 10:33:25 -06:00
|
|
|
if (message_dirty) {
|
|
|
|
static std::string str = std::string("DFHack: ") + plugin_name + " active";
|
|
|
|
Screen::paintString(Screen::Pen(' ', COLOR_LIGHTCYAN, COLOR_GREEN), 0, gps->dimy - 1, str);
|
|
|
|
for (int32_t i = 0; i < gps->dimx; ++i)
|
|
|
|
((scdata*)screen)[i * gps->dimy + gps->dimy - 1].bg = 2;
|
|
|
|
|
|
|
|
message_dirty = false;
|
|
|
|
}
|
2022-08-06 10:22:27 -06:00
|
|
|
}
|
2015-08-28 14:21:11 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Renderer::renderer_wrap *w = NULL;
|
|
|
|
DFhackCExport command_result plugin_enable (color_ostream &out, bool enable)
|
|
|
|
{
|
|
|
|
if (is_enabled == enable)
|
|
|
|
return CR_OK;
|
|
|
|
CoreSuspender s;
|
|
|
|
is_enabled = enable;
|
|
|
|
if (enable)
|
|
|
|
w = Renderer::AddRenderer(new renderer_msg, true);
|
|
|
|
else
|
|
|
|
Renderer::RemoveRenderer(w);
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DFhackCExport command_result plugin_shutdown (color_ostream &out)
|
|
|
|
{
|
|
|
|
plugin_enable(out, false);
|
|
|
|
return plugin_enable(out, false);
|
|
|
|
}
|