public void Update() { if (!KerbalHealthGeneralSettings.Instance.modEnabled) { if (reportWindow != null) { reportWindow.Dismiss(); } return; } if ((reportWindow != null) && dirty) { if (gridContents == null) { Core.Log("gridContents is null.", LogLevel.Error); return; } // # of tracked kerbals has changed => close & reopen the window if (gridContents.Count != (ShipConstruction.ShipManifest.CrewCount + 1) * colNum) { Core.Log("Kerbals' number has changed. Recreating the Health Report window.", LogLevel.Important); UndisplayData(); DisplayData(); } // Fill the Health Report's grid with kerbals' health data int i = 0; KerbalHealthStatus khs = null; HealthModifierSet.VesselCache.Clear(); List <ModuleKerbalHealth> trainingParts = Core.GetTrainingCapableParts(EditorLogic.SortedShipList); foreach (ProtoCrewMember pcm in ShipConstruction.ShipManifest.GetAllCrew(false).Where(pcm => pcm != null)) { khs = Core.KerbalHealthList[pcm]?.Clone(); if (khs == null) { Core.Log("Could not create a clone of KerbalHealthStatus for " + pcm.name + ". It is " + ((Core.KerbalHealthList[pcm] == null) ? "not " : "") + "found in KerbalHealthList, which contains " + Core.KerbalHealthList.Count + " records.", LogLevel.Error); i++; continue; } gridContents[(i + 1) * colNum].SetOptionText(khs.FullName); khs.HP = khs.MaxHP; // Making this call here, so that GetBalanceHP doesn't have to: double changePerDay = khs.HealthChangePerDay(); double balanceHP = khs.GetBalanceHP(); string s = balanceHP > 0 ? "-> " + balanceHP.ToString("F0") + " HP (" + (balanceHP / khs.MaxHP * 100).ToString("F0") + "%)" : Localizer.Format("#KH_ER_HealthPerDay", changePerDay.ToString("F1")); // + " HP/day" gridContents[(i + 1) * colNum + 1].SetOptionText(s); s = balanceHP > khs.NextConditionHP() ? "—" : ((khs.LastRecuperation > khs.LastDecay) ? "> " : "") + Core.ParseUT(khs.TimeToNextCondition(), false, 100); gridContents[(i + 1) * colNum + 2].SetOptionText(s); gridContents[(i + 1) * colNum + 3].SetOptionText(KerbalHealthFactorsSettings.Instance.TrainingEnabled ? Core.ParseUT(TrainingTime(khs, trainingParts), false, 100) : "N/A"); i++; } spaceLbl.SetOptionText("<color=\"white\">" + khs.VesselModifiers.Space.ToString("F1") + "</color>"); recupLbl.SetOptionText("<color=\"white\">" + khs.VesselModifiers.Recuperation.ToString("F1") + "%</color>"); shieldingLbl.SetOptionText("<color=\"white\">" + khs.VesselModifiers.Shielding.ToString("F1") + "</color>"); exposureLbl.SetOptionText("<color=\"white\">" + khs.LastExposure.ToString("P1") + "</color>"); shelterExposureLbl.SetOptionText("<color=\"white\">" + khs.VesselModifiers.ShelterExposure.ToString("P1") + "</color>"); dirty = false; } }
public void Update() { if (!Core.ModEnabled) { if (reportWindow != null) { reportWindow.Dismiss(); } return; } if ((reportWindow != null) && dirty) { if (gridContents == null) { Core.Log("gridContents is null.", Core.LogLevel.Error); return; } if (gridContents.Count != (ShipConstruction.ShipManifest.CrewCount + 1) * colNum) // # of tracked kerbals has changed => close & reopen the window { Core.Log("Kerbals' number has changed. Recreating the Health Report window.", Core.LogLevel.Important); UndisplayData(); DisplayData(); } // Fill the Health Report's grid with kerbals' health data int i = 0; KerbalHealthStatus khs = null; VesselHealthInfo.Cache.Clear(); foreach (ProtoCrewMember pcm in ShipConstruction.ShipManifest.GetAllCrew(false)) { if (pcm == null) { continue; } gridContents[(i + 1) * colNum].SetOptionText(pcm.name); khs = Core.KerbalHealthList?.Find(pcm)?.Clone(); if (khs == null) { Core.Log("Could not create a clone of KerbalHealthStatus for " + pcm.name + ". It is " + ((Core.KerbalHealthList?.Find(pcm) == null) ? "not " : "") + "found in KerbalHealthList, which contains " + Core.KerbalHealthList.Count + " records.", Core.LogLevel.Error); i++; continue; } khs.HP = khs.MaxHP; double ch = khs.HealthChangePerDay(); double b = khs.GetBalanceHP(); string s = ""; if (b > 0) { s = "-> " + b.ToString("F0") + " HP (" + (b / khs.MaxHP * 100).ToString("F0") + "%)"; } else { s = ch.ToString("F1") + " HP/day"; } gridContents[(i + 1) * colNum + 1].SetOptionText(s); if (b > khs.NextConditionHP()) { s = "—"; } else { s = ((khs.LastRecuperation > khs.LastDecay) ? "> " : "") + Core.ParseUT(khs.TimeToNextCondition()); } gridContents[(i + 1) * colNum + 2].SetOptionText(s); i++; } spaceLbl.SetOptionText(khs.VesselHealthInfo.Space.ToString("F1")); recupLbl.SetOptionText(khs.VesselHealthInfo.Recuperation.ToString("F1") + "%"); shieldingLbl.SetOptionText(khs.VesselHealthInfo.Shielding.ToString("F1")); exposureLbl.SetOptionText(khs.Exposure.ToString("P1")); dirty = false; } }