Esempio n. 1
0
 /// <summary>Compares two KSPPluginFramework.KSPTimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.</summary> 
 /// <param name="t1">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <param name="t2">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <returns>Value Condition -1 t1 is shorter than t20 t1 is equal to t21 t1 is longer than t2</returns>
 public static Int32 Compare(KSPTimeSpan t1, KSPTimeSpan t2)
 {
     if (t1.UT < t2.UT)
         return -1;
     else if (t1.UT > t2.UT)
         return 1;
     else
         return 0;
 }
        /// <summary>Initializes a new instance of the System.DateTime structure to the specified year, day, hour, minute, and second.</summary>
        /// <param name="year">The year</param>
        /// <param name="day">The day of the year</param>
        /// <param name="hour">The hour</param>
        /// <param name="minute">The minute</param>
        /// <param name="second">The second</param>
        /// <param name="millisecond">The milliseconds</param>
        public KSPDateTime(int year, int day, int hour, int minute, int second, int millisecond)
        {
            //Test for entering values outside the norm - eg 25 hours, day 600

            UT = new KSPTimeSpan((Int32)((year - KSPDateStructure.EpochYear) * KSPDateStructure.DaysPerYear) +
                                 (day - KSPDateStructure.EpochDayOfYear),
                                 hour,
                                 minute,
                                 second,
                                 millisecond
                                 ).UT;
        }
Esempio n. 3
0
 /// <summary>Compares two KSPPluginFramework.KSPTimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.</summary>
 /// <param name="t1">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <param name="t2">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <returns>Value Condition -1 t1 is shorter than t20 t1 is equal to t21 t1 is longer than t2</returns>
 public static Int32 Compare(KSPTimeSpan t1, KSPTimeSpan t2)
 {
     if (t1.UT < t2.UT)
     {
         return(-1);
     }
     else if (t1.UT > t2.UT)
     {
         return(1);
     }
     else
     {
         return(0);
     }
 }
        private void SetWindowStrings()
        {
            //KSPDateTime kTime = new KSPDateTime(DepartureMin);
            //strDepartureMinYear = (kTime.Year ).ToString();
            //strDepartureMinDay = (kTime.Day).ToString();

            //kTime.UT = DepartureMax;
            //strDepartureMaxYear = (kTime.Year).ToString();
            //strDepartureMaxDay = (kTime.Day).ToString();

            dateMinDeparture = new KSPDateTime(DepartureMin);
            dateMaxDeparture = new KSPDateTime(DepartureMax);

            KSPTimeSpan kSpan = new KSPTimeSpan(0);
            kSpan.UT = TravelMin;
            strTravelMinDays = ((Int32)kSpan.TotalDays).ToString();

            kSpan.UT = TravelMax;
            strTravelMaxDays = ((Int32)kSpan.TotalDays).ToString();

            strArrivalAltitude = (InitialOrbitAltitude / 1000).ToString();
            strDepartureAltitude = (FinalOrbitAltitude / 1000).ToString();
        }
        private void WindowLayout_AddPane_Contract()
        {
            GUILayout.Label("Select Contract...", KACResources.styleAddSectionHeading);
            if (Contracts.ContractSystem.Instance == null)
            {
                GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
                GUILayout.Label("Jebediah digs around in the Sandbox, but can't\nfind any contracts in this game mode", KACResources.styleContent);
                GUILayout.EndVertical();
            }
            else
            {

                if (lstContracts.Count == 0)
                {
                    GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
                    GUILayout.Label("No Contracts Offered or Active", KACResources.styleContent);
                    GUILayout.EndVertical();
                }
                else
                {

                    scrollContract = GUILayout.BeginScrollView(scrollContract, KACResources.styleAddFieldAreas);

                    //If the selected contract is already an alarm then move the selected one
                    if (intSelectedContract == -1  || alarms.Any(a => a.ContractGUID == lstContracts[intSelectedContract].ContractGuid)){
                        intSelectedContract = -1;
                        for (int i = 0; i < lstContracts.Count; i++) {
                            if(!alarms.Any(a => a.ContractGUID == lstContracts[i].ContractGuid)){
                                intSelectedContract = i;
                                BuildContractStringsAndMargin();
                                break;
                            }
                        }
                    }

                    //Loop through the contracts to draw the lines
                    for (Int32 intTarget = 0; intTarget < lstContracts.Count; intTarget++)
                    {
                        Contract c = lstContracts[intTarget];
                        Boolean AlarmExists = alarms.Any(a => a.ContractGUID == c.ContractGuid);

                        GUILayout.BeginHorizontal();
                        //Appropriate icon
                        GUILayout.Space(5);
                        if (AlarmExists) {
                            GUILayout.Label(new GUIContent(KACResources.iconRaw, "Alarm Exists"), GUILayout.Width(20), GUILayout.Height(25));
                        } else if (c.ContractState == Contract.State.Active) {
                            GUILayout.Label(new GUIContent(KACResources.iconContract, "Active"), GUILayout.Width(20), GUILayout.Height(25));
                        } else {
                            GUILayout.Space(24);
                        }

                        //What style should the name be
                        GUIStyle styleContLabel = KACResources.styleContractLabelOffer;
                        if (c.ContractState == Contract.State.Active)
                            styleContLabel = KACResources.styleContractLabelActive;
                        else if (AlarmExists)
                            styleContLabel = KACResources.styleContractLabelAlarmExists;

                        if (GUILayout.Button(c.Title, styleContLabel, GUILayout.Width(243)))
                        {
                            if (!AlarmExists)
                            {
                                intSelectedContract = intTarget;
                                BuildContractStringsAndMargin();
                            }
                        };

                        //Is the check box on?
                        Boolean blnSelected = (intSelectedContract == intTarget);

                        if (!AlarmExists)
                        {
                            if (DrawToggle(ref blnSelected, "", KACResources.styleCheckbox, GUILayout.Width(20)))
                            {
                                if (blnSelected)
                                {
                                    intSelectedContract = intTarget;
                                    BuildContractStringsAndMargin();
                                }
                            }
                        } GUILayout.EndHorizontal();
                    }
                    GUILayout.EndScrollView();

                    if (intSelectedContract < 0) {
                        GUILayout.Label("All Contracts Have alarms set already", KACResources.styleContent);
                    } else {
                        //Draw the Add Alarm details at the bottom
                        //If its an interval add the interval to the current time
                        ContractTime = new KSPDateTime(lstContracts[intSelectedContract].DateNext());
                        ContractTimeToEvent = new KSPTimeSpan(lstContracts[intSelectedContract].DateNext() - KACWorkerGameState.CurrentTime.UT);
                        ContractTimeToAlarm = new KSPTimeSpan(ContractTimeToEvent.UT - timeMargin.UT);

                        if (DrawAddAlarm(ContractTime, ContractTimeToEvent, ContractTimeToAlarm))
                        {
                            //"VesselID, Name, Message, AlarmTime.UT, Type, Enabled,  HaltWarp, PauseGame, Maneuver"
                            String strVesselID = "";
                            if (KACWorkerGameState.CurrentVessel != null && blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();
                            KACAlarm tmpAlarm = new KACAlarm(strVesselID, strAlarmName, strAlarmNotes, KACWorkerGameState.CurrentTime.UT + ContractTimeToAlarm.UT,
                                timeMargin.UT, KACAlarm.AlarmTypeEnum.Contract, AddActions);

                            tmpAlarm.ContractGUID = lstContracts[intSelectedContract].ContractGuid;
                            tmpAlarm.ContractAlarmType = lstContracts[intSelectedContract].AlarmType();

                            alarms.Add(tmpAlarm);
                            //settings.Save();
                            _ShowAddPane = false;
                        }
                    }
                }
            }
        }
        private void WindowLayout_AddPane_Crew()
        {
            intAddCrewHeight = 304;// 322;
            GUILayout.Label("Select Crew...", KACResources.styleAddSectionHeading);
            if (KACWorkerGameState.CurrentVessel == null)
            {
                GUILayout.Label("No Active Vessel");
            }
            else
            {
                GUILayout.BeginVertical(KACResources.styleAddFieldAreas);

                //get the kerbals in the current vessel
                List<ProtoCrewMember> pCM = KACWorkerGameState.CurrentVessel.GetVesselCrew();
                intAddCrewHeight += (pCM.Count * 30);
                if (pCM.Count == 0)
                {
                    //Draw something about no crew present
                    GUILayout.Label("No Kerbals present in this vessel", KACResources.styleContent, GUILayout.ExpandWidth(true));
                }
                else
                {
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Kerbal Name", KACResources.styleAddSectionHeading, GUILayout.Width(267));
                    GUILayout.Label("Add", KACResources.styleAddSectionHeading);//, GUILayout.Width(30));
                    GUILayout.EndHorizontal();

                    for (int intTarget = 0; intTarget < pCM.Count; intTarget++)
                    {
                        //LogFormatted("{2}", pCM[intTarget].name);
                        GUILayout.BeginHorizontal();
                        //        //draw a line and a radio button for selecting Crew
                        GUILayout.Space(20);
                        GUILayout.Label(pCM[intTarget].name, KACResources.styleAddXferName, GUILayout.Width(240), GUILayout.Height(20));

                        //        //when they are selected adjust message to have a name of the crew member, and message of vessel when alarm was set
                        Boolean blnSelected = (intSelectedCrew == intTarget);
                        if (DrawToggle(ref blnSelected, "", KACResources.styleCheckbox, GUILayout.Width(40)))
                        {
                            if (blnSelected)
                            {
                                intSelectedCrew = intTarget;
                                BuildCrewStrings();
                            }
                        }
                        GUILayout.EndHorizontal();
                    }

                    DrawCheckbox(ref CrewAlarmStoreNode, "Store Man Node/Target with Crew Alarm");

                }
                GUILayout.EndVertical();

                if (pCM.Count > 0)
                {
                    //Now the time entry area
                    GUILayout.Label("Enter Time Values...", KACResources.styleAddSectionHeading);

                    GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Time type:", KACResources.styleAddHeading, GUILayout.Width(90));
                    if (DrawRadioList(ref intCrewType, new string[] { "Date", "Time Interval" }))
                    {
                        if (intRawType == 0)
                        {
                            rawEntry = new KACTimeStringArray(Planetarium.GetUniversalTime() + 600, KACTimeStringArray.TimeEntryPrecisionEnum.Years);
                        }
                    }
                    GUILayout.EndHorizontal();

                    if (intCrewType == 0)
                    {
                        //date
                        KACTimeStringArray CrewDate = new KACTimeStringArray(CrewEntry.UT + KSPDateStructure.EpochAsKSPDateTime.UT, KACTimeStringArray.TimeEntryPrecisionEnum.Years);
                        if (DrawTimeEntry(ref CrewDate, KACTimeStringArray.TimeEntryPrecisionEnum.Years, "Time:", 50, 35, 15))
                        {
                            rawEntry.BuildFromUT(CrewDate.UT - KSPDateStructure.EpochAsKSPDateTime.UT);
                        }
                    }
                    else
                    {
                        //interval
                        if (DrawTimeEntry(ref CrewEntry, KACTimeStringArray.TimeEntryPrecisionEnum.Years, "Time:", 50, 35, 15))
                        {

                        }
                    }
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("UT (raw seconds):", KACResources.styleAddHeading, GUILayout.Width(100));
                    strCrewUT = GUILayout.TextField(strCrewUT, KACResources.styleAddField);
                    GUILayout.EndHorizontal();
                    GUILayout.EndVertical();

                    try
                    {
                        if (strCrewUT != "")
                            CrewTime.UT = Convert.ToDouble(strCrewUT);
                        else
                            CrewTime.UT = CrewEntry.UT;

                        //If its an interval add the interval to the current time
                        if (intCrewType == 1)
                            CrewTime = new KSPDateTime(KACWorkerGameState.CurrentTime.UT + CrewTime.UT);

                        CrewTimeToAlarm = new KSPTimeSpan(CrewTime.UT - KACWorkerGameState.CurrentTime.UT);

                        //Draw the Add Alarm details at the bottom
                        if (DrawAddAlarm(CrewTime, null, CrewTimeToAlarm))
                        {
                            //"VesselID, Name, Message, AlarmTime.UT, Type, Enabled,  HaltWarp, PauseGame, Maneuver"
                            KACAlarm addAlarm = new KACAlarm(pCM[intSelectedCrew].name, strAlarmName, (blnRepeatingAlarmFlag ? "Alarm Repeats\r\n" : "") + strAlarmNotes, CrewTime.UT, 0, KACAlarm.AlarmTypeEnum.Crew,
                                AddActions);
                            if (CrewAlarmStoreNode)
                            {
                                if (KACWorkerGameState.ManeuverNodeExists) addAlarm.ManNodes = KACWorkerGameState.ManeuverNodesFuture;
                                if (KACWorkerGameState.CurrentVesselTarget != null) addAlarm.TargetObject = KACWorkerGameState.CurrentVesselTarget;
                            }
                            addAlarm.RepeatAlarm = blnRepeatingAlarmFlag;
                            addAlarm.RepeatAlarmPeriod = new KSPTimeSpan(timeRepeatPeriod.UT);

                            alarms.Add(addAlarm);
                            //settings.Save();
                            _ShowAddPane = false;
                        }
                    }
                    catch (Exception)
                    {
                        //    LogFormatted(ex.Message);
                        GUILayout.Label("Unable to combine all text fields to date", GUILayout.ExpandWidth(true));
                    }
                }
            }
        }
 /// <summary>Returns a new KSPPluginFramework.KSPDateTime object whose value is the sum of the specified KSPPluginFramework.KSPTimeSpan object and this instance.</summary> 
 /// <param name="value">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <returns>A KSPPluginFramework.KSPDateTime whose value is the sum of the date and time represented by this instance and the time interval represented by value.</returns>
 public KSPDateTime Add(KSPTimeSpan value)
 {
     return new KSPDateTime(UT + value.UT);
 }
 /// <summary>Initializes a new KSPPluginFramework.KSPTimeSpan to a specified number of days, hours, minutes, and seconds.</summary> 
 /// <param name="days">Number of days.</param>
 /// <param name="hours">Number of hours.</param>
 /// <param name="minutes">Number of minutes.</param>
 /// <param name="seconds">Number of seconds.</param>
 public KSPTimeSpan(int days, int hours, int minutes, int seconds)
 {
     UT = new KSPTimeSpan(days, hours, minutes, seconds, 0).UT;
 }
 /// <summary>Subtracts the specified duration from this instance.</summary>
 /// <param name="value">An instance of System.TimeSpan.</param>
 /// <returns>A System.DateTime equal to the date and time represented by this instance minus the time interval represented by value.</returns>
 public KSPTimeSpan Subtract(KSPTimeSpan value)
 {
     return(new KSPTimeSpan(UT - value.UT));
 }
Esempio n. 10
0
 /// <summary>Compares this instance to a specified KSPPluginFramework.KSPTimeSpan object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the KSPPluginFramework.KSPTimeSpan object.</summary>
 /// <param name="value">A KSPPluginFramework.KSPTimeSpan object to compare to this instance.</param>
 /// <returns>A signed number indicating the relative values of this instance and value.Value Description A negative integer This instance is shorter than value. Zero This instance is equal to value. A positive integer This instance is longer than value.</returns>
 public Int32 CompareTo(KSPTimeSpan value)
 {
     return(KSPTimeSpan.Compare(this, value));
 }
        public void BuildFromUT(Double UT)
        {
            KSPTimeSpan timeTemp = new KSPTimeSpan(UT);
            if (TimeEntryPrecision >= TimeEntryPrecisionEnum.Years)
                Years = timeTemp.Years.ToString();
            else
                Years = "0";

            if (TimeEntryPrecision > TimeEntryPrecisionEnum.Days)
                Days = timeTemp.Days.ToString();
            else if (TimeEntryPrecision == TimeEntryPrecisionEnum.Days)
                Days = ((timeTemp.Years * KSPDateStructure.DaysPerYear) + timeTemp.Days).ToString();
            else
                Days = "0";

            if (TimeEntryPrecision > TimeEntryPrecisionEnum.Hours)
                Hours = timeTemp.Hours.ToString();
            else if (TimeEntryPrecision == TimeEntryPrecisionEnum.Hours)
                Hours = ((timeTemp.Years * KSPDateStructure.HoursPerYear) + (timeTemp.Days * KSPDateStructure.HoursPerDay) + timeTemp.Hours).ToString();
            else
                Hours = "0";

            Minutes = timeTemp.Minutes.ToString();
            Seconds = timeTemp.Seconds.ToString();
        }
 /// <summary>Returns a new KSPPluginFramework.KSPTimeSpan object whose value is the sum of the specified KSPPluginFramework.KSPTimeSpan object and this instance.</summary> 
 /// <param name="value">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <returns>A new object that represents the value of this instance plus the value of the timespan supplied.</returns>
 public KSPTimeSpan Add(KSPTimeSpan value) {
     return new KSPTimeSpan(UT + value.UT);
 }
 /// <summary>Returns a value indicating whether two specified instances of KSPPluginFramework.KSPTimeSpan are equal.</summary> 
 /// <param name="t1">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <param name="t2">A TimeSpan.</param>
 /// <returns>true if the values of t1 and t2 are equal; otherwise, false.</returns>
 public static Boolean Equals(KSPTimeSpan t1, KSPTimeSpan t2)
 {
     return t1.UT == t2.UT;
 }
        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()))
            {
                LogFormatted("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();
        }
 /// <summary>Compares two KSPPluginFramework.KSPTimeSpan values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value.</summary> 
 /// <param name="t1">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <param name="t2">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <returns>Value Condition -1 t1 is shorter than t20 t1 is equal to t21 t1 is longer than t2</returns>
 public static Int32 Compare(KSPTimeSpan t1, KSPTimeSpan t2)
 {
     if (t1.UT < t2.UT)
         return -1;
     else if (t1.UT > t2.UT)
         return 1;
     else
         return 0;
 }
 /// <summary>Returns a value indicating whether this instance is equal to a specified KSPPluginFramework.KSPTimeSpan object.</summary> 
 /// <param name="value">An KSPPluginFramework.KSPTimeSpan object to compare with this instance.</param>
 /// <returns>true if obj represents the same time interval as this instance; otherwise, false.</returns>
 public Boolean Equals(KSPTimeSpan value) {
     return KSPTimeSpan.Equals(this, value);
 }
 /// <summary>Compares this instance to a specified KSPPluginFramework.KSPTimeSpan object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the KSPPluginFramework.KSPTimeSpan object.</summary> 
 /// <param name="value">A KSPPluginFramework.KSPTimeSpan object to compare to this instance.</param>
 /// <returns>A signed number indicating the relative values of this instance and value.Value Description A negative integer This instance is shorter than value. Zero This instance is equal to value. A positive integer This instance is longer than value.</returns>
 public Int32 CompareTo(KSPTimeSpan value) {
     return KSPTimeSpan.Compare(this, value);
 }
        private void SetWorkerVariables()
        {
            DepartureMin = dateMinDeparture.UT; // new KSPDateTime(strDepartureMinYear, strDepartureMinDay).UT; // new KSPDateTime(strDepartureMinYear, strDepartureMinDay, "0", "0", "0").UT - KSPDateStructure.SecondsPerYear - KSPDateStructure.SecondsPerDay;
            DepartureMax = dateMaxDeparture.UT; // new KSPDateTime(strDepartureMaxYear, strDepartureMaxDay).UT; // new KSPDateTime(strDepartureMaxYear, strDepartureMaxDay, "0", "0", "0").UT - KSPDateStructure.SecondsPerYear - KSPDateStructure.SecondsPerDay;
            DepartureRange = DepartureMax - DepartureMin;
            DepartureSelected = -1;
            TravelMin = new KSPTimeSpan(strTravelMinDays, "0", "0", "0").UT;
            TravelMax = new KSPTimeSpan(strTravelMaxDays, "0", "0", "0").UT;
            TravelRange = TravelMax - TravelMin;
            TravelSelected = -1;
            InitialOrbitAltitude = Convert.ToDouble(strDepartureAltitude) * 1000;
            if (blnFlyby)
                FinalOrbitAltitude = 0;
            else
                FinalOrbitAltitude = Convert.ToDouble(strArrivalAltitude) * 1000;

            //Store the transfer Specs for display purposes
            TransferSpecs = new TransferWorkerDetails();
            TransferSpecs.DepartureMin = DepartureMin;
            TransferSpecs.DepartureMax = DepartureMax;
            TransferSpecs.DepartureRange = DepartureRange;
            TransferSpecs.TravelMin = TravelMin;
            TransferSpecs.TravelMax = TravelMax;
            TransferSpecs.TravelRange = TravelRange;
            TransferSpecs.InitialOrbitAltitude = InitialOrbitAltitude;
            TransferSpecs.FinalOrbitAltitude = FinalOrbitAltitude;
            TransferSpecs.OriginName = cbOrigin.bodyName;
            TransferSpecs.DestinationName = cbDestination.bodyName;
            
            // minus 1 so when we loop from for PlotX pixels the last pixel is the actual last value
            xResolution = DepartureRange / (PlotWidth - 1);
            yResolution = TravelRange / (PlotHeight - 1);

            DeltaVs = new Double[PlotWidth * PlotHeight];
            DeltaVsColorIndex = new Int32[PlotWidth * PlotHeight];
        }
 /// <summary>Subtracts the specified duration from this instance.</summary>
 /// <param name="value">An instance of System.TimeSpan.</param>
 /// <returns>A System.DateTime equal to the date and time represented by this instance minus the time interval represented by value.</returns>
 public KSPTimeSpan Subtract(KSPTimeSpan value)
 {
     return new KSPTimeSpan(UT - value.UT);
 }
        internal void FillEarthAlarmWindow(int WindowID)
        {
            GUILayout.BeginVertical();

            intHeight_AddWindowCommon = 64;
            WindowLayout_CommonFields3(ref strAlarmName, ref blnAlarmAttachToVessel, ref AddActions, 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));

                KSPTimeSpan TimeToAlarm = new KSPTimeSpan(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(TimeToAlarm.ToStringStandard(TimeSpanStringFormatsEnum.DateTimeFormatLong), 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)))
                {
                    alarms.Add(
                        new KACAlarm(null,strAlarmName,strAlarmNotes,
                            EarthTimeEncode(DateTime.Now + tmAlarm),
                            0, KACAlarm.AlarmTypeEnum.EarthTime,
                            AddActions)
                        );
                    //settings.SaveAlarms();
                    _ShowEarthAlarm = false;
                }
                GUILayout.EndHorizontal();
            }
            catch (Exception)
            {
                GUILayout.Label("Unable to determine Earth Time", GUILayout.ExpandWidth(true));
            }

            GUILayout.EndVertical();

            SetTooltipText();
        }
        /// <summary>Initializes a new instance of the System.DateTime structure to the specified year, day, hour, minute, and second.</summary>
        /// <param name="year">The year</param>
        /// <param name="day">The day of the year</param>
        /// <param name="hour">The hour</param>
        /// <param name="minute">The minute</param>
        /// <param name="second">The second</param>
        /// <param name="millisecond">The milliseconds</param>
        public KSPDateTime(int year, int day, int hour, int minute, int second, int millisecond)
        {
            //Test for entering values outside the norm - eg 25 hours, day 600

            UT = new KSPTimeSpan((year - KSPDateStructure.EpochYear) * KSPDateStructure.DaysPerYear  +
                                (day - KSPDateStructure.EpochDayOfYear),
                                hour,
                                minute,
                                second,
                                millisecond
                                ).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;
                    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();
        }
        ////Variables for Node Alarms screen
        ////String strNodeMargin = "1";
        ///// <summary>
        ///// Screen Layout for adding Alarm from Maneuver Node
        ///// </summary>
        private void WindowLayout_AddPane_Maneuver()
        {
            if (HighLogic.LoadedScene == GameScenes.FLIGHT &&
                (KERWrapper.APIReady || VOIDWrapper.APIReady))
            {
                intHeight_AddWindowKER = 73;

                if (KACWorkerGameState.CurrentVessel == null)
                {
                    GUILayout.Label("No Active Vessel");
                }
                else
                {
                    if (!KACWorkerGameState.ManeuverNodeExists)
                    {
                        GUILayout.Label("No Maneuver Nodes Found", GUILayout.ExpandWidth(true));
                    }
                    else
                    {
                        if (KERWrapper.APIReady)
                        {
                            KERWrapper.KER.UpdateManNodeValues();
                            GUILayout.Label("Kerbal Engineer Node Margin", KACResources.styleAddSectionHeading);
                            GUILayout.BeginVertical(KACResources.styleAddFieldAreas);

                            GUILayout.BeginHorizontal();

                            GUILayout.Label("Add KER Burn Time: ", KACResources.styleAddHeading);
                            ddlKERNodeMargin.DrawButton();
                            GUILayout.EndHorizontal();

                            GUILayout.BeginHorizontal();
                            GUILayout.Label("Enough Δv:", KACResources.styleAddHeading);
                            GUILayout.Label(KERWrapper.KER.HasDeltaV.ToString(), KACResources.styleAddXferName);
                            GUILayout.Label("   Burn:", KACResources.styleAddHeading);
                            GUILayout.Label(String.Format("{0:0.0}s", KERWrapper.KER.BurnTime), KACResources.styleAddXferName);
                            GUILayout.Label("   ½ Burn:", KACResources.styleAddHeading);
                            GUILayout.Label(String.Format("{0:0.0}s", KERWrapper.KER.HalfBurnTime), KACResources.styleAddXferName);
                            GUILayout.EndHorizontal();

                            GUILayout.EndVertical();
                        }
                        else if (VOIDWrapper.APIReady)
                        {
                            GUILayout.Label("VOID Node Margin", KACResources.styleAddSectionHeading);
                            GUILayout.BeginVertical(KACResources.styleAddFieldAreas);

                            GUILayout.BeginHorizontal();

                            GUILayout.Label("Add VOID Burn Time: ", KACResources.styleAddHeading);
                            ddlKERNodeMargin.DrawButton();
                            GUILayout.EndHorizontal();

                            GUILayout.BeginHorizontal();
                            GUILayout.Label("Enough Δv:", KACResources.styleAddHeading);
                            GUILayout.Label(VOIDWrapper.VOID.HasDeltaV.ToString(), KACResources.styleAddXferName);
                            GUILayout.Label("   Burn:", KACResources.styleAddHeading);
                            GUILayout.Label(String.Format("{0:0.0}s", VOIDWrapper.VOID.BurnTime), KACResources.styleAddXferName);
                            GUILayout.Label("   ½ Burn:", KACResources.styleAddHeading);
                            GUILayout.Label(String.Format("{0:0.0}s", VOIDWrapper.VOID.HalfBurnTime), KACResources.styleAddXferName);
                            GUILayout.EndHorizontal();

                            GUILayout.EndVertical();
                        }
                    }
                }
            }
            else
            {
                intHeight_AddWindowKER = 0;
            }

            GUILayout.BeginVertical();
            GUILayout.Label("Node Details...", KACResources.styleAddSectionHeading);

            if (KACWorkerGameState.CurrentVessel == null)
            {
                GUILayout.Label("No Active Vessel");
            }
            else
            {
                if (!KACWorkerGameState.ManeuverNodeExists)
                {
                    GUILayout.Label("No Maneuver Nodes Found", GUILayout.ExpandWidth(true));
                }
                else
                {
                    Boolean blnFoundNode = false;
                    String strMarginConversion = "";
                    //loop to find the first future node
                    for (int intNode = 0; (intNode < KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes.Count) && !blnFoundNode; intNode++)
                    {
                        KSPDateTime nodeTime = new KSPDateTime(KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes[intNode].UT);
                        KSPTimeSpan nodeInterval = new KSPTimeSpan(nodeTime.UT - KACWorkerGameState.CurrentTime.UT);

                        KSPDateTime nodeAlarm;
                        KSPTimeSpan nodeAlarmInterval;

                        Double KERMarginAdd = GetBurnMarginSecs((Settings.BurnMarginEnum)ddlKERNodeMargin.SelectedIndex);

                        try
                        {
                            nodeAlarm = new KSPDateTime(nodeTime.UT - timeMargin.UT - KERMarginAdd);
                            nodeAlarmInterval = new KSPTimeSpan(nodeTime.UT - KACWorkerGameState.CurrentTime.UT - timeMargin.UT - KERMarginAdd);
                        }
                        catch (Exception)
                        {
                            nodeAlarm = null;
                            nodeAlarmInterval = null;
                            strMarginConversion = "Unable to Add the Margin Minutes";
                        }

                        if ((nodeTime.UT > KACWorkerGameState.CurrentTime.UT) && strMarginConversion == "")
                        {
                            if (DrawAddAlarm(nodeTime,nodeInterval,nodeAlarmInterval))
                            {
                                //Get a list of all future Maneuver Nodes - thats what the skip does
                                List<ManeuverNode> manNodesToStore = KACWorkerGameState.CurrentVessel.patchedConicSolver.maneuverNodes.Skip(intNode).ToList<ManeuverNode>();

                                alarms.Add(new KACAlarm(KACWorkerGameState.CurrentVessel.id.ToString(), strAlarmName, strAlarmNotes, nodeAlarm.UT, timeMargin.UT + KERMarginAdd, KACAlarm.AlarmTypeEnum.Maneuver,
                                    AddActions, manNodesToStore));
                                //settings.Save();
                                _ShowAddPane = false;
                            }
                            blnFoundNode = true;
                        }
                    }

                    if (strMarginConversion != "")
                        GUILayout.Label(strMarginConversion, GUILayout.ExpandWidth(true));
                    else if (!blnFoundNode)
                        GUILayout.Label("No Future Maneuver Nodes Found", GUILayout.ExpandWidth(true));
                }
            }

            GUILayout.EndVertical();
        }
        private void WindowLayout_AddPane_NodeEvent(Boolean PointFound,Double timeToPoint)
        {
            GUILayout.BeginVertical();
            GUILayout.Label(strAlarmEventName + " Details...", KACResources.styleAddSectionHeading);
            if (lstAlarmsWithTarget.Contains(AddType))
            {
                if (KACWorkerGameState.CurrentVesselTarget == null)
                    GUILayout.Label("Equatorial Nodes (No Valid Target)", KACResources.styleAddXferName, GUILayout.Height(18));
                else
                {
                    if (KACWorkerGameState.CurrentVesselTarget is Vessel)
                        GUILayout.Label("Target Vessel: " + KACWorkerGameState.CurrentVesselTarget.GetVessel().vesselName, KACResources.styleAddXferName,GUILayout.Height(18));
                    else if (KACWorkerGameState.CurrentVesselTarget is CelestialBody)
                        GUILayout.Label("Target Body: " + ((CelestialBody)KACWorkerGameState.CurrentVesselTarget).bodyName, KACResources.styleAddXferName,GUILayout.Height(18));
                    else
                        GUILayout.Label("Object Targeted", KACResources.styleAddXferName, GUILayout.Height(18));
                        //GUILayout.Label("Target Vessel: " + KACWorkerGameState.CurrentVesselTarget.GetVessel().vesselName, KACResources.styleAddXferName, GUILayout.Height(18));
                }
            }

            if (KACWorkerGameState.CurrentVessel == null)
                GUILayout.Label("No Active Vessel");
            else
            {
                if (!PointFound)
                {
                    GUILayout.Label("No " + strAlarmEventName + " Point Found on current plan", GUILayout.ExpandWidth(true));
                }
                else
                {
                    String strMarginConversion = "";
                    KSPDateTime eventTime = new KSPDateTime(KACWorkerGameState.CurrentTime.UT + timeToPoint);
                    KSPTimeSpan eventInterval = new KSPTimeSpan(timeToPoint);

                    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);
                            if (lstAlarmsWithTarget.Contains(AddType))
                                newAlarm.TargetObject = KACWorkerGameState.CurrentVesselTarget;

                            if (newAlarm.SupportsRepeat)
                                newAlarm.RepeatAlarm = blnRepeatingAlarmFlag;

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

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

            GUILayout.EndVertical();
        }
        private void WindowLayout_AddPane_Raw()
        {
            GUILayout.Label("Enter Raw Time Values...", KACResources.styleAddSectionHeading);

            GUILayout.BeginVertical(KACResources.styleAddFieldAreas);

            GUILayout.BeginHorizontal();
            GUILayout.Label("Time type:", KACResources.styleAddHeading, GUILayout.Width(90));
            if (DrawRadioList(ref intRawType, new string[] { "Date", "Time Interval" }))
            {
                if (intRawType == 0)
                {
                    rawEntry = new KACTimeStringArray(Planetarium.GetUniversalTime() + 600, KACTimeStringArray.TimeEntryPrecisionEnum.Years);
                }
            }
            GUILayout.EndHorizontal();

            if (intRawType == 0)
            {
                //date
                KACTimeStringArray rawDate = new KACTimeStringArray(rawEntry.UT + KSPDateStructure.EpochAsKSPDateTime.UT, KACTimeStringArray.TimeEntryPrecisionEnum.Years);
                if (DrawTimeEntry(ref rawDate, KACTimeStringArray.TimeEntryPrecisionEnum.Years, "Time:", 50, 35, 15))
                {
                    rawEntry.BuildFromUT(rawDate.UT - KSPDateStructure.EpochAsKSPDateTime.UT);
                }
            }
            else
            {
                //interval
                if (DrawTimeEntry(ref rawEntry, KACTimeStringArray.TimeEntryPrecisionEnum.Years, "Time:", 50, 35, 15))
                {

                }
            }
            GUILayout.BeginHorizontal();
            GUILayout.Label("UT (raw seconds):", KACResources.styleAddHeading,GUILayout.Width(100));
            strRawUT = GUILayout.TextField(strRawUT, KACResources.styleAddField);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
            try
            {
                if (strRawUT != "")
                    rawTime.UT = Convert.ToDouble(strRawUT);
                else
                    rawTime.UT = rawEntry.UT;

                //If its an interval add the interval to the current time
                if (intRawType==1)
                    rawTime = new KSPDateTime(KACWorkerGameState.CurrentTime.UT + rawTime.UT);

                rawTimeToAlarm = new KSPTimeSpan(rawTime.UT - KACWorkerGameState.CurrentTime.UT);

                //Draw the Add Alarm details at the bottom
                if (DrawAddAlarm(rawTime,null,rawTimeToAlarm))
                {
                    //"VesselID, Name, Message, AlarmTime.UT, Type, Enabled,  HaltWarp, PauseGame, Maneuver"
                    String strVesselID = "";
                    if (KACWorkerGameState.CurrentVessel != null && blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();
                    KACAlarm alarmNew = new KACAlarm(strVesselID, strAlarmName, (blnRepeatingAlarmFlag ? "Alarm Repeats\r\n" : "") + strAlarmNotes, rawTime.UT, 0, KACAlarm.AlarmTypeEnum.Raw,
                        AddActions);
                    alarmNew.RepeatAlarm = blnRepeatingAlarmFlag;
                    alarmNew.RepeatAlarmPeriod = new KSPTimeSpan(timeRepeatPeriod.UT);
                    alarms.Add(alarmNew);

                    //settings.Save();
                    _ShowAddPane = false;
                }
            }
            catch (Exception ex)
            {
                GUILayout.Label("Unable to combine all text fields to date", GUILayout.ExpandWidth(true));
                LogFormatted_DebugOnly("{0}\r\n{1}", ex.Message, ex.StackTrace);
            }
        }
Esempio n. 26
0
 /// <summary>Returns a new KSPPluginFramework.KSPDateTime object whose value is the sum of the specified KSPPluginFramework.KSPTimeSpan object and this instance.</summary>
 /// <param name="value">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <returns>A KSPPluginFramework.KSPDateTime whose value is the sum of the date and time represented by this instance and the time interval represented by value.</returns>
 public KSPDateTime Add(KSPTimeSpan value)
 {
     return(new KSPDateTime(UT + value.UT));
 }
        private void WindowLayout_AddPane_ScienceLab()
        {
            intAddScienceLabHeight = 150;
            if (KACWorkerGameState.CurrentVessel == null)
            {
                GUILayout.Label("No Active Vessel.", KACResources.styleLabelWarning);
            }
            else
            {
                GUILayout.Label("Select Science Lab...", KACResources.styleAddSectionHeading);
                GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
                var lstScienceLabs = KACWorkerGameState.CurrentVessel.FindPartModulesImplementing<ModuleScienceLab>();
                if (lstScienceLabs.Count == 0)
                {
                    GUILayout.Label("No Science Labs on Active Vessel.", KACResources.styleLabelWarning);
                }
                else
                {
                    intAddScienceLabHeight += (lstScienceLabs.Count * 30);
                    GUILayout.BeginHorizontal();
                    GUILayout.Space(20);
                    GUILayout.Label("Science Lab", KACResources.styleAddSectionHeading, GUILayout.Width(240));
                    GUILayout.Label("Select", KACResources.styleAddSectionHeading);
                    GUILayout.EndHorizontal();

                    for (var i = 0; i < lstScienceLabs.Count; ++i)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Space(20);
                        GUILayout.Label(
                            string.Format(
                                "Science Lab {0} (Science: {1:0}, Data: {2:0})",
                                i + 1,
                                lstScienceLabs[i].storedScience,
                                lstScienceLabs[i].dataStored),
                            KACResources.styleAddXferName,
                            GUILayout.Width(240),
                            GUILayout.Height(20));

                        bool blnSelected = (intSelectedScienceLab == i);
                        if (DrawToggle(ref blnSelected, string.Empty, KACResources.styleCheckbox, GUILayout.Width(40)))
                        {
                            if (blnSelected)
                            {
                                intSelectedScienceLab = i;
                                BuildScienceLabStrings();
                            }
                        }
                        GUILayout.EndHorizontal();
                    }
                }
                GUILayout.EndVertical();

                if (intSelectedScienceLab >= 0 && intSelectedScienceLab < lstScienceLabs.Count)
                {
                    blnClearScienceLabHighlight = false;
                    var partToHighlight = lstScienceLabs[intSelectedScienceLab].part;
                    if (partToHighlight != highlightedScienceLab && highlightedScienceLab != null && highlightedScienceLab.HighlightActive)
                    {
                        highlightedScienceLab.SetHighlightDefault();
                    }

                    if (!partToHighlight.HighlightActive)
                    {
                        partToHighlight.SetHighlight(true, false);
                    }

                    partToHighlight.highlightType = Part.HighlightType.AlwaysOn;
                    partToHighlight.SetHighlightColor(Color.yellow);
                    highlightedScienceLab = partToHighlight;

                    var lab = lstScienceLabs[intSelectedScienceLab];
                    var converter = lab.Converter;
                    if (!converter.IsActivated)
                    {
                        GUILayout.Label("Science Lab is not Active.", KACResources.styleLabelWarning);
                    }
                    else if (Mathf.Approximately(lab.dataStored, 0f))
                    {
                        GUILayout.Label("Science Lab has no Data.", KACResources.styleLabelWarning);
                    }
                    else if (!lab.part.protoModuleCrew.Any(c => c.trait == "Scientist"))
                    {
                        GUILayout.Label("Science Lab has no Scientists.", KACResources.styleLabelWarning);
                    }
                    else if (Mathf.Approximately(lab.storedScience, converter.scienceCap))
                    {
                        GUILayout.Label("Science Lab is already full.", KACResources.styleLabelWarning);
                    }
                    else
                    {
                        intAddScienceLabHeight += 232;
                        var fltMaxScience = Math.Min(converter.scienceCap, lab.storedScience + (lab.dataStored * converter.scienceMultiplier));
                        var intMinScience = (int)Math.Floor(lab.storedScience) + 1;
                        var intMaxScience = (int)Math.Floor(fltMaxScience);

                        GUILayout.Label("Choose Target Science Amount...", KACResources.styleAddSectionHeading);
                        GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Target Science:", KACResources.styleAddXferName);
                        DrawTextField(ref strTargetScience, "[^\\d\\.]+", true);
                        int intTargetScience;
                        if (!int.TryParse(strTargetScience, out intTargetScience))
                        {
                            intTargetScience = intMaxScience;
                            GUILayout.Label(new GUIContent("*", "Invalid fields treated as Max"), KACResources.styleLabelError, GUILayout.Width(8));
                        }
                        GUILayout.EndHorizontal();
                        GUILayout.Label(string.Format("Min Target Science: {0}", intMinScience), GUILayout.Width(160));
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(string.Format("Max Target Science: {0}", intMaxScience), GUILayout.Width(160));
                        if (GUILayout.Button("Set to Max"))
                        {
                            strTargetScience = intMaxScience.ToString();
                        }
                        GUILayout.EndHorizontal();
                        intTargetScienceClamped =
                            Math.Max((int)Math.Floor(lab.storedScience) + 1, Math.Min((int)Math.Floor(fltMaxScience), intTargetScience));
                        BuildScienceLabStrings();
                        if (intTargetScience != intTargetScienceClamped)
                        {
                            intAddScienceLabHeight += 25;
                            GUILayout.Label("Selected Target is out of reach. Target Amount changed.", KACResources.styleLabelWarning);
                        }
                        GUILayout.EndVertical();

                        var fltScienceNeeded = intTargetScienceClamped - lab.storedScience;
                        var fltDataNeeded = fltScienceNeeded / converter.scienceMultiplier;
                        var fltFinalData = lab.dataStored - fltDataNeeded;
                        var dblRateStart = converter.CalculateScienceRate(lab.dataStored);
                        var dblRateEnd = converter.CalculateScienceRate(fltFinalData);
                        var dblRateAvg = (dblRateStart + dblRateEnd) * 0.5d;
                        var dblDaysToProcess = fltScienceNeeded / dblRateAvg;
                        var totalResearchTime = KSPTimeSpan.FromDays(dblDaysToProcess);
                        // var totalResearchTime = new KSPTimeSpan(converter.CalculateResearchTime(fltDataNeeded));

                        GUILayout.Label("Target Details...", KACResources.styleAddSectionHeading);
                        GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Target Science Amount:", KACResources.styleAddHeading, GUILayout.Width(150));
                        GUILayout.Label(intTargetScienceClamped.ToString() + "/" + converter.scienceCap, KACResources.styleAddXferName);
                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Final Data Amount:", KACResources.styleAddHeading, GUILayout.Width(150));
                        GUILayout.Label(fltFinalData.ToString("0.00") + "/" + lab.dataStorage.ToString("0"), KACResources.styleAddXferName);
                        GUILayout.EndHorizontal();

                        GUILayout.BeginHorizontal();
                        GUILayout.Label("Final Data Rate:", KACResources.styleAddHeading, GUILayout.Width(150));
                        GUILayout.Label(dblRateEnd.ToString("0.00") + " sci/day", KACResources.styleAddXferName);
                        GUILayout.EndHorizontal();
                        GUILayout.EndVertical();

                        var scienceLabTime = new KSPDateTime(KACWorkerGameState.CurrentTime.UT + totalResearchTime.UT);
                        var scienceLabToAlarm = new KSPTimeSpan(scienceLabTime.UT - KACWorkerGameState.CurrentTime.UT);
                        if (DrawAddAlarm(scienceLabTime, null, scienceLabToAlarm))
                        {
                            KACAlarm alarmNew = new KACAlarm(
                                KACWorkerGameState.CurrentVessel.id.ToString(),
                                strAlarmName,
                                strAlarmNotes,
                                KACWorkerGameState.CurrentTime.UT + scienceLabToAlarm.UT,
                                0,
                                KACAlarm.AlarmTypeEnum.ScienceLab,
                                AddActions);

                            alarms.Add(alarmNew);

                            //settings.Save();
                            _ShowAddPane = false;
                        }
                    }
                }
            }
        }
Esempio n. 28
0
 /// <summary>Returns a new KSPPluginFramework.KSPTimeSpan object whose value is the sum of the specified KSPPluginFramework.KSPTimeSpan object and this instance.</summary>
 /// <param name="value">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <returns>A new object that represents the value of this instance plus the value of the timespan supplied.</returns>
 public KSPTimeSpan Add(KSPTimeSpan value)
 {
     return(new KSPTimeSpan(UT + value.UT));
 }
        private void WindowLayout_AddPane_Transfer()
        {
            intAddXferHeight = 304;// 317;

            if (settings.RSSActive) {
                GUILayout.Label("RSS detected - it is recommended that you use the Transfer Window Planner Plugin to plan transfers", KACResources.styleAddXferName);
                GUILayout.Space(-8);
                if (GUILayout.Button("Click here to open the TWP forum thread", KACResources.styleContent))
                    Application.OpenURL("http://forum.kerbalspaceprogram.com/threads/93115");
                intAddXferHeight += 58;
            }

            KSPDateTime XferCurrentTargetEventTime = null;
            List<KSPDateTime> lstXferCurrentTargetEventTime = new List<KSPDateTime>();
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Label("Transfers", KACResources.styleAddSectionHeading, GUILayout.Width(60));
            //add something here to select the modelled or formula values for Solar orbiting bodies
            if (settings.XferModelDataLoaded)
            {
                GUILayout.FlexibleSpace();
                GUILayout.Label("Calc by:", KACResources.styleAddHeading);
                if (intXferCurrentParent == 0)
                {
                    //intAddXferHeight += 35;
                    if (DrawRadioList(ref intXferType, "Model", "Formula"))
                    {
                        settings.XferUseModelData = (intXferType == 0);
                        settings.Save();
                    }
                }
                else
                {
                    int zero = 0;
                    DrawRadioList(ref zero, "Formula");
                }
            }
            GUILayout.EndHorizontal();
            try
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Xfer Parent:", KACResources.styleAddHeading, GUILayout.Width(80), GUILayout.Height(20));
                GUILayout.Label(XferParentBodies[intXferCurrentParent].bodyName, KACResources.styleAddXferName, GUILayout.ExpandWidth(true), GUILayout.Height(20));
                if (GUILayout.Button(new GUIContent("Change", "Click to cycle through Parent Bodies"), KACResources.styleAddXferOriginButton))
                {
                    intXferCurrentParent += 1;
                    if (intXferCurrentParent >= XferParentBodies.Count) intXferCurrentParent = 0;
                    SetupXferOrigins();
                    intXferCurrentOrigin = 0;
                    SetupXFerTargets();
                    BuildTransferStrings();
                    //strAlarmNotesNew = String.Format("{0} Transfer", XferOriginBodies[intXferCurrentOrigin].bodyName);
                }
                GUILayout.Space(34);
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();
                GUILayout.Label("Xfer Origin:", KACResources.styleAddHeading, GUILayout.Width(80),GUILayout.Height(20));
                GUILayout.Label(XferOriginBodies[intXferCurrentOrigin].bodyName, KACResources.styleAddXferName, GUILayout.ExpandWidth(true), GUILayout.Height(20));
                if (GUILayout.Button(new GUIContent("Change", "Click to cycle through Origin Bodies"), KACResources.styleAddXferOriginButton))
                {
                    intXferCurrentOrigin += 1;
                    if (intXferCurrentOrigin >= XferOriginBodies.Count) intXferCurrentOrigin = 0;
                    SetupXFerTargets();
                    BuildTransferStrings();
                    //strAlarmNotesNew = String.Format("{0} Transfer", XferOriginBodies[intXferCurrentOrigin].bodyName);
                }

                if (!settings.AlarmXferDisplayList)
                    GUILayout.Space(34);
                else
                    if (GUILayout.Button(new GUIContent(KACResources.btnChevronUp, "Hide Full List"), KACResources.styleSmallButton))
                    {
                        settings.AlarmXferDisplayList = !settings.AlarmXferDisplayList;
                        settings.Save();
                    }
                GUILayout.EndHorizontal();

                if (!settings.AlarmXferDisplayList)
                {
                    //Simple single chosen target
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Xfer Target:", KACResources.styleAddHeading, GUILayout.Width(80), GUILayout.Height(20));
                    GUILayout.Label(XferTargetBodies[intXferCurrentTarget].Target.bodyName, KACResources.styleAddXferName, GUILayout.ExpandWidth(true), GUILayout.Height(20));
                    if (GUILayout.Button(new GUIContent("Change", "Click to cycle through Target Bodies"), KACResources.styleAddXferOriginButton))
                    {
                        intXferCurrentTarget += 1;
                        if (intXferCurrentTarget >= XferTargetBodies.Count) intXferCurrentTarget = 0;
                        SetupXFerTargets();
                        BuildTransferStrings();
                        //strAlarmNotesNew = String.Format("{0} Transfer", XferTargetBodies[intXferCurrentTarget].Target.bodyName);
                    }
                    if (GUILayout.Button(new GUIContent(KACResources.btnChevronDown, "Show Full List"), KACResources.styleSmallButton))
                    {
                        settings.AlarmXferDisplayList = !settings.AlarmXferDisplayList;
                        settings.Save();
                    }
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Phase Angle-Current:",  KACResources.styleAddHeading,GUILayout.Width(130));
                    GUILayout.Label(String.Format("{0:0.00}", XferTargetBodies[intXferCurrentTarget].PhaseAngleCurrent), KACResources.styleContent, GUILayout.Width(67));
                    GUILayout.EndHorizontal();

                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Phase Angle-Target:", KACResources.styleAddHeading, GUILayout.Width(130));
                    if (intXferCurrentParent != 0 || (!settings.XferUseModelData && settings.XferModelDataLoaded))
                    {
                        //formula based
                        GUILayout.Label(String.Format("{0:0.00}", XferTargetBodies[intXferCurrentTarget].PhaseAngleTarget), KACResources.styleContent, GUILayout.Width(67));
                    }
                    else
                    {
                        //this is the modelled data, but only for Kerbol orbiting bodies
                        try
                        {
                            KACXFerModelPoint tmpModelPoint = KACResources.lstXferModelPoints.FirstOrDefault(
                            m => FlightGlobals.Bodies[m.Origin] == XferTargetBodies[intXferCurrentTarget].Origin &&
                                FlightGlobals.Bodies[m.Target] == XferTargetBodies[intXferCurrentTarget].Target &&
                                m.UT >= KACWorkerGameState.CurrentTime.UT);

                            if (tmpModelPoint != null)
                            {
                                GUILayout.Label(String.Format("{0:0.00}", tmpModelPoint.PhaseAngle), KACResources.styleContent, GUILayout.Width(67));
                                XferCurrentTargetEventTime = new KSPDateTime(tmpModelPoint.UT);
                            }
                            else
                            {
                                GUILayout.Label("No future model data available for this transfer", KACResources.styleContent, GUILayout.ExpandWidth(true));
                            }
                        }
                        catch (Exception ex)
                        {
                            GUILayout.Label("Unable to determine model data", KACResources.styleContent, GUILayout.ExpandWidth(true));
                            LogFormatted("Error determining model data: {0}", ex.Message);
                        }
                    }
                    GUILayout.EndHorizontal();
                }
                else
                {

                    //Build the list of model points for the add all button
                    for (int intTarget = 0; intTarget < XferTargetBodies.Count; intTarget++) {
                        if (!(intXferCurrentParent != 0 || (!settings.XferUseModelData && settings.XferModelDataLoaded))) {
                            try
                            {
                                KACXFerModelPoint tmpModelPoint = KACResources.lstXferModelPoints.FirstOrDefault(
                                m => FlightGlobals.Bodies[m.Origin] == XferTargetBodies[intTarget].Origin &&
                                    FlightGlobals.Bodies[m.Target] == XferTargetBodies[intTarget].Target &&
                                    m.UT >= KACWorkerGameState.CurrentTime.UT);

                                if (tmpModelPoint != null) {
                                    lstXferCurrentTargetEventTime.Add(new KSPDateTime(tmpModelPoint.UT));
                                }
                            }
                            catch (Exception ex)
                            {
                                LogFormatted("Error determining model data: {0}", ex.Message);
                            }
                        }
                    }

                    // Now do the add all buttons
                    intAddXferHeight += 28;
                    if (intXferCurrentParent != 0 || (!settings.XferUseModelData && settings.XferModelDataLoaded))
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button(new GUIContent("Create Alarms for All", "Create Alarms for all listed transfers"), new GUIStyle(KACResources.styleAddXferOriginButton) { fixedWidth = 140 }))
                        {
                            for (int i = 0; i < XferTargetBodies.Count; i++)
                            {
                                String strVesselID = "";
                                if (blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();

                                TransferStrings ts = BuildTransferStrings(i, false);
                                alarms.Add(new KACAlarm(strVesselID, ts.AlarmName, ts.AlarmNotes + "\r\n\tMargin: " + new KSPTimeSpan(timeMargin.UT).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLongTrimYears),
                                (KACWorkerGameState.CurrentTime.UT + XferTargetBodies[i].AlignmentTime.UT - timeMargin.UT), timeMargin.UT, KACAlarm.AlarmTypeEnum.Transfer,
                                AddActions, XferTargetBodies[i]));
                            }
                            _ShowAddPane = false;
                        }
                        GUILayout.EndHorizontal();
                    } else {
                        //Model based

                        GUILayout.BeginHorizontal();
                        GUILayout.FlexibleSpace();
                        if (GUILayout.Button(new GUIContent("Create Alarms for All", "Create Alarms for all listed transfers"), new GUIStyle(KACResources.styleAddXferOriginButton) { fixedWidth = 140 }))
                        {
                            for (int i = 0; i < XferTargetBodies.Count; i++)
                            {
                                String strVesselID = "";
                                if (blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();

                                TransferStrings ts = BuildTransferStrings(i, false);
                                KACAlarm alarmNew = new KACAlarm(strVesselID, ts.AlarmName, (blnRepeatingAlarmFlag ? "Alarm Repeats\r\n" : "") + ts.AlarmNotes + "\r\n\tMargin: " + new KSPTimeSpan(timeMargin.UT).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLongTrimYears),
                                    (lstXferCurrentTargetEventTime[i].UT - timeMargin.UT), timeMargin.UT, KACAlarm.AlarmTypeEnum.TransferModelled,
                                    AddActions, XferTargetBodies[i]);
                                alarmNew.RepeatAlarm = blnRepeatingAlarmFlag;
                                alarms.Add(alarmNew);
                            }
                            _ShowAddPane = false;
                        }
                        GUILayout.EndHorizontal();
                    }

                    GUIStyle styleTemp = new GUIStyle();
                    xferListScrollPosition = GUILayout.BeginScrollView(xferListScrollPosition, styleTemp);

                    // And now the table of results
                    GUILayout.BeginHorizontal();
                    GUILayout.Label("Target", KACResources.styleAddSectionHeading, GUILayout.Width(55));
                    GUILayout.Label(new GUIContent("Phase Angle", "Displayed as \"Current Angle (Target Angle)\""), KACResources.styleAddSectionHeading, GUILayout.Width(105));
                    GUILayout.Label("Time to Transfer", KACResources.styleAddSectionHeading, GUILayout.ExpandWidth(true));
                    //GUILayout.Label("Time to Alarm", KACResources.styleAddSectionHeading, GUILayout.ExpandWidth(true));
                    GUILayout.Label("Add", KACResources.styleAddSectionHeading, GUILayout.Width(30));
                    GUILayout.EndHorizontal();

                    for (int intTarget = 0; intTarget < XferTargetBodies.Count; intTarget++)
                    {
                        GUILayout.BeginHorizontal();
                        GUILayout.Label(XferTargetBodies[intTarget].Target.bodyName, KACResources.styleAddXferName, GUILayout.Width(55), GUILayout.Height(20));
                        if (intXferCurrentParent != 0 || (!settings.XferUseModelData && settings.XferModelDataLoaded))
                        {
                            //formula based
                            String strPhase = String.Format("{0:0.00}({1:0.00})", XferTargetBodies[intTarget].PhaseAngleCurrent, XferTargetBodies[intTarget].PhaseAngleTarget);
                            GUILayout.Label(strPhase, KACResources.styleAddHeading, GUILayout.Width(105), GUILayout.Height(20));
                            GUILayout.Label(XferTargetBodies[intTarget].AlignmentTime.ToStringStandard(settings.TimeSpanFormat), KACResources.styleAddHeading, GUILayout.ExpandWidth(true), GUILayout.Height(20));
                        }
                        else
                        {
                            try
                            {
                                KACXFerModelPoint tmpModelPoint = KACResources.lstXferModelPoints.FirstOrDefault(
                                m => FlightGlobals.Bodies[m.Origin] == XferTargetBodies[intTarget].Origin &&
                                    FlightGlobals.Bodies[m.Target] == XferTargetBodies[intTarget].Target &&
                                    m.UT >= KACWorkerGameState.CurrentTime.UT);

                                if (tmpModelPoint != null)
                                {
                                    String strPhase = String.Format("{0:0.00}({1:0.00})", XferTargetBodies[intTarget].PhaseAngleCurrent, tmpModelPoint.PhaseAngle);
                                    GUILayout.Label(strPhase, KACResources.styleAddHeading, GUILayout.Width(105), GUILayout.Height(20));
                                    KSPTimeSpan tmpTime = new KSPTimeSpan(tmpModelPoint.UT - KACWorkerGameState.CurrentTime.UT);
                                    GUILayout.Label(tmpTime.ToStringStandard(settings.TimeSpanFormat), KACResources.styleAddHeading, GUILayout.ExpandWidth(true), GUILayout.Height(20));

                                    if (intTarget==intXferCurrentTarget)
                                        XferCurrentTargetEventTime = new KSPDateTime(tmpModelPoint.UT);

                                    // Doing this at the top of the loop now
                                    //lstXferCurrentTargetEventTime.Add(new KSPDateTime(tmpModelPoint.UT));
                                }
                                else
                                {
                                    GUILayout.Label("No future model data", KACResources.styleContent, GUILayout.ExpandWidth(true));
                                }
                            }
                            catch (Exception ex)
                            {
                                GUILayout.Label("Unable to determine model data", KACResources.styleContent, GUILayout.ExpandWidth(true));
                                LogFormatted("Error determining model data: {0}", ex.Message);
                            }
                        }
                        Boolean blnSelected = (intXferCurrentTarget == intTarget);
                        if (DrawToggle(ref blnSelected, "", KACResources.styleCheckbox, GUILayout.Width(42)))
                        {
                            if (blnSelected)
                            {
                                intXferCurrentTarget = intTarget;
                                BuildTransferStrings();
                            }
                        }

                        GUILayout.EndHorizontal();
                    }

                    intAddXferHeight += -56 + ( XferTargetBodies.Count * 30);

                    GUILayout.EndScrollView();
                    intAddXferHeight += 2; //For the scroll bar
                }

                if(intXferCurrentParent != 0 || (!settings.XferUseModelData && settings.XferModelDataLoaded))
                {
                    ////Formula based - Add All Alarms
                    //if (settings.AlarmXferDisplayList)
                    //{
                    //    intAddXferHeight += 28;

                    //    GUILayout.BeginHorizontal();
                    //    GUILayout.FlexibleSpace();
                    //    if (GUILayout.Button(new GUIContent("Create Alarms for All", "Create Alarms for all listed transfers"), new GUIStyle(KACResources.styleAddXferOriginButton) {fixedWidth=140 }))
                    //    {
                    //        for (int i = 0; i < XferTargetBodies.Count; i++)
                    //        {
                    //            String strVesselID = "";
                    //            if (blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();

                    //            TransferStrings ts = BuildTransferStrings(i, false);
                    //            alarms.Add(new KACAlarm(strVesselID, ts.AlarmName, ts.AlarmNotes + "\r\n\tMargin: " + new KSPTimeSpan(timeMargin.UT).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLongTrimYears),
                    //            (KACWorkerGameState.CurrentTime.UT + XferTargetBodies[i].AlignmentTime.UT - timeMargin.UT), timeMargin.UT, KACAlarm.AlarmTypeEnum.Transfer,
                    //            AddActions, XferTargetBodies[i]));
                    //        }
                    //        _ShowAddPane = false;
                    //    }
                    //    GUILayout.EndHorizontal();
                    //}

                    //Formula based - add new alarm
                    if (DrawAddAlarm(new KSPDateTime(KACWorkerGameState.CurrentTime.UT + XferTargetBodies[intXferCurrentTarget].AlignmentTime.UT),
                                    XferTargetBodies[intXferCurrentTarget].AlignmentTime,
                                    new KSPTimeSpan(XferTargetBodies[intXferCurrentTarget].AlignmentTime.UT - timeMargin.UT)))
                    {
                        String strVesselID = "";
                        if (blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();
                        alarms.Add(new KACAlarm(strVesselID, strAlarmName, strAlarmNotes + "\r\n\tMargin: " + new KSPTimeSpan(timeMargin.UT).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLongTrimYears),
                            (KACWorkerGameState.CurrentTime.UT + XferTargetBodies[intXferCurrentTarget].AlignmentTime.UT - timeMargin.UT), timeMargin.UT, KACAlarm.AlarmTypeEnum.Transfer,
                            AddActions, XferTargetBodies[intXferCurrentTarget]));
                        //settings.Save();
                        _ShowAddPane = false;
                    }
                }
                else
                {

                    //Model based
                    if (XferCurrentTargetEventTime!=null)
                    {
                        ////Formula based - Add All Alarms
                        //if (settings.AlarmXferDisplayList)
                        //{
                        //    intAddXferHeight += 28;

                        //    GUILayout.BeginHorizontal();
                        //    GUILayout.FlexibleSpace();
                        //    if (GUILayout.Button(new GUIContent("Create Alarms for All", "Create Alarms for all listed transfers"), new GUIStyle(KACResources.styleAddXferOriginButton) { fixedWidth = 140 }))
                        //    {
                        //        for (int i = 0; i < XferTargetBodies.Count; i++)
                        //        {
                        //            String strVesselID = "";
                        //            if (blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();

                        //            TransferStrings ts = BuildTransferStrings(i, false);

                        //            KACAlarm alarmNew = new KACAlarm(strVesselID, ts.AlarmName, (blnRepeatingAlarmFlag ? "Alarm Repeats\r\n" : "") + ts.AlarmNotes + "\r\n\tMargin: " + new KSPTimeSpan(timeMargin.UT).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLongTrimYears),
                        //                (lstXferCurrentTargetEventTime[i].UT - timeMargin.UT), timeMargin.UT, KACAlarm.AlarmTypeEnum.TransferModelled,
                        //                AddActions, XferTargetBodies[i]);
                        //            alarmNew.RepeatAlarm = blnRepeatingAlarmFlag;
                        //            alarms.Add(alarmNew);
                        //        }
                        //        _ShowAddPane = false;
                        //    }
                        //    GUILayout.EndHorizontal();
                        //}

                        if (DrawAddAlarm(XferCurrentTargetEventTime,
                                    new KSPTimeSpan(XferCurrentTargetEventTime.UT - KACWorkerGameState.CurrentTime.UT),
                                    new KSPTimeSpan(XferCurrentTargetEventTime.UT - KACWorkerGameState.CurrentTime.UT - timeMargin.UT),
                                    true))
                        {
                            String strVesselID = "";
                            if (blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();
                            KACAlarm alarmNew = new KACAlarm(strVesselID, strAlarmName, (blnRepeatingAlarmFlag ? "Alarm Repeats\r\n" : "") + strAlarmNotes + "\r\n\tMargin: " + new KSPTimeSpan(timeMargin.UT).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLongTrimYears),
                                (XferCurrentTargetEventTime.UT - timeMargin.UT), timeMargin.UT, KACAlarm.AlarmTypeEnum.TransferModelled,
                                AddActions, XferTargetBodies[intXferCurrentTarget]);
                            alarmNew.RepeatAlarm = blnRepeatingAlarmFlag;
                            alarms.Add(alarmNew);
                            //settings.Save();
                            _ShowAddPane = false;
                        }
                    }
                    else{
                        GUILayout.Label("Selected a transfer with no event date",GUILayout.ExpandWidth(true));
                    }
                }
            }
            catch (Exception ex)
            {
                if (intXferCurrentTarget >= XferTargetBodies.Count)
                    intXferCurrentTarget = 0;
                GUILayout.Label("Something weird has happened");
                LogFormatted(ex.Message);
                LogFormatted(ex.StackTrace);
            }

            //intAddXferHeight += intTestheight4;

            GUILayout.EndVertical();
        }
Esempio n. 30
0
 /// <summary>Returns a value indicating whether this instance is equal to a specified KSPPluginFramework.KSPTimeSpan object.</summary>
 /// <param name="value">An KSPPluginFramework.KSPTimeSpan object to compare with this instance.</param>
 /// <returns>true if obj represents the same time interval as this instance; otherwise, false.</returns>
 public Boolean Equals(KSPTimeSpan value)
 {
     return(KSPTimeSpan.Equals(this, value));
 }
        private Boolean DrawAddAlarm(KSPDateTime AlarmDate, KSPTimeSpan TimeToEvent, KSPTimeSpan TimeToAlarm, Boolean ForceShowRepeat = false)
        {
            Boolean blnReturn = false;
            intHeight_AddWindowRepeat = 0;
            int intLineHeight = 18;

            GUILayout.BeginVertical();

            //Do we show repeating options
            if (KACAlarm.AlarmTypeSupportsRepeat.Contains(AddType) || ForceShowRepeat)
            {
                intHeight_AddWindowRepeat += 53;
                GUILayout.Label("Alarm Repeat Options...", KACResources.styleAddSectionHeading);
                GUILayout.BeginVertical(KACResources.styleAddFieldAreas);
                DrawCheckbox(ref blnRepeatingAlarmFlag, new GUIContent("Make this alarm repeat when triggered", "If enabled then when one alarm fires another will be created based on the existing alarm"));
                if (KACAlarm.AlarmTypeSupportsRepeatPeriod.Contains(AddType))
                {
                    intHeight_AddWindowRepeat += 24;
                    DrawTimeEntry(ref timeRepeatPeriod, KACTimeStringArray.TimeEntryPrecisionEnum.Days, "Repeat After:", 90);
                }
                GUILayout.EndVertical();
            }

            //Now for the add area
            GUILayout.BeginHorizontal(KACResources.styleAddAlarmArea);
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Date:", KACResources.styleAddHeading, GUILayout.Height(intLineHeight), GUILayout.Width(40), GUILayout.MaxWidth(40));
            GUILayout.Label(AlarmDate.ToStringStandard(DateStringFormatsEnum.DateTimeFormat), KACResources.styleContent, GUILayout.Height(intLineHeight));
            GUILayout.EndHorizontal();
            if (TimeToEvent != null)
            {
                GUILayout.BeginHorizontal();
                //GUILayout.Label("Time to " + strAlarmEventName + ":", KACResources.styleAddHeading, GUILayout.Height(intLineHeight), GUILayout.Width(120), GUILayout.MaxWidth(120));
                GUILayout.Label("Time to " + strAlarmEventName + ":", KACResources.styleAddHeading, GUILayout.Height(intLineHeight));
                GUILayout.Label(TimeToEvent.ToStringStandard(settings.TimeSpanFormat), KACResources.styleContent, GUILayout.Height(intLineHeight));
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            //GUILayout.Label("Time to Alarm:", KACResources.styleAddHeading, GUILayout.Height(intLineHeight), GUILayout.Width(120), GUILayout.MaxWidth(120));
            GUILayout.Label("Time to Alarm:", KACResources.styleAddHeading, GUILayout.Height(intLineHeight));
            GUILayout.Label(TimeToAlarm.ToStringStandard(settings.TimeSpanFormat), KACResources.styleContent, GUILayout.Height(intLineHeight));
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();

            GUILayout.Space(10);
            int intButtonHeight = 36;
            if (TimeToEvent != null) intButtonHeight += 22;
            if (GUILayout.Button("Add Alarm", KACResources.styleButton, GUILayout.Width(75), GUILayout.Height(intButtonHeight)))
            {
                blnReturn = true;
            }
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            return blnReturn;
        }
Esempio n. 32
0
 /// <summary>Returns a value indicating whether two specified instances of KSPPluginFramework.KSPTimeSpan are equal.</summary>
 /// <param name="t1">A KSPPluginFramework.KSPTimeSpan.</param>
 /// <param name="t2">A TimeSpan.</param>
 /// <returns>true if the values of t1 and t2 are equal; otherwise, false.</returns>
 public static Boolean Equals(KSPTimeSpan t1, KSPTimeSpan t2)
 {
     return(t1.UT == t2.UT);
 }
 /// <summary>Initializes a new KSPPluginFramework.KSPTimeSpan to a specified number of days, hours, minutes, and seconds.</summary> 
 /// <param name="days">Number of days.</param>
 /// <param name="hours">Number of hours.</param>
 /// <param name="minutes">Number of minutes.</param>
 /// <param name="seconds">Number of seconds.</param>
 public KSPTimeSpan(String days, String hours, String minutes, String seconds)
 {
     UT = new KSPTimeSpan(Convert.ToInt32(days), Convert.ToInt32(hours), Convert.ToInt32(minutes), Convert.ToInt32(seconds), 0).UT;
 }