The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
hotkey_command.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY.
11 
12  See the COPYING file for more details.
13 */
14 
15 #define GETTEXT_DOMAIN "wesnoth-lib"
16 
17 #include "gettext.hpp"
18 #include "hotkey_command.hpp"
19 #include "hotkey_item.hpp"
20 #include "config.hpp"
21 #include "preferences.hpp"
22 #include "log.hpp"
23 
24 static lg::log_domain log_config("config");
25 #define ERR_G LOG_STREAM(err, lg::general())
26 #define LOG_G LOG_STREAM(info, lg::general())
27 #define DBG_G LOG_STREAM(debug, lg::general())
28 #define ERR_CF LOG_STREAM(err, log_config)
29 
30 
31 namespace {
32  //make them global ?
33  hotkey::hk_scopes scope_game(1 << hotkey::SCOPE_GAME);
34  hotkey::hk_scopes scope_editor(1 << hotkey::SCOPE_EDITOR);
36 // this contains all static hotkeys
37 hotkey::hotkey_command_temp hotkey_list_[] = {
38  { hotkey::HOTKEY_SCROLL_UP, "scroll-up", N_("Scroll Up"), false, scope_game | scope_editor, "" },
39  { hotkey::HOTKEY_SCROLL_DOWN, "scroll-down", N_("Scroll Down"), false, scope_game | scope_editor, "" },
40  { hotkey::HOTKEY_SCROLL_LEFT, "scroll-left", N_("Scroll Left"), false, scope_game | scope_editor, "" },
41  { hotkey::HOTKEY_SCROLL_RIGHT, "scroll-right", N_("Scroll Right"), false, scope_game | scope_editor, "" },
42 
43  { hotkey::HOTKEY_CANCEL, N_("cancel"), N_("Cancel"), false, scope_game | scope_editor | scope_main, "" },
44  { hotkey::HOTKEY_SELECT_HEX, "selecthex", N_("Select Hex"), false, scope_game, "" },
45  { hotkey::HOTKEY_DESELECT_HEX, "deselecthex", N_("Deselect Hex"), false, scope_game, "" },
46  { hotkey::HOTKEY_MOVE_ACTION, "moveaction", N_("Move/Attack"), false, scope_game, "" },
47  { hotkey::HOTKEY_SELECT_AND_ACTION, "selectmoveaction", N_("Select/Move/Attack"), false, scope_game, "" },
48  { hotkey::HOTKEY_ANIMATE_MAP, "animatemap", N_("Animate Map"), false, scope_game | scope_editor | scope_main, "" },
49  { hotkey::HOTKEY_CYCLE_UNITS, "cycle", N_("Next Unit"), false, scope_game, "" },
50  { hotkey::HOTKEY_CYCLE_BACK_UNITS, "cycleback", N_("Previous Unit"), false, scope_game, "" },
51  { hotkey::HOTKEY_UNIT_HOLD_POSITION, "holdposition", N_("Hold Position"), false, scope_game, "" },
52  { hotkey::HOTKEY_END_UNIT_TURN, "endunitturn", N_("End Unit Turn"), false, scope_game, "" },
53  { hotkey::HOTKEY_LEADER, "leader", N_("Leader"), false, scope_game, "" },
54  { hotkey::HOTKEY_UNDO, "undo", N_("Undo"), false, scope_game | scope_editor, "" },
55  { hotkey::HOTKEY_REDO, "redo", N_("Redo"), false, scope_game | scope_editor, "" },
56  { hotkey::HOTKEY_ZOOM_IN, "zoomin", N_("Zoom In"), false, scope_game | scope_editor | scope_main, "" },
57  { hotkey::HOTKEY_ZOOM_OUT, "zoomout", N_("Zoom Out"), false, scope_game | scope_editor | scope_main, "" },
58  { hotkey::HOTKEY_ZOOM_DEFAULT, "zoomdefault", N_("Default Zoom"), false, scope_game | scope_editor | scope_main, "" },
59  { hotkey::HOTKEY_FULLSCREEN, "fullscreen", N_("Toggle Full Screen"), false, scope_game | scope_editor | scope_main, "" },
60  { hotkey::HOTKEY_SCREENSHOT, "screenshot", N_("Screenshot"), false, scope_game | scope_editor | scope_main, "" },
61  { hotkey::HOTKEY_MAP_SCREENSHOT, "mapscreenshot", N_("Map Screenshot"), false, scope_game | scope_editor, "" },
62  { hotkey::HOTKEY_ACCELERATED, "accelerated", N_("Accelerated"), false, scope_game, "" },
63  { hotkey::HOTKEY_TERRAIN_DESCRIPTION, "describeterrain", N_("Terrain Description"), false, scope_game | scope_editor, "" },
64  { hotkey::HOTKEY_UNIT_DESCRIPTION, "describeunit", N_("Unit Description"), false, scope_game | scope_editor, "" },
65  { hotkey::HOTKEY_RENAME_UNIT, "renameunit", N_("Rename Unit"), false, scope_game | scope_editor, "" },
66  { hotkey::HOTKEY_DELETE_UNIT, "editor-deleteunit", N_("Delete Unit"), false, scope_game | scope_editor, "" },
67 
68  { hotkey::HOTKEY_SAVE_GAME, "save", N_("Save Game"), false, scope_game, "" },
69  { hotkey::HOTKEY_SAVE_REPLAY, "savereplay", N_("Save Replay"), false, scope_game, "" },
70  { hotkey::HOTKEY_SAVE_MAP, "savemap", N_("Save Map"), false, scope_game, "" },
71  { hotkey::HOTKEY_LOAD_GAME, "load", N_("Load Game"), false, scope_game | scope_main, "" },
72  { hotkey::HOTKEY_RECRUIT, "recruit", N_("Recruit"), false, scope_game, "" },
73  { hotkey::HOTKEY_REPEAT_RECRUIT, "repeatrecruit", N_("Repeat Recruit"), false, scope_game, "" },
74  { hotkey::HOTKEY_RECALL, "recall", N_("Recall"), false, scope_game, "" },
75  { hotkey::HOTKEY_LABEL_SETTINGS, "label_settings", N_("Show/Hide Labels"), false, scope_game, "" },
76  { hotkey::HOTKEY_ENDTURN, "endturn", N_("End Turn"), false, scope_game, "" },
77  //TODO: why has HOTKEY_TOGGLE_ELLIPSES more than scope_game ?
78  { hotkey::HOTKEY_TOGGLE_ELLIPSES, "toggleellipses", N_("Toggle Ellipses"), false, scope_game | scope_editor | scope_main, "" },
79  { hotkey::HOTKEY_TOGGLE_GRID, "togglegrid", N_("Toggle Grid"), false, scope_game | scope_editor, "" },
80  { hotkey::HOTKEY_MOUSE_SCROLL, "mousescroll", N_("Mouse Scrolling"), false, scope_game | scope_editor | scope_main, "" },
81  { hotkey::HOTKEY_STATUS_TABLE, "statustable", N_("Status Table"), false, scope_game, "" },
82  { hotkey::HOTKEY_MUTE, "mute", N_("Mute"), false, scope_game | scope_editor | scope_main, "" },
83  { hotkey::HOTKEY_SPEAK, "speak", N_("Speak"), false, scope_game, "" },
84  { hotkey::HOTKEY_CREATE_UNIT, "createunit", N_("Create Unit (Debug!)"), false, scope_game, "" },
85  { hotkey::HOTKEY_CHANGE_SIDE, "changeside", N_("Change Side (Debug!)"), false, scope_game, "" },
86  { hotkey::HOTKEY_KILL_UNIT, "killunit", N_("Kill Unit (Debug!)"), false, scope_game, "" },
87  { hotkey::HOTKEY_PREFERENCES, "preferences", N_("Preferences"), false, scope_game | scope_editor | scope_main, "" },
88  { hotkey::HOTKEY_OBJECTIVES, "objectives", N_("Scenario Objectives"), false, scope_game, "" },
89  { hotkey::HOTKEY_UNIT_LIST, "unitlist", N_("Unit List"), false, scope_game | scope_editor, "" },
90  { hotkey::HOTKEY_STATISTICS, "statistics", N_("Statistics"), false, scope_game, "" },
91  { hotkey::HOTKEY_STOP_NETWORK, "stopnetwork", N_("Pause Network Game"), false, scope_game, "" },
92  { hotkey::HOTKEY_START_NETWORK, "startnetwork", N_("Continue Network Game"), false, scope_game, "" },
93  { hotkey::HOTKEY_QUIT_GAME, "quit", N_("Quit to Titlescreen"), false, scope_game | scope_editor, "" },
94  { hotkey::HOTKEY_LABEL_TEAM_TERRAIN, "labelteamterrain", N_("Set Team Label"), false, scope_game, "" },
95  { hotkey::HOTKEY_LABEL_TERRAIN, "labelterrain", N_("Set Label"), false, scope_game, "" },
96  { hotkey::HOTKEY_CLEAR_LABELS, "clearlabels", N_("Clear Labels"), false, scope_game, "" },
97  { hotkey::HOTKEY_SHOW_ENEMY_MOVES, "showenemymoves", N_("Show Enemy Moves"), false, scope_game, "" },
98  { hotkey::HOTKEY_BEST_ENEMY_MOVES, "bestenemymoves", N_("Best Possible Enemy Moves"), false, scope_game, "" },
99 
100  { hotkey::HOTKEY_REPLAY_PLAY, "playreplay", N_("Play Replay"), false, scope_game, "" },
101  { hotkey::HOTKEY_REPLAY_RESET, "resetreplay", N_("Reset Replay"), false, scope_game, "" },
102  { hotkey::HOTKEY_REPLAY_STOP, "stopreplay", N_("Stop Replay"), false, scope_game, "" },
103  { hotkey::HOTKEY_REPLAY_NEXT_TURN, "replaynextturn", N_("Next Turn"), false, scope_game, "" },
104  { hotkey::HOTKEY_REPLAY_NEXT_SIDE, "replaynextside", N_("Next Side"), false, scope_game, "" },
105  { hotkey::HOTKEY_REPLAY_NEXT_MOVE, "replaynextmove", N_("Next Move"), false, scope_game, "" },
106  { hotkey::HOTKEY_REPLAY_SHOW_EVERYTHING, "replayshoweverything", N_("Full Map"), false, scope_game, "" },
107  { hotkey::HOTKEY_REPLAY_SHOW_EACH, "replayshoweach", N_("Each Team"), false, scope_game, "" },
108  { hotkey::HOTKEY_REPLAY_SHOW_TEAM1, "replayshowteam1", N_("Human Team"), false, scope_game, "" },
109  { hotkey::HOTKEY_REPLAY_SKIP_ANIMATION, "replayskipanimation", N_("Skip Animation"), false, scope_game, "" },
110  { hotkey::HOTKEY_REPLAY_EXIT, "replayexit", N_("End Replay"), false, scope_game, "" },
111  // Whiteboard commands
112  // TRANSLATORS: whiteboard menu entry: toggle planning mode
113  { hotkey::HOTKEY_WB_TOGGLE, "wbtoggle", N_("whiteboard^Planning Mode"), false, scope_game, "" },
114  // TRANSLATORS: whiteboard menu entry: execute planned action
115  { hotkey::HOTKEY_WB_EXECUTE_ACTION, "wbexecuteaction", N_("whiteboard^Execute Action"), false, scope_game, "" },
116  // TRANSLATORS: whiteboard menu entry: execute all planned actions
117  { hotkey::HOTKEY_WB_EXECUTE_ALL_ACTIONS, "wbexecuteallactions", N_("whiteboard^Execute All Actions"), false, scope_game, "" },
118  // TRANSLATORS: whiteboard menu entry: delete planned action
119  { hotkey::HOTKEY_WB_DELETE_ACTION, "wbdeleteaction", N_("whiteboard^Delete Action"), false, scope_game, "" },
120  // TRANSLATORS: whiteboard menu entry: move planned action up queue
121  { hotkey::HOTKEY_WB_BUMP_UP_ACTION, "wbbumpupaction", N_("whiteboard^Move Action Up"), false, scope_game, "" },
122  // TRANSLATORS: whiteboard menu entry: move planned action down queue
123  { hotkey::HOTKEY_WB_BUMP_DOWN_ACTION, "wbbumpdownaction", N_("whiteboard^Move Action Down"), false, scope_game, "" },
124  // TRANSLATORS: whiteboard menu entry: plan as though the chosen unit were dead
125  { hotkey::HOTKEY_WB_SUPPOSE_DEAD, "wbsupposedead", N_("whiteboard^Suppose Dead"), false, scope_game, "" },
126 
127  { hotkey::HOTKEY_QUIT_TO_DESKTOP, "quit-to-desktop", N_("Quit to Desktop"), false, scope_game | scope_editor | scope_main, "" },
128  { hotkey::HOTKEY_EDITOR_MAP_CLOSE, "editor-close-map", N_("Close Map"), false, scope_editor, "" },
129 
130  // These are not really hotkey items but menu entries to get expanded.
131  // They need to have their own hotkey to control their active state.
132  { hotkey::HOTKEY_EDITOR_PLAYLIST, "editor-playlist", N_("Switch Time of Day"), true, scope_editor, "" },
133  { hotkey::HOTKEY_EDITOR_SCHEDULE, "menu-editor-schedule", "", true, hotkey::SCOPE_EDITOR, "" },
134  { hotkey::HOTKEY_EDITOR_MAP_SWITCH, "editor-switch-map", N_("Switch Map"), true, scope_editor, "" },
135  { hotkey::HOTKEY_EDITOR_LOCAL_TIME, "menu-editor-local-time", N_("Assign Local Time"), true, scope_editor, "" },
136 
137  { hotkey::HOTKEY_EDITOR_CUSTOM_TODS, "editor-custom-tods", N_("Time Schedule Editor"), false, scope_editor, "" },
138  { hotkey::HOTKEY_EDITOR_PARTIAL_UNDO, "editor-partial-undo", N_("Partial Undo"), false, scope_editor, "" },
139  { hotkey::HOTKEY_EDITOR_MAP_NEW, "editor-map-new", N_("New Map"), false, scope_editor, "" },
140  { hotkey::HOTKEY_EDITOR_SCENARIO_NEW, "editor-scenario-new", N_("New Scenario"), false, scope_editor, "" },
141  { hotkey::HOTKEY_EDITOR_MAP_LOAD, "editor-map-load", N_("Load Map"), false, scope_editor, "" },
142  { hotkey::HOTKEY_EDITOR_MAP_SAVE, "editor-map-save", N_("Save Map"), false, scope_editor, "" },
143  { hotkey::HOTKEY_EDITOR_MAP_SAVE_AS, "editor-map-save-as", N_("Save Map As"), false, scope_editor, "" },
144  { hotkey::HOTKEY_EDITOR_SCENARIO_SAVE_AS, "editor-scenario-save-as", N_("Save Scenario As"), false, scope_editor, "" },
145  { hotkey::HOTKEY_EDITOR_MAP_SAVE_ALL, "editor-map-save-all", N_("Save All Maps"), false, scope_editor, "" },
146  { hotkey::HOTKEY_EDITOR_MAP_REVERT, "editor-map-revert", N_("Revert All Changes"), false, scope_editor, "" },
147  { hotkey::HOTKEY_EDITOR_MAP_INFO, "editor-map-info", N_("Map Information"), false, scope_editor, "" },
148 
149  { hotkey::HOTKEY_EDITOR_PALETTE_ITEMS_CLEAR, "editor-palette-items-clear", N_("Clear Selected Item Set"), false, scope_editor, "" },
150  { hotkey::HOTKEY_EDITOR_PALETTE_ITEM_SWAP, "editor-terrain-palette-swap", N_("Swap Foreground/Background Palette Item"), false, scope_editor, "" },
151  { hotkey::HOTKEY_EDITOR_PALETTE_GROUPS, "editor-palette-groups", N_("Change Palette Group"), false, scope_editor, "" },
152  { hotkey::HOTKEY_EDITOR_PALETTE_UPSCROLL, "editor-palette-upscroll", N_("Scroll Palette Left"), false, scope_editor, "" },
153  { hotkey::HOTKEY_EDITOR_PALETTE_DOWNSCROLL, "editor-palette-downscroll", N_("Scroll Palette Right"), false, scope_editor, "" },
154  { hotkey::HOTKEY_EDITOR_REMOVE_LOCATION, "editor-remove-location", N_("Remove Location"), false, scope_editor, "" },
155 
156  { hotkey::HOTKEY_EDITOR_SIDE_NEW, "editor-side-new", N_("Add New Side"), false, scope_editor, "" },
157 
158  { hotkey::HOTKEY_EDITOR_TOOL_NEXT, "editor-tool-next", N_("Next Tool"), false, scope_editor, "" },
159 
160  { hotkey::HOTKEY_EDITOR_TOOL_PAINT, "editor-tool-paint", N_("Paint Tool"), false, scope_editor, 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.") },
161  { hotkey::HOTKEY_EDITOR_TOOL_FILL, "editor-tool-fill", N_("Fill Tool"), false, scope_editor, 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.") },
162  { hotkey::HOTKEY_EDITOR_TOOL_SELECT, "editor-tool-select", N_("Selection Tool"), false, scope_editor, 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.") },
163  { hotkey::HOTKEY_EDITOR_TOOL_STARTING_POSITION, "editor-tool-starting-position", N_("Starting Positions Tool"), false, scope_editor, 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.") },
164  { hotkey::HOTKEY_EDITOR_TOOL_LABEL, "editor-tool-label", N_("Label Tool"), false, scope_editor, N_("Left mouse button sets or drags a label, right clears.") },
165  { hotkey::HOTKEY_EDITOR_TOOL_UNIT, "editor-tool-unit", N_("Unit Tool"), false, scope_editor, N_("Left mouse button sets a new unit or moves a unit via drag and drop, right brings up a context menu. Needs a defined side.") },
166  { hotkey::HOTKEY_EDITOR_TOOL_ITEM, "editor-tool-item", N_("Item Tool"), false, scope_editor, N_("Left mouse button sets a new item or moves it via drag and drop, right clears. Not implemented yet.") },
167  { hotkey::HOTKEY_EDITOR_TOOL_SOUNDSOURCE, "editor-tool-soundsource", N_("Sound Source Tool"), false, scope_editor, N_("Left mouse button sets or drags a sound source, right clears. Not implemented yet.") },
168  { hotkey::HOTKEY_EDITOR_TOOL_VILLAGE, "editor-tool-village", N_("Village Tool"), false, scope_editor, N_("Left mouse button sets the village ownership to the current side, right clears. Needs a defined side.") },
169 
170  { hotkey::HOTKEY_EDITOR_UNIT_TOGGLE_CANRECRUIT, "editor-toggle-canrecruit", N_("Can Recruit"), false, scope_editor, N_("Toggle the recruit attribute of a unit.") },
171  { hotkey::HOTKEY_EDITOR_UNIT_TOGGLE_RENAMEABLE, "editor-toggle-renameable", N_("Can be Renamed"), false, scope_editor, N_("Toggle the unit being renameable.") },
172  { hotkey::HOTKEY_EDITOR_UNIT_RECRUIT_ASSIGN, "editor-unit-recruit", N_("Assign Recruit List"), false, scope_editor, N_("Assign the selected unit set as recruit list to the unit.") },
173 
174  { hotkey::HOTKEY_EDITOR_UNIT_CHANGE_ID, "editor-change-unitid", N_("Change Unit ID"), false, scope_editor, "" },
175  { hotkey::HOTKEY_EDITOR_UNIT_TOGGLE_LOYAL, "editor-unit-toggle-loyal", N_("Loyal"), false, scope_editor, "" },
176  { hotkey::HOTKEY_EDITOR_UNIT_FACING, "menu-unit-facing", "", true, scope_editor, "" },
177 
178  { hotkey::HOTKEY_MINIMAP_CODING_UNIT, "minimap-unit-coding", N_("Toggle Minimap Unit Coding"), false, scope_game | scope_editor | scope_main, "" },
179  { hotkey::HOTKEY_MINIMAP_CODING_TERRAIN, "minimap-terrain-coding", N_("Toggle Minimap Terrain Coding"), false, scope_game | scope_editor | scope_main, "" },
180 
181  { hotkey::HOTKEY_MINIMAP_DRAW_UNITS, "minimap-draw-units", N_("Toggle Minimap Unit Drawing"), false, scope_game | scope_editor | scope_main, "" },
182  { hotkey::HOTKEY_MINIMAP_DRAW_VILLAGES, "minimap-draw-villages", N_("Toggle Minimap Village Drawing"), false, scope_game | scope_editor | scope_main, "" },
183  { hotkey::HOTKEY_MINIMAP_DRAW_TERRAIN, "minimap-draw-terrain", N_("Toggle Minimap Terrain Drawing"), false, scope_game | scope_editor | scope_main, "" },
184 
185  { hotkey::HOTKEY_EDITOR_BRUSH_NEXT, "editor-brush-next", N_("Next Brush"), false, scope_editor, "" },
186  { hotkey::HOTKEY_EDITOR_BRUSH_DEFAULT, "editor-brush-default", N_("Default Brush"), false, scope_editor, "" },
187  { hotkey::HOTKEY_EDITOR_BRUSH_1, "editor-brush-1", N_("Single Tile"), false, scope_editor, "" },
188  { hotkey::HOTKEY_EDITOR_BRUSH_2, "editor-brush-2", N_("Radius One"), false, scope_editor, "" },
189  { hotkey::HOTKEY_EDITOR_BRUSH_3, "editor-brush-3", N_("Radius Two"), false, scope_editor, "" },
190  { hotkey::HOTKEY_EDITOR_BRUSH_NW_SE, "editor-brush-nw-se", N_("Brush NW-SE"), false, scope_editor, "" },
191  { hotkey::HOTKEY_EDITOR_BRUSH_SW_NE, "editor-brush-sw-ne", N_("Brush SW-NE"), false, scope_editor, "" },
192 
193  { hotkey::HOTKEY_EDITOR_SELECTION_CUT, "editor-cut", N_("Cut"), false, scope_editor, "" },
194  { hotkey::HOTKEY_EDITOR_SELECTION_COPY, "editor-copy", N_("Copy"), false, scope_editor, "" },
195  { hotkey::HOTKEY_EDITOR_CLIPBOARD_PASTE, "editor-paste", N_("Paste"), false, scope_editor, N_("Left mouse button pastes from the clipboard, right brings up a context menu.") },
196  { hotkey::HOTKEY_EDITOR_SELECTION_EXPORT, "editor-export-selection-coords", N_("Export Selected Coordinates to System Clipboard"), true, scope_editor, "" },
197  { hotkey::HOTKEY_EDITOR_SELECT_ALL, "editor-select-all", N_("Select All"), false, scope_editor, "" },
198  { hotkey::HOTKEY_EDITOR_SELECT_INVERSE, "editor-select-inverse", N_("Select Inverse"), false, scope_editor, "" },
199  { hotkey::HOTKEY_EDITOR_SELECT_NONE, "editor-select-none", N_("Select None"), false, scope_editor, "" },
200  { hotkey::HOTKEY_EDITOR_CLIPBOARD_ROTATE_CW, "editor-clipboard-rotate-cw", N_("Rotate Clipboard Clockwise"), false, scope_editor, "" },
201  { hotkey::HOTKEY_EDITOR_CLIPBOARD_ROTATE_CCW, "editor-clipboard-rotate-ccw", N_("Rotate Clipboard Counter-Clockwise"), false, scope_editor, "" },
202  { hotkey::HOTKEY_EDITOR_CLIPBOARD_FLIP_HORIZONTAL, "editor-clipboard-flip-horizontal", N_("Flip Clipboard Horizontally"), false, scope_editor, "" },
203  { hotkey::HOTKEY_EDITOR_CLIPBOARD_FLIP_VERTICAL, "editor-clipboard-flip-vertical", N_("Flip Clipboard Vertically"), false, scope_editor, "" },
204  { hotkey::HOTKEY_EDITOR_SELECTION_ROTATE, "editor-selection-rotate", N_("Rotate Selection"), false, scope_editor, "" },
205  { hotkey::HOTKEY_EDITOR_SELECTION_FLIP, "editor-selection-flip", N_("Flip Selection"), false, scope_editor, "" },
206  { hotkey::HOTKEY_EDITOR_SELECTION_FILL, "editor-selection-fill", N_("Fill Selection"), false, scope_editor, "" },
207  { hotkey::HOTKEY_EDITOR_SELECTION_GENERATE, "editor-selection-generate", N_("Generate Tiles in Selection"), false, scope_editor, "" },
208  { hotkey::HOTKEY_EDITOR_SELECTION_RANDOMIZE, "editor-selection-randomize", N_("Randomize Tiles in Selection"), false, scope_editor, "" },
209  { hotkey::HOTKEY_EDITOR_MAP_RESIZE, "editor-map-resize", N_("Resize Map"), false, scope_editor, "" },
210  { hotkey::HOTKEY_EDITOR_MAP_ROTATE, "editor-map-rotate", N_("Rotate Map"), false, scope_editor, "" },
211  { hotkey::HOTKEY_EDITOR_MAP_GENERATE, "editor-map-generate", N_("Generate Map"), false, scope_editor, "" },
212  { hotkey::HOTKEY_EDITOR_MAP_APPLY_MASK, "editor-map-apply-mask", N_("Apply a Mask"), false, scope_editor, "" },
213  { hotkey::HOTKEY_EDITOR_MAP_CREATE_MASK_TO, "editor-map-create-mask-to", N_("Create Mask"), false, scope_editor, "" },
214  { hotkey::HOTKEY_EDITOR_REFRESH, "editor-refresh", N_("Refresh Display"), false, scope_editor, "" },
215 
216  { hotkey::HOTKEY_EDITOR_UPDATE_TRANSITIONS, "editor-update-transitions", N_("Update Terrain Transitions"), false, scope_editor, "" },
217 
218  // This item is for binding in the preferences
219  { hotkey::HOTKEY_EDITOR_TOGGLE_TRANSITIONS, "editor-toggle-transitions", N_("Toggle Terrain Transition Update"), false, scope_editor, "" },
220  // The next three are for displaying the different states in the menu
221  { hotkey::HOTKEY_EDITOR_AUTO_UPDATE_TRANSITIONS, "editor-auto-update-transitions", N_("Auto-update Terrain Transitions"), true, scope_editor, "" },
222  { hotkey::HOTKEY_EDITOR_NO_UPDATE_TRANSITIONS, "editor-no-update-transitions", N_("Auto-update Terrain Transitions: No"), true, scope_editor, "" },
223  { hotkey::HOTKEY_EDITOR_PARTIAL_UPDATE_TRANSITIONS, "editor-partial-update-transitions", N_("Auto-update Terrain Transitions: Partial"), true, scope_editor, "" },
224 
225  { hotkey::HOTKEY_EDITOR_REFRESH_IMAGE_CACHE, "editor-refresh-image-cache", N_("Refresh Image Cache"), false, scope_editor, "" },
226  { hotkey::HOTKEY_EDITOR_DRAW_COORDINATES, "editor-draw-coordinates", N_("Draw Hex Coordinates"), false, scope_editor, "" },
227  { hotkey::HOTKEY_EDITOR_DRAW_TERRAIN_CODES, "editor-draw-terrain-codes", N_("Draw Terrain Codes"), false, scope_editor, "" },
228 
229  { hotkey::HOTKEY_EDITOR_AREA_SAVE, "editor-save-area", N_("Save Selection to Area"), false, scope_editor, "" },
230  { hotkey::HOTKEY_EDITOR_AREA_RENAME, "editor-rename-area", N_("Rename Selected Area"), false, scope_editor, "" },
231  { hotkey::HOTKEY_EDITOR_AREA_REMOVE, "editor-remove-area", N_("Remove Selected Area"), false, scope_editor, "" },
232  { hotkey::HOTKEY_EDITOR_AREA_ADD, "editor-add-area", N_("Add New Area"), false, scope_editor, "" },
233 
234  { hotkey::HOTKEY_EDITOR_SCENARIO_EDIT, "editor-scenario-edit", N_("Edit Scenario"), false, scope_editor, "" },
235  { hotkey::HOTKEY_EDITOR_SIDE_EDIT, "editor-side-edit", N_("Edit Side"), false, scope_editor, "" },
236  { hotkey::HOTKEY_EDITOR_SIDE_REMOVE, "editor-side-remove", N_("Remove Side"), false, scope_editor, "" },
237 
238  { hotkey::HOTKEY_DELAY_SHROUD, "delayshroud", N_("Delay Shroud Updates"), false, scope_game, "" },
239  { hotkey::HOTKEY_UPDATE_SHROUD, "updateshroud", N_("Update Shroud Now"), false, scope_game, "" },
240  { hotkey::HOTKEY_CONTINUE_MOVE, "continue", N_("Continue Move"), false, scope_game, "" },
241  { hotkey::HOTKEY_SEARCH, "search", N_("Find Label or Unit"), false, scope_game, "" },
242  { hotkey::HOTKEY_SPEAK_ALLY, "speaktoally", N_("Speak to Ally"), false, scope_game, "" },
243  { hotkey::HOTKEY_SPEAK_ALL, "speaktoall", N_("Speak to All"), false, scope_game, "" },
244  { hotkey::HOTKEY_HELP, "help", N_("Help"), false, scope_game | scope_editor | scope_main, "" },
245  { hotkey::HOTKEY_CHAT_LOG, "chatlog", N_("View Chat Log"), false, scope_game, "" },
246  { hotkey::HOTKEY_USER_CMD, "command", N_("Enter User Command"), false, scope_game, "" },
247  { hotkey::HOTKEY_CUSTOM_CMD, "customcommand", N_("Custom Command"), false, scope_game, "" },
248  { hotkey::HOTKEY_AI_FORMULA, "aiformula", N_("Run Formula"), false, scope_game, "" },
249  { hotkey::HOTKEY_CLEAR_MSG, "clearmessages", N_("Clear Messages"), false, scope_game, "" },
250 
251  { hotkey::HOTKEY_LANGUAGE, "changelanguage", N_("Change Language"), false, scope_main, "" },
252  { hotkey::TITLE_SCREEN__RELOAD_WML, "title_screen__reload_wml", N_("Refresh WML"), true , scope_editor | scope_main, "" },
253  { hotkey::TITLE_SCREEN__NEXT_TIP, "title_screen__next_tip", N_("Next Tip of the Day"), false, scope_main, "" },
254  { hotkey::TITLE_SCREEN__PREVIOUS_TIP, "title_screen__previous_tip", N_("Previous Tip of the Day"), false, scope_main, "" },
255  { hotkey::TITLE_SCREEN__TUTORIAL, "title_screen__tutorial", N_("Start Tutorial"), false , scope_main, "" },
256  { hotkey::TITLE_SCREEN__CAMPAIGN, "title_screen__campaign", N_("Start Campaign"), false , scope_main, "" },
257  { hotkey::TITLE_SCREEN__MULTIPLAYER, "title_screen__multiplayer", N_("Start Multiplayer Game"), false, scope_main, "" },
258  { hotkey::TITLE_SCREEN__ADDONS, "title_screen__addons", N_("Manage Add-ons"), false , scope_main, "" },
259  { hotkey::TITLE_SCREEN__CORES, "title_screen__cores", N_("Manage Cores"), false , scope_main, "" },
260  { hotkey::TITLE_SCREEN__EDITOR, "title_screen__editor", N_("Start Editor"), false, scope_main, "" },
261  { hotkey::TITLE_SCREEN__CREDITS, "title_screen__credits", N_("Show Credits"), false , scope_main, "" },
262 
263  { hotkey::GLOBAL__HELPTIP, "global__helptip", N_("Show Helptip"), false, scope_game | scope_editor | scope_main, "" },
264 
265  { hotkey::LUA_CONSOLE, "global__lua__console", N_("Show Lua Console"), false, scope_game | scope_editor | scope_main, ""},
266 
267  //This list item must stay at the end since it is used as terminator for iterating.
268  { hotkey::HOTKEY_NULL, "null", N_("Unrecognized Command"), true, hotkey::SCOPE_COUNT, "" }
269 };
270 
271 // contains copies of hotkey_list_ and all current active wml menu hotkeys
272 // maybe known_hotkeys is not a fitting name anymore.
273 boost::ptr_vector<hotkey::hotkey_command> known_hotkeys;
274 
275 // the size_t are indexes for known_hotkeys, because known_hotkeys begins with input_list_, they are also indexes for input_list_.
276 std::map<std::string, size_t> command_map_;
277 
278 //
279 hotkey::hk_scopes scope_active_(0);
280 
281 }
282 
283 namespace hotkey {
285 : prev_scope_active_(scope_active_)
286 {}
287 
289 {
290  scope_active_ = prev_scope_active_;
291 }
292 
293 
295 {
296  for (int i = 0; i < hotkey::SCOPE_COUNT; ++i) {
297  scope_active_[i] = false;
298  }
299 }
300 
302 {
303  scope_active_[s] = set;
304 }
306 {
307  scope_active_ = s;
308 }
309 
311 {
312  //s is a copy because we need one
313  s &= scope_active_;
314  return s.any();
315 }
316 
317 
319 {
320  if (command_map_.find(command) == command_map_.end())
321  {
322  return get_hotkey_null();
323  }
324 
325  return known_hotkeys[command_map_[command]];
326 }
327 
328 const boost::ptr_vector<hotkey_command>& get_hotkey_commands()
329 {
330  return known_hotkeys;
331 }
332 
333 
334 // Returns whether a hotkey was deleted.
336 {
337  const hotkey::hotkey_command& command = get_hotkey_command(id);
338  if(command.id == hotkey::HOTKEY_NULL)
339  {
340  LOG_G << "remove_wml_hotkey: command with id=" + id + " doesn't exist\n";
341  return false;
342  }
343  else if (command.id != hotkey::HOTKEY_WML)
344  {
345  LOG_G << "remove_wml_hotkey: command with id=" + id + " cannot be removed because it is no wml menu hotkey\n";
346  return false;
347  }
348  else
349  {
350  LOG_G << "removing wml hotkey with id=" + id + "\n";
351  for(boost::ptr_vector<hotkey_command>::iterator itor = known_hotkeys.begin(); itor != known_hotkeys.end(); ++itor)
352  {
353  if(itor->command == id)
354  {
355  known_hotkeys.erase(itor);
356  break;
357  }
358  }
359  //command_map_ might be all wrong now, so we need to rebuild.
360  command_map_.clear();
361  for(size_t index = 0; index < known_hotkeys.size(); index++)
362  {
363  command_map_[known_hotkeys[index].command] = index;
364  }
365  return true;
366  }
367 }
368 
370 {
372 }
373 
374 void add_wml_hotkey(const std::string& id, const t_string& description, const config& default_hotkey)
375 {
376  if(id == "null")
377  {
378  LOG_G << "Couldn't add wml hotkey with null id and description = '" << description << "'.\n";
379  return;
380  }
381  else
382  {
383  if(has_hotkey_command(id))
384  {
385  LOG_G << "Hotkey with id '" << id << "' already exists. Deleting the old hotkey_command.\n";
386  remove_wml_hotkey(id);
387  }
388  DBG_G << "Added wml hotkey with id = '" << id << "' and description = '" << description << "'.\n";
389  known_hotkeys.push_back(new hotkey_command(hotkey::HOTKEY_WML, id, description, false, scope_game, t_string("")));
390 
391  command_map_[id] = known_hotkeys.size() - 1;
392 
393  if(!default_hotkey.empty() && !has_hotkey_item(id))
394  {
395  hotkey::hotkey_ptr new_item = hotkey::load_from_config(default_hotkey);
396  new_item->set_command(id);
397  if(new_item->valid())
398  {
399  DBG_G << "added default description for the wml hotkey with id=" + id;
400  add_hotkey(new_item);
401  }
402  else
403  {
404  ERR_CF << "failed to add default hotkey with id=" + id;
405  }
406  }
407  }
408 }
409 
410 
411 
412 
414  : id(HOTKEY_NULL), command(""), description(""), hidden(true), scope(), tooltip("")
415 {
416  ERR_G << "hotkey_command's default constructor called. This shouldn't happen, because all its members are const.";
417 }
418 
420  : id(cmd), command(id_), description(desc), hidden(hid), scope(scop), tooltip(toolt)
421 {
422 }
423 
425 {
426  return get_hotkey_null();
427 }
428 
430 {
431  if(id == HOTKEY_NULL || command == "null")
432  {
433  const hotkey_command& null_cmd = null_command();
434  if(id == null_cmd.id && command == null_cmd.command && scope == null_cmd.scope && description == null_cmd.description)
435  return true;
436  else
437  {
438  ERR_G << "the hotkey command seems to be the null command but it is not 100% sure. This shouldn't happen";
439  return true;
440  }
441  }
442  return false;
443 }
444 
445 
447 {
448  for(hotkey_command& cmd : known_hotkeys)
449  {
450  if(cmd.id == command)
451  return cmd;
452  }
453  ERR_G << " \"get_command_by_command\" returned get_hotkey_null() because no hotkey_command had the requested number:" << command;
454  return get_hotkey_null();
455 }
456 
457 
459 {
460  //it is the last entry in that array, and the indexes in hotkey_list_ and known_hotkeys are the same.
461  return known_hotkeys[sizeof(hotkey_list_) / sizeof(hotkey_list_[0]) - 1];
462 }
463 
465 {
466  while(known_hotkeys.back().id == hotkey::HOTKEY_WML)
467  {
468  command_map_.erase(known_hotkeys.back().command);
469  //according to some page in the Internet .back() returns a reference not an iterator, so i use this.
470  boost::ptr_vector<hotkey_command>::iterator last_element = known_hotkeys.end();
471  --last_element;
472  //boost::ptr_vector<hotkey_command> will manage the deleting of the object for me.
473  known_hotkeys.erase(last_element);
474  }
475 }
476 
478 {
479  return get_hotkey_command(command).description;
480 }
481 
482 const std::string& get_tooltip(const std::string& command)
483 {
484  // the null hotkey_command has the "" tooltip
485  return get_hotkey_command(command).tooltip;
486 }
487 
489  //the size value is just random set.
490  boost::ptr_vector<hotkey_command> known_hotkeys_temp(200);
491  known_hotkeys = known_hotkeys_temp;
492 
493  size_t i = 0;
494  for(hotkey_command_temp& cmd : hotkey_list_)
495  {
496  known_hotkeys.push_back( new hotkey_command(cmd.id, cmd.command, t_string(cmd.description, "wesnoth-lib"), cmd.hidden, cmd.scope, t_string(cmd.tooltip, "wesnoth-lib")));
497  command_map_[cmd.command] = i;
498  i++;
499  }
500 }
501 
503  command_map_.clear();
504 }
505 
507 {
508  return get_hotkey_command(command).id;
509 }
510 
511 }
bool null() const
checks weather this is the null hotkey_command
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:154
std::string id_
Definition: formula.cpp:636
static lg::log_domain log_config("config")
hotkey_ptr load_from_config(const config &cfg)
Create and instantiate a hotkey from a config element.
scope
Available hotkey scopes.
void set_scope_active(scope s, bool set)
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...
static const hotkey_command & null_command()
returns the command that is treated as null
bool is_scope_active(hk_scopes s)
Stores all information related to functions that can be bound to hotkeys.
#define ERR_G
bool has_hotkey_item(const std::string &command)
bool empty() const
Definition: config.cpp:1105
Definitions for the interface to Wesnoth Markup Language (WML).
void clear_hotkey_commands()
void set_active_scopes(hk_scopes s)
Keyboard shortcuts for game actions.
const std::string & get_tooltip(const std::string &command)
#define LOG_G
const t_string description
GLuint id
Definition: glew.h:1647
std::bitset< SCOPE_COUNT > hk_scopes
void init_hotkey_commands()
const boost::ptr_vector< hotkey_command > & get_hotkey_commands()
returns a container that contains all currently active hotkey_commands.
void add_hotkey(const hotkey_ptr item)
Add a hotkey to the list of hotkeys.
const hotkey::hk_scopes scope
The visibility scope of the command.
void deactivate_all_scopes()
Do not use this outside hotkeys.cpp.
std::map< std::string, tfilter >::iterator itor
Definition: filter.cpp:199
const std::string command
The command is unique.
GLuint index
Definition: glew.h:1782
size_t i
Definition: function.cpp:1057
#define N_(String)
Definition: gettext.hpp:90
#define ERR_CF
hotkey_command()
the compiler want me to make a default constructor since most member are const, calling the default c...
const std::string & get_description(const std::string &command)
const hotkey_command & get_hotkey_null()
returns the hotkey_command that is treated as null.
const hotkey::HOTKEY_COMMAND id
the names are strange: the "hotkey::HOTKEY_COMMAND" is named id, and the string to identify the objec...
bool has_hotkey_command(const std::string &id)
Standard logging facilities (interface).
#define DBG_G
std::string::const_iterator iterator
Definition: tokenizer.hpp:21
A config object defines a single node in a WML file, with access to child nodes.
Definition: config.hpp:83
std::string::size_type size() const
Definition: tstring.hpp:167
GLdouble s
Definition: glew.h:1358
const hotkey_command & get_hotkey_command(const std::string &command)
returns the hotkey_command with the given name
void delete_all_wml_hotkeys()
deletes all wml hotkeys, should be called after a game has ended
bool remove_wml_hotkey(const std::string &id)
removes a wml hotkey with the given id, returns true if the deletion was successful ...
GLsizei const GLcharARB ** string
Definition: glew.h:4503
HOTKEY_COMMAND get_id(const std::string &command)
returns get_hotkey_command(command).id
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...