Skip to content

Game.UI.InGame.UpgradeMenuUISystem

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: class

Base: UISystemBase

Summary:
UI system that drives the in-game Upgrade Menu. It binds available building upgrades and modules into the UI, exposes details for a selected upgrade, tracks upgrading state, and coordinates tool activation (prefab tools, default tool, upgrade tool) when the player selects or clears an upgrade. It also listens for changes relevant to upgrades (unlocks, created/deleted extensions, unique asset status changes, selection and tool changes) and updates UI bindings accordingly.


Fields

  • private const string kGroup = "upgradeMenu"
    Identifier used for the UI binding group for upgrade menu bindings.

  • private EntityQuery m_UnlockedUpgradeQuery
    Entity query used to detect unlocked UI objects/prefabs relevant to upgrades.

  • private EntityQuery m_CreatedExtensionQuery
    Entity query used to detect newly created building extensions.

  • private EntityQuery m_DeletedExtensionQuery
    Entity query used to detect deleted building extensions.

  • private ToolSystem m_ToolSystem
    Reference to the global ToolSystem used to activate and query tools.

  • private DefaultToolSystem m_DefaultTool
    Reference to the default (selection) tool used to revert to non-upgrading mode.

  • private ObjectToolSystem m_ObjectToolSystem
    Reference to object tool system to detect object upgrade mode.

  • private AreaToolSystem m_AreaToolSystem
    Reference to area tool system used in some service upgrade operations.

  • private NetToolSystem m_NetToolSystem
    Reference to net tool system to detect service upgrades for roads/nodes.

  • private RouteToolSystem m_RouteToolSystem
    Reference to route tool system used for transport route upgrades.

  • private UpgradeToolSystem m_UpgradeToolSystem
    Reference to a specialized upgrade tool system.

  • private PrefabSystem m_PrefabSystem
    Reference to PrefabSystem for mapping between prefab entities and PrefabBase.

  • private PrefabUISystem m_PrefabUISystem
    Reference used to bind prefab details to the UI.

  • private ToolbarUISystem m_ToolbarUISystem
    Reference used to bind assets into toolbar-style UI elements.

  • private SelectedInfoUISystem m_SelectedInfoUISystem
    Reference to selected-object UI system; used to track the currently selected building/object.

  • private UniqueAssetTrackingSystem m_UniqueAssetTrackingSystem
    Reference to unique asset tracking system used to determine unique asset status & placement.

  • private RawMapBinding<Entity> m_UpgradesBinding
    Raw binding for the list of available upgrades shown in the menu.

  • private RawMapBinding<Entity> m_UpgradeDetailsBinding
    Raw binding for the details panel of a selected upgrade.

  • private ValueBinding<Entity> m_SelectedUpgradeBinding
    Value binding that stores the currently selected upgrade (Entity or Entity.Null).

  • private ValueBinding<bool> m_UpgradingBinding
    Value binding that stores whether the UI/tool state is currently an upgrading state.

  • private NativeList<SortableEntity> m_Upgrades
    NativeList used internally to collect and sort available upgrade entities.

  • private NativeList<SortableEntity> m_Modules
    NativeList used internally to collect and sort available module entities.

  • private bool m_UniqueAssetStatusChanged
    Flag set when unique asset placed/unplaced status changes so bindings can refresh.

Properties

  • public override GameMode gameMode => GameMode.Game
    Indicates the system runs in normal Game mode (not in editor or other modes).

  • public bool upgrading { get; }
    Read-only property that reports whether an upgrade is currently selected and active. It queries the m_SelectedUpgradeBinding (if active) and returns true when a non-null upgrade entity is selected. This is used by UI to show active upgrading state.

Constructors

  • public UpgradeMenuUISystem()
    Default parameterless constructor. Systems in this codebase are constructed by the ECS/world infrastructure; the constructor itself performs no initialization beyond what the base class does. Actual initialization happens in OnCreate().

Methods

  • [Preserve] protected override void OnCreate() : System.Void
    Initializes queries, retrieves required systems from the world, sets up event handlers and UI bindings, and allocates native lists. Specifically:
  • Creates EntityQueries for unlocked upgrades and created/deleted extensions.
  • Gets references to multiple tool and UI-related systems.
  • Subscribes to UniqueAssetTrackingSystem.EventUniqueAssetStatusChanged.
  • Adds RawMap/Value/Trigger bindings for "upgradeMenu" group keys: "upgrades", "selectedUpgrade", "upgradeDetails", "selectUpgrade", "clearUpgradeSelection", "upgrading".
  • Allocates m_Upgrades and m_Modules NativeLists.

  • private void OnUniqueAssetStatusChanged(Entity prefabEntity, bool placed) : System.Void
    Callback invoked when a unique asset's placed status changes. Sets m_UniqueAssetStatusChanged to true to ensure bindings refresh next update.

  • [Preserve] protected override void OnDestroy() : System.Void
    Disposes NativeList resources (m_Upgrades and m_Modules) and calls base.OnDestroy().

  • [Preserve] protected override void OnStartRunning() : System.Void
    Subscribes to selection and tool change events:

  • Adds OnSelectionChanged to SelectedInfoUISystem.eventSelectionChanged.
  • Adds OnToolChanged to ToolSystem.EventToolChanged.

  • [Preserve] protected override void OnStopRunning() : System.Void
    Unsubscribes the event handlers added in OnStartRunning and calls base.OnStopRunning().

  • [Preserve] protected override void OnUpdate() : System.Void
    Runs each frame to determine whether the upgrade UI data needs refreshing. Triggers m_UpgradesBinding.UpdateAll() and m_UpgradeDetailsBinding.UpdateAll() when:

  • New unlocks for upgrade/module prefabs exist.
  • Created/deleted extension queries are non-empty.
  • Unique asset status changed.
  • The selected upgradable entity has Updated/Destroyed state changes that affect whether upgrades are available. After updates, clears the m_UniqueAssetStatusChanged flag.

  • private Entity GetUpgradable(Entity entity) : Entity
    If the provided entity is an Attached component (e.g., an attached object), returns its parent entity; otherwise returns the entity itself. Used to map selection to the upgradable building entity.

  • private void ClearUpgradeSelection() : System.Void
    If an upgrade is currently selected, switch the active tool back to the default tool and clear the selected upgrade (by invoking SelectUpgrade with Entity.Null).

  • private void BindUpgrades(IJsonWriter writer, Entity upgradable) : System.Void
    Primary binding implementation for the "upgrades" list. Steps:

  • Resolve the upgradable entity (handles attachments).
  • If the target entity or its PrefabRef is missing or the entity is destroyed, writes an empty array.
  • Collects BuildingUpgradeElement and BuildingModule entries from the prefab buffer (if present), gathers their UI priorities via UIObjectData, sorts them, and writes them via ToolbarUISystem.BindAsset().
  • For upgrades that are BuildingUpgradeElement entries, it computes extension/placed status through CheckExtensionBuiltStatus to mark unique/built status for binding.

  • private void BindUpgradeDetails(IJsonWriter writer, Entity upgrade) : System.Void
    Binding implementation for the selected upgrade details. It determines whether the upgrade is an extension and if it is already built/placed using CheckExtensionBuiltStatus, then delegates to PrefabUISystem.BindPrefabDetails to write full prefab details.

  • private (bool extension, bool built) CheckExtensionBuiltStatus(Entity upgradableEntity, Entity upgradeEntity) : (bool, bool)
    Checks whether a given upgrade entity should be considered an extension for the upgradable and whether that extension is already installed or (for unique assets) already placed. Returns a tuple:

  • extension: true if the upgrade is a BuildingExtensionData or a tracked unique asset.
  • built: true if an InstalledUpgrade buffer on the upgradable references this upgrade or the unique asset is placed.

  • private void SelectUpgrade(Entity upgradable, Entity upgrade) : System.Void
    Handles selection requests:

  • Updates the selected upgrade binding.
  • If the upgrade is a valid, unlocked, unbuilt extension on a valid upgradable, it sets m_UpgradingBinding to true, updates the list binding, and activates the prefab tool for the selected upgrade prefab.
  • Otherwise, performs logic to revert to default tool when the prefab/tool state no longer corresponds to the selected upgrade. It checks the currently active prefab tool and buffers to determine if the selected upgrade is still active and clears tool as appropriate.

  • private void OnSelectionChanged(Entity entity, Entity prefab, float3 position) : System.Void
    React to selection changes from SelectedInfoUISystem. If input scheme is KeyboardAndMouse, clear the upgrade selection (so selecting buildings with mouse cancels upgrade selection).

  • private void OnToolChanged(ToolBaseSystem tool) : System.Void
    React to tool switches. Determines whether the newly active tool implies an upgrading state and updates m_UpgradingBinding accordingly. Conditions checked include:

  • The Object tool in Upgrade mode.
  • Net/Routetool service upgrade flags.
  • Area tool recreate operation with ServiceUpgrade on the owner.
  • The tool is a module-prefab (building module) prefab or the dedicated UpgradeToolSystem.

Usage Example

// Query the system (example usage from other UI code)
UpgradeMenuUISystem upgradeMenu = World.GetExistingSystemManaged<UpgradeMenuUISystem>();

// Check if the player is currently in upgrading mode (e.g., to update UI chrome)
if (upgradeMenu != null && upgradeMenu.upgrading)
{
    // Show 'cancel upgrade' UI or disable other controls
}

// Programmatically clear selection (internally this is private, but the UI trigger binding "clearUpgradeSelection"
// is wired in OnCreate; UI code should trigger that binding to clear selection).