readTile(): add hook support and map parameter

develop
lethosor 2017-05-31 12:12:15 -04:00
parent f4e18b2d87
commit 939aff3231
3 changed files with 28 additions and 12 deletions

@ -2074,7 +2074,8 @@ static int screen_readTile(lua_State *L)
{
int x = luaL_checkint(L, 1);
int y = luaL_checkint(L, 2);
Pen pen = Screen::readTile(x, y);
bool map = lua_toboolean(L, 3);
Pen pen = Screen::readTile(x, y, map);
Lua::Push(L, pen);
return 1;
}

@ -189,7 +189,7 @@ namespace DFHack
DFHACK_EXPORT bool paintTile(const Pen &pen, int x, int y, bool map = false);
/// Retrieves one screen tile from the buffer
DFHACK_EXPORT Pen readTile(int x, int y);
DFHACK_EXPORT Pen readTile(int x, int y, bool map = false);
/// Paint a string onto the screen. Ignores ch and tile of pen.
DFHACK_EXPORT bool paintString(const Pen &pen, int x, int y, const std::string &text, bool map = false);
@ -297,6 +297,7 @@ namespace DFHack
};
namespace Hooks {
GUI_HOOK_DECLARE(get_tile, Pen, (int x, int y, bool map));
GUI_HOOK_DECLARE(set_tile, void, (const Pen &pen, int x, int y, bool map));
}

@ -127,19 +127,11 @@ bool Screen::paintTile(const Pen &pen, int x, int y, bool map)
return true;
}
Pen Screen::readTile(int x, int y)
static Pen doGetTile_default(int x, int y, bool map)
{
if (!gps) return Pen(0,0,0,-1);
auto dim = getWindowSize();
if (x < 0 || x >= dim.x || y < 0 || y >= dim.y)
return Pen(0,0,0,-1);
auto dim = Screen::getWindowSize();
int index = x*dim.y + y;
auto screen = gps->screen + index*4;
if (screen[3] & 0x80)
return Pen(0,0,0,-1);
Pen pen(
screen[0], screen[1], screen[2], screen[3]?true:false,
gps->screentexpos[index]
@ -162,6 +154,28 @@ Pen Screen::readTile(int x, int y)
return pen;
}
GUI_HOOK_DEFINE(Screen::Hooks::get_tile, doGetTile_default);
static Pen doGetTile(int x, int y, bool map)
{
return GUI_HOOK_TOP(Screen::Hooks::get_tile)(x, y, map);
}
Pen Screen::readTile(int x, int y, bool map)
{
if (!gps) return Pen(0,0,0,-1);
auto dim = getWindowSize();
if (x < 0 || x >= dim.x || y < 0 || y >= dim.y)
return Pen(0,0,0,-1);
int index = x*dim.y + y;
auto screen = gps->screen + index*4;
if (screen[3] & 0x80)
return Pen(0,0,0,-1);
return doGetTile(x, y, map);
}
bool Screen::paintString(const Pen &pen, int x, int y, const std::string &text, bool map)
{
auto dim = getWindowSize();