summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
authorAlexander Gavrilov2012-08-19 20:00:10 +0400
committerAlexander Gavrilov2012-08-19 20:00:10 +0400
commit38a07a4ca584e2cccc2c2814c35266ba33d692c8 (patch)
treee0748a79f70ee29ed8ecf3cf46f9c0c5c9c54baf /library
parentcacb082416667ec4309d85e934068ded041d21b8 (diff)
downloaddfhack-38a07a4ca584e2cccc2c2814c35266ba33d692c8.tar.gz
dfhack-38a07a4ca584e2cccc2c2814c35266ba33d692c8.tar.bz2
dfhack-38a07a4ca584e2cccc2c2814c35266ba33d692c8.tar.xz
Export the tile finder function to lua, and improve mouse event reporting.
Diffstat (limited to 'library')
-rw-r--r--library/LuaApi.cpp21
-rw-r--r--library/include/modules/Screen.h3
-rw-r--r--library/modules/Screen.cpp46
3 files changed, 58 insertions, 12 deletions
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index 0f3ed935..112cc4fd 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -1075,6 +1075,7 @@ static const luaL_Reg dfhack_constructions_funcs[] = {
/***** Screen module *****/
static const LuaWrapper::FunctionReg dfhack_screen_module[] = {
+ WRAPM(Screen, inGraphicsMode),
WRAPM(Screen, clear),
WRAPM(Screen, invalidate),
{ NULL, NULL }
@@ -1133,6 +1134,25 @@ static int screen_fillRect(lua_State *L)
return 1;
}
+static int screen_findGraphicsTile(lua_State *L)
+{
+ auto str = luaL_checkstring(L, 1);
+ int x = luaL_checkint(L, 2);
+ int y = luaL_checkint(L, 3);
+ int tile, tile_gs;
+ if (Screen::findGraphicsTile(str, x, y, &tile, &tile_gs))
+ {
+ lua_pushinteger(L, tile);
+ lua_pushinteger(L, tile_gs);
+ return 2;
+ }
+ else
+ {
+ lua_pushnil(L);
+ return 1;
+ }
+}
+
namespace {
int screen_show(lua_State *L)
@@ -1168,6 +1188,7 @@ static const luaL_Reg dfhack_screen_funcs[] = {
{ "paintTile", screen_paintTile },
{ "paintString", screen_paintString },
{ "fillRect", screen_fillRect },
+ { "findGraphicsTile", screen_findGraphicsTile },
{ "show", &Lua::CallWithCatchWrapper<screen_show> },
{ "dismiss", screen_dismiss },
{ "isDismissed", screen_isDismissed },
diff --git a/library/include/modules/Screen.h b/library/include/modules/Screen.h
index 0e4963fb..334b466f 100644
--- a/library/include/modules/Screen.h
+++ b/library/include/modules/Screen.h
@@ -86,6 +86,9 @@ namespace DFHack
DFHACK_EXPORT df::coord2d getMousePos();
DFHACK_EXPORT df::coord2d getWindowSize();
+ /// Returns the state of [GRAPHICS:YES/NO]
+ DFHACK_EXPORT bool inGraphicsMode();
+
/// Paint one screen tile with the given pen
DFHACK_EXPORT bool paintTile(const Pen &pen, int x, int y);
diff --git a/library/modules/Screen.cpp b/library/modules/Screen.cpp
index ba0313e2..57b014ac 100644
--- a/library/modules/Screen.cpp
+++ b/library/modules/Screen.cpp
@@ -66,18 +66,24 @@ using Screen::Pen;
df::coord2d Screen::getMousePos()
{
- if (!gps) return df::coord2d();
+ if (!gps || (enabler && !enabler->tracking_on))
+ return df::coord2d(-1, -1);
return df::coord2d(gps->mouse_x, gps->mouse_y);
}
df::coord2d Screen::getWindowSize()
{
- if (!gps) return df::coord2d();
+ if (!gps) return df::coord2d(80, 25);
return df::coord2d(gps->dimx, gps->dimy);
}
+bool Screen::inGraphicsMode()
+{
+ return init && init->display.flag.is_set(init_display_flags::USE_GRAPHICS);
+}
+
static void doSetTile(const Pen &pen, int index)
{
auto screen = gps->screen + index*4;
@@ -399,21 +405,37 @@ int dfhack_lua_viewscreen::do_input(lua_State *L)
lua_pushvalue(L, -2);
- if (keys->empty())
- lua_pushnil(L);
- else
+ lua_createtable(L, 0, keys->size()+3);
+
+ for (auto it = keys->begin(); it != keys->end(); ++it)
{
- lua_createtable(L, 0, keys->size());
+ auto key = *it;
+
+ if (auto name = enum_item_raw_key(key))
+ lua_pushstring(L, name);
+ else
+ lua_pushinteger(L, key);
- for (auto it = keys->begin(); it != keys->end(); ++it)
+ lua_pushboolean(L, true);
+ lua_rawset(L, -3);
+
+ if (key >= interface_key::STRING_A000 &&
+ key <= interface_key::STRING_A255)
{
- if (auto name = enum_item_raw_key(*it))
- lua_pushstring(L, name);
- else
- lua_pushinteger(L, *it);
+ lua_pushinteger(L, key - interface_key::STRING_A000);
+ lua_setfield(L, -2, "_STRING");
+ }
+ }
+ if (enabler && enabler->tracking_on)
+ {
+ if (enabler->mouse_lbut) {
+ lua_pushboolean(L, true);
+ lua_setfield(L, -2, "_MOUSE_L");
+ }
+ if (enabler->mouse_rbut) {
lua_pushboolean(L, true);
- lua_rawset(L, -3);
+ lua_setfield(L, -2, "_MOUSE_R");
}
}