Game.UI.InGame.SignatureBuildingUISystem
Assembly: Game
Namespace: Game.UI.InGame
Type: class
Base: UISystemBase, IPreDeserialize
Summary:
System responsible for managing the in-game UI list of unlocked "signature buildings". It watches for Unlock components in the ECS world, updates a ValueBinding that the UI consumes ("signatureBuildings" -> "unlockedSignatures"), and exposes methods/triggers to add, remove or clear the list. It also contains logic to skip the first update after deserialization and to avoid presenting signature popups when global settings or city configuration indicate that popups are disabled or everything is unlocked.
Fields
-
private const string kGroup = "signatureBuildings"
Description: UI binding group/key prefix used when creating ValueBinding and TriggerBinding entries. -
private CityConfigurationSystem m_CityConfigurationSystem
Description: Cached reference to the CityConfigurationSystem (retrieved from World) used to check configuration flags such as unlockAll. -
private EntityQuery m_UnlockedSignatureBuildingQuery
Description: EntityQuery that matches entities with the Unlock component. Used to find newly unlocked signature building prefabs each update. -
private ValueBinding<List<Entity>> m_UnlockSignaturesBinding
Description: Binding that represents the list of unlocked signature building prefabs exposed to the UI. It is created with the keys ("signatureBuildings", "unlockedSignatures") and uses a ListWriterfor serialization. -
private bool m_SkipUpdate = true
Description: When true, the next OnUpdate run is skipped. Used to avoid processing immediately after deserialization or when explicitly requested via SkipUpdate(). -
private int m_LastListCount
Description: Tracks last observed count of m_UnlockSignaturesBinding.value to detect changes and minimize redundant TriggerUpdate calls. -
private bool m_NeedTriggerUpdate
Description: Flag set when the binding value list was changed programmatically and a TriggerUpdate should be invoked in the next OnUpdate.
Properties
- This class exposes no public properties. Internal state is exposed to UI via bindings (m_UnlockSignaturesBinding) rather than public CLR properties.
Constructors
public SignatureBuildingUISystem()
Description: Default parameterless constructor. The system performs initialization in OnCreate (typical for ECS systems).
Methods
protected override void OnCreate()
: System.Void
Description: Initializes the system:- Retrieves CityConfigurationSystem from the world.
- Builds an EntityQuery for Unlock components.
- Creates a ValueBinding
- > ("signatureBuildings","unlockedSignatures") and registers it via AddBinding.
-
Registers a TriggerBinding ("signatureBuildings","removeUnlockedSignature") that calls RemoveUnlockedSignature when invoked by the UI.
-
protected override void OnUpdate()
: System.Void
Description: Main update loop; behavior: - If m_SkipUpdate is true, clears it and returns (skips this update).
- If SharedSettings.instance.userInterface.blockingPopupsEnabled is false OR the city configuration has unlockAll enabled, returns early (no UI popups should be shown).
- Otherwise, queries all Unlock components (using m_UnlockedSignatureBuildingQuery.ToComponentDataArray
(Allocator.TempJob)), iterates them and for each: - If the prefab entity referenced by Unlock has both SignatureBuildingData and UIObjectData components, calls AddUnlockedSignature(prefab).
- Disposes the NativeArray when done.
- After processing, if the binding list size changed from m_LastListCount or m_NeedTriggerUpdate is set, calls m_UnlockSignaturesBinding.TriggerUpdate(), updates m_LastListCount and clears m_NeedTriggerUpdate. Notes:
- Uses Allocator.TempJob for component array retrieval and disposes it promptly.
-
The logic ensures the UI is updated only when necessary.
-
public void AddUnlockedSignature(Entity prefab)
: System.Void
Description: Adds the provided prefab entity to the front of the unlocked signatures list if not already present, and marks that a TriggerUpdate is needed. The insertion at index 0 ensures most-recent unlocks are presented first. -
private void RemoveUnlockedSignature()
: System.Void
Description: Removes the first element in the unlocked signatures binding list (index 0) and marks that a TriggerUpdate is needed. This is wired to the UI trigger "removeUnlockedSignature". -
public void ClearUnlockedSignature()
: System.Void
Description: Clears the entire unlocked signatures list and marks that a TriggerUpdate is needed. -
public void PreDeserialize(Context context)
: System.Void
Description: IPreDeserialize implementation called before deserialization. Clears the binding list and ensures m_SkipUpdate is false so the system will process normally after deserialization. -
public void SkipUpdate()
: System.Void
Description: Sets m_SkipUpdate = true to skip the next update cycle. Useful to avoid duplicate processing when the caller knows the first OnUpdate should be ignored (e.g., right after certain operations).
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// System initialization is done here in the actual system. Example of how
// this system creates and uses a binding:
m_CityConfigurationSystem = base.World.GetOrCreateSystemManaged<CityConfigurationSystem>();
m_UnlockedSignatureBuildingQuery = GetEntityQuery(ComponentType.ReadOnly<Unlock>());
AddBinding(m_UnlockSignaturesBinding = new ValueBinding<List<Entity>>(
"signatureBuildings",
"unlockedSignatures",
new List<Entity>(),
new ListWriter<Entity>()));
AddBinding(new TriggerBinding("signatureBuildings", "removeUnlockedSignature", RemoveUnlockedSignature));
}
// Example: adding a signature prefab (callable from other systems when an unlock is detected)
public void ExampleAdd(Entity prefab)
{
AddUnlockedSignature(prefab);
}
// Example: prevent processing for one frame (e.g., during save/load)
public void ExampleSkip()
{
SkipUpdate();
}
Notes and modding tips: - The UI list is exposed via the binding key "signatureBuildings" -> "unlockedSignatures". Mod code or UI XML/JS that wants to display signature buildings should consume that binding. - To programmatically remove the top-most displayed signature from UI, invoke the trigger "signatureBuildings.removeUnlockedSignature" (this class already binds that trigger to RemoveUnlockedSignature). - PreDeserialize clears the binding to avoid stale entries after load; SkipUpdate can be used to avoid an extra OnUpdate processing pass when needed. - The system only presents signature popups when SharedSettings.instance.userInterface.blockingPopupsEnabled is true and CityConfigurationSystem.unlockAll is false; otherwise OnUpdate returns early and the binding is not populated.