Game.SceneFlow.OverlayBindings
Assembly: Assembly-CSharp
Namespace: Game.SceneFlow
Type: class OverlayBindings
Base: CompositeBinding
Summary:
Manages the game's overlay UI bindings (active overlay screen, progress values, hint messages, and corrupt-data messages) using Colossal.UI.Binding. Maintains a prioritized set of active overlay screens, exposes a simple API to activate/deactivate/swap screens (including a scoped activation helper), and synchronizes data to the binding system so UI or other systems can observe changes. Triggers an onScreenActivated event whenever the active screen changes.
Fields
-
private const string kGroup = "overlay"
Stores the binding group name used when creating ValueBinding instances. -
private readonly ValueBinding<OverlayScreen> m_ActiveScreen
Binding that represents the current active overlay screen (an enum value serialized as an int). Updated from the top of the active-screen set. -
private readonly ValueBinding<float[]> m_Progress
Binding that stores an array of progress floats for different OverlayProgressType values. -
private readonly ValueBinding<string[]> m_HintMessages
Binding that stores the current hint messages (string array) shown on the overlay. -
private readonly ValueBinding<string[]> m_CorruptDataMessages
Binding that stores messages related to corrupt data. This binding is nullable. -
private readonly SortedSet<OverlayScreen> m_ActiveScreenList
A SortedSet of OverlayScreen values (ordered via OverlayScreenComparer) representing active screens. The first item is treated as the currently active screen (priority ordering). -
public event Action<OverlayScreen> onScreenActivated
Event invoked whenever the effective active overlay screen changes (after UpdateScreen runs).
Properties
-
public OverlayScreen currentlyActiveScreen { get; }
Read-only convenience property returning the first item from m_ActiveScreenList (or OverlayScreen.None if empty). Reflects which screen is currently active based on the priority ordering. -
public string[] hintMessages { get; set }
Gets/sets the hint message array via the m_HintMessages binding. The setter calls Update on the binding so observers are notified. -
public string[] corruptDataMessages { get; set }
Gets/sets the corrupt-data message array via the m_CorruptDataMessages binding. Setter updates the binding (and can be null).
Nested Types
-
public struct ScopedScreen : IDisposable
Helper RAII-style struct that activates a given OverlayScreen for the lifetime of the struct instance and deactivates it when disposed. Designed to be used with a using statement to ensure automatic deactivation. -
Constructor:
public ScopedScreen(OverlayScreen screen, OverlayBindings bindings)
— activates the supplied screen immediately. - Method:
public void Dispose()
— deactivates the previously activated screen.
Constructors
public OverlayBindings()
Initializes the binding group and adds the following ValueBindings:- m_ActiveScreen: binds "overlay", "activeScreen" with default OverlayScreen.None and a writer that serializes the enum as an int.
- m_Progress: binds "overlay", "progress" with a float[3] default and an ArrayWriter
. - m_HintMessages: binds "overlay", "hintMessages" with an empty string[] default and an ArrayWriter
. - m_CorruptDataMessages: binds "overlay", "corruptDataMessages" with a nullable ArrayWriter
. Also constructs the SortedSet used to track active screens.
Methods
-
public ScopedScreen ActivateScreenScoped(OverlayScreen screen)
Returns a ScopedScreen instance that activates the given screen immediately and will deactivate it when disposed. Use with "using" to scope activation. -
private void UpdateScreen()
Internal helper: takes the first element of m_ActiveScreenList (or default), updates the m_ActiveScreen binding with it, logs the change, and invokes onScreenActivated with the new value. Ensures the binding and event are consistent with the active-screen set. -
public void ActivateScreen(OverlayScreen screen)
Adds the screen to m_ActiveScreenList and calls UpdateScreen to reflect the change. -
public void DeactivateScreen(OverlayScreen screen)
Removes the screen from m_ActiveScreenList and calls UpdateScreen to reflect the change. -
public void SwapScreen(OverlayScreen screen1, OverlayScreen screen2)
Convenience: deactivates screen1 and activates screen2 (calls DeactivateScreen then ActivateScreen). Useful for replacing one screen with another while preserving ordering semantics. -
public void DeactivateAllScreens()
Clears m_ActiveScreenList and updates the active binding (sets to none/default). -
public float GetProgress(OverlayProgressType type)
Returns the progress float for the given OverlayProgressType from the m_Progress array. -
public void SetProgress(OverlayProgressType type, float progress)
Sets the progress value at the index of the given OverlayProgressType if it differs from the current value, then triggers an update on the m_Progress binding so observers are notified.
Usage Example
// Subscribe to screen-activated events
var overlayBindings = new OverlayBindings();
overlayBindings.onScreenActivated += screen => Debug.Log($"Active overlay: {screen}");
// Activate a screen directly
overlayBindings.ActivateScreen(OverlayScreen.Loading);
// Use a scoped activation (automatically deactivates when disposed)
using (overlayBindings.ActivateScreenScoped(OverlayScreen.SaveDialog))
{
// Save dialog active inside this block
}
// Set progress for a particular overlay progress type
overlayBindings.SetProgress(OverlayProgressType.Loading, 0.5f);
// Update hint messages
overlayBindings.hintMessages = new[] { "Tip: Place parks to increase land value." };
// Clear all overlays
overlayBindings.DeactivateAllScreens();