move pan input into an InputMapper
This commit is contained in:
@@ -207,8 +207,6 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
|
||||
, m_debugDraw(false)
|
||||
, m_rng(std::random_device{}())
|
||||
, m_boxSelecting(false)
|
||||
, m_scrollLeft(false)
|
||||
, m_scrollRight(false)
|
||||
, m_gameOverShown(false)
|
||||
, m_schematicChoiceShown(false)
|
||||
{
|
||||
@@ -366,15 +364,8 @@ void GameWorldView::onFrame()
|
||||
|
||||
// Apply held scroll
|
||||
{
|
||||
// Holding both keys cancels out, as it did when each key moved the view
|
||||
// independently.
|
||||
PanDirection direction = PanDirection::None;
|
||||
if (m_scrollLeft != m_scrollRight)
|
||||
{
|
||||
direction = m_scrollLeft ? PanDirection::Left : PanDirection::Right;
|
||||
}
|
||||
|
||||
const bool viewMoved = m_camera.advance(direction, elapsed, getScrollBounds());
|
||||
const bool viewMoved =
|
||||
m_camera.advance(m_panDirection, elapsed, getScrollBounds());
|
||||
|
||||
// While the view scrolls, the tile under a stationary cursor changes,
|
||||
// so refresh the box-select rectangle even though no mouse move fires.
|
||||
@@ -2319,6 +2310,10 @@ 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.
|
||||
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.
|
||||
@@ -2359,12 +2354,6 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
|
||||
|
||||
switch (event->key())
|
||||
{
|
||||
case Qt::Key_A:
|
||||
m_scrollLeft = true;
|
||||
break;
|
||||
case Qt::Key_D:
|
||||
m_scrollRight = true;
|
||||
break;
|
||||
case Qt::Key_Space:
|
||||
if (m_gameSpeedMultiplier > 0.0)
|
||||
{
|
||||
@@ -2422,8 +2411,7 @@ void GameWorldView::keyReleaseEvent(QKeyEvent* event)
|
||||
QOpenGLWidget::keyReleaseEvent(event);
|
||||
return;
|
||||
}
|
||||
if (event->key() == Qt::Key_A) { m_scrollLeft = false; }
|
||||
if (event->key() == Qt::Key_D) { m_scrollRight = false; }
|
||||
if (m_inputMapper.handleKeyRelease(event)) { return; }
|
||||
// Releasing Shift discards the copied building settings (REQ-BLD-COPY-CONFIG).
|
||||
if (event->key() == Qt::Key_Shift) { m_copiedConfig.reset(); }
|
||||
QOpenGLWidget::keyReleaseEvent(event);
|
||||
@@ -3070,8 +3058,9 @@ void GameWorldView::resetForNewGame()
|
||||
m_copyConfigFlashes.clear();
|
||||
m_boxSelecting = false;
|
||||
m_camera.reset();
|
||||
m_scrollLeft = false;
|
||||
m_scrollRight = false;
|
||||
// Drops any key still held across the restart, which also republishes the pan
|
||||
// direction so m_panDirection follows.
|
||||
m_inputMapper.releaseAll();
|
||||
m_gameOverShown = false;
|
||||
m_winShown = false;
|
||||
m_prevNonZeroSpeed = 1.0;
|
||||
@@ -3158,6 +3147,11 @@ void GameWorldView::handleEvent(std::shared_ptr<const SpeedChangeRequestedEvent>
|
||||
setGameSpeed(event->multiplier);
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const PanDirectionChangedEvent> event)
|
||||
{
|
||||
m_panDirection = event->direction;
|
||||
}
|
||||
|
||||
void GameWorldView::handleEvent(std::shared_ptr<const CommandRequestedEvent> event)
|
||||
{
|
||||
// Other widgets (MainWindow, SelectedBuildingPanel) request commands via this
|
||||
|
||||
Reference in New Issue
Block a user