Allow dragging and dropping of Entities in editor

+ New Dictionary Helpers
+ Made ImGui Payloads safer
+ Start of Component drag'n'drop
This commit is contained in:
Simon Lübeß
2023-07-24 23:17:00 +02:00
parent b53ed2d8f2
commit 37197cbdf1
19 changed files with 500 additions and 183 deletions
@@ -341,9 +341,13 @@ namespace GlitchyEditor.EditWindows
if (deleted)
return;
bool isDragged = false;
if(ImGui.BeginDragDropSource())
{
ImGui.SetDragDropPayload("DND_Entity", &tree.Value, sizeof(Entity));
isDragged = true;
ImGui.SetDragDropPayload(.Entity, &tree.Value, sizeof(Entity));
ImGui.Text(name);
@@ -352,7 +356,7 @@ namespace GlitchyEditor.EditWindows
if(ImGui.BeginDragDropTarget())
{
ImGui.Payload* payload = ImGui.AcceptDragDropPayload("DND_Entity");
ImGui.Payload* payload = ImGui.AcceptDragDropPayload(.Entity);
if(payload != null)
{
@@ -395,7 +399,7 @@ namespace GlitchyEditor.EditWindows
bool clicked = ImGui.IsItemClicked(.Left);
bool clickedRight = ImGui.IsItemClicked(.Right);
if(isOpen)
{
for(var child in tree.Children)
@@ -407,6 +411,12 @@ namespace GlitchyEditor.EditWindows
}
if (clicked || clickedRight)
{
lastClickedEntity = tree.Value;
}
//if (!isDragged && (clicked || clickedRight))
if (!isDragged && (!ImGui.IsMouseDown(.Left) && !ImGui.IsMouseDown(.Right) && ImGui.IsItemHovered()) && tree.Value == lastClickedEntity)
{
if (inSelectedList && !clickedRight)
{
@@ -418,9 +428,13 @@ namespace GlitchyEditor.EditWindows
SelectEntity(tree.Value, !ImGui.GetIO().KeyCtrl && !clickedRight);
inSelectedList = true;
}
lastClickedEntity = .();
}
}
private static Entity lastClickedEntity;
private void ShowEntityHierarchy()
{
StringView searchString = StringView(&_entitySearchChars);
@@ -464,7 +478,7 @@ namespace GlitchyEditor.EditWindows
{
if(ImGui.BeginDragDropTarget())
{
ImGui.Payload* payload = ImGui.AcceptDragDropPayload("DND_Entity");
ImGui.Payload* payload = ImGui.AcceptDragDropPayload(.Entity);
if(payload != null)
{
@@ -527,6 +541,10 @@ namespace GlitchyEditor.EditWindows
ImGuiPrintEntityTree(scope .(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
if (!ImGui.IsMouseDown(.Left) && !ImGui.IsMouseDown(.Right))
lastClickedEntity = .();
}
}
}