From e43eb0c18bdb87d3e14fd55f938b0bfc136aeb48 Mon Sep 17 00:00:00 2001 From: Ykkrosh Date: Sun, 7 Nov 2010 20:42:52 +0000 Subject: [PATCH] # Various hotkey fixes and cleanups. Support ctrl for removing entities from selection. Move big screenshot hotkey to shift+F2. Increase mouse wheel rotation speed. Fix HotkeyIsPressed when a more specific hotkey was matched instead. Support multiple hotkeys with the same binding. Use hotkeys instead of raw key events in GUI. Delete some obsolete hotkey definitions. Remove unused broken EntitySelection toggle method. This was SVN commit r8546. --- binaries/data/config/default.cfg | 151 ++++++------------ binaries/data/config/keys.txt | 4 +- .../data/mods/public/gui/pregame/mainmenu.xml | 1 - .../data/mods/public/gui/session_new/input.js | 129 +++++++-------- .../mods/public/gui/session_new/selection.js | 40 ++--- .../mods/public/gui/session_new/session.xml | 2 +- source/graphics/GameView.cpp | 19 +-- source/gui/scripting/ScriptFunctions.cpp | 7 + source/ps/Hotkey.cpp | 32 ++-- source/ps/tests/test_Parser.h | 22 +++ 10 files changed, 194 insertions(+), 213 deletions(-) diff --git a/binaries/data/config/default.cfg b/binaries/data/config/default.cfg index b4c16c01a8..2a58eeca42 100644 --- a/binaries/data/config/default.cfg +++ b/binaries/data/config/default.cfg @@ -77,7 +77,7 @@ view.rotate.x.min = 20 view.rotate.x.max = 60 view.rotate.x.default = 30 view.rotate.y.speed = 2.0 -view.rotate.y.speed.wheel = 0.1 +view.rotate.y.speed.wheel = 0.45 view.rotate.y.default = 0.0 view.drag.speed = 0.5 view.zoom.speed = 256.0 @@ -98,53 +98,42 @@ view.rotate.y.smoothness = 0.3 ; See keys.txt for the list of key names. ; > SYSTEM SETTINGS -hotkey.exit = "Alt+F4", "Ctrl+Break" ; Exit to desktop. -hotkey.leave = Escape ;End current game or Exit. -hotkey.pause = Pause ; Pause/unpause game. -hotkey.screenshot = F2 ; Take PNG screenshot. -hotkey.bigscreenshot = "Ctrl+Alt+F2" ; Take large BMP screenshot. -hotkey.togglefullscreen = "Alt+Return" ; Toggle fullscreen/windowed mode -hotkey.screenshot.watermark = "K" ; Toggle product/company watermark for official -hotkey.wireframe = "Alt+W" ; Toggle wireframe mode. - -hotkey.archive.abort = "Alt+F4" ; Prematurely terminate the archive builder process. +hotkey.exit = "Alt+F4", "Ctrl+Break" ; Exit to desktop +hotkey.leave = Escape ; End current game or Exit +hotkey.pause = Pause ; Pause/unpause game +hotkey.screenshot = F2 ; Take PNG screenshot +hotkey.bigscreenshot = "Shift+F2" ; Take large BMP screenshot +hotkey.togglefullscreen = "Alt+Return" ; Toggle fullscreen/windowed mode +hotkey.screenshot.watermark = "K" ; Toggle product/company watermark for official screenshots +hotkey.wireframe = "Alt+W" ; Toggle wireframe mode ; > CAMERA SETTINGS -hotkey.camera.reset = "H" ; Reset camera rotation to default. -hotkey.camera.follow = "F" ; Follow the first unit in the selection -hotkey.camera.reset.origin = "Ctrl+H" ; Reset camera to origin. -hotkey.camera.zoom.in = Plus, Equals, NumPlus ; Zoom camera in. -hotkey.camera.zoom.out = Minus, NumMinus ; Zoom camera out. -hotkey.camera.zoom.wheel.in = WheelUp ; Zoom camera in (wheel speed). -hotkey.camera.zoom.wheel.out = WheelDown ; Zoom camera out (wheel speed). -hotkey.camera.rotate.wheel.cw = "Shift+WheelUp" -hotkey.camera.rotate.wheel.ccw = "Shift+WheelDown" -hotkey.camera.rotate.cw = "Ctrl+LeftArrow", "Ctrl+A", Q -hotkey.camera.rotate.ccw = "Ctrl+RightArrow", "Ctrl+D", E -hotkey.camera.rotate.up = "Ctrl+UpArrow", "Ctrl+W" -hotkey.camera.rotate.down = "Ctrl+DownArrow", "Ctrl+S" - -hotkey.camera.pan = MouseMiddle, ForwardSlash ; Scroll by moving mouse. -hotkey.camera.pan.keyboard = "~Shift+~Ctrl" ; = holding neither Ctrl nor Shift -hotkey.camera.left = A, LeftArrow ; Scroll or rotate left. -hotkey.camera.right = D, RightArrow ; Scroll or rotate right. -hotkey.camera.up = W, UpArrow ; Scroll or rotate up/forwards. -hotkey.camera.down = S, DownArrow ; Scroll or rotate down/backwards. - -;camera.cinema.add = "L" -;camera.cinema.delete = "U" -;camera.cinema.delete.all = "R" -;camera.cinema.write = "O" -camera.cinema.queue = "I" +hotkey.camera.reset = "H" ; Reset camera rotation to default. +hotkey.camera.follow = "F" ; Follow the first unit in the selection +hotkey.camera.zoom.in = Plus, Equals, NumPlus ; Zoom camera in (continuous control) +hotkey.camera.zoom.out = Minus, NumMinus ; Zoom camera out (continuous control) +hotkey.camera.zoom.wheel.in = WheelUp ; Zoom camera in (stepped control) +hotkey.camera.zoom.wheel.out = WheelDown ; Zoom camera out (stepped control) +hotkey.camera.rotate.up = "Ctrl+UpArrow", "Ctrl+W" ; Rotate camera to look upwards +hotkey.camera.rotate.down = "Ctrl+DownArrow", "Ctrl+S" ; Rotate camera to look downwards +hotkey.camera.rotate.cw = "Ctrl+LeftArrow", "Ctrl+A", Q ; Rotate camera clockwise around terrain +hotkey.camera.rotate.ccw = "Ctrl+RightArrow", "Ctrl+D", E ; Rotate camera anticlockwise around terrain +hotkey.camera.rotate.wheel.cw = "Shift+WheelUp" ; Rotate camera clockwise around terrain (stepped control) +hotkey.camera.rotate.wheel.ccw = "Shift+WheelDown" ; Rotate camera clockwise around terrain (stepped control) +hotkey.camera.pan = MouseMiddle, ForwardSlash ; Enable scrolling by moving mouse +hotkey.camera.left = A, LeftArrow ; Scroll or rotate left +hotkey.camera.right = D, RightArrow ; Scroll or rotate right +hotkey.camera.up = W, UpArrow ; Scroll or rotate up/forwards +hotkey.camera.down = S, DownArrow ; Scroll or rotate down/backwards ; > CONSOLE SETTINGS -hotkey.console.toggle = BackQuote, F9 ; Open/close console. -hotkey.console.copy = "Ctrl+C" ; Copy from console to clipboard. -hotkey.console.paste = Insert, "Ctrl+V" ; Paste clipboard to console. +hotkey.console.toggle = BackQuote, F9 ; Open/close console +hotkey.console.copy = "Ctrl+C" ; Copy from console to clipboard +hotkey.console.paste = "Ctrl+V" ; Paste clipboard to console ; > ENTITY SELECTION -hotkey.selection.add = Shift ; Add units to selection. -hotkey.selection.remove = Ctrl ; Remove units from selection. +hotkey.selection.add = Shift ; Add units to selection +hotkey.selection.remove = Ctrl ; Remove units from selection hotkey.selection.group.0 = 0 hotkey.selection.group.1 = 1 hotkey.selection.group.2 = 2 @@ -155,70 +144,30 @@ hotkey.selection.group.6 = 6 hotkey.selection.group.7 = 7 hotkey.selection.group.8 = 8 hotkey.selection.group.9 = 9 -hotkey.selection.group.add = Shift ; +group: Add units to group. -hotkey.selection.group.save = Ctrl ; +group: Save units to group. -hotkey.selection.group.snap = Alt ; +group: Check up on group. -hotkey.selection.snap = Home ; Centre view on selection. -hotkey.highlightall = O ; Show selection circle for all units on screen. -hotkey.killUnit = Delete +hotkey.selection.group.add = Shift ; +group: Add units to group +hotkey.selection.group.save = Ctrl ; +group: Save units to group +hotkey.selection.group.snap = Alt ; +group: Check up on group +hotkey.selection.snap = Home ; Centre view on selection -; > CONTEXT CURSOR -hotkey.contextorder.next = LeftBracket ; Cycle right through orders (context cursors). -hotkey.contextorder.previous = RightBracket ; Cycle left through orders (context cursors). - -; > TESTING KEYS -hotkey.orbital.toggle = V ; Enable/disable ball arena. -hotkey.orbital.cheat = "LeftCtrl+Backslash" ; Freeze ball. -hotkey.dudemachine.random = "Ctrl+ForwardSlash" ; Create random Dude. +; > SESSION CONTROLS +hotkey.session.kill = Delete ; Destroy selected units +hotkey.session.garrison = Ctrl ; Modifier to garrison when clicking on building +hotkey.session.queue = Shift ; Modifier to queue unit orders instead of replacing +hotkey.session.batchtrain = Shift ; Modifier to train units in batches +hotkey.session.deselectgroup = Ctrl ; Modifier to deselect units when clicking group icon, instead of selecting +hotkey.session.rotate.cw = RightBracket ; Rotate building placement preview clockwise +hotkey.session.rotate.ccw = LeftBracket ; Rotate building placement preview anticlockwise ; > OVERLAY KEYS -hotkey.fps.toggle = "Shift+F" ; Toggle frame counter. -hotkey.session.statuspane.toggle = "Shift+S" ; Toggle Status Orb. -hotkey.session.minimap.toggle = "Shift+M" ; Toggle Map Orb. -hotkey.resourcepool.toggle = "Shift+R" ; Toggle Resource Pool. -hotkey.grouppane.toggle = "Shift+G" ; Toggle Group Pane. -hotkey.teamtray.toggle = "Shift+T" ; Toggle Team Tray. -hotkey.session.ShowPlayersList = "Shift+P" ; Toggle Players List -hotkey.session.devcommands.toggle = "Shift+D" - -; > SESSION ORIENTATION KEYS -hotkey.session.gui.flip = "Alt+G" ; Toggle GUI to top/bottom/left/right of screen. -hotkey.session.gui.toggle = "G" ; Toggle visibility of session GUI. - -; (TEMPORARY) -hotkey.alwayson.toggle = "Shift+X" ; Toggle always ons (Exit Button, End Game Button). - -; > SUBMENU KEYS -hotkey.menu.toggle = "F10" ; Toggle in-game menu. -hotkey.menu.resign = "Alt+X" ; End current game session and return to main menu. +hotkey.fps.toggle = "Shift+F" ; Toggle frame counter +hotkey.session.devcommands.toggle = "Shift+D" ; Toggle developer commands panel +hotkey.session.gui.toggle = "G" ; Toggle visibility of session GUI +hotkey.menu.toggle = "F10" ; Toggle in-game menu ; > HOTKEYS ONLY - - - -hotkey.chat = Return ; Toggles chat window - - - -hotkey.onlinehelp = "F1" ; Enable/disable online manual entry for current selection. -hotkey.music.toggle = "M" ; Enable/disable music. -hotkey.audio.toggle = "Ctrl+A" ; Enable/disable sound. +hotkey.chat = Return ; Toggle chat window ; > PROFILER -hotkey.profile.toggle = "F11" ; Enable/disable real-time profiler -hotkey.profile.save = "Shift+F11" ; Save current profiler data to "logs/profile.txt" +hotkey.profile.toggle = "F11" ; Enable/disable real-time profiler +hotkey.profile.save = "Shift+F11" ; Save current profiler data to logs/profile.txt -; UNMAPPED KEY/MOUSE REFERENCE: - -; LMB ; select unit -; RMB ; issue order to selected units -; LMB-drag ; bandbox units -; LMB-doubleclick ; select all units of this type on screen -; LMB-tripleclick ; select all units of this type on map -; shift+mouse select ; add to selection -; ctrl+mouse select ; remove from selection -; #=(1...0) ; select group #, pressing again centres view -; shift+# ; add group # to selection -; ctrl+# ; save selection as group # -; alt+# (hold down) ; snap view to group # (while alt is held down) -; mouse on map edge ; scroll in this direction diff --git a/binaries/data/config/keys.txt b/binaries/data/config/keys.txt index 2f49d9c683..29024a71b0 100644 --- a/binaries/data/config/keys.txt +++ b/binaries/data/config/keys.txt @@ -126,8 +126,8 @@ Right Alt, RightAlt Left Alt, LeftAlt Right Meta Left Meta -Left Super, LeftWin -Right Super, RightWin +Left Super, LeftWin +Right Super, RightWin Alt Gr, AltGr Compose diff --git a/binaries/data/mods/public/gui/pregame/mainmenu.xml b/binaries/data/mods/public/gui/pregame/mainmenu.xml index dceff2ec9c..3cf8167c46 100644 --- a/binaries/data/mods/public/gui/pregame/mainmenu.xml +++ b/binaries/data/mods/public/gui/pregame/mainmenu.xml @@ -356,7 +356,6 @@ Watch for updates or get involved in the development: http://wildfiregames.com/0 Mute All - + performCommand(g_Selection.toList()[0], "delete"); diff --git a/source/graphics/GameView.cpp b/source/graphics/GameView.cpp index 5aee7875e1..6c2d36fe01 100644 --- a/source/graphics/GameView.cpp +++ b/source/graphics/GameView.cpp @@ -638,17 +638,14 @@ void CGameView::Update(float DeltaTime) moveForward += m->ViewScrollSpeed * DeltaTime; } - if (HotkeyIsPressed("camera.pan.keyboard")) - { - if (HotkeyIsPressed("camera.right")) - moveRightward += m->ViewScrollSpeed * DeltaTime; - if (HotkeyIsPressed("camera.left")) - moveRightward -= m->ViewScrollSpeed * DeltaTime; - if (HotkeyIsPressed("camera.up")) - moveForward += m->ViewScrollSpeed * DeltaTime; - if (HotkeyIsPressed("camera.down")) - moveForward -= m->ViewScrollSpeed * DeltaTime; - } + if (HotkeyIsPressed("camera.right")) + moveRightward += m->ViewScrollSpeed * DeltaTime; + if (HotkeyIsPressed("camera.left")) + moveRightward -= m->ViewScrollSpeed * DeltaTime; + if (HotkeyIsPressed("camera.up")) + moveForward += m->ViewScrollSpeed * DeltaTime; + if (HotkeyIsPressed("camera.down")) + moveForward -= m->ViewScrollSpeed * DeltaTime; if (moveRightward || moveForward) { diff --git a/source/gui/scripting/ScriptFunctions.cpp b/source/gui/scripting/ScriptFunctions.cpp index d625a36fa9..ee2e719c26 100644 --- a/source/gui/scripting/ScriptFunctions.cpp +++ b/source/gui/scripting/ScriptFunctions.cpp @@ -33,6 +33,7 @@ #include "ps/CConsole.h" #include "ps/Errors.h" #include "ps/Game.h" +#include "ps/Hotkey.h" #include "ps/Overlay.h" #include "ps/Pyrogenesis.h" #include "ps/GameSetup/Atlas.h" @@ -322,6 +323,11 @@ void CameraFollowFPS(void* UNUSED(cbdata), entity_id_t entityid) g_Game->GetView()->CameraFollow(entityid, true); } +bool HotkeyIsPressed_(void* UNUSED(cbdata), std::string hotkeyName) +{ + return HotkeyIsPressed(hotkeyName); +} + void SetSimRate(void* UNUSED(cbdata), float rate) { g_Game->SetSimRate(rate); @@ -403,6 +409,7 @@ void GuiScriptingInit(ScriptInterface& scriptInterface) scriptInterface.RegisterFunction("LoadMapSettings"); scriptInterface.RegisterFunction("CameraFollow"); scriptInterface.RegisterFunction("CameraFollowFPS"); + scriptInterface.RegisterFunction("HotkeyIsPressed"); // Development/debugging functions scriptInterface.RegisterFunction("SetSimRate"); diff --git a/source/ps/Hotkey.cpp b/source/ps/Hotkey.cpp index 5511653e1d..90cce5d3a2 100644 --- a/source/ps/Hotkey.cpp +++ b/source/ps/Hotkey.cpp @@ -256,12 +256,12 @@ InReaction HotkeyInputHandler( const SDL_Event_* ev ) // -- KEYDOWN SECTION -- - const char* closestMapName = NULL; + std::vector closestMapNames; size_t closestMapMatch = 0; for( std::vector::iterator it = g_HotkeyMap[keycode].begin(); it < g_HotkeyMap[keycode].end(); it++ ) { - // If a key has been pressed, and this event triggers on it's release, skip it. + // If a key has been pressed, and this event triggers on its release, skip it. // Similarly, if the key's been released and the event triggers on a keypress, skip it. if( it->negated == typeKeyDown ) continue; @@ -298,22 +298,34 @@ InReaction HotkeyInputHandler( const SDL_Event_* ev ) if( accept && !( isCapturable && consoleCapture ) ) { - g_HotkeyStatus[it->name] = true; - if( it->requires.size() >= closestMapMatch ) + // Tentatively set status to un-pressed, since it may be overridden by + // a closer match. (The closest matches will be set to pressed later.) + g_HotkeyStatus[it->name] = false; + + // Check if this is an equally precise or more precise match + if( it->requires.size() + 1 >= closestMapMatch ) { - // Only if it's a more precise match, and it either isn't capturable or the console won't capture it. - closestMapName = it->name.c_str(); - closestMapMatch = it->requires.size() + 1; + // Check if more precise + if( it->requires.size() + 1 > closestMapMatch ) + { + // Throw away the old less-precise matches + closestMapNames.clear(); + closestMapMatch = it->requires.size() + 1; + } + + closestMapNames.push_back(it->name.c_str()); } } } - if( closestMapMatch ) + for (size_t i = 0; i < closestMapNames.size(); ++i) { + g_HotkeyStatus[closestMapNames[i]] = true; + SDL_Event hotkeyNotification; hotkeyNotification.type = SDL_HOTKEYDOWN; - hotkeyNotification.user.data1 = const_cast(closestMapName); - SDL_PushEvent( &hotkeyNotification ); + hotkeyNotification.user.data1 = const_cast(closestMapNames[i]); + SDL_PushEvent(&hotkeyNotification); } // -- KEYUP SECTION -- diff --git a/source/ps/tests/test_Parser.h b/source/ps/tests/test_Parser.h index b691df162c..fa72695ff6 100644 --- a/source/ps/tests/test_Parser.h +++ b/source/ps/tests/test_Parser.h @@ -38,6 +38,28 @@ public: TS_ASSERT(Line.GetArgInt(1, i) && i == 23); } + void test_hotkey() + { + CParser Parser; + Parser.InputTaskType( "multikey", "<[~$arg(_negate)]$value_+_>_[~$arg(_negate)]$value" ); + + std::string str; + + CParserLine Line; + + TS_ASSERT(Line.ParseString(Parser, "x+yzzy+~w")); + TS_ASSERT_EQUALS((int)Line.GetArgCount(), 4); + TS_ASSERT(Line.GetArgString(0, str) && str == "x"); + TS_ASSERT(Line.GetArgString(1, str) && str == "yzzy"); + TS_ASSERT(Line.GetArgString(2, str) && str == "_negate"); + TS_ASSERT(Line.GetArgString(3, str) && str == "w"); + + // This fails because '[' isn't a value character (per _IsValueChar). + // I don't know whether that's a feature or a bug. +// TS_ASSERT(Line.ParseString(Parser, "[")); +// TS_ASSERT_EQUALS((int)Line.GetArgCount(), 1); +// TS_ASSERT(Line.GetArgString(0, str) && str == "["); + } void test_optional() {