Keyboard shortcuts for game actions. More...
Classes | |
struct | ui_command |
Used as the main paramneter for can_execute_command/do_execute_command These functions are used to execute hotkeys but also to execute menu items, (Most menu items point to the same action as a hotkey but not all) More... | |
class | command_executor |
class | command_executor_default |
struct | hotkey_command_temp |
struct | hotkey_command |
Stores all information related to functions that can be bound to hotkeys. More... | |
class | scope_changer |
class | wml_hotkey_record |
RAII helper class to control the lifetime of a WML hotkey_command. More... | |
class | hotkey_base |
This is the base class for hotkey event matching. More... | |
class | hotkey_keyboard |
This class is responsible for handling keys, not modifiers. More... | |
class | hotkey_void |
This class is used to return non-valid results in order to save other people from null checks. More... | |
class | hotkey_mouse |
This class is responsible for handling mouse button presses. More... | |
class | manager |
this class is initialized once at game start put all initialization and wipe code in the methods here. More... | |
Typedefs | |
typedef std::bitset< SCOPE_COUNT > | hk_scopes |
typedef std::shared_ptr< class hotkey_base > | hotkey_ptr |
typedef std::shared_ptr< class hotkey_mouse > | hotkey_mouse_ptr |
typedef std::shared_ptr< class hotkey_keyboard > | hotkey_keyboard_ptr |
typedef std::vector< hotkey::hotkey_ptr > | hotkey_list |
Functions | |
static void | event_queue (const SDL_Event &event, command_executor *executor) |
void | mbutton_event (const SDL_Event &event, command_executor *executor) |
void | jbutton_event (const SDL_Event &event, command_executor *executor) |
void | jhat_event (const SDL_Event &event, command_executor *executor) |
void | key_event (const SDL_Event &event, command_executor *executor) |
void | keyup_event (const SDL_Event &, command_executor *executor) |
void | run_events (command_executor *executor) |
bool | is_scope_active (scope s) |
bool | is_scope_active (hk_scopes s) |
const hotkey_command & | get_hotkey_command (const std::string &command) |
returns the hotkey_command with the given name More... | |
const std::map< std::string_view, hotkey::hotkey_command > & | get_hotkey_commands () |
returns a container that contains all currently active hotkey_commands. More... | |
bool | has_hotkey_command (const std::string &id) |
void | init_hotkey_commands () |
t_string | get_translatable_category_name (HOTKEY_CATEGORY category) |
Gets the display name for a given hotkey category. More... | |
hotkey_ptr | create_hotkey (const std::string &id, const SDL_Event &event) |
Create a new hotkey item for a command from an SDL_Event. More... | |
hotkey_ptr | load_from_config (const config &cfg) |
Create and instantiate a hotkey from a config element. More... | |
bool | has_hotkey_item (const std::string &command) |
void | del_hotkey (const hotkey_ptr item) |
Remove a hotkey from the list of hotkeys. More... | |
void | add_hotkey (hotkey_ptr item) |
Add a hotkey to the list of hotkeys. More... | |
void | clear_hotkeys (const std::string &command) |
Unset the command bindings for all hotkeys matching the command. More... | |
void | clear_hotkeys () |
Unset the bindings for all hotkeys. More... | |
const hotkey_ptr | get_hotkey (const SDL_Event &event) |
Iterate through the list of hotkeys and return a hotkey that matches the SDL_Event and the current keyboard modifier state. More... | |
void | load_default_hotkeys (const game_config_view &cfg) |
Registers all hotkeys present in this config. More... | |
void | load_custom_hotkeys (const game_config_view &cfg) |
Registers all hotkeys present in this config, overwriting any matching default hotkeys. More... | |
void | reset_default_hotkeys () |
Reset all hotkeys to the defaults. More... | |
const hotkey_list & | get_hotkeys () |
Returns the list of hotkeys. More... | |
void | save_hotkeys (config &cfg) |
Save the non-default hotkeys to the config. More... | |
std::string | get_names (const std::string &id) |
Returns a comma-separated string of hotkey names. More... | |
bool | is_hotkeyable_event (const SDL_Event &event) |
Variables | |
constexpr uint32_t | scope_game = 1 << SCOPE_GAME |
constexpr uint32_t | scope_editor = 1 << SCOPE_EDITOR |
constexpr uint32_t | scope_main = 1 << SCOPE_MAIN_MENU |
Keyboard shortcuts for game actions.
Hotkey commands can be loaded from configuration objects. When a keyboard event corresponding to a hotkey occurs, a command_executor object can execute the hotkeys actions. For this to work, key_event() must be called whenever a keyboard event happens.
typedef std::bitset<SCOPE_COUNT> hotkey::hk_scopes |
Definition at line 234 of file hotkey_command.hpp.
typedef std::shared_ptr<class hotkey_keyboard> hotkey::hotkey_keyboard_ptr |
Definition at line 29 of file hotkey_item.hpp.
typedef std::vector<hotkey::hotkey_ptr> hotkey::hotkey_list |
Definition at line 31 of file hotkey_item.hpp.
typedef std::shared_ptr<class hotkey_mouse> hotkey::hotkey_mouse_ptr |
Definition at line 28 of file hotkey_item.hpp.
typedef std::shared_ptr<class hotkey_base> hotkey::hotkey_ptr |
Definition at line 27 of file hotkey_item.hpp.
enum hotkey::ACTION_STATE |
Enumerator | |
---|---|
ACTION_STATELESS | |
ACTION_ON | |
ACTION_OFF | |
ACTION_SELECTED | |
ACTION_DESELECTED |
Definition at line 26 of file command_executor.hpp.
Enumerator | |
---|---|
HKCAT_GENERAL | |
HKCAT_SAVING | |
HKCAT_MAP | |
HKCAT_UNITS | |
HKCAT_CHAT | |
HKCAT_REPLAY | |
HKCAT_WHITEBOARD | |
HKCAT_SCENARIO | |
HKCAT_PALETTE | |
HKCAT_TOOLS | |
HKCAT_CLIPBOARD | |
HKCAT_DEBUG | |
HKCAT_CUSTOM | |
HKCAT_PLACEHOLDER |
Definition at line 214 of file hotkey_command.hpp.
Definition at line 48 of file hotkey_command.hpp.
enum hotkey::scope |
Available hotkey scopes.
The scope is used to allow command from non-overlapping areas of the game share the same key
Enumerator | |
---|---|
SCOPE_MAIN_MENU | |
SCOPE_GAME | |
SCOPE_EDITOR | |
SCOPE_COUNT |
Definition at line 34 of file hotkey_command.hpp.
void hotkey::add_hotkey | ( | hotkey_ptr | item | ) |
Add a hotkey to the list of hotkeys.
item | The item to add. |
Definition at line 335 of file hotkey_item.cpp.
Referenced by gui2::dialogs::preferences_dialog::add_hotkey_callback(), load_custom_hotkeys(), and hotkey::wml_hotkey_record::wml_hotkey_record().
void hotkey::clear_hotkeys | ( | ) |
Unset the bindings for all hotkeys.
Definition at line 362 of file hotkey_item.cpp.
void hotkey::clear_hotkeys | ( | const std::string & | command | ) |
Unset the command bindings for all hotkeys matching the command.
command | The binding to be unset |
Definition at line 349 of file hotkey_item.cpp.
Referenced by gui2::dialogs::preferences_dialog::remove_hotkey_callback(), and hotkey::manager::~manager().
hotkey_ptr hotkey::create_hotkey | ( | const std::string & | id, |
const SDL_Event & | event | ||
) |
Create a new hotkey item for a command from an SDL_Event.
id | The command to bind to. |
event | The SDL_Event to base the creation on. |
Definition at line 123 of file hotkey_item.cpp.
References ERR_G, get_hotkey_command(), sdl::get_mods(), CKey::is_uncomposable(), and hotkey::hotkey_command::toggle.
Referenced by gui2::dialogs::hotkey_bind::sdl_event_callback().
void hotkey::del_hotkey | ( | const hotkey_ptr | item | ) |
Remove a hotkey from the list of hotkeys.
Definition at line 328 of file hotkey_item.cpp.
References utils::erase().
|
static |
Definition at line 576 of file command_executor.cpp.
References hotkey::command_executor::queue_command(), and hotkey::command_executor::set_button_state().
Referenced by jbutton_event(), jhat_event(), key_event(), and mbutton_event().
const hotkey_ptr hotkey::get_hotkey | ( | const SDL_Event & | event | ) |
Iterate through the list of hotkeys and return a hotkey that matches the SDL_Event and the current keyboard modifier state.
event | The SDL_Event to use as a template. |
Definition at line 367 of file hotkey_item.cpp.
Referenced by gui2::event::sdl_event_handler::button_down(), gui2::event::sdl_event_handler::hat_motion(), gui2::event::sdl_event_handler::key_down(), wb::manager::print_help_once(), and hotkey::command_executor::queue_command().
NOT_DANGLING const hotkey_command & hotkey::get_hotkey_command | ( | const std::string & | command | ) |
returns the hotkey_command with the given name
Definition at line 367 of file hotkey_command.cpp.
References hotkey::hotkey_command::null_command().
Referenced by gui2::dialogs::preferences_dialog::add_hotkey_callback(), hotkey::hotkey_base::bindings_equal(), create_hotkey(), hotkey::command_executor::get_menu_images(), has_hotkey_command(), gui2::event::sdl_event_handler::hotkey_pressed(), editor::editor_toolkit::init_mouse_actions(), hotkey::hotkey_base::matches(), hotkey::hotkey_keyboard::matches_helper(), theme::menu::menu(), hotkey::command_executor::queue_command(), editor::editor_controller::show_menu(), theme::action::tooltip(), and hotkey::ui_command::ui_command().
const std::map< std::string_view, hotkey::hotkey_command > & hotkey::get_hotkey_commands | ( | ) |
returns a container that contains all currently active hotkey_commands.
everything that wants a hotkey, must be in this container
Definition at line 376 of file hotkey_command.cpp.
Referenced by gui2::dialogs::preferences_dialog::setup_hotkey_list().
const hotkey_list & hotkey::get_hotkeys | ( | ) |
Returns the list of hotkeys.
Definition at line 411 of file hotkey_item.cpp.
Referenced by gui2::dialogs::preferences_dialog::add_hotkey_callback().
std::string hotkey::get_names | ( | const std::string & | id | ) |
Returns a comma-separated string of hotkey names.
A hotkey name is in the form of "ctrl+l" or "n" or "mouse 1". The comman separated string is of the form "ctrl+l,n,mouse 1".
Definition at line 427 of file hotkey_item.cpp.
References utils::join(), and names.
Referenced by gui2::dialogs::preferences_dialog::add_hotkey_callback(), hotkey::command_executor::get_menu_images(), gui2::dialogs::preferences_dialog::initialize_callbacks(), theme::menu::menu(), gui2::dialogs::mp_staging::pre_show(), gui2::dialogs::preferences_dialog::remove_hotkey_callback(), gui2::dialogs::preferences_dialog::setup_hotkey_list(), gui2::styled_widget::signal_handler_show_tooltip(), play_controller::hotkey_handler::toggle_accelerated_speed(), theme::action::tooltip(), and playsingle_controller::hotkey_handler::whiteboard_toggle().
t_string hotkey::get_translatable_category_name | ( | HOTKEY_CATEGORY | category | ) |
Gets the display name for a given hotkey category.
Definition at line 502 of file hotkey_command.cpp.
Referenced by gui2::dialogs::preferences_dialog::setup_hotkey_list().
bool hotkey::has_hotkey_command | ( | const std::string & | id | ) |
Definition at line 381 of file hotkey_command.cpp.
References hotkey::hotkey_command::command, get_hotkey_command(), and HOTKEY_NULL.
bool hotkey::has_hotkey_item | ( | const std::string & | command | ) |
Definition at line 308 of file hotkey_item.cpp.
Referenced by hotkey::wml_hotkey_record::wml_hotkey_record().
void hotkey::init_hotkey_commands | ( | ) |
Definition at line 492 of file hotkey_command.cpp.
Referenced by hotkey::manager::manager().
bool hotkey::is_hotkeyable_event | ( | const SDL_Event & | event | ) |
Definition at line 451 of file hotkey_item.cpp.
References sdl::get_mods().
Referenced by gui2::dialogs::hotkey_bind::sdl_event_callback().
bool hotkey::is_scope_active | ( | hk_scopes | s | ) |
Definition at line 360 of file hotkey_command.cpp.
References s.
bool hotkey::is_scope_active | ( | scope | s | ) |
Definition at line 354 of file hotkey_command.cpp.
References s, and SCOPE_COUNT.
Referenced by help::description_type(), and hotkey::hotkey_base::matches().
void hotkey::jbutton_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 545 of file command_executor.cpp.
References event_queue().
Referenced by controller_base::handle_event().
void hotkey::jhat_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 550 of file command_executor.cpp.
References event_queue().
Referenced by controller_base::handle_event().
void hotkey::key_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 555 of file command_executor.cpp.
References event_queue().
Referenced by controller_base::handle_event().
void hotkey::keyup_event | ( | const SDL_Event & | , |
command_executor * | executor | ||
) |
Definition at line 561 of file command_executor.cpp.
References hotkey::command_executor::handle_keyup().
Referenced by controller_base::keyup_listener::handle_event().
void hotkey::load_custom_hotkeys | ( | const game_config_view & | cfg | ) |
Registers all hotkeys present in this config, overwriting any matching default hotkeys.
cfg | The config to load from. |
Definition at line 390 of file hotkey_item.cpp.
References add_hotkey(), game_config_view::child_range(), and load_from_config().
Referenced by prefs::load_hotkeys().
void hotkey::load_default_hotkeys | ( | const game_config_view & | cfg | ) |
Registers all hotkeys present in this config.
cfg | The config to load from. This is saved and is used again when reset_default_hotkeys is called. |
Definition at line 377 of file hotkey_item.cpp.
References game_config_view::child_range(), and load_from_config().
Referenced by test_utils::game_config_manager::game_config_manager(), game_config_manager::init_game_config(), and reset_default_hotkeys().
hotkey_ptr hotkey::load_from_config | ( | const config & | cfg | ) |
Create and instantiate a hotkey from a config element.
cfg | The config element to read for data. |
Definition at line 174 of file hotkey_item.cpp.
References config_attribute_value::empty(), ERR_G, and config_attribute_value::to_int().
Referenced by load_custom_hotkeys(), load_default_hotkeys(), and hotkey::wml_hotkey_record::wml_hotkey_record().
void hotkey::mbutton_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 527 of file command_executor.cpp.
References event_queue(), and run_events().
Referenced by controller_base::handle_event().
void hotkey::reset_default_hotkeys | ( | ) |
Reset all hotkeys to the defaults.
Definition at line 400 of file hotkey_item.cpp.
References ERR_G, and load_default_hotkeys().
Referenced by prefs::clear_hotkeys().
void hotkey::run_events | ( | command_executor * | executor | ) |
Definition at line 567 of file command_executor.cpp.
References hotkey::command_executor::run_queued_commands(), and hotkey::command_executor::set_button_state().
Referenced by mbutton_event(), and controller_base::process().
void hotkey::save_hotkeys | ( | config & | cfg | ) |
Save the non-default hotkeys to the config.
cfg | The config to save to. |
Definition at line 416 of file hotkey_item.cpp.
References config::add_child(), and config::clear_children().
Referenced by prefs::save_hotkeys().
|
constexpr |
Definition at line 45 of file hotkey_command.hpp.
Referenced by editor::start().
|
constexpr |
Definition at line 44 of file hotkey_command.hpp.
Referenced by test_utils::game_config_manager::game_config_manager(), and hotkey::wml_hotkey_record::wml_hotkey_record().
|
constexpr |
Definition at line 46 of file hotkey_command.hpp.
Referenced by game_config_manager::init_game_config().