コード例 #1
0
        public static void AddActionToAnActionGroup(this BaseAction bA, KSPActionGroup aG)
        {
            if ((bA.actionGroup & aG) == aG)
                return;

            bA.actionGroup |= aG;
        }
コード例 #2
0
        public IEnumerable <BaseAction> GetBaseActionAttachedToActionGroup(KSPActionGroup ag)
        {
            IEnumerable <Part> parts = manager.GetParts();

            List <BaseAction> ret = new List <BaseAction>();

            foreach (Part p in parts)
            {
                foreach (BaseAction ba in p.Actions)
                {
                    if (ba.IsInActionGroup(ag))
                    {
                        ret.Add(ba);
                    }
                }
                foreach (PartModule pm in p.Modules)
                {
                    foreach (BaseAction ba in pm.Actions)
                    {
                        if (ba.IsInActionGroup(ag))
                        {
                            ret.Add(ba);
                        }
                    }
                }
            }
            return(ret);
        }
コード例 #3
0
        /// <summary>
        /// Draws a single action group button.
        /// </summary>
        /// <param name="group">The action group button to draw.</param>
        /// <param name="textOnly">True the button should contain text instead of images.</param>
        private void DrawActionGroupSelectorButton(KSPActionGroup group, bool textOnly)
        {
            List <BaseAction> actions = PartManager.GetBaseActionAttachedToActionGroup(group);
            GUIContent        content;

            // Configure the button
            if (textOnly)
            {
                content = new GUIContent(
                    group.displayDescription() + (actions.Count > 0 ? " " + Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_150"), actions.Count) : null),
                    Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_104"), group.displayDescription()));
            }
            else
            {
                content = new GUIContent(
                    actions.Count > 0 ? actions.Count.ToString(CultureInfo.InvariantCulture) : string.Empty,
                    group.GetTexture(),
                    string.Format(CultureInfo.InvariantCulture, Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_104"), group.displayDescription())));
            }

            // Create the button
            if (GUILayout.Toggle(group == this.currentSelectedActionGroup, content, textOnly ? Style.Button : Style.ButtonIcon))
            {
                this.SelectedActionGroup = group;
            }
        }
コード例 #4
0
 protected override void DrawThis()
 {
     GUILayout.BeginHorizontal();
     if (Edit)
     {
         Edit &= !GUILayout.Button(Label, Styles.active_button, GUILayout.ExpandWidth(false));
         var new_group = KSPActionGroup.None;
         scroll = GUILayout.BeginScrollView(scroll, Styles.white, GUILayout.ExpandWidth(true), GUILayout.Height(100));
         foreach (KSPActionGroup g in Enum.GetValues(typeof(KSPActionGroup)))
         {
             if (g == KSPActionGroup.None || g == KSPActionGroup.REPLACEWITHDEFAULT)
             {
                 continue;
             }
             var is_set = group_is_set(g);
             if (Utils.ButtonSwitch(g.ToString(), is_set) && !is_set)
             {
                 new_group |= g;
             }
             else if (is_set)
             {
                 new_group |= g;
             }
         }
         GUILayout.EndScrollView();
         Group = new_group;
     }
     else
     {
         Edit |= GUILayout.Button(new GUIContent(Name + ": " + Group, Label.tooltip), Styles.normal_button);
     }
     GUILayout.EndHorizontal();
 }
コード例 #5
0
        /// <summary>
        /// Called when an action group button, from the KSP GUI, is pressed.
        /// </summary>
        /// <param name="ag">The action group that was pressed.</param>
        private static void ActivateActionGroup(KSPActionGroup ag)
        {
            var satellite = RTCore.Instance.Satellites[FlightGlobals.ActiveVessel];
            if (satellite != null && satellite.FlightComputer != null)
            {
                satellite.SignalProcessor.FlightComputer.Enqueue(ActionGroupCommand.WithGroup(ag));
            }
            else if (satellite == null || (satellite != null && satellite.HasLocalControl))
            {
                if (!FlightGlobals.ready)
                    return;

                if (FlightGlobals.ActiveVessel.IsControllable)
                {
                    // check if EVA or not (as we removed the default KSP listener).
                    if(!FlightGlobals.ActiveVessel.isEVA)
                    {
                        FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(ag);
                    }
                    else // it's an EVA
                    {
                        if (ag == KSPActionGroup.RCS)
                        {
                            FlightGlobals.ActiveVessel.evaController.ToggleJetpack();
                        }
                        else if (ag == KSPActionGroup.Light)
                        {
                            FlightGlobals.ActiveVessel.evaController.ToggleLamp();
                        }
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets a collection of <see cref="BaseAction"/> assigned to a <see cref="KSPActionGroup"/>
        /// </summary>
        /// <param name="group">The <see cref="KSPActionGroup"/> to get the action assignments for.</param>
        /// <returns>A collection of <see cref="BaseAction"/> assigned to the <see cref="KSPActionGroup"/>.</returns>
        public static List <BaseAction> GetBaseActionAttachedToActionGroup(KSPActionGroup group)
        {
            var ret = new List <BaseAction>();

            foreach (Part part in VesselManager.Instance.Parts)
            {
                foreach (BaseAction action in part.Actions)
                {
                    if (group.ContainsAction(action))
                    {
                        ret.Add(action);
                    }
                }

                foreach (PartModule module in part.Modules)
                {
                    foreach (BaseAction action in module.Actions)
                    {
                        if (group.ContainsAction(action))
                        {
                            ret.Add(action);
                        }
                    }
                }
            }

            return(ret);
        }
コード例 #7
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 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;
                    }
                }
            }
        }
コード例 #8
0
        public static void RemoveActionToAnActionGroup(this BaseAction bA, KSPActionGroup aG)
        {
            if ((bA.actionGroup & aG) != aG)
                return;

            bA.actionGroup ^= aG;
        }
コード例 #9
0
        /// <summary>
        /// Draws buttons to allow the user to jump to a linked action group.
        /// </summary>
        /// <param name="part">The part to link the action group to.</param>
        private void DrawLinkedGroupButtons(Part part)
        {
            foreach (KSPActionGroup group in PartManager.GetActionGroupAttachedToPart(part))
            {
                if (group != KSPActionGroup.None && part != this.currentSelectedPart)
                {
                    GUIContent content;
                    if (true)//VisualUi.UiSettings.TextActionGroupButtons)
                    {
                        // #autoLOC_AGM_106 = Part has an action linked to action group <<1>>.
                        content = new GUIContent(group.ToShortString(), Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_106"), group.displayDescription()));
                    }
                    else
                    {
                        // #autoLOC_AGM_106 = Part has an action linked to action group <<1>>.
                        content = new GUIContent(group.GetTexture(), Localizer.Format(Localizer.GetStringByTag("#autoLOC_AGM_106"), group.displayDescription()));
                    }

                    if (GUILayout.Button(content, Style.GroupFindButton, GUILayout.Width(Style.UseUnitySkin ? 30 : 20)))
                    {
                        this.SelectedActionGroup = group;
                    }
                }
            }
        }
コード例 #10
0
 public virtual void CommandAG(KSPActionGroup ag)
 {
     if (!pilotEnabled)
     {
         return;
     }
     vessel.ActionGroups.ToggleGroup(ag);
 }
コード例 #11
0
 public static ActionGroupCommand WithGroup(KSPActionGroup group)
 {
     return(new ActionGroupCommand()
     {
         ActionGroup = group,
         TimeStamp = RTUtil.GameTime,
     });
 }
コード例 #12
0
ファイル: Wrapper.cs プロジェクト: Xaero86/KspTrigger
 public void CustomGroup(int GroupNum)
 {
     if ((GroupNum > 0) && (GroupNum <= 10))
     {
         KSPActionGroup action = (KSPActionGroup)(GroupNum + (int)KSPActionGroup.Custom01 - 1);
         _vessel.ActionGroups.SetGroup(action, true);
     }
 }
コード例 #13
0
 public static IEnumerable<BaseAction> FromParts(IEnumerable<Part> parts, KSPActionGroup ag)
 {
     return FromParts(parts).Where(
         (e) =>
         {
             return e.IsInActionGroup(ag);
         });
 }
コード例 #14
0
 public static IEnumerable <BaseAction> FromParts(IEnumerable <Part> parts, KSPActionGroup ag)
 {
     return(FromParts(parts).Where(
                (e) =>
     {
         return e.IsInActionGroup(ag);
     }));
 }
コード例 #15
0
 public static ActionGroupCommand WithGroup(KSPActionGroup group)
 {
     return new ActionGroupCommand()
     {
         ActionGroup = group,
         TimeStamp = RTUtil.GameTime,
     };
 }
コード例 #16
0
        void CommandAG(IBDAIControl wingman, int index, object ag)
        {
            //Debug.Log("object to string: "+ag.ToString());
            KSPActionGroup actionGroup = (KSPActionGroup)ag;

            //Debug.Log("ag to string: " + actionGroup.ToString());
            wingman.CommandAG(actionGroup);
        }
コード例 #17
0
        void CommandAG(BDModulePilotAI wingman, int index, object ag)
        {
            //Debug.Log("object to string: "+ag.ToString());
            KSPActionGroup actionGroup = (KSPActionGroup)ag;

            //Debug.Log("ag to string: " + actionGroup.ToString());
            wingman.CommandAG(actionGroup);
        }
コード例 #18
0
        private void PopCommand()
        {
            if (mCommandBuffer.Count > 0)
            {
                for (int i = 0; i < mCommandBuffer.Count &&
                     mCommandBuffer[i].TimeStamp < RTUtil.GetGameTime(); i++)
                {
                    DelayedCommand dc = mCommandBuffer[i];
                    if (dc.ExtraDelay > 0)
                    {
                        dc.ExtraDelay -= TimeWarp.deltaTime;
                    }
                    else
                    {
                        if (dc.ActionGroupCommand != null)
                        {
                            KSPActionGroup ag = dc.ActionGroupCommand.ActionGroup;
                            mAttachedVessel.ActionGroups.ToggleGroup(ag);
                            if (ag == KSPActionGroup.Stage && !FlightInputHandler.fetch.stageLock)
                            {
                                Staging.ActivateNextStage();
                                ResourceDisplay.Instance.Refresh();
                            }
                            if (ag == KSPActionGroup.RCS)
                            {
                                FlightInputHandler.fetch.rcslock = !FlightInputHandler.RCSLock;
                            }
                        }

                        if (dc.AttitudeCommand != null)
                        {
                            mKillrot = mAttachedVessel.transform.rotation *
                                       Quaternion.AngleAxis(90, Vector3.left);
                            mCommand = dc;
                        }

                        if (dc.BurnCommand != null)
                        {
                            mLastSpeed           = mAttachedVessel.obt_velocity.magnitude;
                            mCommand.BurnCommand = dc.BurnCommand;
                        }

                        if (dc.DriveCommand != null)
                        {
                            mRoverComputer.InitMode(dc.DriveCommand);
                            mCommand.DriveCommand = dc.DriveCommand;
                        }

                        if (dc.Event != null)
                        {
                            dc.Event.BaseEvent.Invoke();
                        }

                        mCommandBuffer.RemoveAt(i);
                    }
                }
            }
        }
コード例 #19
0
        /// <summary>
        /// Adds the <see cref="BaseAction"/> to the <see cref="KSPActionGroup"/>.
        /// </summary>
        /// <param name="group">The action group to add to.</param>
        /// <param name="action">The base action to add.</param>
        public static void AddAction(this KSPActionGroup group, BaseAction action)
        {
            if (action == null || (action.actionGroup & group) == group)
            {
                return;
            }

            action.actionGroup |= group;
        }
コード例 #20
0
ファイル: BasicCommand.cs プロジェクト: tony48/IR-Sequencer
 public BasicCommand(BasicCommand clone)
 {
     servo           = clone.servo;
     position        = clone.position;
     speedMultiplier = clone.speedMultiplier;
     wait            = clone.wait;
     waitTime        = clone.waitTime;
     ag = clone.ag;
 }
コード例 #21
0
        /// <summary>
        /// Removes the <see cref="BaseAction"/> from a <see cref="KSPActionGroup"/>.
        /// </summary>
        /// <param name="group">The action group to remove from.</param>
        /// <param name="action">The action group to remove.</param>
        public static void RemoveAction(this KSPActionGroup group, BaseAction action)
        {
            if (action == null || (action.actionGroup & group) != group)
            {
                return;
            }

            action.actionGroup ^= group;
        }
コード例 #22
0
ファイル: Ext.cs プロジェクト: xdedss/KSP_RemoteJoystick
 public static bool SetIfNot(this ActionGroupList actions, KSPActionGroup group, bool value)
 {
     if (actions.GetGroup(group) ^ value)
     {
         actions.ToggleGroup(group);
         return(true);
     }
     return(false);
 }
コード例 #23
0
        /// <summary>
        /// Get action groups buttons depending on their group.
        /// </summary>
        /// <param name="actionGroups">The action group(s) in which the buttons should be.</param>
        /// <returns>A list of action ActionGroupToggleButton buttons, filter by actionGroups paramter.</returns>
        private static List<ActionGroupToggleButton> CollectActionGroupToggleButtons(KSPActionGroup[] actionGroups)
        {
            // get all action group buttons
            ActionGroupToggleButton[] actionGroupToggleButtons = UnityEngine.Object.FindObjectsOfType<ActionGroupToggleButton>();
            // filter them to only get the buttons that have a group in the actionGroups array
            var buttons = actionGroupToggleButtons.Where(button => actionGroups.Any(ag => button.group == ag)).ToList();

            return buttons;
        }
コード例 #24
0
        public static void RemoveActionToAnActionGroup(this BaseAction bA, KSPActionGroup aG)
        {
            if ((bA.actionGroup & aG) != aG)
            {
                return;
            }

            bA.actionGroup ^= aG;
        }
コード例 #25
0
        public static void AddActionToAnActionGroup(this BaseAction bA, KSPActionGroup aG)
        {
            if ((bA.actionGroup & aG) == aG)
            {
                return;
            }

            bA.actionGroup |= aG;
        }
コード例 #26
0
        public static void LoadConfiguration()
        {
            string[] namesTmp = Enum.GetNames(typeof(KSPActionGroup));
            var      names    = new string[namesTmp.Length - 1];

            for (int i = 0; i < namesTmp.Length - 1; ++i)
            {
                names[i] = namesTmp[i];
            }
            var agTypes = new KSPActionGroup[names.Length];

            actionGroupDropDown = new GUIDropDown <KSPActionGroup> [3];

            for (int i = 0; i < agTypes.Length; i++)
            {
                agTypes[i] = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), names[i]);
            }
            // straight forward, reading the (action name, action group) tuples
            PluginConfiguration config = FARDebugAndSettings.config;

            for (int i = 0; i < ACTION_COUNT; ++i)
            {
                try
                {
                    // don't forget to initialize the gui
                    string currentGuiString = currentGuiStrings[i] = id2actionGroup[i].ToString();
                    id2actionGroup[i] =
                        (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup),
                                                   config.GetValue(configKeys[i], currentGuiString));
                    FARLogger.Info($"Loaded AG {configKeys[i]} as {currentGuiString}");
                }
                catch (Exception e)
                {
                    FARLogger.Warning("Error reading config key '" +
                                      configKeys[i] +
                                      "' with value '" +
                                      config.GetValue(configKeys[i], "n/a") +
                                      "' gave " +
                                      e);
                }

                int initIndex = 0;
                for (int j = 0; j < agTypes.Length; j++)
                {
                    if (id2actionGroup[i] != agTypes[j])
                    {
                        continue;
                    }
                    initIndex = j;
                    break;
                }

                var dropDown = new GUIDropDown <KSPActionGroup>(names, agTypes, initIndex);
                actionGroupDropDown[i] = dropDown;
            }
        }
コード例 #27
0
        public void ActionGroupFired(Vessel vessel, KSPActionGroup actionGroup, bool value)
        {
            if (LockSystem.LockQuery.UpdateLockExists(vessel.id) &&
                !LockSystem.LockQuery.UpdateLockBelongsToPlayer(vessel.id, SettingsSystem.CurrentSettings.PlayerName))
            {
                return;
            }

            System.MessageSender.SendVesselActionGroup(FlightGlobals.ActiveVessel, actionGroup, value);
        }
コード例 #28
0
 void SetAutoInitializingGroup(KSPActionGroup group, bool?activate)
 {
     if (activate.HasValue)
     {
         FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(group);
         if (activate.Value != FlightGlobals.ActiveVessel.ActionGroups[group])
         {
             FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(group);
         }
     }
 }
コード例 #29
0
 public static DelayedCommand Group(KSPActionGroup group)
 {
     return(new DelayedCommand()
     {
         ActionGroupCommand = new ActionGroupCommand()
         {
             ActionGroup = group,
         },
         TimeStamp = RTUtil.GetGameTime(),
     });
 }
コード例 #30
0
ファイル: Actions.cs プロジェクト: linuxgurugamer/SOS
 public ActionGroupInfo(Part part, BaseAction baseAction, int actionNum, PartModule partModule, int partModuleNum, KSPActionGroup actionGroup)
 {
     this.partName              = part.partInfo.name;
     this.persistentId          = part.persistentId;
     this.baseActionActionGroup = baseAction.actionGroup;
     this.actionGroupName       = baseAction.name;
     this.partModuleName        = partModule.moduleName;
     this.partModulePeristentId = partModule.PersistentId;
     this.partModuleNum         = partModuleNum;
     this.actionGroup           = actionGroup;
     this.actionNum             = actionNum;
 }
コード例 #31
0
        /// <summary>
        /// Determines if career mode is disabled or if the action group is unlocked by way of facility upgrades.
        /// </summary>
        /// <param name="group">The action group to check.</param>
        /// <returns>True if the action group is available.</returns>
        public static bool Unlocked(this KSPActionGroup group)
        {
            if (!Program.Settings.EnableCareer)
            {
                return(true);
            }

            float level = Math.Max(
                ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.SpaceplaneHangar),
                ScenarioUpgradeableFacilities.GetFacilityLevel(SpaceCenterFacility.VehicleAssemblyBuilding));

            return(level > 0.5f || (level > 0.0f && !group.ToString().Contains("Custom")));
        }
コード例 #32
0
ファイル: FlightUIPatcher.cs プロジェクト: jvdnbus/SSAT2
        /// <summary>
        /// Hook flight action group buttons: gear, brakes, light and abort buttons.
        /// </summary>
        public static void Patch()
        {
            var buttons = CollectActionGroupToggleButtons(PatchedActionGroups);

            for (int i = 0; i < buttons.Count; ++i)
            {
                //Remove default KSP listener (otherwise we can't delay anything)
                buttons[i].toggle.onToggle.RemoveListener(buttons[i].SetToggle);

                // set our hook
                KSPActionGroup actionGroup = buttons[i].group;
                buttons[i].toggle.onToggle.AddListener(() => ActivateActionGroup(actionGroup));
            }
        }
コード例 #33
0
        private void initializeGuiFields()
        {
            Fields["displayState"].guiName   = stateLabel;
            Fields["displayState"].guiActive = Fields["displayState"].guiActiveEditor = showState;

            Actions["deployAction"].guiName  = deployActionName;
            Actions["retractAction"].guiName = retractActionName;

            if (deployActionGroup != "NONE")
            {
                try
                {
                    KSPActionGroup ag = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), deployActionGroup, true);
                    Actions["deployAction"].defaultActionGroup = ag;
                }
                catch (Exception e)
                {
                    MonoBehaviour.print("ERROR PARSING ACTION GROUP FOR NAME: " + deployActionGroup + " :: " + e.Message);
                }
            }
            if (retractActionGroup != "NONE")
            {
                try
                {
                    KSPActionGroup ag = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), retractActionGroup, true);
                    Actions["retractAction"].defaultActionGroup = ag;
                }
                catch (Exception e)
                {
                    MonoBehaviour.print("ERROR PARSING ACTION GROUP FOR NAME: " + retractActionGroup + " :: " + e.Message);
                }
            }


            BaseEvent deployEvent = Events["deployEvent"];

            deployEvent.guiName            = deployActionName;
            deployEvent.externalToEVAOnly  = usableFromEVA;
            deployEvent.guiActiveUncommand = usableUncommanded;
            deployEvent.guiActiveUnfocused = usableUnfocused;
            deployEvent.unfocusedRange     = unfocusedRange;
            BaseEvent retractEvent = Events["retractEvent"];

            retractEvent.guiName            = retractActionName;
            retractEvent.externalToEVAOnly  = usableFromEVA;
            retractEvent.guiActiveUncommand = usableUncommanded;
            retractEvent.guiActiveUnfocused = usableUnfocused;
            retractEvent.unfocusedRange     = unfocusedRange;
        }
コード例 #34
0
        /// <summary>
        /// Returns a list of base actions that exist for the provided parts in the provided action group.
        /// </summary>
        /// <param name="parts">A list of part to get base actions from.</param>
        /// <param name="group">The action group to filter actions by.</param>
        /// <returns>The base actions available to the parts that are in the action group.</returns>
        public static ICollection <BaseAction> FromParts(IEnumerable <Part> parts, KSPActionGroup group)
        {
            IEnumerable <BaseAction> list = FromParts(parts);
            var ret = new List <BaseAction>();

            foreach (BaseAction action in list)
            {
                if (group.ContainsAction(action))
                {
                    ret.Add(action);
                }
            }

            return(ret);
        }
コード例 #35
0
 private static void ActivateActionGroup(KSPActionGroup ag)
 {
     var satellite = RTCore.Instance.Satellites[FlightGlobals.ActiveVessel];
     if (satellite != null && satellite.FlightComputer != null)
     {
         satellite.SignalProcessor.FlightComputer.Enqueue(ActionGroupCommand.WithGroup(ag));
     }
     else if (satellite == null || (satellite != null && satellite.HasLocalControl))
     {
         if (FlightGlobals.ActiveVessel.IsControllable)
         {
             FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(ag);
         }
     }
 }
コード例 #36
0
        private static void ActivateActionGroup(KSPActionGroup ag)
        {
            var satellite = RTCore.Instance.Satellites[FlightGlobals.ActiveVessel];

            if (satellite != null && satellite.FlightComputer != null)
            {
                satellite.SignalProcessor.FlightComputer.Enqueue(ActionGroupCommand.WithGroup(ag));
            }
            else if (satellite == null || (satellite != null && satellite.HasLocalControl))
            {
                if (FlightGlobals.ActiveVessel.IsControllable)
                {
                    FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(ag);
                }
            }
        }
コード例 #37
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;
             }
         }
     }
 }
コード例 #38
0
ファイル: Misc.cs プロジェクト: ferram4/BDArmory
        public static KeyBinding AGEnumToKeybinding(KSPActionGroup group)
        {
            string groupName = group.ToString();
            if(groupName.Contains("Custom"))
            {
                groupName = groupName.Substring(6);
                int customNumber = int.Parse(groupName);
                groupName = "CustomActionGroup" + customNumber;
            }
            else
            {
                return null;
            }

            FieldInfo field = typeof(GameSettings).GetField(groupName);
            return (KeyBinding)field.GetValue(null);
        }
コード例 #39
0
 public static extern List<BaseAction> CreateActionList(Part p, KSPActionGroup group, bool include);
コード例 #40
0
        public static void LoadConfiguration()
        {
            string[] names = Enum.GetNames(typeof(KSPActionGroup));
            KSPActionGroup[] agTypes = new KSPActionGroup[names.Length];
            actionGroupDropDown = new GUIDropDown<KSPActionGroup>[3];

            for(int i = 0; i < agTypes.Length; i++)
            {
                agTypes[i] = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), names[i]);
            }

            // straight forward, reading the (action name, action group) tuples
            KSP.IO.PluginConfiguration config = FARDebugAndSettings.config;
            for (int i = 0; i < ACTION_COUNT; ++i)
            {
                try
                {
                    id2actionGroup[i] = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), config.GetValue(configKeys[i], id2actionGroup[i].ToString())); ;
                    currentGuiStrings[i] = id2actionGroup[i].ToString(); // don't forget to initialize the gui
                    Debug.Log(String.Format("FAR: loaded AG {0} as {1}", configKeys[i], id2actionGroup[i]));
                }
                catch (Exception e)
                {
                    Debug.LogWarning("FAR: error reading config key '" + configKeys[i] + "' with value '" + config.GetValue(configKeys[i], "n/a") + "' gave " + e.ToString());
                }
                int initIndex = 0;
                for(int j = 0; j < agTypes.Length; j++)
                {
                    if(id2actionGroup[i] == agTypes[j])
                    {
                        initIndex = j;
                        break;
                    }
                }
                GUIDropDown<KSPActionGroup> dropDown = new GUIDropDown<KSPActionGroup>(names, agTypes, initIndex);
                actionGroupDropDown[i] = dropDown;
            }
        }
コード例 #41
0
        public void Start()
        {
            switch (groupName)
            {
                case "Gear":
                    actionGroup = KSPActionGroup.Gear;
                    break;
                case "Brakes":
                    actionGroup = KSPActionGroup.Brakes;
                    break;
                case "Light":
                    actionGroup = KSPActionGroup.Light;
                    break;
                case "RCS":
                    actionGroup = KSPActionGroup.RCS;
                    break;
                case "SAS":
                    actionGroup = KSPActionGroup.SAS;
                    break;
                case "Stage":
                    customAction = true;
                    //actionGroup = KSPActionGroup.Stage;
                    break;
                case "Abort":
                    actionGroup = KSPActionGroup.Abort;
                    break;
                case "Custom01":
                    actionGroup = KSPActionGroup.Custom01;
                    break;
                case "Custom02":
                    actionGroup = KSPActionGroup.Custom02;
                    break;
                case "Custom03":
                    actionGroup = KSPActionGroup.Custom03;
                    break;
                case "Custom04":
                    actionGroup = KSPActionGroup.Custom04;
                    break;
                case "Custom05":
                    actionGroup = KSPActionGroup.Custom05;
                    break;
                case "Custom06":
                    actionGroup = KSPActionGroup.Custom06;
                    break;
                case "Custom07":
                    actionGroup = KSPActionGroup.Custom07;
                    break;
                case "Custom08":
                    actionGroup = KSPActionGroup.Custom08;
                    break;
                case "Custom09":
                    actionGroup = KSPActionGroup.Custom09;
                    break;
                case "Custom10":
                    actionGroup = KSPActionGroup.Custom10;
                    break;
                default:
                    customAction = true;
                    break;
            }
            actionGroupNumber = BaseAction.GetGroupIndex(actionGroup);
            switchObjectTransform = base.internalProp.FindModelTransform(switchObjectName);

            buttonObject = base.internalProp.FindModelTransform(buttonTrigger).gameObject;
            buttonHandler = buttonObject.AddComponent<FSgenericButtonHandler>();
            buttonHandler.mouseDownFunction = buttonClick;
            //buttonObject.AddComponent<FSswitchButtonHandler>();
            //buttonObject.GetComponent<FSswitchButtonHandler>().buttonNumber = 1;
            //buttonObject.GetComponent<FSswitchButtonHandler>().target = base.internalProp.gameObject;

            try
            {
                switchTypeEnum = (SwitchType) Enum.Parse(typeof(SwitchType), switchType, true);
            }
            catch
            {
                switchTypeEnum = SwitchType.undefined;
            }
        }
コード例 #42
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsEditor)
            {
                return;
            }

            try
            {
                RPMVesselComputer comp = RPMVesselComputer.Instance(vessel);

                if (!groupList.ContainsKey(actionName) && !customGroupList.ContainsKey(actionName))
                {
                    JUtil.LogErrorMessage(this, "Action \"{0}\" is not supported.", actionName);
                    return;
                }

                // Parse the needs-electric-charge here.
                if (!string.IsNullOrEmpty(needsElectricCharge))
                {
                    switch (needsElectricCharge.ToLowerInvariant().Trim())
                    {
                        case "true":
                        case "yes":
                        case "1":
                            needsElectricChargeValue = true;
                            break;
                        case "false":
                        case "no":
                        case "0":
                            needsElectricChargeValue = false;
                            break;
                    }
                }

                // Now parse consumeOnToggle and consumeWhileActive...
                if (!string.IsNullOrEmpty(consumeOnToggle))
                {
                    string[] tokens = consumeOnToggle.Split(',');
                    if (tokens.Length == 3)
                    {
                        consumeOnToggleName = tokens[0].Trim();
                        if (!(PartResourceLibrary.Instance.GetDefinition(consumeOnToggleName) != null &&
                           float.TryParse(tokens[1].Trim(), NumberStyles.Any, CultureInfo.InvariantCulture,
                               out consumeOnToggleAmount)))
                        {
                            JUtil.LogErrorMessage(this, "Could not parse \"{0}\"", consumeOnToggle);
                        }
                        switch (tokens[2].Trim().ToLower())
                        {
                            case "on":
                                consumingOnToggleUp = true;
                                break;
                            case "off":
                                consumingOnToggleDown = true;
                                break;
                            case "both":
                                consumingOnToggleUp = true;
                                consumingOnToggleDown = true;
                                break;
                            default:
                                JUtil.LogErrorMessage(this, "So should I consume resources when turning on, turning off, or both in \"{0}\"?", consumeOnToggle);
                                break;
                        }
                    }
                }

                if (!string.IsNullOrEmpty(consumeWhileActive))
                {
                    string[] tokens = consumeWhileActive.Split(',');
                    if (tokens.Length == 2)
                    {
                        consumeWhileActiveName = tokens[0].Trim();
                        if (!(PartResourceLibrary.Instance.GetDefinition(consumeWhileActiveName) != null &&
                           float.TryParse(tokens[1].Trim(),
                               NumberStyles.Any, CultureInfo.InvariantCulture,
                               out consumeWhileActiveAmount)))
                        {
                            JUtil.LogErrorMessage(this, "Could not parse \"{0}\"", consumeWhileActive);
                        }
                        else
                        {
                            consumingWhileActive = true;
                            JUtil.LogMessage(this, "Switch in prop {0} prop id {1} will consume {2} while active at a rate of {3}", internalProp.propName,
                                internalProp.propID, consumeWhileActiveName, consumeWhileActiveAmount);
                        }
                    }
                }

                if (groupList.ContainsKey(actionName))
                {
                    kspAction = groupList[actionName];
                    currentState = vessel.ActionGroups[kspAction];
                    // action group switches may not belong to a radio group
                    switchGroupIdentifier = -1;
                }
                else
                {
                    isCustomAction = true;
                    switch (actionName)
                    {
                        case "intlight":
                            persistentVarName = internalLightName;
                            lightObjects = internalModel.FindModelComponents<Light>();
                            needsElectricChargeValue |= string.IsNullOrEmpty(needsElectricCharge) || needsElectricChargeValue;
                            break;
                        case "plugin":
                            persistentVarName = string.Empty;
                            comp.UpdateDataRefreshRate(refreshRate);

                            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP"))
                            {
                                if (node.GetValue("name") == internalProp.propName)
                                {
                                    foreach (ConfigNode pluginConfig in node.GetNodes("MODULE")[moduleID].GetNodes("PLUGINACTION"))
                                    {
                                        if (pluginConfig.HasValue("name") && pluginConfig.HasValue("actionMethod"))
                                        {
                                            string action = pluginConfig.GetValue("name").Trim() + ":" + pluginConfig.GetValue("actionMethod").Trim();
                                            actionHandler = (Action<bool>)comp.GetMethod(action, internalProp, typeof(Action<bool>));

                                            if (actionHandler == null)
                                            {
                                                JUtil.LogErrorMessage(this, "Failed to instantiate action handler {0}", action);
                                            }
                                            else
                                            {
                                                if (pluginConfig.HasValue("stateMethod"))
                                                {
                                                    string state = pluginConfig.GetValue("name").Trim() + ":" + pluginConfig.GetValue("stateMethod").Trim();
                                                    stateVariable = "PLUGIN_" + state;
                                                }
                                                else if(pluginConfig.HasValue("stateVariable"))
                                                {
                                                    stateVariable = pluginConfig.GetValue("stateVariable").Trim();
                                                }
                                                isPluginAction = true;
                                                break;
                                            }
                                        }
                                    }
                                }
                            }
                            if (actionHandler == null)
                            {
                                actionName = "dummy";
                                JUtil.LogMessage(this, "Plugin handlers did not start, reverting to dummy mode.");
                            }
                            break;
                        case "transfer":
                            persistentVarName = string.Empty;
                            comp.UpdateDataRefreshRate(refreshRate);

                            foreach (ConfigNode node in GameDatabase.Instance.GetConfigNodes("PROP"))
                            {
                                if (node.GetValue("name") == internalProp.propName)
                                {
                                    foreach (ConfigNode pluginConfig in node.GetNodes("MODULE")[moduleID].GetNodes("TRANSFERACTION"))
                                    {
                                        if (pluginConfig.HasValue("name") && pluginConfig.HasValue("perPodPersistenceName"))
                                        {
                                            transferPersistentName = pluginConfig.GetValue("perPodPersistenceName").Trim();
                                            if (pluginConfig.HasValue("stateMethod"))
                                            {
                                                string state = pluginConfig.GetValue("name").Trim() + ":" + pluginConfig.GetValue("stateMethod").Trim();
                                                stateVariable = "PLUGIN_" + state;
                                            }
                                            else if (pluginConfig.HasValue("stateVariable"))
                                            {
                                                stateVariable = pluginConfig.GetValue("stateVariable").Trim();
                                            }
                                            if (pluginConfig.HasValue("setMethod"))
                                            {
                                                string action = pluginConfig.GetValue("name").Trim() + ":" + pluginConfig.GetValue("setMethod").Trim();
                                                transferSetter = (Action<double>)comp.GetMethod(action, internalProp, typeof(Action<double>));

                                                if (transferSetter == null)
                                                {
                                                    JUtil.LogErrorMessage(this, "Failed to instantiate transfer handler {0}", pluginConfig.GetValue("name"));
                                                }
                                                else
                                                {
                                                    //JUtil.LogMessage(this, "Got setter {0}", action);
                                                    break;
                                                }
                                            }
                                            else if (pluginConfig.HasValue("getMethod"))
                                            {
                                                string action = pluginConfig.GetValue("name").Trim() + ":" + pluginConfig.GetValue("getMethod").Trim();
                                                transferGetter = (Func<double>)comp.GetMethod(action, internalProp, typeof(Func<double>));

                                                if (transferGetter == null)
                                                {
                                                    JUtil.LogErrorMessage(this, "Failed to instantiate transfer handler {0}", pluginConfig.GetValue("name"));
                                                }
                                                else
                                                {
                                                    //JUtil.LogMessage(this, "Got getter {0}", action);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            if (transferGetter == null && transferSetter == null)
                            {
                                actionName = "dummy";
                                stateVariable = string.Empty;
                                JUtil.LogMessage(this, "Transfer handlers did not start, reverting to dummy mode.");
                            }
                            break;
                        default:
                            persistentVarName = "switch" + internalProp.propID + "_" + moduleID;
                            break;
                    }
                    if (!string.IsNullOrEmpty(perPodPersistenceName))
                    {
                        persistentVarName = perPodPersistenceName;
                    }
                    else
                    {
                        // If there's no persistence name, there's no valid group id for this switch
                        switchGroupIdentifier = -1;
                    }
                }

                if (customGroupList.ContainsKey(actionName))
                {
                    customAction = customGroupList[actionName];
                }

                if (needsElectricChargeValue || !string.IsNullOrEmpty(persistentVarName) || !string.IsNullOrEmpty(perPodMasterSwitchName) || !string.IsNullOrEmpty(masterVariableName) ||
                    transferGetter != null || transferSetter != null)
                {
                    rpmComp = RasterPropMonitorComputer.Instantiate(internalProp);

                    comp.UpdateDataRefreshRate(refreshRate);

                    if (!string.IsNullOrEmpty(masterVariableName))
                    {
                        string[] range = masterVariableRange.Split(',');
                        if (range.Length == 2)
                        {
                            masterVariable = new VariableOrNumberRange(masterVariableName, range[0], range[1]);
                        }
                        else
                        {
                            masterVariable = null;
                        }
                    }
                }

                // set up the toggle switch
                if (!string.IsNullOrEmpty(switchTransform))
                {
                    SmarterButton.CreateButton(internalProp, switchTransform, Click);
                }

                if (isCustomAction)
                {
                    if (isPluginAction && !string.IsNullOrEmpty(stateVariable))
                    {
                        try
                        {
                            currentState = ((int)comp.ProcessVariable(stateVariable, -1)) > 0;
                        }
                        catch
                        {
                            // no-op
                        }
                    }
                    else
                    {
                        if (rpmComp != null && !string.IsNullOrEmpty(persistentVarName))
                        {
                            if (switchGroupIdentifier >= 0)
                            {
                                int activeSwitch = rpmComp.GetVar(persistentVarName, 0);

                                currentState = customGroupState = (switchGroupIdentifier == activeSwitch);
                            }
                            else
                            {
                                currentState = customGroupState = rpmComp.GetBool(persistentVarName, initialState);
                            }

                            if (customAction == CustomActions.IntLight)
                            {
                                // We have to restore lighting after reading the
                                // persistent variable.
                                SetInternalLights(customGroupState);
                            }
                        }
                    }
                }

                if (rpmComp != null && !rpmComp.HasVar(persistentVarName))
                {
                    if (switchGroupIdentifier >= 0)
                    {
                        if (currentState)
                        {
                            rpmComp.SetVar(persistentVarName, switchGroupIdentifier);
                        }
                    }
                    else
                    {
                        rpmComp.SetVar(persistentVarName, currentState);
                    }
                }

                if (!string.IsNullOrEmpty(animationName))
                {
                    // Set up the animation
                    Animation[] animators = animateExterior ? part.FindModelAnimators(animationName) : internalProp.FindModelAnimators(animationName);
                    if (animators.Length > 0)
                    {
                        anim = animators[0];
                    }
                    else
                    {
                        JUtil.LogErrorMessage(this, "Could not find animation \"{0}\" on {2} \"{1}\"",
                            animationName, animateExterior ? part.name : internalProp.name, animateExterior ? "part" : "prop");
                        return;
                    }
                    anim[animationName].wrapMode = WrapMode.Once;

                    if (currentState ^ reverse)
                    {
                        anim[animationName].speed = float.MaxValue;
                        anim[animationName].normalizedTime = 0;

                    }
                    else
                    {
                        anim[animationName].speed = float.MinValue;
                        anim[animationName].normalizedTime = 1;
                    }
                    anim.Play(animationName);
                }
                else if (!string.IsNullOrEmpty(coloredObject))
                {
                    // Set up the color shift.
                    colorShiftRenderer = internalProp.FindModelComponent<Renderer>(coloredObject);
                    disabledColorValue = ConfigNode.ParseColor32(disabledColor);
                    enabledColorValue = ConfigNode.ParseColor32(enabledColor);
                    colorShiftRenderer.material.SetColor(colorName, (currentState ^ reverse ? enabledColorValue : disabledColorValue));
                }
                else
                {
                    JUtil.LogMessage(this, "Warning, neither color nor animation are defined in prop {0} #{1} (this may be okay).", internalProp.propName, internalProp.propID);
                }

                audioOutput = JUtil.SetupIVASound(internalProp, switchSound, switchSoundVolume, false);

                startupComplete = true;
            }
            catch
            {
                JUtil.AnnoyUser(this);
                enabled = false;
                throw;
            }
        }
コード例 #43
0
ファイル: RemoteCore.cs プロジェクト: JDPKSP/RemoteTechLegacy
        void applyTrigger(KSPActionGroup ActionGroup)
        {
            if (ActionGroup == KSPActionGroup.Stage)
            {
                if (RTUtils.PhysicsActive && !DockingMode)
                {
                    Staging.ActivateNextStage();
                    vessel.ActionGroups.ToggleGroup(ActionGroup);
                }
            }
            else if (ActionGroup == KSPActionGroup.RCS)
            {
                RCSoverride = !RCSoverride;
                vessel.ActionGroups.SetGroup(KSPActionGroup.RCS, RCSoverride);
            }
            else
            {
                vessel.ActionGroups.ToggleGroup(ActionGroup);

                if (ActionGroup == KSPActionGroup.Gear)
                {
                    foreach (HLandingLeg l in vessel.parts.OfType<HLandingLeg>())
                    {
                        if (vessel.ActionGroups[KSPActionGroup.Gear])
                            l.RaiseAction(new KSPActionParam(KSPActionGroup.Gear, KSPActionType.Activate));
                        else
                            l.LowerAction(new KSPActionParam(KSPActionGroup.Gear, KSPActionType.Activate));
                    }
                }
            }

            if (FlightInputHandler.fetch.rcslock != RCSoverride)
                FlightInputHandler.fetch.rcslock = RCSoverride;
        }
コード例 #44
0
ファイル: Flight.cs プロジェクト: CameronHunt5812/AGExt
        public void GroupsWindow(int WindowID)
        {
            GUI.skin.scrollView.normal.background = null;
            AGXBtnStyle.alignment = TextAnchor.MiddleCenter;
            //AGXScrollStyle.normal.background = null;
            if (AutoHideGroupsWin)
            {
                //GUI.DrawTexture(new Rect(6, 4, 78, 18), BtnTexRed);
                AGXBtnStyle.normal.background = ButtonTextureRed;
                AGXBtnStyle.hover.background = ButtonTextureRed;
            }
            //if (GUI.Button(new Rect(15, 3, 65, 20), "Auto-Hide", AGXBtnStyle))
            //{
            //    AutoHideGroupsWin = !AutoHideGroupsWin;

            //}
            AGXBtnStyle.normal.background = ButtonTexture;
            AGXBtnStyle.hover.background = ButtonTexture;
            bool[] PageGrn = new bool[5];
            foreach (AGXAction AGact in StaticData.CurrentVesselActions)
            {
                if (AGact.group <= 50)
                {
                    PageGrn[0] = true;
                }
                if (AGact.group >= 51 && AGact.group <= 100)
                {
                    PageGrn[1] = true;
                }
                if (AGact.group >= 101 && AGact.group <= 150)
                {
                    PageGrn[2] = true;
                }
                if (AGact.group >= 151 && AGact.group <= 200)
                {
                    PageGrn[3] = true;
                }
                if (AGact.group >= 201 && AGact.group <= 250)
                {
                    PageGrn[4] = true;
                }
            }
            if (showCareerCustomAGs)
            {
                if (GUI.Button(new Rect(80, 3, 40, 20), "Other", AGXBtnStyle))
                {
                    defaultShowingNonNumeric = !defaultShowingNonNumeric;
                    if (defaultShowingNonNumeric)
                    {
                        defaultActionsListAll.Clear();
                        {
                            foreach (Part p in FlightGlobals.ActiveVessel.parts)
                            {
                                defaultActionsListAll.AddRange(p.Actions);
                                foreach (PartModule pm in p.Modules)
                                {
                                    defaultActionsListAll.AddRange(pm.Actions);
                                }
                            }
                        }
                        RefreshDefaultActionsListType();
                    }
                }
            }
            // for (int i = 1; i <= 5; i = i + 1)
            //   {
            // if (PageGrn[i - 1] == true && GroupsPage != i)
            // {
            //    GUI.DrawTexture(new Rect(96 + (i * 25), 4, 23, 18), BtnTexGrn);
            // }
            // }
            //GUI.DrawTexture(new Rect(96 + (GroupsPage * 25), 4, 23, 18), BtnTexRed);
            // bool[5] PageBtnGrn = new bool[]();
            if (PageGrn[0]) AGXBtnStyle.normal.background = ButtonTextureGreen;
            if (PageGrn[0]) AGXBtnStyle.hover.background = ButtonTextureGreen;
            if (GroupsPage == 1) AGXBtnStyle.normal.background = ButtonTextureRed;
            if (GroupsPage == 1) AGXBtnStyle.hover.background = ButtonTextureRed;
            if (GUI.Button(new Rect(120, 3, 25, 20), "1", AGXBtnStyle))
            {
                defaultShowingNonNumeric = false;
                GroupsPage = 1;
            }
            AGXBtnStyle.normal.background = ButtonTexture;
            AGXBtnStyle.hover.background = ButtonTexture;
            if (PageGrn[1]) AGXBtnStyle.normal.background = ButtonTextureGreen;
            if (PageGrn[1]) AGXBtnStyle.hover.background = ButtonTextureGreen;
            if (GroupsPage == 2) AGXBtnStyle.normal.background = ButtonTextureRed;
            if (GroupsPage == 2) AGXBtnStyle.hover.background = ButtonTextureRed;
            if (GUI.Button(new Rect(145, 3, 25, 20), "2", AGXBtnStyle))
            {
                defaultShowingNonNumeric = false;
                GroupsPage = 2;
            }
            AGXBtnStyle.normal.background = ButtonTexture;
            AGXBtnStyle.hover.background = ButtonTexture;
            if (PageGrn[2]) AGXBtnStyle.normal.background = ButtonTextureGreen;
            if (PageGrn[2]) AGXBtnStyle.hover.background = ButtonTextureGreen;
            if (GroupsPage == 3) AGXBtnStyle.normal.background = ButtonTextureRed;
            if (GroupsPage == 3) AGXBtnStyle.hover.background = ButtonTextureRed;
            if (GUI.Button(new Rect(170, 3, 25, 20), "3", AGXBtnStyle))
            {
                defaultShowingNonNumeric = false;
                GroupsPage = 3;
            }
            AGXBtnStyle.normal.background = ButtonTexture;
            AGXBtnStyle.hover.background = ButtonTexture;
            if (PageGrn[3]) AGXBtnStyle.normal.background = ButtonTextureGreen;
            if (PageGrn[3]) AGXBtnStyle.normal.background = ButtonTextureGreen;
            if (GroupsPage == 4) AGXBtnStyle.normal.background = ButtonTextureRed;
            if (GroupsPage == 4) AGXBtnStyle.hover.background = ButtonTextureRed;
            if (GUI.Button(new Rect(195, 3, 25, 20), "4", AGXBtnStyle))
            {
                defaultShowingNonNumeric = false;
                GroupsPage = 4;
            }
            AGXBtnStyle.normal.background = ButtonTexture;
            AGXBtnStyle.hover.background = ButtonTexture;
            if (PageGrn[4]) AGXBtnStyle.normal.background = ButtonTextureGreen;
            if (PageGrn[4]) AGXBtnStyle.normal.background = ButtonTextureGreen;
            if (GroupsPage == 5) AGXBtnStyle.normal.background = ButtonTextureRed;
            if (GroupsPage == 5) AGXBtnStyle.hover.background = ButtonTextureRed;
            if (GUI.Button(new Rect(220, 3, 25, 20), "5", AGXBtnStyle))
            {
                defaultShowingNonNumeric = false;
                GroupsPage = 5;
            }
            AGXBtnStyle.normal.background = ButtonTexture;
            AGXBtnStyle.hover.background = ButtonTexture;
            if (showAllPartsList) //show all parts list is clicked so change to that mode
            {
                ScrollGroups = GUI.BeginScrollView(new Rect(5, 25, 240, 500), ScrollGroups, new Rect(0, 0, 240, Mathf.Max(500, showAllPartsListTitles.Count * 20))); //scroll view just in case there are a lot of parts to list
                int listCount = 1; //track which button we are on in list
                while (listCount <= showAllPartsListTitles.Count) //procedurally generate buttons
                {
                    if (GUI.Button(new Rect(0, (listCount - 1) * 20, 240, 20), showAllPartsListTitles.ElementAt(listCount - 1), AGXBtnStyle)) //button code
                    {
                        string partNameToSelect = showAllPartsListTitles.ElementAt(listCount - 1); //title of part clicked on as string, not a Part object
                        AGEditorSelectedParts.Clear(); //selected parts list should be clear if we are in this mode, but check anyways
                        foreach (Part p in FlightGlobals.ActiveVessel.parts) //add all Parts with matching title to selected parts list, converting from string to Part
                        {
                            if (p.partInfo.title == partNameToSelect)
                            {
                                AGEditorSelectedParts.Add(new AGXPart(p));
                            }
                        }
                        //AGEditorSelectedParts.RemoveAll(p2 => p2.AGPart.name != AGEditorSelectedParts.First().AGPart.name); //error trap just incase two parts have the same title, they can't have the same name
                        PartActionsList.Clear(); //populate actions list from selected parts
                        PartActionsList.AddRange(AGEditorSelectedParts.First().AGPart.Actions.Where(ba => ba.active == true));
                        foreach (PartModule pm in AGEditorSelectedParts.First().AGPart.Modules)
                        {
                            PartActionsList.AddRange(pm.Actions.Where(ba => ba.active == true));
                        }
                        //ScrollGroups = Vector2.zero;
                        showAllPartsList = false; //exit show all parts mode
                        TempShowGroupsWin = false; //hide window if auto hide enabled
                        AGEEditorSelectedPartsSame = true; //all selected parts are the same type as per the check above
                    }

                    listCount = listCount + 1; //moving to next button
                }

                GUI.EndScrollView();
            }
            else if (defaultShowingNonNumeric)
            {
                if (defaultGroupToShow == KSPActionGroup.Abort)
                {
                    AGXBtnStyle.normal.background = ButtonTextureGreen;
                    AGXBtnStyle.hover.background = ButtonTextureGreen;
                }
                else
                {
                    AGXBtnStyle.normal.background = ButtonTexture;
                    AGXBtnStyle.hover.background = ButtonTexture;
                }
                if (GUI.Button(new Rect(5, 25, 58, 20), "Abort", AGXBtnStyle)) //button code
                {
                    defaultGroupToShow = KSPActionGroup.Abort;
                    RefreshDefaultActionsListType();
                }
                if (defaultGroupToShow == KSPActionGroup.Brakes)
                {
                    AGXBtnStyle.normal.background = ButtonTextureGreen;
                    AGXBtnStyle.hover.background = ButtonTextureGreen;
                }
                else
                {
                    AGXBtnStyle.normal.background = ButtonTexture;
                    AGXBtnStyle.hover.background = ButtonTexture;
                }
                if (GUI.Button(new Rect(64, 25, 58, 20), "Brakes", AGXBtnStyle)) //button code
                {
                    defaultGroupToShow = KSPActionGroup.Brakes;
                    RefreshDefaultActionsListType();
                }
                if (defaultGroupToShow == KSPActionGroup.Gear)
                {
                    AGXBtnStyle.normal.background = ButtonTextureGreen;
                    AGXBtnStyle.hover.background = ButtonTextureGreen;
                }
                else
                {
                    AGXBtnStyle.normal.background = ButtonTexture;
                    AGXBtnStyle.hover.background = ButtonTexture;
                }
                if (GUI.Button(new Rect(122, 25, 59, 20), "Gear", AGXBtnStyle)) //button code
                {
                    defaultGroupToShow = KSPActionGroup.Gear;
                    RefreshDefaultActionsListType();
                }
                if (defaultGroupToShow == KSPActionGroup.Light)
                {
                    AGXBtnStyle.normal.background = ButtonTextureGreen;
                    AGXBtnStyle.hover.background = ButtonTextureGreen;
                }
                else
                {
                    AGXBtnStyle.normal.background = ButtonTexture;
                    AGXBtnStyle.hover.background = ButtonTexture;
                }
                if (GUI.Button(new Rect(182, 25, 58, 20), "Lights", AGXBtnStyle)) //button code
                {
                    defaultGroupToShow = KSPActionGroup.Light;
                    RefreshDefaultActionsListType();
                }

                if (defaultGroupToShow == KSPActionGroup.RCS)
                {
                    AGXBtnStyle.normal.background = ButtonTextureGreen;
                    AGXBtnStyle.hover.background = ButtonTextureGreen;
                }
                else
                {
                    AGXBtnStyle.normal.background = ButtonTexture;
                    AGXBtnStyle.hover.background = ButtonTexture;
                }
                if (GUI.Button(new Rect(5, 45, 76, 20), "RCS", AGXBtnStyle)) //button code
                {
                    defaultGroupToShow = KSPActionGroup.RCS;
                    RefreshDefaultActionsListType();
                }
                if (defaultGroupToShow == KSPActionGroup.SAS)
                {
                    AGXBtnStyle.normal.background = ButtonTextureGreen;
                    AGXBtnStyle.hover.background = ButtonTextureGreen;
                }
                else
                {
                    AGXBtnStyle.normal.background = ButtonTexture;
                    AGXBtnStyle.hover.background = ButtonTexture;
                }
                if (GUI.Button(new Rect(81, 45, 76, 20), "SAS", AGXBtnStyle)) //button code
                {
                    defaultGroupToShow = KSPActionGroup.SAS;
                    RefreshDefaultActionsListType();
                }
                if (defaultGroupToShow == KSPActionGroup.Stage)
                {
                    AGXBtnStyle.normal.background = ButtonTextureGreen;
                    AGXBtnStyle.hover.background = ButtonTextureGreen;
                }
                else
                {
                    AGXBtnStyle.normal.background = ButtonTexture;
                    AGXBtnStyle.hover.background = ButtonTexture;
                }
                if (GUI.Button(new Rect(157, 45, 76, 20), "Stage", AGXBtnStyle)) //button code
                {
                    defaultGroupToShow = KSPActionGroup.Stage;
                    RefreshDefaultActionsListType();
                }

                AGXBtnStyle.normal.background = ButtonTexture;
                AGXBtnStyle.hover.background = ButtonTexture;
                //add vector2
                groupWinScroll = GUI.BeginScrollView(new Rect(5, 70, 240, 455), groupWinScroll, new Rect(0, 0, 240, Mathf.Max(455, defaultActionsListThisType.Count * 20)));
                int listCount2 = 1;
                highlightPartThisFrameGroupWin = false;
                while (listCount2 <= defaultActionsListThisType.Count)
                {
                    if (Mouse.screenPos.y >= GroupsWin.y + 70 && Mouse.screenPos.y <= GroupsWin.y + 525 && new Rect(GroupsWin.x + 5, (GroupsWin.y + 70 + ((listCount2 - 1) * 20)) - groupWinScroll.y, 240, 20).Contains(Mouse.screenPos))
                    {
                        highlightPartThisFrameGroupWin = true;
                        //print("part found to highlight acts " + highlightPartThisFrameActsWin + " " + ThisGroupActions.ElementAt(RowCnt - 1).ba.listParent.part.transform.position);
                        partToHighlight = defaultActionsListThisType.ElementAt(listCount2 - 1).listParent.part;
                    }

                    if (GUI.Button(new Rect(0, (listCount2 - 1) * 20, 240, 20), defaultActionsListThisType.ElementAt(listCount2 - 1).listParent.part.partInfo.title + " " + defaultActionsListThisType.ElementAt(listCount2 - 1).guiName, AGXBtnStyle)) //button code
                    {
                        defaultActionsListThisType.ElementAt(listCount2 - 1).actionGroup = defaultActionsListThisType.ElementAt(listCount2 - 1).actionGroup & ~defaultGroupToShow;
                        RefreshDefaultActionsListType();
                    }
                    listCount2 = listCount2 + 1;
                }
                GUI.EndScrollView();
            }
            else
            {

                AGXBtnStyle.normal.background = ButtonTexture;
                AGXBtnStyle.hover.background = ButtonTexture;
                ScrollGroups = GUI.BeginScrollView(new Rect(5, 25, 240, 500), ScrollPosSelParts, new Rect(0, 0, 240, 500));

                int ButtonID = new int();
                ButtonID = 1 + (50 * (GroupsPage - 1));
                int ButtonPos = new int();
                ButtonPos = 1;
                TextAnchor TxtAnch3 = new TextAnchor();
                TxtAnch3 = GUI.skin.button.alignment;
                AGXBtnStyle.alignment = TextAnchor.MiddleLeft;
                while (ButtonPos <= 25)
                {
                    if (ShowKeySetWin)
                    {
                        string btnName = "";
                        if (AGXguiMod1Groups[ButtonID] && AGXguiMod2Groups[ButtonID])
                        {
                            btnName = '\u00bd' + AGXguiKeys[ButtonID].ToString();
                        }
                        else if (AGXguiMod1Groups[ButtonID])
                        {
                            btnName = '\u2474' + AGXguiKeys[ButtonID].ToString();
                        }
                        else if (AGXguiMod2Groups[ButtonID])
                        {
                            btnName = '\u2475' + AGXguiKeys[ButtonID].ToString();
                        }
                        else
                        {
                            btnName = AGXguiKeys[ButtonID].ToString();
                        }
                        if (GUI.Button(new Rect(0, (ButtonPos - 1) * 20, 120, 20), ButtonID + " Key: " + btnName, AGXBtnStyle))
                        {

                            AGXCurActGroup = ButtonID;
                            ShowKeyCodeWin = true;
                        }
                    }

                    else
                    {
                        if (StaticData.CurrentVesselActions.Any(pfd => pfd.group == ButtonID)) AGXBtnStyle.normal.background = ButtonTextureGreen;
                        if (StaticData.CurrentVesselActions.Any(pfd => pfd.group == ButtonID)) AGXBtnStyle.hover.background = ButtonTextureGreen;
                        //{
                        //    GUI.DrawTexture(new Rect(1, ((ButtonPos - 1) * 20) + 1, 118, 18), BtnTexGrn);
                        //}

                        if (GUI.Button(new Rect(0, (ButtonPos - 1) * 20, 120, 20), ButtonID + ": " + AGXguiNames[ButtonID], AGXBtnStyle))
                        {
                            AGXCurActGroup = ButtonID;
                            TempShowGroupsWin = false;
                        }
                        AGXBtnStyle.normal.background = ButtonTexture;
                        AGXBtnStyle.hover.background = ButtonTexture;
                    }
                    ButtonPos = ButtonPos + 1;
                    ButtonID = ButtonID + 1;
                }
                while (ButtonPos <= 50)
                {
                    if (ShowKeySetWin)
                    {
                        string btnName2 = "";
                        if (AGXguiMod1Groups[ButtonID] && AGXguiMod2Groups[ButtonID])
                        {
                            btnName2 = '\u00bd' + AGXguiKeys[ButtonID].ToString();
                        }
                        else if (AGXguiMod1Groups[ButtonID])
                        {
                            btnName2 = '\u2474' + AGXguiKeys[ButtonID].ToString();
                        }
                        else if (AGXguiMod2Groups[ButtonID])
                        {
                            btnName2 = '\u2475' + AGXguiKeys[ButtonID].ToString();
                        }
                        else
                        {
                            btnName2 = AGXguiKeys[ButtonID].ToString();
                        }
                        if (GUI.Button(new Rect(120, (ButtonPos - 26) * 20, 120, 20), ButtonID + " Key: " + btnName2, AGXBtnStyle))
                        {
                            AGXCurActGroup = ButtonID;
                            ShowKeyCodeWin = true;
                        }
                    }
                    else
                    {
                        if (StaticData.CurrentVesselActions.Any(pfd => pfd.group == ButtonID)) AGXBtnStyle.normal.background = ButtonTextureGreen;
                        if (StaticData.CurrentVesselActions.Any(pfd => pfd.group == ButtonID)) AGXBtnStyle.hover.background = ButtonTextureGreen;
                        //{
                        //    GUI.DrawTexture(new Rect(121, ((ButtonPos - 26) * 20) + 1, 118, 18), BtnTexGrn);
                        //}
                        if (GUI.Button(new Rect(120, (ButtonPos - 26) * 20, 120, 20), ButtonID + ": " + AGXguiNames[ButtonID], AGXBtnStyle))
                        {

                            AGXCurActGroup = ButtonID;
                            TempShowGroupsWin = false;

                        }
                        AGXBtnStyle.normal.background = ButtonTexture;
                        AGXBtnStyle.hover.background = ButtonTexture;
                    }
                    ButtonPos = ButtonPos + 1;
                    ButtonID = ButtonID + 1;
                }
                GUI.skin.button.alignment = TxtAnch3;

                GUI.EndScrollView();

            }
            GUI.DragWindow();
        }
コード例 #45
0
            internal TriggeredEvent(TriggeredEventTemplate template, RasterPropMonitorComputer rpmComp)
            {
                eventName = template.eventName;
                if (string.IsNullOrEmpty(eventName))
                {
                    throw new Exception("TriggeredEvent: eventName not valid");
                }

                string[] tokens = template.range.Split(',');
                if (string.IsNullOrEmpty(template.variableName))
                {
                    throw new Exception("TriggeredEvent: variableName not valid");
                }
                if (tokens.Length != 2)
                {
                    throw new Exception("TriggeredEvent: tokens not valid");
                }
                variable = new VariableOrNumberRange(rpmComp, template.variableName, tokens[0], tokens[1]);

                if (JSIActionGroupSwitch.groupList.ContainsKey(template.triggerEvent))
                {
                    isPluginAction = false;
                    action = JSIActionGroupSwitch.groupList[template.triggerEvent];
                }
                else
                {
                    isPluginAction = true;
                    pluginAction = (Action<bool>)rpmComp.GetInternalMethod(template.triggerEvent, typeof(Action<bool>));

                    if (pluginAction == null)
                    {
                        throw new Exception("TriggeredEvent: Unable to initialize pluginAction");
                    }
                }

                if (string.IsNullOrEmpty(template.triggerState))
                {
                    throw new Exception("TriggeredEvent: Unable to initialize triggerState");
                }
                if (bool.TryParse(template.triggerState, out triggerState))
                {
                    toggleAction = false;
                }
                else if (template.triggerState.ToLower() == "toggle")
                {
                    toggleAction = true;

                    if (isPluginAction)
                    {
                        pluginState = (Func<bool>)rpmComp.GetInternalMethod(template.eventState, typeof(Func<bool>));
                        if (pluginState == null)
                        {
                            throw new Exception("TriggeredEvent: Unable to initialize pluginState");
                        }
                    }
                }
                else
                {
                    throw new Exception("TriggeredEvent: Unable to determine triggerState");
                }

                if (!string.IsNullOrEmpty(template.oneShot))
                {
                    if (!bool.TryParse(template.oneShot, out oneShot))
                    {
                        oneShot = false;
                    }
                }
                else
                {
                    oneShot = false;
                }

                JUtil.LogMessage(this, "Triggered Event {0} created", eventName);
            }
コード例 #46
0
ファイル: View.cs プロジェクト: KaiSforza/ActionGroupManager
        //Draw the Action groups grid in Part View
        private void DrawSelectedActionGroup()
        {
            #if DEBUG_VERBOSE
            Debug.Log("AGM : Draw Action Group list");
            #endif
            bool selectMode = currentSelectedBaseAction.Count == 0;

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();

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

                List<BaseAction> list = partFilter.GetBaseActionAttachedToActionGroup(ag).ToList();

                string buttonTitle = ag.ToString();

                if (list.Count > 0)
                {
                    buttonTitle += " (" + list.Count + ")";
                }

                string tooltip;
                if (selectMode)
                    if (list.Count > 0)
                        tooltip = "Put all the parts linked to " + ag.ToString() + " in the selection.";
                    else
                        tooltip = string.Empty;
                else
                    tooltip = "Link all parts selected to " + ag.ToString();

                if (selectMode && list.Count == 0)
                    GUI.enabled = false;

                //Push the button will replace the actual action group list with all the selected action
                if(GUILayout.Button(new GUIContent(buttonTitle, tooltip), Style.ButtonToggleStyle))
                {

                    if (!selectMode)
                    {
                        foreach (BaseAction ba in list)
                            ba.RemoveActionToAnActionGroup(ag);

                        foreach (BaseAction ba in currentSelectedBaseAction)
                            ba.AddActionToAnActionGroup(ag);

                        currentSelectedBaseAction.Clear();

                        currentSelectedPart = null;
                        confirmDelete = false;
                    }
                    else
                    {
                        if (list.Count > 0)
                        {
                            currentSelectedBaseAction = list;
                            allActionGroupSelected = true;
                            currentSelectedActionGroup = ag;
                        }
                    }
                }

                GUI.enabled = true;

                if (ag == KSPActionGroup.Custom02)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }

            }

            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            GUI.enabled = true;
        }
コード例 #47
0
 public extern KSPAction(string guiName, KSPActionGroup actionGroup);
コード例 #48
0
ファイル: View.cs プロジェクト: KaiSforza/ActionGroupManager
        //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();
            }
        }
コード例 #49
0
ファイル: View.cs プロジェクト: KaiSforza/ActionGroupManager
        //Internal draw routine for DrawAllParts()
        private void InternalDrawParts(IEnumerable<Part> list)
        {
            #if DEBUG_VERBOSE
            Debug.Log("AGM : Internal Draw All parts");
            #endif
            foreach (Part p in list)
            {
                List<KSPActionGroup> currentAG = partFilter.GetActionGroupAttachedToPart(p).ToList();
                GUILayout.BeginHorizontal();

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

                initial = p == currentSelectedPart;
                string str = p.partInfo.title;

                final = GUILayout.Toggle(initial, str, Style.ButtonToggleStyle);
                if (initial != final)
                {
                    if (final)
                        currentSelectedPart = p;
                    else
                        currentSelectedPart = null;
                }

                if (currentAG.Count > 0)
                {
                    foreach (KSPActionGroup ag in currentAG)
                    {
                        if (ag == KSPActionGroup.None)
                            continue;
                        GUIContent content = new GUIContent(ag.ToShortString(), "Part has an action linked to action group " + ag.ToString());

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

                }

                GUILayout.EndHorizontal();

                if (currentSelectedPart == p)
                    DrawSelectedPartView();
            }

            #if DEBUG_VERBOSE
            Debug.Log("AGM : End Internal Draw All parts");
            #endif
        }
コード例 #50
0
 public static bool IsInActionGroup(this BaseAction bA, KSPActionGroup aG)
 {
     return bA == null ? false : (bA.actionGroup & aG) == aG;
 }
コード例 #51
0
        public IEnumerable<BaseAction> GetBaseActionAttachedToActionGroup(KSPActionGroup ag)
        {
            IEnumerable<Part> parts = manager.GetParts();

            List<BaseAction> ret = new List<BaseAction>();
            foreach (Part p in parts)
            {
                foreach (BaseAction ba in p.Actions)
                    if (ba.IsInActionGroup(ag))
                        ret.Add(ba);
                foreach (PartModule pm in p.Modules)
                {
                    foreach (BaseAction ba in pm.Actions)
                    {
                        if (ba.IsInActionGroup(ag))
                            ret.Add(ba);
                    }

                }
            }
            return ret;
        }
コード例 #52
0
 public static extern void FireAction(List<Part> parts, KSPActionGroup group, KSPActionType type);
コード例 #53
0
ファイル: View.cs プロジェクト: KaiSforza/ActionGroupManager
        //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();
        }
コード例 #54
0
 public static extern int GetGroupIndex(KSPActionGroup group);
コード例 #55
0
ファイル: Editor.cs プロジェクト: CameronHunt5812/AGExt
        public void MonitorDefaultActions()
        {
            //print("AGX Monitor default start " + StaticData.CurrentVesselActions.Count());
            KSPActionGroup KSPDefaultActionGroupThisFrame = KSPActionGroup.Custom01;
            try //find which action group is selected in default ksp editor this pass
            {
                string grpText = "None";
                for (int i = 0; i < EditorActionGroups.Instance.actionGroupList.Count; i++)
                {
                    IUIListObject lObj = EditorActionGroups.Instance.actionGroupList.GetItem(i);
                    UIListItem LstItem = (UIListItem)lObj;
                    if (LstItem.controlState == UIButton.CONTROL_STATE.ACTIVE)
                    {
                        grpText = LstItem.Text;
                    }
                }

                KSPDefaultActionGroupThisFrame = (KSPActionGroup)Enum.Parse(typeof(KSPActionGroup), grpText);
                //print("Selected group " + KSPDefaultLastActionGroup);

            }
            catch
            {
                print("AGX Monitor default list fail");
            }
            string errLine = "1";
            try
            {
                errLine = "2";
                if (EditorActionGroups.Instance.GetSelectedParts() != null) //is a part selected?
                {
                    errLine = "3";
                    if (EditorActionGroups.Instance.GetSelectedParts().Count > 0) //list can exist with no parts in it if you selected then unselect one
                    {
                        errLine = "4";
                        if (SelectedWithSym.Count == 0 || SelectedWithSym.First() != EditorActionGroups.Instance.GetSelectedParts().First() || KSPDefaultActionGroupThisFrame != KSPDefaultLastActionGroup) //check if there is a previously selected part, if so check if its changed
                        {
                            errLine = "5";
                            //print("2b");
                            //parts are different
                            SelectedWithSym.Clear(); //reset lastpart list
                            SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts());
                            SelectedWithSym.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts);
                            SelectedWithSymActions.Clear(); //reset actions list
                            //print("2c");
                            errLine = "6";
                            foreach (Part prt in SelectedWithSym)
                            {
                                //  print("2d");
                                errLine = "7";
                                foreach (BaseAction bap in prt.Actions) //get part actions
                                {
                                    SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare
                                }
                                errLine = "8";
                                foreach (PartModule pm in prt.Modules) //add actions from all partmodules
                                {
                                    errLine = "9";
                                    foreach (BaseAction bapm in pm.Actions)
                                    {
                                        errLine = "10";
                                        SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup });
                                    }
                                }
                            }
                            errLine = "11";
                            int groupToAdd = 1;
                            switch (KSPDefaultActionGroupThisFrame)
                            {
                                case KSPActionGroup.Custom01:
                                    groupToAdd = 1;
                                    break;
                                case KSPActionGroup.Custom02:
                                    groupToAdd = 2;
                                    break;
                                case KSPActionGroup.Custom03:
                                    groupToAdd = 3;
                                    break;
                                case KSPActionGroup.Custom04:
                                    groupToAdd = 4;
                                    break;
                                case KSPActionGroup.Custom05:
                                    groupToAdd = 5;
                                    break;
                                case KSPActionGroup.Custom06:
                                    groupToAdd = 6;
                                    break;
                                case KSPActionGroup.Custom07:
                                    groupToAdd = 7;
                                    break;
                                case KSPActionGroup.Custom08:
                                    groupToAdd = 8;
                                    break;
                                case KSPActionGroup.Custom09:
                                    groupToAdd = 9;
                                    break;
                                case KSPActionGroup.Custom10:
                                    groupToAdd = 10;
                                    break;
                            }
                            errLine = "12";
                            foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd))
                            {
                                SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = agact2.ba, agrp = agact2.ba.actionGroup });
                            }
                            errLine = "13";
                            KSPDefaultLastActionGroup = KSPDefaultActionGroupThisFrame;
                            //foreach (AGXDefaultCheck dC in SelectedWithSymActions)
                            //{
                            //    print("Acts " + dC.ba.name);
                            //}
                            // print("2e");
                        }
                        else //selected part is the same a previously selected part
                        {
                            errLine = "14";
                            //print("2f");
                            List<Part> PartsThisFrame = new List<Part>(); //get list of parts this update frame
                            PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts());
                            PartsThisFrame.AddRange(EditorActionGroups.Instance.GetSelectedParts().First().symmetryCounterparts);
                            // print("2g");
                            List<BaseAction> ThisFrameActions = new List<BaseAction>(); //get actions fresh again this update frame
                            foreach (Part prt in PartsThisFrame)
                            {
                                errLine = "15";
                                // print("2h");
                                foreach (BaseAction bap in prt.Actions)
                                {
                                    ThisFrameActions.Add(bap);
                                }
                                errLine = "16";
                                foreach (PartModule pm in prt.Modules)
                                {
                                    foreach (BaseAction bapm in pm.Actions)
                                    {
                                        ThisFrameActions.Add(bapm);
                                    }
                                }
                            }
                            errLine = "17";
                            int groupToAdd = 1;
                            switch (KSPDefaultActionGroupThisFrame)
                            {
                                case KSPActionGroup.Custom01:
                                    groupToAdd = 1;
                                    break;
                                case KSPActionGroup.Custom02:
                                    groupToAdd = 2;
                                    break;
                                case KSPActionGroup.Custom03:
                                    groupToAdd = 3;
                                    break;
                                case KSPActionGroup.Custom04:
                                    groupToAdd = 4;
                                    break;
                                case KSPActionGroup.Custom05:
                                    groupToAdd = 5;
                                    break;
                                case KSPActionGroup.Custom06:
                                    groupToAdd = 6;
                                    break;
                                case KSPActionGroup.Custom07:
                                    groupToAdd = 7;
                                    break;
                                case KSPActionGroup.Custom08:
                                    groupToAdd = 8;
                                    break;
                                case KSPActionGroup.Custom09:
                                    groupToAdd = 9;
                                    break;
                                case KSPActionGroup.Custom10:
                                    groupToAdd = 10;
                                    break;
                            }

                            foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd))
                            {
                                ThisFrameActions.Add(agact2.ba);
                            }

                            errLine = "18";

                            //print("2i");

                            foreach (BaseAction ba2 in ThisFrameActions) //check each action's actiongroup enum against last update frames actiongroup enum, this adds/removes a group to default KSP when added/removed in agx
                            {
                                //print("2j");
                                errLine = "19";
                                AGXDefaultCheck ActionLastFrame = new AGXDefaultCheck();
                                //print("2j1");
                                ActionLastFrame = SelectedWithSymActions.Find(a => a.ba == ba2);
                                // print("2j2");
                                errLine = "20";
                                if (ActionLastFrame.agrp != ba2.actionGroup) //actiongroup enum is different
                                {
                                    //  print("2j3");
                                    int NewGroup = 0; //which actiongroup changed?
                                    if (KSPActionGroup.Custom01 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 1;
                                    }
                                    else if (KSPActionGroup.Custom02 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 2;
                                    }
                                    else if (KSPActionGroup.Custom03 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 3;
                                    }
                                    else if (KSPActionGroup.Custom04 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 4;
                                    }
                                    else if (KSPActionGroup.Custom05 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 5;
                                    }
                                    else if (KSPActionGroup.Custom06 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 6;
                                    }
                                    else if (KSPActionGroup.Custom07 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 7;
                                    }
                                    else if (KSPActionGroup.Custom08 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 8;
                                    }
                                    else if (KSPActionGroup.Custom09 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 9;
                                    }
                                    else if (KSPActionGroup.Custom10 == (ActionLastFrame.agrp ^ ba2.actionGroup))
                                    {
                                        NewGroup = 10;
                                    }

                                    // print("2k");
                                    errLine = "21";

                                    if (NewGroup != 0) //if one of the other actiongroups (gear, lights) has changed, ignore it. newgroup will be the actiongroup if I want to process it.
                                    {
                                        // print("Newgroup called on " + NewGroup);
                                        errLine = "22";
                                        if (Mouse.screenPos.x >= 130 && Mouse.screenPos.x <= 280)
                                        {
                                            //print("remove actions");
                                            //AGXAction ToRemove = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false };
                                            StaticData.CurrentVesselActions.RemoveAll(ag3 => ag3.ba == ba2 && ag3.group == NewGroup);
                                        }
                                        else
                                        {
                                            errLine = "23";
                                            //print("add actions");
                                            AGXAction ToAdd = new AGXAction() { prt = ba2.listParent.part, ba = ba2, group = NewGroup, activated = false };
                                            List<AGXAction> Checking = new List<AGXAction>();
                                            Checking.AddRange(StaticData.CurrentVesselActions);
                                            Checking.RemoveAll(p => p.group != ToAdd.group);
                                            Checking.RemoveAll(p => p.prt != ToAdd.prt);
                                            Checking.RemoveAll(p => p.ba != ToAdd.ba);

                                            if (Checking.Count == 0)
                                            {
                                                StaticData.CurrentVesselActions.Add(ToAdd);
                                                //SaveCurrentVesselActions();
                                            }
                                        }

                                    }
                                    errLine = "24";
                                    ActionLastFrame.agrp = KSPActionGroup.None;
                                    ActionLastFrame.agrp = ActionLastFrame.agrp | ba2.actionGroup;
                                    //print("2l");
                                }

                            }
                            SelectedWithSymActions.Clear(); //reset actions list as one of the enums changed.
                            //print("2k");
                            errLine = "25";
                            foreach (Part prt in SelectedWithSym)
                            {
                                errLine = "26";
                                foreach (BaseAction bap in prt.Actions) //get part actions
                                {
                                    SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bap, agrp = bap.actionGroup }); //add actiongroup separate otherwise it links and so have nothing to compare
                                }
                                errLine = "27";
                                foreach (PartModule pm in prt.Modules) //add actions from all partmodules
                                {
                                    foreach (BaseAction bapm in pm.Actions)
                                    {
                                        SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = bapm, agrp = bapm.actionGroup });
                                    }
                                }
                            }
                            errLine = "28";
                            foreach (AGXAction agact2 in StaticData.CurrentVesselActions.Where(ag => ag.group == groupToAdd))
                            {
                                SelectedWithSymActions.Add(new AGXDefaultCheck() { ba = agact2.ba, agrp = agact2.ba.actionGroup });
                            }

                            errLine = "29";

                        }
                    }
                }
                //print("AGX Monitor default end " + StaticData.CurrentVesselActions.Count());
            }
            catch (Exception e)
            {
                Debug.Log("AGX Monitor Default Actions Error " + errLine + " " + e);
            }
            //print("2l " + Mouse.screenPos);
        }
コード例 #56
0
ファイル: BDModulePilotAI.cs プロジェクト: ferram4/BDArmory
        public void CommandAG(KSPActionGroup ag)
        {
            if(!pilotEnabled)
            {
                return;
            }

            vessel.ActionGroups.ToggleGroup(ag);
        }
コード例 #57
0
ファイル: ModuleWeapon.cs プロジェクト: gomker/BDArmory
        IEnumerator FireHoldRoutine(KSPActionGroup group)
        {
            KeyBinding key = Misc.AGEnumToKeybinding(group);
            if(key == null)
            {
                yield break;
            }

            while(key.GetKey())
            {
                agHoldFiring = true;
                yield return null;
            }

            agHoldFiring = false;
            yield break;
        }