Show error in Properties window, deselect invalid objects in Inspector window

This commit is contained in:
Simon Lübeß
2024-06-09 17:12:42 +02:00
parent 2d5e6a9278
commit c8be6eca5c
3 changed files with 53 additions and 9 deletions
@@ -161,7 +161,7 @@ namespace GlitchyEditor.EditWindows
if (entityResult case .Ok(let entity))
{
new PropertiesWindow(_editor, .Entity(entity));
new PropertiesWindow(_editor, .Entity(entity.UUID));
}
}
}
@@ -15,7 +15,7 @@ enum SelectedObject
{
case None;
case Asset(AssetHandle AssetHandle);
case Entity(Entity entity);
case Entity(UUID entityId);
}
class InspectorWindow : EditorWindow
@@ -66,7 +66,7 @@ class InspectorWindow : EditorWindow
if (entityResult case .Ok(let selectedEntity))
{
_selectedObject = .Entity(selectedEntity);
_selectedObject = .Entity(selectedEntity.UUID);
return;
}
}
@@ -91,26 +91,49 @@ class InspectorWindow : EditorWindow
ImGui.Checkbox("Lock", &_lockCurrentSelection);
ImGui.Separator();
DeselectIfInvalid();
ShowSelectedObject(_selectedObject, _editor);
}
private void DeselectIfInvalid()
{
if (_selectedObject case .Entity(let entityId) &&
_editor.CurrentScene.GetEntityByID(entityId) case .Err)
{
_selectedObject = .None;
}
else if (_selectedObject case .Asset(let assetHandle) &&
_editor.ContentManager.AssetHierarchy.GetNodeFromAssetHandle(assetHandle) case .Err)
{
_selectedObject = .None;
}
}
public static void ShowSelectedObject(SelectedObject object, Editor editor)
{
if (object case .Asset(let assetHandle))
{
ShowAssetProperties(assetHandle, editor);
}
else if (object case .Entity(let entity))
else if (object case .Entity(let entityId))
{
ShowEntityProperties(entity);
ShowEntityProperties(entityId, editor);
}
}
private static void ShowAssetProperties(AssetHandle assetHandle, Editor editor)
{
TreeNode<AssetNode> assetNode = TrySilent!(editor.ContentManager.AssetHierarchy.GetNodeFromAssetHandle(assetHandle));
Result<TreeNode<AssetNode>> assetNode = editor.ContentManager.AssetHierarchy.GetNodeFromAssetHandle(assetHandle);
AssetFile assetFile = assetNode->AssetFile;
if (assetNode case .Err)
{
ImGui.TextWrapped($"ERROR!\n\nAsset {assetHandle} doesn't exist.");
return;
}
AssetFile assetFile = assetNode->Value.AssetFile;
if (ImGui.BeginPropertyTable("asset_properties", ImGui.GetID("asset_properties")))
{
@@ -137,8 +160,17 @@ class InspectorWindow : EditorWindow
ImGui.EndDisabled();
}
private static void ShowEntityProperties(Entity entity)
private static void ShowEntityProperties(UUID entityId, Editor editor)
{
Result<Entity> entityResult = editor.CurrentScene.GetEntityByID(entityId);
if (entityResult case .Ok(let entity))
{
ComponentEditWindow.ShowComponents(entity);
}
else
{
ImGui.TextWrapped($"ERROR!\n\nEntity {entityId} doesn't exist.");
}
}
}
+12
View File
@@ -116,6 +116,8 @@ namespace GlitchyEngine.World
*/
public void RemoveEntity(EcsEntity entity)
{
Log.EngineLogger.AssertDebug(IsValid(entity));
var listEntity = ref _entities[entity.Index];
if(entity != listEntity.ID)
return;
@@ -176,6 +178,8 @@ namespace GlitchyEngine.World
*/
public T* AssignComponent<T>(EcsEntity entity, T value = T()) where T : struct, new
{
Log.EngineLogger.AssertDebug(IsValid(entity));
if(entity.Index > _entities.Count)
return null;
@@ -213,6 +217,8 @@ namespace GlitchyEngine.World
*/
public void RemoveComponent<T>(EcsEntity entity) where T : struct, new
{
Log.EngineLogger.AssertDebug(IsValid(entity));
if(entity.Index > _entities.Count)
return;
@@ -233,6 +239,8 @@ namespace GlitchyEngine.World
public void RemoveComponent<T>(EcsEntity entity) where T : struct, new, IDisposableComponent
{
Log.EngineLogger.AssertDebug(IsValid(entity));
if(entity.Index > _entities.Count)
return;
@@ -257,6 +265,8 @@ namespace GlitchyEngine.World
/// Returns whether or not the given entity has the specified component.
public bool HasComponent<T>(EcsEntity entity) where T : struct, new
{
Log.EngineLogger.AssertDebug(IsValid(entity));
var listEntity = ref _entities[entity.Index];
if(entity != listEntity.ID)
return false;
@@ -270,6 +280,8 @@ namespace GlitchyEngine.World
public T* GetComponent<T>(EcsEntity entity) where T : struct, new
{
Log.EngineLogger.AssertDebug(IsValid(entity));
var listEntity = ref _entities[entity.Index];
if(entity != listEntity.ID)
return null;