private void SymmetryMode_Clicked(UIActionGroupManager obj)
        {
            if (!obj.ActionGroup.ContainsAction(obj.Current.Action))
            {
                obj.ActionGroup.AddAction(obj.Current.Action);
            }
            else
            {
                obj.ActionGroup.RemoveAction(obj.Current.Action);
            }

            if (obj.SymmetryMode == UIActionGroupManager.SymmetryType.All)
            {
                foreach (BaseAction ba in BaseActionManager.FromParts(obj.Current.Action.listParent.part.symmetryCounterparts))
                {
                    if (ba.name == obj.Current.Action.name)
                    {
                        if (!obj.ActionGroup.ContainsAction(ba))
                        {
                            obj.ActionGroup.AddAction(ba);
                        }
                        else
                        {
                            obj.ActionGroup.RemoveAction(ba);
                        }
                    }
                }
            }

            actionGroupList.Find(
                (e) =>
            {
                return(!e.IsSymmetrySelector && !e.Isfolder && e.Events[UIActionGroupManager.EVENTNAME].active);
            }).UpdateName();
        }
Beispiel #2
0
        /// <summary>
        /// Draws internal elements in <see cref="DrawPartButtons"/>.
        /// </summary>
        private void InternaDrawPartActions()
        {
            if (this.currentSelectedPart)
            {
                GUILayout.BeginVertical(); // Begin Action List

                foreach (BaseAction action in BaseActionManager.FromParts(this.currentSelectedPart))
                {
                    GUILayout.BeginHorizontal();                        // Begin Action Controls
                    GUILayout.Space(20);
                    GUILayout.Label(action.guiName, Style.LabelExpand); // Action Name
                    GUILayout.FlexibleSpace();

                    // Add Action Group Find button
                    this.DrawFindActionGroupButton(action);

                    if (this.SelectedActionGroup.Unlocked())
                    {
                        // Action Remove Buttons
                        if (this.assignedActions.Contains(action))
                        {
                            this.DrawRemoveActionButtons(action);
                        }
                        else
                        {
                            this.DrawAddActionButtons(action);
                        }
                    }

                    GUILayout.EndHorizontal(); // End Action Row
                }

                GUILayout.EndVertical(); // End Actions List
            }
        }
        /// <summary>
        /// Draws the find action group button in the Part Scroll List.
        /// </summary>
        /// <param name="action">The action to draw the button for.</param>
        private void DrawFindActionGroupButton(BaseAction action)
        {
            if (BaseActionManager.GetActionGroupList(action).Count > 0)
            {
                foreach (KSPActionGroup group in BaseActionManager.GetActionGroupList(action))
                {
                    GUIContent      content;
                    GUILayoutOption width;
                    // Configure the button
                    if (true)//VisualUi.UiSettings.TextActionGroupButtons)
                    {
                        content = new GUIContent(
                            group.ToShortString(),
                            Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_107"), group.ToString()));
                        width = GUILayout.Width(Style.UseUnitySkin ? 30 : 20);
                    }
                    else
                    {
                        content = new GUIContent(
                            group.GetTexture(),
                            Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_107"), group.ToString()));
                        width = GUILayout.Width(20);
                    }

                    if (GUILayout.Button(
                            content,
                            Style.Button,
                            width))
                    {
                        this.SelectedActionGroup = group;
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Draws the find action group button in the Part Scroll List.
 /// </summary>
 /// <param name="action">The action to draw the button for.</param>
 private void DrawFindActionGroupButton(BaseAction action)
 {
     if (BaseActionManager.GetActionGroupList(action).Count > 0)
     {
         foreach (KSPActionGroup ag in BaseActionManager.GetActionGroupList(action))
         {
             if (GUILayout.Button(
                     new GUIContent(ag.ToShortString(), Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_107"), ag.ToString())),
                     Style.Button,
                     GUILayout.Width(Style.UseUnitySkin ? 30 : 20)))
             {
                 this.SelectedActionGroup = ag;
             }
         }
     }
 }
Beispiel #5
0
        /// <summary>
        /// Draws the add action and add symmetry actions button to the line.
        /// </summary>
        /// <param name="action">The <see cref="BaseAction"/> controlled by the buttons.</param>
        private void DrawAddActionButtons(BaseAction action)
        {
            // Single action add.
            // #autoLOC_AGM_156 = >
            // #autoLOC_AGM_110 = Add to selection.
            if (GUILayout.Button(new GUIContent(Localizer.GetStringByTag("#autoLOC_AGM_156"), Localizer.GetStringByTag("#autoLOC_AGM_110")), Style.Button, GUILayout.Width(20)))
            {
                this.modifiedActions.Add(new KeyValuePair <BaseAction, ActionModifyState>(action, ActionModifyState.Add));
            }

            // Add all symmetry parts.
            if (this.currentSelectedPart.symmetryCounterparts.Count > 0)
            {
                // #autoLOC_AGM_156 = >
                // #autoLOC_AGM_111 = Add part and all symmetry linked parts to selection.
                var content = new GUIContent(
                    Localizer.GetStringByTag("#autoLOC_AGM_156") + (this.currentSelectedPart.symmetryCounterparts.Count + 1).ToString(CultureInfo.InvariantCulture),
                    Localizer.GetStringByTag("#autoLOC_AGM_111"));

                if (GUILayout.Button(content, Style.Button, GUILayout.Width(25)))
                {
                    this.SelectedActionGroup.AddAction(action);
                    if (!this.assignedActions.Contains(action))
                    {
                        this.modifiedActions.Add(new KeyValuePair <BaseAction, ActionModifyState>(action, ActionModifyState.Add));
                    }

                    // Add all symmetrical action.
                    foreach (BaseAction symmetryAction in BaseActionManager.FromParts(this.currentSelectedPart.symmetryCounterparts))
                    {
                        if (symmetryAction.name == action.name && !this.assignedActions.Contains(symmetryAction))
                        {
                            this.modifiedActions.Add(new KeyValuePair <BaseAction, ActionModifyState>(symmetryAction, ActionModifyState.Add));
                        }
                    }
                }
            }
        }
Beispiel #6
0
        /// <summary>
        /// Draws the remove action and remove symmetry actions button to the line.
        /// </summary>
        /// <param name="action">The <see cref="BaseAction"/> controlled by the buttons.</param>
        private void DrawRemoveActionButtons(BaseAction action)
        {
            // Single action removal.
            // #autoLOC_AGM_155 = <
            // #autoLOC_AGM_108 = Remove from selection.
            if (GUILayout.Button(
                    new GUIContent(Localizer.GetStringByTag("#autoLOC_AGM_155"), Localizer.GetStringByTag("#autoLOC_AGM_108")),
                    Style.Button,
                    GUILayout.Width(20)))
            {
                this.modifiedActions.Add(new KeyValuePair <BaseAction, ActionModifyState>(action, ActionModifyState.Remove));
            }

            // All symmetrical action removal.
            if (action.listParent.part.symmetryCounterparts.Count > 0)
            {
                // #autoLOC_AGM_155 = <
                // #autoLOC_AGM_109 = Remove part and all symmetry linked parts from selection.
                var content = new GUIContent(
                    (action.listParent.part.symmetryCounterparts.Count + 1).ToString(CultureInfo.InvariantCulture) + Localizer.GetStringByTag("#autoLOC_AGM_155"),
                    Localizer.GetStringByTag("#autoLOC_AGM_109"));

                if (GUILayout.Button(content, Style.Button, GUILayout.Width(25)))
                {
                    foreach (BaseAction symmetryAction in BaseActionManager.FromParts(action.listParent.part.symmetryCounterparts))
                    {
                        if (symmetryAction.name == action.name && this.assignedActions.Contains(symmetryAction))
                        {
                            this.modifiedActions.Add(new KeyValuePair <BaseAction, ActionModifyState>(symmetryAction, ActionModifyState.Remove));
                        }
                    }

                    this.modifiedActions.Add(new KeyValuePair <BaseAction, ActionModifyState>(action, ActionModifyState.Remove));
                }
            }
        }
        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 BaseActionManager.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);
        }
Beispiel #8
0
        /// <summary>
        /// Main entry point for drawing the Reference UI view.
        /// </summary>
        /// <param name="windowId">The ID of the window.</param>
        private void DoMyReferenceView(int windowId)
        {
            ICollection <BaseAction> baseActions;

            this.scrollView = GUILayout.BeginScrollView(this.scrollView, Style.ScrollView);
            GUILayout.BeginVertical();
            int listCount = 0;

            foreach (KSPActionGroup ag in Enum.GetValues(typeof(KSPActionGroup)) as KSPActionGroup[])
            {
                if (ag != KSPActionGroup.None && ag != KSPActionGroup.REPLACEWITHDEFAULT)
                {
                    baseActions = BaseActionManager.FromParts(VesselManager.Instance.Parts, ag);
                    if (baseActions.Count > 0)
                    {
                        // Draw the Action Group name
                        listCount++; // Size for group name
                        GUILayout.Label(ag.displayDescription() + Localizer.GetStringByTag("#autoLOC_AGM_258"), Style.ScrollTextEmphasis);

                        // Build a list of actions in the action group
                        var dic = new SortedList <string, int>();
                        foreach (BaseAction action in baseActions)
                        {
                            // #autoLOC_AGM_150 = (<<1>>)
                            string str = action.listParent.part.partInfo.title + "\n" + Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_150"), action.guiName);
                            if (!dic.ContainsKey(str))
                            {
                                listCount += 2;
                                dic.Add(str, 1);
                            }
                            else
                            {
                                dic[str]++;
                            }
                        }

                        // Add the list of actions to the scroll view
                        foreach (KeyValuePair <string, int> item in dic)
                        {
                            GUILayout.BeginHorizontal();
                            GUILayout.Space(20);

                            var str = new StringBuilder(item.Key);
                            if (dic[item.Key] > 1)
                            {
                                str.Append(" * ").Append(dic[item.Key]);
                            }

                            GUILayout.Label(str.ToString(), Style.ScrollText);
                            GUILayout.EndHorizontal();
                        }
                    }
                }
            }

            //Program.AddDebugLog("Total List Line Height: " + (listCount * 27), true);
            this.referenceWindowSize.height = Math.Max(listCount * 27, 100);                  // Set the minimum size
            this.referenceWindowSize.height = Math.Min(this.referenceWindowSize.height, 500); // Set the Maximum size

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

            GUI.DragWindow();
        }