diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf index e14a321..83be384 100644 --- a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -84,8 +84,9 @@ namespace GlitchyEditor.EditWindows public Event> 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 entry) diff --git a/GlitchyEditor/src/EditWindows/EditorWindow.bf b/GlitchyEditor/src/EditWindows/EditorWindow.bf index b79ca1c..c1437c0 100644 --- a/GlitchyEditor/src/EditWindows/EditorWindow.bf +++ b/GlitchyEditor/src/EditWindows/EditorWindow.bf @@ -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(); + } } \ No newline at end of file diff --git a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf index ffafd4a..b23bc5e 100644 --- a/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf +++ b/GlitchyEditor/src/EditWindows/EntityHierarchyWindow.bf @@ -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 entityResult = GetSelectedEntity(0); + + if (entityResult case .Ok(let entity)) + { + new PropertiesWindow(_editor, .Entity(entity)); + } + } + } } protected override void InternalShow() diff --git a/GlitchyEditor/src/EditWindows/InspectorWindow.bf b/GlitchyEditor/src/EditWindows/InspectorWindow.bf index 9b6a7fd..9ca3701 100644 --- a/GlitchyEditor/src/EditWindows/InspectorWindow.bf +++ b/GlitchyEditor/src/EditWindows/InspectorWindow.bf @@ -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)) + ShowSelectedObject(_selectedObject, _editor); + } + + public static void ShowSelectedObject(SelectedObject object, Editor editor) + { + if (object case .Asset(let assetHandle)) { - ShowAssetProperties(assetHandle); + ShowAssetProperties(assetHandle, editor); } - else if (_selectedObject case .Entity(let entity)) + else if (object case .Entity(let entity)) { ShowEntityProperties(entity); } } - private void ShowAssetProperties(AssetHandle assetHandle) + private static void ShowAssetProperties(AssetHandle assetHandle, Editor editor) { - TreeNode assetNode = TrySilent!(_editor.ContentManager.AssetHierarchy.GetNodeFromAssetHandle(assetHandle)); + TreeNode 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); } diff --git a/GlitchyEditor/src/EditWindows/PropertiesWindow.bf b/GlitchyEditor/src/EditWindows/PropertiesWindow.bf index a330edc..c6bf488 100644 --- a/GlitchyEditor/src/EditWindows/PropertiesWindow.bf +++ b/GlitchyEditor/src/EditWindows/PropertiesWindow.bf @@ -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 = _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); } } diff --git a/GlitchyEditor/src/Editor.bf b/GlitchyEditor/src/Editor.bf index 5428054..8dab152 100644 --- a/GlitchyEditor/src/Editor.bf +++ b/GlitchyEditor/src/Editor.bf @@ -27,6 +27,8 @@ namespace GlitchyEditor private AssetViewer _assetViewer ~ delete _; private LogWindow _logWindow ~ delete _; + private List _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; } } }