Properties window

This commit is contained in:
Simon Lübeß
2024-06-09 01:44:58 +02:00
parent f61d1bc644
commit 2d5e6a9278
6 changed files with 113 additions and 90 deletions
@@ -84,8 +84,9 @@ namespace GlitchyEditor.EditWindows
public Event<EventHandler<StringView>> OnFileSelected ~ _.Dispose();
public this(EditorContentManager contentManager, AssetThumbnailManager thumbnailManager)
public this(Editor editor, EditorContentManager contentManager, AssetThumbnailManager thumbnailManager)
{
_editor = editor;
_manager = contentManager;
_thumbnailManager = thumbnailManager;
}
@@ -864,6 +865,18 @@ namespace GlitchyEditor.EditWindows
{
wantsDelete = true;
}
ImGui.Separator();
if (ImGui.MenuItem("Properties..."))
{
AssetHandle? assetHandle = fileOrFolder->AssetFile?.AssetConfig?.AssetHandle;
if (assetHandle != null)
{
new PropertiesWindow(_editor, .Asset(assetHandle.Value));
}
}
}
private void OpenEntry(TreeNode<AssetNode> entry)
@@ -1,4 +1,5 @@
using System;
using ImGui;
namespace GlitchyEditor.EditWindows
{
abstract class EditorWindow
@@ -29,4 +30,54 @@ namespace GlitchyEditor.EditWindows
protected abstract void InternalShow();
}
abstract class ClosableWindow
{
private static int32 _nextWindowId = 9000;
private String _windowTitle ~ delete _;
private String _windowTitleId ~ delete _;
private int32 _windowId;
protected Editor _editor;
public StringView WindowTitle
{
get => _windowTitle;
set
{
String.NewOrSet!(_windowTitle, value);
String.NewOrSet!(_windowTitleId, value);
_windowTitleId.AppendF($"##{_windowId}");
}
}
public this(Editor editor, StringView windowTitle = "Window")
{
_windowId = ++_nextWindowId;
_editor = editor;
WindowTitle = windowTitle;
_editor.AddWindow(this);
}
public void Show()
{
bool open = true;
if(ImGui.Begin(_windowTitleId, &open, .None))
{
InternalShow();
}
ImGui.End();
if (!open)
{
_editor.RemoveWindow(this);
}
}
protected abstract void InternalShow();
}
}
@@ -150,7 +150,21 @@ namespace GlitchyEditor.EditWindows
Show_ContextMenu_Create(true, SelectedEntityIds.Count == 1, isAnyEntitySelected);
if (isAnyEntitySelected)
{
deletedEntity = Show_ContextMenu_Delete();
ImGui.Separator();
if (ImGui.MenuItem("Properties..."))
{
Result<Entity> entityResult = GetSelectedEntity(0);
if (entityResult case .Ok(let entity))
{
new PropertiesWindow(_editor, .Entity(entity));
}
}
}
}
protected override void InternalShow()
@@ -24,8 +24,6 @@ class InspectorWindow : EditorWindow
private bool _lockCurrentSelection;
private append String _selectedFileName = .();
private SelectedObject _selectedObject = .None;
public this(Editor editor)
@@ -93,19 +91,24 @@ class InspectorWindow : EditorWindow
ImGui.Checkbox("Lock", &_lockCurrentSelection);
ImGui.Separator();
if (_selectedObject case .Asset(let assetHandle))
{
ShowAssetProperties(assetHandle);
ShowSelectedObject(_selectedObject, _editor);
}
else if (_selectedObject case .Entity(let entity))
public static void ShowSelectedObject(SelectedObject object, Editor editor)
{
if (object case .Asset(let assetHandle))
{
ShowAssetProperties(assetHandle, editor);
}
else if (object case .Entity(let entity))
{
ShowEntityProperties(entity);
}
}
private void ShowAssetProperties(AssetHandle assetHandle)
private static void ShowAssetProperties(AssetHandle assetHandle, Editor editor)
{
TreeNode<AssetNode> assetNode = TrySilent!(_editor.ContentManager.AssetHierarchy.GetNodeFromAssetHandle(assetHandle));
TreeNode<AssetNode> assetNode = TrySilent!(editor.ContentManager.AssetHierarchy.GetNodeFromAssetHandle(assetHandle));
AssetFile assetFile = assetNode->AssetFile;
@@ -134,7 +137,7 @@ class InspectorWindow : EditorWindow
ImGui.EndDisabled();
}
private void ShowEntityProperties(Entity entity)
private static void ShowEntityProperties(Entity entity)
{
ComponentEditWindow.ShowComponents(entity);
}
@@ -6,95 +6,21 @@ using System.Reflection;
using GlitchyEngine;
using GlitchyEditor.Assets;
using GlitchyEngine.Core;
using GlitchyEngine.World;
namespace GlitchyEditor.EditWindows;
class PropertiesWindow : EditorWindow
class PropertiesWindow : ClosableWindow
{
public const String s_WindowTitle = "Properties";
private SelectedObject _selectedObject = .None;
private AssetPropertiesEditor _currentPropertiesEditor ~ delete _;
private bool _lockCurrentAsset;
private bool _selectedNewAsset;
private append String _selectedFileName = .();
private AssetHandle _currentAssetHandle;
private SelectedObject _selectedObject;
public this(Editor editor)
public this(Editor editor, SelectedObject selectedObject) : base(editor, "Properties")
{
_editor = editor;
_selectedObject = selectedObject;
}
protected override void InternalShow()
{
defer { ImGui.End(); }
if(!ImGui.Begin(s_WindowTitle, &_open, .None))
return;
// TODO: make a little button in title bar?
ImGui.Checkbox("Lock", &_lockCurrentAsset);
ImGui.Separator();
ShowAssetProperties();
}
/// Gets the AssetFile for the asset currently selected in the ContentBrowserWindow
/// @returns the AssetFile for the currently selected asset of null, if no file is selected.
private AssetFile GetCurrentAssetFile()
{
// Only grab the currently selected file if we aren't locked
if (!_lockCurrentAsset)
{
StringView selectedInFileBrowser = _editor.ContentBrowserWindow.SelectedFile;
if (_selectedFileName != selectedInFileBrowser)
{
_selectedFileName.Set(_editor.ContentBrowserWindow.SelectedFile);
}
}
Result<TreeNode<AssetNode>> treeNode = _editor.ContentManager.AssetHierarchy.GetNodeFromPath(_selectedFileName);
if (treeNode case .Ok(let assetNode))
return assetNode->AssetFile;
return null;
}
private void ShowAssetProperties()
{
AssetFile assetFile = GetCurrentAssetFile();
if (assetFile == null)
return;
if (ImGui.BeginPropertyTable("asset_properties", ImGui.GetID("asset_properties")))
{
assetFile.AssetConfig?.ImporterConfig?.ShowEditor();
assetFile.AssetConfig?.ProcessorConfig?.ShowEditor();
assetFile.AssetConfig?.ExporterConfig?.ShowEditor();
ImGui.EndTable();
ImGui.Separator();
}
bool hasChanges = (assetFile.AssetConfig?.ImporterConfig?.Changed ?? false) || (assetFile.AssetConfig?.ProcessorConfig?.Changed ?? false) || (assetFile.AssetConfig?.ExporterConfig?.Changed ?? false);
if (!hasChanges)
ImGui.BeginDisabled();
if (ImGui.Button("Apply"))
{
assetFile.SaveAssetConfig();
}
if (!hasChanges)
ImGui.EndDisabled();
InspectorWindow.ShowSelectedObject(_selectedObject, _editor);
}
}
+17 -1
View File
@@ -27,6 +27,8 @@ namespace GlitchyEditor
private AssetViewer _assetViewer ~ delete _;
private LogWindow _logWindow ~ delete _;
private List<ClosableWindow> _windows = new .() ~ DeleteContainerAndItems!(_);
public Scene CurrentScene
{
get => _scene;
@@ -94,7 +96,7 @@ namespace GlitchyEditor
_gameViewportWindow = new GameViewportWindow(this);
_entityHierarchyWindow = new EntityHierarchyWindow(this, _scene);
_componentEditWindow = new ComponentEditWindow();
_contentBrowserWindow = new ContentBrowserWindow((.)Application.Get().ContentManager, _thumbnailManager);
_contentBrowserWindow = new ContentBrowserWindow(this, (.)Application.Instance.ContentManager, _thumbnailManager);
_inspectorWindow = new InspectorWindow(this);
_assetViewer = new AssetViewer((.)Application.Get().ContentManager);
_logWindow = new LogWindow();
@@ -110,6 +112,20 @@ namespace GlitchyEditor
_inspectorWindow.Show();
_assetViewer.Show();
_logWindow.Show();
for (ClosableWindow window in _windows)
window.Show();
}
public void AddWindow(ClosableWindow ownClosableWindow)
{
_windows.Add(ownClosableWindow);
}
public void RemoveWindow(ClosableWindow closableWindow)
{
_windows.Remove(closableWindow);
delete closableWindow;
}
}
}