Game.UI.Menu.ModdingToolchainDependency
Assembly: Assembly-CSharp
Namespace: Game.UI.Menu
Type: class
Base: ReadonlyField
Summary:
Represents a read-only UI field that displays an IToolchainDependency and can expand/collapse to show child widgets. The widget uses an ITypedValueAccessor
Fields
-
private bool m_Expanded
Tracks the last-known expanded state used to detect changes during Update and to raise WidgetChanges when the value toggles. -
private IList<IWidget> m_Children = Array.Empty<IWidget>()
Holds the current list of child widgets. Initialized to an empty array to avoid null checks. When replaced, the setter calls ContainerExtensions.SetDefaults and may trigger children change notifications if the control is expanded.
Properties
-
public ITypedValueAccessor<bool> expandedAccessor { get; set; }
Accessor used to read and write the persisted/host expansion state. If null, the control falls back to treating itself as expanded by default. -
public bool expanded { get; set; }
Wrapper property that reads/writes the boolean through expandedAccessor. Getter returns expandedAccessor?.GetTypedValue() ?? true. Setter writes via expandedAccessor?.SetTypedValue(value). This is the externally stored expanded state, not the internal m_Expanded tracking field. -
public IList<IWidget> children { get; set; }
Gets or sets the child widgets collection. The setter compares for equality with the existing m_Children; if different it calls ContainerExtensions.SetDefaults(value), replaces m_Children, and calls SetChildrenChanged() if the control is currently expanded. -
public override IList<IWidget> visibleChildren { get; }
Returns children when expanded; otherwise returns an empty array. This drives which child widgets are considered for visibility updates and rendering.
Constructors
public ModdingToolchainDependency()
Initializes a new instance and assigns base.valueWriter = new ModdingToolchainDependencyWriter() so the displayed toolchain dependency uses the custom writer for its value presentation.
Methods
-
public override WidgetChanges UpdateVisibility()
Iterates through visibleChildren (filtered by current expanded state) and calls UpdateVisibility() on each child widget (casts to Widget when enumerating). Finally returns base.UpdateVisibility() so parent behavior is preserved. Ensures child visibility is refreshed only when they are actually visible. -
protected override WidgetChanges Update()
Calls base.Update() and then compares the current value read from expandedAccessor to the internal m_Expanded. If the expanded state changed, it sets widgetChanges |= WidgetChanges.Properties | WidgetChanges.Children, updates m_Expanded, and returns the aggregated changes. This causes the UI to react to expand/collapse (property updates and children list changes).
Usage Example
using Game.UI.Menu;
using Game.UI.Widgets;
using Game.Modding.Toolchain;
using Game.Reflection;
using System.Collections.Generic;
// Example: creating the widget and wiring up a simple boolean accessor
public class Example
{
public void Create()
{
var dependencyWidget = new ModdingToolchainDependency();
// Provide an accessor implementation to persist expansion state (example implementation)
dependencyWidget.expandedAccessor = new SimpleBooleanAccessor(initialValue: false);
// Set child widgets (these will receive defaults via ContainerExtensions.SetDefaults)
dependencyWidget.children = new List<IWidget>
{
new LabelWidget("Dependency detail 1"),
new LabelWidget("Dependency detail 2")
};
// The widget will use ModdingToolchainDependencyWriter to render the IToolchainDependency value.
// When expandedAccessor's value changes, Update() will mark properties & children as changed.
}
}
// A trivial example accessor (replace with game's accessor implementation)
public class SimpleBooleanAccessor : ITypedValueAccessor<bool>
{
private bool _value;
public SimpleBooleanAccessor(bool initialValue) => _value = initialValue;
public bool GetTypedValue() => _value;
public void SetTypedValue(bool value) => _value = value;
}
Notes: - The widget defaults to expanded if expandedAccessor is null. - Replacing children will call ContainerExtensions.SetDefaults on the new collection — ensure children are valid IWidget instances. - The writer assigned in the constructor (ModdingToolchainDependencyWriter) controls how the IToolchainDependency is displayed.