diff --git a/data/init/dfhack.tools.init b/data/init/dfhack.tools.init index a910a8e34..741298109 100644 --- a/data/init/dfhack.tools.init +++ b/data/init/dfhack.tools.init @@ -78,6 +78,9 @@ # Display DFHack version on title screen #enable title-version +# Allow DFHack tools to overlay functionality and information on the DF screen +enable overlay + # Dwarf Manipulator (simple in-game Dwarf Therapist replacement) #enable manipulator @@ -89,7 +92,6 @@ # Other interface improvement tools #enable \ -# overlay \ # confirm \ # dwarfmonitor \ # mousequery \ diff --git a/docs/dev/Lua API.rst b/docs/dev/Lua API.rst index 83a99e5e6..8ec2b24ac 100644 --- a/docs/dev/Lua API.rst +++ b/docs/dev/Lua API.rst @@ -2392,13 +2392,13 @@ Supported callbacks and fields are: ``_STRING`` Maps to an integer in range 0-255. Duplicates a separate "STRING_A???" code for convenience. - ``_MOUSE_L, _MOUSE_R`` - If the left or right mouse button is being pressed. + ``_MOUSE_L, _MOUSE_R, _MOUSE_M`` + If the left, right, and/or middle mouse button is being pressed. - ``_MOUSE_L_DOWN, _MOUSE_R_DOWN`` - If the left or right mouse button was just pressed. + ``_MOUSE_L_DOWN, _MOUSE_R_DOWN, _MOUSE_M_DOWN`` + If the left, right, and/or middle mouse button was just pressed. - If this method is omitted, the screen is dismissed on receival of the ``LEAVESCREEN`` key. + If this method is omitted, the screen is dismissed on reception of the ``LEAVESCREEN`` key. * ``function screen:onGetSelectedUnit()`` * ``function screen:onGetSelectedItem()`` diff --git a/library/LuaTools.cpp b/library/LuaTools.cpp index 5b080ce43..084e5a21b 100644 --- a/library/LuaTools.cpp +++ b/library/LuaTools.cpp @@ -131,9 +131,13 @@ void DFHack::Lua::GetVector(lua_State *state, std::vector &pvec) } } +static bool inhibit_l_down = false; +static bool inhibit_r_down = false; +static bool inhibit_m_down = false; + void DFHack::Lua::PushInterfaceKeys(lua_State *L, const std::set &keys) { - lua_createtable(L, 0, keys.size() + 5); + lua_createtable(L, 0, keys.size() + 7); for (auto &key : keys) { @@ -154,23 +158,32 @@ void DFHack::Lua::PushInterfaceKeys(lua_State *L, } if (df::global::enabler) { - if (df::global::enabler->mouse_lbut_down) { + if (!inhibit_l_down && df::global::enabler->mouse_lbut_down) { lua_pushboolean(L, true); lua_setfield(L, -2, "_MOUSE_L_DOWN"); + inhibit_l_down = true; } - if (df::global::enabler->mouse_rbut_down) { + if (!inhibit_r_down && df::global::enabler->mouse_rbut_down) { lua_pushboolean(L, true); lua_setfield(L, -2, "_MOUSE_R_DOWN"); + inhibit_r_down = true; + } + if (!inhibit_m_down && df::global::enabler->mouse_mbut_down) { + lua_pushboolean(L, true); + lua_setfield(L, -2, "_MOUSE_M_DOWN"); + inhibit_m_down = true; } if (df::global::enabler->mouse_lbut) { lua_pushboolean(L, true); lua_setfield(L, -2, "_MOUSE_L"); - df::global::enabler->mouse_lbut_down = 0; } if (df::global::enabler->mouse_rbut) { lua_pushboolean(L, true); lua_setfield(L, -2, "_MOUSE_R"); - df::global::enabler->mouse_rbut_down = 0; + } + if (df::global::enabler->mouse_mbut) { + lua_pushboolean(L, true); + lua_setfield(L, -2, "_MOUSE_M"); } } } @@ -2134,4 +2147,11 @@ void DFHack::Lua::Core::Reset(color_ostream &out, const char *where) out.printerr("Common lua context stack top left at %d after %s.\n", top, where); lua_settop(State, 0); } + + if (!df::global::enabler->mouse_lbut) + inhibit_l_down = false; + if (!df::global::enabler->mouse_rbut) + inhibit_r_down = false; + if (!df::global::enabler->mouse_mbut) + inhibit_m_down = false; } diff --git a/library/lua/gui.lua b/library/lua/gui.lua index 31631b469..1742ee342 100644 --- a/library/lua/gui.lua +++ b/library/lua/gui.lua @@ -14,8 +14,10 @@ CLEAR_PEN = to_pen{tile=909, ch=32, fg=0, bg=0} local FAKE_INPUT_KEYS = { _MOUSE_L = true, _MOUSE_R = true, + _MOUSE_M = true, _MOUSE_L_DOWN = true, _MOUSE_R_DOWN = true, + _MOUSE_M_DOWN = true, _STRING = true, }