// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using FlaxEditor.CustomEditors; using FlaxEditor.GUI.Docking; using FlaxEditor.Windows; using FlaxEngine.GUI; namespace FlaxEditor { /// /// Base class for custom editor window that can create custom GUI layout and expose various functionalities to the user. /// /// public abstract class CustomEditorWindow : CustomEditor { private class Win : EditorWindow { private readonly CustomEditorPresenter _presenter; private CustomEditorWindow _customEditor; public Win(CustomEditorWindow customEditor) : base(Editor.Instance, false, ScrollBars.Vertical) { Title = customEditor.GetType().Name; _customEditor = customEditor; _presenter = new CustomEditorPresenter(null); _presenter.Panel.Parent = this; Set(customEditor); } private void Set(CustomEditorWindow value) { _customEditor = value; _presenter.Select(value); _presenter.OverrideEditor = value; } /// protected override void OnShow() { base.OnShow(); _presenter.BuildLayout(); } /// protected override void OnClose() { Set(null); base.OnClose(); } } private readonly Win _win; /// /// Gets the editor window. /// public EditorWindow Window => _win; /// /// Initializes a new instance of the class. /// protected CustomEditorWindow() { _win = new Win(this); ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin; } /// /// Finalizes an instance of the class. /// ~CustomEditorWindow() { ScriptsBuilder.ScriptsReloadBegin -= OnScriptsReloadBegin; } private void OnScriptsReloadBegin() { // Skip if window type is not from game script assembly (eg. plugin code) var type = GetType(); if (!FlaxEngine.Scripting.IsTypeFromGameScripts(type)) return; if (!Window.IsHidden) { Editor.Instance.Windows.AddToRestore(this); } Window.Close(); Window.Dispose(); } /// /// Shows the window. /// /// Initial window state. /// The panel to dock to, if any. /// Only used if is set. If true the window will be selected after docking it. /// The splitter value to use if toDock is not null. If not specified, a default value will be used. public void Show(DockState state = DockState.Float, DockPanel toDock = null, bool autoSelect = true, float? splitterValue = null) { _win.Show(state, toDock, autoSelect, splitterValue); } } }