Example #1
0
        /// <summary>
        /// Stuff
        /// </summary>
        private static void MakeNewAlarm(Vessel v)
        {
            if (KACWrapper.APIReady)
            {
                //Check if Alarm already exist
                Predicate <KACWrapper.KACAPI.KACAlarm> VesselFinder = (KACWrapper.KACAPI.KACAlarm a) => { return(a.VesselID == v.id.ToString()); };
                KACWrapper.KACAPI.KACAlarm             OldAlarm     = KACWrapper.KAC.Alarms.Find(VesselFinder);
                //String aID = OldAlarm.ID;
                //Debug.Log ("String aID:" + aID);

                //If not
                if (OldAlarm == null)
                {
                    Debug.Log("Adding New Alarm");
                    String aID = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.SOIChange, v.RevealName() + " Heading for Kerbin", v.orbit.UTsoi);
                    if (aID != "")
                    {
                        //if the alarm was made get the object so we can update it
                        KACWrapper.KACAPI.KACAlarm a = KACWrapper.KAC.Alarms.First(z => z.ID == aID);

                        //Now update some of the other properties
                        a.Notes       = "An Asteroid is on a collision Course for Kerbin";
                        a.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                        a.VesselID    = v.id.ToString();
                    }
                }
                else
                {
                    Debug.Log("Alarm Already exist:" + OldAlarm.ID);
                }
            }
        }
Example #2
0
        private void KACButton(PlanEntry entry, Color color, string text)
        {
            KACWrapper.KACAPI.AlarmTypeEnum alarmType;
            switch (entry.type)
            {
            case EntryType.Encounter:
                alarmType = KACWrapper.KACAPI.AlarmTypeEnum.SOIChange;
                break;

            case EntryType.Escape:
                alarmType = KACWrapper.KACAPI.AlarmTypeEnum.SOIChange;
                break;

            case EntryType.Maneuver:
                alarmType = KACWrapper.KACAPI.AlarmTypeEnum.Maneuver;
                break;

            case EntryType.Burn:
                alarmType = KACWrapper.KACAPI.AlarmTypeEnum.Closest;
                break;

            case EntryType.Crater:
                alarmType = KACWrapper.KACAPI.AlarmTypeEnum.Periapsis;
                break;

            default:
                alarmType = KACWrapper.KACAPI.AlarmTypeEnum.Raw;
                break;
            }

            guiButtonStyle.normal.textColor = color;
            if ((uiCoreActive && UI.Layout.Button("A", color, GUILayout.Width(20))) ||
                (!uiCoreActive && GUILayout.Button("A", guiButtonStyle, GUILayout.Width(20))))
            {
                String tmpID = KACWrapper.KAC.CreateAlarm(
                    alarmType,
                    FlightGlobals.ActiveVessel.vesselName,
                    entry.UT - 600
                    );

                KACWrapper.KACAPI.KACAlarm alarmNew = KACWrapper.KAC.Alarms.First(a => a.ID == tmpID);
                alarmNew.Notes = FlightGlobals.ActiveVessel.vesselName + "\n" +
                                 "Is about to " + text;
                alarmNew.AlarmMargin = 600;
                alarmNew.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                alarmNew.VesselID    = FlightGlobals.ActiveVessel.id.ToString();
                ScreenMessages.PostScreenMessage("KAC alarm added for " + FlightGlobals.ActiveVessel.vesselName);
            }
        }
 private bool CheckForAlarm()
 {
     if (KACWrapper.AssemblyExists && stopTimeWarp)
     {
         if (!KACWrapper.APIReady)
         {
             return(false);
         }
         IEnumerable <KACWrapper.KACAPI.KACAlarm> alarms = KACWrapper.KAC.Alarms.Where(a => a.Name == "Next Budget Period" && a.AlarmTime > Planetarium.GetUniversalTime());
         if (alarms.Count() < 1)
         {
             // add a five minute alarm window for the next budget so we can make adjustments as desired (KCT, part unlocks).
             String id = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Raw, "Next Budget Period", lastUpdate + budgetInterval);
             KACWrapper.KACAPI.KACAlarm alarm = KACWrapper.KAC.Alarms.Find(a => a.ID == id);
             if (alarm != null)
             {
                 alarm.AlarmMargin = 300;
             }
         }
     }
     return(true); // everything falls through to true, we're really only checking for the API to be ready.
 }
        void UpdateAlarm(double mostFutureAlarmTime, bool forward)
        {
            if (KACWrapper.APIReady && ELSettings.use_KAC)
            {
                if (control.paused)
                {
                    // It doesn't make sense to have an alarm for an event that will never happen
                    if (control.KACalarmID != "")
                    {
                        try {
                            KACWrapper.KAC.DeleteAlarm(control.KACalarmID);
                        }
                        catch {
                            // Don't crash if there was some problem deleting the alarm
                        }
                        control.KACalarmID = "";
                    }
                }
                else if (mostFutureAlarmTime > 0)
                {
                    // Find the existing alarm, if it exists
                    // Note that we might have created an alarm, and then the user deleted it!
                    KACWrapper.KACAPI.KACAlarmList alarmList = KACWrapper.KAC.Alarms;
                    KACWrapper.KACAPI.KACAlarm     a         = null;
                    if ((alarmList != null) && (control.KACalarmID != ""))
                    {
                        //Debug.Log ("Searching for alarm with ID [" + control.KACalarmID + "]");
                        a = alarmList.FirstOrDefault(z => z.ID == control.KACalarmID);
                    }

                    // set up the strings for the alarm
                    string builderShipName = FlightGlobals.ActiveVessel.vesselName;
                    string newCraftName    = control.craftConfig.GetValue("ship");

                    string alarmMessage = "[EL] build: \"" + newCraftName + "\"";
                    string alarmNotes   = "Completion of Extraplanetary Launchpad build of \"" + newCraftName + "\" on \"" + builderShipName + "\"";
                    if (!forward)                       // teardown messages
                    {
                        alarmMessage = "[EL] teardown: \"" + newCraftName + "\"";
                        alarmNotes   = "Teardown of Extraplanetary Launchpad build of \"" + newCraftName + "\" on \"" + builderShipName + "\"";
                    }

                    if (a == null)
                    {
                        // no existing alarm, make a new alarm
                        control.KACalarmID = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Raw, alarmMessage, mostFutureAlarmTime);
                        //Debug.Log ("new alarm ID: [" + control.KACalarmID + "]");

                        if (control.KACalarmID != "")
                        {
                            a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == control.KACalarmID);
                            if (a != null)
                            {
                                a.AlarmAction = ELSettings.KACAction;
                                a.AlarmMargin = 0;
                                a.VesselID    = FlightGlobals.ActiveVessel.id.ToString();
                            }
                        }
                    }
                    if (a != null)
                    {
                        // Whether we created an alarm or found an existing one, now update it
                        a.AlarmTime = mostFutureAlarmTime;
                        a.Notes     = alarmNotes;
                        a.Name      = alarmMessage;
                    }
                }
            }
        }
Example #5
0
        public void checkdelivery()
        {
            if (vessel.packed || !vessel.loaded)
            {
                return;
            }

            if (!checkPLanet())
            {
                return;
            }
            if (!isActivated())
            {            //If not no resources can be supplied by module.
                status = "not yet supply-activated";
                return;
            }

            if (vessel.orbit.semiMajorAxis / 1000 > MaxSemiMayorAxis) //check if module is not on an orbit which has a higher semi mayor axis than the Maximum Semi mayor axis altitude
            {                                                         //Inform and don't supply recources.
                status = "orbit limit exceeded";

                //Update UI
                UIcontrol();
                return;
            }

            if (String.IsNullOrEmpty(request) || "0" == request.Substring(0, 1))           //check if there is a delivery pending
            {
                status = "no delivery pending";
                return;
            }

            //unpack request string
            string[] SplitArray = request.Split(':');
            string[] arrRequest = new string[SplitArray.Length];
            for (int runs = 0; runs < SplitArray.Length; runs++)
            {
                arrRequest[runs] = SplitArray[runs].Replace(" ", string.Empty);
            }

            double requesttime = Convert.ToDouble(arrRequest[1]);

            if (staticorbit() > (Planetarium.GetUniversalTime() - requesttime - 5))
            {            //orbit is stable since request was made.
                string[] SplataArray     = DeliveryTimeList.Split(',');
                string[] arrDeliveryTime = new string[SplataArray.Length];
                for (int runs = 0; runs < SplataArray.Length; runs++)
                {
                    arrDeliveryTime[runs] = SplataArray[runs].Replace(" ", string.Empty);
                }

                //Use planet specific delivery time if available
                double requestduration = Convert.ToDouble(BaseDeliveryTime);
                for (int runs = 0; runs < SplataArray.Length; runs++)
                {
                    if (arrDeliveryTime[runs] == vessel.orbit.referenceBody.name)
                    {
                        requestduration = Convert.ToDouble(arrDeliveryTime[runs + 1]);
                    }
                }

                if (requestduration > ((Planetarium.GetUniversalTime() - requesttime) / 21600d))              //check if delivery should be ready
                {
                    status = "delivery in " + Math.Round((requestduration - (Planetarium.GetUniversalTime() - requesttime) / 21600d), 1) + " days";

                    if (KACWrapper.APIReady)
                    {
                        string shipName = FlightGlobals.ActiveVessel.vesselName;

                        KACWrapper.KACAPI.KACAlarm a = null;
                        if (KACalarmID != "")
                        {
                            a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == KACalarmID);
                        }
                        else
                        {
                            KACalarmID = KACWrapper.KAC.CreateAlarm(
                                KACWrapper.KACAPI.AlarmTypeEnum.Raw,
                                "Davon delivery to " + shipName,
                                requesttime + requestduration * 21600d
                                );
                            a = KACWrapper.KAC.Alarms.FirstOrDefault(z => z.ID == KACalarmID);
                            if (a != null)
                            {
                                a.AlarmAction = KACWrapper.KACAPI.AlarmActionEnum.KillWarp;
                                a.AlarmMargin = 0;
                                a.VesselID    = FlightGlobals.ActiveVessel.id.ToString();
                                a.Notes       = "Delivery of resources to " + shipName + " by Davon Tech Ltd";
                            }
                        }
                    }
                }
                else
                {
                    //deliver

                    string[] ResourceArray = requestContent.Split(',');
                    string[] arrResource   = new string[ResourceArray.Length];
                    for (int runs = 0; runs < ResourceArray.Length; runs++)
                    {
                        arrResource[runs] = ResourceArray[runs].Replace(" ", string.Empty);
                    }

                    foreach (String st in ResourceArray)
                    {
                        string[] ResourceInfo = st.Split(':');

                        foreach (PartResource r in part.Resources)
                        {
                            if (r.info.name == ResourceInfo[0].Trim())
                            {
                                //how much needs to be delivered
                                double deliverAmount = Convert.ToDouble(ResourceInfo[1].Trim());

                                if (deliverAmount >= r.maxAmount - r.amount)
                                {
                                    //first deliver to part
                                    deliverAmount = deliverAmount - (r.maxAmount - r.amount);
                                    r.amount      = r.maxAmount;

                                    //deliver to other parts
                                    foreach (Part op in vessel.parts)
                                    {
                                        foreach (PartResource or in op.Resources)
                                        {
                                            if (or.info.name == r.info.name)
                                            {
                                                if (deliverAmount >= or.maxAmount - or.amount)
                                                {
                                                    deliverAmount = deliverAmount - (or.maxAmount - or.amount);
                                                    or.amount     = or.maxAmount;
                                                }
                                                else
                                                {
                                                    or.amount     = or.amount + deliverAmount;
                                                    deliverAmount = 0;
                                                }
                                            }
                                        }
                                    }
                                    //part.RequestResource(r.info.name, (float)-r.maxAmount*DeliveryAmountFactor);
                                }
                                else
                                {
                                    r.amount      = r.amount + deliverAmount;
                                    deliverAmount = 0;
                                }
                            }
                        }
                    }
                    request        = "0";
                    requestContent = "";
                    status         = "delivery completed";
                    KACalarmID     = "";
                }
            }
            else
            {            //orbit is not stable since request.
                //Redeploy from the new orbit, cancel deliveries.
                status         = "no static orbit - delivery cancelled";
                request        = "0";
                requestContent = "";
                saveorbit();
            }

            //Update UI
            UIcontrol();
        }
Example #6
0
        private void DrawTransferDetails()
        {
            if (ShowEjectionDetails)
            {
                GUI.Box(new Rect(10, EjectionDetailsYOffset, WindowRect.width - 20, 23), "");
                //Styles.styleSettingsArea if needed
            }
            ////Draw the selected position indicators
            //GUILayout.Space(mbTWP.windowDebug.intTest1);
            GUILayout.BeginHorizontal();
            GUILayout.Label("Selected Transfer Details", GUILayout.Width(150));
            GUILayout.Label(String.Format("{0} (@{2:0}km) -> {1} (@{3:0}km)", TransferSpecs.OriginName, TransferSpecs.DestinationName, TransferSpecs.InitialOrbitAltitude / 1000, TransferSpecs.FinalOrbitAltitude / 1000), Styles.styleTextYellow);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.BeginVertical();
            GUILayout.Label("Departure:", Styles.styleTextDetailsLabel);
            GUILayout.Label("Phase Angle:", Styles.styleTextDetailsLabel);
            if (ShowEjectionDetails)
            {
                GUILayout.Label(""); GUILayout.Label("    Ejection Heading:", Styles.styleTextDetailsLabel);
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            //GUILayout.Label(String.Format("{0:0}", KSPTime.PrintDate(new KSPTime(TransferSelected.DepartureTime), KSPTime.PrintTimeFormat.DateTimeString)), Styles.styleTextYellow);
            GUILayout.Label(new KSPDateTime(TransferSelected.DepartureTime).ToStringStandard(DateStringFormatsEnum.DateTimeFormat), Styles.styleTextYellow);
            GUIStyle styleCopyButton = new GUIStyle(SkinsLibrary.CurrentSkin.button);

            styleCopyButton.fixedHeight = 18;
            styleCopyButton.padding.top = styleCopyButton.padding.bottom = 0;
            if (GUILayout.Button(new GUIContent(Resources.btnCopy, "Copy Departure UT"), styleCopyButton))
            {
                Utilities.CopyTextToClipboard(String.Format("{0:0}", TransferSelected.DepartureTime));
            }
            GUILayout.EndHorizontal();
            GUILayout.Label(String.Format("{0:0.00}°", TransferSelected.PhaseAngle * LambertSolver.Rad2Deg), Styles.styleTextYellow);
            //GUILayout.Label("Phase Angle:", Styles.styleTextDetailsLabel);
            if (ShowEjectionDetails)
            {
                GUILayout.Label(""); GUILayout.Label(String.Format("{0:0.00}°", TransferSelected.EjectionHeading * LambertSolver.Rad2Deg), Styles.styleTextYellow);
            }

            //Action Buttons
            if (KACWrapper.APIReady)
            {
                if (GUI.Button(new Rect(10, WindowRect.height - 30, 132, 20), new GUIContent("  Add KAC Alarm", Resources.btnKAC)))
                {
                    String tmpID = KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.TransferModelled,
                                                              String.Format("{0} -> {1}", mbTWP.windowMain.TransferSelected.Origin.bodyName, mbTWP.windowMain.TransferSelected.Destination.bodyName),
                                                              (mbTWP.windowMain.TransferSelected.DepartureTime - settings.KACMargin * 60 * 60));


                    KACWrapper.KACAPI.KACAlarm alarmNew = KACWrapper.KAC.Alarms.First(a => a.ID == tmpID);
                    alarmNew.Notes              = mbTWP.windowMain.GenerateTransferDetailsText();
                    alarmNew.AlarmMargin        = settings.KACMargin * 60 * 60;
                    alarmNew.AlarmAction        = settings.KACAlarmAction;
                    alarmNew.XferOriginBodyName = mbTWP.windowMain.TransferSelected.Origin.bodyName;
                    alarmNew.XferTargetBodyName = mbTWP.windowMain.TransferSelected.Destination.bodyName;
                }

                if (GUI.Button(new Rect(132 + 15, WindowRect.height - 30, 120, 20), new GUIContent("  Copy Details", Resources.btnCopy)))
                {
                    CopyAllDetailsToClipboard();
                }
            }
            else
            {
                if (GUI.Button(new Rect(10, WindowRect.height - 30, 250, 20), new GUIContent("  Copy Transfer Details", Resources.btnCopy)))
                {
                    CopyAllDetailsToClipboard();
                }
            }


            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Label("Arrival:", Styles.styleTextDetailsLabel);
            GUILayout.Label("Ejection Angle:", Styles.styleTextDetailsLabel);
            GUILayout.Label("Ejection Inclination:", Styles.styleTextDetailsLabel);
            if (ShowEjectionDetails)
            {
                GUILayout.Label("Ejection Normal Δv:", Styles.styleTextDetailsLabel);
            }
            if (TransferSpecs.FinalOrbitAltitude > 0)
            {
                GUILayout.Label("Insertion Inclination:", Styles.styleTextDetailsLabel);
            }
            else
            {
                GUILayout.Label("", Styles.styleTextDetailsLabel); //empty label to maintain window height
            }
            GUILayout.EndVertical();
            GUILayout.BeginVertical();
            //GUILayout.Label(String.Format("{0:0}", KSPTime.PrintDate(new KSPTime(TransferSelected.DepartureTime + TransferSelected.TravelTime), KSPTime.PrintTimeFormat.DateTimeString)), Styles.styleTextYellow);
            GUILayout.Label(new KSPDateTime(TransferSelected.DepartureTime + TransferSelected.TravelTime).ToStringStandard(DateStringFormatsEnum.DateTimeFormat), Styles.styleTextYellow);
            //GUILayout.Label(String.Format("{0:0.00}°", TransferSelected.EjectionAngle * LambertSolver.Rad2Deg), Styles.styleTextYellow);
            GUILayout.Label(TransferSelected.EjectionAngleText, Styles.styleTextYellow);
            GUILayout.Label(String.Format("{0:0.00}°", TransferSelected.EjectionInclination * LambertSolver.Rad2Deg), Styles.styleTextYellow);
            if (ShowEjectionDetails)
            {
                GUILayout.Label(String.Format("{0:0.0} m/s", TransferSelected.EjectionDVNormal), Styles.styleTextYellow);
            }
            if (TransferSpecs.FinalOrbitAltitude > 0)
            {
                GUILayout.Label(String.Format("{0:0.00}°", TransferSelected.InsertionInclination * LambertSolver.Rad2Deg), Styles.styleTextYellow);
            }
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Label("Travel Time:", Styles.styleTextDetailsLabel);
            GUILayout.Label("Total Δv:", Styles.styleTextDetailsLabel);
            GUILayout.Label("Ejection Δv:", Styles.styleTextDetailsLabel);
            if (ShowEjectionDetails)
            {
                GUILayout.Label("Ejection Prograde Δv:", Styles.styleTextDetailsLabel);
            }

            if (TransferSpecs.FinalOrbitAltitude > 0)
            {
                GUILayout.Label("Insertion Δv:", Styles.styleTextDetailsLabel);
            }
            GUILayout.EndVertical();


            GUILayout.BeginVertical();
            GUILayout.Label(String.Format("{0:0}", new KSPTimeSpan(TransferSelected.TravelTime).ToStringStandard(TimeSpanStringFormatsEnum.IntervalLongTrimYears)), Styles.styleTextYellow);
            GUILayout.Label(String.Format("{0:0} m/s", TransferSelected.DVTotal), Styles.styleTextYellow);
            GUILayout.BeginHorizontal();
            GUILayout.Label(String.Format("{0:0} m/s", TransferSelected.DVEjection), Styles.styleTextYellow);
            if (Event.current.type == EventType.Repaint)
            {
                DVEjectionRect         = GUILayoutUtility.GetLastRect();
                EjectionDetailsYOffset = DVEjectionRect.y + 20;
            }
            if (DVEjectionRect != null)
            {
                if (GUI.Button(new Rect(DVEjectionRect.x + DVEjectionRect.width - 20, DVEjectionRect.y, 16, 16), new GUIContent(Resources.btnInfo, "Toggle Details..."), new GUIStyle()))
                {
                    ShowEjectionDetails = !ShowEjectionDetails;
                    if (!ShowEjectionDetails)
                    {
                        WindowRect.height = 400;
                    }
                }
            }
            GUILayout.EndHorizontal();
            if (ShowEjectionDetails)
            {
                GUILayout.Label(String.Format("{0:0.0} m/s", TransferSelected.EjectionDVPrograde), Styles.styleTextYellow);
            }
            if (TransferSpecs.FinalOrbitAltitude > 0)
            {
                GUILayout.Label(String.Format("{0:0} m/s", TransferSelected.DVInjection), Styles.styleTextYellow);
            }
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
        }
Example #7
0
 public KACAlarmWrapper(String alarmID)
 {
     alarm = KACWrapper.KAC.Alarms.First(z => z.ID == alarmID);
     InitializeSuffixes();
 }
Example #8
0
 public KACAlarmWrapper(KACWrapper.KACAPI.KACAlarm init)
 {
     alarm = init;
     InitializeSuffixes();
 }
Example #9
0
 internal Alarm(KACWrapper.KACAPI.KACAlarm alarm)
 {
     this.alarm = alarm;
 }
        private void windowKAC(int id)
        {
            GUIContent closeContent = new GUIContent(Textures.BtnRedCross, "Close Window");
            Rect closeRect = new Rect(DFKACwindowPos.width - 21, 4, 16, 16);
            if (GUI.Button(closeRect, closeContent, Textures.ClosebtnStyle))
            {
                showKACGUI = false;
                return;
            }

            // Utilities.Log_Debug("start WindowKAC ModKacAlarm active=" + ModKACAlarm);

            //Draw the alarms that KAC has that are for the CURRENT Vessel ONLY, so ONLY in FLIGHT mode.
            GUIscrollViewVectorKAC = GUILayout.BeginScrollView(GUIscrollViewVectorKAC, false, false);
            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.Label(new GUIContent("Name", "Alarm Name"), Textures.sectionTitleLeftStyle, GUILayout.Width(KACtxtWdthName));
            GUILayout.Label(new GUIContent("Alarm Type", "KAC Alarm Type"), Textures.sectionTitleLeftStyle, GUILayout.Width(KACtxtWdthAtyp));
            GUILayout.Label(new GUIContent("Time Remain.", "Time remaining before Alarm is triggered"), Textures.sectionTitleLeftStyle, GUILayout.Width(KACtxtWdthATme));
            GUILayout.EndHorizontal();
            if (KACWrapper.KAC.Alarms.Count == 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("There are currently no KAC alarms associated to a DeepFreeze vessel", Textures.frozenStyle);
                GUILayout.EndHorizontal();
            }
            else
            {
                foreach (KACWrapper.KACAPI.KACAlarm alarm in KACWrapper.KAC.Alarms)
                {
                    //Only show KAC alarms that are in the DeepFreeze known vessels list. (IE: vessels that have a freezer)
                    if (alarm.VesselID == "" || alarm.AlarmType == KACWrapper.KACAPI.AlarmTypeEnum.Crew)
                    {
                        continue;
                    }
                    Guid tmpid = new Guid(alarm.VesselID);
                    if (DeepFreeze.Instance.DFgameSettings.knownVessels.ContainsKey(tmpid))
                    {
                        GUILayout.BeginHorizontal();
                        double TmeRemaining = Math.Round(alarm.AlarmTime - Planetarium.GetUniversalTime(), 0);

                        if (TmeRemaining <= 5)
                        {
                            GUILayout.Label(alarm.Name, Textures.StatusWarnStyle, GUILayout.Width(KACtxtWdthName));
                            GUILayout.Label(alarm.AlarmType.ToString(), Textures.StatusWarnStyle, GUILayout.Width(KACtxtWdthAtyp));
                            GUILayout.Label(Utilities.FormatDateString(TmeRemaining), Textures.StatusWarnStyle, GUILayout.Width(KACtxtWdthATme));
                        }
                        else
                        {
                            GUILayout.Label(alarm.Name, Textures.statusStyle, GUILayout.Width(KACtxtWdthName));
                            GUILayout.Label(alarm.AlarmType.ToString(), Textures.statusStyle, GUILayout.Width(KACtxtWdthAtyp));
                            GUILayout.Label(Utilities.FormatDateString(TmeRemaining), Textures.statusStyle, GUILayout.Width(KACtxtWdthATme));
                        }
                        // Utilities.Log_Debug("Show alarm  from KAC " + alarm.ID + " " + alarm.Name + " " + alarm.VesselID);

                        //Option to delete each alarm
                        if (ModKACAlarm || (DFInstalledMods.IsRTInstalled && !DFInstalledMods.RTVesselConnected(tmpid)))
                        {
                            //If a modify is in progress we turn off the delete button
                            GUI.enabled = false;
                            GUILayout.Button(new GUIContent("Delete", "Delete this KAC alarm completely"), GUILayout.Width(50));
                            GUI.enabled = true;
                            // Utilities.Log_Debug("Delete button disabled");
                        }
                        else
                        {
                            if (TmeRemaining <= 0) GUI.enabled = false;
                            if (GUILayout.Button(new GUIContent("Delete", "Delete this KAC alarm completely"), GUILayout.Width(50)))
                            {
                                KACWrapper.KAC.DeleteAlarm(alarm.ID);
                            }
                            GUI.enabled = true;
                        }

                        //Option to modify
                        if (ModKACAlarm) // If a Modify is in progress
                        {
                            if (KACalarmMod.ID != alarm.ID) //If it isn't this alarm we disable the button
                            {
                                GUI.enabled = false;
                                GUILayout.Button(new GUIContent("Modify", "Modify this Alarm"), GUILayout.Width(50));
                                GUI.enabled = true;
                                // Utilities.Log_Debug("Modify button disabled");
                            }
                            else //We are modifying an alarm and it's this one. So we draw a SAVE and Cancel button to save/cancel changes.
                            {
                                // Utilities.Log_Debug("mod in progress and it's this one, change to Save/Cancel");
                                if (GUILayout.Button(new GUIContent("Save", "Save Alarm Changes"), GUILayout.Width(50)))
                                {
                                    if (DFInstalledMods.IsRTInstalled && !DFInstalledMods.RTVesselConnected(tmpid))
                                    {
                                        ScreenMessages.PostScreenMessage("Cannot Save Alarm. No R/Tech Connection to vessel.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                                    }
                                    else
                                    {
                                        if (TmeRemaining > 0)
                                        {
                                            DFIntMemory.Instance.ModifyKACAlarm(KACalarmMod, KACAlarm_FrzKbls, KACAlarm_ThwKbls);
                                            ScreenMessages.PostScreenMessage("DeepFreeze Alarm changes Saved.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                                            // Utilities.Log_Debug("DF KAC Modified alarm " + KACalarmMod.ID + " " + KACalarmMod.Name);
                                        }
                                        else
                                        {
                                            ScreenMessages.PostScreenMessage("DeepFreeze Cannot Save alarm changes, Time is up.", 5.0f, ScreenMessageStyle.UPPER_CENTER);
                                            Utilities.Log_Debug("DF KAC Couldn't save Modified alarm time is up");
                                        }
                                    }
                                    ModKACAlarm = false;
                                }
                                if (GUILayout.Button(new GUIContent("Cancel", "Cancel any changes"), GUILayout.Width(50)))
                                {
                                    // Utilities.Log_Debug("User cancelled mod");
                                    ModKACAlarm = false;
                                }
                                GUILayout.EndHorizontal();
                                GUIscrollViewVectorKACKerbals = GUILayout.BeginScrollView(GUIscrollViewVectorKACKerbals, false, false, GUILayout.MaxHeight(100f));
                                GUILayout.BeginVertical();
                                GUILayout.BeginHorizontal();
                                GUILayout.Label(new GUIContent("Name", "The Kerbals Name"), Textures.sectionTitleLeftStyle, GUILayout.Width(KACtxtWdthKName));
                                GUILayout.Label(new GUIContent("Trait", "The Kerbals Profession"), Textures.sectionTitleLeftStyle, GUILayout.Width(KACtxtWdthKTyp));
                                GUILayout.Label(new GUIContent("Thaw", "Thaw this kerbal on alarm activation"), Textures.sectionTitleLeftStyle, GUILayout.Width(KACtxtWdthKTg1));
                                GUILayout.Label(new GUIContent("Freeze", "Freeze this kerbal on alarm activation"), Textures.sectionTitleLeftStyle, GUILayout.Width(KACtxtWdthKTg2));
                                GUILayout.EndHorizontal();
                                //Build the Crew list for the alarm and allow modifications
                                List<KeyValuePair<uint, PartInfo>> frzrs = DeepFreeze.Instance.DFgameSettings.knownFreezerParts.Where(a => a.Value.vesselID == tmpid).ToList();
                                //foreach (DeepFreezer frzr in DFIntMemory.Instance.DpFrzrActVsl)
                                foreach (KeyValuePair<uint, PartInfo> frzr in frzrs)
                                {
                                    //Thawed Crew List
                                    for (int i = 0; i < frzr.Value.crewMembers.Count; i++)
                                    {
                                        GUILayout.BeginHorizontal();
                                        bool ThawCrew = KACAlarm_ThwKbls.Contains(frzr.Value.crewMembers[i]);
                                        bool FrzCrew = KACAlarm_FrzKbls.Contains(frzr.Value.crewMembers[i]);
                                        GUILayout.Label(frzr.Value.crewMembers[i], Textures.statusStyle, GUILayout.Width(KACtxtWdthKName));
                                        GUILayout.Label(frzr.Value.crewMemberTraits[i], Textures.statusStyle, GUILayout.Width(KACtxtWdthKTyp));
                                        if (FrzCrew) GUI.enabled = false;
                                        ThawCrew = GUILayout.Toggle(ThawCrew, "", Textures.ButtonStyle, GUILayout.Width(KACtxtWdthKTg1));
                                        GUI.enabled = true;
                                        if (ThawCrew)
                                        {
                                            if (!KACAlarm_ThwKbls.Contains(frzr.Value.crewMembers[i]))
                                            {
                                                KACAlarm_ThwKbls.Add(frzr.Value.crewMembers[i]);
                                            }
                                        }
                                        else
                                        {
                                            if (KACAlarm_ThwKbls.Contains(frzr.Value.crewMembers[i]))
                                            {
                                                KACAlarm_ThwKbls.Remove(frzr.Value.crewMembers[i]);
                                            }
                                        }
                                        if (ThawCrew) GUI.enabled = false;
                                        FrzCrew = GUILayout.Toggle(FrzCrew, "", Textures.ButtonStyle, GUILayout.Width(KACtxtWdthKTg2));
                                        GUI.enabled = true;

                                        if (FrzCrew)
                                        {
                                            if (!KACAlarm_FrzKbls.Contains(frzr.Value.crewMembers[i]))
                                            {
                                                KACAlarm_FrzKbls.Add(frzr.Value.crewMembers[i]);
                                            }
                                        }
                                        else
                                        {
                                            if (KACAlarm_FrzKbls.Contains(frzr.Value.crewMembers[i]))
                                            {
                                                KACAlarm_FrzKbls.Remove(frzr.Value.crewMembers[i]);
                                            }
                                        }

                                        GUILayout.EndHorizontal();
                                    }
                                    //Frozen Crew List
                                    List<KeyValuePair<string, KerbalInfo>> frzncrew = DeepFreeze.Instance.DFgameSettings.KnownFrozenKerbals.Where(f => f.Value.partID == frzr.Key && f.Value.type != ProtoCrewMember.KerbalType.Tourist).ToList();
                                    foreach (KeyValuePair<string, KerbalInfo> crew in frzncrew)
                                    {
                                        GUILayout.BeginHorizontal();
                                        bool ThawCrew = KACAlarm_ThwKbls.Contains(crew.Key);
                                        bool FrzCrew = KACAlarm_FrzKbls.Contains(crew.Key);
                                        GUILayout.Label(crew.Key, Textures.frozenStyle, GUILayout.Width(KACtxtWdthKName));
                                        GUILayout.Label(crew.Value.experienceTraitName, Textures.frozenStyle, GUILayout.Width(KACtxtWdthKTyp));
                                        if (FrzCrew) GUI.enabled = false;
                                        ThawCrew = GUILayout.Toggle(ThawCrew, "", Textures.ButtonStyle, GUILayout.Width(KACtxtWdthKTg1));
                                        GUI.enabled = true;
                                        if (ThawCrew)
                                        {
                                            if (!KACAlarm_ThwKbls.Contains(crew.Key))
                                            {
                                                KACAlarm_ThwKbls.Add(crew.Key);
                                            }
                                        }
                                        else
                                        {
                                            if (KACAlarm_ThwKbls.Contains(crew.Key))
                                            {
                                                KACAlarm_ThwKbls.Remove(crew.Key);
                                            }
                                        }
                                        if (ThawCrew) GUI.enabled = false;
                                        FrzCrew = GUILayout.Toggle(FrzCrew, "", Textures.ButtonStyle, GUILayout.Width(KACtxtWdthKTg2));
                                        GUI.enabled = true;
                                        if (FrzCrew)
                                        {
                                            if (!KACAlarm_FrzKbls.Contains(crew.Key))
                                            {
                                                KACAlarm_FrzKbls.Add(crew.Key);
                                            }
                                        }
                                        else
                                        {
                                            if (KACAlarm_FrzKbls.Contains(crew.Key))
                                            {
                                                KACAlarm_FrzKbls.Remove(crew.Key);
                                            }
                                        }
                                        GUILayout.EndHorizontal();
                                    }
                                }
                                GUILayout.EndVertical();
                                GUILayout.EndScrollView();
                                continue;
                            }
                        }
                        else  // no modify is in progress so we draw modify buttons on all alarms
                        {
                            // Utilities.Log_Debug("no modify in progress so just show modify buttons on KAC alarm");
                            if (TmeRemaining <= 0) GUI.enabled = false;
                            if (GUILayout.Button(new GUIContent("Modify", "Modify this Alarms settings"), GUILayout.Width(50)))
                            {
                                KACalarmMod = alarm;
                                KACAlarm_FrzKbls.Clear();
                                KACAlarm_ThwKbls.Clear();
                                string tmpnotes = DFIntMemory.Instance.ParseKACNotes(alarm.Notes, out KACAlarm_FrzKbls, out KACAlarm_ThwKbls);
                                ModKACAlarm = true;
                                // Utilities.Log_Debug("Modify in progress " + alarm.ID);
                            }
                            GUI.enabled = true;
                        }
                        GUILayout.EndHorizontal();
                    }
                }
            }
            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            GUILayout.Space(14);

            GUIContent resizeContent = new GUIContent(Textures.BtnResize, "Resize Window");
            Rect resizeRect = new Rect(DFKACwindowPos.width - 17, DFKACwindowPos.height - 17, 16, 16);
            GUI.Label(resizeRect, resizeContent, Textures.ResizeStyle);

            HandleResizeEventsKAC(resizeRect);
            if (DeepFreeze.Instance.DFsettings.ToolTips)
                Utilities.SetTooltipText();
            GUI.DragWindow();
        }