# Conflicts: # Source/Platforms/DotNet/NUnit/agents/net40/nunit-agent.exe # Source/Platforms/DotNet/NUnit/agents/net40/nunit.engine.api.dll # Source/Platforms/DotNet/NUnit/agents/net40/nunit.engine.core.dll # Source/Platforms/DotNet/NUnit/agents/net7.0/nunit.agent.addins # Source/Platforms/DotNet/NUnit/nunit.engine.api.dll # Source/Platforms/DotNet/NUnit/nunit.engine.core.dll # Source/Platforms/DotNet/NUnit/nunit.engine.dll # Source/Platforms/DotNet/NUnit/nunit3-console.exe # Source/Platforms/DotNet/NUnit/nunit3-console.exe.config # Source/Platforms/DotNet/NUnit/testcentric.engine.metadata.dll # Source/Tools/Flax.Build/Deps/Downloader.cs # Source/Tools/Flax.Stats/CodeFrame.cs # Source/Tools/Flax.Stats/CodeFrameNode.cs # Source/Tools/Flax.Stats/Flax.Stats.Build.cs # Source/Tools/Flax.Stats/Languages.cs # Source/Tools/Flax.Stats/Program.cs # Source/Tools/Flax.Stats/TaskType.cs # Source/Tools/Flax.Stats/Tools.cs # Source/Tools/FlaxEngine.Tests/TestEditorUtils.cs
264 lines
8.7 KiB
C#
264 lines
8.7 KiB
C#
// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
|
|
|
|
using System.Xml;
|
|
using FlaxEditor.Content;
|
|
using FlaxEditor.Content.Import;
|
|
using FlaxEditor.CustomEditors;
|
|
using FlaxEditor.CustomEditors.Dedicated;
|
|
using FlaxEditor.CustomEditors.Editors;
|
|
using FlaxEditor.GUI;
|
|
using FlaxEditor.Scripting;
|
|
using FlaxEditor.Viewport.Previews;
|
|
using FlaxEngine;
|
|
using FlaxEngine.GUI;
|
|
|
|
namespace FlaxEditor.Windows.Assets
|
|
{
|
|
/// <summary>
|
|
/// Texture window allows to view and edit <see cref="Texture"/> asset.
|
|
/// </summary>
|
|
/// <seealso cref="Texture" />
|
|
/// <seealso cref="FlaxEditor.Windows.Assets.AssetEditorWindow" />
|
|
public sealed class TextureWindow : AssetEditorWindowBase<Texture>
|
|
{
|
|
private sealed class ProxyEditor : GenericEditor
|
|
{
|
|
public override void Initialize(LayoutElementsContainer layout)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// The texture properties proxy object.
|
|
/// </summary>
|
|
[CustomEditor(typeof(ProxyEditor))]
|
|
private sealed class PropertiesProxy
|
|
{
|
|
internal TextureWindow _window;
|
|
|
|
[EditorOrder(1000), EditorDisplay("Import Settings", EditorDisplayAttribute.InlineStyle)]
|
|
public TextureImportSettings ImportSettings = new TextureImportSettings();
|
|
|
|
/// <summary>
|
|
/// Gathers parameters from the specified texture.
|
|
/// </summary>
|
|
/// <param name="window">The asset window.</param>
|
|
public void OnLoad(TextureWindow window)
|
|
{
|
|
// Link
|
|
_window = window;
|
|
|
|
// Try to restore target asset texture import options (useful for fast reimport)
|
|
TextureImportSettings.TryRestore(ref ImportSettings, window.Item.Path);
|
|
|
|
// Prepare restore data
|
|
PeekState();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Records the current state to restore it on DiscardChanges.
|
|
/// </summary>
|
|
public void PeekState()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reimports asset.
|
|
/// </summary>
|
|
public void Reimport()
|
|
{
|
|
Editor.Instance.ContentImporting.Reimport((BinaryAssetItem)_window.Item, ImportSettings);
|
|
}
|
|
|
|
/// <summary>
|
|
/// On discard changes
|
|
/// </summary>
|
|
public void DiscardChanges()
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Clears temporary data.
|
|
/// </summary>
|
|
public void OnClean()
|
|
{
|
|
// Unlink
|
|
_window = null;
|
|
}
|
|
}
|
|
|
|
private readonly SplitPanel _split;
|
|
private readonly TexturePreview _preview;
|
|
private readonly CustomEditorPresenter _propertiesEditor;
|
|
private readonly ToolStripButton _saveButton;
|
|
private readonly PropertiesProxy _properties;
|
|
private bool _isWaitingForLoad;
|
|
|
|
/// <inheritdoc />
|
|
public TextureWindow(Editor editor, AssetItem item)
|
|
: base(editor, item)
|
|
{
|
|
// Split Panel
|
|
_split = new SplitPanel(Orientation.Horizontal, ScrollBars.None, ScrollBars.Vertical)
|
|
{
|
|
AnchorPreset = AnchorPresets.StretchAll,
|
|
Offsets = new Margin(0, 0, _toolstrip.Bottom, 0),
|
|
SplitterValue = 0.7f,
|
|
Parent = this
|
|
};
|
|
|
|
// Texture preview
|
|
_preview = new TexturePreview(true)
|
|
{
|
|
Parent = _split.Panel1
|
|
};
|
|
|
|
// Texture properties editor
|
|
_propertiesEditor = new CustomEditorPresenter(null);
|
|
_propertiesEditor.Panel.Parent = _split.Panel2;
|
|
_properties = new PropertiesProxy();
|
|
_propertiesEditor.Select(_properties);
|
|
|
|
// Toolstrip
|
|
_saveButton = (ToolStripButton)_toolstrip.AddButton(Editor.Icons.Save64, Save).LinkTooltip("Save");
|
|
_toolstrip.AddButton(Editor.Icons.Import64, () => Editor.ContentImporting.Reimport((BinaryAssetItem)Item)).LinkTooltip("Reimport");
|
|
_toolstrip.AddSeparator();
|
|
_toolstrip.AddButton(Editor.Icons.CenterView64, _preview.CenterView).LinkTooltip("Center view");
|
|
_toolstrip.AddSeparator();
|
|
_toolstrip.AddButton(editor.Icons.Docs64, () => Platform.OpenUrl(Utilities.Constants.DocsUrl + "manual/graphics/textures/index.html")).LinkTooltip("See documentation to learn more");
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void UnlinkItem()
|
|
{
|
|
_properties.OnClean();
|
|
_preview.Asset = null;
|
|
_isWaitingForLoad = false;
|
|
|
|
base.UnlinkItem();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void OnAssetLinked()
|
|
{
|
|
_preview.Asset = _asset;
|
|
_isWaitingForLoad = true;
|
|
|
|
base.OnAssetLinked();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void OnItemReimported(ContentItem item)
|
|
{
|
|
// Invalidate data
|
|
_isWaitingForLoad = true;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void UpdateToolstrip()
|
|
{
|
|
_saveButton.Enabled = IsEdited;
|
|
|
|
base.UpdateToolstrip();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
protected override void OnClose()
|
|
{
|
|
// Discard unsaved changes
|
|
_properties.DiscardChanges();
|
|
|
|
base.OnClose();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Save()
|
|
{
|
|
if (!IsEdited)
|
|
return;
|
|
|
|
if (Asset.Save())
|
|
{
|
|
Editor.LogError("Cannot save asset.");
|
|
return;
|
|
}
|
|
|
|
ClearEditedFlag();
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void Update(float deltaTime)
|
|
{
|
|
base.Update(deltaTime);
|
|
|
|
// Check if need to load
|
|
if (_isWaitingForLoad && _asset.IsLoaded)
|
|
{
|
|
// Clear flag
|
|
_isWaitingForLoad = false;
|
|
|
|
// Init properties and parameters proxy
|
|
_properties.OnLoad(this);
|
|
_propertiesEditor.BuildLayout();
|
|
|
|
// Setup
|
|
ClearEditedFlag();
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override bool UseLayoutData => true;
|
|
|
|
/// <inheritdoc />
|
|
public override void OnLayoutSerialize(XmlWriter writer)
|
|
{
|
|
LayoutSerializeSplitter(writer, "Split", _split);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void OnLayoutDeserialize(XmlElement node)
|
|
{
|
|
LayoutDeserializeSplitter(node, "Split", _split);
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public override void OnLayoutDeserialize()
|
|
{
|
|
_split.SplitterValue = 0.7f;
|
|
}
|
|
}
|
|
}
|