diff --git a/src/ui/GameWorldView.cpp b/src/ui/GameWorldView.cpp index 69dee28..6b56bce 100644 --- a/src/ui/GameWorldView.cpp +++ b/src/ui/GameWorldView.cpp @@ -2314,44 +2314,6 @@ void GameWorldView::keyPressEvent(QKeyEvent* event) // (REQ-UI-HOTKEYS); this widget reacts to those as an ordinary subscriber. if (m_inputMapper.handleKeyPress(event)) { return; } - // Number-key build-mode hotkeys (REQ-UI-HOTKEYS). nativeVirtualKey gives the - // physical digit independent of keyboard layout and Shift (with Shift held, key() - // for the number row can arrive as Key_Exclam etc.). VK_1..VK_9 = 0x31..0x39. - const quint32 virtualKey = event->nativeVirtualKey(); - if (virtualKey >= 0x31 && virtualKey <= 0x39) - { - const int digit = static_cast(virtualKey - 0x30); - const bool shift = (event->modifiers() & Qt::ShiftModifier) != 0; - std::optional type; - if (!shift) - { - switch (digit) - { - case 1: type = BuildingType::Belt; break; - case 2: type = BuildingType::Splitter; break; - case 3: type = BuildingType::TunnelEntry; break; // unified tunnel mode (REQ-BLD-TUNNEL-MODE); 4 unused - } - } - else - { - switch (digit) - { - case 1: type = BuildingType::Miner; break; - case 2: type = BuildingType::Smelter; break; - case 3: type = BuildingType::Assembler; break; - case 4: type = BuildingType::Shipyard; break; - case 5: type = BuildingType::SalvageBay; break; - case 6: type = BuildingType::ReprocessingPlant; break; - } - } - if (type.has_value()) - { - EventManager::getInstance()->sendEventImmediately( - std::make_shared(*type)); - return; - } - } - switch (event->key()) { case Qt::Key_Space: @@ -2379,25 +2341,11 @@ void GameWorldView::keyPressEvent(QKeyEvent* event) else if (m_blueprintMode.has_value()) { exitBlueprintMode(); } else { toggleDeconstructMode(); } break; - case Qt::Key_T: - // Request a temporary blueprint from the current selection (REQ-UI-BLUEPRINT-TEMP). - // The BlueprintPanel owns the selection and blueprint-capture logic; it decides - // whether anything placeable is selected and drives placement mode from there. - EventManager::getInstance()->sendEventImmediately( - std::make_shared()); - break; - case Qt::Key_Escape: - EventManager::getInstance()->sendEventImmediately( - std::make_shared()); - break; case Qt::Key_F3: m_debugDraw = !m_debugDraw; EventManager::getInstance()->sendEventImmediately( std::make_shared(m_debugDraw)); break; - case Qt::Key_F4: - EventManager::getInstance()->addEvent(std::make_shared()); - break; default: QOpenGLWidget::keyPressEvent(event); break; diff --git a/src/ui/InputMapper.cpp b/src/ui/InputMapper.cpp index b0beb4f..3a5f473 100644 --- a/src/ui/InputMapper.cpp +++ b/src/ui/InputMapper.cpp @@ -1,11 +1,50 @@ #include "InputMapper.h" #include +#include #include +#include "BuildHotkeyPressedEvent.h" +#include "BuildingType.h" +#include "EscapeMenuRequestedEvent.h" #include "EventManager.h" #include "PanDirectionChangedEvent.h" +#include "TemporaryBlueprintRequestedEvent.h" +#include "TracePrintRequestedEvent.h" + +namespace +{ + +// The building type a number-key build hotkey selects, or nullopt for the digits +// that are unbound (REQ-UI-HOTKEYS). Plain digits pick the transport buildings, +// Shift+digit the production ones. +std::optional buildHotkeyType(int digit, bool shiftHeld) +{ + if (!shiftHeld) + { + switch (digit) + { + case 1: return BuildingType::Belt; + case 2: return BuildingType::Splitter; + case 3: return BuildingType::TunnelEntry; // unified tunnel mode (REQ-BLD-TUNNEL-MODE); 4 unused + } + return std::nullopt; + } + + switch (digit) + { + case 1: return BuildingType::Miner; + case 2: return BuildingType::Smelter; + case 3: return BuildingType::Assembler; + case 4: return BuildingType::Shipyard; + case 5: return BuildingType::SalvageBay; + case 6: return BuildingType::ReprocessingPlant; + } + return std::nullopt; +} + +} // namespace bool InputMapper::handleKeyPress(QKeyEvent* event) { @@ -13,6 +52,23 @@ bool InputMapper::handleKeyPress(QKeyEvent* event) // already held. if (event->isAutoRepeat()) { return false; } + // Number-key build-mode hotkeys (REQ-UI-HOTKEYS). nativeVirtualKey gives the + // physical digit independent of keyboard layout and Shift (with Shift held, key() + // for the number row can arrive as Key_Exclam etc.). VK_1..VK_9 = 0x31..0x39. + const quint32 virtualKey = event->nativeVirtualKey(); + if (virtualKey >= 0x31 && virtualKey <= 0x39) + { + const std::optional type = buildHotkeyType( + static_cast(virtualKey - 0x30), + (event->modifiers() & Qt::ShiftModifier) != 0); + if (type.has_value()) + { + EventManager::getInstance()->sendEventImmediately( + std::make_shared(*type)); + return true; + } + } + switch (event->key()) { case Qt::Key_A: @@ -23,6 +79,21 @@ bool InputMapper::handleKeyPress(QKeyEvent* event) m_panRightHeld = true; updatePanDirection(); return true; + case Qt::Key_T: + // Request a temporary blueprint from the current selection (REQ-UI-BLUEPRINT-TEMP). + // The BlueprintPanel owns the selection and blueprint-capture logic; it decides + // whether anything placeable is selected and drives placement mode from there. + EventManager::getInstance()->sendEventImmediately( + std::make_shared()); + return true; + case Qt::Key_Escape: + EventManager::getInstance()->sendEventImmediately( + std::make_shared()); + return true; + case Qt::Key_F4: + EventManager::getInstance()->addEvent( + std::make_shared()); + return true; default: return false; }