Keyboard shortcuts for game actions. More...
Classes | |
class | command_executor |
class | command_executor_default |
class | hotkey_base |
This is the base class for hotkey event matching. More... | |
struct | hotkey_command |
Stores all information related to functions that can be bound to hotkeys. More... | |
struct | hotkey_command_temp |
Do not use this outside hotkeys.cpp. More... | |
class | hotkey_keyboard |
This class is responsible for handling keys, not modifiers. More... | |
class | hotkey_mouse |
This class is responsible for handling mouse button presses. More... | |
class | hotkey_void |
This class is used to return non-valid results in order to save other people from null checks. More... | |
class | manager |
this class is initialized once at game start put all initialization and wipe code in the methods here. More... | |
class | scope_changer |
Typedefs | |
using | category_name_map_t = std::map< HOTKEY_CATEGORY, std::string > |
typedef std::bitset< SCOPE_COUNT > | hk_scopes |
typedef std::shared_ptr< hotkey_base > | hotkey_ptr |
typedef std::shared_ptr< hotkey_mouse > | hotkey_mouse_ptr |
typedef std::shared_ptr< hotkey_keyboard > | hotkey_keyboard_ptr |
typedef std::vector< hotkey::hotkey_ptr > | hotkey_list |
typedef std::vector< hotkey::hotkey_ptr >::iterator | hotkey_list_iter |
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) |
void | deactivate_all_scopes () |
void | set_scope_active (scope s, bool set) |
void | set_active_scopes (hk_scopes s) |
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::vector< hotkey_command > & | get_hotkey_commands () |
returns a container that contains all currently active hotkey_commands. More... | |
bool | remove_wml_hotkey (const std::string &id) |
removes a wml hotkey with the given id, returns true if the deletion was successful More... | |
bool | has_hotkey_command (const std::string &id) |
void | add_wml_hotkey (const std::string &id, const t_string &description, const config &default_hotkey) |
adds a new wml hotkey to the list, but only if there is no hotkey with that id yet on the list. More... | |
const hotkey_command & | get_hotkey_null () |
returns the hotkey_command that is treated as null. More... | |
void | delete_all_wml_hotkeys () |
deletes all wml hotkeys, should be called after a game has ended More... | |
const std::string & | get_description (const std::string &command) |
const std::string & | get_tooltip (const std::string &command) |
void | init_hotkey_commands () |
void | clear_hotkey_commands () |
HOTKEY_COMMAND | get_id (const std::string &command) |
returns get_hotkey_command(command).id More... | |
const category_name_map_t & | get_category_names () |
Returns the map of hotkey categories and their display names. More... | |
std::list< HOTKEY_COMMAND > | get_hotkeys_by_category (HOTKEY_CATEGORY category) |
Returns a list of all the hotkeys belonging to the given category. More... | |
static unsigned int | sdl_get_mods () |
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 (const 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_hotkeys (const game_config_view &cfg, bool set_as_default=false) |
Iterates through all hotkeys present in the config struct and creates and adds them to the hotkey list. 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 | |
hotkey_list | hotkeys_ |
game_config_view | default_hotkey_cfg_ |
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.
using hotkey::category_name_map_t = typedef std::map<HOTKEY_CATEGORY, std::string> |
Definition at line 211 of file hotkey_command.hpp.
typedef std::bitset<SCOPE_COUNT> hotkey::hk_scopes |
Definition at line 224 of file hotkey_command.hpp.
typedef std::shared_ptr<hotkey_keyboard> hotkey::hotkey_keyboard_ptr |
Definition at line 35 of file hotkey_item.hpp.
typedef std::vector<hotkey::hotkey_ptr> hotkey::hotkey_list |
Definition at line 37 of file hotkey_item.hpp.
typedef std::vector<hotkey::hotkey_ptr>::iterator hotkey::hotkey_list_iter |
Definition at line 38 of file hotkey_item.hpp.
typedef std::shared_ptr<hotkey_mouse> hotkey::hotkey_mouse_ptr |
Definition at line 34 of file hotkey_item.hpp.
typedef std::shared_ptr<hotkey_base> hotkey::hotkey_ptr |
Definition at line 32 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 194 of file hotkey_command.hpp.
Definition at line 41 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 | ( | const hotkey_ptr | item | ) |
Add a hotkey to the list of hotkeys.
item | The item to add. |
Definition at line 357 of file hotkey_item.cpp.
References get_hotkey_command(), and set_active_scopes().
Referenced by gui2::dialogs::preferences_dialog::add_hotkey_callback(), add_wml_hotkey(), and load_hotkeys().
void hotkey::add_wml_hotkey | ( | const std::string & | id, |
const t_string & | description, | ||
const config & | default_hotkey | ||
) |
adds a new wml hotkey to the list, but only if there is no hotkey with that id yet on the list.
the object that is created here will be deleted in "delete_all_wml_hotkeys()"
Definition at line 413 of file hotkey_command.cpp.
References add_hotkey(), DBG_G, config::empty(), ERR_CF, has_hotkey_command(), has_hotkey_item(), HKCAT_CUSTOM, HOTKEY_WML, id, load_from_config(), LOG_G, remove_wml_hotkey(), and t_string::size().
Referenced by game_events::wml_menu_item::init_handler(), game_events::wml_menu_item::update(), and game_events::wml_menu_item::wml_menu_item().
void hotkey::clear_hotkey_commands | ( | ) |
Definition at line 563 of file hotkey_command.cpp.
Referenced by hotkey::manager::wipe().
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 377 of file hotkey_item.cpp.
Referenced by gui2::dialogs::preferences_dialog::default_hotkey_callback(), gui2::dialogs::preferences_dialog::remove_hotkey_callback(), and hotkey::manager::wipe().
void hotkey::clear_hotkeys | ( | ) |
Unset the bindings for all hotkeys.
Definition at line 390 of file hotkey_item.cpp.
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 148 of file hotkey_item.cpp.
References ERR_G, get_hotkey_command(), CKey::is_uncomposable(), and sdl_get_mods().
Referenced by gui2::dialogs::hotkey_bind::sdl_event_callback().
void hotkey::deactivate_all_scopes | ( | ) |
Definition at line 329 of file hotkey_command.cpp.
References i, and SCOPE_COUNT.
Referenced by test_utils::game_config_manager::game_config_manager(), game_config_manager::init_game_config(), play_controller::play_controller(), and editor::start().
void hotkey::del_hotkey | ( | const hotkey_ptr | item | ) |
Remove a hotkey from the list of hotkeys.
Definition at line 350 of file hotkey_item.cpp.
References gui2::dialogs::tip::remove().
void hotkey::delete_all_wml_hotkeys | ( | ) |
deletes all wml hotkeys, should be called after a game has ended
Definition at line 517 of file hotkey_command.cpp.
References HKCAT_CUSTOM, and HOTKEY_WML.
Referenced by hotkey::manager::wipe(), and play_controller::~play_controller().
|
static |
Definition at line 582 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 category_name_map_t & hotkey::get_category_names | ( | ) |
Returns the map of hotkey categories and their display names.
These aren't translated and need be converted to a t_string before being displayed to the player.
Definition at line 573 of file hotkey_command.cpp.
Referenced by gui2::dialogs::preferences_dialog::preferences_dialog().
const std::string & hotkey::get_description | ( | const std::string & | command | ) |
Definition at line 528 of file hotkey_command.cpp.
References hotkey::hotkey_command::description, and get_hotkey_command().
Referenced by gui2::dialogs::preferences_dialog::add_hotkey_callback(), hotkey::command_executor::get_menu_images(), theme::menu::menu(), and theme::action::tooltip().
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 395 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().
const hotkey_command & hotkey::get_hotkey_command | ( | const std::string & | command | ) |
returns the hotkey_command with the given name
Definition at line 359 of file hotkey_command.cpp.
References get_hotkey_null().
Referenced by add_hotkey(), hotkey::hotkey_base::bindings_equal(), create_hotkey(), hotkey::command_executor::execute_action(), controller_base::execute_action(), get_description(), get_id(), get_tooltip(), has_hotkey_command(), hotkey::hotkey_base::matches(), hotkey::hotkey_keyboard::matches_helper(), hotkey::command_executor::queue_command(), remove_wml_hotkey(), hotkey::command_executor_default::set_button_state(), editor::editor_controller::show_menu(), play_controller::hotkey_handler::show_menu(), hotkey::command_executor::show_menu(), and controller_base::show_menu().
const std::vector< 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 368 of file hotkey_command.cpp.
Referenced by gui2::dialogs::preferences_dialog::setup_hotkey_list().
const hotkey_command & hotkey::get_hotkey_null | ( | ) |
returns the hotkey_command that is treated as null.
Definition at line 511 of file hotkey_command.cpp.
Referenced by hotkey::hotkey_command::get_command_by_command(), get_hotkey_command(), and hotkey::hotkey_command::null_command().
const hotkey_list & hotkey::get_hotkeys | ( | ) |
Returns the list of hotkeys.
Definition at line 435 of file hotkey_item.cpp.
References hotkeys_.
Referenced by gui2::dialogs::preferences_dialog::add_hotkey_callback().
std::list< HOTKEY_COMMAND > hotkey::get_hotkeys_by_category | ( | HOTKEY_CATEGORY | category | ) |
Returns a list of all the hotkeys belonging to the given category.
Definition at line 578 of file hotkey_command.cpp.
References hotkey::hotkey_command::category.
Referenced by gui2::dialogs::preferences_dialog::preferences_dialog().
HOTKEY_COMMAND hotkey::get_id | ( | const std::string & | command | ) |
returns get_hotkey_command(command).id
Definition at line 568 of file hotkey_command.cpp.
References get_hotkey_command(), and hotkey::hotkey_command::id.
Referenced by gui2::implementation::builder_window::build(), events::call_in_main_thread(), ai::component::component(), editor::editor_palette< overlay >::draw_contents(), hotkey::command_executor::get_menu_image(), hotkey::command_executor::get_menu_images(), gui2::event::sdl_event_handler::hotkey_pressed(), game_lua_kernel::impl_game_config_get(), game_lua_kernel::impl_scenario_get(), editor::editor_toolkit::init_mouse_actions(), events::pump(), and gui2::window::show().
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 452 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(), theme::menu::menu(), gui2::dialogs::preferences_dialog::post_build(), 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().
const std::string & hotkey::get_tooltip | ( | const std::string & | command | ) |
Definition at line 533 of file hotkey_command.cpp.
References get_hotkey_command(), and hotkey::hotkey_command::tooltip.
Referenced by theme::menu::menu(), and theme::action::tooltip().
bool hotkey::has_hotkey_command | ( | const std::string & | id | ) |
Definition at line 408 of file hotkey_command.cpp.
References get_hotkey_command(), HOTKEY_NULL, and hotkey::hotkey_command::id.
Referenced by add_wml_hotkey().
bool hotkey::has_hotkey_item | ( | const std::string & | command | ) |
Definition at line 328 of file hotkey_item.cpp.
Referenced by add_wml_hotkey().
void hotkey::init_hotkey_commands | ( | ) |
Definition at line 539 of file hotkey_command.cpp.
References i.
Referenced by hotkey::manager::init().
bool hotkey::is_hotkeyable_event | ( | const SDL_Event & | event | ) |
Definition at line 477 of file hotkey_item.cpp.
References sdl_get_mods().
Referenced by gui2::dialogs::hotkey_bind::sdl_event_callback().
bool hotkey::is_scope_active | ( | scope | s | ) |
Definition at line 346 of file hotkey_command.cpp.
References s, and SCOPE_COUNT.
Referenced by help::description_type(), and hotkey::hotkey_base::matches().
bool hotkey::is_scope_active | ( | hk_scopes | s | ) |
Definition at line 352 of file hotkey_command.cpp.
void hotkey::jbutton_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 551 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 556 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 561 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 567 of file command_executor.cpp.
References hotkey::command_executor::handle_keyup().
Referenced by controller_base::keyup_listener::handle_event().
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 197 of file hotkey_item.cpp.
References ERR_G.
Referenced by preferences::acquaintance::acquaintance(), add_wml_hotkey(), and load_hotkeys().
void hotkey::load_hotkeys | ( | const game_config_view & | cfg, |
bool | set_as_default = false |
||
) |
Iterates through all hotkeys present in the config struct and creates and adds them to the hotkey list.
cfg | The config struct to load from. |
set_as_default | Indicates whether the config struct should be treated as the default game settings. |
Definition at line 405 of file hotkey_item.cpp.
References add_hotkey(), 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(), preferences::load_hotkeys(), and reset_default_hotkeys().
void hotkey::mbutton_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 533 of file command_executor.cpp.
References event_queue(), and run_events().
Referenced by controller_base::handle_event().
bool hotkey::remove_wml_hotkey | ( | const std::string & | id | ) |
removes a wml hotkey with the given id, returns true if the deletion was successful
Definition at line 374 of file hotkey_command.cpp.
References get_hotkey_command(), HOTKEY_NULL, HOTKEY_WML, hotkey::hotkey_command::id, utf8::index(), and LOG_G.
Referenced by add_wml_hotkey(), game_events::wml_menu_item::finish_handler(), and game_events::wml_menu_item::update().
void hotkey::reset_default_hotkeys | ( | ) |
Reset all hotkeys to the defaults.
Definition at line 424 of file hotkey_item.cpp.
References game_config_view::child_range(), ERR_G, and load_hotkeys().
Referenced by preferences::clear_hotkeys().
void hotkey::run_events | ( | command_executor * | executor | ) |
Definition at line 573 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 440 of file hotkey_item.cpp.
References config::add_child(), and config::clear_children().
Referenced by gui2::dialogs::preferences_dialog::post_show(), and preferences::save_hotkeys().
|
static |
Definition at line 49 of file hotkey_item.cpp.
Referenced by create_hotkey(), is_hotkeyable_event(), hotkey::hotkey_keyboard::matches_helper(), and hotkey::hotkey_mouse::matches_helper().
void hotkey::set_active_scopes | ( | hk_scopes | s | ) |
Definition at line 341 of file hotkey_command.cpp.
References s.
Referenced by add_hotkey(), and gui2::dialogs::preferences_dialog::add_hotkey_callback().
void hotkey::set_scope_active | ( | scope | s, |
bool | set | ||
) |
Definition at line 336 of file hotkey_command.cpp.
References s.
Referenced by test_utils::game_config_manager::game_config_manager(), game_config_manager::init_game_config(), play_controller::play_controller(), and editor::start().
game_config_view hotkey::default_hotkey_cfg_ |
Definition at line 42 of file hotkey_item.cpp.
hotkey_list hotkey::hotkeys_ |
Definition at line 41 of file hotkey_item.cpp.
Referenced by get_hotkeys().