summaryrefslogtreecommitdiff
path: root/library/modules
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/modules
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/modules')
-rw-r--r--library/modules/Screen.cpp46
1 files changed, 34 insertions, 12 deletions
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");
}
}