Ejemplo n.º 1
0
 public tabs summaryTab()
 {
     selectedCourse = null;
     selectedNaut   = null;
     summaryBody(tabs.Training);
     return(selectedNaut == null ? tabs.Training : tabs.Naut);
 }
Ejemplo n.º 2
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
        private void CancelCourse(ActiveCourse course)
        {
            DialogGUIBase[] options = new DialogGUIBase[3];
            options[0] = new DialogGUIFlexibleSpace();
            options[1] = new DialogGUIButton("Yes", () =>
            {
                // We "complete" the course but we didn't mark it as Completed, so it just releases the students and doesn't apply rewards
                course.CompleteCourse();
                CrewHandler.Instance.ActiveCourses.Remove(course);
                MaintenanceHandler.Instance?.UpdateUpkeep();
            });
            options[2] = new DialogGUIButton("No", () => { });
            var sb = new StringBuilder("Are you sure you want to cancel this course? The following students will cease study:");

            foreach (ProtoCrewMember stud in course.Students)
            {
                sb.AppendLine();
                sb.Append(stud.name);
            }
            var diag = new MultiOptionDialog("ConfirmCancelCourse", sb.ToStringAndRelease(), "Stop Course?",
                                             HighLogic.UISkin,
                                             new Rect(0.5f, 0.5f, 150f, 60f),
                                             new DialogGUIFlexibleSpace(),
                                             new DialogGUIHorizontalLayout(options));

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
Ejemplo n.º 3
0
 public tabs newCourseTab()
 {
     GUILayout.BeginHorizontal();
     try {
         GUILayout.FlexibleSpace();
         GUILayout.Label(selectedCourse.name);
         GUILayout.FlexibleSpace();
     } finally {
         GUILayout.EndHorizontal();
     }
     GUILayout.Label(selectedCourse.description);
     summaryBody(tabs.NewCourse);
     if (selectedCourse.seatMax > 0)
     {
         GUILayout.Label(selectedCourse.seatMax - selectedCourse.Students.Count + " remaining seat(s).");
     }
     if (selectedCourse.seatMin > selectedCourse.Students.Count)
     {
         GUILayout.Label(selectedCourse.seatMin - selectedCourse.Students.Count + " more student(s) required.");
     }
     GUILayout.Label("Will take " + KSPUtil.PrintDateDeltaCompact(selectedCourse.GetTime(), false, false));
     GUILayout.Label("and finish on " + KSPUtil.PrintDate(selectedCourse.CompletionTime(), false));
     if (GUILayout.Button("Start Course", GUILayout.ExpandWidth(false)))
     {
         if (selectedCourse.StartCourse())
         {
             CrewHandler.Instance.ActiveCourses.Add(selectedCourse);
             selectedCourse = null;
         }
     }
     return(selectedCourse == null ? tabs.Training : tabs.NewCourse);
 }
Ejemplo n.º 4
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
 public UITab RenderSummaryTab()
 {
     _selectedCourse = null;
     _selectedNaut   = null;
     RenderSummaryBody(UITab.Training);
     return(_selectedNaut == null ? UITab.Training : UITab.Naut);
 }
Ejemplo n.º 5
0
        private void cancelCourse(ActiveCourse course)
        {
            DialogGUIBase[] options = new DialogGUIBase[3];
            options[0] = new DialogGUIFlexibleSpace();
            options[1] = new DialogGUIButton("Yes", () =>
            {
                /* We "complete" the course but we didn't mark it as Completed, so it just releases the students and doesn't apply rewards */
                course.CompleteCourse();
            });
            options[2] = new DialogGUIButton("No", () => { });
            StringBuilder msg = new StringBuilder("Are you sure you want to cancel this course?  The following students will cease study:");

            foreach (ProtoCrewMember stud in course.Students)
            {
                msg.AppendLine();
                msg.Append(stud.name);
            }
            MultiOptionDialog diag = new MultiOptionDialog("ConfirmCancelCourse", msg.ToStringAndRelease(), "Stop Course?",
                                                           HighLogic.UISkin,
                                                           new Rect(0.5f, 0.5f, 150f, 60f),
                                                           new DialogGUIFlexibleSpace(),
                                                           new DialogGUIVerticalLayout(options));

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
Ejemplo n.º 6
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
        protected void RenderCourseSelector()
        {
            if (_courseBtnStyle == null)
            {
                _courseBtnStyle = new GUIStyle(HighLogic.Skin.button);
                _courseBtnStyle.normal.textColor = Color.yellow;
            }

            _courseSelectorScroll = GUILayout.BeginScrollView(_courseSelectorScroll, GUILayout.Width(505), GUILayout.Height(430));
            try
            {
                foreach (CourseTemplate course in CrewHandler.Instance.OfferedCourses)
                {
                    var style = course.isTemporary ? _courseBtnStyle : HighLogic.Skin.button;
                    var c     = new GUIContent(course.name, course.PartsTooltip);
                    if (GUILayout.Button(c, style))
                    {
                        _selectedCourse = new ActiveCourse(course);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            GUILayout.EndScrollView();
        }
Ejemplo n.º 7
0
        public void nautTab()
        {
            updateActiveMap();
            GUILayout.BeginHorizontal();
            try {
                GUILayout.FlexibleSpace();
                GUILayout.Label(selectedNaut.name);
                GUILayout.FlexibleSpace();
            } finally {
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            try {
                GUILayout.Label($"{selectedNaut.trait} {selectedNaut.experienceLevel.ToString():D}");
                if (CrewHandler.Instance.RetirementEnabled && CrewHandler.Instance.KerbalRetireTimes.ContainsKey(selectedNaut.name))
                {
                    GUILayout.Space(8);
                    GUILayout.Label($"Retires NET {KSPUtil.PrintDate(CrewHandler.Instance.KerbalRetireTimes[selectedNaut.name], false)}", rightLabel);
                }
            } finally {
                GUILayout.EndHorizontal();
            }

            double nlt = CrewHandler.Instance.GetLatestRetireTime(selectedNaut);

            if (nlt > 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(string.Empty, GUILayout.ExpandWidth(true));
                GUILayout.Label($"Retires NLT {KSPUtil.PrintDate(nlt, false)}", rightLabel);
                GUILayout.EndHorizontal();
            }

            if (activeMap.ContainsKey(selectedNaut))
            {
                ActiveCourse currentCourse = activeMap[selectedNaut];
                GUILayout.BeginHorizontal();
                try {
                    GUILayout.Label($"Studying {currentCourse.name} until {KSPUtil.PrintDate(currentCourse.CompletionTime(), false)}");
                    if (currentCourse.seatMin > 1)
                    {
                        if (GUILayout.Button("Cancel", GUILayout.ExpandWidth(false)))
                        {
                            cancelCourse(currentCourse);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Remove", GUILayout.ExpandWidth(false)))
                        {
                            leaveCourse(currentCourse, selectedNaut);
                        }
                    }
                } finally {
                    GUILayout.EndHorizontal();
                }
            }
            GUILayout.Label(CrewHandler.Instance.GetTrainingString(selectedNaut));
        }
Ejemplo n.º 8
0
 protected void courseSelector()
 {
     foreach (CourseTemplate course in CrewHandler.Instance.OfferedCourses)
     {
         if (GUILayout.Button(course.name))
         {
             selectedCourse = new ActiveCourse(course);
         }
     }
 }
Ejemplo n.º 9
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
        private static void CreateCourseFinishAlarm(ProtoCrewMember student, ActiveCourse currentCourse)
        {
            // CrewHandler processes trainings every 3600 seconds. Need to account for that to set up accurate KAC alarms.
            double completeUT = currentCourse.CompletionTime();
            double timeDiff   = completeUT - CrewHandler.Instance.NextUpdate;
            double timesChRun = Math.Ceiling(timeDiff / CrewHandler.UpdateInterval);
            double alarmUT    = CrewHandler.Instance.NextUpdate + timesChRun * CrewHandler.UpdateInterval;
            string alarmTxt   = $"{currentCourse.name} - {student.name}";

            KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Crew, alarmTxt, alarmUT);
        }
Ejemplo n.º 10
0
        private void ProcessCourses(double time)
        {
            bool anyCourseEnded = false;

            for (int i = ActiveCourses.Count; i-- > 0;)
            {
                ActiveCourse course = ActiveCourses[i];
                if (course.ProgressTime(time)) //returns true when the course completes
                {
                    ActiveCourses.RemoveAt(i);
                    anyCourseEnded = true;
                }
            }

            for (int i = _expireTimes.Count; i-- > 0;)
            {
                TrainingExpiration e = _expireTimes[i];
                if (time > e.Expiration)
                {
                    ProtoCrewMember pcm = HighLogic.CurrentGame.CrewRoster[e.PcmName];
                    if (pcm != null)
                    {
                        for (int j = pcm.careerLog.Entries.Count; j-- > 0;)
                        {
                            int eC = e.Entries.Count;
                            if (eC == 0)
                            {
                                break;
                            }
                            FlightLog.Entry ent = pcm.careerLog[j];
                            for (int k = eC; k-- > 0;)
                            {
                                // Allow only mission trainings to expire.
                                // This check is actually only needed for old savegames as only these can have expirations on proficiencies.
                                if (ent.type == "TRAINING_mission" && e.Compare(k, ent))
                                {
                                    ScreenMessages.PostScreenMessage(pcm.name + ": Expired: " + GetPrettyCourseName(ent.type) + ent.target);
                                    ent.type = "expired_" + ent.type;
                                    e.Entries.RemoveAt(k);
                                }
                            }
                        }
                    }
                    _expireTimes.RemoveAt(i);
                }
            }

            if (anyCourseEnded)
            {
                MaintenanceHandler.Instance?.ScheduleMaintenanceUpdate();
            }
        }
Ejemplo n.º 11
0
        private void leaveCourse(ActiveCourse course, ProtoCrewMember student)
        {
            DialogGUIBase[] options = new DialogGUIBase[3];
            options[0] = new DialogGUIFlexibleSpace();
            options[1] = new DialogGUIButton("Yes", () => { course.RemoveStudent(student); });
            options[2] = new DialogGUIButton("No", () => { });
            MultiOptionDialog diag = new MultiOptionDialog("ConfirmStudentDropCourse", "Are you sure you want " + student.name + " to drop this course?", "Drop Course?",
                                                           HighLogic.UISkin,
                                                           new Rect(0.5f, 0.5f, 150f, 60f),
                                                           new DialogGUIFlexibleSpace(),
                                                           new DialogGUIVerticalLayout(options));

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
Ejemplo n.º 12
0
 public void nautTab()
 {
     updateActiveMap();
     GUILayout.BeginHorizontal();
     try {
         GUILayout.FlexibleSpace();
         GUILayout.Label(selectedNaut.name);
         GUILayout.FlexibleSpace();
     } finally {
         GUILayout.EndHorizontal();
     }
     GUILayout.BeginHorizontal();
     try {
         GUILayout.Label(String.Format("{0} {1:D}", selectedNaut.trait, selectedNaut.experienceLevel.ToString()));
         if (CrewHandler.Instance.retirementEnabled && CrewHandler.Instance.kerbalRetireTimes.ContainsKey(selectedNaut.name))
         {
             GUILayout.Space(8);
             GUILayout.Label(String.Format("Retires NET {0}", KSPUtil.PrintDate(CrewHandler.Instance.kerbalRetireTimes[selectedNaut.name], false)),
                             rightLabel);
         }
     } finally {
         GUILayout.EndHorizontal();
     }
     if (activeMap.ContainsKey(selectedNaut))
     {
         ActiveCourse currentCourse = activeMap[selectedNaut];
         GUILayout.BeginHorizontal();
         try {
             GUILayout.Label("Studying " + currentCourse.name + " until " + KSPUtil.PrintDate(currentCourse.CompletionTime(), false));
             if (currentCourse.seatMin > 1)
             {
                 if (GUILayout.Button("Cancel", GUILayout.ExpandWidth(false)))
                 {
                     cancelCourse(currentCourse);
                 }
             }
             else
             {
                 if (GUILayout.Button("Remove", GUILayout.ExpandWidth(false)))
                 {
                     leaveCourse(currentCourse, selectedNaut);
                 }
             }
         } finally {
             GUILayout.EndHorizontal();
         }
     }
     GUILayout.Label(CrewHandler.Instance.GetTrainingString(selectedNaut));
 }
Ejemplo n.º 13
0
 protected void courseSelector()
 {
     courseSelectorScroll = GUILayout.BeginScrollView(courseSelectorScroll, GUILayout.Width(480), GUILayout.Height(430));
     try {
         foreach (CourseTemplate course in CrewHandler.Instance.OfferedCourses)
         {
             if (GUILayout.Button(course.name))
             {
                 selectedCourse = new ActiveCourse(course);
             }
         }
     } finally {
         GUILayout.EndScrollView();
     }
 }
Ejemplo n.º 14
0
        public tabs newCourseTab()
        {
            if (tempCourseLblStyle == null)
            {
                tempCourseLblStyle = new GUIStyle(GUI.skin.label);
                tempCourseLblStyle.normal.textColor = Color.yellow;
            }

            GUILayout.BeginHorizontal();
            try {
                GUILayout.FlexibleSpace();
                GUILayout.Label(selectedCourse.name);
                GUILayout.FlexibleSpace();
            } finally {
                GUILayout.EndHorizontal();
            }
            if (!string.IsNullOrEmpty(selectedCourse.description))
            {
                GUILayout.Label(selectedCourse.description);
            }
            if (selectedCourse.isTemporary)
            {
                GUILayout.Label("Tech for this part is still being researched", tempCourseLblStyle);
            }
            summaryBody(tabs.NewCourse);
            if (selectedCourse.seatMax > 0)
            {
                GUILayout.Label(selectedCourse.seatMax - selectedCourse.Students.Count + " remaining seat(s).");
            }
            if (selectedCourse.seatMin > selectedCourse.Students.Count)
            {
                GUILayout.Label(selectedCourse.seatMin - selectedCourse.Students.Count + " more student(s) required.");
            }
            GUILayout.Label("Will take " + KSPUtil.PrintDateDeltaCompact(selectedCourse.GetTime(), false, false));
            GUILayout.Label("and finish on " + KSPUtil.PrintDate(selectedCourse.CompletionTime(), false));
            if (GUILayout.Button("Start Course", GUILayout.ExpandWidth(false)))
            {
                if (selectedCourse.StartCourse())
                {
                    CrewHandler.Instance.ActiveCourses.Add(selectedCourse);
                    selectedCourse = null;
                    MaintenanceHandler.Instance?.UpdateUpkeep();
                }
            }
            return(selectedCourse == null ? tabs.Training : tabs.NewCourse);
        }
Ejemplo n.º 15
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
        public UITab RenderNewCourseTab()
        {
            if (_tempCourseLblStyle == null)
            {
                _tempCourseLblStyle = new GUIStyle(GUI.skin.label);
                _tempCourseLblStyle.normal.textColor = Color.yellow;
            }

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(_selectedCourse.name);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (!string.IsNullOrEmpty(_selectedCourse.description))
            {
                GUILayout.Label(_selectedCourse.description);
            }
            if (_selectedCourse.isTemporary)
            {
                GUILayout.Label("Tech for this part is still being researched", _tempCourseLblStyle);
            }

            RenderSummaryBody(UITab.NewCourse);
            if (_selectedCourse.seatMax > 0)
            {
                GUILayout.Label($"{_selectedCourse.seatMax - _selectedCourse.Students.Count} remaining seat(s).");
            }
            if (_selectedCourse.seatMin > _selectedCourse.Students.Count)
            {
                GUILayout.Label($"{_selectedCourse.seatMin - _selectedCourse.Students.Count} more student(s) required.");
            }
            GUILayout.Label($"Will take {KSPUtil.PrintDateDeltaCompact(_selectedCourse.GetTime(), true, false)}");
            GUILayout.Label($"and finish on {KSPUtil.PrintDate(_selectedCourse.CompletionTime(), false)}");
            if (GUILayout.Button("Start Course", HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
            {
                if (_selectedCourse.StartCourse())
                {
                    CrewHandler.Instance.ActiveCourses.Add(_selectedCourse);
                    _selectedCourse = null;
                    MaintenanceHandler.Instance?.UpdateUpkeep();
                }
            }
            return(_selectedCourse == null ? UITab.Training : UITab.NewCourse);
        }
Ejemplo n.º 16
0
        protected void courseSelector()
        {
            if (courseBtnStyle == null)
            {
                courseBtnStyle = new GUIStyle(GUI.skin.button);
                courseBtnStyle.normal.textColor = Color.yellow;
            }

            courseSelectorScroll = GUILayout.BeginScrollView(courseSelectorScroll, GUILayout.Width(505), GUILayout.Height(430));
            try {
                foreach (CourseTemplate course in CrewHandler.Instance.OfferedCourses)
                {
                    var style = course.isTemporary ? courseBtnStyle : GUI.skin.button;
                    if (GUILayout.Button(course.name, style))
                    {
                        selectedCourse = new ActiveCourse(course);
                    }
                }
            } finally {
                GUILayout.EndScrollView();
            }
        }
Ejemplo n.º 17
0
        private void leaveCourse(ActiveCourse course, ProtoCrewMember student)
        {
            DialogGUIBase[] options = new DialogGUIBase[3];
            options[0] = new DialogGUIFlexibleSpace();
            options[1] = new DialogGUIButton("Yes", () =>
            {
                course.RemoveStudent(student);
                if (course.Students.Count == 0)
                {
                    CrewHandler.Instance.ActiveCourses.Remove(course);
                    MaintenanceHandler.Instance?.UpdateUpkeep();
                }
            });
            options[2] = new DialogGUIButton("No", () => { });
            MultiOptionDialog diag = new MultiOptionDialog("ConfirmStudentDropCourse", "Are you sure you want " + student.name + " to drop this course?", "Drop Course?",
                                                           HighLogic.UISkin,
                                                           new Rect(0.5f, 0.5f, 150f, 60f),
                                                           new DialogGUIFlexibleSpace(),
                                                           new DialogGUIHorizontalLayout(options));

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
Ejemplo n.º 18
0
        protected void nautListRow(tabs currentTab, ProtoCrewMember student)
        {
            GUIStyle     style         = HighLogic.Skin.label;
            ActiveCourse currentCourse = null;

            if (activeMap.ContainsKey(student))
            {
                currentCourse = activeMap[student];
            }
            bool onSelectedCourse = selectedCourse != null && currentCourse != null && currentCourse.id == selectedCourse.id;

            if (onSelectedCourse)
            {
                style = boldLabel;
            }
            bool selectedForCourse = selectedCourse != null && selectedCourse.Students.Contains(student);

            GUILayout.BeginHorizontal();
            try {
                GUILayout.Label(String.Format("{0} {1}", student.trait.Substring(0, 1), student.experienceLevel), GUILayout.Width(24));
                if (currentCourse == null && selectedCourse != null && (selectedForCourse || selectedCourse.MeetsStudentReqs(student)))
                {
                    if (toggleButton(student.name, selectedForCourse, GUILayout.Width(144)))
                    {
                        if (selectedForCourse)
                        {
                            selectedCourse.RemoveStudent(student);
                        }
                        else
                        {
                            selectedCourse.AddStudent(student);
                        }
                    }
                }
                else if (currentTab == tabs.Training)
                {
                    if (GUILayout.Button(student.name, GUILayout.Width(144)))
                    {
                        selectedNaut = student;
                    }
                }
                else
                {
                    GUILayout.Label(student.name, GUILayout.Width(144));
                }
                string course, complete, retires;
                if (currentCourse == null)
                {
                    if (student.inactive)
                    {
                        course   = "(inactive)";
                        complete = KSPUtil.PrintDate(student.inactiveTimeEnd, false);
                    }
                    else
                    {
                        course   = "(free)";
                        complete = "(n/a)";
                    }
                }
                else
                {
                    course   = currentCourse.name;
                    complete = KSPUtil.PrintDate(currentCourse.CompletionTime(), false);
                }
                GUILayout.Label(course, GUILayout.Width(96));
                GUILayout.Label(complete, GUILayout.Width(80));
                if (CrewHandler.Instance.kerbalRetireTimes.ContainsKey(student.name))
                {
                    retires = CrewHandler.Instance.retirementEnabled ? KSPUtil.PrintDate(CrewHandler.Instance.kerbalRetireTimes[student.name], false) : "(n/a)";
                }
                else
                {
                    retires = "(unknown)";
                }
                GUILayout.Label(retires, GUILayout.Width(80));
                if (currentCourse != null)
                {
                    if (currentCourse.seatMin > 1)
                    {
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            cancelCourse(currentCourse);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            leaveCourse(currentCourse, student);
                        }
                    }
                }
            } finally {
                GUILayout.EndHorizontal();
            }
        }
Ejemplo n.º 19
0
        public void Update()
        {
            if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.CrewRoster == null)
            {
                return;
            }

            // Catch earlies
            if (firstLoad)
            {
                firstLoad = false;
                List <string> newHires = new List <string>();

                foreach (ProtoCrewMember pcm in HighLogic.CurrentGame.CrewRoster.Crew)
                {
                    if ((pcm.rosterStatus == ProtoCrewMember.RosterStatus.Assigned || pcm.rosterStatus == ProtoCrewMember.RosterStatus.Available) && !kerbalRetireTimes.ContainsKey(pcm.name))
                    {
                        newHires.Add(pcm.name);
                        OnCrewHired(pcm, int.MinValue);
                    }
                }
                if (newHires.Count > 0)
                {
                    string msgStr = "Crew will retire as follows:";
                    foreach (string s in newHires)
                    {
                        msgStr += "\n" + s + ", no earlier than " + KSPUtil.PrintDate(kerbalRetireTimes[s], false);
                    }

                    PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                 new Vector2(0.5f, 0.5f),
                                                 "InitialRetirementDateNotification",
                                                 "Initial Retirement Date",
                                                 msgStr
                                                 + "\n(Retirement will be delayed the more interesting flights they fly.)",
                                                 "OK",
                                                 false,
                                                 HighLogic.UISkin);
                }
            }

            // Retirements
            double time = Planetarium.GetUniversalTime();

            if (nextUpdate < time)
            {
                // Ensure that CrewHandler updates happen at predictable times so that accurate KAC alarms can be set.
                do
                {
                    nextUpdate += updateInterval;
                }while (nextUpdate < time);

                if (retirementEnabled)
                {
                    foreach (KeyValuePair <string, double> kvp in kerbalRetireTimes)
                    {
                        ProtoCrewMember pcm = HighLogic.CurrentGame.CrewRoster[kvp.Key];
                        if (pcm == null)
                        {
                            toRemove.Add(kvp.Key);
                        }
                        else
                        {
                            if (pcm.rosterStatus != ProtoCrewMember.RosterStatus.Available)
                            {
                                if (pcm.rosterStatus != ProtoCrewMember.RosterStatus.Assigned)
                                {
                                    toRemove.Add(kvp.Key);
                                }

                                continue;
                            }

                            if (pcm.inactive)
                            {
                                continue;
                            }

                            if (time > kvp.Value)
                            {
                                toRemove.Add(kvp.Key);
                                retirees.Add(kvp.Key);
                                pcm.rosterStatus = ProtoCrewMember.RosterStatus.Dead;
                            }
                        }
                    }
                }

                bool anyCourseEnded = false;
                for (int i = ActiveCourses.Count; i-- > 0;)
                {
                    ActiveCourse course = ActiveCourses[i];
                    if (course.ProgressTime(time)) //returns true when the course completes
                    {
                        ActiveCourses.RemoveAt(i);
                        anyCourseEnded = true;
                    }
                }

                for (int i = expireTimes.Count; i-- > 0;)
                {
                    TrainingExpiration e = expireTimes[i];
                    if (time > e.expiration)
                    {
                        ProtoCrewMember pcm = HighLogic.CurrentGame.CrewRoster[e.pcmName];
                        if (pcm != null)
                        {
                            for (int j = pcm.careerLog.Entries.Count; j-- > 0;)
                            {
                                int eC = e.entries.Count;
                                if (eC == 0)
                                {
                                    break;
                                }
                                FlightLog.Entry ent = pcm.careerLog[j];
                                for (int k = eC; k-- > 0;)
                                {
                                    // Allow only mission trainings to expire.
                                    // This check is actually only needed for old savegames as only these can have expirations on proficiencies.
                                    if (ent.type == "TRAINING_mission" && e.Compare(k, ent))
                                    {
                                        ScreenMessages.PostScreenMessage(pcm.name + ": Expired: " + GetPrettyCourseName(ent.type) + ent.target);
                                        ent.type = "expired_" + ent.type;
                                        e.entries.RemoveAt(k);
                                    }
                                }
                            }
                        }
                        expireTimes.RemoveAt(i);
                    }
                }

                // TODO remove from courses? Except I think they won't retire if inactive either so that's ok.
                if (toRemove.Count > 0)
                {
                    string msgStr = string.Empty;
                    foreach (string s in toRemove)
                    {
                        kerbalRetireTimes.Remove(s);
                        if (HighLogic.CurrentGame.CrewRoster[s] != null)
                        {
                            msgStr += "\n" + s;
                        }
                    }
                    if (!string.IsNullOrEmpty(msgStr))
                    {
                        PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f),
                                                     new Vector2(0.5f, 0.5f),
                                                     "CrewRetirementNotification",
                                                     "Crew Retirement",
                                                     "The following retirements have occurred:\n" + msgStr,
                                                     "OK",
                                                     true,
                                                     HighLogic.UISkin);
                    }

                    toRemove.Clear();
                }

                if (anyCourseEnded || toRemove.Count > 0)
                {
                    MaintenanceHandler.Instance.UpdateUpkeep();
                }
            }

            // UI fixing
            if (inAC)
            {
                if (astronautComplex == null)
                {
                    KSP.UI.Screens.AstronautComplex[] mbs = GameObject.FindObjectsOfType <KSP.UI.Screens.AstronautComplex>();
                    int maxCount = -1;
                    foreach (KSP.UI.Screens.AstronautComplex c in mbs)
                    {
                        int count = c.ScrollListApplicants.Count + c.ScrollListAssigned.Count + c.ScrollListAvailable.Count + c.ScrollListKia.Count;
                        if (count > maxCount)
                        {
                            maxCount         = count;
                            astronautComplex = c;
                        }
                    }

                    if (astronautComplex == null)
                    {
                        return;
                    }
                }
                int newAv   = astronautComplex.ScrollListAvailable.Count;
                int newAsgn = astronautComplex.ScrollListAssigned.Count;
                int newKIA  = astronautComplex.ScrollListKia.Count;
                if (newAv != countAvailable || newKIA != countKIA || newAsgn != countAssigned)
                {
                    countAvailable = newAv;
                    countAssigned  = newAsgn;
                    countKIA       = newKIA;

                    foreach (KSP.UI.UIListData <KSP.UI.UIListItem> u in astronautComplex.ScrollListAvailable)
                    {
                        KSP.UI.CrewListItem cli = u.listItem.GetComponent <KSP.UI.CrewListItem>();
                        if (cli != null)
                        {
                            FixTooltip(cli);
                            if (cli.GetCrewRef().inactive)
                            {
                                cli.MouseoverEnabled = false;
                                bool notTraining = true;
                                for (int i = ActiveCourses.Count; i-- > 0 && notTraining;)
                                {
                                    foreach (ProtoCrewMember pcm in ActiveCourses[i].Students)
                                    {
                                        if (pcm == cli.GetCrewRef())
                                        {
                                            notTraining = false;
                                            cli.SetLabel("Training, done " + KSPUtil.PrintDate(ActiveCourses[i].startTime + ActiveCourses[i].GetTime(ActiveCourses[i].Students), false));
                                            break;
                                        }
                                    }
                                }
                                if (notTraining)
                                {
                                    cli.SetLabel("Recovering");
                                }
                            }
                        }
                    }

                    foreach (KSP.UI.UIListData <KSP.UI.UIListItem> u in astronautComplex.ScrollListAssigned)
                    {
                        KSP.UI.CrewListItem cli = u.listItem.GetComponent <KSP.UI.CrewListItem>();
                        if (cli != null)
                        {
                            FixTooltip(cli);
                        }
                    }

                    foreach (KSP.UI.UIListData <KSP.UI.UIListItem> u in astronautComplex.ScrollListKia)
                    {
                        KSP.UI.CrewListItem cli = u.listItem.GetComponent <KSP.UI.CrewListItem>();
                        if (cli != null)
                        {
                            if (retirees.Contains(cli.GetName()))
                            {
                                cli.SetLabel("Retired");
                                cli.MouseoverEnabled = false;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 20
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
 public UITab RenderCoursesTab()
 {
     _selectedCourse = null;
     RenderCourseSelector();
     return(_selectedCourse == null ? UITab.Courses : UITab.NewCourse);
 }
Ejemplo n.º 21
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
        public void RenderNautTab()
        {
            UpdateActiveCourseMap();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(_selectedNaut.name);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            try
            {
                GUILayout.Label($"{_selectedNaut.trait} {_selectedNaut.experienceLevel.ToString():D}");
                if (CrewHandler.Instance.RetirementEnabled && CrewHandler.Instance.KerbalRetireTimes.ContainsKey(_selectedNaut.name))
                {
                    GUILayout.Space(8);
                    GUILayout.Label($"Retires NET {KSPUtil.PrintDate(CrewHandler.Instance.KerbalRetireTimes[_selectedNaut.name], false)}", RightLabel);
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            GUILayout.EndHorizontal();

            double nlt = CrewHandler.Instance.GetLatestRetireTime(_selectedNaut);

            if (nlt > 0)
            {
                GUILayout.BeginHorizontal();
                GUILayout.Label(string.Empty, GUILayout.ExpandWidth(true));
                GUILayout.Label($"Retires NLT {KSPUtil.PrintDate(nlt, false)}", RightLabel);
                GUILayout.EndHorizontal();
            }

            if (_activeMap.ContainsKey(_selectedNaut))
            {
                ActiveCourse currentCourse = _activeMap[_selectedNaut];
                GUILayout.BeginHorizontal();
                try
                {
                    GUILayout.Label($"Studying {currentCourse.name} until {KSPUtil.PrintDate(currentCourse.CompletionTime(), false)}");
                    if (currentCourse.seatMin > 1)
                    {
                        if (GUILayout.Button("Cancel", HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                        {
                            CancelCourse(currentCourse);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Remove", HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                        {
                            LeaveCourse(currentCourse, _selectedNaut);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.LogException(ex);
                }
                GUILayout.EndHorizontal();
            }
            GUILayout.Label(CrewHandler.Instance.GetTrainingString(_selectedNaut));
        }
Ejemplo n.º 22
0
Archivo: FSGUI.cs Proyecto: KvaNTy/RP-0
        protected void RenderNautListRow(UITab currentTab, ProtoCrewMember student)
        {
            ActiveCourse currentCourse = null;

            if (_activeMap.ContainsKey(student))
            {
                currentCourse = _activeMap[student];
            }
            bool selectedForCourse = _selectedCourse != null && _selectedCourse.Students.Contains(student);

            GUILayout.BeginHorizontal();
            try
            {
                GUILayout.Label($"{student.trait.Substring(0, 1)} {student.experienceLevel}", GUILayout.Width(24));
                if (currentCourse == null && _selectedCourse != null && (selectedForCourse || _selectedCourse.MeetsStudentReqs(student)))
                {
                    var c = new GUIContent(student.name, "Select for course");
                    if (RenderToggleButton(c, selectedForCourse, GUILayout.Width(144)))
                    {
                        if (selectedForCourse)
                        {
                            _selectedCourse.RemoveStudent(student);
                        }
                        else
                        {
                            _selectedCourse.AddStudent(student);
                        }
                    }
                }
                else if (currentTab == UITab.Training)
                {
                    if (GUILayout.Button(student.name, HighLogic.Skin.button, GUILayout.Width(144)))
                    {
                        _selectedNaut = student;
                    }
                }
                else
                {
                    GUILayout.Label(student.name, GUILayout.Width(144));
                }

                string course, complete, retires;
                bool   isInactive = false;
                if (currentCourse == null)
                {
                    if (student.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        course   = "(in-flight)";
                        complete = "(n/a)";
                    }
                    else if (student.inactive)
                    {
                        course     = "(inactive)";
                        complete   = KSPUtil.PrintDate(student.inactiveTimeEnd, false);
                        isInactive = true;
                    }
                    else
                    {
                        course   = "(free)";
                        complete = "(n/a)";
                    }
                }
                else
                {
                    course   = currentCourse.name;
                    complete = KSPUtil.PrintDate(currentCourse.CompletionTime(), false);
                }
                GUILayout.Label(course, GUILayout.Width(96));
                GUILayout.Label(complete, GUILayout.Width(80));

                if (CrewHandler.Instance.KerbalRetireTimes.ContainsKey(student.name))
                {
                    retires = CrewHandler.Instance.RetirementEnabled ? KSPUtil.PrintDate(CrewHandler.Instance.KerbalRetireTimes[student.name], false) : "(n/a)";
                }
                else
                {
                    retires = "(unknown)";
                }
                GUILayout.Label(retires, GUILayout.Width(80));

                if (currentCourse != null)
                {
                    if (currentCourse.seatMin > 1)
                    {
                        if (GUILayout.Button(new GUIContent("X", "Cancel course"), HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                        {
                            CancelCourse(currentCourse);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(new GUIContent("X", "Remove from course"), HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                        {
                            LeaveCourse(currentCourse, student);
                        }
                    }

                    if (KACWrapper.APIReady && GUILayout.Button(_nautRowAlarmBtnContent, HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                    {
                        CreateCourseFinishAlarm(student, currentCourse);
                    }
                }
                else if (KACWrapper.APIReady && isInactive && GUILayout.Button(_nautRowAlarmBtnContent, HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                {
                    CreateReturnToDutyAlarm(student);
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 23
0
        protected void nautListRow(tabs currentTab, ProtoCrewMember student)
        {
            GUIStyle     style         = HighLogic.Skin.label;
            ActiveCourse currentCourse = null;

            if (activeMap.ContainsKey(student))
            {
                currentCourse = activeMap[student];
            }
            bool onSelectedCourse = selectedCourse != null && currentCourse != null && currentCourse.id == selectedCourse.id;

            if (onSelectedCourse)
            {
                style = boldLabel;
            }
            bool selectedForCourse = selectedCourse != null && selectedCourse.Students.Contains(student);

            GUILayout.BeginHorizontal();
            try {
                GUILayout.Label(String.Format("{0} {1}", student.trait.Substring(0, 1), student.experienceLevel), GUILayout.Width(24));
                if (currentCourse == null && selectedCourse != null && (selectedForCourse || selectedCourse.MeetsStudentReqs(student)))
                {
                    if (toggleButton(student.name, selectedForCourse, GUILayout.Width(144)))
                    {
                        if (selectedForCourse)
                        {
                            selectedCourse.RemoveStudent(student);
                        }
                        else
                        {
                            selectedCourse.AddStudent(student);
                        }
                    }
                }
                else if (currentTab == tabs.Training)
                {
                    if (GUILayout.Button(student.name, GUILayout.Width(144)))
                    {
                        selectedNaut = student;
                    }
                }
                else
                {
                    GUILayout.Label(student.name, GUILayout.Width(144));
                }
                string course, complete, retires;
                if (currentCourse == null)
                {
                    if (student.inactive)
                    {
                        course   = "(inactive)";
                        complete = KSPUtil.PrintDate(student.inactiveTimeEnd, false);
                    }
                    else
                    {
                        course   = "(free)";
                        complete = "(n/a)";
                    }
                }
                else
                {
                    course   = currentCourse.name;
                    complete = KSPUtil.PrintDate(currentCourse.CompletionTime(), false);
                }
                GUILayout.Label(course, GUILayout.Width(96));
                GUILayout.Label(complete, GUILayout.Width(80));
                if (CrewHandler.Instance.kerbalRetireTimes.ContainsKey(student.name))
                {
                    retires = CrewHandler.Instance.retirementEnabled ? KSPUtil.PrintDate(CrewHandler.Instance.kerbalRetireTimes[student.name], false) : "(n/a)";
                }
                else
                {
                    retires = "(unknown)";
                }
                GUILayout.Label(retires, GUILayout.Width(80));
                if (currentCourse != null)
                {
                    if (currentCourse.seatMin > 1)
                    {
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            cancelCourse(currentCourse);
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("X", GUILayout.ExpandWidth(false)))
                        {
                            leaveCourse(currentCourse, student);
                        }
                    }

                    if (KACWrapper.APIReady && GUILayout.Button(nautRowAlarmBtnContent, GUILayout.ExpandWidth(false)))
                    {
                        // CrewHandler processes trainings every 3600 seconds. Need to account for that to set up accurate KAC alarms.
                        double completeUT = currentCourse.CompletionTime();
                        double timeDiff   = completeUT - CrewHandler.Instance.nextUpdate;
                        double timesChRun = Math.Ceiling(timeDiff / CrewHandler.Instance.updateInterval);
                        double alarmUT    = CrewHandler.Instance.nextUpdate + timesChRun * CrewHandler.Instance.updateInterval;
                        string alarmTxt   = $"{currentCourse.name} - {student.name}";
                        KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Crew, alarmTxt, alarmUT);
                    }
                }
            } finally {
                GUILayout.EndHorizontal();
            }
        }
Ejemplo n.º 24
0
 public tabs coursesTab()
 {
     selectedCourse = null;
     courseSelector();
     return(selectedCourse == null ? tabs.Courses : tabs.NewCourse);
 }