let the hover follow a view that scrolls under a still cursor
Only the selection box was refreshed while the camera panned, so the ghost, its validity, the resolved tunnel end and the deconstruct hover all kept the tile of the last mouse move. Give the whole hover update one entry point and run it from the pan step as well, for a cursor that is over the world. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Ne3mejABZoLWKLh8fgpM3x
This commit is contained in:
@@ -123,7 +123,7 @@ Any ship, module, building, or assembler recipe id that appears in no unlock gro
|
||||
- REQ-BLD-QUEUE: Placed buildings enter a construction queue and are built one at a time. Each building takes a duration defined in `buildings.toml [[building]].construction_time_seconds` to construct.
|
||||
- REQ-BLD-ASTEROID-ONLY: Buildings can only be placed on asteroid tiles (per surface_mask; tiles marked `S` may extend into space).
|
||||
- REQ-BLD-BUILDER-MODE: Clicking a build button activates builder mode for that building type. Builder mode is exited by right-clicking in the game world or clicking the same build button again. (Exception: while a belt drag placement is in progress, right-clicking cancels that drag instead of exiting, and builder mode stays active — REQ-BLD-BELT-DRAG.)
|
||||
- REQ-BLD-GHOST: While in builder mode, a ghost of the building is rendered at the tile under the cursor, showing where it would be placed. The ghost is drawn semi-transparently in the building type's own visuals — its `fill` and `outline` colors and `glyph` from `visuals.toml` — so that different building types are visually distinguishable in builder mode rather than all looking alike. When the current cursor position is invalid, the ghost instead uses the distinct "invalid" color (REQ-BLD-PLACE-VALID), which overrides the per-building coloring.
|
||||
- REQ-BLD-GHOST: While in builder mode, a ghost of the building is rendered at the tile under the cursor, showing where it would be placed. The ghost follows the tile the cursor points at, which includes the view scrolling (REQ-UI-SCROLL) under a cursor that has not moved: the ghost then moves across the world with the scroll rather than sticking to the tile it was last placed on by a mouse move, exactly as a running selection box does (REQ-UI-MULTI-SELECT). The same holds for everything else the hovered position determines — placement validity (REQ-BLD-PLACE-VALID), the tunnel end being placed (REQ-BLD-TUNNEL-MODE), a belt drag's path (REQ-BLD-BELT-DRAG), the blueprint ghost (REQ-UI-BLUEPRINT-MODE), and the deconstruct hover (REQ-UI-DECONSTRUCT-BUTTON). A cursor that is not over the game world — resting on one of the floating panels, or outside the window — hovers nothing, so scrolling leaves that state untouched (REQ-UI-CONTROLS-PANEL). The ghost is drawn semi-transparently in the building type's own visuals — its `fill` and `outline` colors and `glyph` from `visuals.toml` — so that different building types are visually distinguishable in builder mode rather than all looking alike. When the current cursor position is invalid, the ghost instead uses the distinct "invalid" color (REQ-BLD-PLACE-VALID), which overrides the per-building coloring.
|
||||
- REQ-BLD-ROTATE: While in builder mode, pressing Shift+R rotates the ghost 90° clockwise and R rotates it 90° counter-clockwise. Rotation affects the direction of the output port.
|
||||
- REQ-BLD-PLACE: Clicking a valid tile in builder mode places a construction site and adds it to the build queue, consuming building blocks from the global stock. (For belts, placement is instead deferred to a drag gesture and happens on mouse release — REQ-BLD-BELT-DRAG.)
|
||||
- REQ-BLD-PLACE-VALID: A placement position is valid only if (a) every footprint cell in the rotated `surface_mask` is satisfied by the underlying terrain — `A` cells coincide with asteroid tiles, `S` cells coincide with space tiles — (b) no footprint cell overlaps an existing placed building or construction site, except as allowed by REQ-BLD-ROTATE-IN-PLACE (builder mode) or REQ-UI-BLUEPRINT-OVERLAP and REQ-UI-BLUEPRINT-TRANSFER (blueprint placement mode), and (c) the player has enough building blocks to afford the building. The ghost (REQ-BLD-GHOST) is rendered in a distinct "invalid" color — overriding its per-building coloring (REQ-BLD-GHOST) — when the current cursor position fails any of these conditions.
|
||||
|
||||
@@ -296,10 +296,18 @@ void GameWorldView::onFrame()
|
||||
m_camera.advance(m_panDirection, elapsed, getScrollBounds());
|
||||
|
||||
// While the view scrolls, the world position under a stationary cursor
|
||||
// changes, so refresh the box even though no mouse move fires.
|
||||
if (m_boxSelecting && viewMoved)
|
||||
// changes, so the hover state is refreshed even though no mouse move fires.
|
||||
if (viewMoved)
|
||||
{
|
||||
updateBoxDrag(mapFromGlobal(QCursor::pos()));
|
||||
const QPoint cursorWidgetPos = mapFromGlobal(QCursor::pos());
|
||||
// A running box drag holds the button and follows the cursor wherever it
|
||||
// is, the floating panels included; hover state only tracks a cursor over
|
||||
// the world, so scrolling past a cursor resting on a panel leaves the
|
||||
// ghost where it was (REQ-UI-CONTROLS-PANEL).
|
||||
if (m_boxSelecting || underMouse())
|
||||
{
|
||||
updateHoverAt(cursorWidgetPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1327,6 +1335,63 @@ void GameWorldView::selectInBox(bool additive)
|
||||
if (!additive) { m_selection.clearAll(); }
|
||||
}
|
||||
|
||||
void GameWorldView::updateHoverAt(QPoint cursorWidgetPos)
|
||||
{
|
||||
const WorldCoordinates coordinates = getCoordinates();
|
||||
const QPoint tile = coordinates.widgetToTile(cursorWidgetPos);
|
||||
m_cursorWorldPos = coordinates.widgetToWorld(cursorWidgetPos);
|
||||
|
||||
if (m_buildMode.isBuilderMode())
|
||||
{
|
||||
m_buildMode.setGhostTile(tile);
|
||||
m_buildMode.setGhostValidity(
|
||||
canPlaceBuildingHere(m_buildMode.getBuilderType(), tile,
|
||||
m_buildMode.getGhostRotation()));
|
||||
|
||||
if (m_buildMode.isTunnelMode())
|
||||
{
|
||||
// Resolve entry vs exit and the completion partner for the new hover
|
||||
// position and sub-tile cursor (REQ-BLD-TUNNEL-MODE).
|
||||
updateTunnelGhost();
|
||||
}
|
||||
|
||||
if (m_buildMode.isDraggingBelt())
|
||||
{
|
||||
// Belt drag: update the previewed path; placement happens on release
|
||||
// (REQ-BLD-BELT-DRAG).
|
||||
recomputeBeltDragPath(tile);
|
||||
}
|
||||
}
|
||||
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())
|
||||
{
|
||||
m_buildMode.setDeconstructHoverBuildingId(buildingAtTile(tile));
|
||||
if (m_boxSelecting) { updateBoxDrag(cursorWidgetPos); }
|
||||
}
|
||||
else if (m_boxSelecting)
|
||||
{
|
||||
updateBoxDrag(cursorWidgetPos);
|
||||
}
|
||||
}
|
||||
|
||||
void GameWorldView::updateBoxDrag(QPoint cursorWidgetPos)
|
||||
{
|
||||
const WorldCoordinates coordinates = getCoordinates();
|
||||
@@ -1387,59 +1452,7 @@ void GameWorldView::publishSelectionAnchor(SelectionMode mode,
|
||||
|
||||
void GameWorldView::mouseMoveEvent(QMouseEvent* event)
|
||||
{
|
||||
const WorldCoordinates coordinates = getCoordinates();
|
||||
const QPoint tile = coordinates.widgetToTile(event->pos());
|
||||
m_cursorWorldPos = coordinates.widgetToWorld(event->pos());
|
||||
|
||||
if (m_buildMode.isBuilderMode())
|
||||
{
|
||||
m_buildMode.setGhostTile(tile);
|
||||
m_buildMode.setGhostValidity(
|
||||
canPlaceBuildingHere(m_buildMode.getBuilderType(), tile,
|
||||
m_buildMode.getGhostRotation()));
|
||||
|
||||
if (m_buildMode.isTunnelMode())
|
||||
{
|
||||
// Resolve entry vs exit and the completion partner for the new hover
|
||||
// position and sub-tile cursor (REQ-BLD-TUNNEL-MODE).
|
||||
updateTunnelGhost();
|
||||
}
|
||||
|
||||
if (m_buildMode.isDraggingBelt())
|
||||
{
|
||||
// Belt drag: update the previewed path; placement happens on release
|
||||
// (REQ-BLD-BELT-DRAG).
|
||||
recomputeBeltDragPath(tile);
|
||||
}
|
||||
}
|
||||
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())
|
||||
{
|
||||
m_buildMode.setDeconstructHoverBuildingId(buildingAtTile(tile));
|
||||
if (m_boxSelecting) { updateBoxDrag(event->pos()); }
|
||||
}
|
||||
else if (m_boxSelecting)
|
||||
{
|
||||
updateBoxDrag(event->pos());
|
||||
}
|
||||
updateHoverAt(event->pos());
|
||||
}
|
||||
|
||||
void GameWorldView::mouseReleaseEvent(QMouseEvent* event)
|
||||
|
||||
@@ -226,6 +226,12 @@ private:
|
||||
// which is the only case that goes on to start a box drag.
|
||||
bool selectAtPoint(QPoint tile, QVector2D worldPos, bool additive);
|
||||
void selectInBox(bool additive);
|
||||
// Re-resolves everything that follows from where the cursor points into the world:
|
||||
// the ghost tile and its validity, the tunnel ends, a running belt or box drag, the
|
||||
// deconstruct hover. Called for every mouse move, and once per frame while the view
|
||||
// scrolls under a cursor that has not moved, since that changes the world position
|
||||
// the cursor points at just as moving the mouse does (REQ-BLD-GHOST).
|
||||
void updateHoverAt(QPoint cursorWidgetPos);
|
||||
// Moves the running box drag's far corner to the world position under
|
||||
// `cursorWidgetPos` and, once the cursor sits far enough from where the anchor is
|
||||
// drawn, promotes the gesture from a click to a drag. Every corner update goes
|
||||
|
||||
Reference in New Issue
Block a user