Game.UI.InGame.InfoviewsUISystem
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: UISystemBase
Summary:
Manages the Infoviews UI for Cities: Skylines 2. This UISystem collects available infoview prefabs, reports which are locked/unlocked, exposes the active infoview and its infomodes to the UI, and handles UI-triggered actions to change the active infoview or activate/deactivate individual infomodes. It listens to ToolSystem events to react to infoview/infomode changes and uses Prefab/Unlock systems to query prefab entities and lock state. Contains a nested readonly struct Infoview that represents a single infoview entry (entity, id, icon, group/priority and locked state).
Fields
-
private const string kGroup = "infoviews"
The UI group name used when adding bindings for the infoviews UI. -
private ToolSystem m_ToolSystem
Reference to the ToolSystem used to read/set the currently active infoview and infomode state. -
private PrefabSystem m_PrefabSystem
Reference to the PrefabSystem used to get Entity ids for Infoview and Infomode prefabs. -
private UnlockSystem m_UnlockSystem
Reference to the UnlockSystem used to determine whether an infoview prefab is locked/unlocked. -
private PrefabUISystem m_PrefabUISystem
Used to bind prefab requirements when serializing an Infoview for the UI. -
private InfoviewInitializeSystem m_InfoviewInitializeSystem
Provides the list of available InfoviewPrefab instances (infoview definitions). -
private RawValueBinding m_ActiveView
RawValueBinding that supplies the currently active infoview (and its infomodes) to the UI. -
private List<Infoview> m_InfoviewsCache
Cached list of Infoview entries built each time the infoview list is bound to the UI. -
private RawValueBinding m_Infoviews
RawValueBinding that supplies the list of available infoviews (with lock state) to the UI. -
private EntityQuery m_UnlockedInfoviewQuery
EntityQuery used to test for unlocked infoview prefabs to decide whether to update infoview bindings. -
private bool m_InfoviewChanged
Flag that marks that the active infoview or infomodes changed and the active view binding should be updated on the next OnUpdate.
Properties
public override GameMode gameMode => GameMode.GameOrEditor
Indicates this UISystem runs in both Game and Editor modes.
Constructors
public InfoviewsUISystem()
Default constructor (Preserve attribute present on the class methods). Initializes the system instance; actual wiring of dependencies happens in OnCreate.
Methods
-
protected override void OnCreate()
Initializes references to required systems (ToolSystem, PrefabSystem, UnlockSystem, PrefabUISystem, InfoviewInitializeSystem), creates bindings for the UI (infoview list, active infoview, trigger handlers for setting active infoview and infomode activation), prepares the infoview cache, and subscribes to ToolSystem events (EventInfoviewChanged, EventInfomodesChanged). -
protected override void OnDestroy()
Unsubscribes from ToolSystem events and calls base.OnDestroy to clean up. -
protected override void OnUpdate()
Updates the infoviews binding only if any infoview prefabs have become unlocked (using PrefabUtils.HasUnlockedPrefab) and updates the active view binding when m_InfoviewChanged is set. Clears the m_InfoviewChanged flag after updating. -
protected override void OnGameLoaded(Context serializationContext)
Called after game load; forces both the infoviews list and the active view bindings to update to reflect serialized state. -
private void OnInfoviewChanged(InfoviewPrefab prefab)
Event handler called when the ToolSystem reports the active infoview prefab changed; marks the active view binding for update. -
private void OnChanged()
Event handler for generic infomode changes; marks the active view binding for update. -
private void BindInfoviews(IJsonWriter writer)
Builds the infoview list presented to the UI: iterates infoview prefabs from InfoviewInitializeSystem, filters valid ones, checks unlocked state, constructs the Infoview entries, sorts them (by group, priority, then id) and writes them to the provided writer. Uses PrefabUISystem to bind prefab requirements for each entry. -
private void BindActiveInfoview(IJsonWriter writer)
Writes the currently active infoview to the writer (entity, id, icon, uiTag, a list of its infomodes, and editor flag). If no active infoview exists, writes null. -
private void BindInfomode(IJsonWriter writer, InfomodeInfo info)
Serializes a single infomode entry for the active infoview: writes entity, id, uiTag, active state, priority, a color or gradient legend where applicable, an array of color legends (for field-based gradients), and the localized type key. -
private void BindInfomodeGradientLegend(IJsonWriter writer, IGradientInfomode gradientInfomode)
Writes a gradient legend block for a gradient infomode: low/high labels and a gradient with 3 stops (low, medium, high colors). -
private void BindGradientStop(IJsonWriter writer, float offset, Color color)
Writes a single gradient stop (offset + Color) into the JSON writer. -
private void BindColorLegends(IJsonWriter writer, IGradientInfomode gradientInfomode)
If the gradient infomode uses field legend types, writes an array of ColorLegend entries for low/medium/high labels that exist. -
private void BindColorLegend(IJsonWriter writer, Color color, LocalizedString label)
Writes a ColorLegend entry consisting of color + localized label. -
public void SetActiveInfoview(Entity entity)
UI trigger target: sets the active infoview on the ToolSystem. If the provided entity exists, it resolves the InfoviewPrefab from PrefabSystem and assigns it to m_ToolSystem.infoview; otherwise clears the infoview. -
private void SetInfomodeActive(Entity entity, bool active, int priority)
UI trigger target: forwards requests from UI to enable/disable a particular infomode on the ToolSystem with the given priority. -
Nested type: readonly struct
Infoview
(implements IComparable) - Properties:
public Entity entity { get; }
— prefab entity for this infoview.public string id { get; }
— prefab name/id.public string icon { get; }
— icon path.public bool locked { get; }
— whether the infoview is locked.public string uiTag { get; }
— UI tag for grouping/layout.public int group { get; }
— grouping index.
- Constructor:
public Infoview(Entity entity, InfoviewPrefab prefab, bool locked)
— constructs an Infoview from the prefab and lock state. public int CompareTo(Infoview other)
— ordering used when sorting the list (group -> priority -> id).public void Write(PrefabUISystem prefabUISystem, IJsonWriter writer)
— serializes this Infoview entry to the given writer (entity, id, icon, locked, uiTag, group, editor flag, and requirements via PrefabUISystem).
Usage Example
// Example: set the active infoview from code (e.g. in response to a UI action)
InfoviewsUISystem uiSystem = World.GetOrCreateSystemManaged<InfoviewsUISystem>();
// 'entity' should be the Entity id previously obtained from PrefabSystem.GetEntity(infoviewPrefab)
uiSystem.SetActiveInfoview(entity);
// Example: toggle an infomode via the UISystem (the UI normally calls this)
uiSystem.SetInfomodeActive(infomodeEntity, true, priority);