コード例 #1
0
ファイル: FSGUI.cs プロジェクト: Wallum/LRTR
        private static void CreateCourseFinishAlarm(ProtoCrewMember student, ActiveCourse currentCourse, bool StockAlarmEnabled)
        {
            // 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}";

            if (KACWrapper.APIReady)
            {
                KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Crew, alarmTxt, alarmUT);
            }
            if (StockAlarmEnabled)
            {
                AlarmTypeRaw alarmToSet = new AlarmTypeRaw
                {
                    title       = alarmTxt,
                    description = alarmTxt,
                    actions     =
                    {
                        warp    = AlarmActions.WarpEnum.KillWarp,
                        message = AlarmActions.MessageEnum.Yes
                    },
                    ut = alarmUT
                };
                AlarmClockScenario.AddAlarm(alarmToSet);
            }
        }
コード例 #2
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", () => { });
            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 DialogGUIHorizontalLayout(options));

            PopupDialog.SpawnPopupDialog(diag, false, HighLogic.UISkin);
        }
コード例 #3
0
 public Tabs summaryTab()
 {
     selectedCourse = null;
     selectedNaut   = null;
     summaryBody(Tabs.Training);
     return(selectedNaut == null ? Tabs.Training : Tabs.Naut);
 }
コード例 #4
0
ファイル: FSGUI.cs プロジェクト: Wallum/LRTR
        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();
        }
コード例 #5
0
ファイル: FSGUI.cs プロジェクト: Wallum/LRTR
 public UITab RenderSummaryTab()
 {
     _selectedCourse = null;
     _selectedNaut   = null;
     RenderSummaryBody(UITab.Training);
     return(_selectedNaut == null ? UITab.Training : UITab.Naut);
 }
コード例 #6
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));
        }
コード例 #7
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;)
                        {
                            if (e.Entries.Count == 0)
                            {
                                break;
                            }
                            FlightLog.Entry ent = pcm.careerLog[j];
                            for (int k = e.Entries.Count; 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();
            }
        }
コード例 #8
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(), true, 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);
        }
コード例 #9
0
ファイル: FSGUI.cs プロジェクト: Wallum/LRTR
        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);
        }
コード例 #10
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);
        }
コード例 #11
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();
            }
        }
コード例 #12
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.rosterStatus == ProtoCrewMember.RosterStatus.Assigned)
                    {
                        course   = "(in-flight)";
                        complete = KSPUtil.PrintDate(student.inactiveTimeEnd, false);
                    }
                    else 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.UpdateInterval);
                        double alarmUT    = CrewHandler.Instance.NextUpdate + timesChRun * CrewHandler.UpdateInterval;
                        string alarmTxt   = $"{currentCourse.name} - {student.name}";
                        KACWrapper.KAC.CreateAlarm(KACWrapper.KACAPI.AlarmTypeEnum.Crew, alarmTxt, alarmUT);
                    }
                }
            } finally {
                GUILayout.EndHorizontal();
            }
        }
コード例 #13
0
 public Tabs coursesTab()
 {
     selectedCourse = null;
     courseSelector();
     return(selectedCourse == null ? Tabs.Courses : Tabs.NewCourse);
 }
コード例 #14
0
ファイル: FSGUI.cs プロジェクト: Wallum/LRTR
        protected void RenderNautListRow(UITab currentTab, ProtoCrewMember student)
        {
            ActiveCourse currentCourse     = null;
            bool         StockAlarmEnabled = HighLogic.CurrentGame.Parameters.CustomParams <LRTRSettings>().StockAlarmClockEnabled;

            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 || StockAlarmEnabled) && GUILayout.Button(_nautRowAlarmBtnContent, HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                    {
                        CreateCourseFinishAlarm(student, currentCourse, StockAlarmEnabled);
                    }
                }
                else if ((KACWrapper.APIReady || StockAlarmEnabled) && isInactive && GUILayout.Button(_nautRowAlarmBtnContent, HighLogic.Skin.button, GUILayout.ExpandWidth(false)))
                {
                    CreateReturnToDutyAlarm(student, StockAlarmEnabled);
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
            GUILayout.EndHorizontal();
        }
コード例 #15
0
ファイル: FSGUI.cs プロジェクト: Wallum/LRTR
        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));
        }
コード例 #16
0
ファイル: FSGUI.cs プロジェクト: Wallum/LRTR
 public UITab RenderCoursesTab()
 {
     _selectedCourse = null;
     RenderCourseSelector();
     return(_selectedCourse == null ? UITab.Courses : UITab.NewCourse);
 }