Game.UI.Editor.HierarchyMenu
Assembly: Assembly-CSharp (game code / modding)
Namespace: Game.UI.Editor
Type: abstract class
Base: Widget
Summary:
HierarchyMenu is an abstract base widget intended for editor UI that displays a hierarchical list of items (a hierarchy/tree) and receives external binding-based events to control which portion of the hierarchy is rendered and the selection/expansion state of items. It declares a SelectionType enum to describe selection behavior modes and provides a nested Bindings class that creates binding triggers which route UI/data-binding events to the protected abstract handlers. Implementations should override the abstract handlers to update the internal representation / visual state when the UI system signals changes.
Fields
- This class declares no explicit instance fields in the source file.
Implementations may maintain data structures (visible items, selection state, expansion state) as needed inside subclasses.
Properties
- This class declares no public or protected properties in the source file.
The class exposes behavior via abstract methods and the nested Bindings factory.
Constructors
- No explicit constructors are declared.
As an abstract class it uses the default constructor; subclasses should call base class initialization if the base class requires it (not shown in the source file).
Methods
-
protected abstract void OnSetRenderedRange(int startVisibleIndex, int endVisibleIndex)
Called when the UI/binding layer indicates which range of viewport indices should be rendered. Implementations should ensure that the items in the provided index range are prepared (loaded, instantiated or bound) for display. -
protected abstract void OnSetItemSelected(int viewportIndex, bool selected)
Called when a specific viewport item is marked selected or deselected by the UI/binding layer. Implementations should update selection state and visuals for the item at the given viewport index. -
protected abstract void OnSetItemExpanded(int viewportIndex, bool expanded)
Called when a specific viewport item is expanded or collapsed by the UI/binding layer. Implementations should update expansion state and visuals for the item at the given viewport index.
Nested types and bindings:
public enum SelectionType
singleSelection
— only one item selected at a time.multiSelection
— multiple independent selections allowed.-
inheritedMultiSelection
— multi-selection where selection may be inherited/propagated (e.g., selecting a parent affects children) — semantics depend on the concrete implementation. -
public class Bindings : IWidgetBindingFactory
Implements CreateBindings(...) and yields three TriggerBinding entries that map binding triggers (strings) to the HierarchyMenu's handlers: - "setHierarchyRenderedRange" => triggers OnSetRenderedRange(startVisibleIndex, endVisibleIndex)
- "setHierarchyItemSelected" => triggers OnSetItemSelected(viewportIndex, selected)
- "setHierarchyItemExpanded" => triggers OnSetItemExpanded(viewportIndex, expanded) Each trigger checks that the targeted widget is a HierarchyMenu, calls the corresponding handler, then invokes the provided onValueChanged callback to notify the binding system of the change.
Notes: - The bindings are intended to be used by the UI/data-binding layer (Colossal.UI.Binding) to drive the menu from external data or controller code. - Viewport indices are indices into the currently visible/virtualized viewport; implementations must map viewport indices to underlying item data.
Usage Example
public class MyHierarchyMenu : HierarchyMenu
{
protected override void OnSetRenderedRange(int startVisibleIndex, int endVisibleIndex)
{
// Prepare or bind items in the range [startVisibleIndex, endVisibleIndex]
}
protected override void OnSetItemSelected(int viewportIndex, bool selected)
{
// Update selection state for the item that maps to viewportIndex
}
protected override void OnSetItemExpanded(int viewportIndex, bool expanded)
{
// Update expansion state (show/hide children) for the item at viewportIndex
}
// Optionally expose the Bindings factory to the UI system so the binding strings
// ("setHierarchyRenderedRange", "setHierarchyItemSelected", "setHierarchyItemExpanded")
// are hooked up to this widget instance.
}
Additional tips: - Use the Bindings class to register this widget with the Colossal.UI binding system so external code can drive rendering, selection and expansion using the binding strings shown above. - When implementing virtualization (rendered range), keep a consistent mapping from viewportIndex to the underlying item model so selection/expansion calls are applied to the correct items.