private void WindowLayout_AddPane_Crew()
        {
            intAddCrewHeight = 322;
            GUILayout.Label("Select Crew...", KACResources.styleAddSectionHeading);

            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++)
                {
                    //DebugLogFormatted("{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 + KACTime.timeDateOffest.UT, KACTimeStringArray.TimeEntryPrecisionEnum.Years);
                    if (DrawTimeEntry(ref CrewDate, KACTimeStringArray.TimeEntryPrecisionEnum.Years, "Time:", 50, 35, 15))
                    {
                        rawEntry.BuildFromUT(CrewDate.UT - KACTime.timeDateOffest.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 KACTime(KACWorkerGameState.CurrentTime.UT + CrewTime.UT);

                    CrewTimeToAlarm = new KACTime(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, Manuever"
                        KACAlarm addAlarm = new KACAlarm(pCM[intSelectedCrew].name, strAlarmName, strAlarmNotes, CrewTime.UT, 0, KACAlarm.AlarmType.Crew,
                            (AddAction == KACAlarm.AlarmAction.KillWarp), (AddAction == KACAlarm.AlarmAction.PauseGame));
                        if (CrewAlarmStoreNode)
                        {
                            if (KACWorkerGameState.ManeuverNodeExists) addAlarm.ManNodes = KACWorkerGameState.ManeuverNodesFuture;
                            if (KACWorkerGameState.CurrentVesselTarget != null) addAlarm.TargetObject = KACWorkerGameState.CurrentVesselTarget;
                        }
                        Settings.Alarms.Add(addAlarm);
                        Settings.Save();
                        _ShowAddPane = false;
                    }
                }
                catch (Exception)
                {
                //    DebugLogFormatted(ex.Message);
                    GUILayout.Label("Unable to combine all text fields to date", GUILayout.ExpandWidth(true));
                }
            }
        }
        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 + KACTime.timeDateOffest.UT, KACTimeStringArray.TimeEntryPrecisionEnum.Years);
                if (DrawTimeEntry(ref rawDate, KACTimeStringArray.TimeEntryPrecisionEnum.Years, "Time:", 50, 35, 15))
                {
                    rawEntry.BuildFromUT(rawDate.UT - KACTime.timeDateOffest.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 KACTime(KACWorkerGameState.CurrentTime.UT + rawTime.UT);

                rawTimeToAlarm = new KACTime(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, Manuever"
                    String strVesselID = "";
                    if (KACWorkerGameState.CurrentVessel != null && blnAlarmAttachToVessel) strVesselID = KACWorkerGameState.CurrentVessel.id.ToString();
                    Settings.Alarms.Add(new KACAlarm(strVesselID, strAlarmName, strAlarmNotes, rawTime.UT, 0, KACAlarm.AlarmType.Raw,
                        (AddAction== KACAlarm.AlarmAction.KillWarp), (AddAction== KACAlarm.AlarmAction.PauseGame)));
                    Settings.Save();
                    _ShowAddPane = false;
                }
            }
            catch (Exception)
            {
                GUILayout.Label("Unable to combine all text fields to date", GUILayout.ExpandWidth(true));
            }
        }
 public Boolean DrawTimeEntry(ref KACTimeStringArray time, KACTimeStringArray.TimeEntryPrecisionEnum Prec, String LabelText, int LabelWidth, params GUILayoutOption[] options)
 {
     return DrawTimeEntry(ref time, Prec, LabelText, LabelWidth, 40,20);
 }
        public Boolean DrawTimeEntry(ref KACTimeStringArray time, KACTimeStringArray.TimeEntryPrecisionEnum Prec, String LabelText, int LabelWidth, int FieldWidth, int SuffixWidth, params GUILayoutOption[] options)
        {
            Boolean blnReturn = false;

            GUILayout.BeginHorizontal();
            if (LabelText!="")
                GUILayout.Label(LabelText, KACResources.styleAddHeading, GUILayout.Width(LabelWidth));

            String strTemp;
            if (Prec >= KACTimeStringArray.TimeEntryPrecisionEnum.Years)
            {
                strTemp = time.Years;
                if (DrawTimeField(ref strTemp, "y", FieldWidth, SuffixWidth))
                {
                    blnReturn = true;
                    time.Years = strTemp;
                }
            }
            if (Prec >= KACTimeStringArray.TimeEntryPrecisionEnum.Days)
            {
                strTemp = time.Days;
                if (DrawTimeField(ref strTemp, "d", FieldWidth, SuffixWidth))
                {
                    blnReturn = true;
                    time.Days = strTemp;
                }
            }
            if (Prec >= KACTimeStringArray.TimeEntryPrecisionEnum.Hours)
            {
                strTemp = time.Hours;
                if (DrawTimeField(ref strTemp, "h", FieldWidth, SuffixWidth))
                {
                    blnReturn = true;
                    time.Hours = strTemp;
                }
            }
            if (Prec >= KACTimeStringArray.TimeEntryPrecisionEnum.Minutes)
            {
                strTemp = time.Minutes;
                if (DrawTimeField(ref strTemp, "m", FieldWidth, SuffixWidth))
                {
                    blnReturn = true;
                    time.Minutes = strTemp;
                }
            }
            if (Prec >= KACTimeStringArray.TimeEntryPrecisionEnum.Seconds)
            {
                strTemp = time.Seconds;
                if (DrawTimeField(ref strTemp, "s", FieldWidth, SuffixWidth))
                {
                    blnReturn = true;
                    time.Seconds = strTemp;
                }
            }
            //blnReturn = DrawTimeField(ref time.Seconds, "s", FieldWidth, SuffixWidth) && blnReturn;
            if (!time.Valid)
            {
                GUILayout.Label(new GUIContent("*","Invalid fields treated as 0"), KACResources.styleLabelError, GUILayout.Width(SuffixWidth));
            }
            GUILayout.EndHorizontal();

            return blnReturn;
        }
 public Boolean DrawTimeEntry(ref KACTimeStringArray time, KACTimeStringArray.TimeEntryPrecisionEnum Prec, params GUILayoutOption[] options)
 {
     return DrawTimeEntry(ref time, Prec, "", 0, 40,20);
 }
        /// <summary>
        /// Layout of Common Parts of every alarm
        /// </summary>
        private void WindowLayout_CommonFields2(ref String strName, ref Boolean blnAttachVessel, ref KACAlarm.AlarmAction Action, ref KACTimeStringArray Margin, KACAlarm.AlarmType TypeOfAlarm, int WindowHeight)
        {
            //Two Columns
            String strTitle = "";
            switch (TypeOfAlarm)
            {
                case KACAlarm.AlarmType.Raw: strTitle = "Raw Time"; break;
                case KACAlarm.AlarmType.Maneuver: strTitle = "Maneuver Node"; break;
                case KACAlarm.AlarmType.SOIChange: strTitle = "SOI Change"; break;
                case KACAlarm.AlarmType.Transfer: strTitle = "Transfer Window"; break;
                case KACAlarm.AlarmType.TransferModelled: strTitle = "Transfer Window"; break;
                case KACAlarm.AlarmType.Apoapsis: strTitle = "Apoapsis"; break;
                case KACAlarm.AlarmType.Periapsis: strTitle = "Periapsis"; break;
                case KACAlarm.AlarmType.AscendingNode: strTitle = "Ascending Node"; break;
                case KACAlarm.AlarmType.DescendingNode: strTitle = "Descending Node"; break;
                case KACAlarm.AlarmType.LaunchRendevous: strTitle = "Launch Ascent"; break;
                case KACAlarm.AlarmType.Closest: strTitle = "Closest Approach"; break;
                case KACAlarm.AlarmType.Distance: strTitle = "Target Distance"; break;
                case KACAlarm.AlarmType.Crew: strTitle = "Crew"; break;
                case KACAlarm.AlarmType.EarthTime: strTitle = "Earth Time"; break;
                default: strTitle = "Raw Time"; break;
            }
            strTitle += " Alarm - Common Properties";
            GUILayout.Label(strTitle, KACResources.styleAddSectionHeading);
            GUILayout.BeginVertical(KACResources.styleAddFieldAreas, GUILayout.Height(WindowHeight));

            if (KACWorkerGameState.CurrentGUIScene == GameScenes.TRACKSTATION)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label("Selected Vessel:", KACResources.styleAddHeading);
                String strVesselName = "No Selected Vessel";
                if (KACWorkerGameState.CurrentVessel != null) strVesselName = KACWorkerGameState.CurrentVessel.vesselName;
                GUILayout.Label(strVesselName, KACResources.styleLabelWarning);
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Label("Alarm:", KACResources.styleAddHeading, GUILayout.Width(60));
            strName = GUILayout.TextField(strName, KACResources.styleAddField, GUILayout.MaxWidth(200)).Replace("|", "");

            GUIContent guiBtnMessages = new GUIContent(KACResources.btnChevRight, "Show Extra Details");
            if (_ShowAddMessages) guiBtnMessages = new GUIContent(KACResources.btnChevLeft, "Hide Details");
            if (GUILayout.Button(guiBtnMessages, KACResources.styleSmallButton))
                _ShowAddMessages = !_ShowAddMessages;
            GUILayout.EndHorizontal();

            if (ScenesForAttachOption.Contains(KACWorkerGameState.CurrentGUIScene) && TypesForAttachOption.Contains(TypeOfAlarm)
                && KACWorkerGameState.CurrentVessel!=null)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Space(15);
                DrawCheckbox(ref blnAttachVessel, "Attach to Active Vessel");
                GUILayout.EndHorizontal();
            }

            //Full width one under the two columns for the kill time warp
            DrawAlarmActionChoice2(ref Action, "Action:", 60);

            if (TypeOfAlarm != KACAlarm.AlarmType.Raw && TypeOfAlarm != KACAlarm.AlarmType.EarthTime && TypeOfAlarm != KACAlarm.AlarmType.Crew)
            {
                DrawTimeEntry(ref Margin, KACTimeStringArray.TimeEntryPrecisionEnum.Hours, "Margin:", 60);
            }
            GUILayout.EndVertical();
        }
        /// <summary>
        /// Layout of Common Parts of every alarm
        /// </summary>
        private void WindowLayout_CommonFields(ref String strName, ref String strMessage, ref int Action, ref KACTimeStringArray Margin, KACAlarm.AlarmType TypeOfAlarm, int WindowHeight)
        {
            //Two Columns
            GUILayout.Label("Common Alarm Properties", KACResources.styleAddSectionHeading);
            GUILayout.BeginVertical(KACResources.styleAddFieldAreas, GUILayout.Height(WindowHeight));

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical(GUILayout.Width(90));
            GUILayout.Label("Alarm Name:", KACResources.styleAddHeading);
            GUILayout.Label("Message:", KACResources.styleAddHeading);
            GUILayout.EndVertical();

            GUILayout.BeginVertical(GUILayout.Width(260), GUILayout.MaxWidth(260));
            strName = GUILayout.TextField(strName, KACResources.styleAddField).Replace("|", "");
            strMessage = GUILayout.TextArea(strMessage, KACResources.styleAddField).Replace("|", "");
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            //Full width one under the two columns for the kill time warp
            DrawAlarmActionChoice(ref Action, "On Alarm:", 90);

            if (TypeOfAlarm != KACAlarm.AlarmType.Raw && TypeOfAlarm != KACAlarm.AlarmType.EarthTime && TypeOfAlarm != KACAlarm.AlarmType.Crew)
            {
                DrawTimeEntry(ref Margin, KACTimeStringArray.TimeEntryPrecisionEnum.Hours, "Alarm Margin:", 90);
            }

            GUILayout.EndVertical();
        }
 private void WindowLayout_CommonFields(ref String strName, ref String strMessage, ref int Action, ref Double Margin, KACAlarm.AlarmType TypeOfAlarm, int WindowHeight)
 {
     KACTimeStringArray tmpTime = new KACTimeStringArray(Margin,KACTimeStringArray.TimeEntryPrecisionEnum.Hours);
     WindowLayout_CommonFields(ref strName, ref strMessage, ref Action, ref tmpTime, TypeOfAlarm, WindowHeight);
     Margin = tmpTime.UT;
 }
        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);
            }
        }