Skip to content

Game.UI.InGame.GamePanelUISystem

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

Type: class

Base: UISystemBase, IPreDeserialize

Summary:
Manages the in-game UI panels: opening, closing, toggling and default arguments. Wires UI bindings (group "game") to the game state, blocks input tools when blocking panels are active, coordinates with other systems (ToolSystem, SelectedInfoUISystem, PrefabSystem, ToolbarUISystem, PhotoModeUISystem) and emits panel open/close events. Handles special-case rules (radio enabled, life-path follow state), selection retention, photo mode activation, and transport infoview substitution.


Fields

  • private const string kGroup = "game"
    Constant string used as the UI binding group key for all bindings created by this system.

  • private PrefabSystem m_PrefabSystem
    Reference to the PrefabSystem used to query singleton prefabs such as UI transport configuration.

  • private ToolSystem m_ToolSystem
    Reference to the ToolSystem used to change active tools and infoviews when panels open/close.

  • private DefaultToolSystem m_DefaultTool
    Reference to the default tool system; used to reset tool when certain panels open.

  • private SelectedInfoUISystem m_SelectedInfoUISystem
    Reference to the system that manages the currently selected entity in the UI; used to clear or restore selection when panels open/close.

  • private ToolbarUISystem m_ToolbarUISystem
    Reference to toolbar system; used to clear asset selections when certain panels open.

  • private PhotoModeUISystem m_PhotoModeUISystem
    Reference to photo mode UI system; activated/deactivated when PhotoModePanel opens/closes.

  • private EntityQuery m_TransportConfigQuery
    EntityQuery used to find UITransportConfigurationData to obtain transport infoview prefabs.

  • private InputBarrier m_ToolBarrier
    An InputBarrier created via InputManager to block tool input while blocking panels are active. The barrier's blocked flag is updated each frame.

  • private ValueBinding<GamePanel> m_ActivePanelBinding
    Binding that stores the currently active GamePanel in the UI binding group ("game", "activePanel"). Central source for the active panel.

  • private Dictionary<string, GamePanel> m_defaultArgs
    Maps panel type full name strings to default GamePanel instances used when ShowPanel is called by type string; used to preserve panel properties between openings.

  • public Action<GamePanel> eventPanelOpened
    Event invoked when a panel is opened (after it has been opened). Subscribers can react to the newly opened panel.

  • public Action<GamePanel> eventPanelClosed
    Event invoked when a panel is closed (after it has been closed). Subscribers can react to the closed panel.

  • private Entity m_PreviousSelectedEntity
    Stores the previously selected entity when a panel requests selection retention, so it can be restored when the panel closes.

  • private InfoviewPrefab m_PreviousInfoview
    Stores the previously active infoview prefab so it can be restored when certain panels close.

Properties

  • public GamePanel activePanel { get; private set }
    Returns the currently active GamePanel (from m_ActivePanelBinding.value). May be null (annotated [CanBeNull] in source). This is the primary way other systems can query which panel is currently open.

  • private bool NeedsClear { get; }
    Internal helper that determines whether the currently active panel should be cleared due to selection/tool state changes. Logic:

  • If SelectedInfoUISystem has a selected entity -> needs clear.
  • If active panel is not an InfoviewMenu:
    • If the active tool is the default tool -> needs clear if toolbar has an active asset selection.
    • Otherwise (active tool is not default) -> needs clear.
  • Otherwise, no clear needed. Used each update to decide whether to automatically close the active panel.

Constructors

  • public GamePanelUISystem()
    Default constructor (annotated [Preserve]). Standard ECS/UISystem constructor; initialization of runtime state performed in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes system references (PrefabSystem, ToolSystem, DefaultToolSystem, SelectedInfoUISystem, ToolbarUISystem, PhotoModeUISystem), creates the transport config EntityQuery, creates an InputBarrier ("Tool", "GamePanelUISystem"), and sets up UI bindings:
  • m_ActivePanelBinding bound to "game"/"activePanel".
  • Getter binding for "blockingPanelActive" (true when activePanel.blocking).
  • Getter binding for "activePanelPosition" (active panel layout position as int).
  • Trigger bindings for "togglePanel", "showPanel", "closePanel", "closeActivePanel".
  • Registers default panel instances via InitializeDefaults() and stores them in m_defaultArgs.

  • protected override void OnUpdate()
    Called each frame; closes the active panel if activePanel != null and (NeedsClear || !IsPanelAllowed(activePanel)). Also updates m_ToolBarrier.blocked to reflect whether the active panel is blocking (activePanel?.blocking ?? false).

  • public void PreDeserialize(Context context)
    Implementation of IPreDeserialize. If the active panel binding currently contains a PhotoModePanel, this method disables the photo mode UI system before deserialization. Then clears the active panel binding (updates to null) to avoid restoring photo mode state directly during deserialization.

  • public void SetDefaultArgs(GamePanel defaultArgs)
    Stores a default GamePanel instance indexed by its runtime type's full name in m_defaultArgs. Used by ShowPanel(string) to construct panels with preserved properties.

  • public void TogglePanel([CanBeNull] string panelType)
    Toggles a panel identified by its type full name: if the current active panel is of the same type, clears it; otherwise calls ShowPanel(panelType) to open the default instance for that type.

  • public void ShowPanel(string panelType)
    If a default instance exists in m_defaultArgs for panelType, calls ShowPanel(GamePanel) with that instance. Does not construct new instance itself — relies on InitializeDefaults or SetDefaultArgs to populate m_defaultArgs.

  • public void ShowPanel(GamePanel panel)
    Opens the provided panel instance if IsPanelAllowed(panel) returns true. Updates m_ActivePanelBinding to the panel and calls OnPanelChanged(previous, panel) to handle opening logic.

  • public void ClosePanel(string panelType)
    If the currently active panel is of the provided type full name, clears the active panel binding and calls OnPanelChanged(previous, null) to handle cleanup.

  • private void CloseActivePanel()
    Closes the currently active panel (if any) by setting the binding to null and invoking OnPanelChanged(previous, null).

  • protected override void OnGameLoaded(Context serializationContext)
    Invoked after game load; reinitializes default panel instances via InitializeDefaults() to ensure defaults are present post-load.

  • private void InitializeDefaults()
    Creates and registers default GamePanel instances for many UI panels used by the game (InfoviewMenu, ProgressionPanel, EconomyPanel, CityInfoPanel, StatisticsPanel, TransportationOverviewPanel, ChirperPanel, LifePathPanel, JournalPanel, RadioPanel, PhotoModePanel, CinematicCameraPanel, NotificationsPanel). Also adds trigger bindings to show certain panels (e.g., showProgressionPanel, showEconomyPanel, showCityInfoPanel, showTransportationOverviewPanel, showLifePathDetail). This centralizes which panels are available by name and supplies default instances.

  • public void ShowPanel<T>(int tab) where T : TabbedGamePanel, new()
    Convenience generic overload that constructs a new T, sets selectedTab to tab, and passes it to ShowPanel(GamePanel).

  • public void ShowPanel<T>(Entity selectedEntity) where T : EntityGamePanel, new()
    Convenience generic overload that constructs a new T, sets selectedEntity, and passes it to ShowPanel(GamePanel).

  • private bool IsPanelAllowed(GamePanel panel)
    Checks whether a panel is allowed to open:

  • RadioPanel: only if SharedSettings.instance.audio.radioActive is true.
  • LifePathPanel with a specific selectedEntity: only if that entity has the Followed component in EntityManager.
  • Default: allowed.

  • private void OnPanelChanged([CanBeNull] GamePanel previous, [CanBeNull] GamePanel next)
    Centralized transition logic called after the binding is updated. If previous is closing (previous != null and previous type != next type or next is null):

  • Invokes eventPanelClosed(previous) and calls OnPanelClosed(previous).
  • If next is null (fully closed), restores m_ToolSystem.infoview from m_PreviousInfoview unless previous was InfoviewMenu.
  • Restores previously selected entity if the UI's SelectedInfoUISystem selection is currently Entity.Null. If next is opening (next != null and next type != previous type):
  • Calls OnPanelOpened(next) and invokes eventPanelOpened(next).

  • private void OnPanelOpened(GamePanel panel)
    Handles setup when a panel opens:

  • Stores current m_ToolSystem.activeInfoview into m_PreviousInfoview.
  • Activates photo mode UI if panel is PhotoModePanel.
  • If panel is not an InfoviewMenu:
    • Sets active tool to default tool.
    • Clears toolbar asset selection.
  • If panel is TransportationOverviewPanel and a transport config prefab is available, replaces tool system infoview with transport-specific infoview.
  • Sends telemetry PanelOpened(panel).
  • If the panel requests retainSelection, stores current selected entity into m_PreviousSelectedEntity and clears selection by setting SelectedInfoUISystem selection to Entity.Null.

  • private void OnPanelClosed(GamePanel panel)
    Handles cleanup when a panel closes:

  • Deactivates photo mode UI if panel was PhotoModePanel.
  • Sends telemetry PanelClosed(panel).
  • If panel.retainProperties is true, calls SetDefaultArgs(panel) to persist that panel's properties as defaults for future openings.

  • private bool TryGetTransportConfig(out UITransportConfigurationPrefab config)
    Queries m_PrefabSystem for the UITransportConfigurationPrefab singleton prefab using m_TransportConfigQuery and returns true if found, providing the config via out parameter.

Usage Example

// Example: Wiring and opening a panel from code (within a system or mod)
var panelSystem = World.GetOrCreateSystemManaged<Game.UI.InGame.GamePanelUISystem>();

// Show the default progression panel instance (registered in InitializeDefaults)
panelSystem.ShowPanel(typeof(ProgressionPanel).FullName);

// Open a specific tab of a tabbed panel
panelSystem.ShowPanel<ProgressionPanel>(tab: 2);

// Open an entity-based panel for a specific entity
Entity someCitizen = ...;
panelSystem.ShowPanel<LifePathPanel>(someCitizen);

// Toggle a panel by type full name
panelSystem.TogglePanel(typeof(RadioPanel).FullName);

// Subscribe to open/close events
panelSystem.eventPanelOpened += panel => Debug.Log($"Panel opened: {panel.GetType().FullName}");
panelSystem.eventPanelClosed += panel => Debug.Log($"Panel closed: {panel.GetType().FullName}");

Notes: - Panel type comparisons use GetType().FullName; when calling ShowPanel(string) or TogglePanel(string) ensure you pass the full name string for the panel type (e.g., typeof(ProgressionPanel).FullName). - Some panels are blocked by gameplay conditions (radio disabled, life-path following not present) and will be prevented by IsPanelAllowed. - Panels that set retainSelection or retainProperties will preserve or restore selection/properties via m_PreviousSelectedEntity and m_defaultArgs.