Exemple #1
0
		public static void Body_info(this Panel p)
		{
			// only show in mapview
			if (!MapView.MapIsEnabled) return;

			// only show if there is a selected body and that body is not the sun
			CelestialBody body = Lib.SelectedBody();
			if (body == null || (body.flightGlobalsIndex == 0 && !Features.Radiation)) return;

			// shortcut
			CelestialBody sun = FlightGlobals.Bodies[0];

			// for all bodies except the sun
			if (body != sun)
			{
				// calculate simulation values
				double atmo_factor = Sim.AtmosphereFactor(body, 0.7071);
				double gamma_factor = Sim.GammaTransparency(body, 0.0);
				double sun_dist = Sim.Apoapsis(Lib.PlanetarySystem(body)) - sun.Radius - body.Radius;
				Vector3d sun_dir = (sun.position - body.position).normalized;
				double solar_flux = Sim.SolarFlux(sun_dist) * atmo_factor;
				double albedo_flux = Sim.AlbedoFlux(body, body.position + sun_dir * body.Radius);
				double body_flux = Sim.BodyFlux(body, 0.0);
				double total_flux = solar_flux + albedo_flux + body_flux + Sim.BackgroundFlux();
				double temperature = body.atmosphere ? body.GetTemperature(0.0) : Sim.BlackBodyTemperature(total_flux);

				// calculate night-side temperature
				double total_flux_min = Sim.AlbedoFlux(body, body.position - sun_dir * body.Radius) + body_flux + Sim.BackgroundFlux();
				double temperature_min = Sim.BlackBodyTemperature(total_flux_min);

				// calculate radiation at body surface
				double radiation = Radiation.ComputeSurface(body, gamma_factor);

				// surface panel
				string temperature_str = body.atmosphere
				  ? Lib.HumanReadableTemp(temperature)
				  : Lib.BuildString(Lib.HumanReadableTemp(temperature_min), " / ", Lib.HumanReadableTemp(temperature));
				p.AddSection("SURFACE");
				p.AddContent("temperature", temperature_str);
				p.AddContent("solar flux", Lib.HumanReadableFlux(solar_flux));
				if (Features.Radiation) p.AddContent("radiation", Lib.HumanReadableRadiation(radiation));

				// atmosphere panel
				if (body.atmosphere)
				{
					p.AddSection("ATMOSPHERE");
					p.AddContent("breathable", Sim.Breathable(body) ? "yes" : "no");
					p.AddContent("light absorption", Lib.HumanReadablePerc(1.0 - Sim.AtmosphereFactor(body, 0.7071)));
					if (Features.Radiation) p.AddContent("gamma absorption", Lib.HumanReadablePerc(1.0 - Sim.GammaTransparency(body, 0.0)));
				}
			}

			// rendering panel
			if (Features.Radiation)
			{
				p.AddSection("RENDERING");
				p.AddContent("inner belt", Radiation.show_inner ? "<color=green>show</color>" : "<color=red>hide</color>", string.Empty, () => p.Toggle(ref Radiation.show_inner));
				p.AddContent("outer belt", Radiation.show_outer ? "<color=green>show</color>" : "<color=red>hide</color>", string.Empty, () => p.Toggle(ref Radiation.show_outer));
				p.AddContent("magnetopause", Radiation.show_pause ? "<color=green>show</color>" : "<color=red>hide</color>", string.Empty, () => p.Toggle(ref Radiation.show_pause));
			}

			// explain the user how to toggle the BodyInfo window
			p.AddContent(string.Empty);
			p.AddContent("<i>Press <b>B</b> to open this window again</i>");

			// set metadata
			p.Title(Lib.BuildString(Lib.Ellipsis(body.bodyName, Styles.ScaleStringLength(24)), " <color=#cccccc>BODY INFO</color>"));
		}
Exemple #2
0
        static void Render_file(Panel p, string filename, File file, Drive drive, bool short_strings, double rate)
        {
            // get experiment info
            ExperimentInfo exp = Science.Experiment(filename);

            // render experiment name
            string exp_label = Lib.BuildString
                               (
                "<b>",
                Lib.Ellipsis(exp.name, Styles.ScaleStringLength(short_strings ? 24 : 38)),
                "</b> <size=", Styles.ScaleInteger(10).ToString(), ">",
                Lib.Ellipsis(exp.situation, Styles.ScaleStringLength((short_strings ? 32 : 62) - Lib.Ellipsis(exp.name, Styles.ScaleStringLength(short_strings ? 24 : 38)).Length)),
                "</size>"
                               );
            string exp_tooltip = Lib.BuildString
                                 (
                exp.name, "\n",
                "<color=#aaaaaa>", exp.situation, "</color>"
                                 );
            double exp_value = Science.Value(filename, file.size);

            if (exp_value > double.Epsilon)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n<b>", Lib.HumanReadableScience(exp_value), "</b>");
            }

            if (rate > 0)
            {
                p.AddContent(exp_label, Lib.HumanReadableDataSize(file.size), "<i>" + Lib.HumanReadableDuration(file.size / rate) + "</i>");
            }
            else
            {
                p.AddContent(exp_label, Lib.HumanReadableDataSize(file.size), exp_tooltip);
            }

            p.AddIcon(file.send ? Icons.send_cyan : Icons.send_black, "Flag the file for transmission to <b>DSN</b>", () => { file.send = !file.send; });
            p.AddIcon(Icons.toggle_red, "Delete the file", () => Lib.Popup
                      (
                          "Warning!",
                          Lib.BuildString("Do you really want to delete ", exp.fullname, "?"),
                          new DialogGUIButton("Delete it", () => drive.files.Remove(filename)),
                          new DialogGUIButton("Keep it", () => { })
                      ));
        }
Exemple #3
0
        /// <summary>
        /// Shows the Network status, ControlPath, Signal strength
        /// </summary>
        public static void ConnMan(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, Styles.ScaleStringLength(40)), " <color=#cccccc>CONNECTION MANAGER</color>"));
            p.Width(Styles.ScaleWidthFloat(365.0f));
            p.paneltype = Panel.PanelType.connection;

            // time-out simulation
            if (p.Timeout(vi))
            {
                return;
            }

            // draw ControlPath section
            p.AddSection("CONTROL PATH");
            if (vi.connection.linked)
            {
                if (RemoteTech.Enabled)
                {
                    if (vi.connection.controlPath != null)
                    {
                        Guid i = v.id;
                        foreach (Guid id in vi.connection.controlPath)
                        {
                            p.AddContent(
                                Lib.Ellipsis(RemoteTech.GetSatelliteName(i) + " \\ " + RemoteTech.GetSatelliteName(id), 35),
                                Lib.HumanReadablePerc(Math.Ceiling((1 - (RemoteTech.GetCommsDistance(i, id) / RemoteTech.GetCommsMaxDistance(i, id))) * 10000) / 10000, "F2"),
                                "\nDistance: " + Lib.HumanReadableRange(RemoteTech.GetCommsDistance(i, id)) +
                                "\nMax Distance: " + Lib.HumanReadableRange(RemoteTech.GetCommsMaxDistance(i, id)));
                            i = id;
                        }
                    }
                }
                if (HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet)
                {
                    foreach (CommLink link in v.connection.ControlPath)
                    {
                        double antennaPower   = link.end.isHome ? link.start.antennaTransmit.power + link.start.antennaRelay.power : link.start.antennaTransmit.power;
                        double signalStrength = 1 - ((link.start.position - link.end.position).magnitude / Math.Sqrt(antennaPower * link.end.antennaRelay.power));

                        signalStrength = (3 - (2 * signalStrength)) * Math.Pow(signalStrength, 2);

                        p.AddContent(
                            Lib.Ellipsis(Localizer.Format(link.end.name).Replace("Kerbin", "DSN"), 35),
                            Lib.HumanReadablePerc(Math.Ceiling(signalStrength * 10000) / 10000, "F2"),
                            "\nDistance: " + Lib.HumanReadableRange((link.start.position - link.end.position).magnitude) +
                            "\nMax Distance: " + Lib.HumanReadableRange(Math.Sqrt((link.start.antennaTransmit.power + link.start.antennaRelay.power) * link.end.antennaRelay.power))
                            );
                    }
                }
            }
            else
            {
                p.AddContent("<i>no connection</i>", string.Empty);
            }
        }
        public static void NetMan(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, 20), " <color=#cccccc>NETWORK INFO</color>"));

            // time-out simulation
#if !DEBUG
            if (p.Timeout(vi))
            {
                return;
            }
#endif

            p.SetSection("ADAPTORS");
            p.Set_IsFreqSelector(true);

            // store all devices
            var devices = new Dictionary <uint, NetDevice>();

            // store device being added
            NetDevice adap;

            // loaded vessel
            if (v.loaded)
            {
                foreach (NetworkAdaptor m in Lib.FindModules <NetworkAdaptor>(v))
                {
                    adap = new NetAdaptorDevice(m);

                    // add the device
                    // - multiple same-type components in the same part will have the same id, and are ignored
                    if (!devices.ContainsKey(adap.Id()))
                    {
                        devices.Add(adap.Id(), adap);
                    }
                }
            }
            else
            {
                // store data required to support multiple modules of same type in a part
                var PD = new Dictionary <string, Lib.module_prefab_data>();

                // for each part
                foreach (ProtoPartSnapshot proto in v.protoVessel.protoPartSnapshots)
                {
                    // get part prefab (required for module properties)
                    Part part_prefab = PartLoader.getPartInfoByName(proto.partName).partPrefab;

                    // get all module prefabs
                    var module_prefabs = part_prefab.FindModulesImplementing <PartModule>();

                    // clear module indexes
                    PD.Clear();

                    // for each module
                    foreach (ProtoPartModuleSnapshot m in proto.modules)
                    {
                        // get the module prefab
                        // if the prefab doesn't contain this module, skip it
                        PartModule module_prefab = Lib.ModulePrefab(module_prefabs, m.moduleName, PD);
                        if (!module_prefab)
                        {
                            continue;
                        }

                        // if the module is disabled, skip it
                        // note: this must be done after ModulePrefab is called, so that indexes are right
                        if (!Lib.Proto.GetBool(m, "isEnabled"))
                        {
                            continue;
                        }

                        if (m.moduleName == "NetworkAdaptor")
                        {
                            adap = new ProtoNetAdaptorDevice(m, proto.flightID, v);

                            // add the device
                            // - multiple same-type components in the same part will have the same id, and are ignored
                            if (!devices.ContainsKey(adap.Id()))
                            {
                                devices.Add(adap.Id(), adap);
                            }
                        }
                    }
                }
            }

            // dict order by device name
            // for each device
            foreach (var pair in devices.OrderBy(x => x.Value.Name()))
            {
                // render device entry
                NetDevice dev = pair.Value;
                // Get how many antennas share the same freq
                AntennasByFrequency x = null;
                if (vi.antenna.antennasByFreq.ContainsKey(dev.InfoFreq()))
                {
                    x = vi.antenna.antennasByFreq[dev.InfoFreq()];
                }

                p.SetContent(dev.Name(), dev.InfoRate(), string.Empty, null, () => Highlighter.Set(dev.Part(), Color.cyan), dev.InfoFreq());
                p.SetIcon(Icons.left_freq, "Decrease", () =>
                {
                    if (dev.InfoFreq() > 0) // && x != null
                    {
                        //if (x.antCount == 1 && x.countConnections > 0)
                        //{
                        //  Lib.Popup(
                        //    "Warning!",
                        //    Lib.BuildString("This is the last antenna on '", dev.InfoFreq().ToString(),
                        //                    "' frequency.\nYou will lost connection in this frequency.\nDo you really want to remove this frequency from this vessel?"),
                        //    new DialogGUIButton("Remove", () => dev.ChangeFreq(-1)),
                        //    new DialogGUIButton("Keep it", () => { }));
                        //}
                        //else
                        dev.ChangeFreq(-1);
                    }
                });
                p.SetIcon(Icons.right_freq, "Increase", () =>
                {
                    if (dev.InfoFreq() < 99) // && x != null
                    {
                        //if (x.antCount == 1 && x.countConnections > 0)
                        //{
                        //  Lib.Popup(
                        //    "Warning!",
                        //    Lib.BuildString("This is the last antenna on '", dev.InfoFreq().ToString(),
                        //                    "' frequency.\nYou will lost connection in this frequency.\nDo you really want to remove this frequency from this vessel?"),
                        //    new DialogGUIButton("Remove", () => dev.ChangeFreq(+1)),
                        //    new DialogGUIButton("Keep it", () => { }));
                        //}
                        //else
                        dev.ChangeFreq(+1);
                    }
                });
            }

            p.SetSection("FREQUENCY(S) DETAIL");
            foreach (short key in vi.antenna.antennasByFreq.Keys)
            {
                double range = vi.antenna.antennasByFreq[key].antennaPower;
                double rate  = vi.antenna.antennasByFreq[key].antennaRate;

                Render_ConnectionDetail(p, range, rate, key);
            }
        }
Exemple #5
0
        static void Render_sample(Panel p, string filename, Sample sample, Drive drive, bool short_strings)
        {
            // get experiment info
            ExperimentInfo exp = Science.Experiment(filename);

            // render experiment name
            string exp_label = Lib.BuildString
                               (
                "<b>",
                Lib.Ellipsis(exp.name, Styles.ScaleStringLength(short_strings ? 24 : 38)),
                "</b> <size=", Styles.ScaleInteger(10).ToString(), ">",
                Lib.Ellipsis(exp.situation, Styles.ScaleStringLength((short_strings ? 32 : 62) - Lib.Ellipsis(exp.name, Styles.ScaleStringLength(short_strings ? 24 : 38)).Length)),
                "</size>"
                               );
            string exp_tooltip = Lib.BuildString
                                 (
                exp.name, "\n",
                "<color=#aaaaaa>", exp.situation, "</color>"
                                 );
            double exp_value = Science.Value(filename, sample.size);

            if (exp_value > double.Epsilon)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n<b>", Lib.HumanReadableScience(exp_value), "</b>");
            }

            p.AddContent(exp_label, Lib.HumanReadableDataSize(sample.size), exp_tooltip);
            p.AddIcon(sample.analyze ? Icons.lab_cyan : Icons.lab_black, "Flag the file for analysis in a <b>laboratory</b>", () => { sample.analyze = !sample.analyze; });
            p.AddIcon(Icons.toggle_red, "Dump the sample", () => Lib.Popup
                      (
                          "Warning!",
                          Lib.BuildString("Do you really want to dump ", exp.fullname, "?"),
                          new DialogGUIButton("Dump it", () => drive.samples.Remove(filename)),
                          new DialogGUIButton("Keep it", () => { })
                      ));
        }
Exemple #6
0
        static void Render_Crew(Panel p, List <ProtoCrewMember> crew)
        {
            // do nothing if there isn't a crew, or if there are no rules
            if (crew.Count == 0 || Profile.rules.Count == 0)
            {
                return;
            }

            // panel section
            p.SetSection("VITALS");

            // for each crew
            foreach (ProtoCrewMember kerbal in crew)
            {
                // get kerbal data from DB
                KerbalData kd = DB.Kerbal(kerbal.name);

                // analyze issues
                UInt32 health_severity = 0;
                UInt32 stress_severity = 0;

                // generate tooltip
                List <string> tooltips = new List <string>();
                foreach (Rule r in Profile.rules)
                {
                    // get rule data
                    RuleData rd = kd.Rule(r.name);

                    // add to the tooltip
                    tooltips.Add(Lib.BuildString("<b>", Lib.HumanReadablePerc(rd.problem / r.fatal_threshold), "</b>\t", Lib.SpacesOnCaps(r.name).ToLower()));

                    // analyze issue
                    if (rd.problem > r.danger_threshold)
                    {
                        if (!r.breakdown)
                        {
                            health_severity = Math.Max(health_severity, 2);
                        }
                        else
                        {
                            stress_severity = Math.Max(stress_severity, 2);
                        }
                    }
                    else if (rd.problem > r.warning_threshold)
                    {
                        if (!r.breakdown)
                        {
                            health_severity = Math.Max(health_severity, 1);
                        }
                        else
                        {
                            stress_severity = Math.Max(stress_severity, 1);
                        }
                    }
                }
                string tooltip = Lib.BuildString("<align=left />", String.Join("\n", tooltips.ToArray()));

                // generate kerbal name
                string name = kerbal.name.ToLower().Replace(" kerman", string.Empty);

                // render selectable title
                p.SetContent(Lib.Ellipsis(name, 20), kd.disabled ? "<color=#00ffff>HYBERNATED</color>" : string.Empty);
                p.SetIcon(health_severity == 0 ? Icons.health_white : health_severity == 1 ? Icons.health_yellow : Icons.health_red, tooltip);
                p.SetIcon(stress_severity == 0 ? Icons.brain_white : stress_severity == 1 ? Icons.brain_yellow : Icons.brain_red, tooltip);
            }
        }
Exemple #7
0
        public static void config(this Panel p, Vessel v)
        {
            // if vessel doesn't exist anymore, leave the panel empty
            if (FlightGlobals.FindVessel(v.id) == 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, 20), " <color=#cccccc>VESSEL CONFIG</color>"));

            // time-out simulation
            if (p.timeout(vi))
            {
                return;
            }

            // get data from db
            VesselData vd = DB.Vessel(v);

            // toggle rendering
            string tooltip;

            if (Features.Signal || Features.Reliability)
            {
                p.section("RENDERING");
            }
            if (Features.Signal)
            {
                tooltip = "Render the connection line\nin mapview and tracking station";
                p.content("show links", string.Empty, tooltip);
                p.icon(vd.cfg_showlink ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_showlink));
            }
            if (Features.Reliability)
            {
                tooltip = "Highlight failed components";
                p.content("highlight malfunctions", string.Empty, tooltip);
                p.icon(vd.cfg_highlights ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_highlights));
            }

            // toggle messages
            p.section("MESSAGES");
            tooltip = "Receive a message when\nElectricCharge level is low";
            p.content("battery", string.Empty, tooltip);
            p.icon(vd.cfg_ec ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_ec));
            if (Features.Supplies)
            {
                tooltip = "Receive a message when\nsupply resources level is low";
                p.content("supply", string.Empty, tooltip);
                p.icon(vd.cfg_supply ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_supply));
            }
            if (Features.Signal)
            {
                tooltip = "Receive a message when signal is lost or obtained";
                p.content("signal", string.Empty, tooltip);
                p.icon(vd.cfg_signal ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_signal));
            }
            if (Features.Reliability)
            {
                tooltip = "Receive a message\nwhen a component fail";
                p.content("reliability", string.Empty, tooltip);
                p.icon(vd.cfg_malfunction ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_malfunction));
            }
            if (Features.SpaceWeather)
            {
                tooltip = "Receive a message\nduring CME events";
                p.content("storm", string.Empty, tooltip);
                p.icon(vd.cfg_storm ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_storm));
            }
            if (Features.Automation)
            {
                tooltip = "Receive a message when\nscripts are executed";
                p.content("script", string.Empty, tooltip);
                p.icon(vd.cfg_script ? Icons.toggle_green : Icons.toggle_red, tooltip, () => p.toggle(ref vd.cfg_script));
            }
        }
Exemple #8
0
        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, Styles.ScaleStringLength(20)), " <color=#cccccc>" + Localizer.Format("#KERBALISM_UI_devman") + "</color>"));
            p.width(Styles.ScaleWidthFloat(355.0f));
            p.paneltype = Panel.PanelType.scripts;

            // 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
                (
                    Localizer.Format("#KERBALISM_UI_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>" + Localizer.Format("#KERBALISM_UI_dontcare") + " </color>" : state == 0 ? "<color=red>" + Localizer.Format("#KERBALISM_Generic_OFF") + "</color>" : "<color=cyan>" + Localizer.Format("#KERBALISM_Generic_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>");
            }
        }
Exemple #9
0
        public static void Config(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 vessel data
            VesselData vd = v.KerbalismData();

            // if not a valid vessel, leave the panel empty
            if (!vd.IsSimulated)
            {
                return;
            }

            // set metadata
            p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(20)), " ", Lib.Color(Local.VESSELCONFIG_title, Lib.Kolor.LightGrey)));            //"VESSEL CONFIG"
            p.Width(Styles.ScaleWidthFloat(355.0f));
            p.paneltype = Panel.PanelType.config;

            // toggle rendering
            string tooltip;

            p.AddSection(Local.VESSELCONFIG_RENDERING);            //"RENDERING"

            tooltip = Local.VESSELCONFIG_ShowVessel_desc;
            p.AddContent(Local.VESSELCONFIG_ShowVessel, string.Empty, tooltip);
            p.AddRightIcon(vd.cfg_show ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_show));

            if (Features.Reliability)
            {
                tooltip = Local.VESSELCONFIG_Highlightfailed_desc;                       //"Highlight failed components"
                p.AddContent(Local.VESSELCONFIG_Highlightfailed, string.Empty, tooltip); //"highlight malfunctions"
                p.AddRightIcon(vd.cfg_highlights ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_highlights));
            }

            // toggle messages
            p.AddSection(Local.VESSELCONFIG_MESSAGES);                       //"MESSAGES"
            tooltip = Local.VESSELCONFIG_EClow;                              //"Receive a message when\nElectricCharge level is low"
            p.AddContent(Local.VESSELCONFIG_battery, string.Empty, tooltip); //"battery"
            p.AddRightIcon(vd.cfg_ec ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_ec));
            if (Features.Supplies)
            {
                tooltip = Local.VESSELCONFIG_Supplylow;                         //"Receive a message when\nsupply resources level is low"
                p.AddContent(Local.VESSELCONFIG_supply, string.Empty, tooltip); //"supply"
                p.AddRightIcon(vd.cfg_supply ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_supply));
            }
            if (API.Comm.handlers.Count > 0 || HighLogic.fetch.currentGame.Parameters.Difficulty.EnableCommNet)
            {
                tooltip = Local.VESSELCONFIG_Signallost;                        //"Receive a message when signal is lost or obtained"
                p.AddContent(Local.VESSELCONFIG_signal, string.Empty, tooltip); //"signal"
                p.AddRightIcon(vd.cfg_signal ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_signal));
            }
            if (Features.Reliability)
            {
                tooltip = Local.VESSELCONFIG_Componentfail;                          //"Receive a message\nwhen a component fail"
                p.AddContent(Local.VESSELCONFIG_reliability, string.Empty, tooltip); //"reliability"
                p.AddRightIcon(vd.cfg_malfunction ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_malfunction));
            }
            if (Features.SpaceWeather)
            {
                tooltip = Local.VESSELCONFIG_CMEevent;                         //"Receive a message\nduring CME events"
                p.AddContent(Local.VESSELCONFIG_storm, string.Empty, tooltip); //"storm"
                p.AddRightIcon(vd.cfg_storm ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_storm));
            }
            if (Features.Automation)
            {
                tooltip = Local.VESSELCONFIG_ScriptExe;                         //"Receive a message when\nscripts are executed"
                p.AddContent(Local.VESSELCONFIG_script, string.Empty, tooltip); //"script"
                p.AddRightIcon(vd.cfg_script ? Textures.toggle_green : Textures.toggle_red, tooltip, () => p.Toggle(ref vd.cfg_script));
            }
        }
Exemple #10
0
        bool Render_Vessel(Panel p, Vessel v)
        {
            // get vessel info
            Vessel_Info vi = Cache.VesselInfo(v);

            // skip invalid vessels
            if (!vi.is_valid)
            {
                return(false);
            }

            if (!Lib.IsVessel(v))
            {
                return(false);
            }

            // get data from db
            VesselData vd = DB.Vessel(v);

            // determine if filter must be shown
            show_filter |= vd.group.Length > 0 && vd.group != "NONE";

            // skip filtered vessels
            if (Filtered() && vd.group != filter)
            {
                return(false);
            }

            // get resource handler
            Vessel_Resources resources = ResourceCache.Get(v);

            // get vessel crew
            List <ProtoCrewMember> crew = Lib.CrewList(v);

            // get vessel name
            string vessel_name = v.isEVA ? crew[0].name : v.vesselName;

            // get body name
            string body_name = v.mainBody.name.ToUpper();

            // render entry
            p.SetHeader
            (
                Lib.BuildString("<b>", Lib.Ellipsis(vessel_name, 20), "</b> <size=9><color=#cccccc>", Lib.Ellipsis(body_name, 8), "</color></size>"),
                string.Empty,
                () => { selected_id = selected_id != v.id ? v.id : Guid.Empty; }
            );

            // problem indicator
            Indicator_Problems(p, v, vi, crew);

            // battery indicator
            Indicator_EC(p, v, vi);

            // supply indicator
            if (Features.Supplies)
            {
                Indicator_Supplies(p, v, vi);
            }

            // reliability indicator
            if (Features.Reliability)
            {
                Indicator_Reliability(p, v, vi);
            }

            // signal indicator
            if (Features.Signal || Features.KCommNet)
            {
                Indicator_Signal(p, v, vi);
            }

            // done
            return(true);
        }
Exemple #11
0
        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 data
            VesselData vd = v.KerbalismData();

            // if not a valid vessel, leave the panel empty
            if (!vd.IsSimulated)
            {
                return;
            }

            // set metadata
            p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(20)), Lib.Color(Local.UI_devman, Lib.Kolor.LightGrey)));
            p.Width(Styles.ScaleWidthFloat(355.0f));
            p.paneltype = Panel.PanelType.scripts;

            // time-out simulation
            if (!Lib.IsControlUnit(v) && p.Timeout(vd))
            {
                return;
            }

            // get devices
            List <Device> devices     = Computer.GetModuleDevices(v);
            int           deviceCount = 0;

            // direct control
            if (script_index == 0)
            {
                // draw section title and desc
                p.AddSection
                (
                    Local.UI_devices,
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last),
                    false
                );

                bool hasVesselDeviceSection = false;
                bool hasModuleDeviceSection = false;

                // for each device
                for (int i = devices.Count - 1; i >= 0; i--)
                {
                    Device dev = devices[i];

                    dev.OnUpdate();
                    if (!dev.IsVisible)
                    {
                        continue;
                    }

                    // create vessel device section if necessary
                    if (dev is VesselDevice)
                    {
                        if (!hasVesselDeviceSection)
                        {
                            p.AddSection(Local.DevManager_VESSELDEVICES);                            //"VESSEL DEVICES"
                            hasVesselDeviceSection = true;
                        }
                    }
                    // create module device section if necessary
                    else
                    {
                        if (!hasModuleDeviceSection)
                        {
                            p.AddSection(Local.DevManager_MODULEDEVICES);                            //"MODULE DEVICES"
                            hasModuleDeviceSection = true;
                        }
                    }

                    if (dev.PartId != 0u)
                    {
                        p.AddContent(dev.DisplayName, dev.Status, dev.Tooltip, dev.Toggle, () => Highlighter.Set(dev.PartId, Color.cyan));
                    }
                    else
                    {
                        p.AddContent(dev.DisplayName, dev.Status, dev.Tooltip, dev.Toggle);
                    }

                    if (dev.Icon != null)
                    {
                        p.SetLeftIcon(dev.Icon.texture, dev.Icon.tooltip, dev.Icon.onClick);
                    }

                    deviceCount++;
                }
            }
            // script editor
            else
            {
                // get script
                ScriptType script_type = (ScriptType)script_index;
                string     script_name = script_type.ToString().Replace('_', ' ').ToUpper();
                Script     script      = v.KerbalismData().computer.Get(script_type);

                // draw section title and desc
                p.AddSection
                (
                    script_name,
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last)
                );

                bool hasVesselDeviceSection = false;
                bool hasModuleDeviceSection = false;

                // for each device
                for (int i = devices.Count - 1; i >= 0; i--)
                {
                    Device dev = devices[i];

                    dev.OnUpdate();
                    if (!dev.IsVisible)
                    {
                        continue;
                    }

                    // determine tribool state
                    int state = !script.states.ContainsKey(dev.Id)
                                          ? -1
                                          : !script.states[dev.Id]
                                          ? 0
                                          : 1;

                    // create vessel device section if necessary
                    if (dev is VesselDevice)
                    {
                        if (!hasVesselDeviceSection)
                        {
                            p.AddSection(Local.DevManager_VESSELDEVICES);                            //"VESSEL DEVICES"
                            hasVesselDeviceSection = true;
                        }
                    }
                    // create module device section if necessary
                    else
                    {
                        if (!hasModuleDeviceSection)
                        {
                            p.AddSection(Local.DevManager_MODULEDEVICES);                            //"MODULE DEVICES"
                            hasModuleDeviceSection = true;
                        }
                    }

                    // render device entry
                    p.AddContent
                    (
                        dev.DisplayName,
                        state == -1 ? Lib.Color(Local.UI_dontcare, Lib.Kolor.DarkGrey) : Lib.Color(state == 0, Local.Generic_OFF, Lib.Kolor.Yellow, Local.Generic_ON, Lib.Kolor.Green),
                        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.PartId, Color.cyan)
                    );
                    deviceCount++;
                }
            }

            // no devices case
            if (deviceCount == 0)
            {
                p.AddContent("<i>" + Local.DevManager_nodevices + "</i>");             //no devices
            }
        }
Exemple #12
0
        static void Render_science(Panel p, Vessel v, VesselData vd)
        {
            // don't show env panel in eva kerbals
            if (v.isEVA)
            {
                return;
            }

            p.AddSection("TRANSMISSION");

            // comm status
            if (vd.filesTransmitted.Count > 0)
            {
                double        transmitRate = 0.0;
                StringBuilder tooltip      = new StringBuilder();
                tooltip.Append(string.Format("<align=left /><b>{0,-15}\t{1}</b>\n", "rate", "file transmitted"));
                for (int i = 0; i < vd.filesTransmitted.Count; i++)
                {
                    transmitRate += vd.filesTransmitted[i].transmitRate;
                    tooltip.Append(string.Format("{0,-15}\t{1}", Lib.HumanReadableDataRate(vd.filesTransmitted[i].transmitRate), Lib.Ellipsis(vd.filesTransmitted[i].subjectData.FullTitle, 40u)));
                    if (i < vd.filesTransmitted.Count - 1)
                    {
                        tooltip.Append("\n");
                    }
                }

                p.AddContent("transmitting", Lib.BuildString(vd.filesTransmitted.Count.ToString(), vd.filesTransmitted.Count > 1 ? " files at " : " file at ", Lib.HumanReadableDataRate(transmitRate)), tooltip.ToString());
            }
            else
            {
                p.AddContent("max transmission rate", Lib.HumanReadableDataRate(vd.Connection.rate));
            }

            p.AddContent("target", vd.Connection.target_name);

            // total science gained by vessel
            p.AddContent("total science transmitted", Lib.HumanReadableScience(vd.scienceTransmitted, false));
        }