Fix getCurFocus lua, use where appropriate in c++

develop
Robob27 2023-02-02 23:15:49 -05:00
parent 36e4bba779
commit 2bf9b86c7b
3 changed files with 12 additions and 5 deletions

@ -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<std::string> focusStrings = Gui::getFocusStrings(Core::getTopViewscreen());
std::vector<std::string> focusStrings = Gui::getCurFocus(true);
if(Gui::matchFocusString(binding.focus)) {
found = true;
}

@ -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<std::string> 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 }
};

@ -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());
});