Keyboard shortcuts for game actions. More...
Classes | |
class | basic_handler |
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_joystick |
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 | |
typedef std::bitset< SCOPE_COUNT > | hk_scopes |
typedef boost::ptr_vector < hotkey_command > | t_hotkey_command_list |
typedef boost::shared_ptr < hotkey_base > | hotkey_ptr |
typedef boost::shared_ptr < hotkey_mouse > | hotkey_mouse_ptr |
typedef boost::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_execute (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 | execute_command (const hotkey_command &command, command_executor *executor, int index, bool press) |
void | deactivate_all_scopes () |
void | set_scope_active (scope s, bool set) |
void | set_active_scopes (hk_scopes 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 boost::ptr_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... | |
static unsigned int | sdl_get_mods () |
hotkey_ptr | create_hotkey (const std::string &id, 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 config &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 (std::string id) |
Returns a comma-separated string of hotkey names. More... | |
hotkey_ptr | show_binding_dialog (CVideo &video, const std::string &id) |
Variables | |
hotkey_list | hotkeys_ |
config | 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.
typedef std::bitset<SCOPE_COUNT> hotkey::hk_scopes |
Definition at line 191 of file hotkey_command.hpp.
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.
Definition at line 34 of file hotkey_item.hpp.
Definition at line 32 of file hotkey_item.hpp.
typedef boost::ptr_vector<hotkey_command> hotkey::t_hotkey_command_list |
Definition at line 248 of file hotkey_command.hpp.
enum hotkey::ACTION_STATE |
Enumerator | |
---|---|
ACTION_STATELESS | |
ACTION_ON | |
ACTION_OFF | |
ACTION_SELECTED | |
ACTION_DESELECTED |
Definition at line 27 of file command_executor.hpp.
Definition at line 38 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 31 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 354 of file hotkey_item.cpp.
References hotkey::hotkey_base::bindings_equal(), get_hotkey_command(), and set_active_scopes().
Referenced by gui2::tpreferences::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 374 of file hotkey_command.cpp.
References add_hotkey(), DBG_G, config::empty(), ERR_CF, has_hotkey_command(), has_hotkey_item(), HOTKEY_WML, 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 502 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 375 of file hotkey_item.cpp.
Referenced by gui2::tpreferences::default_hotkey_callback(), gui2::tpreferences::remove_hotkey_callback(), and hotkey::manager::wipe().
void hotkey::clear_hotkeys | ( | ) |
Unset the bindings for all hotkeys.
Definition at line 388 of file hotkey_item.cpp.
hotkey_ptr hotkey::create_hotkey | ( | const std::string & | id, |
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 158 of file hotkey_item.cpp.
References ERR_G, and sdl_get_mods().
Referenced by show_binding_dialog().
void hotkey::deactivate_all_scopes | ( | ) |
Definition at line 294 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 347 of file hotkey_item.cpp.
References schema_validation::remove.
void hotkey::delete_all_wml_hotkeys | ( | ) |
deletes all wml hotkeys, should be called after a game has ended
Definition at line 464 of file hotkey_command.cpp.
References HOTKEY_WML.
Referenced by hotkey::manager::wipe(), and play_controller::~play_controller().
|
static |
Definition at line 549 of file command_executor.cpp.
References execute_command(), get_hotkey(), get_hotkey_command(), and hotkey::command_executor::set_button_state().
Referenced by hotkey::basic_handler::handle_event(), jbutton_event(), jhat_event(), key_event(), and mbutton_event().
void hotkey::execute_command | ( | const hotkey_command & | command, |
command_executor * | executor, | ||
int | index, | ||
bool | press | ||
) |
Definition at line 563 of file command_executor.cpp.
References _(), preferences::animate_map(), hotkey::command_executor::can_execute_command(), DBG_G, preferences::enable_mouse_scroll(), hotkey::command_executor::execute_command(), preferences::fullscreen(), hotkey::command_executor::get_video(), HOTKEY_ANIMATE_MAP, HOTKEY_FULLSCREEN, HOTKEY_MINIMAP_CODING_TERRAIN, HOTKEY_MINIMAP_CODING_UNIT, HOTKEY_MINIMAP_DRAW_TERRAIN, HOTKEY_MINIMAP_DRAW_UNITS, HOTKEY_MINIMAP_DRAW_VILLAGES, HOTKEY_MOUSE_SCROLL, HOTKEY_MUTE, HOTKEY_SCREENSHOT, hotkey::hotkey_command::id, preferences::mouse_scroll_enabled(), preferences::music_on(), hotkey::command_executor::recalculate_minimap(), preferences::set_animate_map(), CVideo::set_fullscreen(), preferences::set_music(), preferences::set_sound(), preferences::sound_on(), preferences::toggle_minimap_draw_terrain(), preferences::toggle_minimap_draw_units(), preferences::toggle_minimap_draw_villages(), preferences::toggle_minimap_movement_coding(), and preferences::toggle_minimap_terrain_coding().
Referenced by event_execute(), hotkey::command_executor::execute_action(), controller_base::handle_event(), and hotkey::command_executor::show_menu().
const std::string & hotkey::get_description | ( | const std::string & | command | ) |
Definition at line 477 of file hotkey_command.cpp.
References hotkey::hotkey_command::description, and get_hotkey_command().
Referenced by gui2::tpreferences::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 393 of file hotkey_item.cpp.
Referenced by gui2::event::thandler::button_down(), event_execute(), gui2::event::thandler::hat_motion(), gui2::event::thandler::key_down(), and wb::manager::print_help_once().
const hotkey_command & hotkey::get_hotkey_command | ( | const std::string & | command | ) |
returns the hotkey_command with the given name
Definition at line 318 of file hotkey_command.cpp.
References get_hotkey_null().
Referenced by add_hotkey(), hotkey::hotkey_base::bindings_equal(), event_execute(), hotkey::command_executor::execute_action(), controller_base::execute_action(), get_description(), get_id(), get_tooltip(), has_hotkey_command(), hotkey::hotkey_base::matches(), 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 boost::ptr_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 328 of file hotkey_command.cpp.
Referenced by gui2::tpreferences::setup_hotkey_list().
const hotkey_command & hotkey::get_hotkey_null | ( | ) |
returns the hotkey_command that is treated as null.
Definition at line 458 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 433 of file hotkey_item.cpp.
References hotkeys_.
Referenced by gui2::tpreferences::add_hotkey_callback().
HOTKEY_COMMAND hotkey::get_id | ( | const std::string & | command | ) |
returns get_hotkey_command(command).id
Definition at line 506 of file hotkey_command.cpp.
References get_hotkey_command(), and hotkey::hotkey_command::id.
Referenced by editor::editor_palette< Item >::draw_contents(), hotkey::command_executor::get_menu_image(), hotkey::command_executor::get_menu_images(), gui2::event::thandler::hotkey_pressed(), editor::editor_toolkit::init_mouse_actions(), and events::pump().
std::string hotkey::get_names | ( | 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 450 of file hotkey_item.cpp.
References utils::join().
Referenced by gui2::tpreferences::add_hotkey_callback(), hotkey::command_executor::get_menu_images(), theme::menu::menu(), gui2::tpreferences::remove_hotkey_callback(), gui2::tpreferences::setup_hotkey_list(), gui2::tcontrol::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 482 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 369 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 325 of file hotkey_item.cpp.
Referenced by add_wml_hotkey().
void hotkey::init_hotkey_commands | ( | ) |
Definition at line 488 of file hotkey_command.cpp.
References i.
Referenced by hotkey::manager::init().
bool hotkey::is_scope_active | ( | hk_scopes | s | ) |
Definition at line 310 of file hotkey_command.cpp.
Referenced by help::description_type(), and hotkey::hotkey_base::matches().
void hotkey::jbutton_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 533 of file command_executor.cpp.
References event_execute().
Referenced by controller_base::handle_event(), and hotkey::basic_handler::handle_event().
void hotkey::jhat_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 538 of file command_executor.cpp.
References event_execute().
Referenced by controller_base::handle_event().
void hotkey::key_event | ( | const SDL_Event & | event, |
command_executor * | executor | ||
) |
Definition at line 543 of file command_executor.cpp.
References event_execute().
Referenced by controller_base::handle_event(), and hotkey::basic_handler::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 191 of file hotkey_item.cpp.
References ERR_G.
Referenced by add_wml_hotkey(), and load_hotkeys().
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 403 of file hotkey_item.cpp.
References add_hotkey(), config::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 528 of file command_executor.cpp.
References event_execute().
Referenced by controller_base::handle_event(), and hotkey::basic_handler::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 335 of file hotkey_command.cpp.
References get_hotkey_command(), HOTKEY_NULL, HOTKEY_WML, hotkey::hotkey_command::id, itor, 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 422 of file hotkey_item.cpp.
References config::empty(), ERR_G, and load_hotkeys().
Referenced by preferences::clear_hotkeys().
Save the non-default hotkeys to the config.
cfg | The config to save to. |
Definition at line 438 of file hotkey_item.cpp.
References config::add_child(), and config::clear_children().
Referenced by gui2::tpreferences::post_show(), and preferences::save_hotkeys().
|
static |
Definition at line 48 of file hotkey_item.cpp.
Referenced by create_hotkey(), and hotkey::hotkey_base::matches().
void hotkey::set_active_scopes | ( | hk_scopes | s | ) |
Definition at line 305 of file hotkey_command.cpp.
Referenced by add_hotkey(), and gui2::tpreferences::add_hotkey_callback().
void hotkey::set_scope_active | ( | scope | s, |
bool | set | ||
) |
Definition at line 301 of file hotkey_command.cpp.
References cursor::set().
Referenced by test_utils::game_config_manager::game_config_manager(), game_config_manager::init_game_config(), play_controller::play_controller(), and editor::start().
hotkey::hotkey_ptr hotkey::show_binding_dialog | ( | CVideo & | video, |
const std::string & | id | ||
) |
Definition at line 31 of file hotkey_preferences_display.cpp.
References _(), create_hotkey(), sdl::create_rect(), gui::dialog_frame::draw_background(), gui::dialog_frame::draw_border(), font::draw_text(), CVideo::flip(), CVideo::getx(), CVideo::gety(), gui::dialog_frame::layout(), font::NORMAL_COLOR, events::peek_for_resize(), surface_restorer::restore(), and font::SIZE_LARGE.
Referenced by gui2::tpreferences::add_hotkey_callback().
config hotkey::default_hotkey_cfg_ |
Definition at line 46 of file hotkey_item.cpp.
hotkey_list hotkey::hotkeys_ |
Definition at line 45 of file hotkey_item.cpp.
Referenced by get_hotkeys().