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" />
|
/// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" />
|
||||||
public sealed class TextureWindow : AssetEditorWindowBase<Texture>
|
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;
|
// Link
|
||||||
var texture = window?.Asset;
|
_window = window;
|
||||||
if (texture == null || !texture.IsLoaded)
|
}
|
||||||
{
|
|
||||||
layout.Label("Loading...", TextAlignment.Center);
|
/// <summary>
|
||||||
return;
|
/// Clears temporary data.
|
||||||
}
|
/// </summary>
|
||||||
|
public void OnClean()
|
||||||
// Texture info
|
{
|
||||||
var general = layout.Group("General");
|
// Unlink
|
||||||
general.Label("Format: " + texture.Format);
|
_window = null;
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[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>
|
/// <summary>
|
||||||
/// The texture properties proxy object.
|
/// The texture import properties proxy object.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[CustomEditor(typeof(ProxyEditor))]
|
[CustomEditor(typeof(ProxyEditor))]
|
||||||
private sealed class PropertiesProxy
|
private sealed class ImportPropertiesProxy : PropertiesProxyBase
|
||||||
{
|
{
|
||||||
internal TextureWindow _window;
|
|
||||||
|
|
||||||
[EditorOrder(1000), EditorDisplay("Import Settings", EditorDisplayAttribute.InlineStyle)]
|
[EditorOrder(1000), EditorDisplay("Import Settings", EditorDisplayAttribute.InlineStyle)]
|
||||||
public FlaxEngine.Tools.TextureTool.Options ImportSettings = new();
|
public FlaxEngine.Tools.TextureTool.Options ImportSettings = new();
|
||||||
|
|
||||||
@@ -76,10 +97,9 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
/// Gathers parameters from the specified texture.
|
/// Gathers parameters from the specified texture.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="window">The asset window.</param>
|
/// <param name="window">The asset window.</param>
|
||||||
public void OnLoad(TextureWindow window)
|
public override void OnLoad(TextureWindow window)
|
||||||
{
|
{
|
||||||
// Link
|
base.OnLoad(window);
|
||||||
_window = window;
|
|
||||||
|
|
||||||
// Try to restore target asset texture import options (useful for fast reimport)
|
// Try to restore target asset texture import options (useful for fast reimport)
|
||||||
Editor.TryRestoreImportOptions(ref ImportSettings, window.Item.Path);
|
Editor.TryRestoreImportOptions(ref ImportSettings, window.Item.Path);
|
||||||
@@ -109,22 +129,85 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
public void DiscardChanges()
|
public void DiscardChanges()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
private sealed class ProxyEditor : GenericEditor
|
||||||
/// Clears temporary data.
|
|
||||||
/// </summary>
|
|
||||||
public void OnClean()
|
|
||||||
{
|
{
|
||||||
// Unlink
|
public override void Initialize(LayoutElementsContainer layout)
|
||||||
_window = null;
|
{
|
||||||
|
// 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 SplitPanel _split;
|
||||||
private readonly TexturePreview _preview;
|
private readonly TexturePreview _preview;
|
||||||
private readonly CustomEditorPresenter _propertiesEditor;
|
|
||||||
private readonly ToolStripButton _saveButton;
|
private readonly ToolStripButton _saveButton;
|
||||||
private readonly PropertiesProxy _properties;
|
|
||||||
private bool _isWaitingForLoad;
|
private bool _isWaitingForLoad;
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -145,12 +228,20 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
{
|
{
|
||||||
Parent = _split.Panel1
|
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
|
_tabs.AddTab(new TextureTab(this));
|
||||||
_propertiesEditor = new CustomEditorPresenter(null);
|
_tabs.AddTab(new ImportTab(this));
|
||||||
_propertiesEditor.Panel.Parent = _split.Panel2;
|
|
||||||
_properties = new PropertiesProxy();
|
|
||||||
_propertiesEditor.Select(_properties);
|
|
||||||
|
|
||||||
// Toolstrip
|
// Toolstrip
|
||||||
_saveButton = (ToolStripButton)_toolstrip.AddButton(Editor.Icons.Save64, Save).LinkTooltip("Save");
|
_saveButton = (ToolStripButton)_toolstrip.AddButton(Editor.Icons.Save64, Save).LinkTooltip("Save");
|
||||||
@@ -164,7 +255,11 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void UnlinkItem()
|
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;
|
_preview.Asset = null;
|
||||||
_isWaitingForLoad = false;
|
_isWaitingForLoad = false;
|
||||||
|
|
||||||
@@ -195,15 +290,6 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
base.UpdateToolstrip();
|
base.UpdateToolstrip();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void OnClose()
|
|
||||||
{
|
|
||||||
// Discard unsaved changes
|
|
||||||
_properties.DiscardChanges();
|
|
||||||
|
|
||||||
base.OnClose();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Save()
|
public override void Save()
|
||||||
{
|
{
|
||||||
@@ -231,8 +317,14 @@ namespace FlaxEditor.Windows.Assets
|
|||||||
_isWaitingForLoad = false;
|
_isWaitingForLoad = false;
|
||||||
|
|
||||||
// Init properties and parameters proxy
|
// Init properties and parameters proxy
|
||||||
_properties.OnLoad(this);
|
foreach (var child in _tabs.Children)
|
||||||
_propertiesEditor.BuildLayout();
|
{
|
||||||
|
if (child is Tab tab && tab.Proxy != null)
|
||||||
|
{
|
||||||
|
tab.Proxy.OnLoad(this);
|
||||||
|
tab.Presenter.BuildLayout();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Setup
|
// Setup
|
||||||
ClearEditedFlag();
|
ClearEditedFlag();
|
||||||
|
|||||||
Reference in New Issue
Block a user