예제 #1
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();
            }
        }
예제 #2
0
        private void TextNodePopup(ITextNode node)
        {
            var style          = ImGui.GetStyle();
            var newItemSpacing = new Vector2(style.ItemSpacing.X / 2, style.ItemSpacing.Y);

            if (ImGui.BeginPopup($"{node.GetHashCode()}-popup"))
            {
                if (node is TextEntryNode entryNode)
                {
                    ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, newItemSpacing);

                    var enabled = entryNode.Enabled;
                    if (ImGui.Checkbox("Enabled", ref enabled))
                    {
                        entryNode.Enabled = enabled;
                        plugin.SaveConfiguration();
                    }

                    ImGui.SameLine(ImGui.GetContentRegionMax().X - ImGuiEx.GetIconButtonWidth(FontAwesomeIcon.TrashAlt));
                    if (ImGuiEx.IconButton(FontAwesomeIcon.TrashAlt, "Delete"))
                    {
                        if (plugin.Configuration.TryFindParent(node, out var parentNode))
                        {
                            RemoveTextNode.Add(new RemoveTextNodeOperation {
                                Node = node, ParentNode = parentNode
                            });
                        }
                    }

                    var matchText = entryNode.Text;
                    if (ImGui.InputText($"##{node.Name}-matchText", ref matchText, 100, ImGuiInputTextFlags.AutoSelectAll | ImGuiInputTextFlags.EnterReturnsTrue))
                    {
                        entryNode.Text = matchText;
                        plugin.SaveConfiguration();
                    }

                    var zoneRestricted = entryNode.ZoneRestricted;
                    if (ImGui.Checkbox("Zone Restricted", ref zoneRestricted))
                    {
                        entryNode.ZoneRestricted = zoneRestricted;
                        plugin.SaveConfiguration();
                    }

                    var searchWidth     = ImGuiEx.GetIconButtonWidth(FontAwesomeIcon.Search);
                    var searchPlusWidth = ImGuiEx.GetIconButtonWidth(FontAwesomeIcon.SearchPlus);

                    ImGui.SameLine(ImGui.GetContentRegionMax().X - searchWidth);
                    if (ImGuiEx.IconButton(FontAwesomeIcon.Search, "Zone List"))
                    {
                        IsImguiZoneListOpen = true;
                    }

                    ImGui.SameLine(ImGui.GetContentRegionMax().X - searchWidth - searchPlusWidth - newItemSpacing.X);
                    if (ImGuiEx.IconButton(FontAwesomeIcon.SearchPlus, "Fill with current zone"))
                    {
                        var currentID = plugin.Interface.ClientState.TerritoryType;
                        if (plugin.TerritoryNames.TryGetValue(currentID, out var zoneName))
                        {
                            entryNode.ZoneText = zoneName;
                        }
                        else
                        {
                            entryNode.ZoneText = "Could not find name";
                        }
                    }

                    ImGui.PopStyleVar(); // ItemSpacing

                    var zoneText = entryNode.ZoneText;
                    if (ImGui.InputText($"##{node.Name}-zoneText", ref zoneText, 100, ImGuiInputTextFlags.AutoSelectAll | ImGuiInputTextFlags.EnterReturnsTrue))
                    {
                        entryNode.ZoneText = zoneText;
                        plugin.SaveConfiguration();
                    }
                }

                if (node is TextFolderNode folderNode)
                {
                    ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, newItemSpacing);

                    if (ImGuiEx.IconButton(FontAwesomeIcon.Plus, "Add entry"))
                    {
                        var newNode = new TextEntryNode {
                            Enabled = false, Text = "Your text goes here"
                        };
                        AddTextNode.Add(new AddTextNodeOperation {
                            Node = newNode, ParentNode = folderNode, Index = -1
                        });
                    }

                    ImGui.SameLine();
                    if (ImGuiEx.IconButton(FontAwesomeIcon.SearchPlus, "Add last seen as new entry"))
                    {
                        var newNode = new TextEntryNode()
                        {
                            Enabled = true, Text = plugin.LastSeenDialogText
                        };
                        AddTextNode.Add(new AddTextNodeOperation {
                            Node = newNode, ParentNode = folderNode, Index = -1
                        });
                    }

                    ImGui.SameLine();
                    if (ImGuiEx.IconButton(FontAwesomeIcon.FolderPlus, "Add folder"))
                    {
                        var newNode = new TextFolderNode {
                            Name = "Untitled folder"
                        };
                        AddTextNode.Add(new AddTextNodeOperation {
                            Node = newNode, ParentNode = folderNode, Index = -1
                        });
                    }

                    var trashWidth = ImGuiEx.GetIconButtonWidth(FontAwesomeIcon.TrashAlt);
                    ImGui.SameLine(ImGui.GetContentRegionMax().X - trashWidth);
                    if (ImGuiEx.IconButton(FontAwesomeIcon.TrashAlt, "Delete"))
                    {
                        if (plugin.Configuration.TryFindParent(node, out var parentNode))
                        {
                            RemoveTextNode.Add(new RemoveTextNodeOperation {
                                Node = node, ParentNode = parentNode
                            });
                        }
                    }

                    ImGui.PopStyleVar(); // ItemSpacing

                    var folderName = folderNode.Name;
                    if (ImGui.InputText($"##{node.Name}-rename", ref folderName, 100, ImGuiInputTextFlags.AutoSelectAll | ImGuiInputTextFlags.EnterReturnsTrue))
                    {
                        folderNode.Name = folderName;
                        plugin.SaveConfiguration();
                    }
                }

                ImGui.EndPopup();
            }
        }