Game.UI.Editor.PopupSearchField
Assembly: Game
Namespace: Game.UI.Editor
Type: class
Base: Widget, ISettable, IWidget, IJsonWritable
Summary:
PopupSearchField is a UI widget representing a search field with support for suggestion items and marking queries as "favorites". It delegates search-state and suggestion data to an external adapter (IAdapter), serializes/deserializes its value and suggestion list to/from JSON, and exposes bindings to mark queries as favorite. The class contains nested types used to describe suggestions (Suggestion), the adapter interface (IAdapter) and bindings factory (Bindings). It is intended for use in in-game editors / mod UI where searchable lists with favorites are needed.
Fields
-
private string m_Value
Holds the current search query value cached locally. It is synchronized from the adapter during Update(). -
private bool m_ValueIsFavorite
Cached flag indicating whether the current search query is marked as a favorite. It is synchronized from the adapter during Update(). -
private List<Suggestion> m_Suggestions = new List<Suggestion>()
Cached list of Suggestion entries (value + favorite flag). This list is updated when adapter.searchSuggestions differs from the cached list (using SequenceEqual).
Properties
-
public IAdapter adapter { get; set; }
Adapter used to connect the widget to the backing search model. The adapter must implement IAdapter (extends SearchField.IAdapter) and provides properties and methods used by the widget: searchQuery, searchQueryIsFavorite, searchSuggestions, and SetFavorite(query, favorite). PopupSearchField reads from and writes to this adapter to stay in sync with the underlying search state. -
public bool hasFavorites { get; set; }
If true, the widget exposes favorite-related UI affordances (e.g., favorite markers in suggestion list). The value is written out by WriteProperties for JSON consumers. -
public bool shouldTriggerValueChangedEvent => true
Read-only property indicating that this widget should trigger value-changed events. Always returns true for PopupSearchField.
Constructors
public PopupSearchField()
Default constructor (no explicit constructor defined in source — the compiler-provided default is used). No special initialization beyond the base Widget initialization and the private fields already declared.
Methods
-
public void SetValue(IJsonReader reader)
Implements ISettable; reads a string from the supplied IJsonReader and forwards it to SetValue(string). Used to set the widget's value from JSON input. -
public void SetValue(string value)
Sets the search query via the adapter if the provided value differs from the cached m_Value. Specifically, if value != m_Value then it assigns adapter.searchQuery = value. This ensures adapter/state is changed only when necessary. -
protected override WidgetChanges Update()
Synchronizes the widget's cached state with the adapter. It compares adapter.searchQuery against m_Value, adapter.searchQueryIsFavorite against m_ValueIsFavorite, and the adapter.searchSuggestions against the cached m_Suggestions (SequenceEqual). If differences are found, the corresponding cached fields are updated and the WidgetChanges.Properties flag is set in the returned WidgetChanges to indicate that the widget's properties have changed and need to be sent to the UI consumer. -
protected override void WriteProperties(IJsonWriter writer)
Serializes relevant properties into the provided IJsonWriter. It writes the following properties: - hasFavorites (bool)
- value (string; m_Value or empty string if null)
- valueIsFavorite (bool; m_ValueIsFavorite)
- suggestions (list of Suggestion; the cached m_Suggestions) This is used to produce the JSON that describes the widget's current visible state.
Additional nested types and notable behaviors:
- IAdapter: extends SearchField.IAdapter and exposes:
- bool searchQueryIsFavorite { get; }
- IEnumerable
- Suggestion (struct): represents a suggestion item with fields/properties:
- string value
-
bool favorite It implements IComparable
and IEquatable . CompareTo groups by favorite first (favorite.CompareTo(other.favorite)), and then by ordinal string compare of value when favorite flags are equal. Equality checks both value and favorite. It also implements IJsonWritable via Write to serialize itself as JSON. -
Bindings (class): implements IWidgetBindingFactory. It provides a TriggerBinding under the name "setSearchFavorite" which, when invoked, calls adapter.SetFavorite(query, favorite) on the widget instance (if the target widget is a PopupSearchField). This enables bindings-driven favorite toggles from UI or data binding systems.
Usage Example
// Example: set up a PopupSearchField in a custom widget and attach an adapter.
// Assume MyAdapter implements PopupSearchField.IAdapter.
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
var popup = new PopupSearchField();
popup.adapter = new MyAdapter(); // provide adapter that exposes searchQuery, searchSuggestions, etc.
popup.hasFavorites = true;
// Programmatically set the search value (calls adapter.searchQuery if changed)
popup.SetValue("park");
// Mark a query as favorite via adapter (or use binding "setSearchFavorite")
popup.adapter.SetFavorite("park", true);
}
Notes: - The widget expects an adapter to supply and accept the authoritative search state. Without a properly-implemented adapter, the widget cannot function. - Suggestion equality includes the favorite flag; toggling favorite on an existing suggestion will cause Update() to treat the list as changed. - The JSON property names emitted by WriteProperties are: "hasFavorites", "value", "valueIsFavorite", and "suggestions".