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 {
199 {
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.") },
200 {
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.") },
201 {
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.") },
202 {
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.") },
308 const std::set<HOTKEY_COMMAND> toggle_commands {
316 std::map<std::string_view, hotkey::hotkey_command> registered_hotkeys;
322 : prev_scope_active_(scope_active)
331 scope_active = new_scopes;
345 return scope_active[
s];
358 return registered_hotkeys.at(command);
359 }
catch(
const std::out_of_range&) {
366 return registered_hotkeys;
378 LOG_G <<
"Couldn't add wml hotkey with null id and description = '" << description <<
"'.";
382 const auto& [iter, inserted] = registered_hotkeys.try_emplace(
386 DBG_G <<
"Added wml hotkey with id = '" <<
id <<
"' and description = '" << description <<
"'.";
388 LOG_G <<
"Hotkey with id '" <<
id <<
"' already exists.";
394 new_item->set_command(
id);
396 if(new_item->valid()) {
397 DBG_G <<
"added default description for the wml hotkey with id=" +
id;
400 ERR_CF <<
"failed to add default hotkey with id=" +
id;
405 cleanup_ = [
i = iter] { registered_hotkeys.erase(
i); };
416 : command(temp_command.command)
417 ,
id(temp_command.
id)
418 , description(
std::string(temp_command.description),
"wesnoth-lib")
419 , hidden(temp_command.hidden)
420 , toggle(toggle_commands.count(temp_command.command) > 0)
422 , category(temp_command.category)
428 const std::string& id_,
448 return registered_hotkeys.at(
"null");
460 ERR_G <<
"the hotkey command seems to be the null command but it is not 100% sure. This shouldn't happen";
470 for(
auto& [
id, cmd] : registered_hotkeys) {
471 if(cmd.command == command) {
476 ERR_G <<
"No hotkey with requested command '" << command <<
"' found. Returning null hotkey.";
482 registered_hotkeys.clear();
486 registered_hotkeys.try_emplace(cmd.id, cmd);
492 return category_names;
static lg::log_domain log_config("config")
hotkey_ptr load_from_config(const config &cfg)
Create and instantiate a hotkey from a config element.
bool is_scope_active(scope s)
scope
Available hotkey scopes.
const std::map< HOTKEY_CATEGORY, std::string > & get_category_names()
Returns the map of hotkey categories and their display names.
static const hotkey_command & null_command()
returns the command that is treated as null
Stores all information related to functions that can be bound to hotkeys.
bool has_hotkey_item(const std::string &command)
HOTKEY_COMMAND command
The command associated with this hotkey.
std::string id
The unique ID.
bool null() const
checks weather this is the null hotkey_command
Definitions for the interface to Wesnoth Markup Language (WML).
std::string_view description
Keyboard shortcuts for game actions.
wml_hotkey_record()=default
constexpr uint32_t scope_main
constexpr uint32_t scope_editor
const std::map< std::string_view, hotkey::hotkey_command > & get_hotkey_commands()
returns a container that contains all currently active hotkey_commands.
std::bitset< SCOPE_COUNT > hk_scopes
std::shared_ptr< class hotkey_base > hotkey_ptr
void init_hotkey_commands()
constexpr uint32_t scope_game
hk_scopes scope
The visibility scope of the command.
std::function< void()> cleanup_
Handles removing the associated hotkey_command on this object's destruction.
std::string id
Text to match against addon_info.tags()
bool toggle
Toggle hotkeys have some restrictions on what can be bound to them.
static map_location::DIRECTION s
void add_hotkey(hotkey_ptr item)
Add a hotkey to the list of hotkeys.
hk_scopes prev_scope_active_
bool has_hotkey_command(const std::string &id)
Standard logging facilities (interface).
bool hidden
If hidden then don't show the command in the hotkey preferences.
A config object defines a single node in a WML file, with access to child nodes.
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
HOTKEY_CATEGORY category
The category of the command.
std::string tooltip
Shown when hovering over an entry in the filter's drop-down list.
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...