mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Inspector window to combine asset properties and components editor
This commit is contained in:
@@ -6,7 +6,6 @@ using GlitchyEngine.Content;
|
||||
using GlitchyEngine;
|
||||
using GlitchyEngine.Renderer;
|
||||
using GlitchyEngine.Math;
|
||||
using System.Threading;
|
||||
using GlitchyEditor.Assets.Processors;
|
||||
using ImGui;
|
||||
|
||||
@@ -68,7 +67,6 @@ class TextureImporter : IAssetImporter
|
||||
|
||||
public Result<ImportedResource> Import(StringView fullFileName, AssetIdentifier assetIdentifier, AssetImporterConfig config)
|
||||
{
|
||||
Thread.Sleep(1000);
|
||||
|
||||
Log.EngineLogger.AssertDebug(config is TextureImporterConfig);
|
||||
|
||||
|
||||
@@ -15,56 +15,11 @@ namespace GlitchyEditor.EditWindows
|
||||
{
|
||||
using internal GlitchyEngine.World.TransformComponent;
|
||||
|
||||
class ComponentEditWindow : EditorWindow
|
||||
class ComponentEditWindow
|
||||
{
|
||||
public const String s_WindowTitle = "Components";
|
||||
|
||||
private EntityHierarchyWindow _entityHierarchyWindow;
|
||||
|
||||
private List<(Type, ComponentAttribute attribute)> _componentTypes = new .() ~ delete _;
|
||||
|
||||
public this(EntityHierarchyWindow entityHierarchyWindow)
|
||||
{
|
||||
_entityHierarchyWindow = entityHierarchyWindow;
|
||||
|
||||
for (let type in Type.Types)
|
||||
{
|
||||
if (let componentAttribute = type.GetCustomAttribute<ComponentAttribute>())
|
||||
{
|
||||
_componentTypes.Add((type, componentAttribute));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void InternalShow()
|
||||
{
|
||||
ImGui.SetNextWindowSizeConstraints(.(200, 200), .(-1, -1));
|
||||
|
||||
if(!ImGui.Begin(s_WindowTitle, &_open, .None))
|
||||
{
|
||||
ImGui.PopStyleVar();
|
||||
ImGui.End();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_entityHierarchyWindow.SelectionSize == 1)
|
||||
{
|
||||
Result<Entity> entityResult = _entityHierarchyWindow.GetSelectedEntity(0);
|
||||
|
||||
if (entityResult case .Ok(let selectedEntity))
|
||||
ShowComponents(selectedEntity);
|
||||
}
|
||||
else
|
||||
{
|
||||
_editVerticesPolygonCollider2D = false;
|
||||
}
|
||||
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
private static uint32 TableId;
|
||||
|
||||
private void ShowComponents(Entity entity)
|
||||
public static void ShowComponents(Entity entity)
|
||||
{
|
||||
float cellPaddingY = ImGui.GetTextLineHeight() / 3.0f;
|
||||
|
||||
@@ -112,7 +67,7 @@ namespace GlitchyEditor.EditWindows
|
||||
ShowAddComponentButton(entity);
|
||||
}
|
||||
|
||||
public void DrawSceneGUI(Entity entity)
|
||||
public static void DrawSceneGUI(Entity entity)
|
||||
{
|
||||
DrawComponenSceneGUI<PolygonCollider2DComponent>(entity, => ShowPolygonColliderSceneGUI);
|
||||
}
|
||||
|
||||
@@ -79,6 +79,11 @@ namespace GlitchyEditor.EditWindows
|
||||
bool _showNewFile = false;
|
||||
AssetCreator _newFileCreator = null;
|
||||
|
||||
char8[256] _filesFilter = .();
|
||||
bool _searchEverywhere;
|
||||
|
||||
public Event<EventHandler<StringView>> OnFileSelected ~ _.Dispose();
|
||||
|
||||
public this(EditorContentManager contentManager, AssetThumbnailManager thumbnailManager)
|
||||
{
|
||||
_manager = contentManager;
|
||||
@@ -188,8 +193,15 @@ namespace GlitchyEditor.EditWindows
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
char8[256] _filesFilter = .();
|
||||
bool _searchEverywhere;
|
||||
private void SelectFile(StringView fullFileName)
|
||||
{
|
||||
if (_selectedFile == fullFileName)
|
||||
return;
|
||||
|
||||
_selectedFile.Set(fullFileName);
|
||||
|
||||
OnFileSelected(this, _selectedFile);
|
||||
}
|
||||
|
||||
private void DrawSearchBar()
|
||||
{
|
||||
@@ -517,7 +529,7 @@ namespace GlitchyEditor.EditWindows
|
||||
{
|
||||
if (_selectedFile != entry->Path)
|
||||
{
|
||||
_selectedFile.Set(entry->Path);
|
||||
SelectFile(entry->Path);
|
||||
_assetToRename.Clear();
|
||||
}
|
||||
}
|
||||
@@ -617,7 +629,7 @@ namespace GlitchyEditor.EditWindows
|
||||
{
|
||||
if (_selectedFile != entry->Path)
|
||||
{
|
||||
_selectedFile.Set(entry->Path);
|
||||
SelectFile(entry->Path);
|
||||
_assetToRename.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ namespace GlitchyEditor.EditWindows
|
||||
parentView = parentTransformCmp.WorldTransform.Invert();
|
||||
}
|
||||
|
||||
_editor.ComponentEditWindow.DrawSceneGUI(entity);
|
||||
ComponentEditWindow.DrawSceneGUI(entity);
|
||||
|
||||
float3 snap = (float3)_snap;
|
||||
if (_gizmoType.HasFlag(.ROTATE))
|
||||
|
||||
@@ -35,6 +35,8 @@ namespace GlitchyEditor.EditWindows
|
||||
|
||||
/// Gets the number of entities that are currently selected.
|
||||
public int SelectionSize => _selectedEntityIds.Count;
|
||||
|
||||
public Event<EventHandler<List<UUID>>> SelectionChanged ~ _.Dispose();
|
||||
|
||||
/// Returns the Entity at the given index or null if it doesn't exist.
|
||||
public Result<Entity> GetSelectedEntity(int index)
|
||||
@@ -102,6 +104,8 @@ namespace GlitchyEditor.EditWindows
|
||||
public void ClearEntitySelection()
|
||||
{
|
||||
_selectedEntityIds.Clear();
|
||||
|
||||
SelectionChanged(this, _selectedEntityIds);
|
||||
}
|
||||
|
||||
/// Selects the given entity.
|
||||
@@ -113,13 +117,20 @@ namespace GlitchyEditor.EditWindows
|
||||
ClearEntitySelection();
|
||||
|
||||
_selectedEntityIds.Add(entity.UUID);
|
||||
|
||||
SelectionChanged(this, _selectedEntityIds);
|
||||
}
|
||||
|
||||
/// Deselects the given entity.
|
||||
/// @param entity The entity to deselect.
|
||||
public bool DeselectEntity(Entity entity)
|
||||
{
|
||||
return _selectedEntityIds.Remove(entity.UUID);
|
||||
bool removed = _selectedEntityIds.Remove(entity.UUID);
|
||||
|
||||
if (removed)
|
||||
SelectionChanged(this, _selectedEntityIds);
|
||||
|
||||
return removed;
|
||||
}
|
||||
|
||||
/// Returns whether or not the given entity is currently selected.
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
using ImGui;
|
||||
using System;
|
||||
using GlitchyEngine.Collections;
|
||||
using GlitchyEngine.Content;
|
||||
using System.Reflection;
|
||||
using GlitchyEngine;
|
||||
using GlitchyEditor.Assets;
|
||||
using GlitchyEngine.Core;
|
||||
using System.Collections;
|
||||
using GlitchyEngine.World;
|
||||
|
||||
namespace GlitchyEditor.EditWindows;
|
||||
|
||||
enum SelectedObject
|
||||
{
|
||||
case None;
|
||||
case Asset(AssetHandle AssetHandle);
|
||||
case Entity(Entity entity);
|
||||
}
|
||||
|
||||
class InspectorWindow : EditorWindow
|
||||
{
|
||||
public const String s_WindowTitle = "Inspector";
|
||||
|
||||
private bool _lockCurrentSelection;
|
||||
|
||||
private append String _selectedFileName = .();
|
||||
|
||||
private SelectedObject _selectedObject = .None;
|
||||
|
||||
public this(Editor editor)
|
||||
{
|
||||
_editor = editor;
|
||||
|
||||
_editor.ContentBrowserWindow.OnFileSelected.Add(new => SetSelectedAsset);
|
||||
_editor.EntityHierarchyWindow.SelectionChanged.Add(new => SetSelectedEntities);
|
||||
}
|
||||
|
||||
private void SetSelectedAsset(Object sender, StringView fullFileName)
|
||||
{
|
||||
if (_lockCurrentSelection)
|
||||
return;
|
||||
|
||||
Result<TreeNode<AssetNode>> treeNode = _editor.ContentManager.AssetHierarchy.GetNodeFromPath(fullFileName);
|
||||
|
||||
if (treeNode case .Ok(let assetNode))
|
||||
{
|
||||
AssetHandle? assetHandle = assetNode->AssetFile?.AssetConfig?.AssetHandle;
|
||||
|
||||
if (assetHandle != null)
|
||||
{
|
||||
_selectedObject = .Asset(assetHandle.Value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_selectedObject = .None;
|
||||
}
|
||||
|
||||
private void SetSelectedEntities(Object sender, List<UUID> selectedEntities)
|
||||
{
|
||||
if (_lockCurrentSelection)
|
||||
return;
|
||||
|
||||
if (selectedEntities.Count > 0)
|
||||
{
|
||||
Result<Entity> entityResult = _editor.EntityHierarchyWindow.GetSelectedEntity(0);
|
||||
|
||||
if (entityResult case .Ok(let selectedEntity))
|
||||
{
|
||||
_selectedObject = .Entity(selectedEntity);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
_selectedObject = .None;
|
||||
}
|
||||
|
||||
protected override void InternalShow()
|
||||
{
|
||||
//ImGui.SetNextWindowSizeConstraints(.(200, 200), .(-1, -1));
|
||||
|
||||
defer
|
||||
{
|
||||
//ImGui.PopStyleVar();
|
||||
ImGui.End();
|
||||
}
|
||||
|
||||
if(!ImGui.Begin(s_WindowTitle, &_open, .None))
|
||||
return;
|
||||
|
||||
// TODO: make a little button in title bar?
|
||||
ImGui.Checkbox("Lock", &_lockCurrentSelection);
|
||||
ImGui.Separator();
|
||||
|
||||
if (_selectedObject case .Asset(let assetHandle))
|
||||
{
|
||||
ShowAssetProperties(assetHandle);
|
||||
}
|
||||
else if (_selectedObject case .Entity(let entity))
|
||||
{
|
||||
ShowEntityProperties(entity);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowAssetProperties(AssetHandle assetHandle)
|
||||
{
|
||||
TreeNode<AssetNode> assetNode = TrySilent!(_editor.ContentManager.AssetHierarchy.GetNodeFromAssetHandle(assetHandle));
|
||||
|
||||
AssetFile assetFile = assetNode->AssetFile;
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
private void ShowEntityProperties(Entity entity)
|
||||
{
|
||||
ComponentEditWindow.ShowComponents(entity);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using GlitchyEngine.Content;
|
||||
using System.Reflection;
|
||||
using GlitchyEngine;
|
||||
using GlitchyEditor.Assets;
|
||||
using GlitchyEngine.Core;
|
||||
|
||||
namespace GlitchyEditor.EditWindows;
|
||||
|
||||
@@ -22,6 +23,8 @@ class PropertiesWindow : EditorWindow
|
||||
|
||||
private AssetHandle _currentAssetHandle;
|
||||
|
||||
private SelectedObject _selectedObject;
|
||||
|
||||
public this(Editor editor)
|
||||
{
|
||||
_editor = editor;
|
||||
@@ -93,74 +96,5 @@ class PropertiesWindow : EditorWindow
|
||||
|
||||
if (!hasChanges)
|
||||
ImGui.EndDisabled();
|
||||
|
||||
/*if (_currentPropertiesEditor?.Asset != assetFile)
|
||||
{
|
||||
delete _currentPropertiesEditor;
|
||||
_currentPropertiesEditor = _editor.ContentManager.GetNewPropertiesEditor(assetFile);
|
||||
}
|
||||
|
||||
if (assetFile == null)
|
||||
return;
|
||||
|
||||
Asset asset = _editor.ContentManager.GetAsset(null, _currentAssetHandle);
|
||||
|
||||
// We need the actual asset for preview and sometimes for editing
|
||||
if (asset?.Identifier != assetFile.AssetFile.Identifier)
|
||||
{
|
||||
//_currentAssetHandle = _editor.ContentManager.LoadAsset(assetFile.AssetFile.Identifier);
|
||||
}
|
||||
|
||||
// TODO: allow changing AssetLoader
|
||||
// assetFile.AssetConfig.AssetLoade
|
||||
|
||||
// TODO: ignore file
|
||||
/*ImGui.Checkbox("Ignore", &assetFile.AssetConfig.IgnoreFile);
|
||||
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip("If checked this file will be ignored and not treated as an asset.");*/
|
||||
|
||||
ShowPropertiesEditor(assetFile);
|
||||
|
||||
ImGui.Separator();
|
||||
*/
|
||||
// TODO: preview asset
|
||||
}
|
||||
|
||||
private void ShowPropertiesEditor(AssetFile assetFile)
|
||||
{
|
||||
return;
|
||||
|
||||
if (_currentPropertiesEditor == null)
|
||||
return;
|
||||
|
||||
_currentPropertiesEditor.ShowEditor();
|
||||
|
||||
bool assetConfigChanged = assetFile.AssetConfig.Config.Changed;
|
||||
bool hasAssetSaver = (_editor.ContentManager.[Friend]GetAssetLoader(assetFile) is IAssetSaver);
|
||||
|
||||
// If the asset can't be saved and it's config didn't change disable save button
|
||||
if (!hasAssetSaver && !assetConfigChanged)
|
||||
{
|
||||
ImGui.BeginDisabled();
|
||||
defer:: { ImGui.EndDisabled(); }
|
||||
}
|
||||
|
||||
if (ImGui.Button("Save"))
|
||||
{
|
||||
// Only save config if it changed
|
||||
if (assetConfigChanged)
|
||||
{
|
||||
assetFile.SaveAssetConfig();
|
||||
}
|
||||
|
||||
// If the asset type has an asset saver, also save the asset
|
||||
// TODO: Check whether or not the asset was changed?
|
||||
if (hasAssetSaver)
|
||||
{
|
||||
Asset asset = _editor.ContentManager.GetAsset(null, _currentAssetHandle);
|
||||
_editor.ContentManager.SaveAsset(asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace GlitchyEditor
|
||||
private EditorViewportWindow _sceneViewportWindow ~ delete _;
|
||||
private GameViewportWindow _gameViewportWindow ~ delete _;
|
||||
private ContentBrowserWindow _contentBrowserWindow ~ delete _;
|
||||
private PropertiesWindow _propertiesWindow ~ delete _;
|
||||
private InspectorWindow _inspectorWindow ~ delete _;
|
||||
private AssetViewer _assetViewer ~ delete _;
|
||||
private LogWindow _logWindow ~ delete _;
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace GlitchyEditor
|
||||
public EditorViewportWindow SceneViewportWindow => _sceneViewportWindow;
|
||||
public GameViewportWindow GameViewportWindow => _gameViewportWindow;
|
||||
public ContentBrowserWindow ContentBrowserWindow => _contentBrowserWindow;
|
||||
public PropertiesWindow PropertiesWindow => _propertiesWindow;
|
||||
public InspectorWindow InspectorWindow => _inspectorWindow;
|
||||
public AssetViewer AssetViewer => _assetViewer;
|
||||
public LogWindow LogWindow => _logWindow;
|
||||
|
||||
@@ -93,9 +93,9 @@ namespace GlitchyEditor
|
||||
_sceneViewportWindow = new EditorViewportWindow(this);
|
||||
_gameViewportWindow = new GameViewportWindow(this);
|
||||
_entityHierarchyWindow = new EntityHierarchyWindow(this, _scene);
|
||||
_componentEditWindow = new ComponentEditWindow(_entityHierarchyWindow);
|
||||
_componentEditWindow = new ComponentEditWindow();
|
||||
_contentBrowserWindow = new ContentBrowserWindow((.)Application.Get().ContentManager, _thumbnailManager);
|
||||
_propertiesWindow = new PropertiesWindow(this);
|
||||
_inspectorWindow = new InspectorWindow(this);
|
||||
_assetViewer = new AssetViewer((.)Application.Get().ContentManager);
|
||||
_logWindow = new LogWindow();
|
||||
}
|
||||
@@ -105,9 +105,9 @@ namespace GlitchyEditor
|
||||
_sceneViewportWindow.Show();
|
||||
_gameViewportWindow.Show();
|
||||
_entityHierarchyWindow.Show();
|
||||
_componentEditWindow.Show();
|
||||
//_componentEditWindow.Show();
|
||||
_contentBrowserWindow.Show();
|
||||
_propertiesWindow.Show();
|
||||
_inspectorWindow.Show();
|
||||
_assetViewer.Show();
|
||||
_logWindow.Show();
|
||||
}
|
||||
|
||||
@@ -1444,11 +1444,8 @@ namespace GlitchyEditor
|
||||
|
||||
if(ImGui.BeginMenu("View", true))
|
||||
{
|
||||
if(ImGui.MenuItem(ComponentEditWindow.s_WindowTitle))
|
||||
_editor.ComponentEditWindow.Open = true;
|
||||
|
||||
if(ImGui.MenuItem(ContentBrowserWindow.s_WindowTitle))
|
||||
_editor.ComponentEditWindow.Open = true;
|
||||
_editor.ContentBrowserWindow.Open = true;
|
||||
|
||||
if(ImGui.MenuItem(EditorViewportWindow.s_WindowTitle))
|
||||
_editor.SceneViewportWindow.Open = true;
|
||||
@@ -1459,8 +1456,8 @@ namespace GlitchyEditor
|
||||
if(ImGui.MenuItem(GameViewportWindow.s_WindowTitle))
|
||||
_editor.GameViewportWindow.Open = true;
|
||||
|
||||
if(ImGui.MenuItem(PropertiesWindow.s_WindowTitle))
|
||||
_editor.PropertiesWindow.Open = true;
|
||||
if(ImGui.MenuItem(InspectorWindow.s_WindowTitle))
|
||||
_editor.InspectorWindow.Open = true;
|
||||
|
||||
if(ImGui.MenuItem(AssetViewer.s_WindowTitle))
|
||||
_editor.AssetViewer.Open = true;
|
||||
|
||||
Reference in New Issue
Block a user