Game.UI.Editor.EditorPanelSystemBase
Assembly:
Game (Assembly-CSharp)
Namespace:
Game.UI.Editor
Type:
abstract class
Base:
GameSystemBase, IEditorPanel
Summary:
Base class for editor-panel systems used by the game's UI editor. Provides common functionality for panels that can host child widgets and optionally delegate behavior to an active sub-panel (IEditorPanel). Handles switching between sub-panels, forwarding IEditorPanel interface calls to the active sub-panel, and integrates with Unity/Colossal component systems by enabling/disabling and updating ComponentSystemBase sub-panels in OnUpdate. Also exposes a default widget renderer and a logger configured for the editor.
Fields
private IEditorPanel m_LastSubPanel
Holds the previously active sub-panel to detect changes when switching activeSubPanel.
Properties
-
protected IEditorPanel activeSubPanel { get; set; }
The currently active child sub-panel. When set to a ComponentSystemBase, the system will enable/disable and update it as appropriate in OnUpdate. Marked [CanBeNull]. -
protected virtual LocalizedString title { get; set; }
Panel title shown when there is no active sub-panel. Can be overridden by derived classes. -
protected virtual IList<IWidget> children { get; set; } = Array.Empty<IWidget>()
Widgets that belong to this panel. When there is an activeSubPanel, the panel forwards children access to the sub-panel. -
public virtual EditorPanelWidgetRenderer widgetRenderer => EditorPanelWidgetRenderer.Editor
Which widget renderer to use for this panel. Defaults to Editor. -
protected ILog log { get; } = LogManager.GetLogger("Editor")
Logger instance preconfigured with the "Editor" category for diagnostics and debugging. -
LocalizedString IEditorPanel.title
Explicit interface implementation. Returns the activeSubPanel.title if a sub-panel is active; otherwise returns this.title. -
IList<IWidget> IEditorPanel.children
Explicit interface implementation. Returns the activeSubPanel.children if a sub-panel is active; otherwise returns this.children.
Constructors
protected EditorPanelSystemBase()
[Preserve] default constructor. The class is abstract; derived classes should call base() which performs no extra initialization besides the default.
Methods
-
protected override void OnCreate()
[Preserve] Called when the system is created. Calls base.OnCreate() and sets base.Enabled = false so the system is initially disabled by default (panels are enabled when used). -
protected override void OnUpdate()
Monitors changes to activeSubPanel. If activeSubPanel changed: - If m_LastSubPanel was a ComponentSystemBase, it is disabled and its Update() is invoked once to allow any shutdown logic.
- Updates m_LastSubPanel reference.
-
If the new activeSubPanel is a ComponentSystemBase, it is enabled. After handling switches, if activeSubPanel is a ComponentSystemBase it calls Update() on it every frame, effectively forwarding update to the sub-panel.
-
protected virtual void OnValueChanged(IWidget widget)
Hook for derived classes to react to widget value changes when there is no active sub-panel. Default implementation is empty. -
protected virtual bool OnCancel()
Called when a cancel action occurs and there is no active sub-panel. Default implementation forwards to OnClose(). Return true to allow the caller to close the panel; false to prevent close. -
protected virtual bool OnClose()
Called when a close action occurs and there is no active sub-panel. Default implementation returns true (allow close). Derived classes can override to prevent closing or to perform cleanup. -
public void CloseSubPanel()
Sets activeSubPanel to null, effectively closing any open sub-panel. -
void IEditorPanel.OnValueChanged(IWidget widget)
Explicit interface implementation that forwards the event to the active sub-panel if present; otherwise calls this.OnValueChanged(widget). -
bool IEditorPanel.OnCancel()
Explicit interface implementation that forwards the cancel action to the active sub-panel if present. If the sub-panel returns true (indicating it handled close), clears activeSubPanel and returns false (meaning the outer panel should remain open). If no sub-panel is present, calls this.OnCancel() and returns its result. -
bool IEditorPanel.OnClose()
Explicit interface implementation that forwards the close action to the active sub-panel if present. If the sub-panel returns true (indicating it handled close), clears activeSubPanel and returns false. If no sub-panel is present, calls this.OnClose() and returns its result.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The base implementation sets Enabled = false; enable if you want this panel to update:
// base.Enabled = true;
// Set a default title and widgets for this editor panel
title = new LocalizedString("My Editor Panel");
children = new List<IWidget>
{
new ButtonWidget("Apply"),
new ButtonWidget("Close")
};
}
// Example: open a sub-panel at runtime
void OpenSubPanel(IEditorPanel subPanel)
{
activeSubPanel = subPanel;
}
// Example: close the current sub-panel
void CloseCurrentSubPanel()
{
CloseSubPanel();
}
Notes: - Many sub-panels may be implemented as ComponentSystemBase. This base class will automatically enable/disable and update such sub-panels when they become active. - Interface members are explicitly implemented so consumers using IEditorPanel will receive forwarded calls to the active sub-panel when present.