resolve keyboard shortcuts through one action table instead of a switch
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "GameWorldView.h"
|
||||
#include "PlacementRules.h"
|
||||
#include "FactoryQueries.h"
|
||||
#include "BlueprintLibrary.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
@@ -1075,7 +1076,7 @@ void GameWorldView::keyPressEvent(QKeyEvent* event)
|
||||
// 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; }
|
||||
if (m_inputMapper.handleKeyPress(event, getControlContext())) { return; }
|
||||
|
||||
QOpenGLWidget::keyPressEvent(event);
|
||||
}
|
||||
@@ -1087,7 +1088,7 @@ void GameWorldView::keyReleaseEvent(QKeyEvent* event)
|
||||
QOpenGLWidget::keyReleaseEvent(event);
|
||||
return;
|
||||
}
|
||||
if (m_inputMapper.handleKeyRelease(event)) { return; }
|
||||
if (m_inputMapper.handleKeyRelease(event, getControlContext())) { return; }
|
||||
QOpenGLWidget::keyReleaseEvent(event);
|
||||
}
|
||||
|
||||
@@ -1101,6 +1102,43 @@ void GameWorldView::focusOutEvent(QFocusEvent* event)
|
||||
QOpenGLWidget::focusOutEvent(event);
|
||||
}
|
||||
|
||||
void GameWorldView::setBlueprintLibrary(const BlueprintLibrary* library)
|
||||
{
|
||||
m_blueprintLibrary = library;
|
||||
}
|
||||
|
||||
ControlContext GameWorldView::getControlContext() const
|
||||
{
|
||||
ControlContext context;
|
||||
context.mode = m_buildMode.getMode();
|
||||
context.draggingBelt = m_buildMode.isDraggingBelt();
|
||||
context.hoveredGhostIsTransfer = m_buildMode.isHoveredGhostTransfer();
|
||||
if (m_buildMode.isBuilderMode()) { context.builderType = m_buildMode.getBuilderType(); }
|
||||
|
||||
// Buildings win over field objects, so the two are never both non-empty
|
||||
// (REQ-UI-SELECTION-CATEGORIES).
|
||||
const std::vector<BuildingId>& buildings = m_selection.getSelectedBuildings();
|
||||
const std::vector<entt::entity>& actors = m_selection.getSelectedActors();
|
||||
const std::vector<entt::entity>& debris = m_selection.getSelectedDebris();
|
||||
if (!buildings.empty())
|
||||
{
|
||||
context.selection = ControlSelection::Buildings;
|
||||
context.selectionCount = static_cast<int>(buildings.size());
|
||||
}
|
||||
else if (!actors.empty() || !debris.empty())
|
||||
{
|
||||
context.selection = ControlSelection::FieldObjects;
|
||||
context.selectionCount = static_cast<int>(actors.size() + debris.size());
|
||||
}
|
||||
|
||||
if (m_blueprintLibrary)
|
||||
{
|
||||
context.placeableBuildingSelected = m_blueprintLibrary->getCanCaptureSelection();
|
||||
context.temporaryBlueprintExists = m_blueprintLibrary->getHasTemporaryBlueprint();
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
void GameWorldView::mousePressEvent(QMouseEvent* event)
|
||||
{
|
||||
const WorldCoordinates coordinates = getCoordinates();
|
||||
@@ -1263,6 +1301,21 @@ void GameWorldView::mouseMoveEvent(QMouseEvent* event)
|
||||
else if (m_buildMode.isBlueprintMode())
|
||||
{
|
||||
m_buildMode.setBlueprintGhostTile(tile);
|
||||
|
||||
// Resolved here, once, through the same classifier the click and the ghost's
|
||||
// colour use, and stored on the mode: the controls panel says "Apply settings"
|
||||
// exactly when clicking would transfer (REQ-UI-BLUEPRINT-TRANSFER). Only a
|
||||
// single-building blueprint hit-tests the cursor, so only it can be a hovered
|
||||
// transfer target.
|
||||
const std::vector<BlueprintBuilding>& buildings =
|
||||
m_buildMode.getBlueprint().buildings;
|
||||
bool transfer = false;
|
||||
if (buildings.size() == 1)
|
||||
{
|
||||
transfer = resolveBlueprintGhostHere(buildings.front(), tile).action
|
||||
== BlueprintGhostAction::Transfer;
|
||||
}
|
||||
m_buildMode.setHoveredGhostTransfer(transfer);
|
||||
}
|
||||
else if (m_buildMode.isDeconstructMode())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user