schematic selection dialog
This commit is contained in:
@@ -119,7 +119,7 @@ multiplied_attack_rate_hz_formula = "0.8"
|
||||
id = "laser_cannon_xs"
|
||||
unlock_at_station_level = -1
|
||||
surface_mask = ["O"]
|
||||
materials = [{item = "laser_cannon_xs_module", amount = 1}]
|
||||
materials = [{item = "iron_ore", amount = 1}]
|
||||
player_production_level = 1
|
||||
production_time_seconds = 0.5
|
||||
threat_cost = 5.0
|
||||
|
||||
@@ -5,7 +5,7 @@ layout = ["O"]
|
||||
default_modules = [{type = "laser_cannon_xs", x = 0, y = 0, rotation = "east"}]
|
||||
|
||||
[ship.schematic]
|
||||
materials = [{item = "drone_hull", amount = 1}]
|
||||
materials = [{item = "iron_ore", amount = 1}]
|
||||
player_production_level = 1
|
||||
production_time_seconds = 5
|
||||
|
||||
|
||||
@@ -60,22 +60,25 @@ Simulation types shared across subsystems:
|
||||
- `Port` — `struct Port { QPoint tile; Rotation direction; }`. Identifies a belt-adjacent cell and the direction of flow across that cell.
|
||||
- `MovementIntent` — `struct MovementIntent { int priority; QVector2D target; }`. Priority follows the order declared under Movement Arbitration. Cleared at the start of each tick; the highest-priority write wins; `tickMovement` reads the winner.
|
||||
- `FireEvent` — `struct FireEvent { EntityId shooter; EntityId target; Tick emittedAt; }`. Transient record emitted each time a weapon fires (REQ-SHP-FIRING, REQ-SHP-FIRING-BEAM). Buffered in a sim-owned queue and drained by the renderer; see Sim → UI Events.
|
||||
- `SchematicDropEvent` — `struct SchematicDropEvent { ShipSchematicId schematic; int newLevel; bool wasNewUnlock; }`. Emitted when a destroyed enemy-defence-station set awards a schematic (REQ-DEF-SCHEMATIC-DROP). The UI renders a toast (REQ-UI-SCHEMATIC-TOAST); `wasNewUnlock` chooses between the "unlocked" and "level → N" wording.
|
||||
- `SchematicChoiceOption` — `struct SchematicChoiceOption { string schematicId; SchematicType type; string displayName; bool isNewUnlock; int targetLevel; }`. Describes one option in the schematic choice dialog (REQ-DEF-SCHEMATIC-DROP). Up to three are generated when an enemy station set is destroyed. `SchematicType` is `Ship`, `Module`, or `Recipe`.
|
||||
- `SchematicChoicesAvailableEvent` — EventManager event carrying a `vector<SchematicChoiceOption>`. Sent by the UI each frame when pending choices are detected; handled by `MainWindow` which opens the schematic choice dialog.
|
||||
|
||||
## Sim → UI Events
|
||||
|
||||
The sim owns a small set of per-frame event queues that the UI drains on each render. These carry one-shot signals that are not derivable from persistent state — currently weapon fires (REQ-SHP-FIRING-BEAM) and schematic drops (REQ-UI-SCHEMATIC-TOAST). Additional event types can be added here later (e.g., building-complete, unit-death flashes) without changing the pattern.
|
||||
The sim owns a per-frame event queue for weapon fires that the UI drains on each render. `FireEvent` records are one-shot signals not derivable from persistent state. Additional one-shot event types can be added here later (e.g., building-complete, unit-death flashes) without changing the pattern.
|
||||
|
||||
Implementation: a plain `std::vector<FireEvent>` owned by `Simulation`, one vector per event type. Combat resolution (tick-order step 8) appends to it. The UI calls `simulation.drainFireEvents()` once per rendered frame, which returns the accumulated vector by move and clears the internal one. Beams are tracked by the renderer for 0.3 s of wall time (9 ticks at 30 Hz) using the events' `emittedAt` tick, then discarded. If either the shooter or target entity is gone when the renderer looks them up, the beam is dropped early.
|
||||
Implementation: a plain `std::vector<FireEvent>` owned by `Simulation`. Combat resolution (tick-order step 8) appends to it. The UI calls `simulation.drainFireEvents()` once per rendered frame, which returns the accumulated vector by move and clears the internal one. Beams are tracked by the renderer for 0.3 s of wall time (9 ticks at 30 Hz) using the events' `emittedAt` tick, then discarded. If either the shooter or target entity is gone when the renderer looks them up, the beam is dropped early.
|
||||
|
||||
We deliberately do **not** use `QObject` signals/slots or `QEvent`:
|
||||
Schematic drops use a different pattern: when an enemy station set is destroyed, the simulation generates up to 3 `SchematicChoiceOption` entries and stores them as pending state. The UI polls `hasSchematicChoicesPending()` each frame and, when true, sends a `SchematicChoicesAvailableEvent` via the EventManager. `MainWindow` handles this event by pausing the game and opening a modal `SchematicChoiceDialog`. The player's selection is fed back via `applySchematicChoice(index)`, which applies the chosen schematic and clears the pending state.
|
||||
|
||||
We deliberately do **not** use `QObject` signals/slots or `QEvent` for the fire-event queue:
|
||||
|
||||
- **Determinism.** A plain ordered vector preserves tick-order exactly; the queue is part of per-tick state, inspectable in tests.
|
||||
- **Sim/UI seam.** The sim exposes pull-style access only; the UI never subscribes into the sim, keeping the simulation/presentation split clean.
|
||||
- **Headless testability.** Catch2 tests read the queue directly after `tick()`; no event loop, no `QApplication`.
|
||||
- **Zero overhead.** Sim types remain plain structs — no `QObject`, no moc, no signal dispatch machinery.
|
||||
|
||||
If the number of event types grows past a handful, we can wrap them in a small `EventQueue<T>` template, still owned by the sim. Signals/slots would only be warranted if we needed multiple independent subscribers or cross-thread dispatch, and we need neither.
|
||||
If the number of event types grows past a handful, we can wrap them in a small `EventQueue<T>` template, still owned by the sim.
|
||||
|
||||
## Tick Order
|
||||
|
||||
@@ -89,7 +92,7 @@ Within a single simulation tick, subsystems run in this fixed order. The order i
|
||||
6. **Belt tick** — advance items along belt tiles; apply splitter routing (REQ-BLD-SPLITTER).
|
||||
7. **Ship behavior systems** — clear `MovementIntent` on each ship, then run `tickThreatResponse`, `tickScrapCollector`, `tickRepairBehavior`, `tickHomeReturn` in any order (arbitration is via intent priority).
|
||||
8. **Combat resolution** — ships and defence stations acquire targets, fire, apply damage; queue deaths. Each fire appends a `FireEvent` to the sim's fire-event queue (REQ-SHP-FIRING-BEAM).
|
||||
9. **Deaths & loot** — process queued deaths: drop scrap (REQ-RES-SCRAP-DROP); if a full enemy-defence-station set was destroyed this tick, award one schematic (REQ-DEF-SCHEMATIC-DROP) and append a `SchematicDropEvent`; remove entities.
|
||||
9. **Deaths & loot** — process queued deaths: drop scrap (REQ-RES-SCRAP-DROP); if a full enemy-defence-station set was destroyed this tick, generate up to 3 schematic choice options (REQ-DEF-SCHEMATIC-DROP) stored as pending state for the UI to present; remove entities.
|
||||
10. **`tickMovement`** — advance ship positions based on final `MovementIntent`.
|
||||
11. **Scrap despawn** — decrement scrap timers; remove expired scrap (REQ-RES-SCRAP-DROP).
|
||||
|
||||
@@ -280,7 +283,7 @@ The game world is rendered by a single `GameWorldView` widget that inherits `QOp
|
||||
|
||||
### Threading
|
||||
|
||||
Sim and UI run on the same thread for v1. `paintEvent` reads sim state directly without locks. If profiling later justifies moving the sim to a worker thread, the pull-style `drainFireEvents()` / `drainSchematicDropEvents()` / `forEachVisualItem()` APIs already support a clean snapshot-and-render split; a single mutex at the sim boundary would suffice.
|
||||
Sim and UI run on the same thread for v1. `paintEvent` reads sim state directly without locks. If profiling later justifies moving the sim to a worker thread, the pull-style `drainFireEvents()` / `getPendingSchematicChoices()` / `applySchematicChoice()` / `forEachVisualItem()` APIs already support a clean snapshot-and-render split; a single mutex at the sim boundary would suffice.
|
||||
|
||||
### Layer Order (back to front)
|
||||
|
||||
@@ -291,7 +294,7 @@ Sim and UI run on the same thread for v1. `paintEvent` reads sim state directly
|
||||
5. **Ships** — colored arrows oriented by velocity; color keyed to role (player combat / salvage / repair / enemy).
|
||||
6. **Laser beams** — lines derived from live `FireEvent`s kept by the renderer for 0.3 s (REQ-SHP-FIRING-BEAM).
|
||||
7. **Build overlays** — ghost in builder mode (REQ-BLD-GHOST), demolish-mode tint, tile highlight under cursor, box-drag selection rectangle.
|
||||
8. **Screen-space UI** — schematic toasts (REQ-UI-SCHEMATIC-TOAST) and any other screen-anchored elements, drawn after resetting the world-space transform.
|
||||
8. **Screen-space UI** — screen-anchored elements, drawn after resetting the world-space transform.
|
||||
|
||||
### Coordinates and Scrolling
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ Config files use the TOML format. The following config files drive game paramete
|
||||
- **world.toml** — world dimensions, region widths, expansion amounts, building refund percentage, wave timing, boss wave timing, enemy ship level formula, belt speed, starting building blocks, departure interval.
|
||||
- **buildings.toml** — building block cost and construction time per building type.
|
||||
- **recipes.toml** — crafting recipes: inputs, outputs, quantities, durations, and reprocessing plant probabilities. Assembler recipe entries may optionally define `unlock_at_station_level` (integer): -1 means the recipe is explicitly unlocked at game start; a value ≥ 0 means the recipe starts locked and a schematic for it can be awarded via defence station destruction (see REQ-LOCK-EXPLICIT, REQ-DEF-SCHEMATIC-DROP).
|
||||
- **ships.toml** — per schematic: a human-readable display name (used in toasts and UI), hull stats (HP, max linear speed, sensor range, main acceleration, maneuvering acceleration, angular acceleration, max rotation speed) as formulas of ship level, required build materials, threat cost formula, player production level, the station level at which the schematic becomes available for unlock (`unlock_at_station_level`; -1 means the player starts with the schematic already unlocked), a layout grid defining the ship's module slots, and a `default_modules` list used for enemy wave ships (see REQ-WAV-DEFAULT-MODULES).
|
||||
- **ships.toml** — per schematic: a human-readable display name (used in the UI), hull stats (HP, max linear speed, sensor range, main acceleration, maneuvering acceleration, angular acceleration, max rotation speed) as formulas of ship level, required build materials, threat cost formula, player production level, the station level at which the schematic becomes available for unlock (`unlock_at_station_level`; -1 means the player starts with the schematic already unlocked), a layout grid defining the ship's module slots, and a `default_modules` list used for enemy wave ships (see REQ-WAV-DEFAULT-MODULES).
|
||||
- **modules.toml** — per module type: id, surface mask, materials list, initial player production level, production time, threat cost, fill color, glyph, the station level at which the schematic becomes available for unlock (`unlock_at_station_level`; -1 means the player starts with the module schematic already unlocked), and an optional capability section and/or stat modifier formulas. A module with a capability section (`[module.weapon]`, `[module.salvage]`, or `[module.repair]`) containing base stat formulas is a **capability module** that grants the ship a weapon, salvage bay, or repair tool per instance (see REQ-MOD-CONFIG for the full list of formulas per capability type). A module with only `added_*`/`multiplied_*` formulas is a **passive module** that modifies stats on the ship or on capability module instances (see REQ-MOD-STAT-CALC).
|
||||
- **stations.toml** — HP, damage, range, fire rate, and scrap drop for player and enemy defence stations, defined as formulas of station level.
|
||||
- **visuals.toml** — rendering-only config (not game parameters): fill and outline colors and glyphs for every building type, item type, ship schematic, and station type; beam color and width; overlay and toast colors. Loaded by the UI at startup; the simulation does not read it.
|
||||
@@ -169,7 +169,7 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
|
||||
Each repair module instance operates independently: it has its own repair rate (`repair_rate`) and repair range (`repair_range`). On each tick, a module first attempts to heal the ship's current behavior-level navigation target if that target is within the module's `repair_range` and is damaged (HP above zero and below maximum HP). If those conditions are not met — because the target is out of the module's `repair_range`, already at full health, or destroyed — the module independently searches for the nearest damaged friendly (player ship or player defence station) within its own `repair_range` and heals that instead. If no valid target is found within range, the module idles. A ship with multiple repair modules can therefore heal different targets simultaneously. Navigation is driven solely by the behavior-level target; individual module fallback targets do not affect which direction the ship moves.
|
||||
- REQ-SHP-ENEMY-AI: **Enemy ships** — engage the closest valid target (player defence station, HQ, or player ship) within their sensor range. If no target is in sensor range, they move toward the asteroid (leftward in world coordinates).
|
||||
- REQ-SHP-SCHEMATICS: The player selects a schematic per shipyard by clicking it. New schematics are unlocked automatically when an enemy defence station set is destroyed (REQ-DEF-SCHEMATIC-DROP) — there is no physical loot to collect.
|
||||
- REQ-SHP-SCHEMATICS: The player selects a schematic per shipyard by clicking it. New schematics are unlocked by destroying enemy defence station sets (REQ-DEF-SCHEMATIC-DROP) — there is no physical loot to collect.
|
||||
|
||||
## Ship Modules
|
||||
|
||||
@@ -270,13 +270,17 @@ Modules in `modules.toml` define a `surface_mask` — a list of strings that des
|
||||
- REQ-DEF-ENEMY-FIRE: Enemy defence stations automatically fire at player ships within range.
|
||||
- REQ-DEF-NO-CROSSFIRE: Enemy and player defence stations are never in each other's firing range.
|
||||
- REQ-DEF-PUSH: When both enemy defence stations in a set are destroyed, the boss countdown is advanced (REQ-WAV-BOSS-ADVANCE), the scrollable area is extended (REQ-GW-PUSH-EXPAND), a new set of enemy defence stations is placed at the new boundary, and exactly one schematic drop is awarded for the destroyed set (REQ-DEF-SCHEMATIC-DROP).
|
||||
- REQ-DEF-SCHEMATIC-DROP: Each destroyed set of enemy defence stations awards exactly one schematic drop (not one per station). The drop is automatic — no physical item to collect. A schematic is chosen uniformly at random from the eligible drop pool, which contains:
|
||||
- REQ-DEF-SCHEMATIC-DROP: Each destroyed set of enemy defence stations awards exactly one schematic drop (not one per station). The drop opens a **schematic choice dialog** — a modal dialog that pauses the game (speed set to 0×; on close, speed is restored to what it was before the dialog opened). Up to three schematic options are drawn uniformly at random **without replacement** from the eligible drop pool. If the pool contains fewer than three entries, only that many options are shown. The eligible drop pool contains:
|
||||
- All **ship schematics** and **module schematics** whose `unlock_at_station_level` is -1 or is ≤ the level of the destroyed station set.
|
||||
- All **assembler recipe schematics** whose `unlock_at_station_level` is ≥ 0 and ≤ the level of the destroyed station set, whose output item is currently implicitly unlocked (REQ-LOCK-IMPLICIT), and which have not yet been awarded.
|
||||
|
||||
For a **ship or module schematic** drop: if the player does not yet have the schematic, it is unlocked (ship schematics unlock the corresponding shipyard selection; module schematics unlock the module type for placement in the layout configuration dialog (REQ-MOD-UI-DIALOG)). If the player already has it, the schematic's `player_production_level` is incremented by 1 — for ship schematics, subsequent ships of that type are produced at a higher level; for module schematics, all instances of that module type use the higher level in their stat formulas. The player is notified via a toast (REQ-UI-SCHEMATIC-TOAST).
|
||||
Each option in the dialog displays: the schematic name (ship `display_name` from `ships.toml`, module `id` from `modules.toml`, or the output item type for assembler recipes), the schematic type (ship, module, or assembler recipe), and whether selecting it would be a **new unlock** or a **level-up** (showing the target level for level-ups). Assembler recipe schematics are always new unlocks since they are removed from the pool once awarded.
|
||||
|
||||
For an **assembler recipe schematic** drop: the recipe is explicitly unlocked and becomes available in the assembler recipe-selection dropdown (subject to REQ-LOCK-UI-RECIPE). The schematic is removed from the drop pool permanently (REQ-LOCK-EXPLICIT). The implicit unlock set is recomputed (REQ-LOCK-IMPLICIT). No toast is shown.
|
||||
The player selects one option by clicking it. The selected schematic is applied and the dialog closes:
|
||||
|
||||
For a **ship or module schematic**: if the player does not yet have the schematic, it is unlocked (ship schematics unlock the corresponding shipyard selection; module schematics unlock the module type for placement in the layout configuration dialog (REQ-MOD-UI-DIALOG)). If the player already has it, the schematic's `player_production_level` is incremented by 1 — for ship schematics, subsequent ships of that type are produced at a higher level; for module schematics, all instances of that module type use the higher level in their stat formulas.
|
||||
|
||||
For an **assembler recipe schematic**: the recipe is explicitly unlocked and becomes available in the assembler recipe-selection dropdown (subject to REQ-LOCK-UI-RECIPE). The schematic is removed from the drop pool permanently (REQ-LOCK-EXPLICIT). The implicit unlock set is recomputed (REQ-LOCK-IMPLICIT).
|
||||
|
||||
## Progression & Locking
|
||||
|
||||
@@ -354,13 +358,6 @@ The screen is divided into three vertical sections:
|
||||
- REQ-UI-PORT-GLYPH: Every output port of every building is indicated by a directional glyph drawn on the port's tile. The glyph is a `>` rotated to face the port's exit direction (`>` for East, `^` for North, `<` for West, `v` for South). It is drawn at the midpoint between the tile center and the tile edge that the port exits through (i.e. halfway from center toward the exit edge). The indicator is rendered for all building states: operational buildings, construction sites, and the builder-mode ghost. Buildings with multiple output ports (e.g. splitters) show one indicator per port.
|
||||
- REQ-UI-HP-BARS: All entities with HP — the HQ, player and enemy defence stations, and player and enemy ships — render an HP bar below them. The bar is always visible regardless of current HP. The bar's filled portion represents the fraction of current HP to maximum HP.
|
||||
- REQ-UI-NO-ZOOM: The view has a fixed zoom level; the player cannot zoom in or out.
|
||||
- REQ-UI-SCHEMATIC-TOAST: When a schematic is unlocked or leveled up (REQ-DEF-SCHEMATIC-DROP), a transient notification toast appears in the top-right corner of the game world view for 4 seconds and then fades out. Toast text:
|
||||
- **Ship schematic — new unlock**: `Schematic unlocked: <Ship Name>` (where `<Ship Name>` is `ships.toml [ship.schematic].display_name`).
|
||||
- **Ship schematic — level-up (duplicate drop)**: `<Ship Name> production level → N` (where N is the new level).
|
||||
- **Module schematic — new unlock**: `Module unlocked: <Module Id>` (where `<Module Id>` is the module's `id` from `modules.toml`).
|
||||
- **Module schematic — level-up (duplicate drop)**: `<Module Id> production level → N` (where N is the new level).
|
||||
|
||||
If multiple toasts arrive in close succession, they stack vertically in a queue (most recent at the top) and each fades out independently after its own 4-second lifetime.
|
||||
- REQ-UI-HOTKEYS: Global keyboard shortcuts:
|
||||
- **Space** — toggles pause. Pressing Space pauses (sets speed to 0×) and stores the previously selected non-zero speed; pressing Space again restores that speed.
|
||||
- **W** — increases game speed by one step in the sequence 0×, 0.5×, 1×, 2×, 4× (no wrap-around past 4×).
|
||||
|
||||
@@ -10,7 +10,8 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ItemType.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Item.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Port.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicDropEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicChoiceOption.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DisplayName.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -18,6 +19,7 @@ SET(SRCS
|
||||
${SRCS}
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BuildingType.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntityAdmin.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/DisplayName.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
|
||||
27
src/lib/core/DisplayName.cpp
Normal file
27
src/lib/core/DisplayName.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "DisplayName.h"
|
||||
|
||||
#include <cctype>
|
||||
|
||||
std::string toDisplayName(const std::string& id)
|
||||
{
|
||||
std::string result;
|
||||
bool nextUpper = true;
|
||||
for (char c : id)
|
||||
{
|
||||
if (c == '_')
|
||||
{
|
||||
result += ' ';
|
||||
nextUpper = true;
|
||||
}
|
||||
else if (nextUpper)
|
||||
{
|
||||
result += static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
nextUpper = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
5
src/lib/core/DisplayName.h
Normal file
5
src/lib/core/DisplayName.h
Normal file
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string toDisplayName(const std::string& id);
|
||||
22
src/lib/core/SchematicChoiceOption.h
Normal file
22
src/lib/core/SchematicChoiceOption.h
Normal file
@@ -0,0 +1,22 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
enum class SchematicType
|
||||
{
|
||||
Ship,
|
||||
Module,
|
||||
Recipe
|
||||
};
|
||||
|
||||
// One option presented to the player in the schematic choice dialog
|
||||
// (REQ-DEF-SCHEMATIC-DROP). Built by the simulation when enemy stations are
|
||||
// destroyed; the UI reads these to populate the dialog.
|
||||
struct SchematicChoiceOption
|
||||
{
|
||||
std::string schematicId;
|
||||
SchematicType type;
|
||||
std::string displayName;
|
||||
bool isNewUnlock;
|
||||
int targetLevel;
|
||||
};
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
// Emitted in tick step 9 (Deaths & loot) when a destroyed enemy-defence-station
|
||||
// set awards a schematic (REQ-DEF-SCHEMATIC-DROP). The UI renders a toast
|
||||
// (REQ-UI-SCHEMATIC-TOAST); wasNewUnlock chooses between the "unlocked" and
|
||||
// "level -> N" wording. isModuleSchematic selects ship vs. module toast text.
|
||||
struct SchematicDropEvent
|
||||
{
|
||||
std::string schematicId; // matches ShipDef::id or ModuleDef::id in the config.
|
||||
int newLevel;
|
||||
bool wasNewUnlock;
|
||||
bool isModuleSchematic;
|
||||
};
|
||||
@@ -6,6 +6,7 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/EntitySelectedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/GameSpeedChangedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/BossWaveUpdatedEvent.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicChoicesAvailableEvent.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
|
||||
14
src/lib/eventsystem/event/SchematicChoicesAvailableEvent.h
Normal file
14
src/lib/eventsystem/event/SchematicChoicesAvailableEvent.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "Event.h"
|
||||
#include "SchematicChoiceOption.h"
|
||||
|
||||
class SchematicChoicesAvailableEvent : public Event
|
||||
{
|
||||
public:
|
||||
explicit SchematicChoicesAvailableEvent(std::vector<SchematicChoiceOption> choices)
|
||||
: choices(std::move(choices)) {}
|
||||
const std::vector<SchematicChoiceOption> choices;
|
||||
};
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "Simulation.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
#include "AiSystem.h"
|
||||
#include "DisplayName.h"
|
||||
#include "BuildingSystem.h"
|
||||
#include "CombatSystem.h"
|
||||
#include "DynamicBodySystem.h"
|
||||
@@ -135,7 +137,7 @@ void Simulation::reset(unsigned int seed)
|
||||
m_currentEnemyStationEntities[0] = entt::null;
|
||||
m_currentEnemyStationEntities[1] = entt::null;
|
||||
m_fireEvents.clear();
|
||||
m_schematicDropEvents.clear();
|
||||
m_pendingSchematicChoices.clear();
|
||||
|
||||
m_admin.clear();
|
||||
m_beltSystem = BeltSystem(m_config.world.beltSpeed_tps);
|
||||
@@ -532,11 +534,11 @@ void Simulation::tickDeathsAndLoot()
|
||||
const int destroyedLevel = m_waveSystem->generation();
|
||||
m_waveSystem->onEnemyStationsDestroyed();
|
||||
placeEnemyStationSet(m_waveSystem->generation());
|
||||
awardSchematicDrop(destroyedLevel);
|
||||
generateSchematicChoices(destroyedLevel);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::awardSchematicDrop(int destroyedStationLevel)
|
||||
void Simulation::generateSchematicChoices(int destroyedStationLevel)
|
||||
{
|
||||
enum class DropType { Ship, Module, Recipe };
|
||||
struct PoolEntry { std::string id; DropType type; };
|
||||
@@ -572,32 +574,78 @@ void Simulation::awardSchematicDrop(int destroyedStationLevel)
|
||||
pool.push_back({def.id, DropType::Recipe});
|
||||
}
|
||||
|
||||
std::uniform_int_distribution<int> dist(0, static_cast<int>(pool.size()) - 1);
|
||||
const PoolEntry& chosen = pool[static_cast<std::size_t>(dist(m_rng))];
|
||||
if (pool.empty()) { return; }
|
||||
|
||||
if (chosen.type == DropType::Recipe)
|
||||
const int numChoices = std::min(static_cast<int>(pool.size()), 3);
|
||||
m_pendingSchematicChoices.clear();
|
||||
|
||||
for (int i = 0; i < numChoices; ++i)
|
||||
{
|
||||
m_unlockedRecipeSchematicIds.insert(chosen.id);
|
||||
recomputeUnlocked();
|
||||
std::uniform_int_distribution<int> dist(0, static_cast<int>(pool.size()) - 1 - i);
|
||||
const int roll = dist(m_rng);
|
||||
const std::size_t rollIdx = static_cast<std::size_t>(roll);
|
||||
const std::size_t endIdx = pool.size() - 1 - static_cast<std::size_t>(i);
|
||||
std::swap(pool[rollIdx], pool[endIdx]);
|
||||
const PoolEntry& entry = pool[endIdx];
|
||||
|
||||
SchematicChoiceOption option;
|
||||
option.schematicId = entry.id;
|
||||
|
||||
if (entry.type == DropType::Ship)
|
||||
{
|
||||
option.type = SchematicType::Ship;
|
||||
option.displayName = toDisplayName(entry.id);
|
||||
const SchematicState& state = m_schematicLevels.at(entry.id);
|
||||
option.isNewUnlock = !state.unlocked;
|
||||
option.targetLevel = state.level + 1;
|
||||
}
|
||||
else if (entry.type == DropType::Module)
|
||||
{
|
||||
option.type = SchematicType::Module;
|
||||
option.displayName = toDisplayName(entry.id);
|
||||
const SchematicState& state = m_moduleSchematicLevels.at(entry.id);
|
||||
option.isNewUnlock = !state.unlocked;
|
||||
option.targetLevel = state.level + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
option.type = SchematicType::Recipe;
|
||||
option.isNewUnlock = true;
|
||||
option.targetLevel = 0;
|
||||
for (const RecipeDef& def : m_config.recipes.recipes)
|
||||
{
|
||||
if (def.id == entry.id && !def.outputs.empty())
|
||||
{
|
||||
option.displayName = toDisplayName(def.outputs[0].item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_pendingSchematicChoices.push_back(option);
|
||||
}
|
||||
}
|
||||
|
||||
void Simulation::applySchematicChoice(int choiceIndex)
|
||||
{
|
||||
assert(choiceIndex >= 0 && choiceIndex < static_cast<int>(m_pendingSchematicChoices.size()));
|
||||
const SchematicChoiceOption& chosen = m_pendingSchematicChoices[static_cast<std::size_t>(choiceIndex)];
|
||||
|
||||
if (chosen.type == SchematicType::Recipe)
|
||||
{
|
||||
m_unlockedRecipeSchematicIds.insert(chosen.schematicId);
|
||||
}
|
||||
else
|
||||
{
|
||||
SchematicState& state = (chosen.type == DropType::Module)
|
||||
? m_moduleSchematicLevels.at(chosen.id)
|
||||
: m_schematicLevels.at(chosen.id);
|
||||
const bool wasNew = !state.unlocked;
|
||||
SchematicState& state = (chosen.type == SchematicType::Module)
|
||||
? m_moduleSchematicLevels.at(chosen.schematicId)
|
||||
: m_schematicLevels.at(chosen.schematicId);
|
||||
state.unlocked = true;
|
||||
state.level += 1;
|
||||
|
||||
SchematicDropEvent evt;
|
||||
evt.schematicId = chosen.id;
|
||||
evt.newLevel = state.level;
|
||||
evt.wasNewUnlock = wasNew;
|
||||
evt.isModuleSchematic = (chosen.type == DropType::Module);
|
||||
m_schematicDropEvents.push_back(evt);
|
||||
|
||||
recomputeUnlocked();
|
||||
}
|
||||
|
||||
recomputeUnlocked();
|
||||
m_pendingSchematicChoices.clear();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -704,13 +752,17 @@ std::vector<FireEvent> Simulation::drainFireEvents()
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<SchematicDropEvent> Simulation::drainSchematicDropEvents()
|
||||
const std::vector<SchematicChoiceOption>& Simulation::getPendingSchematicChoices() const
|
||||
{
|
||||
std::vector<SchematicDropEvent> result;
|
||||
result.swap(m_schematicDropEvents);
|
||||
return result;
|
||||
return m_pendingSchematicChoices;
|
||||
}
|
||||
|
||||
bool Simulation::hasSchematicChoicesPending() const
|
||||
{
|
||||
return !m_pendingSchematicChoices.empty();
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Accessors
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "BeltSystem.h"
|
||||
#include "EntityAdmin.h"
|
||||
#include "entt/entity/entity.hpp"
|
||||
#include "SchematicDropEvent.h"
|
||||
#include "SchematicChoiceOption.h"
|
||||
#include "BuildingType.h"
|
||||
#include "BuildingId.h"
|
||||
#include "EventHandler.h"
|
||||
@@ -52,8 +52,16 @@ public:
|
||||
// internal queue. Call once per rendered frame (REQ-SHP-FIRING-BEAM).
|
||||
std::vector<FireEvent> drainFireEvents();
|
||||
|
||||
// Returns all schematic drop events since the last drain.
|
||||
std::vector<SchematicDropEvent> drainSchematicDropEvents();
|
||||
// Returns the pending schematic choices (empty if no drop is pending).
|
||||
const std::vector<SchematicChoiceOption>& getPendingSchematicChoices() const;
|
||||
|
||||
// Returns true if there are pending schematic choices waiting for player input.
|
||||
bool hasSchematicChoicesPending() const;
|
||||
|
||||
// Applies the player's chosen schematic from the pending choices.
|
||||
// choiceIndex must be in [0, pendingChoices.size()).
|
||||
// Clears the pending choices after application.
|
||||
void applySchematicChoice(int choiceIndex);
|
||||
|
||||
Tick currentTick() const;
|
||||
int buildingBlocksStock() const;
|
||||
@@ -108,8 +116,8 @@ private:
|
||||
// Tick step 9: remove dead ships and buildings, drop scrap, handle push.
|
||||
void tickDeathsAndLoot();
|
||||
|
||||
// Award a random schematic drop (REQ-DEF-SCHEMATIC-DROP) and emit the event.
|
||||
void awardSchematicDrop(int destroyedStationLevel);
|
||||
// Generate up to 3 schematic choices (REQ-DEF-SCHEMATIC-DROP) for the player.
|
||||
void generateSchematicChoices(int destroyedStationLevel);
|
||||
|
||||
GameConfig m_config;
|
||||
std::mt19937 m_rng;
|
||||
@@ -158,5 +166,5 @@ private:
|
||||
std::unique_ptr<CombatSystem> m_combatSystem;
|
||||
|
||||
std::vector<FireEvent> m_fireEvents;
|
||||
std::vector<SchematicDropEvent> m_schematicDropEvents;
|
||||
std::vector<SchematicChoiceOption> m_pendingSchematicChoices;
|
||||
};
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "GameConfig.h"
|
||||
#include "HealthComponent.h"
|
||||
#include "RecipesConfig.h"
|
||||
#include "SchematicChoiceOption.h"
|
||||
#include "Simulation.h"
|
||||
#include "StationBodyComponent.h"
|
||||
|
||||
@@ -16,7 +17,7 @@ static GameConfig loadConfig()
|
||||
}
|
||||
|
||||
// Zeros the HP of both enemy defence stations and advances one tick so that
|
||||
// tickDeathsAndLoot fires, triggering the push and schematic drop.
|
||||
// tickDeathsAndLoot fires, triggering the push and schematic choices.
|
||||
static void killEnemyStations(Simulation& sim)
|
||||
{
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
@@ -30,15 +31,25 @@ static void killEnemyStations(Simulation& sim)
|
||||
sim.tick();
|
||||
}
|
||||
|
||||
// Kills enemy stations and applies the first schematic choice (index 0).
|
||||
static void killEnemyStationsAndApply(Simulation& sim)
|
||||
{
|
||||
killEnemyStations(sim);
|
||||
if (sim.hasSchematicChoicesPending())
|
||||
{
|
||||
sim.applySchematicChoice(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Destroys station sets until recipeId is unlocked or maxDestructions is reached.
|
||||
// Returns true if the recipe is unlocked on exit.
|
||||
// Applies schematic choice 0 after each destruction. Returns true if unlocked.
|
||||
static bool awaitRecipeUnlock(Simulation& sim, const std::string& recipeId,
|
||||
int maxDestructions = 150)
|
||||
{
|
||||
for (int i = 0; i < maxDestructions; ++i)
|
||||
{
|
||||
if (sim.isRecipeUnlocked(recipeId)) { return true; }
|
||||
killEnemyStations(sim);
|
||||
killEnemyStationsAndApply(sim);
|
||||
}
|
||||
return sim.isRecipeUnlocked(recipeId);
|
||||
}
|
||||
@@ -175,7 +186,7 @@ TEST_CASE("RecipeSchematic: recipe whose output is not implicitly unlocked is ne
|
||||
Simulation sim(loadConfig());
|
||||
for (int i = 0; i < 50; ++i)
|
||||
{
|
||||
killEnemyStations(sim);
|
||||
killEnemyStationsAndApply(sim);
|
||||
}
|
||||
REQUIRE_FALSE(sim.isRecipeUnlocked("exotic_alloy"));
|
||||
}
|
||||
@@ -186,7 +197,7 @@ TEST_CASE("RecipeSchematic: recipe with level > destroyed station level is not a
|
||||
// advanced_circuit has unlock_at_station_level = 1. Destroying a single
|
||||
// level-0 station set must not award it regardless of the RNG outcome.
|
||||
Simulation sim(loadConfig());
|
||||
killEnemyStations(sim);
|
||||
killEnemyStationsAndApply(sim);
|
||||
REQUIRE_FALSE(sim.isRecipeUnlocked("advanced_circuit"));
|
||||
}
|
||||
|
||||
@@ -209,25 +220,35 @@ TEST_CASE("RecipeSchematic: awarded recipe schematic stays unlocked and is not a
|
||||
// Destroy 30 more station sets; the recipe is no longer in the pool.
|
||||
for (int i = 0; i < 30; ++i)
|
||||
{
|
||||
killEnemyStations(sim);
|
||||
killEnemyStationsAndApply(sim);
|
||||
}
|
||||
|
||||
REQUIRE(sim.isRecipeUnlocked("quick_circuit"));
|
||||
}
|
||||
|
||||
TEST_CASE("RecipeSchematic: no SchematicDropEvent is emitted for a recipe schematic drop",
|
||||
TEST_CASE("RecipeSchematic: recipe schematic can appear in pending choices",
|
||||
"[recipe_schematic]")
|
||||
{
|
||||
Simulation sim(loadConfig());
|
||||
sim.drainSchematicDropEvents(); // clear any startup events
|
||||
|
||||
awaitRecipeUnlock(sim, "quick_circuit");
|
||||
|
||||
const std::vector<SchematicDropEvent> events = sim.drainSchematicDropEvents();
|
||||
for (const SchematicDropEvent& ev : events)
|
||||
bool foundRecipeChoice = false;
|
||||
for (int i = 0; i < 150 && !foundRecipeChoice; ++i)
|
||||
{
|
||||
CHECK(ev.schematicId != "quick_circuit");
|
||||
killEnemyStations(sim);
|
||||
if (sim.hasSchematicChoicesPending())
|
||||
{
|
||||
for (const SchematicChoiceOption& opt : sim.getPendingSchematicChoices())
|
||||
{
|
||||
if (opt.type == SchematicType::Recipe)
|
||||
{
|
||||
foundRecipeChoice = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
sim.applySchematicChoice(0);
|
||||
}
|
||||
}
|
||||
CHECK(foundRecipeChoice);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -61,11 +61,11 @@ TEST_CASE("Simulation::drainFireEvents clears queue on drain", "[simulation]")
|
||||
REQUIRE(sim.drainFireEvents().empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Simulation::drainSchematicDropEvents returns empty initially", "[simulation]")
|
||||
TEST_CASE("Simulation::hasSchematicChoicesPending returns false initially", "[simulation]")
|
||||
{
|
||||
Simulation sim(loadConfig());
|
||||
|
||||
REQUIRE(sim.drainSchematicDropEvents().empty());
|
||||
REQUIRE_FALSE(sim.hasSchematicChoicesPending());
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
#include "StationBodyComponent.h"
|
||||
#include "WeaponComponent.h"
|
||||
#include "ModulesConfig.h"
|
||||
#include "RecipesConfig.h"
|
||||
#include "SchematicChoiceOption.h"
|
||||
#include "ShipsConfig.h"
|
||||
#include "Simulation.h"
|
||||
#include "Tick.h"
|
||||
@@ -247,7 +249,7 @@ TEST_CASE("WaveSystem: destroying both enemy stations triggers a push", "[wave]"
|
||||
REQUIRE(enemyCount == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("WaveSystem: push emits exactly one SchematicDropEvent", "[wave]")
|
||||
TEST_CASE("WaveSystem: push generates pending schematic choices", "[wave]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
@@ -259,11 +261,13 @@ TEST_CASE("WaveSystem: push emits exactly one SchematicDropEvent", "[wave]")
|
||||
|
||||
sim.tick();
|
||||
|
||||
const std::vector<SchematicDropEvent> events = sim.drainSchematicDropEvents();
|
||||
REQUIRE(events.size() == 1);
|
||||
REQUIRE(sim.hasSchematicChoicesPending());
|
||||
const std::vector<SchematicChoiceOption>& choices = sim.getPendingSchematicChoices();
|
||||
REQUIRE(choices.size() >= 1);
|
||||
REQUIRE(choices.size() <= 3);
|
||||
}
|
||||
|
||||
TEST_CASE("WaveSystem: push schematic drop awards a known ship id", "[wave]")
|
||||
TEST_CASE("WaveSystem: push schematic choices have valid ids", "[wave]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
@@ -274,23 +278,68 @@ TEST_CASE("WaveSystem: push schematic drop awards a known ship id", "[wave]")
|
||||
});
|
||||
|
||||
sim.tick();
|
||||
const std::vector<SchematicDropEvent> events = sim.drainSchematicDropEvents();
|
||||
REQUIRE(events.size() == 1);
|
||||
const std::vector<SchematicChoiceOption>& choices = sim.getPendingSchematicChoices();
|
||||
REQUIRE_FALSE(choices.empty());
|
||||
|
||||
bool validId = false;
|
||||
for (const ShipDef& def : sim.config().ships.ships)
|
||||
for (const SchematicChoiceOption& opt : choices)
|
||||
{
|
||||
if (def.id == events[0].schematicId) { validId = true; break; }
|
||||
}
|
||||
if (!validId)
|
||||
{
|
||||
for (const ModuleDef& def : sim.config().modules.modules)
|
||||
bool validId = false;
|
||||
for (const ShipDef& def : sim.config().ships.ships)
|
||||
{
|
||||
if (def.id == events[0].schematicId) { validId = true; break; }
|
||||
if (def.id == opt.schematicId) { validId = true; break; }
|
||||
}
|
||||
if (!validId)
|
||||
{
|
||||
for (const ModuleDef& def : sim.config().modules.modules)
|
||||
{
|
||||
if (def.id == opt.schematicId) { validId = true; break; }
|
||||
}
|
||||
}
|
||||
if (!validId)
|
||||
{
|
||||
for (const RecipeDef& def : sim.config().recipes.recipes)
|
||||
{
|
||||
if (def.id == opt.schematicId) { validId = true; break; }
|
||||
}
|
||||
}
|
||||
REQUIRE(validId);
|
||||
}
|
||||
REQUIRE(validId);
|
||||
REQUIRE(events[0].newLevel >= 1);
|
||||
}
|
||||
|
||||
TEST_CASE("WaveSystem: schematic choices have no duplicates", "[wave]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
[](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f, HealthComponent& h)
|
||||
{
|
||||
if (f.isEnemy) { h.hp = -1.0f; }
|
||||
});
|
||||
|
||||
sim.tick();
|
||||
const std::vector<SchematicChoiceOption>& choices = sim.getPendingSchematicChoices();
|
||||
std::set<std::string> ids;
|
||||
for (const SchematicChoiceOption& opt : choices)
|
||||
{
|
||||
ids.insert(opt.schematicId);
|
||||
}
|
||||
REQUIRE(ids.size() == choices.size());
|
||||
}
|
||||
|
||||
TEST_CASE("WaveSystem: applySchematicChoice clears pending and applies", "[wave]")
|
||||
{
|
||||
Simulation sim(loadConfig(), 42);
|
||||
|
||||
sim.admin().forEach<StationBodyComponent, FactionComponent, HealthComponent>(
|
||||
[](entt::entity /*e*/, const StationBodyComponent& /*sb*/, const FactionComponent& f, HealthComponent& h)
|
||||
{
|
||||
if (f.isEnemy) { h.hp = -1.0f; }
|
||||
});
|
||||
|
||||
sim.tick();
|
||||
REQUIRE(sim.hasSchematicChoicesPending());
|
||||
sim.applySchematicChoice(0);
|
||||
REQUIRE_FALSE(sim.hasSchematicChoicesPending());
|
||||
}
|
||||
|
||||
TEST_CASE("WaveSystem: push places new enemy stations further right", "[wave]")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "BuildButtonGrid.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
|
||||
#include <QGridLayout>
|
||||
@@ -8,35 +7,7 @@
|
||||
#include <QSignalMapper>
|
||||
|
||||
#include "BuildingType.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
QString displayName(const std::string& id)
|
||||
{
|
||||
QString result;
|
||||
bool nextUpper = true;
|
||||
for (char c : id)
|
||||
{
|
||||
if (c == '_')
|
||||
{
|
||||
result += ' ';
|
||||
nextUpper = true;
|
||||
}
|
||||
else if (nextUpper)
|
||||
{
|
||||
result += static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
nextUpper = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
#include "DisplayName.h"
|
||||
|
||||
|
||||
BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
|
||||
@@ -62,7 +33,7 @@ BuildButtonGrid::BuildButtonGrid(const GameConfig* config, QWidget* parent)
|
||||
m_types.push_back(def.type);
|
||||
m_costs[def.type] = def.cost;
|
||||
|
||||
const QString label = displayName(def.id)
|
||||
const QString label = QString::fromStdString(toDisplayName(def.id))
|
||||
+ "\n" + tr("%1 Blocks").arg(def.cost);
|
||||
QPushButton* btn = new QPushButton(label, this);
|
||||
btn->setCheckable(true);
|
||||
|
||||
@@ -11,6 +11,7 @@ SET(HDRS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipLayoutDialog.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipLayoutPreview.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipStatsPanel.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicChoiceDialog.h
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -26,5 +27,6 @@ SET(SRCS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipLayoutDialog.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipLayoutPreview.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ShipStatsPanel.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/SchematicChoiceDialog.cpp
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "BossWaveUpdatedEvent.h"
|
||||
#include "BuildingBlocksChangedEvent.h"
|
||||
#include "GameSpeedChangedEvent.h"
|
||||
#include "SchematicChoicesAvailableEvent.h"
|
||||
#include "TickAdvancedEvent.h"
|
||||
|
||||
namespace
|
||||
@@ -68,31 +69,6 @@ Rotation rotateCounterClockwise(Rotation r)
|
||||
return Rotation::East;
|
||||
}
|
||||
|
||||
|
||||
QString toDisplayName(const std::string& id)
|
||||
{
|
||||
QString result;
|
||||
bool nextUpper = true;
|
||||
for (char c : id)
|
||||
{
|
||||
if (c == '_')
|
||||
{
|
||||
result += ' ';
|
||||
nextUpper = true;
|
||||
}
|
||||
else if (nextUpper)
|
||||
{
|
||||
result += static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
nextUpper = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QPoint portBodyTile(QPoint portTile, Rotation direction)
|
||||
{
|
||||
switch (direction)
|
||||
@@ -129,6 +105,7 @@ GameWorldView::GameWorldView(Simulation* sim, const GameConfig* config,
|
||||
, m_scrollLeft(false)
|
||||
, m_scrollRight(false)
|
||||
, m_gameOverShown(false)
|
||||
, m_schematicChoiceShown(false)
|
||||
{
|
||||
setFocusPolicy(Qt::StrongFocus);
|
||||
setMouseTracking(true);
|
||||
@@ -188,31 +165,6 @@ void GameWorldView::onFrame()
|
||||
}
|
||||
}
|
||||
|
||||
// Drain schematic drop events → toasts
|
||||
{
|
||||
const std::vector<SchematicDropEvent> drops =
|
||||
m_sim->drainSchematicDropEvents();
|
||||
for (const SchematicDropEvent& ev : drops)
|
||||
{
|
||||
const QString name = toDisplayName(ev.schematicId);
|
||||
ToastEntry toast;
|
||||
if (ev.isModuleSchematic)
|
||||
{
|
||||
toast.text = ev.wasNewUnlock
|
||||
? tr("Module unlocked: ") + name
|
||||
: name + tr(" production level -> ") + QString::number(ev.newLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
toast.text = ev.wasNewUnlock
|
||||
? tr("Schematic unlocked: ") + name
|
||||
: name + tr(" production level -> ") + QString::number(ev.newLevel);
|
||||
}
|
||||
toast.createdWallMs = m_wallMs;
|
||||
m_toasts.push_back(toast);
|
||||
}
|
||||
}
|
||||
|
||||
// Expire old beams
|
||||
{
|
||||
std::vector<ActiveBeam> live;
|
||||
@@ -226,19 +178,6 @@ void GameWorldView::onFrame()
|
||||
m_activeBeams = std::move(live);
|
||||
}
|
||||
|
||||
// Expire old toasts
|
||||
{
|
||||
std::vector<ToastEntry> live;
|
||||
for (const ToastEntry& t : m_toasts)
|
||||
{
|
||||
if (m_wallMs - t.createdWallMs < kToastLifetimeMs)
|
||||
{
|
||||
live.push_back(t);
|
||||
}
|
||||
}
|
||||
m_toasts = std::move(live);
|
||||
}
|
||||
|
||||
// Apply held scroll
|
||||
{
|
||||
const float delta = kScrollSpeedTilesPerSec
|
||||
@@ -276,6 +215,18 @@ void GameWorldView::onFrame()
|
||||
}
|
||||
}
|
||||
|
||||
// Schematic choice available
|
||||
if (m_sim->hasSchematicChoicesPending() && !m_schematicChoiceShown)
|
||||
{
|
||||
m_schematicChoiceShown = true;
|
||||
EventManager::getInstance()->sendEventImmediately(
|
||||
std::make_shared<SchematicChoicesAvailableEvent>(m_sim->getPendingSchematicChoices()));
|
||||
}
|
||||
if (!m_sim->hasSchematicChoicesPending())
|
||||
{
|
||||
m_schematicChoiceShown = false;
|
||||
}
|
||||
|
||||
// Game over check
|
||||
if (m_sim->isGameOver() && !m_gameOverShown)
|
||||
{
|
||||
@@ -1097,41 +1048,8 @@ void GameWorldView::drawOverlays(QPainter& painter)
|
||||
}
|
||||
}
|
||||
|
||||
void GameWorldView::drawScreenSpace(QPainter& painter)
|
||||
void GameWorldView::drawScreenSpace(QPainter& /*painter*/)
|
||||
{
|
||||
painter.resetTransform();
|
||||
|
||||
const int margin = 8;
|
||||
const int toastW = 320;
|
||||
const int toastH = 36;
|
||||
const int spacing = 4;
|
||||
|
||||
QFont toastFont = painter.font();
|
||||
toastFont.setPointSize(m_visuals->toast.fontSize);
|
||||
painter.setFont(toastFont);
|
||||
|
||||
int y = margin;
|
||||
for (const ToastEntry& toast : m_toasts)
|
||||
{
|
||||
const qint64 age = m_wallMs - toast.createdWallMs;
|
||||
double opacity = 1.0;
|
||||
if (age > kToastFadeStartMs)
|
||||
{
|
||||
opacity = 1.0 - static_cast<double>(age - kToastFadeStartMs)
|
||||
/ static_cast<double>(kToastLifetimeMs - kToastFadeStartMs);
|
||||
opacity = std::max(0.0, opacity);
|
||||
}
|
||||
|
||||
painter.setOpacity(opacity);
|
||||
const int x = width() - toastW - margin;
|
||||
const QRect toastRect(x, y, toastW, toastH);
|
||||
painter.fillRect(toastRect, m_visuals->toast.bg);
|
||||
painter.setPen(m_visuals->toast.fg);
|
||||
painter.drawText(toastRect.adjusted(8, 0, -8, 0),
|
||||
Qt::AlignVCenter | Qt::AlignLeft, toast.text);
|
||||
painter.setOpacity(1.0);
|
||||
y += toastH + spacing;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -1526,7 +1444,7 @@ void GameWorldView::resetForNewGame()
|
||||
exitBuilderMode();
|
||||
exitBlueprintMode();
|
||||
m_activeBeams.clear();
|
||||
m_toasts.clear();
|
||||
m_schematicChoiceShown = false;
|
||||
m_ghostRotation = Rotation::East;
|
||||
m_ghostValid = false;
|
||||
m_demolishMode = false;
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
#include <QVector2D>
|
||||
|
||||
#include "Blueprint.h"
|
||||
#include "SchematicDropEvent.h"
|
||||
#include "SchematicChoiceOption.h"
|
||||
#include "BuildingType.h"
|
||||
#include "BuildingId.h"
|
||||
#include "FireEvent.h"
|
||||
@@ -125,15 +125,7 @@ private:
|
||||
QVector2D targetOffset;
|
||||
};
|
||||
|
||||
struct ToastEntry
|
||||
{
|
||||
QString text;
|
||||
qint64 createdWallMs;
|
||||
};
|
||||
|
||||
static constexpr qint64 kBeamLifetimeMs = 300;
|
||||
static constexpr qint64 kToastLifetimeMs = 4000;
|
||||
static constexpr qint64 kToastFadeStartMs = 3500;
|
||||
static constexpr float kScrollSpeedTilesPerSec = 10.0f;
|
||||
|
||||
Simulation* m_sim;
|
||||
@@ -151,7 +143,6 @@ private:
|
||||
QTimer* m_renderTimer;
|
||||
|
||||
std::vector<ActiveBeam> m_activeBeams;
|
||||
std::vector<ToastEntry> m_toasts;
|
||||
|
||||
std::optional<BuildingType> m_builderType;
|
||||
Rotation m_ghostRotation;
|
||||
@@ -176,6 +167,7 @@ private:
|
||||
bool m_scrollLeft;
|
||||
bool m_scrollRight;
|
||||
bool m_gameOverShown;
|
||||
bool m_schematicChoiceShown;
|
||||
|
||||
Tick m_lastTick = Tick(-1);
|
||||
int m_lastBlocks = -1;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "BuildingSystem.h"
|
||||
#include "ConfigLoader.h"
|
||||
#include "GameWorldView.h"
|
||||
#include "SchematicChoiceDialog.h"
|
||||
#include "HeaderBar.h"
|
||||
#include "SelectedBuildingPanel.h"
|
||||
#include "ShipLayoutBlueprintSerializer.h"
|
||||
@@ -125,12 +126,12 @@ MainWindow::MainWindow(Simulation* sim, const std::string& configDir, QWidget* p
|
||||
}
|
||||
}
|
||||
|
||||
registerForEvent();
|
||||
registerForEvents();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
unregisterForEvent();
|
||||
unregisterForEvents();
|
||||
}
|
||||
|
||||
void MainWindow::resizeEvent(QResizeEvent* event)
|
||||
@@ -176,6 +177,19 @@ void MainWindow::handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> e
|
||||
m_buildButtonGrid->updateAffordability(event->blocks);
|
||||
}
|
||||
|
||||
void MainWindow::handleEvent(std::shared_ptr<const SchematicChoicesAvailableEvent> event)
|
||||
{
|
||||
const double prevSpeed = m_gameWorldView->gameSpeed();
|
||||
m_gameWorldView->setGameSpeed(0.0);
|
||||
|
||||
SchematicChoiceDialog dialog(event->choices, this);
|
||||
dialog.exec();
|
||||
|
||||
m_sim->applySchematicChoice(dialog.getChosenIndex());
|
||||
|
||||
m_gameWorldView->setGameSpeed(prevSpeed);
|
||||
}
|
||||
|
||||
void MainWindow::onEscapeMenuRequested()
|
||||
{
|
||||
const double prevSpeed = m_gameWorldView->gameSpeed();
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "BuildingBlocksChangedEvent.h"
|
||||
#include "BuildingId.h"
|
||||
#include "EventHandler.h"
|
||||
#include "SchematicChoicesAvailableEvent.h"
|
||||
#include "ShipLayoutBlueprint.h"
|
||||
#include "Tick.h"
|
||||
#include "VisualsConfig.h"
|
||||
@@ -22,7 +23,8 @@ class QCloseEvent;
|
||||
class QResizeEvent;
|
||||
|
||||
class MainWindow : public QWidget,
|
||||
public EventHandler<BuildingBlocksChangedEvent>
|
||||
public CombinedEventHandler<BuildingBlocksChangedEvent,
|
||||
SchematicChoicesAvailableEvent>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
@@ -36,6 +38,7 @@ protected:
|
||||
|
||||
private:
|
||||
void handleEvent(std::shared_ptr<const BuildingBlocksChangedEvent> event) override;
|
||||
void handleEvent(std::shared_ptr<const SchematicChoicesAvailableEvent> event) override;
|
||||
void layoutPanels();
|
||||
|
||||
private slots:
|
||||
|
||||
99
src/ui/SchematicChoiceDialog.cpp
Normal file
99
src/ui/SchematicChoiceDialog.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include "SchematicChoiceDialog.h"
|
||||
|
||||
#include <QHBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QPushButton>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
SchematicChoiceDialog::SchematicChoiceDialog(
|
||||
const std::vector<SchematicChoiceOption>& options,
|
||||
QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, m_chosenIndex(0)
|
||||
{
|
||||
setWindowTitle(tr("Schematic Drop"));
|
||||
setWindowFlags(windowFlags() & ~Qt::WindowCloseButtonHint);
|
||||
setModal(true);
|
||||
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout(this);
|
||||
|
||||
QLabel* titleLabel = new QLabel(tr("Choose a schematic to unlock:"), this);
|
||||
QFont titleFont = titleLabel->font();
|
||||
titleFont.setPointSize(titleFont.pointSize() + 2);
|
||||
titleFont.setBold(true);
|
||||
titleLabel->setFont(titleFont);
|
||||
titleLabel->setAlignment(Qt::AlignCenter);
|
||||
mainLayout->addWidget(titleLabel);
|
||||
|
||||
QHBoxLayout* optionsLayout = new QHBoxLayout();
|
||||
mainLayout->addLayout(optionsLayout);
|
||||
|
||||
for (int i = 0; i < static_cast<int>(options.size()); ++i)
|
||||
{
|
||||
const SchematicChoiceOption& option = options[static_cast<std::size_t>(i)];
|
||||
|
||||
QWidget* card = new QWidget(this);
|
||||
QVBoxLayout* cardLayout = new QVBoxLayout(card);
|
||||
card->setStyleSheet("QWidget { border: 1px solid gray; padding: 8px; }");
|
||||
|
||||
QLabel* nameLabel = new QLabel(QString::fromStdString(option.displayName), card);
|
||||
QFont nameFont = nameLabel->font();
|
||||
nameFont.setPointSize(nameFont.pointSize() + 1);
|
||||
nameFont.setBold(true);
|
||||
nameLabel->setFont(nameFont);
|
||||
nameLabel->setAlignment(Qt::AlignCenter);
|
||||
cardLayout->addWidget(nameLabel);
|
||||
|
||||
QString typeText;
|
||||
if (option.type == SchematicType::Ship)
|
||||
{
|
||||
typeText = tr("Ship");
|
||||
}
|
||||
else if (option.type == SchematicType::Module)
|
||||
{
|
||||
typeText = tr("Module");
|
||||
}
|
||||
else
|
||||
{
|
||||
typeText = tr("Recipe");
|
||||
}
|
||||
QLabel* typeLabel = new QLabel(typeText, card);
|
||||
typeLabel->setAlignment(Qt::AlignCenter);
|
||||
cardLayout->addWidget(typeLabel);
|
||||
|
||||
QString statusText;
|
||||
if (option.isNewUnlock)
|
||||
{
|
||||
statusText = tr("New unlock");
|
||||
}
|
||||
else
|
||||
{
|
||||
statusText = tr("Level up -> %1").arg(option.targetLevel);
|
||||
}
|
||||
QLabel* statusLabel = new QLabel(statusText, card);
|
||||
statusLabel->setAlignment(Qt::AlignCenter);
|
||||
cardLayout->addWidget(statusLabel);
|
||||
|
||||
QPushButton* selectButton = new QPushButton(tr("Select"), card);
|
||||
cardLayout->addWidget(selectButton);
|
||||
|
||||
const int index = i;
|
||||
connect(selectButton, &QPushButton::clicked, this, [this, index]()
|
||||
{
|
||||
onOptionClicked(index);
|
||||
});
|
||||
|
||||
optionsLayout->addWidget(card);
|
||||
}
|
||||
}
|
||||
|
||||
int SchematicChoiceDialog::getChosenIndex() const
|
||||
{
|
||||
return m_chosenIndex;
|
||||
}
|
||||
|
||||
void SchematicChoiceDialog::onOptionClicked(int index)
|
||||
{
|
||||
m_chosenIndex = index;
|
||||
accept();
|
||||
}
|
||||
23
src/ui/SchematicChoiceDialog.h
Normal file
23
src/ui/SchematicChoiceDialog.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <QDialog>
|
||||
|
||||
#include "SchematicChoiceOption.h"
|
||||
|
||||
class SchematicChoiceDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SchematicChoiceDialog(const std::vector<SchematicChoiceOption>& options,
|
||||
QWidget* parent = nullptr);
|
||||
|
||||
int getChosenIndex() const;
|
||||
|
||||
private:
|
||||
void onOptionClicked(int index);
|
||||
|
||||
int m_chosenIndex;
|
||||
};
|
||||
@@ -1,9 +1,10 @@
|
||||
#include "ShipLayoutDialog.h"
|
||||
#include "ShipStatsPanel.h"
|
||||
|
||||
#include <cctype>
|
||||
#include <functional>
|
||||
|
||||
#include "DisplayName.h"
|
||||
|
||||
#include <QGridLayout>
|
||||
#include <QHBoxLayout>
|
||||
#include <QInputDialog>
|
||||
@@ -20,30 +21,6 @@ namespace
|
||||
|
||||
const int kCellSize = 32;
|
||||
|
||||
QString displayName(const std::string& id)
|
||||
{
|
||||
QString result;
|
||||
bool nextUpper = true;
|
||||
for (char c : id)
|
||||
{
|
||||
if (c == '_')
|
||||
{
|
||||
result += ' ';
|
||||
nextUpper = true;
|
||||
}
|
||||
else if (nextUpper)
|
||||
{
|
||||
result += static_cast<char>(std::toupper(static_cast<unsigned char>(c)));
|
||||
nextUpper = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
result += c;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> rotateMaskCW(const std::vector<std::string>& grid)
|
||||
{
|
||||
if (grid.empty())
|
||||
@@ -478,7 +455,7 @@ ShipLayoutDialog::ShipLayoutDialog(const GameConfig* config,
|
||||
m_moduleButtons.push_back(nullptr);
|
||||
continue;
|
||||
}
|
||||
const QString label = displayName(def.id)
|
||||
const QString label = QString::fromStdString(toDisplayName(def.id))
|
||||
+ "\n" + QString::fromStdString(def.glyph);
|
||||
QPushButton* btn = new QPushButton(label, this);
|
||||
btn->setCheckable(true);
|
||||
|
||||
Reference in New Issue
Block a user