private void SymmetryMode_Clicked(UIActionGroupManager obj)
        {
            if (!obj.Current.Action.IsInActionGroup(obj.ActionGroup))
            {
                obj.Current.Action.AddActionToAnActionGroup(obj.ActionGroup);
            }
            else
            {
                obj.Current.Action.RemoveActionToAnActionGroup(obj.ActionGroup);
            }

            if (obj.SymmetryMode == UIActionGroupManager.SymmetryType.All)
            {
                foreach (BaseAction ba in BaseActionFilter.FromParts(obj.Current.Action.listParent.part.symmetryCounterparts))
                {
                    if (ba.name == obj.Current.Action.name)
                    {
                        if (!ba.IsInActionGroup(obj.ActionGroup))
                        {
                            ba.AddActionToAnActionGroup(obj.ActionGroup);
                        }
                        else
                        {
                            ba.RemoveActionToAnActionGroup(obj.ActionGroup);
                        }
                    }
                }
            }

            actionGroupList.Find(
                (e) =>
            {
                return(!e.IsSymmetrySelector && !e.Isfolder && e.Events[UIActionGroupManager.EVENTNAME].active);
            }).UpdateName();
        }
Пример #2
0
        //Draw all available action groups
        private void DrawAllUsedActionGroup()
        {
            mainWindowScroll = GUILayout.BeginScrollView(mainWindowScroll, Style.ScrollViewStyle);
            GUILayout.BeginVertical();

            foreach (KSPActionGroup ag in VesselManager.Instance.AllActionGroups)
            {
                if (ag == KSPActionGroup.None)
                {
                    continue;
                }
                OnUpdate(FilterModification.ActionGroup, ag);
                IEnumerable <BaseAction> list = BaseActionFilter.FromParts(partFilter.GetCurrentParts(), partFilter.CurrentActionGroup);

                if (list.Count() == 0)
                {
                    continue;
                }

                bool initial = currentSelectedActionGroup == ag;
                bool final   = GUILayout.Toggle(initial, ag.ToString() + " (" + list.Count() + ")", Style.ButtonToggleStyle);
                if (initial != final)
                {
                    if (final)
                    {
                        currentSelectedActionGroup = ag;
                    }
                    else
                    {
                        currentSelectedActionGroup = KSPActionGroup.None;
                    }
                }
            }

            OnUpdate(FilterModification.ActionGroup, KSPActionGroup.None);

            GUILayout.EndVertical();
            GUILayout.EndScrollView();
        }
        public UIPartManager(Part p)
        {
            this.Part             = p;
            IsActive              = false;
            IsFolderVisible       = false;
            IsActionGroupsVisible = false;
            IsSymmetryModeVisible = false;

            baseActionList  = new List <UIBaseActionManager>();
            actionGroupList = new List <UIActionGroupManager>();

            if (Part.Modules.Contains("UIBaseActionManager") || Part.Modules.Contains("UIActionGroupManager"))
            {
                //if the part already contains actionManager class, we clean them.

                List <PartModule> toRemove = new List <PartModule>();
                foreach (PartModule item in Part.Modules)
                {
                    if (item is UIBaseActionManager || item is UIActionGroupManager)
                    {
                        toRemove.Add(item);
                    }
                }

                foreach (PartModule mod in toRemove)
                {
                    Part.Modules.Remove(mod);
                }
            }


            //We create our base action list
            foreach (BaseAction ba in BaseActionFilter.FromParts(p))
            {
                //We create the module through AddModule to get the initialization done
                UIBaseActionManager man = Part.AddModule("UIBaseActionManager") as UIBaseActionManager;
                // and we remove it to avoid bloating an eventual save.
                Part.Modules.Remove(man);

                man.Action   = ba;
                man.Origin   = this;
                man.Clicked += BaseAction_Clicked;

                man.Initialize();

                baseActionList.Add(man);
            }

            // and our action group list
            //First two specific uiactionmanager as folder.
            UIActionGroupManager agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager;

            Part.Modules.Remove(agm);

            agm.Events[UIActionGroupManager.EVENTNAME].guiName = "    AGM : General";
            agm.Origin   = this;
            agm.Isfolder = true;
            agm.Type     = UIActionGroupManager.FolderType.General;
            agm.Clicked += Folder_Clicked;

            actionGroupList.Add(agm);

            agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager;
            Part.Modules.Remove(agm);

            agm.Events[UIActionGroupManager.EVENTNAME].guiName = "    AGM : Custom";
            agm.Origin   = this;
            agm.Isfolder = true;
            agm.Type     = UIActionGroupManager.FolderType.Custom;
            agm.Clicked += Folder_Clicked;

            actionGroupList.Add(agm);

            //and the rest of action groups
            foreach (KSPActionGroup ag in Enum.GetValues(typeof(KSPActionGroup)))
            {
                if (ag == KSPActionGroup.None)
                {
                    continue;
                }

                agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager;
                Part.Modules.Remove(agm);

                agm.Origin      = this;
                agm.ActionGroup = ag;
                agm.Clicked    += ActionGroup_Clicked;
                agm.Initialize();

                actionGroupList.Add(agm);
            }

            agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager;
            Part.Modules.Remove(agm);

            agm.Events[UIActionGroupManager.EVENTNAME].guiName = "        Only this part";
            agm.Origin             = this;
            agm.IsSymmetrySelector = true;
            agm.SymmetryMode       = UIActionGroupManager.SymmetryType.One;
            agm.Clicked           += SymmetryMode_Clicked;

            actionGroupList.Add(agm);

            agm = Part.AddModule("UIActionGroupManager") as UIActionGroupManager;
            Part.Modules.Remove(agm);

            agm.Events[UIActionGroupManager.EVENTNAME].guiName = "        This part and all symmetry counterparts";
            agm.Origin             = this;
            agm.IsSymmetrySelector = true;
            agm.SymmetryMode       = UIActionGroupManager.SymmetryType.All;
            agm.Clicked           += SymmetryMode_Clicked;

            actionGroupList.Add(agm);
        }
Пример #4
0
        private void DrawAllSelectedBaseAction()
        {
            secondaryWindowScroll = GUILayout.BeginScrollView(secondaryWindowScroll, Style.ScrollViewStyle);
            GUILayout.BeginVertical();
            if (currentSelectedActionGroup != KSPActionGroup.None)
            {
                OnUpdate(FilterModification.ActionGroup, currentSelectedActionGroup);

                IEnumerable <BaseAction> list = BaseActionFilter.FromParts(partFilter.GetCurrentParts(), currentSelectedActionGroup);

                Part partDrawn = null;

                bool repeat = false;
                int  index  = -1;
                do
                {
                    IEnumerable <BaseAction> temp;

                    if (SettingsManager.Settings.GetValue <bool>(SettingsManager.OrderByStage))
                    {
                        repeat = (index <= VesselManager.Instance.ActiveVessel.currentStage - 1);
                        OnUpdate(FilterModification.Stage, index);
                        temp = BaseActionFilter.FromParts(partFilter.GetCurrentParts(), currentSelectedActionGroup);

                        if (temp.Any())
                        {
                            if (index == -1)
                            {
                                GUILayout.Label("Not in active stage. ", HighLogic.Skin.label);
                            }
                            else
                            {
                                GUILayout.Label("Stage " + index.ToString(), HighLogic.Skin.label);
                            }
                        }
                    }
                    else
                    {
                        temp = list;
                    }

                    foreach (BaseAction pa in temp)
                    {
                        bool initial = false, final = false;
                        if (partDrawn != pa.listParent.part)
                        {
                            GUILayout.BeginHorizontal();
                            initial = highlighter.Contains(pa.listParent.part);
                            final   = GUILayout.Toggle(initial, "!", Style.ButtonToggleStyle, GUILayout.Width(20));
                            if (final != initial)
                            {
                                highlighter.Switch(pa.listParent.part);
                            }

                            GUILayout.Label(pa.listParent.part.partInfo.title, Style.ButtonToggleStyle);
                            partDrawn = pa.listParent.part;
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(25);
                        initial = currentSelectedBaseAction.Contains(pa);
                        final   = GUILayout.Toggle(initial, pa.guiName, Style.ButtonToggleStyle);
                        if (final != initial)
                        {
                            if (!final)
                            {
                                currentSelectedBaseAction.Remove(pa);
                            }
                            else
                            {
                                currentSelectedBaseAction.Add(pa);
                            }
                            listIsDirty = true;
                        }
                        GUILayout.Space(25);
                        GUILayout.EndHorizontal();
                    }

                    if (SettingsManager.Settings.GetValue <bool>(SettingsManager.OrderByStage))
                    {
                        index++;
                    }
                } while (repeat);

                OnUpdate(FilterModification.ActionGroup, KSPActionGroup.None);
                OnUpdate(FilterModification.Stage, int.MinValue);
            }
            else
            {
                this.currentSelectedBaseAction.Clear();
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();
        }
Пример #5
0
        //Draw all the current selected action
        private void DrawSelectedAction()
        {
            Part currentDrawn = null;

            if (currentSelectedBaseAction.Count > 0)
            {
                GUILayout.Space(HighLogic.Skin.verticalScrollbar.margin.left);
                GUILayout.BeginHorizontal();

                if (allActionGroupSelected)
                {
                    string str = confirmDelete ? "Delete all actions in " + currentSelectedActionGroup.ToString() + " OK ?" : "Remove all from group " + currentSelectedActionGroup.ToShortString();
                    if (GUILayout.Button(str, Style.ButtonToggleStyle))
                    {
                        if (!confirmDelete)
                        {
                            confirmDelete = !confirmDelete;
                        }
                        else
                        {
                            if (currentSelectedBaseAction.Count > 0)
                            {
                                foreach (BaseAction ba in currentSelectedBaseAction)
                                {
                                    ba.RemoveActionToAnActionGroup(currentSelectedActionGroup);
                                }

                                currentSelectedBaseAction.RemoveAll(
                                    (ba) =>
                                {
                                    highlighter.Remove(ba.listParent.part);
                                    return(true);
                                });
                                allActionGroupSelected = false;
                                confirmDelete          = false;
                            }
                        }
                    }
                }
                else
                {
                    GUILayout.FlexibleSpace();
                }

                if (GUILayout.Button(new GUIContent("X", "Clear the selection."), Style.ButtonToggleStyle, GUILayout.Width(Style.ButtonToggleStyle.fixedHeight)))
                {
                    currentSelectedBaseAction.Clear();
                }
                GUILayout.EndHorizontal();
            }
            foreach (BaseAction pa in currentSelectedBaseAction)
            {
                if (currentDrawn != pa.listParent.part)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(pa.listParent.part.partInfo.title, Style.ButtonToggleStyle);
                    currentDrawn = pa.listParent.part;

                    bool initial = highlighter.Contains(pa.listParent.part);
                    bool final   = GUILayout.Toggle(initial, new GUIContent("!", "Highlight the part."), Style.ButtonToggleStyle, GUILayout.Width(20));
                    if (final != initial)
                    {
                        highlighter.Switch(pa.listParent.part);
                    }

                    GUILayout.EndHorizontal();
                }
                GUILayout.BeginHorizontal();
                if (GUILayout.Button(new GUIContent("<", "Remove from selection."), Style.ButtonToggleStyle, GUILayout.Width(20)))
                {
                    currentSelectedBaseAction.Remove(pa);
                    if (allActionGroupSelected)
                    {
                        allActionGroupSelected = false;
                    }
                }

                if (pa.listParent.part.symmetryCounterparts.Count > 0)
                {
                    if (GUILayout.Button(new GUIContent("<<", "Remove part and all symmetry linked parts from selection."), Style.ButtonToggleStyle, GUILayout.Width(20)))
                    {
                        if (allActionGroupSelected)
                        {
                            allActionGroupSelected = false;
                        }

                        currentSelectedBaseAction.Remove(pa);

                        foreach (BaseAction removeAll in BaseActionFilter.FromParts(pa.listParent.part.symmetryCounterparts))
                        {
                            if (removeAll.name == pa.name && currentSelectedBaseAction.Contains(removeAll))
                            {
                                currentSelectedBaseAction.Remove(removeAll);
                            }
                        }
                        listIsDirty = true;
                    }
                }


                GUILayout.Label(pa.guiName, Style.LabelExpandStyle);

                if (GUILayout.Button(new GUIContent("F", "Find action in parts list."), Style.ButtonToggleStyle, GUILayout.Width(20)))
                {
                    currentSelectedPart = pa.listParent.part;
                }


                GUILayout.EndHorizontal();
            }
        }
Пример #6
0
        //Draw the selected part available actions in Part View
        private void DrawSelectedPartView()
        {
#if DEBUG_VERBOSE
            Debug.Log("AGM : DoMyPartView.");
#endif
            if (currentSelectedPart)
            {
                GUILayout.BeginVertical();

                List <BaseAction> current = BaseActionFilter.FromParts(currentSelectedPart).ToList();
                foreach (BaseAction ba in current)
                {
                    GUILayout.BeginHorizontal();

                    GUILayout.Space(20);

                    GUILayout.Label(ba.guiName, Style.LabelExpandStyle);

                    GUILayout.FlexibleSpace();

                    if (BaseActionFilter.GetActionGroupList(ba).Count() > 0)
                    {
                        foreach (KSPActionGroup ag in BaseActionFilter.GetActionGroupList(ba))
                        {
                            GUIContent content = new GUIContent(ag.ToShortString(), ag.ToString());

                            if (GUILayout.Button(content, Style.ButtonToggleStyle, GUILayout.Width(20)))
                            {
                                currentSelectedBaseAction  = partFilter.GetBaseActionAttachedToActionGroup(ag).ToList();
                                currentSelectedActionGroup = ag;
                                allActionGroupSelected     = true;
                            }
                        }
                    }


                    if (currentSelectedBaseAction.Contains(ba))
                    {
                        if (GUILayout.Button(new GUIContent("<", "Remove from selection."), Style.ButtonToggleStyle, GUILayout.Width(20)))
                        {
                            if (allActionGroupSelected)
                            {
                                allActionGroupSelected = false;
                            }
                            currentSelectedBaseAction.Remove(ba);
                            listIsDirty = true;
                        }

                        //Remove all symetry parts.
                        if (currentSelectedPart.symmetryCounterparts.Count > 0)
                        {
                            if (GUILayout.Button(new GUIContent("<<", "Remove part and all symmetry linked parts from selection."), Style.ButtonToggleStyle, GUILayout.Width(20)))
                            {
                                if (allActionGroupSelected)
                                {
                                    allActionGroupSelected = false;
                                }

                                currentSelectedBaseAction.Remove(ba);

                                foreach (BaseAction removeAll in BaseActionFilter.FromParts(currentSelectedPart.symmetryCounterparts))
                                {
                                    if (removeAll.name == ba.name && currentSelectedBaseAction.Contains(removeAll))
                                    {
                                        currentSelectedBaseAction.Remove(removeAll);
                                    }
                                }
                                listIsDirty = true;
                            }
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(new GUIContent(">", "Add to selection."), Style.ButtonToggleStyle, GUILayout.Width(20)))
                        {
                            if (allActionGroupSelected)
                            {
                                allActionGroupSelected = false;
                            }
                            currentSelectedBaseAction.Add(ba);
                            listIsDirty = true;
                        }

                        //Add all symetry parts.
                        if (currentSelectedPart.symmetryCounterparts.Count > 0)
                        {
                            if (GUILayout.Button(new GUIContent(">>", "Add part and all symmetry linked parts to selection."), Style.ButtonToggleStyle, GUILayout.Width(20)))
                            {
                                if (allActionGroupSelected)
                                {
                                    allActionGroupSelected = false;
                                }
                                if (!currentSelectedBaseAction.Contains(ba))
                                {
                                    currentSelectedBaseAction.Add(ba);
                                }

                                foreach (BaseAction addAll in BaseActionFilter.FromParts(currentSelectedPart.symmetryCounterparts))
                                {
                                    if (addAll.name == ba.name && !currentSelectedBaseAction.Contains(addAll))
                                    {
                                        currentSelectedBaseAction.Add(addAll);
                                    }
                                }
                                listIsDirty = true;
                            }
                        }
                    }

                    GUILayout.EndHorizontal();
                }

                GUILayout.EndVertical();
            }
        }
Пример #7
0
        private void DoMyRecapView(int id)
        {
            if (GUI.Button(new Rect(recapWindowSize.width - 24, 4, 20, 20), new GUIContent("X", "Close the window."), Style.CloseButtonStyle))
            {
                ActionGroupManager.Manager.ShowRecapWindow = false;
            }


            recapWindowScrollposition = GUILayout.BeginScrollView(recapWindowScrollposition, Style.ScrollViewStyle);
            GUILayout.BeginVertical();

            foreach (KSPActionGroup ag in VesselManager.Instance.AllActionGroups)
            {
                if (ag == KSPActionGroup.None)
                {
                    continue;
                }

                List <BaseAction> list = BaseActionFilter.FromParts(VesselManager.Instance.GetParts(), ag).ToList();

                if (list.Count > 0)
                {
                    GUILayout.Label(ag.ToString() + " :", HighLogic.Skin.label);


                    Dictionary <string, int> dic = new Dictionary <string, int>();
                    list.ForEach(
                        (e) =>
                    {
                        string str = e.listParent.part.partInfo.title + "\n(" + e.guiName + ")";
                        if (!dic.ContainsKey(str))
                        {
                            dic.Add(str, 1);
                        }

                        else
                        {
                            dic[str]++;
                        }
                    });

                    foreach (KeyValuePair <string, int> pair in dic)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(20);
                        string str = pair.Key;
                        if (pair.Value > 1)
                        {
                            str += " * " + pair.Value;
                        }
                        GUILayout.Label(str, HighLogic.Skin.label);
                        GUILayout.EndHorizontal();
                    }
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndScrollView();

            GUI.DragWindow();
        }