Compare commits
No commits in common. "86b54e15215e143a15a2aa6ee787c66e50b30f90" and "5cc876fce9aafb3d091f8ba324ca435a54a40f21" have entirely different histories.
86b54e1521
...
5cc876fce9
@ -1,6 +0,0 @@
|
|||||||
namespace Nerfed.Editor.Components;
|
|
||||||
|
|
||||||
public readonly record struct SelectedInHierachy;
|
|
||||||
public readonly record struct ClickedInHierachy;
|
|
||||||
public readonly record struct PayloadSourceInHierachy;
|
|
||||||
public readonly record struct PayloadTargetInHierachy;
|
|
4
Nerfed.Editor/Components/SelectedInHierachy.cs
Normal file
4
Nerfed.Editor/Components/SelectedInHierachy.cs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
namespace Nerfed.Editor.Components;
|
||||||
|
|
||||||
|
public readonly record struct SelectedInHierachy;
|
||||||
|
public readonly record struct ClickedInHierarchy;
|
@ -9,7 +9,6 @@
|
|||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
<Configurations>Debug;Test;Release</Configurations>
|
<Configurations>Debug;Test;Release</Configurations>
|
||||||
<Platforms>x64</Platforms>
|
<Platforms>x64</Platforms>
|
||||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
|
||||||
|
@ -31,7 +31,6 @@ private static void HandleOnInitialize()
|
|||||||
editorSystems.Add(new EditorHierarchyWindow(world));
|
editorSystems.Add(new EditorHierarchyWindow(world));
|
||||||
|
|
||||||
Entity ent1 = world.CreateEntity("parent");
|
Entity ent1 = world.CreateEntity("parent");
|
||||||
world.Set(ent1, new Root());
|
|
||||||
world.Set(ent1, new LocalTransform(new Vector3(1, 0, 0), Quaternion.Identity, Vector3.One));
|
world.Set(ent1, new LocalTransform(new Vector3(1, 0, 0), Quaternion.Identity, Vector3.One));
|
||||||
|
|
||||||
Entity ent2 = world.CreateEntity("child");
|
Entity ent2 = world.CreateEntity("child");
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using MoonTools.ECS;
|
using MoonTools.ECS;
|
||||||
using Nerfed.Editor.Components;
|
using Nerfed.Editor.Components;
|
||||||
using Nerfed.Runtime;
|
|
||||||
using Nerfed.Runtime.Components;
|
using Nerfed.Runtime.Components;
|
||||||
using Nerfed.Runtime.Util;
|
|
||||||
|
|
||||||
namespace Nerfed.Editor.Systems
|
namespace Nerfed.Editor.Systems
|
||||||
{
|
{
|
||||||
@ -12,16 +10,15 @@ internal class EditorHierarchyWindow : MoonTools.ECS.DebugSystem
|
|||||||
{
|
{
|
||||||
private const ImGuiTreeNodeFlags baseFlags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.SpanAvailWidth;
|
private const ImGuiTreeNodeFlags baseFlags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.SpanAvailWidth;
|
||||||
|
|
||||||
//private readonly Filter rootEntitiesWithTransformFilter;
|
private readonly Filter rootEntitiesWithTransformFilter;
|
||||||
//private readonly Filter rootEntitiesFilterBroken;
|
//private readonly Filter rootEntitiesFilterBroken;
|
||||||
private readonly Filter rootEntitiesFilter;
|
private readonly Filter rootEntitiesFilter;
|
||||||
|
|
||||||
private readonly EditorHierachySelectionSystem hierachySelectionSystem;
|
private readonly EditorHierachySelectionSystem hierachySelectionSystem;
|
||||||
private readonly EditorHierachyDragAndDropSystem hierachyDragAndDropSystem;
|
|
||||||
|
|
||||||
public EditorHierarchyWindow(World world) : base(world)
|
public EditorHierarchyWindow(World world) : base(world)
|
||||||
{
|
{
|
||||||
//rootEntitiesWithTransformFilter = FilterBuilder.Include<LocalTransform>().Exclude<Child>().Build();
|
rootEntitiesWithTransformFilter = FilterBuilder.Include<LocalTransform>().Exclude<Child>().Build();
|
||||||
|
|
||||||
// TODO: this doesn't work.
|
// TODO: this doesn't work.
|
||||||
//rootEntitiesFilterBroken = FilterBuilder.Exclude<Child>().Build();
|
//rootEntitiesFilterBroken = FilterBuilder.Exclude<Child>().Build();
|
||||||
@ -34,7 +31,6 @@ public EditorHierarchyWindow(World world) : base(world)
|
|||||||
// Or a EditorComponent, just a component that always gets added when in editor mode.
|
// Or a EditorComponent, just a component that always gets added when in editor mode.
|
||||||
|
|
||||||
hierachySelectionSystem = new EditorHierachySelectionSystem(world);
|
hierachySelectionSystem = new EditorHierachySelectionSystem(world);
|
||||||
hierachyDragAndDropSystem = new EditorHierachyDragAndDropSystem(world);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(TimeSpan delta)
|
public override void Update(TimeSpan delta)
|
||||||
@ -46,28 +42,10 @@ public override void Update(TimeSpan delta)
|
|||||||
|
|
||||||
if (ImGui.TreeNodeEx("World", flags))
|
if (ImGui.TreeNodeEx("World", flags))
|
||||||
{
|
{
|
||||||
//if (ImGui.BeginDragDropTarget())
|
foreach (Entity entity in rootEntitiesWithTransformFilter.Entities)
|
||||||
//{
|
{
|
||||||
// unsafe
|
DrawEntityAndChildren(entity);
|
||||||
// {
|
}
|
||||||
// ImGuiPayloadPtr payload = ImGui.AcceptDragDropPayload($"{nameof(EditorHierarchyWindow)}");
|
|
||||||
// if (payload.NativePtr != null)
|
|
||||||
// {
|
|
||||||
// Entity* data = (Entity*)payload.Data;
|
|
||||||
// Entity child = data[0];
|
|
||||||
|
|
||||||
// Log.Info($"Dropped {child.ID}");
|
|
||||||
|
|
||||||
// Transform.RemoveParent(World, child);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// ImGui.EndDragDropTarget();
|
|
||||||
//}
|
|
||||||
|
|
||||||
//foreach (Entity entity in rootEntitiesWithTransformFilter.Entities)
|
|
||||||
//{
|
|
||||||
// DrawEntityAndChildren(entity);
|
|
||||||
//}
|
|
||||||
|
|
||||||
foreach (Entity entity in rootEntitiesFilter.Entities)
|
foreach (Entity entity in rootEntitiesFilter.Entities)
|
||||||
{
|
{
|
||||||
@ -80,7 +58,6 @@ public override void Update(TimeSpan delta)
|
|||||||
ImGui.End();
|
ImGui.End();
|
||||||
|
|
||||||
hierachySelectionSystem.Update(delta);
|
hierachySelectionSystem.Update(delta);
|
||||||
hierachyDragAndDropSystem.Update(delta);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawEntityAndChildren(in Entity entity)
|
private void DrawEntityAndChildren(in Entity entity)
|
||||||
@ -99,54 +76,9 @@ private void DrawEntityAndChildren(in Entity entity)
|
|||||||
|
|
||||||
if (ImGui.TreeNodeEx($"{entity.ID} | {GetTag(entity)}", flags))
|
if (ImGui.TreeNodeEx($"{entity.ID} | {GetTag(entity)}", flags))
|
||||||
{
|
{
|
||||||
// Selection.
|
|
||||||
if (ImGui.IsItemClicked() && !ImGui.IsItemToggledOpen())
|
if (ImGui.IsItemClicked() && !ImGui.IsItemToggledOpen())
|
||||||
{
|
{
|
||||||
World.Set(entity, new ClickedInHierachy());
|
World.Set(entity, new ClickedInHierarchy());
|
||||||
}
|
|
||||||
|
|
||||||
// Drag and drop.
|
|
||||||
if (ImGui.BeginDragDropSource())
|
|
||||||
{
|
|
||||||
ImGui.SetDragDropPayload($"{nameof(EditorHierarchyWindow)}", nint.Zero, 0);
|
|
||||||
Set(entity, new PayloadSourceInHierachy());
|
|
||||||
Log.Info($"SetSource {entity.ID}");
|
|
||||||
|
|
||||||
//unsafe
|
|
||||||
//{
|
|
||||||
// fixed (Entity* payload = &entity)
|
|
||||||
// {
|
|
||||||
// ImGui.SetDragDropPayload($"{nameof(EditorHierarchyWindow)}", (IntPtr)payload, (uint)sizeof(Entity));
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
ImGui.EndDragDropSource();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui.BeginDragDropTarget())
|
|
||||||
{
|
|
||||||
ImGuiPayloadPtr payload = ImGui.AcceptDragDropPayload($"{nameof(EditorHierarchyWindow)}");
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
if (payload.NativePtr != null)
|
|
||||||
{
|
|
||||||
Log.Info($"SetTarget {entity.ID}");
|
|
||||||
Set(entity, new PayloadTargetInHierachy());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//unsafe
|
|
||||||
//{
|
|
||||||
// ImGuiPayloadPtr payload = ImGui.AcceptDragDropPayload($"{nameof(EditorHierarchyWindow)}");
|
|
||||||
// if (payload.NativePtr != null)
|
|
||||||
// {
|
|
||||||
// Entity ent = *(Entity*)payload.Data;
|
|
||||||
|
|
||||||
// Log.Info($"Dropped {ent.ID}");
|
|
||||||
|
|
||||||
// Transform.SetParent(World, ent, entity);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
ImGui.EndDragDropTarget();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReverseSpanEnumerator<Entity> childEntities = World.InRelations<ChildParentRelation>(entity);
|
ReverseSpanEnumerator<Entity> childEntities = World.InRelations<ChildParentRelation>(entity);
|
||||||
@ -168,7 +100,7 @@ private class EditorHierachySelectionSystem : MoonTools.ECS.System
|
|||||||
public EditorHierachySelectionSystem(World world) : base(world)
|
public EditorHierachySelectionSystem(World world) : base(world)
|
||||||
{
|
{
|
||||||
selectedEntities = FilterBuilder.Include<SelectedInHierachy>().Build();
|
selectedEntities = FilterBuilder.Include<SelectedInHierachy>().Build();
|
||||||
clickedEntities = FilterBuilder.Include<ClickedInHierachy>().Build();
|
clickedEntities = FilterBuilder.Include<ClickedInHierarchy>().Build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(TimeSpan delta)
|
public override void Update(TimeSpan delta)
|
||||||
@ -196,55 +128,7 @@ public override void Update(TimeSpan delta)
|
|||||||
Set(entity, new SelectedInHierachy());
|
Set(entity, new SelectedInHierachy());
|
||||||
}
|
}
|
||||||
|
|
||||||
Remove<ClickedInHierachy>(entity);
|
Remove<ClickedInHierarchy>(entity);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class EditorHierachyDragAndDropSystem : MoonTools.ECS.System
|
|
||||||
{
|
|
||||||
private readonly Filter sourceEntities;
|
|
||||||
private readonly Filter targetEntities;
|
|
||||||
|
|
||||||
public EditorHierachyDragAndDropSystem(World world) : base(world)
|
|
||||||
{
|
|
||||||
sourceEntities = FilterBuilder.Include<PayloadSourceInHierachy>().Build();
|
|
||||||
targetEntities = FilterBuilder.Include<PayloadTargetInHierachy>().Build();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Update(TimeSpan delta)
|
|
||||||
{
|
|
||||||
if (!targetEntities.Empty)
|
|
||||||
{
|
|
||||||
Entity target = GetSingletonEntity<PayloadTargetInHierachy>();
|
|
||||||
|
|
||||||
foreach (Entity source in sourceEntities.Entities)
|
|
||||||
{
|
|
||||||
Transform.SetParent(World, source, target);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool clear = false;
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
ImGuiPayloadPtr payload = ImGui.GetDragDropPayload();
|
|
||||||
if (payload.NativePtr == null)
|
|
||||||
{
|
|
||||||
clear = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clear)
|
|
||||||
{
|
|
||||||
foreach (Entity source in targetEntities.Entities)
|
|
||||||
{
|
|
||||||
Remove<PayloadTargetInHierachy>(source);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (Entity source in sourceEntities.Entities)
|
|
||||||
{
|
|
||||||
Remove<PayloadSourceInHierachy>(source);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ private void UpdateWorldTransform(in Entity entity, Matrix4x4 localToWorldMatrix
|
|||||||
LocalToWorld localToWorld = new(localToWorldMatrix);
|
LocalToWorld localToWorld = new(localToWorldMatrix);
|
||||||
Set(entity, localToWorld);
|
Set(entity, localToWorld);
|
||||||
|
|
||||||
//Log.Info($"Entity {entity} | local position {localTransform.position} | world position {localToWorldMatrix.Translation}");
|
Log.Info($"Entity {entity} | local position {localTransform.position} | world position {localToWorldMatrix.Translation}");
|
||||||
}
|
}
|
||||||
|
|
||||||
ReverseSpanEnumerator<Entity> childEntities = World.OutRelations<ChildParentRelation>(entity);
|
ReverseSpanEnumerator<Entity> childEntities = World.OutRelations<ChildParentRelation>(entity);
|
||||||
|
@ -28,7 +28,10 @@ public static Matrix4x4 TRS(in this LocalTransform localTransform)
|
|||||||
// Relation goes from child to parent.
|
// Relation goes from child to parent.
|
||||||
public static void SetParent(in World world, in Entity child, in Entity parent)
|
public static void SetParent(in World world, in Entity child, in Entity parent)
|
||||||
{
|
{
|
||||||
RemoveParent(world, child);
|
if (world.Related<ChildParentRelation>(parent, child))
|
||||||
|
{
|
||||||
|
RemoveParent(world, parent);
|
||||||
|
}
|
||||||
|
|
||||||
world.Relate(child, parent, new ChildParentRelation());
|
world.Relate(child, parent, new ChildParentRelation());
|
||||||
world.Set(child, new Child());
|
world.Set(child, new Child());
|
||||||
@ -44,10 +47,8 @@ public static void RemoveParent(in World world, in Entity child)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity parent = world.OutRelationSingleton<ChildParentRelation>(child);
|
|
||||||
|
|
||||||
// TODO: Check if Unrelate all also unrelates incomming relations..?
|
// TODO: Check if Unrelate all also unrelates incomming relations..?
|
||||||
world.Unrelate<ChildParentRelation>(child, parent);
|
world.UnrelateAll<ChildParentRelation>(child);
|
||||||
world.Remove<Child>(child);
|
world.Remove<Child>(child);
|
||||||
world.Set(child, new Root());
|
world.Set(child, new Root());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user