示例#1
0
        //String is "VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|ActionedAt|Manuever|Xfer|Target|Options|<ENDLINE>");
        public String SerializeString3()
        {
            //"VesselID, Name, Notes, AlarmTime.UT, AlarmMarginSecs, Type, Enabled,  HaltWarp, PauseGame, Manuever/Xfer"
            String strReturn = "";

            strReturn += VesselID + "|";
            strReturn += KACUtils.PipeSepVariables(Name, Notes, AlarmTime.UT, AlarmMarginSecs, TypeOfAlarm, Enabled, HaltWarp, PauseGame, ActionedAt);
            strReturn += "|";

            if (ManNodes != null)
            {
                strReturn += ManNodeSerializeList(ManNodes);
            }
            strReturn += "|";

            if (XferTargetBodyName != null && XferTargetBodyName != "")
            {
                strReturn += "" + XferOriginBodyName;
                strReturn += "," + XferTargetBodyName;
            }
            strReturn += "|";

            if (TargetObject != null)
            {
                strReturn += KACAlarm.TargetSerialize(TargetObject);
            }
            strReturn += "|";

            //Extra Options go here if we need it later
            strReturn += "|";
            return(strReturn);
        }
示例#2
0
 internal void APIInstance_AlarmStateChanged(KACAlarm alarm, AlarmStateEventsEnum newstate)
 {
     if (onAlarmStateChanged != null)
     {
         onAlarmStateChanged(new AlarmStateChangedEventArgs(alarm, newstate));
     }
 }
示例#3
0
        public KACAlarm Duplicate(Double newUT)
        {
            KACAlarm newAlarm = Duplicate();

            newAlarm.AlarmTime = new KSPDateTime(newUT);
            return(newAlarm);
        }
        private KACAlarm QuickAddEarth(Int32 Minutes)
        {
            KACAlarm tmpAlarm = new KACAlarm(EarthTimeEncode(DateTime.Now.AddMinutes(Minutes)));

            tmpAlarm.TypeOfAlarm = KACAlarm.AlarmTypeEnum.EarthTime;
            tmpAlarm.Name        = "Quick Earth Alarm";

            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
示例#5
0
        /// <summary>
        /// Create a new Alarm method for calling via API
        /// </summary>
        /// <param name="AlarmType">Enum of type of alarm</param>
        /// <param name="Name">Text Name of the Alarm</param>
        /// <param name="UT">Universal Time of the Alarm</param>
        /// <returns>Alarms Unique ID</returns>
        public String CreateAlarm(KACAlarm.AlarmTypeEnum AlarmType, String Name, Double UT)
        //public KACAlarm CreateAlarm(String Name)
        {
            KACAlarm tmpAlarm = new KACAlarm(UT);

            tmpAlarm.TypeOfAlarm = AlarmType;
            tmpAlarm.Name        = Name;

            alarms.Add(tmpAlarm);

            return(tmpAlarm.ID);
        }
        private KACAlarm QuickAddDN()
        {
            KACAlarm tmpAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(),
                                             KACWorkerGameState.CurrentVessel.vesselName + " Descending",
                                             "Quick Added Descending Node",
                                             KACWorkerGameState.CurrentVessel.orbit.TimeOfDescendingNode(KACWorkerGameState.CurrentVesselTarget.GetOrbit(), KACWorkerGameState.CurrentTime.UT) - settings.AlarmAddNodeQuickMargin,
                                             settings.AlarmAddNodeQuickMargin,
                                             KACAlarm.AlarmTypeEnum.DescendingNode,
                                             settings.AlarmAddNodeQuickAction);

            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
        private KACAlarm QuickAddPe()
        {
            KACAlarm tmpAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(),
                                             KACWorkerGameState.CurrentVessel.vesselName + " Periapsis",
                                             "Quick Added Periapsis Alarm",
                                             KACWorkerGameState.CurrentTime.UT + KACWorkerGameState.CurrentVessel.orbit.timeToPe - settings.AlarmAddNodeQuickMargin,
                                             settings.AlarmAddNodeQuickMargin,
                                             KACAlarm.AlarmTypeEnum.Periapsis,
                                             settings.AlarmAddNodeQuickAction);

            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
        private KACAlarm QuickAddSOI()
        {
            KACAlarm tmpAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(),
                                             KACWorkerGameState.CurrentVessel.vesselName + " SOI Change",
                                             "Quick Added SOI Change Alarm",
                                             KACWorkerGameState.CurrentVessel.orbit.UTsoi - settings.AlarmAddSOIQuickMargin,
                                             settings.AlarmAddSOIQuickMargin,
                                             KACAlarm.AlarmTypeEnum.SOIChange,
                                             settings.AlarmAddSOIQuickAction);

            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
示例#9
0
        private KACAlarm QuickAddAN()
        {
            KACAlarm tmpAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(),
                                             KSP.Localization.Localizer.Format(KACWorkerGameState.CurrentVessel.vesselName) + " Ascending",
                                             "Quick Added Ascending Node",
                                             KACWorkerGameState.CurrentVessel.orbit.TimeOfAscendingNode(KACWorkerGameState.CurrentVesselTarget.GetOrbit(), KACWorkerGameState.CurrentTime.UT) - settings.AlarmAddNodeQuickMargin,
                                             settings.AlarmAddNodeQuickMargin,
                                             KACAlarm.AlarmTypeEnum.AscendingNode,
                                             settings.AlarmAddNodeQuickAction);

            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
示例#10
0
        private KACAlarm QuickAddAp()
        {
            KACAlarm tmpAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(),
                                             KSP.Localization.Localizer.Format(KACWorkerGameState.CurrentVessel.vesselName) + " Apopasis",
                                             "Quick Added Apoapsis Alarm",
                                             KACWorkerGameState.CurrentTime.UT + KACWorkerGameState.CurrentVessel.orbit.timeToAp - settings.AlarmAddNodeQuickMargin,
                                             settings.AlarmAddNodeQuickMargin,
                                             KACAlarm.AlarmTypeEnum.Apoapsis,
                                             settings.AlarmAddNodeQuickAction);

            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
示例#11
0
        public KACAlarm Duplicate()
        {
            KACAlarm newAlarm = new KACAlarm(this.VesselID, this.Name, this.Notes, this.AlarmTime.UT, this.AlarmMarginSecs, this.TypeOfAlarm, this.Actions);;

            newAlarm.ContractAlarmType  = this.ContractAlarmType;
            newAlarm.ContractGUID       = this.ContractGUID;
            newAlarm.ManNodes           = this.ManNodes;
            newAlarm.RepeatAlarm        = this.RepeatAlarm;
            newAlarm.RepeatAlarmPeriod  = this.RepeatAlarmPeriod;
            newAlarm.TargetObject       = this.TargetObject;
            newAlarm.XferOriginBodyName = this.XferOriginBodyName;
            newAlarm.XferTargetBodyName = this.XferTargetBodyName;

            return(newAlarm);
        }
        private KACAlarm QuickAddManNode()
        {
            KACAlarm tmpAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(),
                                             KACWorkerGameState.CurrentVessel.vesselName + " Maneuver",
                                             "Quick Added Maneuver Alarm",
                                             KACWorkerGameState.ManeuverNodeFuture.UT - settings.AlarmAddManQuickMargin,
                                             settings.AlarmAddManQuickMargin,
                                             KACAlarm.AlarmTypeEnum.Maneuver,
                                             settings.AlarmAddManQuickAction,
                                             KACWorkerGameState.ManeuverNodesFuture);

            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
        private KACAlarm QuickAddRaw()
        {
            KACAlarm tmpAlarm = new KACAlarm(KACWorkerGameState.CurrentTime.UT + 600);

            tmpAlarm.TypeOfAlarm = KACAlarm.AlarmTypeEnum.Raw;
            tmpAlarm.Name        = "Quick Raw";
            if (KACWorkerGameState.IsVesselActive)
            {
                tmpAlarm.VesselID = KACWorkerGameState.CurrentVessel.id.ToString();
            }


            alarms.Add(tmpAlarm);

            return(tmpAlarm);
        }
示例#14
0
        private void DrawQuickOption(QuickAddItem item)
        {
            GUILayout.BeginHorizontal();
            if (GUILayout.Button(item.Text, KACResources.styleQAListButton))
            {
                if (item.ActionToCall != null)
                {
                    item.ActionToCall.Invoke();
                }
                _ShowQuickAdd = false;
            }
            if (Event.current.type == EventType.Repaint)
            {
                item.ButtonRect = GUILayoutUtility.GetLastRect();
            }
            GUI.Box(new Rect(item.ButtonRect.x + 8, item.ButtonRect.y + 3, 18, 14), item.Icon, new GUIStyle());

            if (item.AllowAddAndWarp)
            {
                GUILayout.Space(-5);

                GUIContent contButton = new GUIContent(">>", "Warp to " + item.Text);
                if (GUILayout.Button(contButton, KACResources.styleQAListButton, GUILayout.Width(30)))
                {
                    if (item.ActionToCall != null)
                    {
                        KACAlarm newAlarm = item.ActionToCall.Invoke();

                        Log.info("Creating Alarm and setting warp rate-Remaining Time:{0}", newAlarm.Remaining.UT);

                        Int32 intRate = TimeWarp.fetch.warpRates.Length - 1;
                        while (intRate > 0 && (TimeWarp.fetch.warpRates[intRate] * 2) > newAlarm.Remaining.UT)
                        {
                            intRate -= 1;
                        }
                        Log.info("Setting Rate to {0}={1}x", intRate, TimeWarp.fetch.warpRates[intRate]);

                        TimeWarp.fetch.Mode = TimeWarp.Modes.HIGH;
                        //Make sure we cancel autowarp if its engaged
                        TimeWarp.fetch.CancelAutoWarp();
                        TimeWarp.SetRate(intRate, false);
                    }
                    _ShowQuickAdd = false;
                }
            }
            GUILayout.EndHorizontal();
        }
示例#15
0
        private static Vessel FindVesselForAlarm(KACAlarm tmpAlarm)
        {
            Vessel tmpVessel;
            String strVesselID = "";

            if (tmpAlarm.TypeOfAlarm == KACAlarm.AlarmTypeEnum.Crew)
            {
                strVesselID = StoredCrewVessel(tmpAlarm.VesselID).id.ToString();
            }
            else
            {
                strVesselID = tmpAlarm.VesselID;
            }

            tmpVessel = FlightGlobals.Vessels.Find(delegate(Vessel v)
            {
                return(strVesselID == v.id.ToString());
            }
                                                   );
            return(tmpVessel);
        }
示例#16
0
        private void LoadAlarms()
        {
            string AlarmsFileVersion = "2";

            Alarms = new KACAlarmList();
            KSP.IO.TextReader tr      = KSP.IO.TextReader.CreateForType <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title));
            String            strFile = tr.ReadToEnd();

            tr.Close();

            while (strFile.Contains("|<ENDLINE>"))
            {
                String strAlarm = strFile.Substring(0, strFile.IndexOf("|<ENDLINE>"));
                strFile = strFile.Substring(strAlarm.Length + "|<ENDLINE>".Length).TrimStart("\r\n".ToCharArray());

                if (strAlarm.StartsWith("AlarmsFileVersion|"))
                {
                    AlarmsFileVersion = strAlarm.Split("|".ToCharArray())[1];
                    KACWorker.DebugLogFormatted("AlarmsFileVersion:{0}", AlarmsFileVersion);
                }
                else if (!strAlarm.StartsWith("VesselID|"))
                {
                    KACAlarm tmpAlarm = new KACAlarm();

                    switch (AlarmsFileVersion)
                    {
                    case "3":
                        tmpAlarm.LoadFromString3(strAlarm, KACWorkerGameState.CurrentTime.UT);
                        break;

                    default:
                        tmpAlarm.LoadFromString2(strAlarm);
                        break;
                    }

                    Alarms.Add(tmpAlarm);
                }
            }
        }
示例#17
0
        /// <summary>
        /// Delete Alarm Method for calling via API
        /// </summary>
        /// <param name="AlarmID">Unique ID of the alarm</param>
        /// <returns>Success</returns>
        public Boolean DeleteAlarm(String AlarmID)
        {
            Boolean blnReturn = false;

            try
            {
                KACAlarm tmpAlarm = alarms.FirstOrDefault(a => a.ID == AlarmID);
                if (tmpAlarm != null)
                {
                    Log.detail("API-DeleteAlarm-Deleting:{0}", AlarmID);
                    alarms.Remove(tmpAlarm);
                    blnReturn = true;
                }
                else
                {
                    Log.detail("API-DeleteAlarm-ID Not Found:{0}", AlarmID);
                }
            }
            catch (Exception ex)
            {
                Log.detail("API-DeleteAlarm-Error:{0}\r\n{1}", AlarmID, ex.Message);
            }
            return(blnReturn);
        }
示例#18
0
        private int DrawAlarmActionButtons(KACAlarm tmpAlarm, out int NoOfDoubleLineButtons)
        {
            int intReturnNoOfButtons = 0;

            NoOfDoubleLineButtons = 0;

            ////is it the current vessel?
            //if ((!ViewAlarmsOnly) && (KACWorkerGameState.CurrentVessel != null) && (FindVesselForAlarm(tmpAlarm).id.ToString() == KACWorkerGameState.CurrentVessel.id.ToString()))
            if ((KACWorkerGameState.CurrentGUIScene == GameScenes.FLIGHT) && (KACWorkerGameState.CurrentVessel != null) && (FindVesselForAlarm(tmpAlarm).id.ToString() == KACWorkerGameState.CurrentVessel.id.ToString()))
            {
                //There is a node and the alarm + Margin is not expired
                if ((tmpAlarm.ManNodes != null) && tmpAlarm.ManNodes.Count > 0)
                //if ((tmpAlarm.ManNodes != null) && ((tmpAlarm.Remaining.UT + tmpAlarm.AlarmMarginSecs) > 0))
                {
                    //Check if theres a Maneuver node and if so put a label saying that it already exists
                    //only display this node button if its the active ship
                    //Add this sae functionality to the alarm triggered window
                    //Add a jump to ship button if not the active ship
                    //As well as to the
                    String strRestoretext = "Restore Maneuver Node(s)";
                    if (KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes.Count > 0)
                    {
                        strRestoretext = "Replace Maneuver Node(s)";
                        //if the count and UT's are the same then go from there
                        if (!KACAlarm.CompareManNodeListSimple(KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes, tmpAlarm.ManNodes))
                        {
                            strRestoretext += "\r\nNOTE: There is already a Node on the flight path";
                        }
                        else
                        {
                            strRestoretext += "\r\nNOTE: These nodes appear to be already set on the flight path";
                        }
                        NoOfDoubleLineButtons++;
                    }
                    if ((tmpAlarm.Remaining.UT + tmpAlarm.AlarmMarginSecs) < 0)
                    {
                        strRestoretext += "\r\nWARNING: The stored Nodes are in the past";
                        NoOfDoubleLineButtons++;
                    }
                    intReturnNoOfButtons++;
                    if (GUILayout.Button(strRestoretext, KACResources.styleButton))
                    {
                        LogFormatted("Attempting to add Node");
                        KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes.Clear();
                        RestoreManeuverNodeList(tmpAlarm.ManNodes);
                    }
                }
                //There is a stored Target, that hasnt passed
                //if ((tmpAlarm.TargetObject != null) && ((tmpAlarm.Remaining.UT + tmpAlarm.AlarmMarginSecs) > 0))
                if ((tmpAlarm.TargetObject != null))
                {
                    String strRestoretext = "Restore Target";
                    if (KACWorkerGameState.CurrentVesselTarget != null)
                    {
                        strRestoretext = "Replace Target";
                        if (KACWorkerGameState.CurrentVesselTarget != tmpAlarm.TargetObject)
                        {
                            strRestoretext += "\r\nNOTE: There is already a target and this will change";
                        }
                        else
                        {
                            strRestoretext += "\r\nNOTE: This already appears to be the target";
                        }
                        NoOfDoubleLineButtons++;
                    }
                    intReturnNoOfButtons++;
                    if (GUILayout.Button(strRestoretext, KACResources.styleButton))
                    {
                        if (tmpAlarm.TargetObject is Vessel)
                        {
                            FlightGlobals.fetch.SetVesselTarget(tmpAlarm.TargetObject as Vessel);
                        }
                        else if (tmpAlarm.TargetObject is CelestialBody)
                        {
                            FlightGlobals.fetch.SetVesselTarget(tmpAlarm.TargetObject as CelestialBody);
                        }
                    }
                }
            }
            else
            {
                //not current vessel
                //There is a node and the alarm + Margin is not expired
                //if (tmpAlarm.ManNodes != null && tmpAlarm.Remaining.UT + tmpAlarm.AlarmMarginSecs > 0)
                if (tmpAlarm.ManNodes != null && tmpAlarm.ManNodes.Count > 0)
                {
                    String strRestoretext = "Jump To Ship and Restore Maneuver Node";
                    if (tmpAlarm.TypeOfAlarm == KACAlarm.AlarmTypeEnum.Crew)
                    {
                        strRestoretext = strRestoretext.Replace("Ship", "Kerbal");
                    }
                    if ((tmpAlarm.Remaining.UT + tmpAlarm.AlarmMarginSecs) < 0)
                    {
                        strRestoretext += "\r\nWARNING: The stored Nodes are in the past";
                        NoOfDoubleLineButtons++;
                    }
                    intReturnNoOfButtons++;

                    if (GUILayout.Button(strRestoretext, KACResources.styleButton))
                    {
                        Vessel tmpVessel = FindVesselForAlarm(tmpAlarm);

                        if (JumpToVessel(tmpVessel))
                        {
                            //Set the Node in memory to restore once the ship change has completed
                            settings.LoadManNode = KACAlarm.ManNodeSerializeList(tmpAlarm.ManNodes);
                            settings.Save();
                        }
                    }
                }

                //There is a target and the alarm has not expired
                //if (tmpAlarm.TargetObject != null && tmpAlarm.Remaining.UT + tmpAlarm.AlarmMarginSecs > 0)
                if (tmpAlarm.TargetObject != null)
                {
                    intReturnNoOfButtons++;
                    String strButtonT = "Jump To Ship and Restore Target";
                    if (tmpAlarm.TypeOfAlarm == KACAlarm.AlarmTypeEnum.Crew)
                    {
                        strButtonT = strButtonT.Replace("Ship", "Kerbal");
                    }
                    if (GUILayout.Button(strButtonT, KACResources.styleButton))
                    {
                        Vessel tmpVessel = FindVesselForAlarm(tmpAlarm);

                        if (JumpToVessel(tmpVessel))
                        {
                            //Set the Target in persistant file to restore once the ship change has completed...
                            settings.LoadVesselTarget = KACAlarm.TargetSerialize(tmpAlarm.TargetObject);
                            settings.Save();
                        }
                    }
                }

                intReturnNoOfButtons++;
                //Or just jump to ship - regardless of alarm time
                String strButton = "Jump To Ship";
                if (tmpAlarm.TypeOfAlarm == KACAlarm.AlarmTypeEnum.Crew)
                {
                    strButton = strButton.Replace("Ship", "Kerbal");
                }
                if (GUILayout.Button(strButton, KACResources.styleButton))
                {
                    Vessel tmpVessel = FindVesselForAlarm(tmpAlarm);
                    // tmpVessel.MakeActive();

                    JumpToVessel(tmpVessel);
                }

                //////////////////////////////////////////////////////////////////////////////////
                // Focus Vessel Code - reflecting to get SetVessel Focus in TS
                //////////////////////////////////////////////////////////////////////////////////
                if (KACWorkerGameState.CurrentGUIScene == GameScenes.TRACKSTATION)
                {
                    Vessel vTarget = FlightGlobals.Vessels.FirstOrDefault(v => v.id.ToString().ToLower() == tmpAlarm.VesselID);
                    if (vTarget != null)
                    {
                        intReturnNoOfButtons++;
                        if (GUILayout.Button("Set Vessel Active", KACResources.styleButton))
                        {
                            SetVesselActiveInTS(vTarget);

                            //FlightGlobals.Vessels.ForEach(v =>
                            //    {
                            //        v.DetachPatchedConicsSolver();
                            //        v.orbitRenderer.isFocused = false;
                            //    });

                            //vTarget.orbitRenderer.isFocused = true;
                            //vTarget.AttachPatchedConicsSolver();
                            //FlightGlobals.SetActiveVessel(vTarget);

                            //SpaceTracking.GoToAndFocusVessel(vTarget);
                            //st.mainCamera.SetTarget(getVesselIdx(vTarget));
                        }
                    }
                    //}
                }
            }
            return(intReturnNoOfButtons);
        }
示例#19
0
        private int DrawTransferAngleButtons(KACAlarm tmpAlarm)
        {
            if ((tmpAlarm.TypeOfAlarm == KACAlarm.AlarmTypeEnum.Transfer || tmpAlarm.TypeOfAlarm == KACAlarm.AlarmTypeEnum.TransferModelled) &&
                (HighLogic.LoadedScene == GameScenes.TRACKSTATION || HighLogic.LoadedScene == GameScenes.FLIGHT))
            {
                //right type of alarm, now is the text there
                Match matchPhase      = Regex.Match(tmpAlarm.Notes, "(?<=Phase\\sAngle\\:\\s+)\\S+(?=°)");
                Match matchEjectPro   = Regex.Match(tmpAlarm.Notes, "(?<=Ejection\\sAngle\\:\\s+)\\S+(?=°\\sto\\sprograde)");
                Match matchEjectRetro = Regex.Match(tmpAlarm.Notes, "(?<=Ejection\\sAngle\\:\\s+)\\S+(?=°\\sto\\sretrograde)");
                if (matchPhase.Success && (matchEjectPro.Success || matchEjectRetro.Success))
                {
                    try
                    {
                        //LogFormatted_DebugOnly("{0}", matchPhase.Value);
                        Double dblPhase = Convert.ToDouble(matchPhase.Value);
                        Double dblEject;
                        if (matchEjectPro.Success)
                        {
                            dblEject = Convert.ToDouble(matchEjectPro.Value);
                        }
                        else
                        {
                            dblEject = Convert.ToDouble(matchEjectRetro.Value);
                        }

                        GUILayout.BeginHorizontal();

                        CelestialBody cbOrigin = FlightGlobals.Bodies.Single(b => b.bodyName == tmpAlarm.XferOriginBodyName);
                        CelestialBody cbTarget = FlightGlobals.Bodies.Single(b => b.bodyName == tmpAlarm.XferTargetBodyName);

                        GUIStyle styleAngleButton = new GUIStyle(KACResources.styleSmallButton)
                        {
                            fixedWidth = 180
                        };

                        if (DrawToggle(ref blnShowPhaseAngle, "Show Phase Angle", styleAngleButton))
                        {
                            if (blnShowPhaseAngle)
                            {
                                EjectAngle.HideAngle();
                                blnShowEjectAngle = false;
                                PhaseAngle.DrawAngle(cbOrigin, cbTarget, dblPhase);
                            }
                            else
                            {
                                PhaseAngle.HideAngle();
                            }
                        }
                        if (DrawToggle(ref blnShowEjectAngle, "Show Eject Angle", styleAngleButton))
                        {
                            if (blnShowEjectAngle)
                            {
                                PhaseAngle.HideAngle();
                                blnShowPhaseAngle = false;
                                EjectAngle.DrawAngle(cbOrigin, dblEject, matchEjectRetro.Success);
                            }
                            else
                            {
                                EjectAngle.HideAngle();
                            }
                        }
                        GUILayout.EndHorizontal();

                        //if (GUILayout.Toggle()) {

                        //}
                        //GUILayout.Label(String.Format("P:{0} - E:{1}",dblPhase,dblEject));

                        return(1);
                    }
                    catch (Exception)
                    {
                        GUILayout.Label("Unable to decipher TWP Phase and Eject Angle found in notes");
                        return(1);
                    }
                }
                else
                {
                    GUILayout.Label("No TWP Phase and Eject Angle found in notes");
                    return(1);
                }
            }
            else
            {
                return(0);
            }
        }
示例#20
0
        internal void FillAlarmWindow(int windowID)
        {
            KACAlarm tmpAlarm = alarms.GetByWindowID(windowID);

            GUILayout.BeginVertical();

            GUILayout.BeginVertical(GUI.skin.textArea);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Alarm Time:", KACResources.styleAlarmMessageTime);
            if (tmpAlarm.TypeOfAlarm != KACAlarm.AlarmTypeEnum.EarthTime)
            {
                GUILayout.Label(tmpAlarm.AlarmTime.ToStringStandard(settings.DateTimeFormat), KACResources.styleAlarmMessageTime);
            }
            else
            {
                GUILayout.Label(EarthTimeDecode(tmpAlarm.AlarmTime.UT).ToLongTimeString(), KACResources.styleAlarmMessageTime);
            }
            if (tmpAlarm.TypeOfAlarm != KACAlarm.AlarmTypeEnum.Raw && tmpAlarm.TypeOfAlarm != KACAlarm.AlarmTypeEnum.EarthTime && tmpAlarm.TypeOfAlarm != KACAlarm.AlarmTypeEnum.Crew && tmpAlarm.TypeOfAlarm != KACAlarm.AlarmTypeEnum.ScienceLab)
            {
                GUILayout.Label("(m: " + new KSPTimeSpan(tmpAlarm.AlarmMarginSecs).ToStringStandard(settings.TimeSpanFormat, 3) + ")", KACResources.styleAlarmMessageTime);
            }
            GUILayout.EndHorizontal();

            GUILayout.Label(tmpAlarm.Notes, KACResources.styleAlarmMessage);

            GUILayout.BeginHorizontal();
            DrawCheckbox(ref tmpAlarm.Actions.DeleteWhenDone, "Delete On Close", 0);
            if (tmpAlarm.PauseGame)
            {
                if (FlightDriver.Pause)
                {
                    GUILayout.Label("Game paused", KACResources.styleAlarmMessageActionPause);
                }
                else
                {
                    GUILayout.Label("Alarm paused game, but has been unpaused", KACResources.styleAlarmMessageActionPause);
                }
            }
            else if (tmpAlarm.HaltWarp)
            {
                GUILayout.Label("Time Warp Halted", KACResources.styleAlarmMessageAction);
            }
            GUILayout.EndHorizontal();
            if (tmpAlarm.TypeOfAlarm == KACAlarm.AlarmTypeEnum.Crew)
            {
                DrawStoredCrewMissing(tmpAlarm.VesselID);
            }
            else
            {
                DrawStoredVesselIDMissing(tmpAlarm.VesselID);
            }
            GUILayout.EndVertical();

            int intNoOfActionButtons           = 0;
            int intNoOfActionButtonsDoubleLine = 0;

            //if the alarm has a vessel ID/Kerbal associated
            if (CheckVesselOrCrewForJump(tmpAlarm.VesselID, tmpAlarm.TypeOfAlarm))
            {
                //option to allow jumping from SC and TS
                if (settings.AllowJumpFromViewOnly)
                {
                    intNoOfActionButtons = DrawAlarmActionButtons(tmpAlarm, out intNoOfActionButtonsDoubleLine);
                }
            }

            intNoOfActionButtons += DrawTransferAngleButtons(tmpAlarm);

            //Work out the text
            String strText = "Close Alarm";

            if (tmpAlarm.PauseGame)
            {
                if (FlightDriver.Pause)
                {
                    strText = "Close Alarm and Unpause";
                }
            }
            //Now draw the button
            if (GUILayout.Button(strText, KACResources.styleButton))
            {
                tmpAlarm.AlarmWindowClosed = true;

                //Stop playing the sound if it is playing
                if (audioController.isPlaying)
                {
                    audioController.Stop();
                }

                //tmpAlarm.ActionedAt = KACWorkerGameState.CurrentTime.UT;
                if (tmpAlarm.PauseGame)
                {
                    FlightDriver.SetPause(false);
                }

                try {
                    APIInstance_AlarmStateChanged(tmpAlarm, AlarmStateEventsEnum.Closed);
                } catch (Exception ex) {
                    MonoBehaviourExtended.LogFormatted("Error Raising API Event-Closed Alarm: {0}\r\n{1}", ex.Message, ex.StackTrace);
                }

                if (tmpAlarm.Actions.DeleteWhenDone)
                {
                    alarms.Remove(tmpAlarm);
                }
                //settings.SaveAlarms();
            }

            GUILayout.EndVertical();

            int intLines = tmpAlarm.Notes.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length;

            if (intLines == 0)
            {
                intLines = 1;
            }
            tmpAlarm.AlarmWindowHeight = 148 +
                                         intLines * 16 +
                                         intNoOfActionButtons * 32 +
                                         intNoOfActionButtonsDoubleLine * 14;

            SetTooltipText();
            GUI.DragWindow();
        }
        internal static KACAlarm LoadFromString3(String AlarmDetails, Double CurrentUT)
        {
            //String is "VesselID|Name|Notes|AlarmTime.UT|AlarmMarginSecs|Type|Enabled|HaltWarp|PauseGame|ActionedAt|Maneuver|Xfer|Target|Options|<ENDLINE>");

            String[] vars = AlarmDetails.Split("|".ToCharArray(), StringSplitOptions.None);

            MonoBehaviourExtended.LogFormatted("AlarmExtract");
            for (int i = 0; i < vars.Length; i++)
            {
                MonoBehaviourExtended.LogFormatted("{0}:{1}", i, vars[i]);
            }

            String SaveName        = HighLogic.CurrentGame.Title;
            String VesselID        = vars[0];
            String Name            = KACUtils.DecodeVarStrings(vars[1]);
            String Notes           = KACUtils.DecodeVarStrings(vars[2]);
            Double UT              = Convert.ToDouble(vars[3]);
            Double AlarmMarginSecs = Convert.ToDouble(vars[4]);

            KACAlarm.AlarmTypeEnum TypeOfAlarm = (KACAlarm.AlarmTypeEnum)Enum.Parse(typeof(KACAlarm.AlarmTypeEnum), vars[5]);
            Boolean Enabled    = Convert.ToBoolean(vars[6]);
            Boolean HaltWarp   = Convert.ToBoolean(vars[7]);
            Boolean PauseGame  = Convert.ToBoolean(vars[8]);
            Double  ActionedAt = Convert.ToDouble(vars[9]);

            List <ManeuverNode> ManNodes = null;
            String      XferOriginBodyName = "", XferTargetBodyName = "";
            ITargetable TargetObject = null;
            String      TargetLoader = "";

            Boolean Triggered = false, Actioned = false, AlarmWindowClosed = false;

            if (vars[10] != "")
            {
                ManNodes = ManNodeDeserializeList(vars[10]);
            }

            if (vars[11] != "")
            {
                try
                {
                    MonoBehaviourExtended.LogFormatted("{0}", vars[11]);
                    String[] XferParts = vars[11].Split(",".ToCharArray());
                    XferOriginBodyName = XferParts[0];
                    XferTargetBodyName = XferParts[1];
                }
                catch (Exception ex)
                {
                    MonoBehaviourExtended.LogFormatted("Unable to load transfer details for {0}", Name);
                    MonoBehaviourExtended.LogFormatted(ex.Message);
                }
            }
            if (vars[12] != "")
            {
                //find the targetable object and set it
                TargetObject = TargetDeserialize(vars[12]);
                if (TargetObject == null && vars[12].StartsWith("Vessel,"))
                {
                    TargetLoader = vars[12];
                }
            }

            //Now do the work to set Actioned/triggered/etc if needed
            //LogFormatted("A:{0},T:{1:0},Act:{2:0}", this.Name, CurrentUT, this.ActionedAt);
            if (ActionedAt > 0 && CurrentUT > ActionedAt)
            {
                MonoBehaviourExtended.LogFormatted("Suppressing Alarm on Load:{0}", Name);
                Triggered         = true;
                Actioned          = true;
                AlarmWindowClosed = true;
            }
            else if (ActionedAt > CurrentUT)
            {
                MonoBehaviourExtended.LogFormatted("Reenabling Alarm on Load:{0}", Name);
                Triggered         = false;
                Actioned          = false;
                ActionedAt        = 0;
                AlarmWindowClosed = false;
            }

            KACAlarm resultAlarm = new KACAlarm(UT);

            resultAlarm.Name            = Name;
            resultAlarm.VesselID        = VesselID;
            resultAlarm.Enabled         = Enabled;
            resultAlarm.Notes           = Notes;
            resultAlarm.AlarmMarginSecs = AlarmMarginSecs;
            resultAlarm.TypeOfAlarm     = TypeOfAlarm;
            if (HaltWarp)
            {
                resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.KillWarp;
            }
            else if (PauseGame)
            {
                resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.PauseGame;
            }

            if (ManNodes != null)
            {
                resultAlarm.ManNodes = ManNodes;
            }
            if (TargetObject != null)
            {
                resultAlarm.TargetObject = TargetObject;
            }
            resultAlarm.TargetLoader = TargetLoader;

            resultAlarm.XferOriginBodyName = XferOriginBodyName;
            resultAlarm.XferTargetBodyName = XferTargetBodyName;

            resultAlarm.Triggered         = Triggered;
            resultAlarm.Actioned          = Actioned;
            resultAlarm.AlarmWindowClosed = AlarmWindowClosed;

            return(resultAlarm);
        }
        // <summary>
        // Basically deserializing the alarm
        // </summary>
        // <param name="AlarmDetails"></param>
        //internal static KACAlarm LoadFromString(String AlarmDetails)
        //{
        //    String[] vars = AlarmDetails.Split("|".ToCharArray());
        //    String VesselID = "";
        //    String SaveName = vars[0];
        //    String Name = vars[1];
        //    Boolean Enabled = Convert.ToBoolean(vars[2]);
        //    Double UT = Convert.ToDouble(vars[3]);
        //    Boolean HaltWarp = Convert.ToBoolean(vars[4]);
        //    Boolean PauseGame = false;
        //    String Notes = "";
        //    if (vars.Length == 6)
        //        Notes = vars[5];
        //    else
        //    {
        //        PauseGame = Convert.ToBoolean(vars[5]);
        //        Notes = vars[6];
        //    }

        //    KACAlarm resultAlarm = new KACAlarm(UT);
        //    resultAlarm.Name = Name;
        //    resultAlarm.Enabled = Enabled;
        //    resultAlarm.Notes = Notes;
        //    resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.MessageOnly;
        //    if (HaltWarp)
        //        resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.KillWarp;
        //    else if (PauseGame)
        //        resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.PauseGame;

        //    return resultAlarm;
        //}

        internal static KACAlarm LoadFromString2(String AlarmDetails)
        {
            String[] vars            = AlarmDetails.Split("|".ToCharArray(), StringSplitOptions.None);
            String   SaveName        = HighLogic.CurrentGame.Title;
            String   VesselID        = vars[0];
            String   Name            = vars[1];
            String   Notes           = vars[2];
            Double   UT              = Convert.ToDouble(vars[3]);
            Double   AlarmMarginSecs = Convert.ToDouble(vars[4]);

            KACAlarm.AlarmTypeEnum TypeOfAlarm = (KACAlarm.AlarmTypeEnum)Enum.Parse(typeof(KACAlarm.AlarmTypeEnum), vars[5]);
            Boolean Enabled   = Convert.ToBoolean(vars[6]);
            Boolean HaltWarp  = Convert.ToBoolean(vars[7]);
            Boolean PauseGame = Convert.ToBoolean(vars[8]);

            String strOptions = vars[9];

            List <ManeuverNode> ManNodes = null;
            String      XferOriginBodyName = "", XferTargetBodyName = "";
            ITargetable TargetObject = null;
            String      TargetLoader = "";

            switch (TypeOfAlarm)
            {
            case KACAlarm.AlarmTypeEnum.Maneuver:
                //Generate the Nodes List from the string
                ManNodes = ManNodeDeserializeList(strOptions);
                break;

            case KACAlarm.AlarmTypeEnum.Transfer:
                try
                {
                    String[] XferParts = strOptions.Split(",".ToCharArray());
                    XferOriginBodyName = XferParts[0];
                    XferTargetBodyName = XferParts[1];
                }
                catch (Exception ex)
                {
                    MonoBehaviourExtended.LogFormatted("Unable to load transfer details for {0}", Name);
                    MonoBehaviourExtended.LogFormatted(ex.Message);
                }
                break;

            case KACAlarm.AlarmTypeEnum.AscendingNode:
            case KACAlarm.AlarmTypeEnum.DescendingNode:
            case KACAlarm.AlarmTypeEnum.LaunchRendevous:
                if (strOptions != "")
                {
                    //find the targetable object and set it
                    TargetObject = TargetDeserialize(strOptions);
                    if (TargetObject == null && strOptions.StartsWith("Vessel,"))
                    {
                        TargetLoader = strOptions;
                    }
                }
                break;

            default:
                break;
            }

            KACAlarm resultAlarm = new KACAlarm(UT);

            resultAlarm.Name            = Name;
            resultAlarm.VesselID        = VesselID;
            resultAlarm.Enabled         = Enabled;
            resultAlarm.Notes           = Notes;
            resultAlarm.AlarmMarginSecs = AlarmMarginSecs;
            resultAlarm.TypeOfAlarm     = TypeOfAlarm;
            if (HaltWarp)
            {
                resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.KillWarp;
            }
            else if (PauseGame)
            {
                resultAlarm.AlarmAction = KACAlarm.AlarmActionEnum.PauseGame;
            }

            if (ManNodes != null)
            {
                resultAlarm.ManNodes = ManNodes;
            }
            if (TargetObject != null)
            {
                resultAlarm.TargetObject = TargetObject;
            }
            resultAlarm.TargetLoader = TargetLoader;

            resultAlarm.XferOriginBodyName = XferOriginBodyName;
            resultAlarm.XferTargetBodyName = XferTargetBodyName;

            return(resultAlarm);
        }
示例#23
0
 public AlarmStateChangedEventArgs(KACAlarm alarm, AlarmStateEventsEnum eventType)
 {
     this.alarm     = alarm;
     this.eventType = eventType;
 }
示例#24
0
        public void Load()
        {
            try
            {
                KACWorker.DebugLogFormatted("Loading Config");
                KSP.IO.PluginConfiguration configfile = KSP.IO.PluginConfiguration.CreateForType <KerbalAlarmClock>();
                configfile.load();

                this.DailyVersionCheck = configfile.GetValue("DailyUpdateCheck", true);

                try { this.VersionCheckDate_Attempt = DateTime.ParseExact(configfile.GetValue("VersionCheckDate_Attempt", ""), "yyyy-MM-dd", CultureInfo.CurrentCulture); }
                catch (Exception) { this.VersionCheckDate_Attempt = new DateTime(); }

                try { this.VersionCheckDate_Success = DateTime.ParseExact(configfile.GetValue("VersionCheckDate_Success", ""), "yyyy-MM-dd", CultureInfo.CurrentCulture); }
                catch (Exception) { this.VersionCheckDate_Success = new DateTime(); }

                this.VersionWeb = configfile.GetValue("VersionWeb", "");

                this.WindowVisible   = configfile.GetValue("WindowVisible", false);
                this.WindowMinimized = configfile.GetValue("WindowMinimized", false);
                this.WindowPos       = configfile.GetValue <Rect>("WindowPos", new Rect(3, 55, 300, 45));

                this.WindowVisible_SpaceCenter   = configfile.GetValue("WindowVisible_SpaceCenter", false);
                this.WindowMinimized_SpaceCenter = configfile.GetValue("WindowMinimized_SpaceCenter", false);
                this.WindowPos_SpaceCenter       = configfile.GetValue <Rect>("WindowPos_SpaceCenter", new Rect(3, 36, 300, 45));

                this.WindowVisible_TrackingStation   = configfile.GetValue("WindowVisible_TrackingStation", false);
                this.WindowMinimized_TrackingStation = configfile.GetValue("WindowMinimized_TrackingStation", false);
                this.WindowPos_TrackingStation       = configfile.GetValue <Rect>("WindowPos_TrackingStation", new Rect(202, 45, 300, 45));

                this.IconPos                        = configfile.GetValue <Rect>("IconPos", new Rect(152, 0, 32, 32));
                this.IconPos.height                 = 32; this.IconPos.width = 32;
                this.IconPos_SpaceCenter            = configfile.GetValue <Rect>("IconPos_SpaceCenter", new Rect(3, 3, 32, 32));
                this.IconPos_SpaceCenter.height     = 32; this.IconPos_TrackingStation.width = 32;
                this.IconPos_TrackingStation        = configfile.GetValue <Rect>("IconPos_TrackingStation", new Rect(196, 0, 32, 32));
                this.IconPos_TrackingStation.height = 32; this.IconPos_TrackingStation.width = 32;

                this.IconShow_SpaceCenter     = configfile.GetValue("IconShow_SpaceCenter", true);
                this.IconShow_TrackingStation = configfile.GetValue("IconShow_TrackingStation", true);

                this.UseBlizzyToolbarIfAvailable = configfile.GetValue <Boolean>("UseBlizzyToolbarIfAvailable", true);
                this.WindowMinimizedType         = (MiminalDisplayType)configfile.GetValue("WindowMinimizedType", 0);

                this.KSCUIBlockersEnabled = configfile.GetValue <Boolean>("UIBlockersEnabled", true);

                this.BehaviourChecksPerSec        = configfile.GetValue("BehaviourChecksPerSec", 10);
                this.BehaviourChecksPerSec_Custom = configfile.GetValue("BehaviourChecksPerSecCustom", 40);

                this.BackupSaves       = configfile.GetValue("BackupSaves", true);
                this.BackupSavesToKeep = configfile.GetValue("BackupSavesToKeep", 20);
                this.CancelFlightModeJumpOnBackupFailure = configfile.GetValue("CancelFlightModeJumpOnBackupFailure", false);

                this.AllowJumpFromViewOnly = configfile.GetValue("AllowJumpFromViewOnly", true);
                this.AllowJumpToAsteroid   = configfile.GetValue("AllowJumpToAsteroid", false);

                this.AlarmListMaxAlarms = configfile.GetValue("AlarmListMaxAlarms", "10");
                this.AlarmDefaultAction = configfile.GetValue <int>("AlarmDefaultAction", 1);
                this.AlarmDefaultMargin = configfile.GetValue <Double>("AlarmDefaultMargin", 60);
                this.AlarmPosition      = configfile.GetValue <int>("AlarmPosition", 1);
                this.AlarmDeleteOnClose = configfile.GetValue("AlarmDeleteOnClose", false);
                this.ShowTooltips       = configfile.GetValue("ShowTooltips", true);
                this.ShowEarthTime      = configfile.GetValue("ShowEarthTime", false);
                this.HideOnPause        = configfile.GetValue("HideOnPause", true);
                String strTimeFormat = configfile.GetValue("TimeFormat", "KSPString");
                //KACWorker.DebugLogFormatted("{0}",strTimeFormat);
                this.TimeFormat = (KACTime.PrintTimeFormat)Enum.Parse(typeof(KACTime.PrintTimeFormat), strTimeFormat);
                //this.TimeFormat = configfile.GetValue<KACTime.PrintTimeFormat>("TimeFormat", KACTime.PrintTimeFormat.KSPString);
                //KACWorker.DebugLogFormatted("{0}",this.TimeFormat.ToString());
                if (configfile.GetValue <bool>("TimeAsUT", false) == true)
                {
                    KACWorker.DebugLogFormatted("Forcing New Format");
                    this.TimeFormat = KACTime.PrintTimeFormat.TimeAsUT;
                    configfile.SetValue("TimeAsUT", false);
                    configfile.SetValue("TimeFormat", Enum.GetName(typeof(KACTime.PrintTimeFormat), this.TimeFormat));
                    configfile.save();
                }

                this.AlarmXferRecalc          = configfile.GetValue("AlarmXferRecalc", true);
                this.AlarmXferRecalcThreshold = configfile.GetValue <Double>("AlarmXferRecalcThreshold", 180);
                this.AlarmXferDisplayList     = configfile.GetValue("AlarmXferDisplayList", false);
                this.XferUseModelData         = configfile.GetValue("XferUseModelData", false);

                this.AlarmNodeRecalc          = configfile.GetValue("AlarmNodeRecalc", false);
                this.AlarmNodeRecalcThreshold = configfile.GetValue <Double>("AlarmNodeRecalcThreshold", 180);

                this.AlarmAddSOIAuto          = configfile.GetValue("AlarmAddSOIAuto", false);
                this.AlarmAddSOIAutoThreshold = configfile.GetValue <Double>("AlarmAddSOIAutoThreshold", 180);
                //this.AlarmAddSOIMargin = configfile.GetValue("AlarmAddSOIMargin", 120);
                this.AlarmAutoSOIMargin         = configfile.GetValue <Double>("AlarmAutoSOIMargin", 900);
                this.AlarmAddSOIAuto_ExcludeEVA = configfile.GetValue("AlarmAddSOIAuto_ExcludeEVA", true);
                this.AlarmCatchSOIChange        = configfile.GetValue("AlarmOnSOIChange", false);
                this.AlarmOnSOIChange_Action    = configfile.GetValue("AlarmOnSOIChange_Action", 1);

                this.AlarmSOIRecalc          = configfile.GetValue("AlarmSOIRecalc", false);
                this.AlarmSOIRecalcThreshold = configfile.GetValue <Double>("AlarmSOIRecalcThreshold", 180);

                this.AlarmAddManAuto           = configfile.GetValue("AlarmAddManAuto", false);
                this.AlarmAddManAuto_andRemove = configfile.GetValue("AlarmAddManAuto_andRemove", false);
                this.AlarmAddManAutoThreshold  = configfile.GetValue <Double>("AlarmAddManAutoThreshold", 180);
                this.AlarmAddManAutoMargin     = configfile.GetValue <Double>("AlarmAddManAutoMargin", 180);
                this.AlarmAddManAuto_Action    = configfile.GetValue("AlarmAddManAuto_Action", 1);

                this.AlarmCrewDefaultStoreNode = configfile.GetValue("AlarmCrewDefaultStoreNode", false);

                this.LoadManNode      = configfile.GetValue("LoadManNode", "");
                this.LoadVesselTarget = configfile.GetValue("LoadVesselTarget", "");

                if (KSP.IO.File.Exists <KerbalAlarmClock>(String.Format("Alarms-{0}.txt", HighLogic.CurrentGame.Title)))
                {
                    KACWorker.DebugLogFormatted("Trying New Alarms file...");
                    LoadAlarms();
                }
                else
                {
                    //Loop through numbers to Load Alarms
                    Alarms = new KACAlarmList();
                    int    intAlarm = 0;
                    String strAlarm = "";
                    do
                    {
                        strAlarm = configfile.GetValue("Alarm_" + intAlarm, "");
                        KACWorker.DebugLogFormatted(strAlarm);
                        if (strAlarm != "")
                        {
                            KACAlarm tmpAlarm = new KACAlarm();
                            tmpAlarm.LoadFromString(strAlarm);
                            Alarms.Add(tmpAlarm);
                            intAlarm++;
                        }
                    } while (strAlarm != "");
                }
                KACWorker.DebugLogFormatted("Config Loaded Successfully");
            }

            catch (Exception ex)
            {
                KACWorker.DebugLogFormatted("Failed To Load Config");
                KACWorker.DebugLogFormatted(ex.Message);
            }
        }
示例#25
0
 public static int SortByUT(KACAlarm c1, KACAlarm c2)
 {
     return(c1.Remaining.UT.CompareTo(c2.Remaining.UT));
 }
        private void WindowLayout_AddPane_ClosestApproach()
        {
            GUILayout.BeginVertical();
            GUILayout.Label(strAlarmEventName + " Details...", KACResources.styleAddSectionHeading);

            if (KACWorkerGameState.CurrentVessel == null)
            {
                GUILayout.Label("No Active Vessel");
            }
            else
            {
                if (!(KACWorkerGameState.CurrentVesselTarget is Vessel) && !(KACWorkerGameState.CurrentVesselTarget is ModuleDockingNode))
                {
                    GUILayout.Label("No valid Vessel Target Selected", GUILayout.ExpandWidth(true));
                }
                else
                {
                    //GUILayout.Label("Adjust Lookahead amounts...", KACResources.styleAddSectionHeading);

                    GUILayout.BeginVertical(KACResources.styleAddFieldAreas);

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Orbits to Search:", KACResources.styleAddHeading, GUILayout.Width(110));
                    GUILayout.Label(((int)Math.Round((Decimal)fltOrbits, 0)).ToString(), KACResources.styleAddXferName, GUILayout.Width(25));
                    fltOrbits = GUILayout.HorizontalSlider(fltOrbits, 1, 20);
                    fltOrbits = (float)Math.Floor((Decimal)fltOrbits);
                    GUILayout.EndHorizontal();

                    intOrbits = (int)fltOrbits;
                    int    intClosestOrbitPass = 0;
                    double dblClosestDistance  = Double.MaxValue;
                    double dblClosestUT        = 0;

                    double dblOrbitTestClosest   = Double.MaxValue;
                    double dblOrbitTestClosestUT = 0;
                    if (KACWorkerGameState.CurrentVessel.orbit.eccentricity > 1)
                    {
                        intOrbits = 1;
                    }
                    for (int intOrbitToTest = 1; intOrbitToTest <= intOrbits; intOrbitToTest++)
                    {
                        dblOrbitTestClosestUT = KACUtils.timeOfClosestApproach(KACWorkerGameState.CurrentVessel.orbit,
                                                                               KACWorkerGameState.CurrentVesselTarget.GetOrbit(),
                                                                               KACWorkerGameState.CurrentTime.UT,
                                                                               intOrbitToTest,
                                                                               out dblOrbitTestClosest
                                                                               );
                        if (dblOrbitTestClosest < dblClosestDistance)
                        {
                            dblClosestDistance  = dblOrbitTestClosest;
                            dblClosestUT        = dblOrbitTestClosestUT;
                            intClosestOrbitPass = intOrbitToTest;
                        }
                    }


                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Distance:", KACResources.styleAddHeading, GUILayout.Width(70));
                    String strDistance = string.Format("{0:#}m", dblClosestDistance);
                    if (dblClosestDistance > 999)
                    {
                        strDistance = string.Format("{0:#.0}km", dblClosestDistance / 1000);
                    }
                    GUILayout.Label(strDistance, KACResources.styleAddXferName, GUILayout.Width(90));
                    GUILayout.Label("On Orbit:", KACResources.styleAddHeading);
                    GUILayout.Label(intClosestOrbitPass.ToString(), KACResources.styleAddXferName);
                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();


                    String      strMarginConversion = "";
                    KSPDateTime eventTime           = new KSPDateTime(dblClosestUT);
                    KSPTimeSpan eventInterval       = new KSPTimeSpan(dblClosestUT - KACWorkerGameState.CurrentTime.UT);

                    KSPDateTime eventAlarm;
                    KSPTimeSpan eventAlarmInterval;
                    try
                    {
                        eventAlarm         = new KSPDateTime(eventTime.UT - timeMargin.UT);
                        eventAlarmInterval = new KSPTimeSpan(eventTime.UT - KACWorkerGameState.CurrentTime.UT - timeMargin.UT);
                    }
                    catch (Exception)
                    {
                        eventAlarm          = null;
                        eventAlarmInterval  = null;
                        strMarginConversion = "Unable to Add the Margin Minutes";
                    }

                    if ((eventTime.UT > KACWorkerGameState.CurrentTime.UT) && strMarginConversion == "")
                    {
                        if (DrawAddAlarm(eventTime, eventInterval, eventAlarmInterval))
                        {
                            KACAlarm newAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(), strAlarmName, strAlarmNotes,
                                                             eventAlarm.UT, timeMargin.UT, AddType,
                                                             AddActions);
                            newAlarm.TargetObject = KACWorkerGameState.CurrentVesselTarget;
                            newAlarm.ManNodes     = KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes;

                            alarms.Add(newAlarm);
                            //settings.Save();
                            _ShowAddPane = false;
                        }
                    }
                    else
                    {
                        strMarginConversion = "No Future Closest Approach found";
                    }

                    if (strMarginConversion != "")
                    {
                        GUILayout.Label(strMarginConversion, GUILayout.ExpandWidth(true));
                    }
                }
            }

            GUILayout.EndVertical();
        }
        private void WindowLayout_AddPane_TargetDistance()
        {
            intAddDistanceHeight = 262;// 272;
            GUILayout.BeginVertical();
            GUILayout.Label(strAlarmEventName + " Details...", KACResources.styleAddSectionHeading);

            //What are the possible targets??
            List <ITargetable> iTargets = new List <ITargetable>();

            if (!(KACWorkerGameState.CurrentVesselTarget == null))
            {
                iTargets.Add(KACWorkerGameState.CurrentVesselTarget);   //VesselTarget
            }
            iTargets.Add(KACWorkerGameState.CurrentVessel.mainBody);    //Body we are orbiting
            if (KACWorkerGameState.SOIPointExists)
            {
                iTargets.Add(KACWorkerGameState.CurrentVessel.orbit.nextPatch.referenceBody);   //Body we will orbit next
            }

            if (intSelectediTarget > iTargets.Count - 1)
            {
                intSelectediTarget = 0;
            }

            intAddDistanceHeight += (iTargets.Count * 30);

            //Now give the user the choice
            GUILayout.BeginHorizontal();
            GUILayout.Label("Select Target:", KACResources.styleAddXferName);
            if (DrawRadioListVertical(ref intSelectediTarget, iTargets.Select(x => x.GetName()).ToArray()))
            {
                Log.info("Distance Target is:{0}", iTargets[intSelectediTarget].GetName());
            }
            GUILayout.EndHorizontal();

            //Set the tgt Object
            tgtSelectedDistance = iTargets[intSelectediTarget];
            string strDistanceName = "Distance";

            if (tgtSelectedDistance is CelestialBody)
            {
                strDistanceName = "Altitude";
            }

            //Ask for the target distance/altitude
            GUILayout.BeginHorizontal();
            GUILayout.Label(string.Format("Target {0} (m):", strDistanceName), KACResources.styleAddXferName);
            dblTargetDistance = Convert.ToDouble(GUILayout.TextField(dblTargetDistance.ToString(), KACResources.styleAddField));
            GUILayout.EndHorizontal();

            //If the body has an atmosphere then add an option to set the Altitude straight to that
            if (tgtSelectedDistance is CelestialBody)
            {
                if ((tgtSelectedDistance as CelestialBody).atmosphere)
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label(string.Format("Atmosphere: {0}", (tgtSelectedDistance as CelestialBody).atmosphereDepth));
                    if (GUILayout.Button("Set to Edge"))
                    {
                        dblTargetDistance = (tgtSelectedDistance as CelestialBody).atmosphereDepth;
                    }
                    GUILayout.EndHorizontal();
                    intAddDistanceHeight += 26;
                }
            }

            //For a vessel give some options for orbits to look forwards
            GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
            if (!(tgtSelectedDistance is CelestialBody))
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Orbits to Search:", KACResources.styleAddHeading, GUILayout.Width(110));
                GUILayout.Label(((int)Math.Round((Decimal)fltOrbits_Distance, 0)).ToString(), KACResources.styleAddXferName, GUILayout.Width(25));
                fltOrbits_Distance = GUILayout.HorizontalSlider(fltOrbits_Distance, 1, 20);
                fltOrbits_Distance = (float)Math.Floor((Decimal)fltOrbits_Distance);
                GUILayout.EndHorizontal();
                intAddDistanceHeight += 18;
            }

            //What VesselOrbit do we care about
            Orbit VesselOrbitToCompare = KACWorkerGameState.CurrentVessel.GetOrbit();

            if ((KACWorkerGameState.SOIPointExists) && ((tgtSelectedDistance as CelestialBody) == KACWorkerGameState.CurrentVessel.orbit.nextPatch.referenceBody))
            {
                VesselOrbitToCompare = KACWorkerGameState.CurrentVessel.orbit.nextPatch;
            }
            //Get the startUT of the orbit
            Double VesselOrbitStartUT = KACWorkerGameState.CurrentVessel.GetOrbit().StartUT;

            //Set up some variables
            intOrbits_Distance = (int)fltOrbits_Distance;
            int    intDistanceOrbitPass = 0;
            double dblClosestDistance   = Double.MaxValue;
            double dblDistanceUT        = 0;

            double dblOrbitTestDistance   = Double.MaxValue;
            double dblOrbitTestDistanceUT = 0;

            //If its an Altitude alarm then do this
            if (tgtSelectedDistance is CelestialBody)
            {
                dblOrbitTestDistanceUT = KACUtils.timeOfTargetAltitude(VesselOrbitToCompare,
                                                                       VesselOrbitStartUT,
                                                                       out dblOrbitTestDistance,
                                                                       dblTargetDistance
                                                                       );

                dblClosestDistance = dblOrbitTestDistance;
                dblDistanceUT      = dblOrbitTestDistanceUT;
            }
            else
            {
                //Else Iterate through the orbits to find the target separation
                for (int intOrbitToTest = 1; intOrbitToTest <= intOrbits_Distance; intOrbitToTest++)
                {
                    dblOrbitTestDistanceUT = KACUtils.timeOfTargetDistance(VesselOrbitToCompare,
                                                                           tgtSelectedDistance.GetOrbit(),
                                                                           KACWorkerGameState.CurrentTime.UT,
                                                                           intOrbitToTest,
                                                                           out dblOrbitTestDistance,
                                                                           dblTargetDistance
                                                                           );

                    if (dblOrbitTestDistance < dblClosestDistance)
                    {
                        dblClosestDistance   = dblOrbitTestDistance;
                        dblDistanceUT        = dblOrbitTestDistanceUT;
                        intDistanceOrbitPass = intOrbitToTest;
                    }
                }
            }

            //Now display what we got
            GUILayout.BeginHorizontal();
            GUILayout.Label(String.Format("{0}:", strDistanceName), KACResources.styleAddHeading, GUILayout.Width(70));
            String strDistance = string.Format("{0:#}m", dblClosestDistance);

            if (dblClosestDistance > 999)
            {
                strDistance = string.Format("{0:#.0}km", dblClosestDistance / 1000);
            }
            GUILayout.Label(strDistance, KACResources.styleAddXferName, GUILayout.Width(90));
            if (!(tgtSelectedDistance is CelestialBody))
            {
                GUILayout.Label("On Orbit:", KACResources.styleAddHeading);
                GUILayout.Label(intDistanceOrbitPass.ToString(), KACResources.styleAddXferName);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            //Now do the stuff to draw the alarm button
            String      strMarginConversion = "";
            KSPDateTime eventTime           = new KSPDateTime(dblDistanceUT);
            KSPTimeSpan eventInterval       = new KSPTimeSpan(dblDistanceUT - KACWorkerGameState.CurrentTime.UT);

            KSPDateTime eventAlarm;
            KSPTimeSpan eventAlarmInterval;

            try
            {
                eventAlarm         = new KSPDateTime(eventTime.UT - timeMargin.UT);
                eventAlarmInterval = new KSPTimeSpan(eventTime.UT - KACWorkerGameState.CurrentTime.UT - timeMargin.UT);
            }
            catch (Exception)
            {
                eventAlarm          = null;
                eventAlarmInterval  = null;
                strMarginConversion = "Unable to Add the Margin Minutes";
            }

            if ((eventTime.UT > KACWorkerGameState.CurrentTime.UT) && strMarginConversion == "")
            {
                if (DrawAddAlarm(eventTime, eventInterval, eventAlarmInterval))
                {
                    KACAlarm newAlarm = new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(), strAlarmName, strAlarmNotes,
                                                     eventAlarm.UT, timeMargin.UT, AddType,
                                                     AddActions);
                    newAlarm.TargetObject = KACWorkerGameState.CurrentVesselTarget;
                    newAlarm.ManNodes     = KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes;

                    alarms.Add(newAlarm);
                    //settings.Save();
                    _ShowAddPane = false;
                }
            }
            else
            {
                strMarginConversion = "No Target Distance Approach found";
            }

            if (strMarginConversion != "")
            {
                GUILayout.Label(strMarginConversion, GUILayout.ExpandWidth(true));
            }

            GUILayout.EndVertical();
        }
        public void FillAlarmWindow(int windowID)
        {
            KACAlarm tmpAlarm = Settings.Alarms.GetByWindowID(windowID);

            GUILayout.BeginVertical();

            GUILayout.BeginVertical(GUI.skin.textArea);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Alarm Time:", KACResources.styleAlarmMessageTime);
            if (tmpAlarm.TypeOfAlarm != KACAlarm.AlarmType.EarthTime)
            {
                GUILayout.Label(KACTime.PrintDate(tmpAlarm.AlarmTime, Settings.TimeFormat), KACResources.styleAlarmMessageTime);
            }
            else
            {
                GUILayout.Label(EarthTimeDecode(tmpAlarm.AlarmTime.UT).ToLongTimeString(), KACResources.styleAlarmMessageTime);
            }
            if (tmpAlarm.TypeOfAlarm != KACAlarm.AlarmType.Raw && tmpAlarm.TypeOfAlarm != KACAlarm.AlarmType.EarthTime && tmpAlarm.TypeOfAlarm != KACAlarm.AlarmType.Crew)
            {
                GUILayout.Label("(m: " + KACTime.PrintInterval(new KACTime(tmpAlarm.AlarmMarginSecs), 3, Settings.TimeFormat) + ")", KACResources.styleAlarmMessageTime);
            }
            GUILayout.EndHorizontal();

            GUILayout.Label(tmpAlarm.Notes, KACResources.styleAlarmMessage);

            GUILayout.BeginHorizontal();
            DrawCheckbox(ref tmpAlarm.DeleteOnClose, "Delete On Close", 0);
            if (tmpAlarm.PauseGame)
            {
                if (FlightDriver.Pause)
                {
                    GUILayout.Label("Game paused", KACResources.styleAlarmMessageActionPause);
                }
                else
                {
                    GUILayout.Label("Alarm paused game, but has been unpaused", KACResources.styleAlarmMessageActionPause);
                }
            }
            else if (tmpAlarm.HaltWarp)
            {
                GUILayout.Label("Time Warp Halted", KACResources.styleAlarmMessageAction);
            }
            GUILayout.EndHorizontal();
            if (tmpAlarm.TypeOfAlarm == KACAlarm.AlarmType.Crew)
            {
                DrawStoredCrewMissing(tmpAlarm.VesselID);
            }
            else
            {
                DrawStoredVesselIDMissing(tmpAlarm.VesselID);
            }
            GUILayout.EndVertical();

            int intNoOfActionButtons           = 0;
            int intNoOfActionButtonsDoubleLine = 0;

            //if the alarm has a vessel ID/Kerbal associated
            if (CheckVesselOrCrewForJump(tmpAlarm.VesselID, tmpAlarm.TypeOfAlarm))
            {
                //option to allow jumping from SC and TS
                if (Settings.AllowJumpFromViewOnly)
                {
                    intNoOfActionButtons = DrawAlarmActionButtons(tmpAlarm, out intNoOfActionButtonsDoubleLine);
                }
            }

            //Work out the text
            String strText = "Close Alarm";

            if (tmpAlarm.PauseGame)
            {
                if (FlightDriver.Pause)
                {
                    strText = "Close Alarm and Unpause";
                }
            }
            //Now draw the button
            if (GUILayout.Button(strText, KACResources.styleButton))
            {
                tmpAlarm.AlarmWindowClosed = true;
                tmpAlarm.ActionedAt        = KACWorkerGameState.CurrentTime.UT;
                if (tmpAlarm.PauseGame)
                {
                    FlightDriver.SetPause(false);
                }
                if (tmpAlarm.DeleteOnClose)
                {
                    Settings.Alarms.Remove(tmpAlarm);
                }
                Settings.SaveAlarms();
            }

            GUILayout.EndVertical();

            int intLines = tmpAlarm.Notes.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length;

            if (intLines == 0)
            {
                intLines = 1;
            }
            tmpAlarm.AlarmWindowHeight = 148 +
                                         intLines * 16 +
                                         intNoOfActionButtons * 32 +
                                         intNoOfActionButtonsDoubleLine * 14;

            SetTooltipText();
            GUI.DragWindow();
        }