Game.SceneFlow.UserInterface
Assembly: Game
Namespace: Game.SceneFlow
Type: class
Base: System.IDisposable
Summary:
UserInterface encapsulates the in-game cohtml-based UI view and its related binding infrastructure. It creates and configures a UIView, registers event listeners for navigation, cursor and input events, manages a CompositeBinding that aggregates multiple binding sets (localization, app state, overlays, input hints, etc.), and exposes helper properties such as the current view and various binding containers. The class also handles lifecycle concerns (attaching/detaching bindings, disposing the view) and forwards specific UI events to the game's InputManager and settings system.
Fields
-
private static ILog log
Used for logging; initialized from UIManager.log. Used to trace lifecycle events such as readiness for bindings. -
private UICursorCollection m_CursorCollection
Holds cursor resources (loaded from "Input/UI Cursors") and is used to change the UI cursor when the cohtml view signals cursor changes. -
private CompositeBinding m_Bindings
Aggregate of multiple binding sets. Responsible for attaching/detaching bindings to the cohtml view and updating-bound data each frame. -
private TaskCompletionSource<bool> m_BindingsReady
Task completion source that is completed when the cohtml view is ready and bindings have been attached. Exposed via WaitForBindings() for async waiting.
Properties
-
public UIView view { get; private set; }
The cohtml-backed UIView instance created by the supplied UISystem. Represents the root UI view for this interface. -
public LocalizationBindings localizationBindings { get; private set; }
Binding container for localization strings and dictionary access. -
public OverlayBindings overlayBindings { get; private set; }
Bindings and helpers for overlay screens and UI overlays. -
public AppBindings appBindings { get; private set; }
Bindings for application-level state (e.g., "can continue" state, active UI). -
public InputHintBindings inputHintBindings { get; private set; }
Bindings related to on-screen input hints. -
public ParadoxBindings paradoxBindings { get; private set; }
Bindings used for Paradox-specific UI/behaviour. -
public VirtualKeyboard virtualKeyboard { get; private set; }
Text input handler passed to UIView.Settings to handle text input via the virtual keyboard implementation. -
public IBindingRegistry bindings => m_Bindings
Exposes the composite binding as an IBindingRegistry for external inspection.
Constructors
public UserInterface(string url, LocalizationManager localizationManager, Colossal.UI.UISystem uiSystem)
Creates a UI view from the given cohtml url, initializes a VirtualKeyboard, prepares UIView.Settings (including allowing text input), sets up event listeners on the view, constructs and registers binding sets (localization, app, overlay, audio, user, input, input actions, input hints, paradox), and registers for user settings applied notifications. If the view reports it is already ready for bindings, OnReadyForBindings is invoked immediately.
Notes: - url: cohtml view URL/path. - localizationManager: supplies localization dictionary and indexed IDs used by overlayBindings. - uiSystem: used to create the UIView instance.
Methods
-
private void OnSettingsApplied(Setting setting)
Callback for SharedSettings.instance.userState.onSettingsApplied. When a UserState is applied, schedules a main-thread task to update appBindings' "can continue" state. -
public void Update()
Call every frame to update all registered binding sets via m_Bindings.Update(). -
public void Dispose()
Cleans up: unsubscribes from settings, deactivates overlays, clears active UI references, disposes and detaches bindings (if attached), removes view listeners and destroys the view via uiSystem. After Dispose the view reference is set to null. -
public Task WaitForBindings()
Returns a Task that completes when bindings have been attached to the view (i.e., when the view signaled ReadyForBindings and OnReadyForBindings executed). Useful for awaiting readiness in async startup logic. -
private void OnReadyForBindings()
Handler for view.Listener.ReadyForBindings. Attaches the composite bindings to the view, marks appBindings.ready = true, and completes the m_BindingsReady Task. -
private bool OnNavigateTo(string url)
Handler for view.Listener.NavigateTo. Detaches current bindings and returns true to allow navigation. Typically used when the view navigates away from the current UI page. -
it sets InputManager.instance.mouseOverUI = false, otherwise true. Returns Actions.ContinueHandling to allow further processing.private Actions OnNodeMouseEvent(INodeProxy node, IMouseEventData ev, IntPtr userData, PhaseType phaseType)
Handler for node-level mouse events. When the active control scheme is KeyboardAndMouse and the event phase is AT_TARGET, this method inspects node tags; if the node is -
private void OnCursorChanged(Cursors cursor, string url)
Handler for view.Listener.CursorChanged. Updates the game's UI cursor via m_CursorCollection. If the cohtml cursor is Cursors.URL and url is provided, the cursor is set to that URL; otherwise sets the cursor by enum. If m_CursorCollection is null, falls back to UICursorCollection.ResetCursor(). -
private void OnTextInputTypeChanged(ControlType type)
Handler for view.Listener.TextInputTypeChanged. Sets InputManager.instance.hasInputFieldFocus depending on whether the control type is TextInput. -
private void OnCaretRectChanged(int x, int y, uint width, uint height)
Handler for view.Listener.CaretRectChanged. Updates InputManager.instance.caretRect with the caret position and size reported by the cohtml view.
Usage Example
// create the UI and wait for bindings to be ready
var ui = new UserInterface("Assets/UI/index.html", localizationManager, uiSystem);
await ui.WaitForBindings(); // ensure bindings are attached before interacting
// in your game's update loop
ui.Update();
// when shutting down or unloading the UI
ui.Dispose();