diff --git a/data/core/editor2-hotkeys.cfg b/data/core/editor2-hotkeys.cfg index 7d5121856de..593022c717e 100644 --- a/data/core/editor2-hotkeys.cfg +++ b/data/core/editor2-hotkeys.cfg @@ -10,21 +10,18 @@ [hotkey] command="editor-undo" - scope="editor" description="Undo" key="u" [/hotkey] [hotkey] command="editor-redo" - scope="editor" description="Redo" key="r" [/hotkey] [hotkey] command="editor-save" - scope="editor" description="Save map" key="s" {IF_APPLE_CMD_ELSE_CTRL} @@ -32,7 +29,6 @@ [hotkey] command="editor-saveas" - scope="editor" description="Save map as" key="s" {IF_APPLE_CMD_ELSE_CTRL} @@ -41,7 +37,6 @@ [hotkey] command="editor-quit" - scope="editor" description="Quit map editor" key="q" {IF_APPLE_CMD_ELSE_CTRL} @@ -50,7 +45,6 @@ [hotkey] command="editor-new" - scope="editor" description="New map" key="n" {IF_APPLE_CMD_ELSE_CTRL} @@ -58,7 +52,6 @@ [hotkey] command="editor-load" - scope="editor" description="Load map from file" key="l" {IF_APPLE_CMD_ELSE_CTRL} @@ -66,105 +59,3 @@ [hotkey] command="editor-edit-cut" - scope="editor" - description="Cut selection from map" - key="x" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -[hotkey] - command="editor-edit-copy" - scope="editor" - description="Copy selection from map" - key="c" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -[hotkey] - command="editor-edit-paste" - scope="editor" - description="Paste selection to map" - key="v" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -[hotkey] - command="editor-revert" - scope="editor" - description="Revert map from file" - key="r" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -[hotkey] - command="editor-resize" - scope="editor" - description="Resize map" - key="r" - {IF_APPLE_CMD_ELSE_CTRL} - alt=yes -[/hotkey] - -[hotkey] - command="editor-selectall" - scope="editor" - description="Select entire map" - key="a" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -[hotkey] - command="editor-flip" - scope="editor" - description="Flip the map" - key="f" - {IF_APPLE_CMD_ELSE_CTRL} - alt=yes -[/hotkey] - -[hotkey] - command="editor-tool-draw" - scope="editor" - description="Draw with the selected terrain and brush" - key="d" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -[hotkey] - command="editor-tool-fill" - scope="editor" - description="Flood fill with selected terrain" - key="f" -[/hotkey] - -[hotkey] - command="editor-tool-select" - scope="editor" - description="Select tiles with the selected brush" - key="s" -[/hotkey] - -[hotkey] - command="editor-refresh" - scope="editor" - description="Refresh map display" - key="e" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -[hotkey] - command="editor-terrainupdate" - scope="editor" - description="Redraw/update terrain transitions" - key="b" -[/hotkey] - -[hotkey] - command="editor-terrainupdatedelay" - scope="editor" - description="Delay terrain transitions" - key="t" - {IF_APPLE_CMD_ELSE_CTRL} -[/hotkey] - -#undef IF_APPLE_CMD_ELSE_CTRL diff --git a/data/core/hotkeys.cfg b/data/core/hotkeys.cfg index 8b0a731ca56..711cb3fe723 100644 --- a/data/core/hotkeys.cfg +++ b/data/core/hotkeys.cfg @@ -12,267 +12,221 @@ [hotkey] command=aiformula - scope="game" key=f [/hotkey] [hotkey] command=accelerated - scope="game" key=a {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=bestenemymoves - scope="game" key=b {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=changeside - scope="game" key=u shift=yes [/hotkey] [hotkey] command=chatlog - scope="game" alt=yes key=c [/hotkey] [hotkey] command=clearlabels - scope="game" {IF_APPLE_CMD_ELSE_CTRL} key=c [/hotkey] [hotkey] command=clearmessages - scope="game" {IF_APPLE_CMD_ELSE_CTRL} key=x [/hotkey] [hotkey] command=createunit - scope="game" key=c shift=yes [/hotkey] [hotkey] command=command - scope="game" key=: [/hotkey] [hotkey] command=continue - scope="game" key=t [/hotkey] [hotkey] command=cycle - scope="game" key=n [/hotkey] [hotkey] command=cycleback - scope="game" key=n shift=yes [/hotkey] [hotkey] command=delayshroud - scope="game" key=d shift=yes [/hotkey] [hotkey] command=describeunit - scope="game" key=d [/hotkey] [hotkey] command=endunitturn - scope="game" key=" " [/hotkey] [hotkey] command=endturn - scope="game" key=" " alt=yes [/hotkey] [hotkey] command=fullscreen - scope="general" key=f {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=help - scope="general" key=F1 [/hotkey] [hotkey] command=holdposition - scope="game" key=" " shift=yes [/hotkey] [hotkey] command=labelteamterrain - scope="game" key=l {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=labelterrain - scope="game" key=l alt=yes [/hotkey] [hotkey] command=leader - scope="game" key=l [/hotkey] [hotkey] command=load - scope="game" key=o cmd=yes [/hotkey] [hotkey] command=mousescroll - scope="general" key=l {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=mute - scope="game" key=m {IF_APPLE_CMD_ELSE_CTRL} alt=yes [/hotkey] [hotkey] command=objectives - scope="game" key=j {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=preferences - scope="general" key=p {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=quit - scope="general" key=q {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=recall - scope="game" key=r alt=yes [/hotkey] [hotkey] command=recruit - scope="game" key=r cmd=yes [/hotkey] [hotkey] command=redo - scope="game" key=r [/hotkey] [hotkey] command=renameunit - scope="game" key=n {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=repeatrecruit - scope="game" key=r {IF_APPLE_CMD_ELSE_CTRL} alt=yes [/hotkey] [hotkey] command=save - scope="game" key=s {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=search - scope="game" key=/ [/hotkey] [hotkey] command=showenemymoves - scope="game" key=v {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=speak - scope="game" key=m [/hotkey] [hotkey] command=speaktoall - scope="game" key=m alt=yes [/hotkey] [hotkey] command=speaktoally - scope="game" key=m {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=statistics - scope="game" key=s [/hotkey] [hotkey] command=statustable - scope="game" key=s alt=yes [/hotkey] [hotkey] command=togglegrid - scope="general" key=g {IF_APPLE_CMD_ELSE_CTRL} [/hotkey] [hotkey] command=toggleshroud - scope="game" key=k alt=yes [/hotkey] [hotkey] command=undo - scope="game" key=u [/hotkey] [hotkey] command=unitlist - scope="game" key=u alt=yes [/hotkey] [hotkey] command=updateshroud - scope="game" key=s #ifdef APPLE cmd=yes @@ -281,17 +235,14 @@ [/hotkey] [hotkey] command=zoomdefault - scope="general" key=0 [/hotkey] [hotkey] command=zoomin - scope="general" key="+" [/hotkey] [hotkey] command=zoomout - scope="general" key=- [/hotkey] diff --git a/src/editor2/editor_controller.cpp b/src/editor2/editor_controller.cpp index 41974a01a95..a10ab078446 100644 --- a/src/editor2/editor_controller.cpp +++ b/src/editor2/editor_controller.cpp @@ -17,6 +17,7 @@ #include "mouse_action.hpp" #include "../config_adapter.hpp" #include "../foreach.hpp" +#include "../hotkeys.hpp" #include "../preferences.hpp" @@ -32,6 +33,9 @@ editor_controller::editor_controller(const config &game_config, CVideo& video) , map_(editor_map::new_map(game_config, 44, 33, t_translation::GRASS_LAND)) , gui_(NULL) { + hotkey::deactivate_all_scopes(); + hotkey::set_scope_active(hotkey::SCOPE_GENERAL); + hotkey::set_scope_active(hotkey::SCOPE_EDITOR); init(video); set_mouse_action(new mouse_action_paint(*this)); gui_->invalidate_game_status(); diff --git a/src/game.cpp b/src/game.cpp index b6c05f1e3ad..a1f3ea3ce10 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1969,6 +1969,9 @@ bool game_controller::change_language() void game_controller::show_preferences() { + hotkey::deactivate_all_scopes(); + hotkey::set_scope_active(hotkey::SCOPE_GENERAL); + hotkey::set_scope_active(hotkey::SCOPE_GAME); const preferences::display_manager disp_manager(&disp()); preferences::show_preferences_dialog(disp(),game_config_); diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index b01a9a09908..64a98dab787 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -25,6 +25,7 @@ #include "game_errors.hpp" #include "gettext.hpp" #include "filesystem.hpp" +#include "foreach.hpp" #include "log.hpp" #include "menu_events.hpp" #include "preferences_display.hpp" @@ -51,122 +52,149 @@ const struct { const char* command; const char* description; bool hidden; + hotkey::scope scope; } hotkey_list_[] = { - { hotkey::HOTKEY_CYCLE_UNITS, "cycle", N_("Next Unit"), false }, - { hotkey::HOTKEY_CYCLE_BACK_UNITS, "cycleback", N_("Previous Unit"), false }, - { hotkey::HOTKEY_UNIT_HOLD_POSITION, "holdposition", N_("Hold Position"), false}, - { hotkey::HOTKEY_END_UNIT_TURN, "endunitturn", N_("End Unit Turn"), false }, - { hotkey::HOTKEY_LEADER, "leader", N_("Leader"), false }, - { hotkey::HOTKEY_UNDO, "undo", N_("Undo"), false }, - { hotkey::HOTKEY_REDO, "redo", N_("Redo"), false }, - { hotkey::HOTKEY_ZOOM_IN, "zoomin", N_("Zoom In"), false }, - { hotkey::HOTKEY_ZOOM_OUT, "zoomout", N_("Zoom Out"), false }, - { hotkey::HOTKEY_ZOOM_DEFAULT, "zoomdefault", N_("Default Zoom"), false }, - { hotkey::HOTKEY_FULLSCREEN, "fullscreen", N_("Toggle Full Screen"), false }, - { hotkey::HOTKEY_SCREENSHOT, "screenshot", N_("Screenshot"), false }, - { hotkey::HOTKEY_MAP_SCREENSHOT, "mapscreenshot", N_("Map Screenshot"), false }, - { hotkey::HOTKEY_ACCELERATED, "accelerated", N_("Accelerated"), false }, - { hotkey::HOTKEY_UNIT_DESCRIPTION, "describeunit", N_("Unit Description"), false }, - { hotkey::HOTKEY_RENAME_UNIT, "renameunit", N_("Rename Unit"), false }, - { hotkey::HOTKEY_SAVE_GAME, "save", N_("Save Game"), false }, - { hotkey::HOTKEY_SAVE_REPLAY, "savereplay", N_("Save Replay"), false }, - { hotkey::HOTKEY_SAVE_MAP, "savemap", N_("Save The Map"), false }, - { hotkey::HOTKEY_LOAD_GAME, "load", N_("Load Game"), false }, - { hotkey::HOTKEY_RECRUIT, "recruit", N_("Recruit"), false }, - { hotkey::HOTKEY_REPEAT_RECRUIT, "repeatrecruit", N_("Repeat Recruit"), false }, - { hotkey::HOTKEY_RECALL, "recall", N_("Recall"), false }, - { hotkey::HOTKEY_ENDTURN, "endturn", N_("End Turn"), false }, - { hotkey::HOTKEY_TOGGLE_GRID, "togglegrid", N_("Toggle Grid"), false }, - { hotkey::HOTKEY_MOUSE_SCROLL, "mousescroll", N_("Mouse Scrolling"), false }, - { hotkey::HOTKEY_STATUS_TABLE, "statustable", N_("Status Table"), false }, - { hotkey::HOTKEY_MUTE, "mute", N_("Mute"), false }, - { hotkey::HOTKEY_SPEAK, "speak", N_("Speak"), false }, - { hotkey::HOTKEY_CREATE_UNIT, "createunit", N_("Create Unit (Debug!)"), false }, - { hotkey::HOTKEY_CHANGE_UNIT_SIDE, "changeside", N_("Change Unit Side (Debug!)"), false }, - { hotkey::HOTKEY_PREFERENCES, "preferences", N_("Preferences"), false }, - { hotkey::HOTKEY_OBJECTIVES, "objectives", N_("Scenario Objectives"), false }, - { hotkey::HOTKEY_UNIT_LIST, "unitlist", N_("Unit List"), false }, - { hotkey::HOTKEY_STATISTICS, "statistics", N_("Statistics"), false }, - { hotkey::HOTKEY_QUIT_GAME, "quit", N_("Quit Game"), false }, - { hotkey::HOTKEY_LABEL_TEAM_TERRAIN, "labelteamterrain", N_("Set Team Label"), false }, - { hotkey::HOTKEY_LABEL_TERRAIN, "labelterrain", N_("Set Label"), false }, - { hotkey::HOTKEY_CLEAR_LABELS, "clearlabels", N_("Clear Labels"), false }, - { hotkey::HOTKEY_SHOW_ENEMY_MOVES, "showenemymoves", N_("Show Enemy Moves"), false }, - { hotkey::HOTKEY_BEST_ENEMY_MOVES, "bestenemymoves", N_("Best Possible Enemy Moves"), false }, - { hotkey::HOTKEY_PLAY_REPLAY, "playreplay", N_("Play"), false }, - { hotkey::HOTKEY_RESET_REPLAY, "resetreplay", N_("Reset"), false }, - { hotkey::HOTKEY_STOP_REPLAY, "stopreplay", N_("Stop"), false }, - { hotkey::HOTKEY_REPLAY_NEXT_TURN, "replaynextturn", N_("Next Turn"), false }, - { hotkey::HOTKEY_REPLAY_NEXT_SIDE, "replaynextside", N_("Next Side"), false }, + { hotkey::HOTKEY_CYCLE_UNITS, "cycle", N_("Next Unit"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_CYCLE_BACK_UNITS, "cycleback", N_("Previous Unit"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_UNIT_HOLD_POSITION, "holdposition", N_("Hold Position"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_END_UNIT_TURN, "endunitturn", N_("End Unit Turn"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_LEADER, "leader", N_("Leader"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_UNDO, "undo", N_("Undo"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_REDO, "redo", N_("Redo"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_ZOOM_IN, "zoomin", N_("Zoom In"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_ZOOM_OUT, "zoomout", N_("Zoom Out"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_ZOOM_DEFAULT, "zoomdefault", N_("Default Zoom"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_FULLSCREEN, "fullscreen", N_("Toggle Full Screen"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_SCREENSHOT, "screenshot", N_("Screenshot"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_MAP_SCREENSHOT, "mapscreenshot", N_("Map Screenshot"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_ACCELERATED, "accelerated", N_("Accelerated"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_UNIT_DESCRIPTION, "describeunit", N_("Unit Description"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_RENAME_UNIT, "renameunit", N_("Rename Unit"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_SAVE_GAME, "save", N_("Save Game"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_SAVE_REPLAY, "savereplay", N_("Save Replay"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_SAVE_MAP, "savemap", N_("Save The Map"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_LOAD_GAME, "load", N_("Load Game"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_RECRUIT, "recruit", N_("Recruit"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_REPEAT_RECRUIT, "repeatrecruit", N_("Repeat Recruit"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_RECALL, "recall", N_("Recall"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_ENDTURN, "endturn", N_("End Turn"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_TOGGLE_GRID, "togglegrid", N_("Toggle Grid"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_MOUSE_SCROLL, "mousescroll", N_("Mouse Scrolling"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_STATUS_TABLE, "statustable", N_("Status Table"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_MUTE, "mute", N_("Mute"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_SPEAK, "speak", N_("Speak"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_CREATE_UNIT, "createunit", N_("Create Unit (Debug!)"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_CHANGE_UNIT_SIDE, "changeside", N_("Change Unit Side (Debug!)"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_PREFERENCES, "preferences", N_("Preferences"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_OBJECTIVES, "objectives", N_("Scenario Objectives"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_UNIT_LIST, "unitlist", N_("Unit List"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_STATISTICS, "statistics", N_("Statistics"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_QUIT_GAME, "quit", N_("Quit Game"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_LABEL_TEAM_TERRAIN, "labelteamterrain", N_("Set Team Label"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_LABEL_TERRAIN, "labelterrain", N_("Set Label"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_CLEAR_LABELS, "clearlabels", N_("Clear Labels"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_SHOW_ENEMY_MOVES, "showenemymoves", N_("Show Enemy Moves"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_BEST_ENEMY_MOVES, "bestenemymoves", N_("Best Possible Enemy Moves"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_PLAY_REPLAY, "playreplay", N_("Play"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_RESET_REPLAY, "resetreplay", N_("Reset"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_STOP_REPLAY, "stopreplay", N_("Stop"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_REPLAY_NEXT_TURN, "replaynextturn", N_("Next Turn"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_REPLAY_NEXT_SIDE, "replaynextside", N_("Next Side"), false, hotkey::SCOPE_GAME }, { hotkey::HOTKEY_REPLAY_SHOW_EVERYTHING, "replayshoweverything", - N_("Full map"), false }, + N_("Full map"), false, hotkey::SCOPE_GAME }, { hotkey::HOTKEY_REPLAY_SHOW_EACH, "replayshoweach", - N_("Each team"), false }, + N_("Each team"), false, hotkey::SCOPE_GAME }, { hotkey::HOTKEY_REPLAY_SHOW_TEAM1, "replayshowteam1", - N_("Team 1"), false }, - { hotkey::HOTKEY_REPLAY_SKIP_ANIMATION, "replayskipanimation", N_("Skip animation"), false }, + N_("Team 1"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_REPLAY_SKIP_ANIMATION, "replayskipanimation", N_("Skip animation"), false, hotkey::SCOPE_GAME }, - { hotkey::HOTKEY_EDIT_SET_TERRAIN, "editsetterrain", N_("Set Terrain"),true }, - { hotkey::HOTKEY_EDIT_QUIT, "editquit", N_("Quit Editor"),true }, - { hotkey::HOTKEY_EDIT_NEW_MAP, "editnewmap", N_("New Map"),true }, - { hotkey::HOTKEY_EDIT_LOAD_MAP, "editloadmap", N_("Load Map"),true }, - { hotkey::HOTKEY_EDIT_SAVE_MAP, "editsavemap", N_("Save Map"),true }, - { hotkey::HOTKEY_EDIT_SAVE_AS, "editsaveas", N_("Save As"),true }, - { hotkey::HOTKEY_EDIT_SET_START_POS, "editsetstartpos", N_("Set Player's keep"),true }, - { hotkey::HOTKEY_EDIT_FLOOD_FILL, "editfloodfill", N_("Flood Fill"),true }, - { hotkey::HOTKEY_EDIT_FILL_SELECTION, "editfillselection", N_("Fill Selection"),true }, - { hotkey::HOTKEY_EDIT_ROTATE_SELECTION, "editrotateselection", N_("Rotate Selection"),true }, - { hotkey::HOTKEY_EDIT_CUT, "editcut", N_("Cut"),true }, - { hotkey::HOTKEY_EDIT_COPY, "editcopy", N_("Copy"),true }, - { hotkey::HOTKEY_EDIT_PASTE, "editpaste", N_("Paste"),true }, - { hotkey::HOTKEY_EDIT_REVERT, "editrevert", N_("Revert from Disk"),true }, - { hotkey::HOTKEY_EDIT_RESIZE, "editresize", N_("Resize Map"),true }, - { hotkey::HOTKEY_EDIT_FLIP, "editflip", N_("Flip Map"),true }, - { hotkey::HOTKEY_EDIT_SELECT_ALL, "editselectall", N_("Select All"),true }, - { hotkey::HOTKEY_EDIT_DRAW, "editdraw", N_("Draw Terrain"),true }, - { hotkey::HOTKEY_EDIT_REFRESH, "editrefresh", N_("Refresh Image Cache"), true }, - { hotkey::HOTKEY_EDIT_AUTO_UPDATE, "editautoupdate", N_("Delay transition updates"), true }, - { hotkey::HOTKEY_EDIT_UPDATE, "editupdate", N_("Update transitions"), true }, + { hotkey::HOTKEY_EDIT_SET_TERRAIN, "editsetterrain", N_("Set Terrain"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_QUIT, "editquit", N_("Quit Editor"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_NEW_MAP, "editnewmap", N_("New Map"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_LOAD_MAP, "editloadmap", N_("Load Map"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_SAVE_MAP, "editsavemap", N_("Save Map"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_SAVE_AS, "editsaveas", N_("Save As"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_SET_START_POS, "editsetstartpos", N_("Set Player's keep"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_FLOOD_FILL, "editfloodfill", N_("Flood Fill"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_FILL_SELECTION, "editfillselection", N_("Fill Selection"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_ROTATE_SELECTION, "editrotateselection", N_("Rotate Selection"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_CUT, "editcut", N_("Cut"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_COPY, "editcopy", N_("Copy"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_PASTE, "editpaste", N_("Paste"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_REVERT, "editrevert", N_("Revert from Disk"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_RESIZE, "editresize", N_("Resize Map"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_FLIP, "editflip", N_("Flip Map"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_SELECT_ALL, "editselectall", N_("Select All"),true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_DRAW, "editdraw", N_("Draw Terrain"), true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_REFRESH, "editrefresh", N_("Refresh Image Cache"), true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_AUTO_UPDATE, "editautoupdate", N_("Delay transition updates"), true, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_EDIT_UPDATE, "editupdate", N_("Update transitions"), true, hotkey::SCOPE_GENERAL }, - { hotkey::HOTKEY_DELAY_SHROUD, "delayshroud", N_("Delay Shroud Updates"), false }, - { hotkey::HOTKEY_UPDATE_SHROUD, "updateshroud", N_("Update Shroud Now"), false }, - { hotkey::HOTKEY_CONTINUE_MOVE, "continue", N_("Continue Move"), false }, - { hotkey::HOTKEY_SEARCH, "search", N_("Find Label or Unit"), false }, - { hotkey::HOTKEY_SPEAK_ALLY, "speaktoally", N_("Speak to Ally"), false }, - { hotkey::HOTKEY_SPEAK_ALL, "speaktoall", N_("Speak to All"), false }, - { hotkey::HOTKEY_HELP, "help", N_("Help"), false }, - { hotkey::HOTKEY_CHAT_LOG, "chatlog", N_("View Chat Log"), false }, - { hotkey::HOTKEY_LANGUAGE, "changelanguage", N_("Change the language"), true }, + { hotkey::HOTKEY_DELAY_SHROUD, "delayshroud", N_("Delay Shroud Updates"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_UPDATE_SHROUD, "updateshroud", N_("Update Shroud Now"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_CONTINUE_MOVE, "continue", N_("Continue Move"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_SEARCH, "search", N_("Find Label or Unit"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_SPEAK_ALLY, "speaktoally", N_("Speak to Ally"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_SPEAK_ALL, "speaktoall", N_("Speak to All"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_HELP, "help", N_("Help"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_CHAT_LOG, "chatlog", N_("View Chat Log"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_LANGUAGE, "changelanguage", N_("Change the language"), true, hotkey::SCOPE_GENERAL }, - { hotkey::HOTKEY_USER_CMD, "command", N_("Enter user command"), false }, - { hotkey::HOTKEY_CUSTOM_CMD, "customcommand", N_("Custom command"), false }, - { hotkey::HOTKEY_AI_FORMULA, "aiformula", N_("Run AI formula"), false }, - { hotkey::HOTKEY_CLEAR_MSG, "clearmessages", N_("Clear messages"), false }, + { hotkey::HOTKEY_USER_CMD, "command", N_("Enter user command"), false, hotkey::SCOPE_GENERAL }, + { hotkey::HOTKEY_CUSTOM_CMD, "customcommand", N_("Custom command"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_AI_FORMULA, "aiformula", N_("Run AI formula"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_CLEAR_MSG, "clearmessages", N_("Clear messages"), false, hotkey::SCOPE_GAME }, #ifdef USRCMD2 - { hotkey::HOTKEY_USER_CMD_2, "usercommand#2", N_("User-Command#2"), false }, - { hotkey::HOTKEY_USER_CMD_3, "usercommand#3", N_("User-Command#3"), false }, + { hotkey::HOTKEY_USER_CMD_2, "usercommand#2", N_("User-Command#2"), false, hotkey::SCOPE_GAME }, + { hotkey::HOTKEY_USER_CMD_3, "usercommand#3", N_("User-Command#3"), false, hotkey::SCOPE_GAME }, #endif - { hotkey::HOTKEY_NULL, NULL, NULL, true } + { hotkey::HOTKEY_NULL, NULL, NULL, true, hotkey::SCOPE_GENERAL } }; std::vector hotkeys_; hotkey::hotkey_item null_hotkey_; +const std::string scope_strings_[] = {"general", "game", "editor"}; +bool scope_active_[hotkey::SCOPE_COUNT] = {true, false}; } namespace hotkey { -const std::string hotkey_item::scope_strings_[] = {"general", "game", "editor"}; + +void deactivate_all_scopes() +{ + foreach (bool& b, scope_active_) { + b = false; + } +} + +void set_scope_active(scope s, bool set) +{ + scope_active_[s] = set; +} + +bool is_scope_active(scope s) +{ + ERR_G << "is_scope_active(" << s << ") -- " << scope_active_[s] << "\n"; + return scope_active_[s]; +} + +const std::string& get_scope_string(scope s) +{ + return scope_strings_[s]; +} static void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor); const std::string CLEARED_TEXT = "__none__"; hotkey_item::hotkey_item(HOTKEY_COMMAND id, - const std::string& command, const std::string& description, bool hidden) : + const std::string& command, const std::string& description, bool hidden, + scope s) : id_(id), command_(command), description_(description), + scope_(s), type_(UNBOUND), character_(0), ctrl_(false), @@ -196,13 +224,6 @@ void hotkey_item::load_from_config(const config& cfg) const std::string& scope_string = cfg["scope"]; int i = 0; - while (i < SCOPE_COUNT && scope_string != scope_strings_[i]) ++i; - if (i == SCOPE_COUNT) { - ERR_CONFIG << "No valid scope (" << scope_string << ") in hotkey " << key << "\n"; - scope_ = SCOPE_GENERAL; - } else { - scope_ = static_cast(i); - } if (!key.empty()) { // They may really want a specific key on the keyboard: we assume @@ -326,7 +347,7 @@ manager::manager() { for (int i = 0; hotkey_list_[i].command; ++i) { hotkeys_.push_back(hotkey_item(hotkey_list_[i].id, hotkey_list_[i].command, - "", hotkey_list_[i].hidden)); + "", hotkey_list_[i].hidden, hotkey_list_[i].scope)); } } @@ -367,7 +388,6 @@ void save_hotkeys(config& cfg) config& item = cfg.add_child("hotkey"); item["command"] = i->get_command(); - item["scope"] = i->get_scope_string(); if (i->get_type() == hotkey_item::CLEARED) { item["key"] = CLEARED_TEXT; @@ -417,7 +437,7 @@ hotkey_item& get_hotkey(const std::string& command) } hotkey_item& get_hotkey(int character, int keycode, bool shift, bool ctrl, - bool alt, bool cmd, hotkey_item::scope scope) + bool alt, bool cmd) { std::vector::iterator itor; @@ -448,11 +468,11 @@ hotkey_item& get_hotkey(int character, int keycode, bool shift, bool ctrl, if (ctrl == itor->get_ctrl() && alt == itor->get_alt() && cmd == itor->get_cmd()) { - if (scope >= hotkey_item::SCOPE_COUNT || scope == itor->get_scope()) { + if (itor->is_in_active_scope()) { DBG_G << "Could match by character..." << "yes\n"; break; } else { - DBG_G << "Could match by character..." << "yes, but wrong scope\n"; + DBG_G << "Could match by character..." << "yes, but scope is inactive\n"; } } DBG_G << "Could match by character..." << "but modifiers different\n"; @@ -463,11 +483,11 @@ hotkey_item& get_hotkey(int character, int keycode, bool shift, bool ctrl, && ctrl == itor->get_ctrl() && alt == itor->get_alt() && cmd == itor->get_cmd()) { - if (scope >= hotkey_item::SCOPE_COUNT || scope == itor->get_scope()) { + if (itor->is_in_active_scope()) { DBG_G << "Could match by keycode..." << "yes\n"; break; } else { - DBG_G << "Could match by keycode..." << "yes, but wrong scope\n"; + DBG_G << "Could match by keycode..." << "yes, but scope is inactive\n"; } } DBG_G << "Could match by keycode..." << "but modifiers different\n"; @@ -481,7 +501,7 @@ hotkey_item& get_hotkey(int character, int keycode, bool shift, bool ctrl, return *itor; } -hotkey_item& get_hotkey(const SDL_KeyboardEvent& event, hotkey_item::scope scope) +hotkey_item& get_hotkey(const SDL_KeyboardEvent& event) { return get_hotkey(event.keysym.unicode, event.keysym.sym, (event.keysym.mod & KMOD_SHIFT) != 0, @@ -491,7 +511,6 @@ hotkey_item& get_hotkey(const SDL_KeyboardEvent& event, hotkey_item::scope scope #ifdef __APPLE__ || (event.keysym.mod & KMOD_RMETA) != 0 #endif - , scope ); } @@ -499,7 +518,7 @@ static void _get_visible_hotkey_itor(int index, std::vector::iterat { int counter = 0; for (itor = hotkeys_.begin(); itor != hotkeys_.end(); ++itor) { - if (itor->hidden()) + if (itor->hidden() || !itor->is_in_active_scope()) continue; if (index == counter) @@ -560,13 +579,6 @@ void key_event(display& disp, const SDL_KeyboardEvent& event, command_executor* void key_event_execute(display& disp, const SDL_KeyboardEvent& event, command_executor* executor) { const hotkey_item* hk = &get_hotkey(event); - if (hk->null()) { - if (disp.in_game()) { - hk = &get_hotkey(event, hotkey_item::SCOPE_GAME); - } else if (disp.in_editor()) { - hk = &get_hotkey(event, hotkey_item::SCOPE_EDITOR); - } - } #if 0 // This is not generally possible without knowing keyboard layout. diff --git a/src/hotkeys.hpp b/src/hotkeys.hpp index 3c3ac69b44c..36420bbd0ae 100644 --- a/src/hotkeys.hpp +++ b/src/hotkeys.hpp @@ -28,6 +28,17 @@ class display; //refers to a hotkey command being executed. namespace hotkey { +/** Available hotkey scopes. The scope is used to allow command from + * non-overlapping areas of the game share the same key + */ +enum scope { + SCOPE_GENERAL, + SCOPE_GAME, + SCOPE_EDITOR, + SCOPE_COUNT +}; + + enum HOTKEY_COMMAND { HOTKEY_CYCLE_UNITS,HOTKEY_CYCLE_BACK_UNITS, HOTKEY_UNIT_HOLD_POSITION, HOTKEY_END_UNIT_TURN, HOTKEY_LEADER, @@ -71,6 +82,11 @@ enum HOTKEY_COMMAND { HOTKEY_NULL }; +void deactivate_all_scopes(); +void set_scope_active(scope s, bool set = true); +bool is_scope_active(scope s); +const std::string& get_scope_string(scope s); + class hotkey_item { public: hotkey_item() : @@ -88,7 +104,9 @@ public: hidden_(false) {} - hotkey_item(HOTKEY_COMMAND id, const std::string& command, const std::string& description, bool hidden=false); + hotkey_item(HOTKEY_COMMAND id, const std::string& command, + const std::string& description, bool hidden=false, + scope s=SCOPE_GENERAL); HOTKEY_COMMAND get_id() const { return id_; }; const std::string& get_command() const { return command_; }; @@ -109,24 +127,11 @@ public: enum type get_type() const { return type_; } - /** Available hotkey scopes. The scope is used to allow command from - * non-overlapping areas of the game share the same key - */ - enum scope { - SCOPE_GENERAL, - SCOPE_GAME, - SCOPE_EDITOR, - SCOPE_COUNT - }; - - /** Array C-string equivalents of the enum values. Must be in sync */ - static const std::string scope_strings_[SCOPE_COUNT]; /** @return the scope of this hotkey */ scope get_scope() const { return scope_; } - /** @return the string equivalent of this hotkey's scope */ - const std::string& get_scope_string() const { return scope_strings_[get_scope()]; } + const bool is_in_active_scope() const { return is_scope_active(get_scope()); } // Returns unicode value of keypress. int get_character() const { return character_; } @@ -167,6 +172,8 @@ private: }; + + class manager { public: manager(); @@ -182,9 +189,8 @@ hotkey_item& get_hotkey(HOTKEY_COMMAND id); hotkey_item& get_hotkey(const std::string& command); hotkey_item& get_hotkey(int character, int keycode, bool shift, bool ctrl, - bool alt, bool cmd, hotkey_item::scope scope = hotkey_item::SCOPE_COUNT); -hotkey_item& get_hotkey(const SDL_KeyboardEvent& event, - hotkey_item::scope scope = hotkey_item::SCOPE_COUNT); + bool alt, bool cmd); +hotkey_item& get_hotkey(const SDL_KeyboardEvent& event); hotkey_item& get_visible_hotkey(int index); diff --git a/src/play_controller.cpp b/src/play_controller.cpp index c6953b7445b..415de5f748b 100644 --- a/src/play_controller.cpp +++ b/src/play_controller.cpp @@ -57,7 +57,9 @@ play_controller::play_controller(const config& level, { status_.teams = &teams_; game_config::add_color_info(level); - + hotkey::deactivate_all_scopes(); + hotkey::set_scope_active(hotkey::SCOPE_GENERAL); +// hotkey::set_scope_active(hotkey::hotkey_item::SCOPE_GAME); init(video, is_replay); } diff --git a/src/preferences_display.cpp b/src/preferences_display.cpp index f59c1cbef20..6f9c1c99982 100644 --- a/src/preferences_display.cpp +++ b/src/preferences_display.cpp @@ -243,7 +243,7 @@ void show_hotkeys_dialog (display & disp, config *save_config) std::vector& hotkeys = hotkey::get_hotkeys(); for(std::vector::iterator i = hotkeys.begin(); i != hotkeys.end(); ++i) { - if(i->hidden()) + if(i->hidden() || !i->is_in_active_scope()) continue; std::stringstream str,name; name << i->get_description();