MP: correctly register Start Game button's shortcut with hotkey system (#9181)

Correctly register the Start Game button's shortcut with hotkey system
This commit is contained in:
Subhraman Sarkar 2024-08-09 08:56:08 +05:30 committed by GitHub
parent c761174331
commit 8863cd1bcd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 35 deletions

View file

@ -655,4 +655,10 @@
command="global__lua__console"
key="`"
[/hotkey]
[hotkey]
command="mp_startgame"
key="g"
{IF_APPLE_CMD_ELSE_CTRL}
[/hotkey]
#undef IF_APPLE_CMD_ELSE_CTRL

View file

@ -35,6 +35,8 @@
#include "gui/widgets/slider.hpp"
#include "gui/widgets/tree_view.hpp"
#include "gui/widgets/tree_view_node.hpp"
#include "hotkey/hotkey_item.hpp"
#include "hotkey/hotkey_command.hpp"
#include "mp_ui_alerts.hpp"
#include "units/types.hpp"
#include "wesnothd_connection.hpp"
@ -74,15 +76,11 @@ void mp_staging::pre_show(window& window)
window.set_escape_disabled(true);
// Ctrl+G triggers 'I'm Ready' (ok) button's functionality
connect_signal<event::SDL_KEY_DOWN>(std::bind(
&mp_staging::signal_handler_sdl_key_down, this, std::placeholders::_2, std::placeholders::_3, std::placeholders::_5, std::placeholders::_6));
window.register_hotkey(hotkey::HOTKEY_MP_START_GAME, std::bind(&mp_staging::start_game, this));
std::stringstream tooltip;
tooltip << vgettext_impl("wesnoth", "Hotkey(s): ", {{}});
#ifdef __APPLE__
tooltip << "cmd+g";
#else
tooltip << "ctrl+g";
#endif
tooltip
<< vgettext_impl("wesnoth", "Hotkey(s): ", {{}})
<< hotkey::get_names(hotkey::hotkey_command::get_command_by_command(hotkey::HOTKEY_MP_START_GAME).id);
find_widget<button>(get_window(), "ok", false).set_tooltip(tooltip.str());
//
@ -578,28 +576,6 @@ void mp_staging::network_handler()
state_changed_ = false;
}
void mp_staging::signal_handler_sdl_key_down(const event::ui_event /*event*/,
bool& handled,
const SDL_Keycode key,
SDL_Keymod modifier)
{
handled = true;
#ifdef __APPLE__
// Idiomatic modifier key in macOS computers.
const SDL_Keycode modifier_key = KMOD_GUI;
#else
// Idiomatic modifier key in Microsoft desktop environments. Common in
// GNU/Linux as well, to some extent.
const SDL_Keycode modifier_key = KMOD_CTRL;
#endif
if ((key == SDLK_g) && (modifier & modifier_key)) {
get_window()->set_retval(retval::OK);
return;
}
}
void mp_staging::post_show(window& window)
{
if(update_timer_ != 0) {

View file

@ -84,11 +84,10 @@ private:
state_changed_ = true;
}
/** for Ctrl+G handling */
void signal_handler_sdl_key_down(const event::ui_event /*event*/,
bool& handled,
const SDL_Keycode key,
SDL_Keymod modifier);
void start_game()
{
get_window()->set_retval(retval::OK);
}
ng::connect_engine& connect_engine_;

View file

@ -296,6 +296,7 @@ constexpr std::array<hotkey_command_temp, HOTKEY_NULL - 1> master_hotkey_list {{
{ HOTKEY_CLEAR_MSG, "clearmessages", N_("Clear Chat"), false, scope_game, HKCAT_CHAT, "" },
{ HOTKEY_LANGUAGE, "changelanguage", N_("Change Language"), false, scope_main, HKCAT_GENERAL, "" },
{ HOTKEY_MP_START_GAME, "mp_startgame", N_("Start Game (MP)"), false, scope_main, HKCAT_GENERAL, "" },
{ TITLE_SCREEN__RELOAD_WML, "title_screen__reload_wml", N_("Refresh WML"), true , scope_editor | scope_main, HKCAT_PLACEHOLDER, "" },
{ TITLE_SCREEN__NEXT_TIP, "title_screen__next_tip", N_("Next Tip of the Day"), false, scope_main, HKCAT_GENERAL, "" },
{ TITLE_SCREEN__PREVIOUS_TIP, "title_screen__previous_tip", N_("Previous Tip of the Day"), false, scope_main, HKCAT_GENERAL, "" },

View file

@ -101,6 +101,9 @@ enum HOTKEY_COMMAND {
HOTKEY_MINIMAP_CODING_TERRAIN, HOTKEY_MINIMAP_CODING_UNIT,
HOTKEY_MINIMAP_DRAW_UNITS, HOTKEY_MINIMAP_DRAW_VILLAGES, HOTKEY_MINIMAP_DRAW_TERRAIN,
// Multiplayer
HOTKEY_MP_START_GAME,
/* Gui2 specific hotkeys. */
TITLE_SCREEN__RELOAD_WML,
TITLE_SCREEN__NEXT_TIP,