move the already-event-driven hotkeys into the InputMapper
This commit is contained in:
@@ -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<int>(virtualKey - 0x30);
|
||||
const bool shift = (event->modifiers() & Qt::ShiftModifier) != 0;
|
||||
std::optional<BuildingType> 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<BuildHotkeyPressedEvent>(*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<TemporaryBlueprintRequestedEvent>());
|
||||
break;
|
||||
case Qt::Key_Escape:
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<EscapeMenuRequestedEvent>());
|
||||
break;
|
||||
case Qt::Key_F3:
|
||||
m_debugDraw = !m_debugDraw;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<DebugDrawToggledEvent>(m_debugDraw));
|
||||
break;
|
||||
case Qt::Key_F4:
|
||||
EventManager::getInstance()->addEvent(std::make_shared<TracePrintRequestedEvent>());
|
||||
break;
|
||||
default:
|
||||
QOpenGLWidget::keyPressEvent(event);
|
||||
break;
|
||||
|
||||
@@ -1,11 +1,50 @@
|
||||
#include "InputMapper.h"
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <QKeyEvent>
|
||||
|
||||
#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<BuildingType> 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<BuildingType> type = buildHotkeyType(
|
||||
static_cast<int>(virtualKey - 0x30),
|
||||
(event->modifiers() & Qt::ShiftModifier) != 0);
|
||||
if (type.has_value())
|
||||
{
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<BuildHotkeyPressedEvent>(*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<TemporaryBlueprintRequestedEvent>());
|
||||
return true;
|
||||
case Qt::Key_Escape:
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<EscapeMenuRequestedEvent>());
|
||||
return true;
|
||||
case Qt::Key_F4:
|
||||
EventManager::getInstance()->addEvent(
|
||||
std::make_shared<TracePrintRequestedEvent>());
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user