diff --git a/rts/Game/UI/GuiHandler.cpp b/rts/Game/UI/GuiHandler.cpp index 370e21cbe9..6cf530ad46 100644 --- a/rts/Game/UI/GuiHandler.cpp +++ b/rts/Game/UI/GuiHandler.cpp @@ -1851,16 +1851,18 @@ int CGuiHandler::GetIconPosCommand(int slot) const // only called by SetActiveCo } +void CGuiHandler::CancelActiveCommand() +{ + activeMousePress = false; + SetActiveCommandIndex(-1); +} + + bool CGuiHandler::KeyPressed(int keyCode, int scanCode, bool isRepeat) { RECOIL_DETAILED_TRACY_ZONE; - if (keyCode == SDLK_ESCAPE && activeMousePress) { - activeMousePress = false; - SetActiveCommandIndex(-1); - return true; - } - if (keyCode == SDLK_ESCAPE && inCommand >= 0) { - SetActiveCommandIndex(-1); + if (keyCode == SDLK_ESCAPE && (activeMousePress || inCommand >= 0)) { + CancelActiveCommand(); return true; } diff --git a/rts/Game/UI/GuiHandler.h b/rts/Game/UI/GuiHandler.h index ee22de092e..de1625aaf9 100644 --- a/rts/Game/UI/GuiHandler.h +++ b/rts/Game/UI/GuiHandler.h @@ -99,6 +99,7 @@ class CGuiHandler : public CInputReceiver { bool SetActiveCommand(int cmdIndex, bool rightMouseButton); bool SetActiveCommand(int cmdIndex, int button, bool leftMouseButton, bool rightMouseButton, bool alt, bool ctrl, bool meta, bool shift); bool SetActiveCommand(const Action& action, const CKeySet& ks, int actionIndex); + void CancelActiveCommand(); void SetDrawSelectionInfo(bool dsi) { drawSelectionInfo = dsi; } bool GetDrawSelectionInfo() const { return drawSelectionInfo; } diff --git a/rts/Game/UnsyncedGameCommands.cpp b/rts/Game/UnsyncedGameCommands.cpp index c49edc0a6a..19a96edd4b 100644 --- a/rts/Game/UnsyncedGameCommands.cpp +++ b/rts/Game/UnsyncedGameCommands.cpp @@ -254,6 +254,22 @@ class DeselectActionExecutor : public IUnsyncedActionExecutor { +class CancelCommandActionExecutor : public IUnsyncedActionExecutor { +public: + CancelCommandActionExecutor() : IUnsyncedActionExecutor("CancelCommand", "Cancels the active command (build/order mode)") { + } + + bool Execute(const UnsyncedAction& action) const final { + if (guihandler == nullptr) + return false; + + guihandler->CancelActiveCommand(); + return true; + } +}; + + + class MapMeshDrawerActionExecutor : public IUnsyncedActionExecutor { public: MapMeshDrawerActionExecutor() : IUnsyncedActionExecutor("mapmeshdrawer", "Switch map-mesh rendering modes: 0=GCM, 1=HLOD, 2=ROAM") { @@ -4038,6 +4054,7 @@ void UnsyncedGameCommands::AddDefaultActionExecutors() AddActionExecutor(AllocActionExecutor()); AddActionExecutor(AllocActionExecutor()); AddActionExecutor(AllocActionExecutor()); + AddActionExecutor(AllocActionExecutor()); AddActionExecutor(AllocActionExecutor()); AddActionExecutor(AllocActionExecutor()); AddActionExecutor(AllocActionExecutor());