public void ProcessActionGroup()
        {
            var vessel = FlightGlobals.fetch.LmpFindVessel(VesselId);

            if (vessel == null)
            {
                return;
            }

            if (!VesselCommon.DoVesselChecks(VesselId))
            {
                return;
            }

            //Ignore SAS if we are spectating as it will fight with the FI
            if (ActionGroup == KSPActionGroup.SAS && VesselCommon.IsSpectating && FlightGlobals.ActiveVessel && FlightGlobals.ActiveVessel.id == vessel.id)
            {
                return;
            }

            if (vessel.ActionGroups != null)
            {
                var currentValue = vessel.ActionGroups[ActionGroup];
                if (currentValue != Value)
                {
                    vessel.ActionGroups.ToggleGroup(ActionGroup);
                }
            }

            vessel.protoVessel?.actionGroups.SetValue(ActionGroup.ToString(), $"{Value.ToString(CultureInfo.InvariantCulture)}, 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")));
        }
Exemple #3
0
        public void Execute()
        {
            isActive    = true;
            timeStarted = UnityEngine.Time.time;

            if (wait)
            {
                //wait commands are dealt with separately in FixedUpdate
                //all we had to do is mark it as Active and set Timestamp, as we did above
            }
            else if (ag != KSPActionGroup.None)
            {
                if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null)
                {
                    FlightGlobals.ActiveVessel.ActionGroups.ToggleGroup(ag);
                }
                isActive   = false;
                isFinished = true;
                Logger.Log("[Sequencer] Firing ActionGroup = " + ag.ToString(), Logger.Level.Debug);
            }
            else if (agX > -1)
            {
                if (HighLogic.LoadedSceneIsFlight && FlightGlobals.ActiveVessel != null &&
                    ActionGroupsExtendedAPI.Instance != null && ActionGroupsExtendedAPI.Instance.Installed())
                {
                    var curState = ActionGroupsExtendedAPI.Instance.GetGroupState(FlightGlobals.ActiveVessel, agX);
                    ActionGroupsExtendedAPI.Instance.ActivateGroup(FlightGlobals.ActiveVessel, agX, !curState);
                }
                isActive   = false;
                isFinished = true;
                Logger.Log("[Sequencer] Firing ActionGroup = " + ag.ToString(), Logger.Level.Debug);
            }
            else if (servo != null)
            {
                Logger.Log("[Sequencer] Executing command, servoName= " + servo.Name + ", pos=" + position, Logger.Level.Debug);
                servo.MoveTo(position, speedMultiplier);
            }
        }
Exemple #4
0
            public override string ToString()
            {
                string str =
                    partName + ":" +
                    persistentId.ToString() + ":" +
                    partModuleName + ":" +
                    partModulePeristentId.ToString() + ":" +
                    partModuleNum.ToString() + ":" +
                    baseActionActionGroup.ToString() + ":" +
                    actionGroupName.ToString() + ":" +
                    actionNum.ToString() + ":" +
                    actionGroup.ToString();


                return(str);
            }
Exemple #5
0
        public void SendVesselActionGroup(Vessel vessel, KSPActionGroup actionGrp, bool value)
        {
            if (vessel == null)
            {
                return;
            }

            var msgData = NetworkMain.CliMsgFactory.CreateNewMessageData <VesselActionGroupMsgData>();

            msgData.GameTime          = TimeSyncSystem.UniversalTime;
            msgData.VesselId          = vessel.id;
            msgData.ActionGroupString = actionGrp.ToString();
            msgData.ActionGroup       = (int)actionGrp;
            msgData.Value             = value;

            SendMessage(msgData);
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        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));
        }
Exemple #8
0
        //Draw all the current selected action
        private void DrawSelectedAction()
        {
            Part currentDrawn = null;

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

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

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

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

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

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

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

                        currentSelectedBaseAction.Remove(pa);

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


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

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


                GUILayout.EndHorizontal();
            }
        }
 /// <summary>
 /// Returns the texture associated with this <see cref="KSPActionGroup"/>.
 /// </summary>
 /// <param name="group">The action group to get the texture for.</param>
 /// <returns>The texture associated with the action group.</returns>
 public static Texture GetTexture(this KSPActionGroup group)
 {
     return(GameDatabase.Instance.GetTexture(Program.ModPath + "Resources/" + group.ToString(), false));
 }