move the remaining hotkeys into the InputMapper

This commit is contained in:
2026-08-05 19:58:08 +02:00
parent bb1ffab8fc
commit d5ab44b9bf
9 changed files with 160 additions and 38 deletions

View File

@@ -2311,46 +2311,12 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
return;
}
// Keys the input mapper owns are turned into actions and published from there
// (REQ-UI-HOTKEYS); this widget reacts to those as an ordinary subscriber.
// Keys are turned into actions and published by the input mapper
// (REQ-UI-HOTKEYS); this widget reacts to those as an ordinary subscriber, so
// nothing is handled here directly.
if (m_inputMapper.handleKeyPress(event)) { return; }
switch (event->key())
{
case Qt::Key_Space:
if (m_gameSpeedMultiplier > 0.0)
{
m_prevNonZeroSpeed = m_gameSpeedMultiplier;
setGameSpeed(0.0);
}
else
{
setGameSpeed(m_prevNonZeroSpeed);
}
break;
case Qt::Key_W:
stepSpeed(+1);
break;
case Qt::Key_S:
stepSpeed(-1);
break;
case Qt::Key_R:
rotateGhost(event->modifiers() & Qt::ShiftModifier);
break;
case Qt::Key_Q:
if (m_builderType.has_value()) { exitBuilderMode(); }
else if (m_blueprintMode.has_value()) { exitBlueprintMode(); }
else { toggleDeconstructMode(); }
break;
case Qt::Key_F3:
m_debugDraw = !m_debugDraw;
EventManager::getInstance()->sendEventImmediately(
std::make_shared<DebugDrawToggledEvent>(m_debugDraw));
break;
default:
QOpenGLWidget::keyPressEvent(event);
break;
}
QOpenGLWidget::keyPressEvent(event);
}
void GameWorldView::keyReleaseEvent(QKeyEvent* event)
@@ -3113,6 +3079,45 @@ void GameWorldView::handleEvent(std::shared_ptr<const PanDirectionChangedEvent>
m_panDirection = event->direction;
}
void GameWorldView::handleEvent(std::shared_ptr<const PauseToggleRequestedEvent> /*event*/)
{
if (m_gameSpeedMultiplier > 0.0)
{
m_prevNonZeroSpeed = m_gameSpeedMultiplier;
setGameSpeed(0.0);
}
else
{
setGameSpeed(m_prevNonZeroSpeed);
}
}
void GameWorldView::handleEvent(std::shared_ptr<const SpeedStepRequestedEvent> event)
{
stepSpeed(event->delta);
}
void GameWorldView::handleEvent(std::shared_ptr<const GhostRotationRequestedEvent> event)
{
rotateGhost(event->clockwise);
}
void GameWorldView::handleEvent(std::shared_ptr<const ModeCancelRequestedEvent> /*event*/)
{
// One key backs out of whichever mode is active, and enters deconstruct mode
// when none is (REQ-UI-HOTKEYS).
if (m_builderType.has_value()) { exitBuilderMode(); }
else if (m_blueprintMode.has_value()) { exitBlueprintMode(); }
else { toggleDeconstructMode(); }
}
void GameWorldView::handleEvent(std::shared_ptr<const DebugDrawToggleRequestedEvent> /*event*/)
{
m_debugDraw = !m_debugDraw;
EventManager::getInstance()->sendEventImmediately(
std::make_shared<DebugDrawToggledEvent>(m_debugDraw));
}
void GameWorldView::handleEvent(std::shared_ptr<const CommandRequestedEvent> event)
{
// Other widgets (MainWindow, SelectedBuildingPanel) request commands via this