From d4bf8368b1dd427d21dc5bedb8068d3007e62957 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 16 Jul 2024 11:43:04 -0500 Subject: [PATCH] Separate import settings as new tab in texture window. --- Source/Editor/Windows/Assets/TextureWindow.cs | 228 ++++++++++++------ 1 file changed, 160 insertions(+), 68 deletions(-) diff --git a/Source/Editor/Windows/Assets/TextureWindow.cs b/Source/Editor/Windows/Assets/TextureWindow.cs index cf913df2b..9d4b94024 100644 --- a/Source/Editor/Windows/Assets/TextureWindow.cs +++ b/Source/Editor/Windows/Assets/TextureWindow.cs @@ -21,54 +21,75 @@ namespace FlaxEditor.Windows.Assets /// public sealed class TextureWindow : AssetEditorWindowBase { - private sealed class ProxyEditor : GenericEditor + /// + /// Properties base class. + /// + public class PropertiesProxyBase { - public override void Initialize(LayoutElementsContainer layout) + internal TextureWindow _window; + + /// + /// Gathers parameters from the specified texture. + /// + /// The asset window. + public virtual void OnLoad(TextureWindow window) { - var window = ((PropertiesProxy)Values[0])._window; - var texture = window?.Asset; - if (texture == null || !texture.IsLoaded) - { - layout.Label("Loading...", TextAlignment.Center); - return; - } - - // Texture info - var general = layout.Group("General"); - general.Label("Format: " + texture.Format); - general.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height)).AddCopyContextMenu(); - general.Label("Mip levels: " + texture.MipLevels); - general.Label("Memory usage: " + Utilities.Utils.FormatBytesCount(texture.TotalMemoryUsage)).AddCopyContextMenu(); - - // Texture properties - var properties = layout.Group("Properties"); - var textureGroup = new CustomValueContainer(new ScriptType(typeof(int)), texture.TextureGroup, - (instance, index) => texture.TextureGroup, - (instance, index, value) => - { - texture.TextureGroup = (int)value; - window.MarkAsEdited(); - }); - properties.Property("Texture Group", textureGroup, new TextureGroupEditor(), "The texture group used by this texture."); - - // Import settings - base.Initialize(layout); - - // Reimport - layout.Space(10); - var reimportButton = layout.Button("Reimport"); - reimportButton.Button.Clicked += () => ((PropertiesProxy)Values[0]).Reimport(); + // Link + _window = window; + } + + /// + /// Clears temporary data. + /// + public void OnClean() + { + // Unlink + _window = null; } } + [CustomEditor(typeof(ProxyEditor))] + private sealed class TexturePropertiesProxy : PropertiesProxyBase + { + private sealed class ProxyEditor : GenericEditor + { + public override void Initialize(LayoutElementsContainer layout) + { + var window = ((TexturePropertiesProxy)Values[0])._window; + var texture = window?.Asset; + if (texture == null || !texture.IsLoaded) + { + layout.Label("Loading...", TextAlignment.Center); + return; + } + + // Texture info + var general = layout.Group("General"); + general.Label("Format: " + texture.Format); + general.Label(string.Format("Size: {0}x{1}", texture.Width, texture.Height)).AddCopyContextMenu(); + general.Label("Mip levels: " + texture.MipLevels); + general.Label("Memory usage: " + Utilities.Utils.FormatBytesCount(texture.TotalMemoryUsage)).AddCopyContextMenu(); + + // Texture properties + var properties = layout.Group("Properties"); + var textureGroup = new CustomValueContainer(new ScriptType(typeof(int)), texture.TextureGroup, + (instance, index) => texture.TextureGroup, + (instance, index, value) => + { + texture.TextureGroup = (int)value; + window.MarkAsEdited(); + }); + properties.Property("Texture Group", textureGroup, new TextureGroupEditor(), "The texture group used by this texture."); + } + } + } + /// - /// The texture properties proxy object. + /// The texture import properties proxy object. /// [CustomEditor(typeof(ProxyEditor))] - private sealed class PropertiesProxy + private sealed class ImportPropertiesProxy : PropertiesProxyBase { - internal TextureWindow _window; - [EditorOrder(1000), EditorDisplay("Import Settings", EditorDisplayAttribute.InlineStyle)] public FlaxEngine.Tools.TextureTool.Options ImportSettings = new(); @@ -76,10 +97,9 @@ namespace FlaxEditor.Windows.Assets /// Gathers parameters from the specified texture. /// /// The asset window. - public void OnLoad(TextureWindow window) + public override void OnLoad(TextureWindow window) { - // Link - _window = window; + base.OnLoad(window); // Try to restore target asset texture import options (useful for fast reimport) Editor.TryRestoreImportOptions(ref ImportSettings, window.Item.Path); @@ -109,22 +129,85 @@ namespace FlaxEditor.Windows.Assets public void DiscardChanges() { } - - /// - /// Clears temporary data. - /// - public void OnClean() + + private sealed class ProxyEditor : GenericEditor { - // Unlink - _window = null; + public override void Initialize(LayoutElementsContainer layout) + { + // Import settings + base.Initialize(layout); + + // Reimport + layout.Space(10); + var reimportButton = layout.Button("Reimport"); + reimportButton.Button.Clicked += () => ((ImportPropertiesProxy)Values[0]).Reimport(); + } } } + private class Tab : GUI.Tabs.Tab + { + /// + /// The presenter to use in the tab. + /// + public CustomEditorPresenter Presenter; + + /// + /// The proxy to use in the tab. + /// + public PropertiesProxyBase Proxy; + + public Tab(string text, TextureWindow window, bool modifiesAsset = true) + : base(text) + { + var scrollPanel = new Panel(ScrollBars.Vertical) + { + AnchorPreset = AnchorPresets.StretchAll, + Offsets = Margin.Zero, + Parent = this + }; + + Presenter = new CustomEditorPresenter(null); + Presenter.Panel.Parent = scrollPanel; + if (modifiesAsset) + Presenter.Modified += window.MarkAsEdited; + } + + /// + public override void OnDestroy() + { + Presenter.Deselect(); + Presenter = null; + Proxy = null; + + base.OnDestroy(); + } + } + + private class TextureTab : Tab + { + public TextureTab(TextureWindow window) + : base("Texture", window) + { + Proxy = new TexturePropertiesProxy(); + Presenter.Select(Proxy); + } + } + + private class ImportTab : Tab + { + public ImportTab(TextureWindow window) + : base("Import", window) + { + Proxy = new ImportPropertiesProxy(); + Presenter.Select(Proxy); + } + } + + private readonly GUI.Tabs.Tabs _tabs; private readonly SplitPanel _split; private readonly TexturePreview _preview; - private readonly CustomEditorPresenter _propertiesEditor; private readonly ToolStripButton _saveButton; - private readonly PropertiesProxy _properties; private bool _isWaitingForLoad; /// @@ -145,12 +228,20 @@ namespace FlaxEditor.Windows.Assets { Parent = _split.Panel1 }; + + // Properties tabs + _tabs = new() + { + AnchorPreset = AnchorPresets.StretchAll, + Offsets = Margin.Zero, + TabsSize = new Float2(60, 20), + TabsTextHorizontalAlignment = TextAlignment.Center, + UseScroll = true, + Parent = _split.Panel2 + }; - // Texture properties editor - _propertiesEditor = new CustomEditorPresenter(null); - _propertiesEditor.Panel.Parent = _split.Panel2; - _properties = new PropertiesProxy(); - _propertiesEditor.Select(_properties); + _tabs.AddTab(new TextureTab(this)); + _tabs.AddTab(new ImportTab(this)); // Toolstrip _saveButton = (ToolStripButton)_toolstrip.AddButton(Editor.Icons.Save64, Save).LinkTooltip("Save"); @@ -164,7 +255,11 @@ namespace FlaxEditor.Windows.Assets /// protected override void UnlinkItem() { - _properties.OnClean(); + foreach (var child in _tabs.Children) + { + if (child is Tab tab && tab.Proxy != null) + tab.Proxy.OnClean(); + } _preview.Asset = null; _isWaitingForLoad = false; @@ -195,15 +290,6 @@ namespace FlaxEditor.Windows.Assets base.UpdateToolstrip(); } - /// - protected override void OnClose() - { - // Discard unsaved changes - _properties.DiscardChanges(); - - base.OnClose(); - } - /// public override void Save() { @@ -231,8 +317,14 @@ namespace FlaxEditor.Windows.Assets _isWaitingForLoad = false; // Init properties and parameters proxy - _properties.OnLoad(this); - _propertiesEditor.BuildLayout(); + foreach (var child in _tabs.Children) + { + if (child is Tab tab && tab.Proxy != null) + { + tab.Proxy.OnLoad(this); + tab.Presenter.BuildLayout(); + } + } // Setup ClearEditedFlag();