Skip to content

Game.UI.Editor.EditorPanelBase

Assembly: Game
Namespace: Game.UI.Editor

Type: abstract class

Base: IEditorPanel

Summary:
EditorPanelBase is a small, reusable base class for editor UI panels in Cities: Skylines 2 modding. It implements the IEditorPanel interface and provides basic behavior and defaults: - Holds a localized panel title. - Exposes a collection of child widgets. - Supplies a default widget renderer and simple lifecycle hooks (OnValueChanged, OnCancel, OnClose) that can be overridden by derived panels.

This class is intended to be subclassed by modders creating custom editor panels; override properties and virtual methods to customize appearance and behavior.

Fields

  • None.
    This type does not declare any explicit backing fields; state is exposed through auto-properties.

Properties

  • public LocalizedString title { get; set; }
    Holds the panel title as a LocalizedString so the UI can display localized names. Set this in your panel implementation or at construction time.

  • public IList<IWidget> children { get; set; } = Array.Empty<IWidget>();
    A list of child widgets that belong to this panel. Defaults to an empty, immutable array; override or replace with a mutable collection (e.g., List) when you want to add widgets.

  • public virtual EditorPanelWidgetRenderer widgetRenderer => EditorPanelWidgetRenderer.Editor
    Specifies which widget renderer should be used to draw this panel. The default value is EditorPanelWidgetRenderer.Editor. Override this property in derived classes to select or implement a different renderer.

Constructors

  • public EditorPanelBase()
    No explicit constructor is declared in source — the default parameterless constructor is used. Initialize title and children in derived types or in your own constructor.

Methods

  • public virtual void OnValueChanged(IWidget widget)
    Called when a child widget value changes. Default implementation is empty. Override this to react to widget changes (update state, validate input, refresh UI, etc.).

  • public virtual bool OnCancel()
    Called when the panel should cancel (for example, user presses a cancel button). Default implementation delegates to OnClose(). Return true to allow the cancel/close, false to prevent it.

  • public virtual bool OnClose()
    Called when the panel is requested to close. Default implementation returns true (allowing the close). Override to implement confirmation dialogs, validation, or prevention of closing under some conditions.

Usage Example

// Example custom editor panel
public class MyCustomPanel : EditorPanelBase
{
    public MyCustomPanel()
    {
        title = new LocalizedString("my_mod.panel.title"); // use your localization key
        children = new List<IWidget>
        {
            // Add widgets implementing IWidget, e.g. LabelWidget, ToggleWidget, etc.
            // new LabelWidget(new LocalizedString("my_mod.label")),
            // new ToggleWidget(initialValue)
        };
    }

    // Choose a different renderer if needed
    public override EditorPanelWidgetRenderer widgetRenderer => EditorPanelWidgetRenderer.Editor;

    public override void OnValueChanged(IWidget widget)
    {
        // React to child widget changes (update settings, re-evaluate UI, etc.)
    }

    public override bool OnCancel()
    {
        // Optionally ask the user to confirm cancellation, then decide:
        // return false; // to block cancel
        return base.OnCancel(); // default behavior -> calls OnClose()
    }

    public override bool OnClose()
    {
        // Validate unsaved changes or confirm with user:
        // return ShowConfirmDialog("Discard changes?");
        return true; // allow closing by default
    }
}

Notes for modders: - Replace LocalizedString usage with your mod's localization keys or localized text helpers. - Populate children with widget implementations from Game.UI.Widgets or your own widgets implementing IWidget. - Use OnValueChanged to keep model/state in sync with widget values; use OnClose/OnCancel to control panel lifecycle.