public static void SetLastFlightStatesToCurrent() { KACWorkerGameState.LastSaveGameName = KACWorkerGameState.CurrentSaveGameName; KACWorkerGameState.LastTime = KACWorkerGameState.CurrentTime; if (LastVessel != CurrentVessel) { if (VesselChanged != null) { VesselChanged(LastVessel, CurrentVessel); } } KACWorkerGameState.LastVessel = KACWorkerGameState.CurrentVessel; KACWorkerGameState.LastSOIBody = KACWorkerGameState.CurrentSOIBody; KACWorkerGameState.LastVesselTarget = KACWorkerGameState.CurrentVesselTarget; }
public static String PrintDate(KACTime timeTemp, KACTime.PrintTimeFormat TimeFormat) { switch (TimeFormat) { case PrintTimeFormat.TimeAsUT: return(timeTemp.UTString()); case PrintTimeFormat.KSPString: return(timeTemp.DateString()); case PrintTimeFormat.DateTimeString: return(timeTemp.DateTimeString()); default: return(timeTemp.DateTimeString()); } }
public static String PrintInterval(KACTime timeTemp, int Segments, KACTime.PrintTimeFormat TimeFormat) { switch (TimeFormat) { case PrintTimeFormat.TimeAsUT: return(timeTemp.UTString()); case PrintTimeFormat.KSPString: return(timeTemp.IntervalString(Segments)); case PrintTimeFormat.DateTimeString: return(timeTemp.IntervalDateTimeString(Segments)); default: return(timeTemp.IntervalString(Segments)); } }
public void BuildFromUT(Double UT) { KACTime timeTemp = new KACTime(UT); if (TimeEntryPrecision >= TimeEntryPrecisionEnum.Years) { Years = timeTemp.Year.ToString(); } else { Years = "0"; } if (TimeEntryPrecision > TimeEntryPrecisionEnum.Days) { Days = timeTemp.Day.ToString(); } else if (TimeEntryPrecision == TimeEntryPrecisionEnum.Days) { Days = ((timeTemp.Year * timeTemp.DaysPerYear) + timeTemp.Day).ToString(); } else { Days = "0"; } if (TimeEntryPrecision > TimeEntryPrecisionEnum.Hours) { Hours = timeTemp.Hour.ToString(); } else if (TimeEntryPrecision == TimeEntryPrecisionEnum.Hours) { Hours = ((timeTemp.Year * timeTemp.HoursPerYear) + (timeTemp.Day * timeTemp.HoursPerDay) + timeTemp.Hour).ToString(); } else { Hours = "0"; } Minutes = timeTemp.Minute.ToString(); Seconds = timeTemp.Second.ToString(); }
/// <summary> /// Build the UT from raw values /// </summary> /// <param name="Years"></param> /// <param name="Days"></param> /// <param name="Hours"></param> /// <param name="Minutes"></param> /// <param name="Seconds"></param> public void BuildUT(double Years, double Days, double Hours, double Minutes, double Seconds) { UT = KACTime.BuildUTFromRaw(Years, Days, Hours, Minutes, Seconds); }
public static String PrintInterval(KACTime timeTemp, KACTime.PrintTimeFormat TimeFormat) { return(PrintInterval(timeTemp, 3, TimeFormat)); }
public void FillEditWindow(int WindowID) { if (alarmEdit.Remaining.UT > 0) { //Edit the Alarm if its not yet passed int intActionSelected = 0; if (alarmEdit.HaltWarp) { intActionSelected = 1; } if (alarmEdit.PauseGame) { intActionSelected = 2; } Double MarginStarting = alarmEdit.AlarmMarginSecs; int intHeight_EditWindowCommon = 88 + alarmEdit.Notes.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length * 16; if (alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.Raw && alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.EarthTime && alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.Crew) { intHeight_EditWindowCommon += 28; } WindowLayout_CommonFields(ref alarmEdit.Name, ref alarmEdit.Notes, ref intActionSelected, ref alarmEdit.AlarmMarginSecs, alarmEdit.TypeOfAlarm, intHeight_EditWindowCommon); //Adjust the UT of the alarm if the margin changed if (alarmEdit.AlarmMarginSecs != MarginStarting) { alarmEdit.AlarmTime.UT += MarginStarting - alarmEdit.AlarmMarginSecs; } //Draw warning if the vessel no longer exists if (alarmEdit.TypeOfAlarm == KACAlarm.AlarmType.Crew) { DrawStoredCrewMissing(alarmEdit.VesselID); } else { DrawStoredVesselIDMissing(alarmEdit.VesselID); } //Draw the old and new times GUILayout.BeginHorizontal(); if (alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.Raw && alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.EarthTime && alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.Crew) { GUILayout.Label("Time To Alarm:", KACResources.styleContent); GUILayout.Label(KACTime.PrintInterval(new KACTime(alarmEdit.AlarmTime.UT - KACWorkerGameState.CurrentTime.UT), Settings.TimeFormat), KACResources.styleAddHeading); } GUILayout.Label("Time To Event:", KACResources.styleContent); if (alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.EarthTime) { GUILayout.Label(KACTime.PrintInterval(new KACTime(alarmEdit.AlarmTime.UT + alarmEdit.AlarmMarginSecs - KACWorkerGameState.CurrentTime.UT), Settings.TimeFormat), KACResources.styleAddHeading); } else { GUILayout.Label(KACTime.PrintInterval(new KACTime(alarmEdit.Remaining.UT), KACTime.PrintTimeFormat.DateTimeString), KACResources.styleAddHeading); } GUILayout.EndHorizontal(); alarmEdit.HaltWarp = (intActionSelected > 0); alarmEdit.PauseGame = (intActionSelected > 1); int intNoOfActionButtons = 0; int intNoOfActionButtonsDoubleLine = 0; //if the alarm has a vessel ID/Kerbal associated if (CheckVesselOrCrewForJump(alarmEdit.VesselID, alarmEdit.TypeOfAlarm)) { //option to allow jumping from SC and TS if (Settings.AllowJumpFromViewOnly) { intNoOfActionButtons = DrawAlarmActionButtons(alarmEdit, out intNoOfActionButtonsDoubleLine); } } if (GUILayout.Button("Close Alarm Details", KACResources.styleButton)) { Settings.Save(); _ShowEditPane = false; } //TODO: Edit the height of this for when we have big text in restore button intAlarmEditHeight = 197 + alarmEdit.Notes.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length * 16 + intNoOfActionButtons * 32 + intNoOfActionButtonsDoubleLine * 14; if (alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.Raw && alarmEdit.TypeOfAlarm != KACAlarm.AlarmType.Crew) { intAlarmEditHeight += 28; } } else { //otherwise just show the details GUILayout.BeginVertical(GUI.skin.textArea); GUILayout.BeginHorizontal(); GUILayout.Label("Alarm:", KACResources.styleAlarmMessageTime); GUILayout.Label(alarmEdit.Name, KACResources.styleAlarmMessageTime); GUILayout.EndHorizontal(); GUILayout.Label(alarmEdit.Notes, KACResources.styleAlarmMessage); //Draw warning if the vessel no longer exists if (alarmEdit.TypeOfAlarm == KACAlarm.AlarmType.Crew) { DrawStoredCrewMissing(alarmEdit.VesselID); } else { DrawStoredVesselIDMissing(alarmEdit.VesselID); } GUILayout.EndVertical(); int intNoOfActionButtons = 0; int intNoOfActionButtonsDoubleLine = 0; //if the alarm has a vessel ID/Kerbal associated if (CheckVesselOrCrewForJump(alarmEdit.VesselID, alarmEdit.TypeOfAlarm)) { //option to allow jumping from SC and TS if (Settings.AllowJumpFromViewOnly) { intNoOfActionButtons = DrawAlarmActionButtons(alarmEdit, out intNoOfActionButtonsDoubleLine); } } if (GUILayout.Button("Close Alarm Details", KACResources.styleButton)) { _ShowEditPane = false; } intAlarmEditHeight = 112 + alarmEdit.Notes.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Length * 16 + intNoOfActionButtons * 32 + intNoOfActionButtonsDoubleLine * 14; } SetTooltipText(); }
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(); }
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; 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 = ""; KACTime eventTime = new KACTime(dblClosestUT); KACTime eventInterval = new KACTime(dblClosestUT - KACWorkerGameState.CurrentTime.UT); KACTime eventAlarm; KACTime eventAlarmInterval; try { eventAlarm = new KACTime(eventTime.UT - timeMargin.UT); eventAlarmInterval = new KACTime(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, (AddAction == KACAlarm.AlarmAction.KillWarp), (AddAction == KACAlarm.AlarmAction.PauseGame)); newAlarm.TargetObject = KACWorkerGameState.CurrentVesselTarget; newAlarm.ManNodes = KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes; Settings.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 = 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())) { DebugLogFormatted("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.ToInt32(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).maxAtmosphereAltitude)); if (GUILayout.Button("Set to Edge")) { dblTargetDistance = (tgtSelectedDistance as CelestialBody).maxAtmosphereAltitude; } 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 = ""; KACTime eventTime = new KACTime(dblDistanceUT); KACTime eventInterval = new KACTime(dblDistanceUT - KACWorkerGameState.CurrentTime.UT); KACTime eventAlarm; KACTime eventAlarmInterval; try { eventAlarm = new KACTime(eventTime.UT - timeMargin.UT); eventAlarmInterval = new KACTime(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, (AddAction == KACAlarm.AlarmAction.KillWarp), (AddAction == KACAlarm.AlarmAction.PauseGame)); newAlarm.TargetObject = KACWorkerGameState.CurrentVesselTarget; newAlarm.ManNodes = KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes; Settings.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 FillEarthAlarmWindow(int WindowID) { GUILayout.BeginVertical(); intHeight_AddWindowCommon = 64; WindowLayout_CommonFields2(ref strAlarmName, ref blnAlarmAttachToVessel, ref AddAction, ref timeMargin, AddType, intHeight_AddWindowCommon); GUILayout.Label("Enter Time for reminder...", KACResources.styleAddSectionHeading); GUILayout.BeginVertical(KACResources.styleAddFieldAreas); GUILayout.BeginHorizontal(); GUILayout.Label("Time for Alarm (24 hour):", KACResources.styleAddHeading); GUILayout.FlexibleSpace(); if (DrawTimeField(ref strAlarmEarthHour, "", 40, 0)) { if (strAlarmEarthHour.Length > 2) { strAlarmEarthHour = strAlarmEarthHour.Substring(strAlarmEarthHour.Length - 2, 2); } } GUILayout.Label(":", KACResources.styleAlarmMessageTime, GUILayout.Width(3)); //strAlarmEarthMin = GUILayout.TextField(strAlarmEarthMin, KACResources.styleAddField, GUILayout.Width(40)); if (DrawTimeField(ref strAlarmEarthMin, "", 40, 0)) { if (strAlarmEarthMin.Length > 2) { strAlarmEarthMin = strAlarmEarthMin.Substring(strAlarmEarthMin.Length - 2, 2); } } GUILayout.EndHorizontal(); GUILayout.EndVertical(); try { DateTime dteWorking; dteWorking = DateTime.ParseExact(strAlarmEarthHour + ":" + strAlarmEarthMin, "H:m", null); TimeSpan tmAlarm = (dteWorking.TimeOfDay - DateTime.Now.TimeOfDay); if (tmAlarm.TotalSeconds < 0) { tmAlarm = tmAlarm.Add(new TimeSpan(24, 0, 0)); } KACTime TimeToAlarm = new KACTime(tmAlarm.TotalSeconds); //Bit at the bottom to add an alarm int intLineHeight = 18; GUILayout.BeginHorizontal(KACResources.styleAddAlarmArea); GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.Label("Date:", KACResources.styleAddHeading, GUILayout.Height(intLineHeight), GUILayout.Width(40), GUILayout.MaxWidth(40)); GUILayout.Label(dteWorking.ToLongTimeString(), KACResources.styleContentEarth, GUILayout.Height(intLineHeight)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Time to Alarm:", KACResources.styleAddHeading, GUILayout.Height(intLineHeight), GUILayout.Width(100), GUILayout.MaxWidth(100)); GUILayout.Label(KACTime.PrintInterval(TimeToAlarm, KACTime.PrintTimeFormat.DateTimeString), KACResources.styleContentEarth, GUILayout.Height(intLineHeight)); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.Space(10); int intButtonHeight = 36; if (GUILayout.Button("Add Alarm", KACResources.styleButton, GUILayout.Width(90), GUILayout.Height(intButtonHeight))) { Settings.Alarms.Add( new KACAlarm(null, strAlarmName, strAlarmNotes, EarthTimeEncode(DateTime.Now + tmAlarm), 0, KACAlarm.AlarmType.EarthTime, (AddAction == KACAlarm.AlarmAction.KillWarp), (AddAction == KACAlarm.AlarmAction.PauseGame)) ); Settings.SaveAlarms(); _ShowEarthAlarm = false; } GUILayout.EndHorizontal(); } catch (Exception) { GUILayout.Label("Unable to determine Earth Time", GUILayout.ExpandWidth(true)); } GUILayout.EndVertical(); SetTooltipText(); }