// set highlighting static void highlight(Part p) { if (DB.Vessel(p.vessel).cfg_highlights) { // get state among all reliability components in the part bool broken = false; bool critical = false; foreach (Reliability m in p.FindModulesImplementing <Reliability>()) { broken |= m.broken; critical |= m.critical; } if (broken) { Highlighter.set(p.flightID, !critical ? Color.yellow : Color.red); } } }
public static void devman(this Panel p, Vessel v) { // avoid corner-case when this is called in a lambda after scene changes v = FlightGlobals.FindVessel(v.id); // if vessel doesn't exist anymore, leave the panel empty if (v == null) { return; } // get info from the cache vessel_info vi = Cache.VesselInfo(v); // if not a valid vessel, leave the panel empty if (!vi.is_valid) { return; } // set metadata p.title(Lib.BuildString(Lib.Ellipsis(v.vesselName, 24), " <color=#cccccc>DEV MANAGER</color>")); // time-out simulation if (p.timeout(vi)) { return; } // get devices Dictionary <uint, Device> devices = Computer.boot(v); // direct control if (script_index == 0) { // draw section title and desc p.section ( "DEVICES", description(), () => p.prev(ref script_index, (int)ScriptType.last), () => p.next(ref script_index, (int)ScriptType.last) ); // for each device foreach (var pair in devices) { // render device entry Device dev = pair.Value; p.content(dev.name(), dev.info(), string.Empty, dev.toggle, () => Highlighter.set(dev.part(), Color.cyan)); } } // script editor else { // get script ScriptType script_type = (ScriptType)script_index; string script_name = script_type.ToString().Replace('_', ' ').ToUpper(); Script script = DB.Vessel(v).computer.get(script_type); // draw section title and desc p.section ( script_name, description(), () => p.prev(ref script_index, (int)ScriptType.last), () => p.next(ref script_index, (int)ScriptType.last) ); // for each device foreach (var pair in devices) { // determine tribool state int state = !script.states.ContainsKey(pair.Key) ? -1 : !script.states[pair.Key] ? 0 : 1; // render device entry Device dev = pair.Value; p.content ( dev.name(), state == -1 ? "<color=#999999>don't care</color>" : state == 0 ? "<color=red>off</color>" : "<color=cyan>on</color>", string.Empty, () => { switch (state) { case -1: script.set(dev, true); break; case 0: script.set(dev, null); break; case 1: script.set(dev, false); break; } }, () => Highlighter.set(dev.part(), Color.cyan) ); } } // no devices case if (devices.Count == 0) { p.content("<i>no devices</i>"); } }