mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Show error in Properties window, deselect invalid objects in Inspector window
This commit is contained in:
@@ -161,7 +161,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
if (entityResult case .Ok(let entity))
|
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 None;
|
||||||
case Asset(AssetHandle AssetHandle);
|
case Asset(AssetHandle AssetHandle);
|
||||||
case Entity(Entity entity);
|
case Entity(UUID entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
class InspectorWindow : EditorWindow
|
class InspectorWindow : EditorWindow
|
||||||
@@ -66,7 +66,7 @@ class InspectorWindow : EditorWindow
|
|||||||
|
|
||||||
if (entityResult case .Ok(let selectedEntity))
|
if (entityResult case .Ok(let selectedEntity))
|
||||||
{
|
{
|
||||||
_selectedObject = .Entity(selectedEntity);
|
_selectedObject = .Entity(selectedEntity.UUID);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,26 +91,49 @@ class InspectorWindow : EditorWindow
|
|||||||
ImGui.Checkbox("Lock", &_lockCurrentSelection);
|
ImGui.Checkbox("Lock", &_lockCurrentSelection);
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
||||||
|
DeselectIfInvalid();
|
||||||
|
|
||||||
ShowSelectedObject(_selectedObject, _editor);
|
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)
|
public static void ShowSelectedObject(SelectedObject object, Editor editor)
|
||||||
{
|
{
|
||||||
if (object case .Asset(let assetHandle))
|
if (object case .Asset(let assetHandle))
|
||||||
{
|
{
|
||||||
ShowAssetProperties(assetHandle, editor);
|
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)
|
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")))
|
if (ImGui.BeginPropertyTable("asset_properties", ImGui.GetID("asset_properties")))
|
||||||
{
|
{
|
||||||
@@ -137,8 +160,17 @@ class InspectorWindow : EditorWindow
|
|||||||
ImGui.EndDisabled();
|
ImGui.EndDisabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ShowEntityProperties(Entity entity)
|
private static void ShowEntityProperties(UUID entityId, Editor editor)
|
||||||
{
|
{
|
||||||
ComponentEditWindow.ShowComponents(entity);
|
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.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ namespace GlitchyEngine.World
|
|||||||
*/
|
*/
|
||||||
public void RemoveEntity(EcsEntity entity)
|
public void RemoveEntity(EcsEntity entity)
|
||||||
{
|
{
|
||||||
|
Log.EngineLogger.AssertDebug(IsValid(entity));
|
||||||
|
|
||||||
var listEntity = ref _entities[entity.Index];
|
var listEntity = ref _entities[entity.Index];
|
||||||
if(entity != listEntity.ID)
|
if(entity != listEntity.ID)
|
||||||
return;
|
return;
|
||||||
@@ -176,6 +178,8 @@ namespace GlitchyEngine.World
|
|||||||
*/
|
*/
|
||||||
public T* AssignComponent<T>(EcsEntity entity, T value = T()) where T : struct, new
|
public T* AssignComponent<T>(EcsEntity entity, T value = T()) where T : struct, new
|
||||||
{
|
{
|
||||||
|
Log.EngineLogger.AssertDebug(IsValid(entity));
|
||||||
|
|
||||||
if(entity.Index > _entities.Count)
|
if(entity.Index > _entities.Count)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
@@ -213,6 +217,8 @@ namespace GlitchyEngine.World
|
|||||||
*/
|
*/
|
||||||
public void RemoveComponent<T>(EcsEntity entity) where T : struct, new
|
public void RemoveComponent<T>(EcsEntity entity) where T : struct, new
|
||||||
{
|
{
|
||||||
|
Log.EngineLogger.AssertDebug(IsValid(entity));
|
||||||
|
|
||||||
if(entity.Index > _entities.Count)
|
if(entity.Index > _entities.Count)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -233,6 +239,8 @@ namespace GlitchyEngine.World
|
|||||||
|
|
||||||
public void RemoveComponent<T>(EcsEntity entity) where T : struct, new, IDisposableComponent
|
public void RemoveComponent<T>(EcsEntity entity) where T : struct, new, IDisposableComponent
|
||||||
{
|
{
|
||||||
|
Log.EngineLogger.AssertDebug(IsValid(entity));
|
||||||
|
|
||||||
if(entity.Index > _entities.Count)
|
if(entity.Index > _entities.Count)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -257,6 +265,8 @@ namespace GlitchyEngine.World
|
|||||||
/// Returns whether or not the given entity has the specified component.
|
/// Returns whether or not the given entity has the specified component.
|
||||||
public bool HasComponent<T>(EcsEntity entity) where T : struct, new
|
public bool HasComponent<T>(EcsEntity entity) where T : struct, new
|
||||||
{
|
{
|
||||||
|
Log.EngineLogger.AssertDebug(IsValid(entity));
|
||||||
|
|
||||||
var listEntity = ref _entities[entity.Index];
|
var listEntity = ref _entities[entity.Index];
|
||||||
if(entity != listEntity.ID)
|
if(entity != listEntity.ID)
|
||||||
return false;
|
return false;
|
||||||
@@ -270,6 +280,8 @@ namespace GlitchyEngine.World
|
|||||||
|
|
||||||
public T* GetComponent<T>(EcsEntity entity) where T : struct, new
|
public T* GetComponent<T>(EcsEntity entity) where T : struct, new
|
||||||
{
|
{
|
||||||
|
Log.EngineLogger.AssertDebug(IsValid(entity));
|
||||||
|
|
||||||
var listEntity = ref _entities[entity.Index];
|
var listEntity = ref _entities[entity.Index];
|
||||||
if(entity != listEntity.ID)
|
if(entity != listEntity.ID)
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user