Add hooks for getDwarfmodeViewDims and getDepthAt (new)

develop
lethosor 2015-11-14 14:14:32 -05:00
parent 1ff9277e12
commit 610170b0b0
5 changed files with 34 additions and 5 deletions

@ -38,6 +38,8 @@ distribution.
#include "df/announcement_flags.h" #include "df/announcement_flags.h"
#include "df/unit_report_type.h" #include "df/unit_report_type.h"
#include "modules/GuiHooks.h"
namespace df { namespace df {
struct viewscreen; struct viewscreen;
struct job; struct job;
@ -150,6 +152,10 @@ namespace DFHack
DFHACK_EXPORT bool setDesignationCoords (const int32_t x, const int32_t y, const int32_t z); DFHACK_EXPORT bool setDesignationCoords (const int32_t x, const int32_t y, const int32_t z);
DFHACK_EXPORT bool getMousePos (int32_t & x, int32_t & y); DFHACK_EXPORT bool getMousePos (int32_t & x, int32_t & y);
// The distance from the z-level of the tile at map coordinates (x, y) to the closest ground z-level below
// Defaults to 0, unless overriden by plugins
DFHACK_EXPORT int getDepthAt (int32_t x, int32_t y);
/* /*
* Gui screens * Gui screens
*/ */
@ -183,5 +189,10 @@ namespace DFHack
DFHACK_EXPORT bool getMenuWidth(uint8_t & menu_width, uint8_t & area_map_width); DFHACK_EXPORT bool getMenuWidth(uint8_t & menu_width, uint8_t & area_map_width);
DFHACK_EXPORT bool setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width); DFHACK_EXPORT bool setMenuWidth(const uint8_t menu_width, const uint8_t area_map_width);
namespace Hooks {
GUI_HOOK_DECLARE(depth_at, int, (int32_t x, int32_t y));
GUI_HOOK_DECLARE(dwarfmode_view_dims, DwarfmodeDims, ());
}
} }
} }

@ -1358,9 +1358,9 @@ df::coord Gui::getCursorPos()
return df::coord(cursor->x, cursor->y, cursor->z); return df::coord(cursor->x, cursor->y, cursor->z);
} }
Gui::DwarfmodeDims Gui::getDwarfmodeViewDims() Gui::DwarfmodeDims getDwarfmodeViewDims_default()
{ {
DwarfmodeDims dims; Gui::DwarfmodeDims dims;
auto ws = Screen::getWindowSize(); auto ws = Screen::getWindowSize();
dims.y1 = 1; dims.y1 = 1;
@ -1403,6 +1403,12 @@ Gui::DwarfmodeDims Gui::getDwarfmodeViewDims()
return dims; return dims;
} }
GUI_HOOK_DEFINE(Gui::Hooks::dwarfmode_view_dims, getDwarfmodeViewDims_default);
Gui::DwarfmodeDims Gui::getDwarfmodeViewDims()
{
return GUI_HOOK_TOP(Gui::Hooks::dwarfmode_view_dims)();
}
void Gui::resetDwarfmodeView(bool pause) void Gui::resetDwarfmodeView(bool pause)
{ {
using df::global::cursor; using df::global::cursor;
@ -1524,6 +1530,17 @@ bool Gui::getMousePos (int32_t & x, int32_t & y)
return (x == -1) ? false : true; return (x == -1) ? false : true;
} }
int getDepthAt_default (int32_t x, int32_t y)
{
return 0;
}
GUI_HOOK_DEFINE(Gui::Hooks::depth_at, getDepthAt_default);
int Gui::getDepthAt (int32_t x, int32_t y)
{
return GUI_HOOK_TOP(Gui::Hooks::depth_at)(x, y);
}
bool Gui::getWindowSize (int32_t &width, int32_t &height) bool Gui::getWindowSize (int32_t &width, int32_t &height)
{ {
if (gps) { if (gps) {

@ -94,7 +94,7 @@ bool Screen::inGraphicsMode()
return init && init->display.flag.is_set(init_display_flags::USE_GRAPHICS); return init && init->display.flag.is_set(init_display_flags::USE_GRAPHICS);
} }
static void real_doSetTile(const Pen &pen, int x, int y, bool map) static void doSetTile_default(const Pen &pen, int x, int y, bool map)
{ {
int index = ((x * gps->dimy) + y); int index = ((x * gps->dimy) + y);
auto screen = gps->screen + index*4; auto screen = gps->screen + index*4;
@ -109,7 +109,7 @@ static void real_doSetTile(const Pen &pen, int x, int y, bool map)
gps->screentexpos_cbr[index] = pen.tile_bg; gps->screentexpos_cbr[index] = pen.tile_bg;
} }
GUI_HOOK_DEFINE(Screen::Hooks::set_tile, real_doSetTile); GUI_HOOK_DEFINE(Screen::Hooks::set_tile, doSetTile_default);
static void doSetTile(const Pen &pen, int x, int y, bool map) static void doSetTile(const Pen &pen, int x, int y, bool map)
{ {
GUI_HOOK_TOP(Screen::Hooks::set_tile)(pen, x, y, map); GUI_HOOK_TOP(Screen::Hooks::set_tile)(pen, x, y, map);

@ -4,6 +4,7 @@
#include "Export.h" #include "Export.h"
#include "PluginManager.h" #include "PluginManager.h"
#include "modules/Gui.h"
#include "modules/Screen.h" #include "modules/Screen.h"
using namespace DFHack; using namespace DFHack;

@ -65,7 +65,7 @@ static df::coord get_mouse_pos(int32_t &mx, int32_t &my)
pos.x = vx + mx - 1; pos.x = vx + mx - 1;
pos.y = vy + my - 1; pos.y = vy + my - 1;
pos.z = vz; pos.z = vz - Gui::getDepthAt(pos.x, pos.y);
return pos; return pos;
} }