Merge branch 'texture-window-tabs' of https://github.com/Tryibion/FlaxEngine into Tryibion-texture-window-tabs
This commit is contained in:
@@ -21,54 +21,75 @@ namespace FlaxEditor.Windows.Assets
|
||||
/// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" />
|
||||
public sealed class TextureWindow : AssetEditorWindowBase<Texture>
|
||||
{
|
||||
private sealed class ProxyEditor : GenericEditor
|
||||
/// <summary>
|
||||
/// Properties base class.
|
||||
/// </summary>
|
||||
public class PropertiesProxyBase
|
||||
{
|
||||
public override void Initialize(LayoutElementsContainer layout)
|
||||
internal TextureWindow _window;
|
||||
|
||||
/// <summary>
|
||||
/// Gathers parameters from the specified texture.
|
||||
/// </summary>
|
||||
/// <param name="window">The asset window.</param>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears temporary data.
|
||||
/// </summary>
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The texture properties proxy object.
|
||||
/// The texture import properties proxy object.
|
||||
/// </summary>
|
||||
[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.
|
||||
/// </summary>
|
||||
/// <param name="window">The asset window.</param>
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Clears temporary data.
|
||||
/// </summary>
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// The presenter to use in the tab.
|
||||
/// </summary>
|
||||
public CustomEditorPresenter Presenter;
|
||||
|
||||
/// <summary>
|
||||
/// The proxy to use in the tab.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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;
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -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
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnClose()
|
||||
{
|
||||
// Discard unsaved changes
|
||||
_properties.DiscardChanges();
|
||||
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user