Exemplo n.º 1
0
        void Traverse(GameObject gameObject)
        {
            bool leaf = gameObject.Transform.Children.Count <= 0;

            if (gameObject == selectedObj)
            {
                ImGui.PushStyleColor(ImGuiCol.Text, new System.Numerics.Vector4(0.25882352941f, 0.5294117647f, 0.96078431372f, 1));
            }
            var x = ImGui.GetCursorPosX();

            ImGui.Dummy(new System.Numerics.Vector2(ImGui.GetContentRegionAvail().X, ImGui.GetFontSize()));
            ImGui.SameLine();
            ImGui.SetCursorPosX(x);
            bool open = ImGui.TreeNodeEx(gameObject.UIDText, (!ImGui.IsMouseClicked(ImGuiMouseButton.Left) && leaf ? ImGuiTreeNodeFlags.Leaf : 0) | ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.SpanAvailWidth | ImGuiTreeNodeFlags.OpenOnArrow, gameObject.Name);


            if (ImGui.BeginDragDropSource())
            {
                if (ImGui.SetDragDropPayload("Transform", IntPtr.Zero, 0))
                {
                    scr = gameObject.Transform;
                }
                ImGui.EndDragDropSource();
            }

            if (ImGui.BeginDragDropTarget())
            {
                var payload = ImGui.AcceptDragDropPayload("Transform");
                if (payload.NativePtr != null && scr != null)
                {
                    scr.Parent = gameObject.Transform;
                }
                ImGui.EndDragDropTarget();
            }

            if (gameObject == selectedObj)
            {
                ImGui.PopStyleColor();
            }

            if (ImGui.IsItemClicked())
            {
                if (selectedObj != gameObject)
                {
                    SelectionChanged(gameObject);
                }
                selectedObj = gameObject;
            }

            if (open)
            {
                for (int i = 0; i < gameObject.Transform.Children.Count; i++)
                {
                    Traverse(gameObject.Transform.Children[i].GameObject);
                }
                ImGui.TreePop();
            }
        }
Exemplo n.º 2
0
        unsafe void OnFunctionDragDrop(INodeGraph bp)
        {
            ImGuiPayloadPtr pPayload = ImGui.AcceptDragDropPayload("FUNCTION_DRAG");

            if (pPayload.NativePtr != null)
            {
                int fucntionID = *(int *)pPayload.Data;
                CreateFunctionCallNode(bp, fucntionID);
            }
        }
Exemplo n.º 3
0
Arquivo: GUI.cs Projeto: randomcrab/SE
        public static unsafe string AcceptDragDropPayload(string type)
        {
            ImGuiPayloadPtr payload = ImGui.AcceptDragDropPayload(type);

            if (payload.NativePtr != null)
            {
                string str = Marshal.PtrToStringUni(payload.Data);
                payload.Clear();
                return(str);
            }
            return(null);
        }
Exemplo n.º 4
0
        private static bool DrawDragDropTargetSources(CooldownTrigger trigger, IList <int> toSwap)
        {
            const string payloadIdentifier = "PRIORITY_PAYLOAD";

            if (ImGui.BeginDragDropSource(ImGuiDragDropFlags.SourceNoHoldToOpenOthers |
                                          ImGuiDragDropFlags.SourceNoPreviewTooltip))
            {
                unsafe
                {
                    var prio = trigger.Priority;
                    var ptr  = new IntPtr(&prio);
                    ImGui.SetDragDropPayload(payloadIdentifier, ptr, sizeof(int));
                }

                ImGui.SameLine();
                ImGui.AlignTextToFramePadding();
#if DEBUG
                ImGui.Text($"{trigger.Priority + 1} Dragging {trigger.ActionName}.");
#else
                ImGui.Text($"Dragging {trigger.ActionName}.");
#endif
                ImGui.EndDragDropSource();
                return(true);
            }

            if (!ImGui.BeginDragDropTarget())
            {
                return(false);
            }
            var imGuiPayloadPtr = ImGui.AcceptDragDropPayload(payloadIdentifier,
                                                              ImGuiDragDropFlags.AcceptNoPreviewTooltip |
                                                              ImGuiDragDropFlags.AcceptNoDrawDefaultRect);
            unsafe
            {
                if (imGuiPayloadPtr.NativePtr is not null)
                {
                    var prio = *(int *)imGuiPayloadPtr.Data;
                    toSwap[0] = prio;
                    toSwap[1] = trigger.Priority;
                }
            }

            ImGui.SameLine();
            ImGui.AlignTextToFramePadding();
#if DEBUG
            ImGui.Text($"{trigger.Priority + 1} Swap with {trigger.ActionName}");
#else
            ImGui.Text($"Swap with {trigger.ActionName}");
#endif
            ImGui.EndDragDropTarget();
            return(true);
        }
Exemplo n.º 5
0
        unsafe void OnVarDragDrop(INodeGraph bp)
        {
            ImGuiPayloadPtr pPayload = ImGui.AcceptDragDropPayload("VAR_DRAG");

            if (pPayload.NativePtr == null)
            {
                return;
            }

            int varID = *(int *)pPayload.Data;

            m_PopupVarGetSet.Show(varID, OnSelectVarGetSet);
            Logger.Info("Var Drop. ID:" + varID);
        }
Exemplo n.º 6
0
        public static bool DragDropTarget(ushort handleIdx,
                                          DragDropWindow window, DragDropTree tree,
                                          string payloadType, ImGuiDragDropFlags flags,
                                          Action <DragDropWindow, DragDropTree, ushort,
                                                  DragDropWindow, DragDropTree, ushort> action)
        {
            bool ret = false;

            if (ImGui.BeginDragDropTarget())
            {
                var payload = ImGui.AcceptDragDropPayload(payloadType, flags);
                unsafe
                {
                    if (payload.NativePtr != null)
                    {
                        IntPtr dataSource = payload.Data;
                        System.Runtime.InteropServices.Marshal.Copy(dataSource, s_dragdropDataE, 0, s_dragdrop_size);
                        DragDropWindow windowSource    = (DragDropWindow)s_dragdropDataE[0];
                        DragDropTree   treeSource      = (DragDropTree)s_dragdropDataE[1];
                        ushort         handleIdxSource = 0;
                        unsafe
                        {
                            fixed(byte *pbyte = &s_dragdropDataE[2])
                            {
                                handleIdxSource = *((ushort *)pbyte);
                            }
                        }

                        if (action != null)
                        {
                            action(windowSource, treeSource, handleIdxSource,
                                   window, tree, handleIdx);
                        }

                        ret = true;
                    }
                }

                ImGui.EndDragDropTarget();
            }

            return(ret);
        }
Exemplo n.º 7
0
        public override void DrawUI()
        {
            if (ImGui.Begin(UIName, ref IsActive, ImGuiWindowFlags.NoCollapse))
            {
                ImGui.Dummy(ImGui.GetContentRegionAvail());
                ImGui.SetCursorPosY(0);

                ImGui.PushStyleColor(ImGuiCol.DragDropTarget, new System.Numerics.Vector4(0.219f, 0.223f, 0.623f, 1));
                if (ImGui.BeginDragDropTarget())
                {
                    var payload = ImGui.AcceptDragDropPayload("Transform");
                    if (payload.NativePtr != null && scr != null)
                    {
                        scr.Parent = null;
                    }
                    ImGui.EndDragDropTarget();
                }
                //for (int i = 0; i < EditorManager.Instance.LÖÖPS.Scenes.Count; i++)
                {
                    Scene scene = Manager.GameGameLoop.MasterScene;
                    if (ImGui.TreeNodeEx(scene.UIDText, ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.Framed | ImGuiTreeNodeFlags.DefaultOpen | ImGuiTreeNodeFlags.FramePadding, "Root Scene"))
                    {
                        var gos = scene.RootObjects;
                        for (int j = 0; j < gos.Count; j++)
                        {
                            if (gos[j].Transform.Parent == null)
                            {
                                Traverse(gos[j]);
                            }
                        }
                        ImGui.TreePop();
                    }
                }
                ImGui.PopStyleColor();
            }
            ImGui.End();
        }
Exemplo n.º 8
0
        private void DrawViewport()
        {
            var size = ImGui.GetWindowSize();

            if (Pipeline.Width != (int)size.X || Pipeline.Height != (int)size.Y)
            {
                Pipeline.Width  = (int)size.X;
                Pipeline.Height = (int)size.Y;
                Pipeline.OnResize();
            }

            Pipeline.RenderScene();

            if ((ImGui.IsWindowFocused() && _mouseDown) ||
                ImGui.IsWindowFocused() && ImGui.IsWindowHovered() || _mouseDown)
            {
                if (!onEnter)
                {
                    Pipeline.ResetPrevious();
                    onEnter = true;
                }

                //Only update scene when necessary
                if (ImGuiController.ApplicationHasFocus)
                {
                    UpdateCamera();
                }
            }
            else
            {
                onEnter = false;

                //Reset drag/dropped model data if mouse leaves the viewport during a drag event
                if (DragDroppedModel != null)
                {
                    DragDroppedModel.DragDroppedOnLeave();
                    DragDroppedModel = null;
                }
            }

            var id = Pipeline.GetViewportTexture();

            ImGui.Image((IntPtr)id, size, new System.Numerics.Vector2(0, 1), new System.Numerics.Vector2(1, 0));

            if (ImGui.BeginDragDropTarget())
            {
                ImGuiPayloadPtr outlinerDrop = ImGui.AcceptDragDropPayload("OUTLINER_ITEM",
                                                                           ImGuiDragDropFlags.AcceptNoDrawDefaultRect | ImGuiDragDropFlags.AcceptBeforeDelivery);

                if (outlinerDrop.IsValid())
                {
                    //Drag/drop things onto meshes
                    var mouseInfo = CreateMouseState();
                    var picked    = Pipeline.GetPickedObject(mouseInfo);
                    //Picking object changed.
                    if (DragDroppedModel != picked)
                    {
                        //Set exit drop event for previous model
                        if (DragDroppedModel != null)
                        {
                            DragDroppedModel.DragDroppedOnLeave();
                        }

                        DragDroppedModel = picked;

                        //Model has changed so call the enter event
                        if (picked != null)
                        {
                            picked.DragDroppedOnEnter();
                        }
                    }

                    if (picked != null)
                    {
                        //Set the drag/drop event
                        var node = Outliner.GetDragDropNode();
                        picked.DragDropped(node.Tag);
                    }
                    if (mouseInfo.LeftButton == ButtonState.Released)
                    {
                        DragDroppedModel = null;
                    }
                }
                ImGui.EndDragDropTarget();
            }
        }
Exemplo n.º 9
0
        static unsafe void SubmitFieldPropertyInspector(FieldPropertyListInfo info, object entityComponent, bool showMidi = true)
        {
            ImGui.PushID(GetIdString(info, entityComponent));

            EditorHelper.RangeAttribute rangeAttribute = null;
            if (info.MemberInfo != null)
            {
                rangeAttribute = CustomAttributeExtensions.GetCustomAttribute <EditorHelper.RangeAttribute>(info.MemberInfo, true);
            }

            var infoType = info.FieldPropertyType;

            if (infoType == typeof(string))
            {
                string val = (string)info.GetValue();
                if (val == null)
                {
                    val = string.Empty;
                }
                if (ImGui.InputText(info.Name, ref val, 1000))
                {
                    info.SetValue(val);
                }
            }
            else if (infoType == typeof(bool))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Button);
                }

                bool val = (bool)info.GetValue();
                if (ImGui.Checkbox(info.Name, ref val))
                {
                    info.SetValue(val);
                }
            }
            else if (infoType == typeof(float))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                float val = (float)info.GetValue();
                bool  result;
                if (rangeAttribute != null &&
                    (rangeAttribute.RangeType == EditorHelper.RangeAttribute.RangeTypeEnum.Float ||
                     rangeAttribute.RangeType == EditorHelper.RangeAttribute.RangeTypeEnum.Int))
                {
                    if (rangeAttribute.RangeType == EditorHelper.RangeAttribute.RangeTypeEnum.Float)
                    {
                        result = ImGui.SliderFloat(info.Name, ref val, rangeAttribute.MinFloat, rangeAttribute.MaxFloat);
                    }
                    else
                    {
                        result = ImGui.SliderFloat(info.Name, ref val, rangeAttribute.MinInt, rangeAttribute.MaxInt);
                    }
                }
                else
                {
                    result = ImGui.DragFloat(info.Name, ref val, 0.1f);
                }
                if (result)
                {
                    info.SetValue(val);
                }
            }
            else if (infoType == typeof(Vector2))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                Vector2 val = (Vector2)info.GetValue();
                if (ImGui.DragFloat2(info.Name, ref val))
                {
                    info.SetValue(val);
                }
            }
            else if (infoType == typeof(Vector3))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                Vector3 val = (Vector3)info.GetValue();
                if (ImGui.DragFloat3(info.Name, ref val))
                {
                    info.SetValue(val);
                }
            }
            else if (infoType == typeof(Vector4))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                Vector4 val = (Vector4)info.GetValue();
                if (ImGui.DragFloat4(info.Name, ref val))
                {
                    info.SetValue(val);
                }
            }
            else if (infoType == typeof(Xna.Vector2))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                Xna.Vector2 xnaVal = (Xna.Vector2)info.GetValue();
                Vector2     val    = new Vector2(xnaVal.X, xnaVal.Y);
                if (ImGui.DragFloat2(info.Name, ref val))
                {
                    xnaVal.X = val.X;
                    xnaVal.Y = val.Y;
                    info.SetValue(xnaVal);
                }
            }
            else if (infoType == typeof(Xna.Vector3))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                Xna.Vector3 xnaVal = (Xna.Vector3)info.GetValue();
                Vector3     val    = new Vector3(xnaVal.X, xnaVal.Y, xnaVal.Z);
                if (ImGui.DragFloat3(info.Name, ref val))
                {
                    xnaVal.X = val.X;
                    xnaVal.Y = val.Y;
                    xnaVal.Z = val.Z;
                    info.SetValue(xnaVal);
                }
            }
            else if (infoType == typeof(Xna.Vector4))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                Xna.Vector4 xnaVal = (Xna.Vector4)info.GetValue();
                Vector4     val    = new Vector4(xnaVal.X, xnaVal.Y, xnaVal.Z, xnaVal.W);
                if (ImGui.DragFloat4(info.Name, ref val))
                {
                    xnaVal.X = val.X;
                    xnaVal.Y = val.Y;
                    xnaVal.Z = val.Z;
                    xnaVal.W = val.W;
                    info.SetValue(xnaVal);
                }
            }
            else if (infoType == typeof(int))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                int  val = (int)info.GetValue();
                bool result;
                if (rangeAttribute != null && rangeAttribute.RangeType == EditorHelper.RangeAttribute.RangeTypeEnum.Int)
                {
                    result = ImGui.SliderInt(info.Name, ref val, rangeAttribute.MinInt, rangeAttribute.MaxInt);
                }
                else
                {
                    result = ImGui.InputInt(info.Name, ref val);
                }
                if (result)
                {
                    info.SetValue(val);
                }
            }
            else if (infoType == typeof(uint))
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Knob);
                }

                int  val = (int)((uint)info.GetValue());
                bool result;
                if (rangeAttribute != null && rangeAttribute.RangeType == EditorHelper.RangeAttribute.RangeTypeEnum.Int)
                {
                    result = ImGui.SliderInt(info.Name, ref val, rangeAttribute.MinInt, rangeAttribute.MaxInt);
                }
                else
                {
                    result = ImGui.InputInt(info.Name, ref val);
                }
                if (result)
                {
                    if (val < 0)
                    {
                        val = 0;
                    }
                    info.SetValue((uint)val);
                }
            }
            else if (infoType.IsEnum)
            {
                if (showMidi)
                {
                    SubmitMidiAssignment(entityComponent, info, MidiState.MidiControlDescriptionType.Button);
                }

                var val          = info.GetValue();
                var enumNames    = infoType.GetEnumNames();
                int currentIndex = 0;
                for (int i = 0; i < enumNames.Length; i++)
                {
                    if (enumNames[i] == val.ToString())
                    {
                        currentIndex = i;
                    }
                }
                if (ImGui.Combo(info.Name, ref currentIndex, enumNames, enumNames.Length))
                {
                    info.SetValue(infoType.GetEnumValues().GetValue(currentIndex));
                }
            }
            else if (typeof(IList).IsAssignableFrom(infoType))
            {
                var   listthing = info.GetValue();
                IList list      = listthing as IList;
                ImGui.Text($"{info.Name} List ({list.Count} items)");
                ImGui.SameLine();
                if (ImGui.Button("-"))
                {
                    if (list.Count > 0)
                    {
                        list.RemoveAt(list.Count - 1);
                    }
                }
                ImGui.SameLine();
                if (ImGui.Button("+"))
                {
                    Type listItemType = list.GetType().GetGenericArguments().First();
                    if (listItemType.IsValueType)
                    {
                        list.Add(Activator.CreateInstance(listItemType));
                    }
                    else
                    {
                        list.Add(null);
                    }
                }

                ImGui.Indent();
                for (int i = 0; i < list.Count; i++)
                {
                    FieldPropertyListInfo itemInfo = new FieldPropertyListInfo(list, i);
                    SubmitFieldPropertyInspector(itemInfo, list);
                }
                ImGui.Unindent();
            }
            else if (!infoType.IsValueType)
            {
                string valText;
                var    value = info.GetValue();
                if (value != null)
                {
                    valText = value.ToString();
                }
                else
                {
                    valText = "null";
                }
                string label = $"{info.Name}: {valText}";
                if (typeof(Component).IsAssignableFrom(infoType) || typeof(Entity).IsAssignableFrom(infoType))
                {
                    if (ImGui.Selectable(label, false))
                    {
                        SelectedEntityComponent = value;
                        scrollEntitiesView      = true;
                        scrollSceneGraphView    = true;
                    }
                }
                else
                {
                    ImGui.Text(label);
                }

                if (draggedObject != null && infoType.IsAssignableFrom(draggedObject.GetType()))
                {
                    if (ImGui.BeginDragDropTarget())
                    {
                        var payload = ImGui.AcceptDragDropPayload(PAYLOAD_STRING);
                        if (payload.NativePtr != null) // Only when this is non-null does it mean that we've released the drag
                        {
                            info.SetValue(draggedObject);
                            draggedObject = null;
                        }
                        ImGui.EndDragDropTarget();
                    }
                }
            }
            else
            {
                SubmitReadonlyFieldPropertyInspector(info);
            }
            ImGui.PopID();

            SubmitHelpMarker(info);
        }
Exemplo n.º 10
0
        private static unsafe void AddSceneGraphTransforms(EntityAdmin admin, List <Transform> list)
        {
            // The selectedTransform is either the selectedEntityComponent (if it's a Transform) or the Transform associated with the selected Entity/Component.
            Transform selectedTransform = SelectedEntityComponent as Transform;

            if (selectedTransform == null)
            {
                Entity entity = SelectedEntityComponent as Entity;
                if (entity == null)
                {
                    Component component = SelectedEntityComponent as Component;
                    if (component != null)
                    {
                        entity = component.Entity;
                    }
                }

                if (entity != null)
                {
                    selectedTransform = entity.GetComponent <Transform>(true);
                }
            }

            foreach (var transform in list)
            {
                ImGuiTreeNodeFlags nodeFlags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.OpenOnDoubleClick | ImGuiTreeNodeFlags.SpanAvailWidth; // OpenOnDoubleClick doesn't seem to work. Not sure why.
                if (transform.Children.Count == 0)
                {
                    nodeFlags |= ImGuiTreeNodeFlags.Leaf;
                }
                if (transform == selectedTransform)
                {
                    nodeFlags |= ImGuiTreeNodeFlags.Selected;
                    if (scrollSceneGraphView)
                    {
                        ImGui.SetScrollHereY();
                    }
                }

                bool      parentOfSelected = false;
                Transform parent           = selectedTransform as Transform;
                while (parent != null)
                {
                    parent = parent.Parent;
                    if (parent == transform)
                    {
                        parentOfSelected = true;
                        break;
                    }
                }
                if (parentOfSelected)
                {
                    ImGui.SetNextItemOpen(true);
                }
                if (!transform.IsActive)
                {
                    ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.5f, 0.5f, 0.5f, 1f));
                }
                bool expanded = ImGui.TreeNodeEx(transform.Guid.ToString(), nodeFlags, transform.EntityName);
                if (!transform.IsActive)
                {
                    ImGui.PopStyleColor();
                }

                if (ImGui.IsItemClicked())
                {
                    SelectedEntityComponent = transform;
                    scrollEntitiesView      = true;
                }
                if (ImGui.BeginDragDropSource())
                {
                    ImGui.SetDragDropPayload(PAYLOAD_STRING, IntPtr.Zero, 0); // Payload is needed to trigger BeginDragDropTarget()
                    draggedObject = transform;
                    ImGui.Text(transform.EntityName);
                    ImGui.EndDragDropSource();
                }
                if (draggedObject != null && draggedObject is Transform)
                {
                    if (ImGui.BeginDragDropTarget())
                    {
                        var payload = ImGui.AcceptDragDropPayload(PAYLOAD_STRING);
                        if (payload.NativePtr != null) // Only when this is non-null does it mean that we've released the drag
                        {
                            Transform draggedTransform = draggedObject as Transform;
                            Transform newParent;
                            if (draggedTransform.Parent == transform)
                            {
                                newParent = null;
                            }
                            else
                            {
                                newParent = transform;
                            }
                            Transform.AssignParent(draggedTransform, newParent, admin, true);

                            draggedObject = null;
                        }
                        ImGui.EndDragDropTarget();
                    }
                }
                if (expanded)
                {
                    AddSceneGraphTransforms(admin, transform.Children.ToList());
                    ImGui.TreePop();
                }
            }
        }
Exemplo n.º 11
0
        public static int DragAndDropList <T>(T[] list, int draggedState, bool horizontal = false)
        {
            //draggedState = -1;
            for (var i = 0; i < list.Length; i++)
            {
                T item = list[i];
                if (item == null)
                {
                    continue;
                }

                if (i == draggedState)
                {
                    ImGui.PushStyleColor(ImGuiCol.Button, 0);
                    ImGui.PushStyleColor(ImGuiCol.Text, 0);
                }

                ImGui.PushID($"Item {i}");
                ImGui.Button(item.ToString());
                ImGui.PopID();

                if (i == draggedState)
                {
                    ImGui.PopStyleColor();
                    ImGui.PopStyleColor();
                }

                if (ImGui.BeginDragDropSource())
                {
                    draggedState = i;
                    ImGui.PushID("carrying");
                    ImGui.Text(item.ToString());
                    ImGui.PopID();

                    ImGui.SetDragDropPayload("UNUSED", IntPtr.Zero, 0);
                    ImGui.EndDragDropSource();
                }

                if (ImGui.BeginDragDropTarget())
                {
                    ImGuiPayloadPtr dataPtr = ImGui.AcceptDragDropPayload("UNUSED");
                    unsafe
                    {
                        if ((IntPtr)dataPtr.NativePtr != IntPtr.Zero && dataPtr.IsDelivery())
                        {
                            int idxDragged = draggedState;
                            (list[idxDragged], list[i]) = (list[i], list[idxDragged]);
                            draggedState = -1;
                        }
                    }

                    ImGui.EndDragDropTarget();
                }

                // Check if drag/drop ended.
                ImGuiPayloadPtr payLoad = ImGui.GetDragDropPayload();
                unsafe
                {
                    if ((IntPtr)payLoad.NativePtr == IntPtr.Zero)
                    {
                        draggedState = -1;
                    }
                }

                if (horizontal && i != list.Length - 1)
                {
                    ImGui.SameLine();
                }
            }

            return(draggedState);
        }
Exemplo n.º 12
0
        private void TextNodeDragDrop(ITextNode node)
        {
            if (node != plugin.Configuration.RootFolder && ImGui.BeginDragDropSource())
            {
                DraggedNode = node;

                ImGui.Text(node.Name);
                ImGui.SetDragDropPayload("TextNodePayload", IntPtr.Zero, 0);
                ImGui.EndDragDropSource();
            }

            if (ImGui.BeginDragDropTarget())
            {
                var payload = ImGui.AcceptDragDropPayload("TextNodePayload");

                bool nullPtr;
                unsafe { nullPtr = payload.NativePtr == null; }

                var targetNode = node;
                if (!nullPtr && payload.IsDelivery() && DraggedNode != null)
                {
                    if (plugin.Configuration.TryFindParent(DraggedNode, out var draggedNodeParent))
                    {
                        if (targetNode is TextFolderNode targetFolderNode)
                        {
                            AddTextNode.Add(new AddTextNodeOperation {
                                Node = DraggedNode, ParentNode = targetFolderNode, Index = -1
                            });
                            RemoveTextNode.Add(new RemoveTextNodeOperation {
                                Node = DraggedNode, ParentNode = draggedNodeParent
                            });
                        }
                        else
                        {
                            if (plugin.Configuration.TryFindParent(targetNode, out var targetNodeParent))
                            {
                                var targetNodeIndex = targetNodeParent.Children.IndexOf(targetNode);
                                if (targetNodeParent == draggedNodeParent)
                                {
                                    var draggedNodeIndex = targetNodeParent.Children.IndexOf(DraggedNode);
                                    if (draggedNodeIndex < targetNodeIndex)
                                    {
                                        targetNodeIndex -= 1;
                                    }
                                }
                                AddTextNode.Add(new AddTextNodeOperation {
                                    Node = DraggedNode, ParentNode = targetNodeParent, Index = targetNodeIndex
                                });
                                RemoveTextNode.Add(new RemoveTextNodeOperation {
                                    Node = DraggedNode, ParentNode = draggedNodeParent
                                });
                            }
                            else
                            {
                                throw new Exception($"Could not find parent of node \"{targetNode.Name}\"");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception($"Could not find parent of node \"{DraggedNode.Name}\"");
                    }

                    DraggedNode = null;
                }

                ImGui.EndDragDropTarget();
            }
        }
Exemplo n.º 13
0
        public void Render()
        {
            //Menu
            if (ImGui.BeginMenuBar())
            {
                if (ImGui.BeginMenu("View Setting"))
                {
                    if (ImGui.BeginMenu("Background"))
                    {
                        ImGui.Checkbox("Display", ref DrawableBackground.Display);
                        ImGui.ColorEdit3("Color Top", ref DrawableBackground.BackgroundTop);
                        ImGui.ColorEdit3("Color Bottom", ref DrawableBackground.BackgroundBottom);
                        ImGui.EndMenu();
                    }
                    if (ImGui.BeginMenu("Grid"))
                    {
                        ImGui.Checkbox("Display", ref DrawableFloor.Display);
                        ImGui.ColorEdit4("Grid Color", ref DrawableFloor.GridColor);
                        ImGui.InputInt("Grid Cell Count", ref Toolbox.Core.Runtime.GridSettings.CellAmount);
                        ImGui.InputFloat("Grid Cell Size", ref Toolbox.Core.Runtime.GridSettings.CellSize);
                        ImGui.EndMenu();
                    }

                    // ImGui.Checkbox("VSync", ref Toolbox.Core.Runtime.EnableVSync);
                    ImGui.Checkbox("Wireframe", ref Toolbox.Core.Runtime.RenderSettings.Wireframe);
                    ImGui.Checkbox("WireframeOverlay", ref Toolbox.Core.Runtime.RenderSettings.WireframeOverlay);
                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu($"Shading [{Runtime.DebugRendering}]"))
                {
                    foreach (var mode in Enum.GetValues(typeof(Runtime.DebugRender)))
                    {
                        bool isSelected = (Runtime.DebugRender)mode == Runtime.DebugRendering;
                        if (ImGui.Selectable(mode.ToString(), isSelected))
                        {
                            Runtime.DebugRendering = (Runtime.DebugRender)mode;
                        }
                        if (isSelected)
                        {
                            ImGui.SetItemDefaultFocus();
                        }
                    }
                    ImGui.EndMenu();
                }

                if (ImGui.BeginMenu("Camera"))
                {
                    if (ImGui.Button("Reset Transform"))
                    {
                        Pipeline._context.Camera.TargetPosition = new OpenTK.Vector3(0, 1, -5);
                        Pipeline._context.Camera.RotationX      = 0;
                        Pipeline._context.Camera.RotationY      = 0;
                        Pipeline._context.Camera.UpdateMatrices();
                    }
                    ImGuiHelper.InputFromBoolean("Orthographic", Pipeline._context.Camera, "IsOrthographic");

                    ImGuiHelper.InputFromFloat("Fov (Degrees)", Pipeline._context.Camera, "FovDegrees", true, 1f);
                    if (Pipeline._context.Camera.FovDegrees != 45)
                    {
                        ImGui.SameLine(); if (ImGui.Button("Reset"))
                        {
                            Pipeline._context.Camera.FovDegrees = 45;
                        }
                    }

                    ImGuiHelper.InputFromFloat("ZFar", Pipeline._context.Camera, "ZFar", true, 1f);
                    if (Pipeline._context.Camera.ZFar != 100000.0f)
                    {
                        ImGui.SameLine(); if (ImGui.Button("Reset"))
                        {
                            Pipeline._context.Camera.ZFar = 100000.0f;
                        }
                    }

                    ImGuiHelper.InputFromFloat("ZNear", Pipeline._context.Camera, "ZNear", true, 0.1f);
                    if (Pipeline._context.Camera.ZNear != 0.1f)
                    {
                        ImGui.SameLine(); if (ImGui.Button("Reset"))
                        {
                            Pipeline._context.Camera.ZNear = 0.1f;
                        }
                    }

                    ImGuiHelper.InputFromFloat("Zoom Speed", Pipeline._context.Camera, "ZoomSpeed", true, 0.1f);
                    if (Pipeline._context.Camera.ZoomSpeed != 1.0f)
                    {
                        ImGui.SameLine(); if (ImGui.Button("Reset"))
                        {
                            Pipeline._context.Camera.ZoomSpeed = 1.0f;
                        }
                    }

                    ImGuiHelper.InputFromFloat("Pan Speed", Pipeline._context.Camera, "PanSpeed", true, 0.1f);
                    if (Pipeline._context.Camera.PanSpeed != 1.0f)
                    {
                        ImGui.SameLine(); if (ImGui.Button("Reset"))
                        {
                            Pipeline._context.Camera.PanSpeed = 1.0f;
                        }
                    }

                    ImGui.EndMenu();
                }
                if (ImGui.BeginMenu("Reset Animations"))
                {
                    parentWindow.Reset();
                    ImGui.EndMenu();
                }

                ImGui.EndMenuBar();

                var menuBG = ImGui.GetStyle().Colors[(int)ImGuiCol.MenuBarBg];
                ImGui.PushStyleColor(ImGuiCol.WindowBg, menuBG);
                ImGui.PushStyleColor(ImGuiCol.ChildBg, menuBG);
                if (ImGui.BeginChild("viewport_menu2", new System.Numerics.Vector2(350, 22)))
                {
                    ImGui.AlignTextToFramePadding();
                    ImGui.Text("Active Model(s)");
                    ImGui.SameLine();
                    if (ImGui.BeginCombo("##model_select", selectedModel))
                    {
                        bool isSelected = "All Models" == selectedModel;
                        if (ImGui.Selectable("All Models", isSelected))
                        {
                            selectedModel = "All Models";
                        }
                        if (isSelected)
                        {
                            ImGui.SetItemDefaultFocus();
                        }

                        foreach (var file in Pipeline.Files)
                        {
                            string name = file.Renderer.Name;
                            isSelected = name == selectedModel;

                            if (ImGui.Selectable(name, isSelected))
                            {
                                selectedModel = name;
                            }
                            if (isSelected)
                            {
                                ImGui.SetItemDefaultFocus();
                            }
                        }
                        ImGui.EndCombo();
                    }
                }
                ImGui.EndChild();
                ImGui.PopStyleColor(2);
            }

            //Make sure the entire viewport is within a child window to have accurate mouse and window sizing relative to the space it uses.
            if (ImGui.BeginChild("viewport_child1"))
            {
                var size = ImGui.GetWindowSize();
                if (Pipeline.Width != (int)size.X || Pipeline.Height != (int)size.Y)
                {
                    Pipeline.Width  = (int)size.X;
                    Pipeline.Height = (int)size.Y;
                    Pipeline.OnResize();
                }

                Pipeline.RenderScene();

                if (ImGui.IsWindowFocused() && ImGui.IsWindowHovered() || ForceUpdate || _mouseDown)
                {
                    ForceUpdate = false;

                    if (!onEnter)
                    {
                        Pipeline.ResetPrevious();
                        onEnter = true;
                    }

                    //Only update scene when necessary
                    UpdateCamera();
                }
                else
                {
                    onEnter = false;

                    //Reset drag/dropped model data if mouse leaves the viewport during a drag event
                    if (DragDroppedModel != null)
                    {
                        DragDroppedModel.DragDroppedOnLeave();
                        DragDroppedModel = null;
                    }
                }

                var id = Pipeline.GetViewportTexture();
                ImGui.Image((IntPtr)id, size, new System.Numerics.Vector2(0, 1), new System.Numerics.Vector2(1, 0));

                if (ImGui.BeginDragDropTarget())
                {
                    ImGuiPayloadPtr outlinerDrop = ImGui.AcceptDragDropPayload("OUTLINER_ITEM",
                                                                               ImGuiDragDropFlags.AcceptNoDrawDefaultRect | ImGuiDragDropFlags.AcceptBeforeDelivery);

                    if (outlinerDrop.IsValid())
                    {
                        //Drag/drop things onto meshes
                        var mouseInfo = CreateMouseState();
                        var picked    = Pipeline.GetPickedObject(mouseInfo);
                        //Picking object changed.
                        if (DragDroppedModel != picked)
                        {
                            //Set exit drop event for previous model
                            if (DragDroppedModel != null)
                            {
                                DragDroppedModel.DragDroppedOnLeave();
                            }

                            DragDroppedModel = picked;

                            //Model has changed so call the enter event
                            if (picked != null)
                            {
                                picked.DragDroppedOnEnter();
                            }
                        }

                        if (picked != null)
                        {
                            //Set the drag/drop event
                            var node = Outliner.GetDragDropNode();
                            picked.DragDropped(node.Tag);
                        }
                    }
                    ImGui.EndDragDropTarget();
                }
            }
            ImGui.EndChild();
        }
Exemplo n.º 14
0
        unsafe private void MapObjectSelectable(Entity e, bool visicon, bool hierarchial = false)
        {
            // Main selectable
            if (e is MapEntity me)
            {
                ImGui.PushID(me.Type.ToString() + e.Name);
            }
            else
            {
                ImGui.PushID(e.Name);
            }
            bool doSelect = false;

            if (_setNextFocus)
            {
                ImGui.SetItemDefaultFocus();
                _setNextFocus = false;
                doSelect      = true;
            }
            bool   nodeopen = false;
            string padding  = hierarchial ? "   " : "    ";

            if (hierarchial && e.Children.Count > 0)
            {
                var treeflags = ImGuiTreeNodeFlags.OpenOnArrow | ImGuiTreeNodeFlags.SpanAvailWidth;
                if (_selection.GetSelection().Contains(e))
                {
                    treeflags |= ImGuiTreeNodeFlags.Selected;
                }
                nodeopen = ImGui.TreeNodeEx(e.PrettyName, treeflags);
                if (ImGui.IsItemHovered() && ImGui.IsMouseDoubleClicked(0))
                {
                    if (e.RenderSceneMesh != null)
                    {
                        _viewport.FrameBox(e.RenderSceneMesh.GetBounds());
                    }
                }
            }
            else
            {
                if (ImGui.Selectable(padding + e.PrettyName, _selection.GetSelection().Contains(e), ImGuiSelectableFlags.AllowDoubleClick | ImGuiSelectableFlags.AllowItemOverlap))
                {
                    // If double clicked frame the selection in the viewport
                    if (ImGui.IsMouseDoubleClicked(0))
                    {
                        if (e.RenderSceneMesh != null)
                        {
                            _viewport.FrameBox(e.RenderSceneMesh.GetBounds());
                        }
                    }
                }
            }
            if (ImGui.IsItemClicked(0))
            {
                _pendingClick = e;
            }

            if (_pendingClick == e && ImGui.IsMouseReleased(ImGuiMouseButton.Left))
            {
                if (ImGui.IsItemHovered())
                {
                    doSelect = true;
                }
                _pendingClick = null;
            }

            if (ImGui.IsItemFocused() && !_selection.IsSelected(e))
            {
                doSelect = true;
            }

            if (hierarchial && doSelect)
            {
                if ((nodeopen && !_treeOpenEntities.Contains(e)) ||
                    (!nodeopen && _treeOpenEntities.Contains(e)))
                {
                    doSelect = false;
                }

                if (nodeopen && !_treeOpenEntities.Contains(e))
                {
                    _treeOpenEntities.Add(e);
                }
                else if (!nodeopen && _treeOpenEntities.Contains(e))
                {
                    _treeOpenEntities.Remove(e);
                }
            }

            if (ImGui.BeginPopupContextItem())
            {
                _handler.OnEntityContextMenu(e);
                ImGui.EndPopup();
            }

            if (ImGui.BeginDragDropSource())
            {
                ImGui.Text(e.PrettyName);
                // Kinda meme
                DragDropPayload p = new DragDropPayload();
                p.Entity = e;
                _dragDropPayloads.Add(_dragDropPayloadCounter, p);
                DragDropPayloadReference r = new DragDropPayloadReference();
                r.Index = _dragDropPayloadCounter;
                _dragDropPayloadCounter++;
                GCHandle handle = GCHandle.Alloc(r, GCHandleType.Pinned);
                ImGui.SetDragDropPayload("entity", handle.AddrOfPinnedObject(), (uint)sizeof(DragDropPayloadReference));
                ImGui.EndDragDropSource();
                handle.Free();
                _initiatedDragDrop = true;
            }
            if (hierarchial && ImGui.BeginDragDropTarget())
            {
                var payload = ImGui.AcceptDragDropPayload("entity");
                if (payload.NativePtr != null)
                {
                    DragDropPayloadReference *h = (DragDropPayloadReference *)payload.Data;
                    var pload = _dragDropPayloads[h->Index];
                    _dragDropPayloads.Remove(h->Index);
                    _dragDropSources.Add(pload.Entity);
                    _dragDropDestObjects.Add(e);
                    _dragDropDests.Add(e.Children.Count);
                }
                ImGui.EndDragDropTarget();
            }

            // Visibility icon
            if (visicon)
            {
                ImGui.SetItemAllowOverlap();
                bool visible = e.EditorVisible;
                ImGui.SameLine(ImGui.GetWindowContentRegionWidth() - 18.0f);
                ImGui.PushStyleColor(ImGuiCol.Text, visible ? new Vector4(1.0f, 1.0f, 1.0f, 1.0f)
                    : new Vector4(0.6f, 0.6f, 0.6f, 1.0f));
                ImGui.TextWrapped(visible ? ForkAwesome.Eye : ForkAwesome.EyeSlash);
                ImGui.PopStyleColor();
                if (ImGui.IsItemClicked(0))
                {
                    e.EditorVisible = !e.EditorVisible;
                    doSelect        = false;
                }
            }

            // If the visibility icon wasn't clicked actually perform the selection
            if (doSelect)
            {
                if (InputTracker.GetKey(Key.ControlLeft) || InputTracker.GetKey(Key.ControlRight))
                {
                    _selection.AddSelection(e);
                }
                else
                {
                    _selection.ClearSelection();
                    _selection.AddSelection(e);
                }
            }

            ImGui.PopID();

            // Invisible item to be a drag drop target between nodes
            if (_pendingDragDrop)
            {
                if (e is MapEntity me2)
                {
                    ImGui.SetItemAllowOverlap();
                    ImGui.InvisibleButton(me2.Type.ToString() + e.Name, new Vector2(-1, 3.0f));
                }
                else
                {
                    ImGui.SetItemAllowOverlap();
                    ImGui.InvisibleButton(e.Name, new Vector2(-1, 3.0f));
                }
                if (ImGui.IsItemFocused())
                {
                    _setNextFocus = true;
                }
                if (ImGui.BeginDragDropTarget())
                {
                    var payload = ImGui.AcceptDragDropPayload("entity");
                    if (payload.NativePtr != null)
                    {
                        DragDropPayloadReference *h = (DragDropPayloadReference *)payload.Data;
                        var pload = _dragDropPayloads[h->Index];
                        _dragDropPayloads.Remove(h->Index);
                        if (hierarchial)
                        {
                            _dragDropSources.Add(pload.Entity);
                            _dragDropDestObjects.Add(e.Parent);
                            _dragDropDests.Add(e.Parent.ChildIndex(e) + 1);
                        }
                        else
                        {
                            _dragDropSources.Add(pload.Entity);
                            _dragDropDests.Add(pload.Entity.Container.Objects.IndexOf(e) + 1);
                        }
                    }
                    ImGui.EndDragDropTarget();
                }
            }

            // If there's children then draw them
            if (nodeopen)
            {
                HierarchyView(e);
                ImGui.TreePop();
            }
        }
Exemplo n.º 15
0
        private void DrawComponents(Entity context)
        {
            // TODO: fix
            bool entityEnabled = context.Enabled;

            if (ImGui.Checkbox("Enabled", ref entityEnabled))
            {
                context.Enabled = entityEnabled;
            }

            var components = context.Components;

            for (int compi = 0; compi < components.Count; compi++)
            {
                Component component = components[compi];

                Type componentType = component.GetType();

                bool stay = true;

                ImGui.PushID(componentType.Name + compi);

                bool valcol = !component.Valid;
                if (valcol)
                {
                    ImGui.PushStyleColor(ImGuiCol.Header, new Vector4(0.412f, 0.118f, 0.118f, 1.0f));
                    ImGui.PushStyleColor(ImGuiCol.HeaderHovered, new Vector4(0.729f, 0.208f, 0.208f, 1.0f));
                }

                // item shifting drop
                unsafe
                {
                    // smoll fix
                    bool resetTarget = false;
                    if (targetedComponent == component)
                    {
                        ImGui.Button("##target", new Vector2(ImGui.GetColumnWidth(), 2.5f));
                        if (ImGui.IsItemHovered())
                        {
                            resetTarget = true;
                        }
                    }

                    if (ImGui.BeginDragDropTarget())
                    {
                        var payload = ImGui.AcceptDragDropPayload("_COMPONENT");
                        if (payload.NativePtr != null && selectedDragNDropComponent != null)
                        {
                            int tci = Context.ActiveEntity.GetComponentIndex(targetedComponent);
                            if (tci > Context.ActiveEntity.GetComponentIndex(selectedDragNDropComponent))
                            {
                                tci--;
                            }
                            Context.ActiveEntity.ShiftComponent(selectedDragNDropComponent, tci);

                            selectedDragNDropComponent = null;
                            targetedComponent          = null;
                        }
                        ImGui.EndDragDropTarget();
                    }

                    if (resetTarget)
                    {
                        targetedComponent = null;
                    }
                }

                bool collapsingHeader = ImGui.CollapsingHeader(componentType.Name, ref stay);

                // item shifting drag
                {
                    if (ImGui.BeginDragDropSource())
                    {
                        ImGui.Text("Component: " + componentType.Name);
                        selectedDragNDropComponent = component;
                        ImGui.SetDragDropPayload("_COMPONENT", IntPtr.Zero, 0);
                        ImGui.EndDragDropSource();
                    }

                    if (ImGui.BeginDragDropTarget())
                    {
                        targetedComponent = component;
                        ImGui.EndDragDropTarget();
                    }
                }

                // contex menu
                {
                    if (ImGui.BeginPopupContextItem())
                    {
                        if (ImGui.MenuItem("Move Up"))
                        {
                            context.ShiftComponent(component, Math.Max(0, compi - 1));
                        }
                        if (ImGui.MenuItem("Move Down"))
                        {
                            context.ShiftComponent(component, Math.Min(components.Count - 1, compi + 1));
                        }
                        ImGui.Separator();
                        if (ImGui.MenuItem("Remove"))
                        {
                            Context.ActiveEntity.RemoveComponent(component);
                        }

                        ImGui.EndPopup();
                    }
                }

                var   style = ImGui.GetStyle();
                float collapsingHeaderButtonOffset = ((ImGui.GetTextLineHeight() + style.FramePadding.Y * 2) + 1);
                ImGui.SameLine(ImGui.GetContentRegionAvail().X - (collapsingHeaderButtonOffset * 1 + style.FramePadding.X + style.FramePadding.Y));
                bool enabled = component.Enabled;
                if (ImGui.Checkbox("##enabled", ref enabled))
                {
                    component.Enabled = enabled;
                }
                ImGui.SameLine(ImGui.GetContentRegionAvail().X - (collapsingHeaderButtonOffset * 2 + style.FramePadding.X + style.FramePadding.Y));
                if (ImGui.ArrowButton("up", ImGuiDir.Up))
                {
                    context.ShiftComponent(component, Math.Max(0, compi - 1));
                }
                ImGui.SameLine(ImGui.GetContentRegionAvail().X - (collapsingHeaderButtonOffset * 3 + style.FramePadding.X + style.FramePadding.Y));
                if (ImGui.ArrowButton("down", ImGuiDir.Down))
                {
                    context.ShiftComponent(component, Math.Min(components.Count - 1, compi + 1));
                }


                if (collapsingHeader)
                {
                    ImGuiUtils.BeginGroupFrame();

                    MemberInfo[] membs = componentType.GetMembers();

                    for (int mi = 0; mi < membs.Length; mi++)
                    {
                        var mem = membs[mi];
                        if (mem.MemberType == MemberTypes.Field || mem.MemberType == MemberTypes.Property)
                        {
                            PropertyDrawer.DrawEditorValue(mem, component);
                        }
                    }

                    //ImGui.Separator();

                    ImGuiUtils.EndGroupFrame();
                }

                if (valcol)
                {
                    ImGui.PopStyleColor(2);
                }

                ImGui.PopID();

                if (!stay)
                {
                    Context.ActiveEntity.RemoveComponent(component);
                }
            }
        }
Exemplo n.º 16
0
        private void AnimationFrameEditor(Dictionary <string, SpriteAnimationData> anims)
        {
            AnimatedSprite      currentFileContext = _currentAsset !.Content !;
            SpriteAnimationData selAnim            = anims[_selectedAnimation];

            ImGui.BeginChild("Animation", new Vector2(-1, -1), true);
            ImGui.Text("Frames: (Drag and Drop to rearrange)");

            SpriteAnimationFrameSource frameSource = currentFileContext.FrameSource;

            _draggedFrame = EditorHelpers.DragAndDropList(selAnim.FrameIndices, _draggedFrame, true);
            if (selAnim.FrameIndices.Length == 0)
            {
                EditorHelpers.ButtonSizedHole("");
            }

            ImGui.PushItemWidth(150);
            if (ImGui.InputInt("", ref _addFrameInput))
            {
                _addFrameInput = Maths.Clamp(_addFrameInput, 0, frameSource.GetFrameCount() - 1);
            }
            ImGui.SameLine();
            if (ImGui.Button("Add Frame"))
            {
                selAnim.FrameIndices = selAnim.FrameIndices.AddToArray(_addFrameInput);
                if (_addFrameInput < frameSource.GetFrameCount() - 2)
                {
                    _addFrameInput++;
                }
                _controller.Reset();
                UnsavedChanges();
            }

            ImGui.SameLine();
            ImGui.Button("Remove (Drop Here)");
            if (ImGui.BeginDragDropTarget())
            {
                ImGuiPayloadPtr dataPtr = ImGui.AcceptDragDropPayload("UNUSED");
                unsafe
                {
                    if ((IntPtr)dataPtr.NativePtr != IntPtr.Zero && dataPtr.IsDelivery())
                    {
                        int[] indices = selAnim.FrameIndices;
                        for (int i = _draggedFrame; i < indices.Length - 1; i++)
                        {
                            indices[i] = indices[i + 1];
                        }

                        Array.Resize(ref selAnim.FrameIndices, selAnim.FrameIndices.Length - 1);
                        _controller.Reset();
                        _draggedFrame = -1;
                        UnsavedChanges();
                    }
                }

                ImGui.EndDragDropTarget();
            }

            ImGui.PushItemWidth(150);
            ImGui.Text("Duration");
            ImGui.SameLine();
            if (ImGui.InputInt("###DurInput", ref selAnim.TimeBetweenFrames))
            {
                _controller.Reset();
                UnsavedChanges();
            }

            ImGui.SameLine();
            if (selAnim.FrameIndices.Length > 0)
            {
                ImGui.Text($"Total Duration: {selAnim.TimeBetweenFrames * selAnim.FrameIndices.Length}");
            }

            var loopType = (int)selAnim.LoopType;

            if (ImGui.Combo("Loop Type", ref loopType, string.Join('\0', Enum.GetNames(typeof(AnimationLoopType)))))
            {
                selAnim.LoopType = (AnimationLoopType)loopType;
                _controller.Reset();
                UnsavedChanges();
            }
        }
Exemplo n.º 17
0
        void DrawEntityNode(TreeNode <Entity> node, string id, int i = 0)
        {
            Entity nodeEntity = node.Value;


            // drag drop
            unsafe
            {
                // smoll fix
                bool resetTarget = false;
                if (targetedNode == node && targetedNode.Value != null)
                {
                    ImGui.Button("##target", new Vector2(ImGui.GetColumnWidth(), 2.5f));

                    if (ImGui.IsItemHovered())
                    {
                        resetTarget = true;
                    }
                }

                // dropped next to
                if (ImGui.BeginDragDropTarget())
                {
                    var payload = ImGui.AcceptDragDropPayload("_TREENODE<ENTITY>");
                    if (payload.NativePtr != null && selectedDragNDropNode != null)
                    {
                        EditorApplication.Log.Trace("dropped " +
                                                    $"{((selectedDragNDropNode != null && selectedDragNDropNode.Value != null) ? selectedDragNDropNode.Value.UID : "null")} before " +
                                                    $"{((targetedNode != null && nodeEntity != null) ? nodeEntity.UID : "null")}");

                        if (!targetedNode.IsParentedBy(selectedDragNDropNode))
                        {
                            if (selectedDragNDropNode.Parent != targetedNode.Parent)
                            {
                                selectedDragNDropNode.Value.Parent = targetedNode.Value.Parent;
                            }

                            int tnei = Context.Scene.GetEntityIndex(targetedNode.Value);
                            if (tnei > Context.Scene.GetEntityIndex(selectedDragNDropNode.Value))
                            {
                                tnei--;
                            }
                            Context.Scene.ShiftEntity(selectedDragNDropNode.Value, tnei);

                            int tnci = targetedNode.Parent.GetChildIndex(targetedNode);
                            if (tnci > targetedNode.Parent.GetChildIndex(selectedDragNDropNode))
                            {
                                tnci--;
                            }
                            targetedNode.Parent.ShiftChild(selectedDragNDropNode, tnci);
                        }
                        else
                        {
                            EditorApplication.Log.Trace($"drop failed (cyclic tree prevented)");
                        }

                        selectedDragNDropNode = null;
                        targetedNode          = null;
                    }
                    ImGui.EndDragDropTarget();
                }

                if (resetTarget)
                {
                    targetedNode = null;
                }
            }

            ImGuiTreeNodeFlags flags = ((nodeEntity == Context.ActiveEntity) ? ImGuiTreeNodeFlags.Selected : ImGuiTreeNodeFlags.None) |
                                       ImGuiTreeNodeFlags.OpenOnArrow |
                                       ImGuiTreeNodeFlags.OpenOnDoubleClick |
                                       ImGuiTreeNodeFlags.DefaultOpen |
                                       ((node.Children.Count <= 0) ? ImGuiTreeNodeFlags.Leaf : ImGuiTreeNodeFlags.None);

            if (nodeEntity == Context.ActiveEntity)
            {
                ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.259f, 0.588f, 0.98f, 1.0f));
            }

            string label = (Context.Scene.HierarchyRoot == node) ? "Scene" : (nodeEntity != null) ? (
                nodeEntity.TryGetComponent(out TagComponent tagcomp) ?
                tagcomp.Tag :
                "uid: " + nodeEntity.UID.ToString())
                : "";

            bool opened = ImGui.TreeNodeEx(id + i.ToString(), flags, label);

            if (nodeEntity == Context.ActiveEntity)
            {
                ImGui.PopStyleColor();
            }

            if (ImGui.IsItemClicked())
            {
                Context.ActiveEntity = nodeEntity;
            }

            // drag drop
            unsafe
            {
                if (ImGui.BeginDragDropSource())
                {
                    ImGui.Text("Entity: " + label);
                    selectedDragNDropNode = node;
                    ImGui.SetDragDropPayload("_TREENODE<ENTITY>", IntPtr.Zero, 0);
                    ImGui.EndDragDropSource();
                }

                // dropped on to
                if (ImGui.BeginDragDropTarget())
                {
                    targetedNode = node;

                    var payload = ImGui.AcceptDragDropPayload("_TREENODE<ENTITY>");
                    if (payload.NativePtr != null)
                    {
                        EditorApplication.Log.Trace("dropped " +
                                                    $"{((selectedDragNDropNode != null && selectedDragNDropNode.Value != null) ? selectedDragNDropNode.Value.UID : "null")} onto " +
                                                    $"{((node != null && nodeEntity != null) ? nodeEntity.UID : "null")}");

                        if (!node.IsParentedBy(selectedDragNDropNode))
                        {
                            selectedDragNDropNode.Value.Parent = nodeEntity;
                        }
                        else
                        {
                            EditorApplication.Log.Trace($"drop failed (cyclic tree prevented)");
                        }

                        selectedDragNDropNode = null;
                        targetedNode          = null;
                    }
                    ImGui.EndDragDropTarget();
                }
            }

            // context menu
            {
                if (ImGui.BeginPopupContextItem())
                {
                    if (ImGui.MenuItem("Add child"))
                    {
                        var newboi = Context.Scene.CreateEntity();
                        newboi.Parent = nodeEntity;
                    }
                    if (ImGui.MenuItem("Add empty child"))
                    {
                        var newboi = Context.Scene.CreateEmptyEntity();
                        newboi.Parent = nodeEntity;
                    }
                    ImGui.Separator();
                    if (ImGui.MenuItem("Remove entity", nodeEntity != null))
                    {
                        Context.Scene.DestroyEntity(nodeEntity);
                        Context.ActiveEntity = null;
                    }

                    ImGui.EndPopup();
                }
            }

            if (opened)
            {
                for (int cni = 0; cni < node.Children.Count; cni++)
                {
                    DrawEntityNode(node.Children[cni], id + "|" + i++.ToString());
                }
                ImGui.TreePop();
            }
        }