Esempio n. 1
0
        private ProfileMenuAction CreateTriggerTextWithPopupMenu(string label, Vector4 color, TriggerComposite parent)
        {
            ImGui.Text(label, color);

            if (ImGui.IsItemHovered(HoveredFlags.Default) && ImGui.IsMouseClicked(1))
            {
                ImGui.OpenPopup("Trigger Menu Context");
            }

            var selectedAction = ProfileMenuAction.None;

            if (ImGui.BeginPopup("Trigger Menu Context"))
            {
                if (ImGui.Selectable("Remove"))
                {
                    selectedAction = ProfileMenuAction.Remove;
                }
                if (ImGui.Selectable("Edit"))
                {
                    selectedAction = ProfileMenuAction.Edit;
                }
                // Only show move up/down if our parent can have more than one child
                if (parent != null && (parent.Type == TriggerType.PrioritySelector || parent.Type == TriggerType.Sequence))
                {
                    if (ImGui.Selectable("Move Up"))
                    {
                        selectedAction = ProfileMenuAction.MoveUp;
                    }
                    if (ImGui.Selectable("Move Down"))
                    {
                        selectedAction = ProfileMenuAction.MoveDown;
                    }
                }
                // TODO: Add an Add parent

                ImGui.EndPopup();
                return(selectedAction);
            }

            return(selectedAction);
        }
Esempio n. 2
0
        private ProfileMenuAction CreateTreeForComposite(TriggerComposite parent, TriggerComposite composite, int depth)
        {
            String typeTag = "";

            if (composite.Type == TriggerType.Action)
            {
                typeTag = "[A]";
            }
            else if (composite.Type == TriggerType.Decorator)
            {
                typeTag = "[D]";
            }
            else if (composite.Type == TriggerType.PrioritySelector)
            {
                typeTag = "[P]";
            }
            else if (composite.Type == TriggerType.Sequence)
            {
                typeTag = "[S]";
            }

            string label = depth + ":" + typeTag + composite.Name;

            ImGui.PushID("Composite" + depth + label);
            try
            {
                Vector4 chosenColor = GreenColor;
                if (!ValidateTree(composite, out string error))
                {
                    chosenColor = RedColor;
                }

                if (composite.Type == TriggerType.Action)
                {
                    // Push an ID so everything below remains unique
                    ImGuiNative.igIndent();

                    var profileAction = CreateTriggerTextWithPopupMenu(label, chosenColor, parent);
                    if (profileAction == ProfileMenuAction.Edit)
                    {
                        ImGui.OpenPopup(TriggerMenuLabel);
                        NewTriggerMenu = new TriggerMenu(Plugin.ExtensionParameter, parent, composite);
                    }
                    else if (profileAction != ProfileMenuAction.None)
                    {
                        // Pass it up, maybe someone above knows how to deal with it
                        return(profileAction);
                    }

                    RenderTriggerMenu();
                    ImGuiNative.igUnindent();
                }
                else if (ImGui.TreeNodeEx("", TreeNodeFlags.OpenOnArrow | TreeNodeFlags.DefaultOpen))
                {
                    ImGui.SameLine();

                    var profileAction = CreateTriggerTextWithPopupMenu(label, chosenColor, parent);
                    if (profileAction == ProfileMenuAction.Edit)
                    {
                        ImGui.OpenPopup(TriggerMenuLabel);
                        NewTriggerMenu = new TriggerMenu(Plugin.ExtensionParameter, parent, composite);
                    }
                    else if (profileAction != ProfileMenuAction.None)
                    {
                        // Pass it up, maybe someone above knows how to deal with it
                        return(profileAction);
                    }

                    // Decorators can only have one child
                    if (composite.Type != TriggerType.Decorator || (composite.Children == null || composite.Children.Count == 0))
                    {
                        if (ImGui.Button("+"))
                        {
                            ImGui.OpenPopup(TriggerMenuLabel);
                            NewTriggerMenu = new TriggerMenu(Plugin.ExtensionParameter, composite);
                        }
                        ImGuiExtension.ToolTip("Add Child");
                    }

                    if (composite.Children != null && composite.Children.Any())
                    {
                        List <TriggerComposite> childrenToRemove   = new List <TriggerComposite>();
                        List <TriggerComposite> childrenToMoveUp   = new List <TriggerComposite>();
                        List <TriggerComposite> childrenToMoveDown = new List <TriggerComposite>();
                        foreach (var child in composite.Children)
                        {
                            var childAction = CreateTreeForComposite(composite, child, depth + 1);
                            if (childAction == ProfileMenuAction.Remove)
                            {
                                childrenToRemove.Add(child);
                            }
                            else if (childAction == ProfileMenuAction.MoveUp)
                            {
                                childrenToMoveUp.Add(child);
                            }
                            else if (childAction == ProfileMenuAction.MoveDown)
                            {
                                childrenToMoveDown.Add(child);
                            }
                        }
                        // Remove all children who were requested deletion
                        childrenToRemove.ForEach(x => composite.Children.Remove(x));
                        childrenToMoveUp.ForEach(x =>
                        {
                            var index = composite.Children.IndexOf(x);
                            composite.Children.Remove(x);
                            composite.Children.Insert(Math.Max(0, index - 1), x);
                        });
                        childrenToMoveDown.ForEach(x =>
                        {
                            var index = composite.Children.IndexOf(x);
                            composite.Children.Remove(x);
                            composite.Children.Insert(index + 1, x);
                        });
                    }

                    RenderTriggerMenu();

                    ImGui.TreePop();
                }
                else
                {
                    // Tree is closed, but we still want to display the text.
                    ImGui.SameLine();
                    var profileAction = CreateTriggerTextWithPopupMenu(label, chosenColor, parent);
                    if (profileAction == ProfileMenuAction.Edit)
                    {
                        ImGui.OpenPopup(TriggerMenuLabel);
                        NewTriggerMenu = new TriggerMenu(Plugin.ExtensionParameter, parent, composite);
                    }
                    else if (profileAction != ProfileMenuAction.None)
                    {
                        // Pass it up, maybe someone above knows how to deal with it
                        return(profileAction);
                    }

                    RenderTriggerMenu();
                }
            }
            finally
            {
                // Just to make sure we pop the ID, no matter if we return early
                ImGui.PopID();
            }

            return(ProfileMenuAction.None);
        }
Esempio n. 3
0
        private ProfileMenuAction CreateTriggerTextWithPopupMenu(string label, Vector4 color, TriggerComposite parent, TriggerComposite composite)
        {
            ImGui.Text(label);

            if (ImGui.IsItemHovered(ImGuiHoveredFlags.AnyWindow) && ImGui.IsMouseClicked(1))
            {
                ImGui.OpenPopup("Trigger Menu Context");
            }

            var selectedAction = ProfileMenuAction.None;

            if (ImGui.BeginPopup("Trigger Menu Context"))
            {
                if (ImGui.Selectable("Remove"))
                {
                    selectedAction = ProfileMenuAction.Remove;
                }
                if (ImGui.Selectable("Edit"))
                {
                    selectedAction = ProfileMenuAction.Edit;
                }
                // Only show move up/down if our parent can have more than one child
                if (parent != null && (parent.Type == TriggerType.PrioritySelector || parent.Type == TriggerType.Sequence))
                {
                    if (ImGui.Selectable("Move Up"))
                    {
                        selectedAction = ProfileMenuAction.MoveUp;
                    }
                    if (ImGui.Selectable("Move Down"))
                    {
                        selectedAction = ProfileMenuAction.MoveDown;
                    }
                }

                // We can't import on decorators with 1 child or actions
                if (composite != null && composite.Type != TriggerType.Action && (composite.Type != TriggerType.Decorator || composite.Children != null && composite.Children.Count == 0))
                {
                    if (ImGui.Selectable("Import"))
                    {
                        selectedAction = ProfileMenuAction.ImportTree;
                    }
                }

                if (ImGui.Selectable("Export"))
                {
                    selectedAction = ProfileMenuAction.ExportTree;
                }

                ImGui.EndPopup();
                return(selectedAction);
            }

            return(selectedAction);
        }
Esempio n. 4
0
        private void RenderLoadProfileMenu()
        {
            bool open = true;

            if (ImGui.BeginPopupModal("Load Profile", ref open, ImGuiWindowFlags.AlwaysAutoResize))
            {
                string[] files = Directory.GetFiles(Plugin.ProfileDirectory);

                if (files.Length == 0)
                {
                    ImGui.Text($"No profiles in profile directory: {Plugin.ProfileDirectory}");
                    currentlySelectedProfile = -1;
                    LoadSaveTrigger          = null;
                    forceOpenLoad            = false;
                }
                else
                {
                    ImGui.Combo("Files", ref currentlySelectedProfile, files.Select(x => Path.GetFileName(x)).ToArray(), files.Length);
                }

                if (currentlySelectedProfile >= 0 && ImGui.Button("Load"))
                {
                    Profile.LoadedProfile loadedProfile = Plugin.LoadSettingFile <Profile.LoadedProfile>(files[currentlySelectedProfile]);
                    if (loadedProfile == null || loadedProfile.Name == null)
                    {
                        StartNewOKMenu("Profile did not load profile properly");
                    }
                    else
                    {
                        if (LoadSaveTrigger != null)
                        {
                            if (loadedProfile.Composite != null)
                            {
                                LoadSaveTrigger.Children.Add((loadedProfile.Composite));
                            }

                            LoadSaveTrigger = null;
                            forceOpenLoad   = false;
                        }
                        else
                        {
                            Plugin.Settings.LoadedProfile = loadedProfile;
                            Plugin.CreateAndStartTreeFromLoadedProfile();

                            currentlySelectedProfile = -1;
                            LoadSaveTrigger          = null;
                            forceOpenLoad            = false;
                        }

                        ImGui.CloseCurrentPopup();
                    }
                }
                // Render the menu from loading profile
                RenderOkMenu();

                if (ImGui.Button("Cancel"))
                {
                    currentlySelectedProfile = -1;
                    LoadSaveTrigger          = null;
                    forceOpenLoad            = false;

                    ImGui.CloseCurrentPopup();
                }

                ImGui.EndPopup();
            }
        }
Esempio n. 5
0
 public TriggerMenu(ExtensionParameter extensionParameter, TriggerComposite parent, TriggerComposite trigger) : this(extensionParameter, parent)
 {
     EditedTrigger    = trigger;
     TriggerComposite = new TriggerComposite(trigger);
 }