From 2bf9b86c7b77edc9d1f7e724f0457cecfaae018c Mon Sep 17 00:00:00 2001 From: Robob27 Date: Thu, 2 Feb 2023 23:15:49 -0500 Subject: [PATCH] Fix getCurFocus lua, use where appropriate in c++ --- library/Core.cpp | 4 ++-- library/LuaApi.cpp | 9 ++++++++- plugins/hotkeys.cpp | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/library/Core.cpp b/library/Core.cpp index 536ab3f20..d56519a9c 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -948,7 +948,7 @@ command_result Core::runCommand(color_ostream &con, const std::string &first_, v << "Context may be used to limit the scope of the binding, by" << endl << "requiring the current context to have a certain prefix." << endl << "Current UI context is: " << endl - << join_strings("\n", Gui::getFocusStrings(Gui::getCurViewscreen(true))) << endl; + << join_strings("\n", Gui::getCurFocus(true)) << endl; } } else if (first == "alias") @@ -2421,7 +2421,7 @@ bool Core::SelectHotkey(int sym, int modifiers) } if (!binding.focus.empty()) { bool found = false; - std::vector focusStrings = Gui::getFocusStrings(Core::getTopViewscreen()); + std::vector focusStrings = Gui::getCurFocus(true); if(Gui::matchFocusString(binding.focus)) { found = true; } diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp index 7cb8d9825..45ea7d84d 100644 --- a/library/LuaApi.cpp +++ b/library/LuaApi.cpp @@ -1471,7 +1471,6 @@ static int gui_getMousePos(lua_State *L) static const LuaWrapper::FunctionReg dfhack_gui_module[] = { WRAPM(Gui, getCurViewscreen), WRAPM(Gui, getDFViewscreen), - WRAPM(Gui, getCurFocus), WRAPM(Gui, getSelectedWorkshopJob), WRAPM(Gui, getSelectedJob), WRAPM(Gui, getSelectedUnit), @@ -1506,6 +1505,13 @@ static int gui_getFocusStrings(lua_State *state) { return 1; } +static int gui_getCurFocus(lua_State *state) { + bool skip_dismissed = lua_toboolean(state, 1); + std::vector cur_focus = Gui::getCurFocus(skip_dismissed); + Lua::PushVector(state, cur_focus); + return 1; +} + static int gui_autoDFAnnouncement(lua_State *state) { bool rv; @@ -1632,6 +1638,7 @@ static const luaL_Reg dfhack_gui_funcs[] = { { "revealInDwarfmodeMap", gui_revealInDwarfmodeMap }, { "getMousePos", gui_getMousePos }, { "getFocusStrings", gui_getFocusStrings }, + { "getCurFocus", gui_getCurFocus }, { NULL, NULL } }; diff --git a/plugins/hotkeys.cpp b/plugins/hotkeys.cpp index 324a972b5..f5a4710e8 100644 --- a/plugins/hotkeys.cpp +++ b/plugins/hotkeys.cpp @@ -37,7 +37,7 @@ static bool can_invoke(const string &cmdline, df::viewscreen *screen) { } static int cleanupHotkeys(lua_State *) { - DEBUG(log).print("cleaning up old stub keybindings for:\n %s\n", join_strings("\n", Gui::getFocusStrings(Gui::getCurViewscreen(true))).c_str()); + DEBUG(log).print("cleaning up old stub keybindings for:\n %s\n", join_strings("\n", Gui::getCurFocus(true)).c_str()); std::for_each(sorted_keys.begin(), sorted_keys.end(), [](const string &sym) { string keyspec = sym + "@" + MENU_SCREEN_FOCUS_STRING; DEBUG(log).print("clearing keybinding: %s\n", keyspec.c_str()); @@ -143,7 +143,7 @@ static void list(color_ostream &out) { find_active_keybindings(Gui::getCurViewscreen(true), false); out.print("Valid keybindings for the current focus:\n %s\n", - join_strings("\n", Gui::getFocusStrings(Gui::getCurViewscreen(true))).c_str()); + join_strings("\n", Gui::getCurFocus(true)).c_str()); std::for_each(sorted_keys.begin(), sorted_keys.end(), [&](const string &sym) { out.print("%s: %s\n", sym.c_str(), current_bindings[sym].c_str()); });