mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 21:01:52 +00:00
Refactor
This commit is contained in:
@@ -365,9 +365,8 @@ namespace GlitchyEditor.EditWindows
|
|||||||
return deleted;
|
return deleted;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ShowVisibilityButton(Entity entity)
|
private void ShowVisibilityToggleButton(Entity entity)
|
||||||
{
|
{
|
||||||
ImGui.PushStyleVar(.WindowPadding, ImGui.Vec2(0, 2));
|
|
||||||
ImGui.PushStyleVar(.ItemInnerSpacing, ImGui.Vec2(0, 0));
|
ImGui.PushStyleVar(.ItemInnerSpacing, ImGui.Vec2(0, 0));
|
||||||
ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0));
|
ImGui.PushStyleColor(.Button, ImGui.Vec4(0, 0, 0, 0));
|
||||||
|
|
||||||
@@ -413,10 +412,11 @@ namespace GlitchyEditor.EditWindows
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImGui.PopStyleColor(3);
|
ImGui.PopStyleColor(3);
|
||||||
ImGui.PopStyleVar(2);
|
ImGui.PopStyleVar(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ImGuiPrintEntityTree(TreeNode<Entity> tree)
|
/// Shows the given entity and it's children as a tree.
|
||||||
|
private void ImGuiPrintEntityTree(TreeNode<Entity> tree, bool flat = false)
|
||||||
{
|
{
|
||||||
Entity entity = tree.Value;
|
Entity entity = tree.Value;
|
||||||
|
|
||||||
@@ -428,7 +428,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
ImGui.TableNextRow();
|
ImGui.TableNextRow();
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
|
|
||||||
ShowVisibilityButton(entity);
|
ShowVisibilityToggleButton(entity);
|
||||||
|
|
||||||
ImGui.TableNextColumn();
|
ImGui.TableNextColumn();
|
||||||
|
|
||||||
@@ -507,6 +507,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
ImGui.EndDragDropSource();
|
ImGui.EndDragDropSource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!flat)
|
||||||
EntityDropTarget(entity);
|
EntityDropTarget(entity);
|
||||||
|
|
||||||
bool clicked = ImGui.IsItemClicked() && !ImGui.IsItemToggledOpen();
|
bool clicked = ImGui.IsItemClicked() && !ImGui.IsItemToggledOpen();
|
||||||
@@ -588,20 +589,9 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
private static Entity lastClickedEntity;
|
private static Entity lastClickedEntity;
|
||||||
|
|
||||||
private void ShowEntityHierarchy()
|
/// Shows the entity hierarchy as a tree.
|
||||||
|
private void ShowUnfilteredEntityHierarchy()
|
||||||
{
|
{
|
||||||
StringView searchString = StringView(&_entitySearchChars);
|
|
||||||
|
|
||||||
if (_scene == null)
|
|
||||||
{
|
|
||||||
ImGui.TextUnformatted("<No scene open>");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(searchString.IsWhiteSpace)
|
|
||||||
{
|
|
||||||
// Show entity hierarchy as tree
|
|
||||||
|
|
||||||
TreeNode<Entity> root = scope .(Entity(.InvalidEntity, _scene));
|
TreeNode<Entity> root = scope .(Entity(.InvalidEntity, _scene));
|
||||||
|
|
||||||
TreeNode<Entity> InsertIntoTree(Entity entity)
|
TreeNode<Entity> InsertIntoTree(Entity entity)
|
||||||
@@ -632,30 +622,35 @@ namespace GlitchyEditor.EditWindows
|
|||||||
InsertIntoTree(entity);
|
InsertIntoTree(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rectangle over the entire window space
|
||||||
ImGui.Rect rect = .();
|
ImGui.Rect rect = .();
|
||||||
rect.Min = (ImGui.Vec2)((float2)ImGui.GetWindowContentRegionMin() + (float2)ImGui.GetWindowPos());
|
rect.Min = (ImGui.Vec2)((float2)ImGui.GetWindowContentRegionMin() + (float2)ImGui.GetWindowPos());
|
||||||
rect.Max = (ImGui.Vec2)((float2)rect.Min + (float2)ImGui.GetContentRegionAvail());
|
rect.Max = (ImGui.Vec2)((float2)rect.Min + (float2)ImGui.GetContentRegionAvail());
|
||||||
|
|
||||||
|
// Use window background as drop target to drop entities into scene root
|
||||||
if(ImGui.BeginDragDropTargetCustom(rect, ImGui.GetID("sceneDropTarget")))
|
if(ImGui.BeginDragDropTargetCustom(rect, ImGui.GetID("sceneDropTarget")))
|
||||||
{
|
{
|
||||||
Payload<UUID>? payload = ImGui.AcceptDragDropPayload<UUID>(.Entity);
|
Payload<UUID>? payload = ImGui.AcceptDragDropPayload<UUID>(.Entity);
|
||||||
|
|
||||||
if(payload != null)
|
if(payload != null)
|
||||||
{
|
{
|
||||||
UUID movedEntityId = payload->Data;
|
if (_editor.CurrentScene.GetEntityByID(payload->Data) case .Ok(let movedEntity))
|
||||||
|
{
|
||||||
Entity movedEntity = _editor.CurrentScene.GetEntityByID(movedEntityId);
|
|
||||||
|
|
||||||
var transformComponent = movedEntity.GetComponent<TransformComponent>();
|
var transformComponent = movedEntity.GetComponent<TransformComponent>();
|
||||||
transformComponent.Parent = .InvalidEntity;
|
transformComponent.Parent = .InvalidEntity;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.EngineLogger.Error($"Tried to move entity with id {payload->Data} into scene root, but the entity doesn't exist.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui.EndDragDropTarget();
|
ImGui.EndDragDropTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui.BeginTable("entityTable", 2, .RowBg | .NoBordersInBody | .SizingFixedFit))
|
if (ImGui.BeginTable("entityTable", 2, .RowBg | .NoBordersInBody | .SizingFixedFit))
|
||||||
{
|
{
|
||||||
ImGui.TableSetupColumn("Visibility", .IndentDisable | .NoResize);
|
ImGui.TableSetupColumn("", .IndentDisable | .NoResize);
|
||||||
ImGui.TableSetupColumn("Entities", .IndentEnable | .WidthStretch);
|
ImGui.TableSetupColumn("Entities", .IndentEnable | .WidthStretch);
|
||||||
|
|
||||||
for(var child in root.Children)
|
for(var child in root.Children)
|
||||||
@@ -666,11 +661,16 @@ namespace GlitchyEditor.EditWindows
|
|||||||
ImGui.EndTable();
|
ImGui.EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
// Show search results as flat list
|
|
||||||
|
|
||||||
List<StringView> searchTokens = new:ScopedAlloc! .(searchString.Split(' ', .RemoveEmptyEntries));
|
/// Shows a list of entities that match the search query.
|
||||||
|
private void ShowFilteredEntityList(StringView searchString)
|
||||||
|
{
|
||||||
|
List<StringView> searchTokens = scope .(searchString.Split(' ', .RemoveEmptyEntries));
|
||||||
|
|
||||||
|
if (ImGui.BeginTable("entityTable", 2, .RowBg | .NoBordersInBody | .SizingFixedFit))
|
||||||
|
{
|
||||||
|
ImGui.TableSetupColumn("Visibility", .IndentDisable | .NoResize);
|
||||||
|
ImGui.TableSetupColumn("Entities", .IndentEnable | .WidthStretch);
|
||||||
|
|
||||||
worldEnumeration:
|
worldEnumeration:
|
||||||
for(var entityId in _scene.[Friend]_ecsWorld.Enumerate())
|
for(var entityId in _scene.[Friend]_ecsWorld.Enumerate())
|
||||||
@@ -700,8 +700,32 @@ namespace GlitchyEditor.EditWindows
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGuiPrintEntityTree(scope .(entity));
|
ImGuiPrintEntityTree(scope .(entity), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui.EndTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shows the entity hierarchy either as tree or as filtered list.
|
||||||
|
private void ShowEntityHierarchy()
|
||||||
|
{
|
||||||
|
StringView searchString = StringView(&_entitySearchChars);
|
||||||
|
|
||||||
|
if (_scene == null)
|
||||||
|
{
|
||||||
|
ImGui.TextUnformatted("<No scene open>");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(searchString.IsWhiteSpace)
|
||||||
|
{
|
||||||
|
ShowUnfilteredEntityHierarchy();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ShowFilteredEntityList(searchString);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the mouse was released and no entity took the chance to become selected we probably hovered the background while releasing -> select no entity
|
// If the mouse was released and no entity took the chance to become selected we probably hovered the background while releasing -> select no entity
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using GlitchyEngine.Scripting;
|
|||||||
using GlitchyEngine.Math;
|
using GlitchyEngine.Math;
|
||||||
using GlitchyEngine.Scripting.Classes;
|
using GlitchyEngine.Scripting.Classes;
|
||||||
using GlitchyEngine.Serialization;
|
using GlitchyEngine.Serialization;
|
||||||
|
using GlitchyEngine.World.Components;
|
||||||
|
|
||||||
namespace GlitchyEngine.World
|
namespace GlitchyEngine.World
|
||||||
{
|
{
|
||||||
@@ -801,6 +802,11 @@ namespace GlitchyEngine.World
|
|||||||
let nameComponent = entity.AddComponent<NameComponent>();
|
let nameComponent = entity.AddComponent<NameComponent>();
|
||||||
nameComponent.Name = (name.IsEmpty ? "Entity" : name);
|
nameComponent.Name = (name.IsEmpty ? "Entity" : name);
|
||||||
|
|
||||||
|
#if GE_EDITOR
|
||||||
|
// Only add the editor flags if we are indeed in an editor
|
||||||
|
entity.AddComponent<EditorFlagsComponent>();
|
||||||
|
#endif
|
||||||
|
|
||||||
// If no id is given generate a random one.
|
// If no id is given generate a random one.
|
||||||
IDComponent idComponent = (id == default) ? IDComponent() : IDComponent(id);
|
IDComponent idComponent = (id == default) ? IDComponent() : IDComponent(id);
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using GlitchyEngine.Renderer;
|
|||||||
using GlitchyEngine.Content;
|
using GlitchyEngine.Content;
|
||||||
using GlitchyEngine.Math;
|
using GlitchyEngine.Math;
|
||||||
using System;
|
using System;
|
||||||
|
using GlitchyEngine.World.Components;
|
||||||
|
|
||||||
namespace GlitchyEngine.World;
|
namespace GlitchyEngine.World;
|
||||||
|
|
||||||
@@ -156,16 +157,22 @@ class SceneRenderer
|
|||||||
// 3D render
|
// 3D render
|
||||||
Renderer.BeginScene(camera, _compositeTarget);
|
Renderer.BeginScene(camera, _compositeTarget);
|
||||||
|
|
||||||
for (var (entity, transform, mesh, meshRenderer) in Scene._ecsWorld.Enumerate<TransformComponent, MeshComponent, MeshRendererComponent>())
|
for (var (entity, transform, mesh, meshRenderer, editorFlags) in Scene._ecsWorld.Enumerate<TransformComponent, MeshComponent, MeshRendererComponent, EditorFlagsComponent>())
|
||||||
{
|
{
|
||||||
|
if (editorFlags.Flags.HasFlag(.HideInScene))
|
||||||
|
continue;
|
||||||
|
|
||||||
if (mesh.Mesh == .Invalid || meshRenderer.Material == .Invalid)
|
if (mesh.Mesh == .Invalid || meshRenderer.Material == .Invalid)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Renderer.Submit(mesh.Mesh, meshRenderer.Material, entity, transform.WorldTransform);
|
Renderer.Submit(mesh.Mesh, meshRenderer.Material, entity, transform.WorldTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var (entity, transform, light) in Scene._ecsWorld.Enumerate<TransformComponent, LightComponent>())
|
for (var (entity, transform, light, editorFlags) in Scene._ecsWorld.Enumerate<TransformComponent, LightComponent, EditorFlagsComponent>())
|
||||||
{
|
{
|
||||||
|
if (editorFlags.Flags.HasFlag(.HideInScene))
|
||||||
|
continue;
|
||||||
|
|
||||||
Renderer.Submit(light.SceneLight, transform.WorldTransform);
|
Renderer.Submit(light.SceneLight, transform.WorldTransform);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,13 +189,19 @@ class SceneRenderer
|
|||||||
// Sprite renderer
|
// Sprite renderer
|
||||||
Renderer2D.BeginScene(camera, .BackToFront);
|
Renderer2D.BeginScene(camera, .BackToFront);
|
||||||
|
|
||||||
for (var (entity, transform, sprite) in Scene._ecsWorld.Enumerate<TransformComponent, SpriteRendererComponent>())
|
for (var (entity, transform, sprite, editorFlags) in Scene._ecsWorld.Enumerate<TransformComponent, SpriteRendererComponent, EditorFlagsComponent>())
|
||||||
{
|
{
|
||||||
|
if (editorFlags.Flags.HasFlag(.HideInScene))
|
||||||
|
continue;
|
||||||
|
|
||||||
Renderer2D.DrawSprite(transform.WorldTransform, sprite, entity.Index);
|
Renderer2D.DrawSprite(transform.WorldTransform, sprite, entity.Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var (entity, transform, circle) in Scene._ecsWorld.Enumerate<TransformComponent, CircleRendererComponent>())
|
for (var (entity, transform, circle, editorFlags) in Scene._ecsWorld.Enumerate<TransformComponent, CircleRendererComponent, EditorFlagsComponent>())
|
||||||
{
|
{
|
||||||
|
if (editorFlags.Flags.HasFlag(.HideInScene))
|
||||||
|
continue;
|
||||||
|
|
||||||
Renderer2D.DrawCircle(transform.WorldTransform, circle, entity.Index);
|
Renderer2D.DrawCircle(transform.WorldTransform, circle, entity.Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user