Skip to content

Game.InputBindings

Assembly:
Assembly-CSharp (game)

Namespace:
Game.UI

Type:
public class

Base:
CompositeBinding, IDisposable

Summary:
Manages UI input-related bindings exposed to the Colossal UI binding system. InputBindings registers a set of Getter/Value/Event/Trigger bindings under the "input" group that reflect the current input state (mouse over UI, hide cursor, active control scheme, scroll sensitivity, gamepad pointer position, camera movement, tool actions, input barriers, etc.). It also creates and manages two InputBarrier instances (Camera and Tool) and listens for tool action events to trigger the corresponding binding. The class is intended to be instantiated by UI code that needs to publish or consume input state through the binding system.


Fields

  • private const string kGroup = "input"
    Provides the binding group name used for all bindings this class registers.

  • private const float kCameraInputSensitivity = 0.2f
    Threshold used for detecting significant camera float input (e.g., zoom/axis).

  • private const float kCameraInputSensitivitySqr = 0.040000003f
    Squared magnitude threshold for detecting significant camera Vector2 input (gamepad/thumbstick). Matches kCameraInputSensitivity^2.

  • private CameraController m_CameraController
    Cached reference to the CameraController (obtained via CameraController.TryGet). Used to inspect in-progress camera input actions.

  • private readonly ValueBinding<bool> m_CameraMovingBinding
    Value binding that exposes whether the camera is currently being moved (based on active input at or above sensitivity thresholds).

  • private readonly EventBinding<bool> m_CameraBarrierBinding
    Event binding used by observers to indicate they want the camera input barrier enabled. The observer count is used to set the barrier's blocked state.

  • private readonly EventBinding<bool> m_ToolBarrierBinding
    Event binding used by observers to indicate they want the tool input barrier enabled. The observer count is used to set the barrier's blocked state.

  • private readonly EventBinding<bool> m_ToolActionPerformedBinding
    Event binding that is triggered when a tool action is performed (ToolBaseSystem.EventToolActionPerformed).

  • private InputBarrier m_CameraInputBarrier
    InputBarrier created for the "Camera" input map. Its blocked property is toggled based on m_CameraBarrierBinding.observerCount.

  • private InputBarrier m_ToolInputBarrier
    InputBarrier created for the "Tool" input map. Its blocked property is toggled based on m_ToolBarrierBinding.observerCount.


Properties

  • None (this class does not expose public properties)

Constructors

  • public InputBindings()
    Initializes the bindings and internal state:
  • Registers GetterValueBinding entries for: mouseOverUI, hideCursor, controlScheme, scrollSensitivity, gamepadPointerPosition, useTextFieldInputBarrier.
  • Registers ValueBinding, EventBinding, and TriggerBinding entries required by the UI for camera/tool input state, tool actions, camera/tool barriers, gamepad pointer events, and setting the active text field rect.
  • Creates two InputBarrier instances via InputManager.instance.CreateMapBarrier("Camera", "InputBindings") and CreateMapBarrier("Tool", "InputBindings").
  • Subscribes to ToolBaseSystem.EventToolActionPerformed to forward tool actions into the m_ToolActionPerformedBinding.

Notes: - The constructor wires event handlers and creates resources that must be cleaned up by calling Dispose().


Methods

  • public void Dispose()
    Disposes the two InputBarrier instances and unsubscribes from ToolBaseSystem.EventToolActionPerformed. This releases native/input resources and avoids leaking event handlers.

  • public override bool Update()
    Updates runtime bindings each frame:

  • Checks CameraController (cached or retrieved) and iterates its inputActions to determine if camera movement is in progress. Uses kCameraInputSensitivity and kCameraInputSensitivitySqr thresholds for float and Vector2 inputs. Updates m_CameraMovingBinding accordingly.
  • Sets m_CameraInputBarrier.blocked if there are observers on m_CameraBarrierBinding.
  • Sets m_ToolInputBarrier.blocked if there are observers on m_ToolBarrierBinding.
  • Returns the result of base.Update() after performing these updates.

Behavioral notes: - Camera movement detection uses raw input values and only sets the "cameraMoving" binding true when input magnitude exceeds thresholds to avoid noisy small inputs. - Barrier blocked states are driven by the observer count of the corresponding event bindings: any observer asking for the barrier will cause it to be blocked.

  • private void OnToolActionPerformed(ProxyAction action)
    Handler for ToolBaseSystem.EventToolActionPerformed. Triggers m_ToolActionPerformedBinding with true to notify binding consumers that a tool action occurred.

  • private void OnGamepadPointerEvent(bool pointerOverUI)
    Trigger from binding "onGamepadPointerEvent". Sets InputManager.instance.mouseOverUI = pointerOverUI so the game input system knows whether the gamepad pointer is over UI.

  • private void SetActiveTextfieldRect(int x, int y, int width, int height)
    Trigger from binding "setActiveTextFieldRect". Calls PlatformManager.instance?.SetActiveTextFieldRect to inform the platform (OS/keyboard) of the on-screen keyboard target rectangle.


Usage Example

// Create bindings and let the UI binding system read/update them each frame.
// Typically owned by a UI manager that calls Update() each frame.
var inputBindings = new Game.UI.InputBindings();

// In your UI update loop:
inputBindings.Update();

// When no longer needed (e.g., on UI shutdown):
inputBindings.Dispose();

Additional example: reacting to camera barrier from a binding consumer - If a UI panel subscribes to the input.cameraBarrier event binding (via the Colossal UI binding observer API), the InputBindings instance will set the Camera InputBarrier.blocked = true while there is at least one observer, preventing camera input from the "Camera" input map.

Remarks and tips - Always call Dispose() to remove event subscriptions and dispose InputBarrier objects to avoid leaks. - The sensitivity constants (kCameraInputSensitivity and kCameraInputSensitivitySqr) reflect the minimum input magnitude considered as active camera movement. If you implement custom camera controls, ensure values are read in a comparable raw form for consistent behavior. - Triggers such as setActiveTextFieldRect are routed to PlatformManager to support on-screen keyboard placement on consoles/platforms that use a virtual keyboard.