16 #define GETTEXT_DOMAIN "wesnoth-lib"
27 #include <string_view>
30 #define ERR_G LOG_STREAM(err, lg::general())
31 #define LOG_G LOG_STREAM(info, lg::general())
32 #define DBG_G LOG_STREAM(debug, lg::general())
33 #define ERR_CF LOG_STREAM(err, log_config)
50 const std::map<HOTKEY_CATEGORY, std::string> category_names {
73 constexpr std::array<hotkey_command_temp,
HOTKEY_NULL - 1> master_hotkey_list {{
203 {
HOTKEY_EDITOR_TOOL_PAINT,
"editor-tool-paint",
N_(
"Paint Tool"),
false,
scope_editor,
HKCAT_TOOLS,
N_(
"Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor.") },
204 {
HOTKEY_EDITOR_TOOL_FILL,
"editor-tool-fill",
N_(
"Fill Tool"),
false,
scope_editor,
HKCAT_TOOLS,
N_(
"Use left/right mouse button to draw fore-/background terrain. Hold Shift to paint base layer only. Ctrl+click to sample terrain under cursor.") },
205 {
HOTKEY_EDITOR_TOOL_SELECT,
"editor-tool-select",
N_(
"Selection Tool"),
false,
scope_editor,
HKCAT_TOOLS,
N_(
"Left mouse button selects or deselects with Ctrl, right brings up a context menu. Hold Shift for magic-wand selection of tiles with same terrain.") },
206 {
HOTKEY_EDITOR_TOOL_STARTING_POSITION,
"editor-tool-starting-position",
N_(
"Starting Positions Tool"),
false,
scope_editor,
HKCAT_TOOLS,
N_(
"Left mouse button displays player selection, right clears. Number keys scroll to the starting position, alt+number sets respective starting position under cursor, delete clears.") },
320 const std::set<HOTKEY_COMMAND> toggle_commands {
328 std::map<std::string_view, hotkey::hotkey_command> registered_hotkeys;
334 : prev_scope_active_(scope_active)
340 : prev_scope_active_(scope_active)
343 scope_active = new_scopes;
357 return scope_active[
s];
370 return registered_hotkeys.at(command);
371 }
catch(
const std::out_of_range&) {
378 return registered_hotkeys;
390 LOG_G <<
"Couldn't add wml hotkey with null id and description = '" << description <<
"'.";
394 const auto& [iter, inserted] = registered_hotkeys.try_emplace(
398 DBG_G <<
"Added wml hotkey with id = '" <<
id <<
"' and description = '" << description <<
"'.";
400 LOG_G <<
"Hotkey with id '" <<
id <<
"' already exists.";
406 new_item->set_command(
id);
408 if(new_item->valid()) {
409 DBG_G <<
"added default description for the wml hotkey with id=" +
id;
412 ERR_CF <<
"failed to add default hotkey with id=" +
id;
417 cleanup_ = [
id] { registered_hotkeys.erase(
id); };
428 : command(temp_command.command)
429 ,
id(temp_command.
id)
430 , description(std::string(temp_command.description),
"wesnoth-lib")
431 , hidden(temp_command.hidden)
432 , toggle(toggle_commands.count(temp_command.command) > 0)
434 , category(temp_command.category)
440 const std::string& id_,
460 return registered_hotkeys.at(
"null");
472 ERR_G <<
"the hotkey command seems to be the null command but it is not 100% sure. This shouldn't happen";
482 for(
auto& [
id, cmd] : registered_hotkeys) {
488 ERR_G <<
"No hotkey with requested command '" <<
command <<
"' found. Returning null hotkey.";
494 registered_hotkeys.clear();
498 registered_hotkeys.try_emplace(cmd.id, cmd);
504 return {category_names.at(category),
"wesnoth-lib"};
A config object defines a single node in a WML file, with access to child nodes.
hk_scopes prev_scope_active_
wml_hotkey_record(const wml_hotkey_record &)=delete
Don't allow copying so objects don't get erased early.
std::function< void()> cleanup_
Handles removing the associated hotkey_command on this object's destruction.
Definitions for the interface to Wesnoth Markup Language (WML).
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
std::string id
Text to match against addon_info.tags()
static lg::log_domain log_config("config")
Standard logging facilities (interface).
Keyboard shortcuts for game actions.
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
bool has_hotkey_command(const std::string &id)
std::shared_ptr< class hotkey_base > hotkey_ptr
constexpr uint32_t scope_game
bool has_hotkey_item(const std::string &command)
void init_hotkey_commands()
const std::map< std::string_view, hotkey::hotkey_command > & get_hotkey_commands()
returns a container that contains all currently active hotkey_commands.
hotkey_ptr load_from_config(const config &cfg)
Create and instantiate a hotkey from a config element.
std::bitset< SCOPE_COUNT > hk_scopes
bool is_scope_active(scope s)
scope
Available hotkey scopes.
constexpr uint32_t scope_main
void add_hotkey(hotkey_ptr item)
Add a hotkey to the list of hotkeys.
t_string get_translatable_category_name(HOTKEY_CATEGORY category)
Gets the display name for a given hotkey category.
constexpr uint32_t scope_editor
@ HOTKEY_EDITOR_TOOL_VILLAGE
@ HOTKEY_MINIMAP_DRAW_VILLAGES
@ HOTKEY_EDITOR_BRUSH_NW_SE
@ HOTKEY_EDITOR_SELECT_NONE
@ HOTKEY_EDITOR_CLIPBOARD_ROTATE_CCW
@ HOTKEY_EDITOR_PALETTE_GROUPS
@ HOTKEY_TERRAIN_DESCRIPTION
@ HOTKEY_EDITOR_PALETTE_UPSCROLL
@ HOTKEY_EDITOR_PALETTE_ITEMS_CLEAR
@ HOTKEY_EDITOR_SIDE_REMOVE
@ HOTKEY_WB_EXECUTE_ALL_ACTIONS
@ HOTKEY_EDITOR_BRUSH_NEXT
@ HOTKEY_HELP_ABOUT_SAVELOAD
@ HOTKEY_EDITOR_TOOL_LABEL
@ HOTKEY_EDITOR_CLIPBOARD_ROTATE_CW
@ HOTKEY_EDITOR_CLIPBOARD_PASTE
@ HOTKEY_EDITOR_PARTIAL_UNDO
@ HOTKEY_EDITOR_UNIT_TOGGLE_CANRECRUIT
@ HOTKEY_EDITOR_PALETTE_ITEM_SWAP
@ HOTKEY_EDITOR_TOOL_PAINT
@ HOTKEY_EDITOR_MAP_CLOSE
@ HOTKEY_EDITOR_MAP_GENERATE
@ HOTKEY_SHOW_ENEMY_MOVES
@ HOTKEY_EDITOR_SELECTION_FLIP
@ HOTKEY_EDITOR_TOOL_FILL
@ TITLE_SCREEN__MULTIPLAYER
@ HOTKEY_EDITOR_SCENARIO_SAVE_AS
@ HOTKEY_EDITOR_MAP_SAVE_AS
@ HOTKEY_UNIT_DESCRIPTION
@ HOTKEY_EDITOR_SELECT_ALL
@ HOTKEY_LABEL_TEAM_TERRAIN
@ HOTKEY_EDITOR_DRAW_COORDINATES
@ HOTKEY_UNIT_HOLD_POSITION
@ HOTKEY_EDITOR_TOOL_NEXT
@ HOTKEY_EDITOR_SELECTION_EXPORT
@ HOTKEY_EDITOR_PARTIAL_UPDATE_TRANSITIONS
@ HOTKEY_EDITOR_MAP_CREATE_MASK_TO
@ HOTKEY_REPLAY_NEXT_TURN
@ HOTKEY_EDITOR_SELECTION_CUT
@ HOTKEY_EDITOR_UNIT_CHANGE_ID
@ HOTKEY_SELECT_AND_ACTION
@ HOTKEY_REPLAY_SHOW_EVERYTHING
@ HOTKEY_REPLAY_SHOW_TEAM1
@ HOTKEY_MINIMAP_DRAW_TERRAIN
@ HOTKEY_EDITOR_DRAW_NUM_OF_BITMAPS
@ HOTKEY_EDITOR_BRUSH_SW_NE
@ HOTKEY_EDITOR_TOOL_UNIT
@ HOTKEY_EDITOR_BRUSH_DEFAULT
@ HOTKEY_BEST_ENEMY_MOVES
@ HOTKEY_EDITOR_HELP_TEXT_SHOWN
@ HOTKEY_EDITOR_CHANGE_ADDON_ID
@ HOTKEY_EDITOR_CUSTOM_TODS
@ HOTKEY_EDITOR_REFRESH_IMAGE_CACHE
@ HOTKEY_EDITOR_SELECTION_FILL
@ HOTKEY_EDITOR_CLIPBOARD_FLIP_VERTICAL
@ HOTKEY_EDITOR_MAP_SAVE_ALL
@ HOTKEY_EDITOR_SELECTION_ROTATE
@ HOTKEY_EDITOR_TOOL_STARTING_POSITION
@ HOTKEY_MINIMAP_CODING_TERRAIN
@ HOTKEY_EDITOR_NO_UPDATE_TRANSITIONS
@ HOTKEY_WB_EXECUTE_ACTION
@ HOTKEY_EDITOR_SELECTION_COPY
@ HOTKEY_MINIMAP_DRAW_UNITS
@ HOTKEY_EDITOR_PALETTE_DOWNSCROLL
@ HOTKEY_EDITOR_UNIT_TOGGLE_LOYAL
@ TITLE_SCREEN__PREVIOUS_TIP
@ HOTKEY_WB_BUMP_UP_ACTION
@ HOTKEY_EDITOR_MAP_APPLY_MASK
@ HOTKEY_EDITOR_LOCAL_TIME
@ HOTKEY_EDITOR_UNIT_FACING
@ HOTKEY_REPLAY_NEXT_SIDE
@ HOTKEY_REPLAY_NEXT_MOVE
@ HOTKEY_EDITOR_EDIT_UNIT
@ HOTKEY_EDITOR_SELECTION_RANDOMIZE
@ HOTKEY_EDITOR_SCENARIO_NEW
@ HOTKEY_EDITOR_MAP_SWITCH
@ HOTKEY_EDITOR_SELECT_INVERSE
@ HOTKEY_EDITOR_TOGGLE_TRANSITIONS
@ HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS
@ HOTKEY_REPLAY_SKIP_ANIMATION
@ HOTKEY_WB_BUMP_DOWN_ACTION
@ HOTKEY_EDITOR_AREA_RENAME
@ HOTKEY_EDITOR_MAP_RESIZE
@ HOTKEY_EDITOR_DRAW_TERRAIN_CODES
@ HOTKEY_EDITOR_AREA_REMOVE
@ HOTKEY_EDITOR_UPDATE_TRANSITIONS
@ HOTKEY_EDITOR_TOOL_SELECT
@ HOTKEY_EDITOR_AREA_SAVE
@ HOTKEY_EDITOR_REMOVE_LOCATION
@ HOTKEY_EDITOR_SIDE_EDIT
@ HOTKEY_EDITOR_SELECT_ADDON
@ HOTKEY_EDITOR_TOOL_ITEM
@ TITLE_SCREEN__RELOAD_WML
@ HOTKEY_REPLAY_SHOW_EACH
@ HOTKEY_CYCLE_BACK_UNITS
@ HOTKEY_EDITOR_UNIT_TOGGLE_RENAMEABLE
@ HOTKEY_EDITOR_SCENARIO_EDIT
@ HOTKEY_EDITOR_OPEN_ADDON
@ HOTKEY_EDITOR_MAP_REVERT
@ HOTKEY_WB_DELETE_ACTION
@ HOTKEY_EDITOR_CLIPBOARD_FLIP_HORIZONTAL
@ HOTKEY_MINIMAP_CODING_UNIT
std::string_view description
Stores all information related to functions that can be bound to hotkeys.
HOTKEY_COMMAND command
The command associated with this hotkey.
std::string id
The unique ID.
hk_scopes scope
The visibility scope of the command.
static const hotkey_command & null_command()
returns the command that is treated as null
bool null() const
checks weather this is the null hotkey_command
static const hotkey_command & get_command_by_command(HOTKEY_COMMAND command)
the execute_command argument was changed from HOTKEY_COMMAND to hotkey_command, to be able to call it...
static map_location::direction s