Skip to content

Game.GameScreenUISystem

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

Type: public class GameScreenUISystem

Base: UISystemBase, IPreDeserialize

Summary:
Manages the in-game UI screen state for Cities: Skylines 2. Provides an enum of supported game screens (Main, FreeCamera, PauseMenu, SaveGame, NewGame, LoadGame, Options), tracks and exposes the currently active screen via a ValueBinding, toggles whether the save system can be used, and handles cursor visibility / lock mode when switching screens. It also listens for game save/load progress (GameManager.instance.onGameSaveLoad) and pushes/pops localized notifications for save operations. Uses Colossal UI binding primitives (ValueBinding, TriggerBinding) to integrate with the UI data layer.


Fields

  • private const string kSavingGameNotificationTitle
    Contains the base notification title key used when showing "saving game" notifications. Value in code: "SavingGame".

  • private const string kGroup
    Group name used for bindings. Value in code: "game".

  • private ValueBinding<GameScreen> m_ActiveScreenBinding
    ValueBinding that holds the currently active GameScreen. Backed by the UI binding system with key ("game","activeScreen"). Used for reading/updating the active screen and determining whether menus are active.

  • private ValueBinding<bool> m_CanUseSaveSystem
    ValueBinding used to enable/disable the save system in the UI (key: "game","canUseSaveSystem"). Updated when save/load starts and finishes.

  • public enum GameScreen
    Defines available UI screens:

  • Main = 0
  • FreeCamera = 1
  • PauseMenu = 10
  • SaveGame = 11
  • NewGame = 12
  • LoadGame = 13
  • Options = 14

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set }
    (not present in this class) — This placeholder appears in the template but is not applicable to GameScreenUISystem. The meaningful properties in this class are below.

  • public GameScreen activeScreen { get; set; }
    Gets or sets the current active screen via m_ActiveScreenBinding. The getter returns the binding's value; the setter updates the binding (m_ActiveScreenBinding.Update(value)), which will propagate to any bound UI elements.

  • public bool isMenuActive { get; }
    Read-only convenience property that returns true when activeScreen is at or above GameScreen.PauseMenu. Useful to quickly check whether any menu UI is currently active.

Constructors

  • public GameScreenUISystem()
    Default constructor. Marked with [Preserve] in the original source. Initialization of bindings and event subscription is done in the overridden OnCreate method rather than the ctor.

Methods

  • protected override void OnCreate()
    Initializes UI bindings and event handlers. Specifically:
  • Calls base.OnCreate().
  • Creates and registers m_ActiveScreenBinding as a ValueBinding with group "game" and key "activeScreen", defaulting to GameScreen.Main, using EnumWriter().
  • Registers a TriggerBinding ("game","setActiveScreen") that calls SetScreen when triggered (uses EnumReader()).
  • Registers m_CanUseSaveSystem as a ValueBinding("game","canUseSaveSystem", initialValue: true).
  • Subscribes SaveLoadInProgress to GameManager.instance.onGameSaveLoad to show/hide save notifications.

  • protected override void OnDestroy()
    Unsubscribes SaveLoadInProgress from GameManager.instance.onGameSaveLoad and calls base.OnDestroy().

  • private void SaveLoadInProgress(string name, bool start)
    Callback invoked when a game save/load begins or ends. When start == true:

  • Pushes a notification via NotificationSystem.Push using identifier "SavingGame" + name, localized text for the save name, and an indeterminate ProgressState. When start == false:
  • Pops the notification via NotificationSystem.Pop with ProgressState.Complete and a 1s fade-out. Also updates m_CanUseSaveSystem to disabled while start is true, enabled when start is false.

  • protected override void OnUpdate()
    Empty override in source. Place for per-frame UI updates if needed.

  • public void PreDeserialize(Context context)
    Implements IPreDeserialize. Called before deserialization: ensures the screen is reset to GameScreen.Main by calling SetScreen(GameScreen.Main). Useful to guarantee a known UI state before loading.

  • public void SetScreen(GameScreen screen)
    Switches the current UI screen and updates input/cursor state:

  • Shows or hides the cursor via InputManager.instance.hideCursor when screen == FreeCamera (hides cursor).
  • Sets InputManager.instance.cursorLockMode: for Main/FreeCamera uses SharedSettings.instance.graphics.cursorMode.ToUnityCursorMode(), otherwise CursorLockMode.None.
  • Updates m_ActiveScreenBinding with the new screen.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Bind active screen (defaults to Main)
    AddBinding(m_ActiveScreenBinding = new ValueBinding<GameScreen>(
        "game", "activeScreen", GameScreen.Main, new EnumWriter<GameScreen>()));

    // Allow external triggers to set the active screen
    AddBinding(new TriggerBinding<GameScreen>(
        "game", "setActiveScreen", SetScreen, new EnumReader<GameScreen>()));

    // Track whether save/load UI should be enabled
    AddBinding(m_CanUseSaveSystem = new ValueBinding<bool>(
        "game", "canUseSaveSystem", initialValue: true));

    // Listen for save/load progress to show notifications and disable save UI while saving
    GameManager.instance.onGameSaveLoad += SaveLoadInProgress;
}