// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System.Collections.Generic; using FlaxEditor.CustomEditors; using FlaxEditor.CustomEditors.Elements; using FlaxEditor.GUI; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Options { /// /// Theme options data container object. /// [CustomEditor(typeof(ThemeOptionsEditor))] public sealed class ThemeOptions { internal class ThemeOptionsEditor : Editor { private LabelElement _infoLabel; /// public override void Initialize(LayoutElementsContainer layout) { _infoLabel = layout.Label("Editor restart is required to apply style changes.", TextAlignment.Center); _infoLabel.Label.Visible = false; base.Initialize(layout); } /// protected override void Deinitialize() { _infoLabel = null; base.Deinitialize(); } /// protected override bool OnDirty(CustomEditor editor, object value, object token = null) { _infoLabel.Label.Visible = true; return base.OnDirty(editor, value, token); } } internal class StyleOptionsEditor : CustomEditor { private ComboBoxElement _combobox; /// public override DisplayStyle Style => DisplayStyle.Inline; /// public override void Initialize(LayoutElementsContainer layout) { _combobox = layout.ComboBox(); ReloadOptions(_combobox.ComboBox); _combobox.ComboBox.SelectedIndexChanged += OnComboBoxSelectedIndexChanged; _combobox.ComboBox.PopupShowing += ReloadOptions; } private void ReloadOptions(ComboBox obj) { var themeOptions = (ThemeOptions)ParentEditor.Values[0]; var options = new string[themeOptions.Styles.Count + 1]; options[0] = "Default"; int i = 0; foreach (var styleName in themeOptions.Styles.Keys) { options[i + 1] = styleName; i++; } _combobox.ComboBox.SetItems(options); _combobox.ComboBox.SelectedItem = (string)Values[0]; } private void OnComboBoxSelectedIndexChanged(ComboBox combobox) { SetValue(combobox.SelectedItem); } /// public override void Refresh() { _combobox.ComboBox.SelectedItem = (string)Values[0]; base.Refresh(); } } /// /// Currently selected style. /// [CustomEditor(typeof(StyleOptionsEditor))] [Tooltip("Restart Editor to apply style")] public string SelectedStyle = "Default"; /// /// All available styles. /// public Dictionary Styles { get; set; } = new Dictionary(); } }