// draw a vessel in the monitor // - return: 1 if vessel wasn't skipped uint render_vessel(Vessel v) { // avoid case when DB isn't ready for whatever reason if (!DB.Ready()) return 0; // skip invalid vessels if (!Lib.IsVessel(v)) return 0; // skip resque missions if (Lib.IsResqueMission(v)) return 0; // skip dead eva kerbals if (EVA.IsDead(v)) return 0; // get vessel info from cache vessel_info vi = Cache.VesselInfo(v); // get vessel data from the db vessel_data vd = DB.VesselData(v.id); // skip filtered vessels if (filtered() && vd.group != filter) return 0; // get vessel crew List<ProtoCrewMember> crew = v.loaded ? v.GetVesselCrew() : v.protoVessel.GetVesselCrew(); // get vessel name string vessel_name = v.isEVA ? crew[0].name : v.vesselName; // get body name string body_name = v.mainBody.name.ToUpper(); // get list of scrubbers List<Scrubber> scrubbers = Scrubber.GetScrubbers(v); // get list of greenhouses List<Greenhouse> greenhouses = Greenhouse.GetGreenhouses(v); // store problems icons & tooltips List<Texture> problem_icons = new List<Texture>(); List<string> problem_tooltips = new List<string>(); // detect problems problem_sunlight(vi, ref problem_icons, ref problem_tooltips); problem_storm(v, ref problem_icons, ref problem_tooltips); if (crew.Count > 0) { problem_kerbals(crew, ref problem_icons, ref problem_tooltips); problem_radiation(vi, ref problem_icons, ref problem_tooltips); problem_scrubbers(v, scrubbers, ref problem_icons, ref problem_tooltips); } problem_greenhouses(v, greenhouses, ref problem_icons, ref problem_tooltips); // choose problem icon const UInt64 problem_icon_time = 3; Texture problem_icon = icon_empty; if (problem_icons.Count > 0) { UInt64 problem_index = (Convert.ToUInt64(Time.realtimeSinceStartup) / problem_icon_time) % (UInt64)(problem_icons.Count); problem_icon = problem_icons[(int)problem_index]; } // generate problem tooltips string problem_tooltip = String.Join("\n", problem_tooltips.ToArray()); // render vessel name & icons GUILayout.BeginHorizontal(row_style); GUILayout.Label(new GUIContent("<b>" + Lib.Epsilon(vessel_name, 20) + "</b>", vessel_name.Length > 20 ? vessel_name : ""), name_style); GUILayout.Label(new GUIContent(Lib.Epsilon(body_name, 8), body_name.Length > 8 ? body_name : ""), body_style); GUILayout.Label(new GUIContent(problem_icon, problem_tooltip), icon_style); GUILayout.Label(indicator_ec(v), icon_style); GUILayout.Label(indicator_supplies(v, scrubbers, greenhouses), icon_style); GUILayout.Label(indicator_reliability(v), icon_style); GUILayout.Label(indicator_signal(v), icon_style); GUILayout.EndHorizontal(); // remember last vessel clicked if (Lib.IsClicked()) last_clicked_id = v.id; // render vessel config if (configured_id == v.id) render_config(v); // spacing between vessels GUILayout.Space(10.0f); // signal that the vessel wasn't skipped for whatever reason return 1; }
void render_info() { // find vessel Vessel v = FlightGlobals.Vessels.Find(k => k.id == vessel_id); // forget vessel if it doesn't exist anymore, or if its a dead eva kerbal if (v == null || EVA.IsDead(v)) { vessel_id = Guid.Empty; return; } // get info from the cache vessel_info vi = Cache.VesselInfo(v); render_title("ENVIRONMENT"); render_content("Temperature:\t", Lib.HumanReadableTemp(vi.temperature)); render_content("Radiation:\t", Lib.HumanReadableRadiationRate(vi.env_radiation)); render_content("Atmosphere:\t", v.mainBody.atmosphere ? " yes" + (vi.breathable ? " <i>(breathable)</i>" : "") : "no"); render_space(); // render supplies if (Kerbalism.supply_rules.Count > 0 || Kerbalism.ec_rule != null) { render_title("SUPPLIES"); if (Kerbalism.ec_rule != null) { var vmon = vi.vmon[Kerbalism.ec_rule.name]; render_content(fix_title("Battery:"), vmon.level > double.Epsilon ? Lib.HumanReadableDuration(vmon.depletion) : "none"); } if (Lib.CrewCapacity(v) > 0) { foreach(Rule r in Kerbalism.supply_rules) { var vmon = vi.vmon[r.name]; render_content(fix_title(r.resource_name + ":"), vmon.level > double.Epsilon ? Lib.HumanReadableDuration(vmon.depletion) : "none"); } } render_space(); } // get crew var crew = v.loaded ? v.GetVesselCrew() : v.protoVessel.GetVesselCrew(); // do not render internal spaces info for eva vessels if (!v.isEVA) { // collect set of spaces Dictionary<string, space_details> spaces = new Dictionary<string, space_details>(); foreach(var c in crew) { kerbal_data kd = DB.KerbalData(c.name); if (!spaces.ContainsKey(kd.space_name)) { space_details sd = new space_details(); sd.living_space = kd.living_space; sd.entertainment = kd.entertainment; sd.shielding = kd.shielding; spaces.Add(kd.space_name, sd); } ++(spaces[kd.space_name].crew_count); } // for each space foreach(var space in spaces) { string space_name = space.Key; space_details det = space.Value; string radiation_txt = vi.env_radiation > double.Epsilon ? " <i>(" + Lib.HumanReadableRadiationRate(vi.env_radiation * (1.0 - det.shielding)) + ")</i>" : ""; render_title(space_name.Length > 0 ? space_name.ToUpper() : v.isEVA ? "EVA" : "VESSEL"); render_content("Living space:\t", QualityOfLife.LivingSpaceToString(det.living_space)); render_content("Entertainment:\t", QualityOfLife.EntertainmentToString(det.entertainment)); render_content("Shielding:\t", Radiation.ShieldingToString(det.shielding) + radiation_txt); render_space(); } } // for each kerbal if (Kerbalism.rules.Count > 0) { foreach(var c in crew) { kerbal_data kd = DB.KerbalData(c.name); render_title(c.name.ToUpper()); foreach(var q in Kerbalism.rules) { Rule r = q.Value; if (r.degeneration > double.Epsilon) { var kmon = DB.KmonData(c.name, r.name); var bar = Lib.ProgressBar(23, kmon.problem, r.warning_threshold, r.danger_threshold, r.fatal_threshold, kd.disabled > 0 ? "cyan" : ""); render_content(fix_title(r.name + ":"), bar); } } if (kd.space_name.Length > 0 && !v.isEVA) render_content("Inside:\t\t", kd.space_name); if (kd.disabled > 0) render_content("Hibernated:\t", "yes"); render_space(); } } // for each greenhouse var greenhouses = Greenhouse.GetGreenhouses(v); foreach(var greenhouse in greenhouses) { render_title("GREENHOUSE"); render_content("Lighting:\t\t", (greenhouse.lighting * 100.0).ToString("F0") + "%"); render_content("Growth:\t\t", (greenhouse.growth * 100.0).ToString("F0") + "%"); render_content("Harvest:\t\t", Lib.HumanReadableDuration(greenhouse.growing > double.Epsilon ? 1.0 / greenhouse.growing : 0.0)); render_space(); } }