Skip to content

Commit

Permalink
fix menu appearing in wrong location when logo is clicked
Browse files Browse the repository at this point in the history
in adventure mode
  • Loading branch information
myk002 committed Apr 21, 2024
1 parent 2f3a615 commit cfaf8a4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions plugins/hotkeys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ using std::vector;

using namespace DFHack;

static const string INVOKE_MENU_COMMAND = "overlay trigger hotkeys.menu";
static const string INVOKE_MENU_BASE_COMMAND = "overlay trigger ";
static const string INVOKE_MENU_PREFIX = INVOKE_MENU_BASE_COMMAND + "hotkeys.";
static const string INVOKE_MENU_DEFAULT_COMMAND = INVOKE_MENU_BASE_COMMAND + "hotkeys.menu";
static const string INVOKE_HOTKEYS_COMMAND = "hotkeys";
static const std::string MENU_SCREEN_FOCUS_STRING = "dfhack/lua/hotkeys/menu";

Expand Down Expand Up @@ -64,7 +66,7 @@ static void add_binding_if_valid(color_ostream &out, const string &sym, const st
if (!can_invoke(cmdline, screen))
return;

if (filtermenu && (cmdline == INVOKE_MENU_COMMAND ||
if (filtermenu && (cmdline.starts_with(INVOKE_MENU_PREFIX) ||
cmdline == INVOKE_HOTKEYS_COMMAND)) {
DEBUG(log).print("filtering out hotkey menu keybinding\n");
return;
Expand Down Expand Up @@ -191,8 +193,12 @@ static bool invoke_command(color_ostream &out, const size_t index) {

static command_result hotkeys_cmd(color_ostream &out, vector <string> & parameters) {
if (!parameters.size()) {
DEBUG(log).print("invoking command: '%s'\n", INVOKE_MENU_COMMAND.c_str());
return Core::getInstance().runCommand(out, INVOKE_MENU_COMMAND );
DEBUG(log).print("invoking command: '%s'\n", INVOKE_MENU_DEFAULT_COMMAND.c_str());
return Core::getInstance().runCommand(out, INVOKE_MENU_DEFAULT_COMMAND );
} else if (parameters.size() == 2 && parameters[0] == "menu") {
string cmd = INVOKE_MENU_BASE_COMMAND + parameters[1];
DEBUG(log).print("invoking command: '%s'\n", cmd.c_str());
return Core::getInstance().runCommand(out, cmd);
}

CoreSuspender guard;
Expand Down
2 changes: 1 addition & 1 deletion plugins/lua/hotkeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function HotspotMenuWidget:init()
get_tile_token(5, 179), get_tile_token(6, 'H'), get_tile_token(7, 'a'), get_tile_token(8, 179), NEWLINE,
get_tile_token(9, 179), get_tile_token(10, 'c'), get_tile_token(11, 'k'), get_tile_token(12, 179),
},
on_click=function() dfhack.run_command('hotkeys') end,
on_click=function() dfhack.run_command{'hotkeys', 'menu', self.name} end,
},
}
end
Expand Down

0 comments on commit cfaf8a4

Please sign in to comment.