Skip to content

Game.UI.Menu.InputBindingField

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

Type: public class

Base: Field, IWarning

Summary:
InputBindingField is a UI field component used to display and edit input bindings (ProxyBinding) in the in-game UI. It exposes a nested Bindings factory that creates widget trigger bindings to rebind, unset, and reset input bindings via the InputRebindingUISystem. The class serializes conflict information into JSON when writing properties and uses a ValueWriter to output its value. Equality checks between values are performed using ProxyBinding.pathAndModifiersComparer so only path-and-modifiers differences are considered relevant for change detection.


Fields

  • No private instance fields declared in this type.
    This class relies on inherited members (for example, the protected/inherited m_Value from Field) and only assigns base.valueWriter in the constructor.

Nested Types

  • public class Bindings : IWidgetBindingFactory
    Creates three TriggerBinding entries for widget bindings:
  • "rebindInput" — Launches InputRebindingUISystem.Start with the current field value so the user can rebind the input; the callback sets the resulting ProxyBinding on the field.
  • "unsetInputBinding" — Copies the current ProxyBinding, clears the path and modifiers (using Array.Empty()), sets that value on the field and triggers the onValueChanged callback.
  • "resetInputBinding" — Creates a copy of the original binding, resets its conflict cache, and starts InputRebindingUISystem with both original and new values; the callback sets the resulting ProxyBinding on the field.

Properties

  • public bool warning { get; private set }
    The getter inspects the field's ProxyBinding state to determine whether a warning should be shown (based on conflict and built-in flags). The setter always throws NotSupportedException ("warning cannot be set to InputBindingField"). Implementation notes:
  • Getter expression in source: ((uint)m_Value.hasConflicts & (uint)(m_Value.isBuiltIn ? 1 : 3)) != 0
  • This evaluates whether the binding should be considered in a conflict/warning state, taking into account whether the binding is built-in.

Constructors

  • public InputBindingField()
    Initializes the field's value writer:
  • base.valueWriter = new ValueWriter();

Methods

  • protected override bool ValueEquals(ProxyBinding newValue, ProxyBinding oldValue)
    Compares the new and old ProxyBinding instances using a comparer that focuses on path and modifiers:
  • return ProxyBinding.pathAndModifiersComparer.Equals(newValue, oldValue);

  • protected override void WriteProperties(IJsonWriter writer)
    Writes JSON properties for the field. The override first calls the base implementation and then writes the "conflicts" property from the current value:

  • base.WriteProperties(writer);
  • writer.PropertyName("conflicts");
  • writer.Write(m_Value.conflicts);

  • IEnumerable<IBinding> Bindings.CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
    (see Nested Types section) Produces TriggerBindings wired to UI triggers:

  • "rebindInput" — open rebinding UI and set returned value
  • "unsetInputBinding" — clear the binding path and modifiers and invoke onValueChanged
  • "resetInputBinding" — restore the original binding and open rebinding UI for confirmation

Usage Example

// Example showing basic instantiation/usage of the field in mod code.
// Note: SetValue is inherited from Field<T> (not shown in this file).
[Preserve]
public void SetupInputField()
{
    var inputField = new InputBindingField();
    var initialBinding = new ProxyBinding(); // construct with desired defaults
    inputField.SetValue(initialBinding);

    // Check whether the field currently signals a warning (read-only)
    bool showWarning = inputField.warning;

    // The Bindings factory is used by the UI system to wire up widget triggers:
    // new InputBindingField.Bindings() will be called by the UI binding infrastructure
    // to create "rebindInput", "unsetInputBinding", and "resetInputBinding" triggers.
}