Beispiel #1
0
        /// <summary>
        /// Displays actual values in Health Monitor
        /// </summary>
        public void Update()
        {
            if (!Core.ModEnabled)
            {
                if (monitorWindow != null)
                {
                    monitorWindow.Dismiss();
                }
                return;
            }

            if ((monitorWindow == null) || !dirty)
            {
                return;
            }

            if (gridContents == null)
            {
                Core.Log("KerbalHealthScenario.gridContents is null.", Core.LogLevel.Error);
                return;
            }

            if (selectedKHS == null)  // Showing list of all kerbals
            {
                if (crewChanged)
                {
                    Core.KerbalHealthList.RegisterKerbals();
                    if ((page >= PageCount) || (Core.KerbalHealthList.Count == LinesPerPage + 1))
                    {
                        Invalidate();
                    }
                    crewChanged = false;
                }
                // Fill the Health Monitor's grid with kerbals' health data
                for (int i = 0; i < LineCount; i++)
                {
                    List <KerbalHealthStatus> kerbals = new List <KerbalHealth.KerbalHealthStatus>(Core.KerbalHealthList.Values);
                    KerbalHealthStatus        khs     = kerbals[FirstLine + i];
                    bool   frozen = khs.HasCondition("Frozen");
                    double ch     = khs.LastChangeTotal;
                    gridContents[(i + 1) * colNumMain].SetOptionText(khs.Name);
                    gridContents[(i + 1) * colNumMain + 1].SetOptionText(khs.ConditionString);
                    gridContents[(i + 1) * colNumMain + 2].SetOptionText((100 * khs.Health).ToString("F2") + "% (" + khs.HP.ToString("F2") + ")");
                    gridContents[(i + 1) * colNumMain + 3].SetOptionText((frozen || (khs.Health >= 1)) ? "—" : (((ch > 0) ? "+" : "") + ch.ToString("F2")));
                    double b = khs.GetBalanceHP();
                    string s = "";
                    if (frozen || (b > khs.NextConditionHP()))
                    {
                        s = "—";
                    }
                    else
                    {
                        s = ((b > 0) ? "> " : "") + Core.ParseUT(khs.TimeToNextCondition(), true, 100);
                    }
                    gridContents[(i + 1) * colNumMain + 4].SetOptionText(s);
                    gridContents[(i + 1) * colNumMain + 5].SetOptionText(khs.Dose.ToString("N0") + (khs.Radiation != 0 ? " (+" + khs.Radiation.ToString("N0") + "/day)" : ""));
                }
            }
            else  // Showing details for one particular kerbal
            {
                ProtoCrewMember pcm    = selectedKHS.PCM;
                bool            frozen = selectedKHS.HasCondition("Frozen");
                gridContents[1].SetOptionText(selectedKHS.Name);
                gridContents[3].SetOptionText(pcm.experienceLevel.ToString());
                string s = "";
                foreach (Quirk q in selectedKHS.Quirks)
                {
                    if (q.IsVisible)
                    {
                        s += ((s != "") ? ", " : "") + q.Title;
                    }
                }
                if (s == "")
                {
                    s = "None";
                }
                gridContents[5].SetOptionText(s);
                gridContents[7].SetOptionText(pcm.rosterStatus.ToString());
                gridContents[9].SetOptionText(selectedKHS.MaxHP.ToString("F2"));
                gridContents[11].SetOptionText(selectedKHS.HP.ToString("F2") + " (" + selectedKHS.Health.ToString("P2") + ")");
                gridContents[13].SetOptionText(frozen ? "—" : selectedKHS.LastChangeTotal.ToString("F2"));
                int i = 15;
                if (Core.IsKerbalLoaded(selectedKHS.PCM) && !frozen)
                {
                    foreach (HealthFactor f in Core.Factors)
                    {
                        gridContents[i].SetOptionText(selectedKHS.Factors.ContainsKey(f.Name) ? selectedKHS.Factors[f.Name].ToString("F2") : "N/A");
                        i += 2;
                    }
                }
                gridContents[i].SetOptionText(frozen ? "N/A" : selectedKHS.LastRecuperation.ToString("F1") + "% (" + selectedKHS.MarginalChange.ToString("F2") + " HP/day)");
                gridContents[i + 2].SetOptionText(selectedKHS.ConditionString);
                gridContents[i + 4].SetOptionText(selectedKHS.Exposure.ToString("P2"));
                gridContents[i + 6].SetOptionText(selectedKHS.Radiation.ToString("N2") + "/day");
                gridContents[i + 8].SetOptionText(selectedKHS.Dose.ToString("N2"));
                gridContents[i + 10].SetOptionText((1 - selectedKHS.RadiationMaxHPModifier).ToString("P2"));
            }
            dirty = false;
        }
Beispiel #2
0
        /// <summary>
        /// Shows Health monitor when the AppLauncher/Blizzy's Toolbar button is clicked
        /// </summary>
        public void DisplayData()
        {
            Core.Log("KerbalHealthScenario.DisplayData", Core.LogLevel.Important);
            UpdateKerbals(true);
            if (selectedKHS == null)
            {
                Core.Log("No kerbal selected, showing overall list.");

                // Preparing a sorted list of kerbals
                kerbals = new SortedList <ProtoCrewMember, KerbalHealthStatus>(new KerbalComparer(HighLogic.CurrentGame.Parameters.CustomParams <KerbalHealthGeneralSettings>().SortByLocation));
                foreach (KerbalHealthStatus khs in Core.KerbalHealthList.Values)
                {
                    kerbals.Add(khs.PCM, khs);
                }

                DialogGUILayoutBase layout = new DialogGUIVerticalLayout(true, true);
                if (page > PageCount)
                {
                    page = PageCount;
                }
                if (ShowPages)
                {
                    layout.AddChild(new DialogGUIHorizontalLayout(true, false,
                                                                  new DialogGUIButton("<<", FirstPage, () => (page > 1), true),
                                                                  new DialogGUIButton("<", PageUp, () => (page > 1), false),
                                                                  new DialogGUIHorizontalLayout(TextAnchor.LowerCenter, new DialogGUILabel("Page " + page + "/" + PageCount)),
                                                                  new DialogGUIButton(">", PageDown, () => (page < PageCount), false),
                                                                  new DialogGUIButton(">>", LastPage, () => (page < PageCount), true)));
                }
                gridContents = new List <DialogGUIBase>((Core.KerbalHealthList.Count + 1) * colNumMain);

                // Creating column titles
                gridContents.Add(new DialogGUILabel("<b><color=\"white\">Name</color></b>", true));
                gridContents.Add(new DialogGUILabel("<b><color=\"white\">Location</color></b>", true));
                gridContents.Add(new DialogGUILabel("<b><color=\"white\">Condition</color></b>", true));
                gridContents.Add(new DialogGUILabel("<b><color=\"white\">Health</color></b>", true));
                gridContents.Add(new DialogGUILabel("<b><color=\"white\">Change/day</color></b>", true));
                gridContents.Add(new DialogGUILabel("<b><color=\"white\">Time Left</color></b>", true));
                gridContents.Add(new DialogGUILabel("<b><color=\"white\">Radiation</color></b>", true));
                gridContents.Add(new DialogGUILabel("", true));

                // Initializing Health Monitor's grid with empty labels, to be filled in Update()
                for (int i = FirstLine; i < FirstLine + LineCount; i++)
                {
                    for (int j = 0; j < colNumMain - 1; j++)
                    {
                        gridContents.Add(new DialogGUILabel("", true));
                    }
                    gridContents.Add(new DialogGUIButton <int>("Details", (n) => { selectedKHS = kerbals.Values[n]; Invalidate(); }, i));
                }
                layout.AddChild(new DialogGUIGridLayout(new RectOffset(0, 0, 0, 0), new Vector2(colWidth, 30), new Vector2(colSpacing, 10), UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleCenter, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, colNumMain, gridContents.ToArray()));
                monitorPosition.width = gridWidthList + 10;
                monitorWindow         = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("Health Monitor", "", "Health Monitor", HighLogic.UISkin, monitorPosition, layout), false, HighLogic.UISkin, false);
            }

            else
            {
                // Creating the grid for detailed view, which will be filled in Update method
                Core.Log("Showing details for " + selectedKHS.Name + ".");
                gridContents = new List <DialogGUIBase>();
                gridContents.Add(new DialogGUILabel("Name:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Level:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Condition:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Quirks:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Max HP:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("HP:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("HP Change:"));
                gridContents.Add(new DialogGUILabel(""));
                if (Core.IsKerbalLoaded(selectedKHS.PCM) && !selectedKHS.HasCondition("Frozen"))
                {
                    foreach (HealthFactor f in Core.Factors)
                    {
                        gridContents.Add(new DialogGUILabel(f.Title + ":"));
                        gridContents.Add(new DialogGUILabel(""));
                    }
                }
                gridContents.Add(new DialogGUILabel("Recuperation:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Exposure:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Radiation:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Lifetime Dose:"));
                gridContents.Add(new DialogGUIHorizontalLayout(
                                     new DialogGUILabel(""),
                                     new DialogGUIButton("Decon", OnDecontamination, 50, 20, false)));
                gridContents.Add(new DialogGUILabel("Rad HP Loss:"));
                gridContents.Add(new DialogGUILabel(""));
                monitorPosition.width = gridWidthDetails + 10;
                monitorWindow         = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("Health Monitor", "", "Health Details", HighLogic.UISkin, monitorPosition, new DialogGUIVerticalLayout(new DialogGUIGridLayout(new RectOffset(3, 3, 3, 3), new Vector2(colWidth, 40), new Vector2(colSpacing, 10), UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleCenter, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, colNumDetails, gridContents.ToArray()), new DialogGUIButton("Back", () => { selectedKHS = null; Invalidate(); }, gridWidthDetails, 20, false))), false, HighLogic.UISkin, false);
            }
            dirty = true;
        }
Beispiel #3
0
        /// <summary>
        /// Shows Health monitor when the AppLauncher/Blizzy's Toolbar button is clicked
        /// </summary>
        public void DisplayData()
        {
            Core.Log("KerbalHealthScenario.DisplayData", Core.LogLevel.Important);
            UpdateKerbals(true);
            if (selectedKHS == null)
            {
                Core.Log("No kerbal selected, showing overall list.");
                DialogGUILayoutBase layout = new DialogGUIVerticalLayout(true, true);
                if (page > PageCount)
                {
                    page = PageCount;
                }
                if (ShowPages)
                {
                    layout.AddChild(new DialogGUIHorizontalLayout(true, false,
                                                                  new DialogGUIButton("<<", FirstPage, () => (page > 1), true),
                                                                  new DialogGUIButton("<", PageUp, () => (page > 1), false),
                                                                  new DialogGUIHorizontalLayout(TextAnchor.LowerCenter, new DialogGUILabel("Page " + page + "/" + PageCount)),
                                                                  new DialogGUIButton(">", PageDown, () => (page < PageCount), false),
                                                                  new DialogGUIButton(">>", LastPage, () => (page < PageCount), true)));
                }
                gridContents = new List <DialogGUIBase>((Core.KerbalHealthList.Count + 1) * colNumMain);
                // Creating column titles
                gridContents.Add(new DialogGUILabel("Name", true));
                gridContents.Add(new DialogGUILabel("Condition", true));
                gridContents.Add(new DialogGUILabel("Health", true));
                gridContents.Add(new DialogGUILabel("Change/day", true));
                gridContents.Add(new DialogGUILabel("Time Left", true));
                gridContents.Add(new DialogGUILabel("Radiation", true));
                gridContents.Add(new DialogGUILabel("", true));
                // Initializing Health Monitor's grid with empty labels, to be filled in Update()
                List <KerbalHealthStatus> kerbals = new List <KerbalHealth.KerbalHealthStatus>(Core.KerbalHealthList.Values);
                for (int i = FirstLine; i < FirstLine + LineCount; i++)
                {
                    for (int j = 0; j < colNumMain - 1; j++)
                    {
                        gridContents.Add(new DialogGUILabel("", true));
                    }
                    gridContents.Add(new DialogGUIButton <int>("Details", (n) => { selectedKHS = kerbals[n]; Invalidate(); }, i));
                }
                layout.AddChild(new DialogGUIGridLayout(new RectOffset(0, 0, 0, 0), new Vector2(colWidth, 30), new Vector2(colSpacing, 10), UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleCenter, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, colNumMain, gridContents.ToArray()));
                monitorPosition.width = gridWidthMain + 10;
                monitorWindow         = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("Health Monitor", "", "Health Monitor", HighLogic.UISkin, monitorPosition, layout), false, HighLogic.UISkin, false);
            }

            else
            {
                Core.Log("Showing details for " + selectedKHS.Name + ".");
                gridContents = new List <DialogGUIBase>();
                gridContents.Add(new DialogGUILabel("Name:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Level:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Quirks:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Status:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Max HP:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("HP:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("HP Change:"));
                gridContents.Add(new DialogGUILabel(""));
                if (Core.IsKerbalLoaded(selectedKHS.PCM) && !selectedKHS.HasCondition("Frozen"))
                {
                    foreach (HealthFactor f in Core.Factors)
                    {
                        gridContents.Add(new DialogGUILabel(f.Title + ":"));
                        gridContents.Add(new DialogGUILabel(""));
                    }
                }
                gridContents.Add(new DialogGUILabel("Recuperation:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Condition:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Exposure:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Radiation:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Accumulated Dose:"));
                gridContents.Add(new DialogGUILabel(""));
                gridContents.Add(new DialogGUILabel("Radiation HP Loss:"));
                gridContents.Add(new DialogGUILabel(""));
                monitorPosition.width = gridWidthDetails + 10;
                monitorWindow         = PopupDialog.SpawnPopupDialog(new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new MultiOptionDialog("Health Monitor", "", "Health Details", HighLogic.UISkin, monitorPosition, new DialogGUIVerticalLayout(new DialogGUIGridLayout(new RectOffset(0, 0, 0, 0), new Vector2(colWidth, 30), new Vector2(colSpacing, 10), UnityEngine.UI.GridLayoutGroup.Corner.UpperLeft, UnityEngine.UI.GridLayoutGroup.Axis.Horizontal, TextAnchor.MiddleCenter, UnityEngine.UI.GridLayoutGroup.Constraint.FixedColumnCount, colNumDetails, gridContents.ToArray()), new DialogGUIButton("Back", () => { selectedKHS = null; Invalidate(); }, gridWidthDetails, 20, false))), false, HighLogic.UISkin, false);
            }
            dirty = true;
        }
Beispiel #4
0
        /// <summary>
        /// Displays actual values in Health Monitor
        /// </summary>
        public void Update()
        {
            if (!Core.ModEnabled)
            {
                if (monitorWindow != null)
                {
                    monitorWindow.Dismiss();
                }
                return;
            }

            if ((monitorWindow == null) || !dirty)
            {
                return;
            }

            if (gridContents == null)
            {
                Core.Log("KerbalHealthScenario.gridContents is null.", Core.LogLevel.Error);
                monitorWindow.Dismiss();
                return;
            }

            if (selectedKHS == null)  // Showing list of all kerbals
            {
                if (crewChanged)
                {
                    Core.KerbalHealthList.RegisterKerbals();
                    Invalidate();
                    crewChanged = false;
                }
                Core.Log(kerbals.Count + " kerbals in Health Monitor list.");
                // Fill the Health Monitor's grid with kerbals' health data
                for (int i = 0; i < LineCount; i++)
                {
                    KerbalHealthStatus khs = kerbals.Values[FirstLine + i];
                    bool   frozen          = khs.HasCondition("Frozen");
                    double ch = khs.LastChangeTotal;
                    double b = khs.GetBalanceHP();
                    string formatTag = "", formatUntag = "";
                    string s = "";
                    if (frozen || (b > khs.NextConditionHP()))
                    {
                        s = "—";
                    }
                    else
                    {
                        s = Core.ParseUT(khs.TimeToNextCondition(), true, 100);
                        if (ch < 0)
                        {
                            if (khs.TimeToNextCondition() < KSPUtil.dateTimeFormatter.Day)
                            {
                                formatTag = "<color=\"red\">";
                            }
                            else
                            {
                                formatTag = "<color=\"orange\">";
                            }
                            formatUntag = "</color>";
                        }
                    }
                    gridContents[(i + 1) * colNumMain].SetOptionText(formatTag + khs.Name + formatUntag);
                    gridContents[(i + 1) * colNumMain + 1].SetOptionText(formatTag + khs.LocationString + formatUntag);
                    gridContents[(i + 1) * colNumMain + 2].SetOptionText(formatTag + khs.ConditionString + formatUntag);
                    gridContents[(i + 1) * colNumMain + 3].SetOptionText(formatTag + (100 * khs.Health).ToString("F2") + "% (" + khs.HP.ToString("F2") + ")" + formatUntag);
                    gridContents[(i + 1) * colNumMain + 4].SetOptionText(formatTag + ((frozen || (khs.Health >= 1)) ? "—" : (((ch > 0) ? "+" : "") + ch.ToString("F2"))) + formatUntag);
                    gridContents[(i + 1) * colNumMain + 5].SetOptionText(formatTag + s + formatUntag);
                    gridContents[(i + 1) * colNumMain + 6].SetOptionText(formatTag + Core.PrefixFormat(khs.Dose, 5) + (khs.Radiation != 0 ? " (" + Core.PrefixFormat(khs.Radiation, 4, true) + "/day)" : "") + formatUntag);
                    //gridContents[(i + 1) * colNumMain + 6].SetOptionText(formatTag + khs.Dose.ToString("N0") + (khs.Radiation != 0 ? " (+" + khs.Radiation.ToString("N0") + "/day)" : "") + formatUntag);
                }
            }
            else  // Showing details for one particular kerbal
            {
                ProtoCrewMember pcm = selectedKHS.PCM;
                if (pcm == null)
                {
                    selectedKHS = null;
                    Invalidate();
                }
                bool frozen = selectedKHS.HasCondition("Frozen");
                gridContents[1].SetOptionText("<color=\"white\">" + selectedKHS.Name + "</color>");
                gridContents[3].SetOptionText("<color=\"white\">" + pcm.experienceLevel.ToString() + "</color>");
                gridContents[5].SetOptionText("<color=\"white\">" + selectedKHS.ConditionString + "</color>");
                string s = "";
                foreach (Quirk q in selectedKHS.Quirks)
                {
                    if (q.IsVisible)
                    {
                        s += ((s != "") ? ", " : "") + q.Title;
                    }
                }
                if (s == "")
                {
                    s = "None";
                }
                gridContents[7].SetOptionText("<color=\"white\">" + s + "</color>");
                gridContents[9].SetOptionText("<color=\"white\">" + selectedKHS.MaxHP.ToString("F2") + "</color>");
                gridContents[11].SetOptionText("<color=\"white\">" + selectedKHS.HP.ToString("F2") + " (" + selectedKHS.Health.ToString("P2") + ")" + "</color>");
                gridContents[13].SetOptionText("<color=\"white\">" + (frozen ? "—" : selectedKHS.LastChangeTotal.ToString("F2")) + "</color>");
                int i = 15;
                if (Core.IsKerbalLoaded(selectedKHS.PCM) && !frozen)
                {
                    foreach (HealthFactor f in Core.Factors)
                    {
                        gridContents[i].SetOptionText("<color=\"white\">" + (selectedKHS.Factors.ContainsKey(f.Name) ? selectedKHS.Factors[f.Name].ToString("F2") : "N/A") + "</color>");
                        i += 2;
                    }
                }
                gridContents[i].SetOptionText("<color=\"white\">" + (frozen ? "N/A" : (selectedKHS.LastRecuperation.ToString("F1") + "%" + (selectedKHS.LastDecay != 0 ? ("/ " + (-selectedKHS.LastDecay).ToString("F1") + "%") : "") + " (" + selectedKHS.MarginalChange.ToString("F2") + " HP)")) + "</color>");
                gridContents[i + 2].SetOptionText("<color=\"white\">" + selectedKHS.LastExposure.ToString("P2") + "</color>");
                gridContents[i + 4].SetOptionText("<color=\"white\">" + selectedKHS.Radiation.ToString("N0") + "/day</color>");
                gridContents[i + 6].SetOptionText("<color=\"white\">" + selectedKHS.Dose.ToString("N0") + "</color>");
                gridContents[i + 8].SetOptionText("<color=\"white\">" + (1 - selectedKHS.RadiationMaxHPModifier).ToString("P2") + "</color>");
            }
            dirty = false;
        }