Exemplo n.º 1
0
        public void Update()
        {
            var exp = Science.Experiment(experiment_id);

            // in flight
            if (Lib.IsFlight())
            {
                Vessel v = FlightGlobals.ActiveVessel;
                if (v == null || EVA.IsDead(v))
                {
                    return;
                }

                // get info from cache
                Vessel_info vi = Cache.VesselInfo(vessel);

                // do nothing if vessel is invalid
                if (!vi.is_valid)
                {
                    return;
                }

                var sampleSize = exp.max_amount;
                var eta        = data_rate < double.Epsilon || Done(exp, dataSampled) ? " done" : " " + Lib.HumanReadableCountdown((sampleSize - dataSampled) / data_rate);

                // update ui
                var title = Lib.Ellipsis(exp.name, Styles.ScaleStringLength(24));
                if (scienceValue > 0.1)
                {
                    title += " •<b>" + scienceValue.ToString("F1") + "</b>";
                }

                string statusString = string.Empty;
                switch (state)
                {
                case State.ISSUE: statusString = Lib.Color("yellow", issue); break;

                case State.RUNNING: statusString = Lib.HumanReadablePerc(dataSampled / sampleSize) + eta; break;

                case State.WAITING: statusString = "waiting" + eta; break;

                case State.STOPPED: statusString = "stopped"; break;
                }

                Events["Toggle"].guiName = Lib.StatusToggle(title, statusString);
                Events["Toggle"].active  = (prepare_cs == null || didPrepare);

                Events["Prepare"].guiName = Lib.BuildString("Prepare <b>", exp.name, "</b>");
                Events["Prepare"].active  = !didPrepare && prepare_cs != null && string.IsNullOrEmpty(last_subject_id);

                Events["Reset"].guiName = Lib.BuildString("Reset <b>", exp.name, "</b>");
                // we need a reset either if we have recorded data or did a setup
                bool resetActive = (reset_cs != null || prepare_cs != null) && !string.IsNullOrEmpty(last_subject_id);
                Events["Reset"].active = resetActive;

                if (issue.Length > 0 && hide_when_unavailable && issue != insufficient_storage)
                {
                    Events["Toggle"].active = false;
                }
            }
            // in the editor
            else if (Lib.IsEditor())
            {
                // update ui
                Events["Toggle"].guiName = Lib.StatusToggle(exp.name, recording ? "recording" : "stopped");
                Events["Reset"].active   = false;
                Events["Prepare"].active = false;
            }
        }
Exemplo n.º 2
0
        public override string Info()
        {
            var state = Experiment.GetState(experiment.scienceValue, experiment.issue, experiment.recording, experiment.forcedRun);

            if (state == Experiment.State.WAITING)
            {
                return("waiting...");
            }
            var exp             = Science.Experiment(experiment.experiment_id);
            var recordedPercent = Lib.HumanReadablePerc(experiment.dataSampled / exp.max_amount);
            var eta             = experiment.data_rate < double.Epsilon || Experiment.Done(exp, experiment.dataSampled) ? " done" : " " + Lib.HumanReadableCountdown((exp.max_amount - experiment.dataSampled) / experiment.data_rate);

            return(!experiment.recording
                          ? "<color=red>" + Localizer.Format("#KERBALISM_Generic_DISABLED") + " </color>"
                          : experiment.issue.Length == 0 ? "<color=cyan>" + Lib.BuildString(recordedPercent, eta) + "</color>"
                          : Lib.BuildString("<color=yellow>", experiment.issue.ToLower(), "</color>"));
        }
Exemplo n.º 3
0
        public override string Info()
        {
            bool   recording    = Lib.Proto.GetBool(proto, "recording");
            bool   forcedRun    = Lib.Proto.GetBool(proto, "forcedRun");
            double scienceValue = Lib.Proto.GetDouble(proto, "scienceValue");
            string issue        = Lib.Proto.GetString(proto, "issue");

            var state = Experiment.GetState(scienceValue, issue, recording, forcedRun);

            if (state == Experiment.State.WAITING)
            {
                return("waiting...");
            }

            double dataSampled = Lib.Proto.GetDouble(proto, "dataSampled");
            double data_rate   = Lib.Proto.GetDouble(proto, "data_rate");

            var exp             = Science.Experiment(prefab.experiment_id);
            var recordedPercent = Lib.HumanReadablePerc(dataSampled / exp.max_amount);
            var eta             = data_rate < double.Epsilon || Experiment.Done(exp, dataSampled) ? " done" : " " + Lib.HumanReadableCountdown((exp.max_amount - dataSampled) / data_rate);

            return(!recording
                          ? "<color=red>" + Localizer.Format("#KERBALISM_Generic_STOPPED") + " </color>"
                          : issue.Length == 0 ? "<color=cyan>" + Lib.BuildString(recordedPercent, eta) + "</color>"
                          : Lib.BuildString("<color=yellow>", issue.ToLower(), "</color>"));
        }
Exemplo n.º 4
0
        static void Render_file(Panel p, uint partId, File file, Drive drive, bool short_strings, Vessel v)
        {
            // render experiment name
            string exp_label = Lib.BuildString
                               (
                "<b>",
                Lib.Ellipsis(file.subjectData.ExperimentTitle, Styles.ScaleStringLength(short_strings ? 24 : 38)),
                "</b> <size=", Styles.ScaleInteger(10).ToString(), ">",
                Lib.Ellipsis(file.subjectData.SituationTitle, Styles.ScaleStringLength((short_strings ? 32 : 62) - Lib.Ellipsis(file.subjectData.ExperimentTitle, Styles.ScaleStringLength(short_strings ? 24 : 38)).Length)),
                "</size>"
                               );
            string exp_tooltip = Lib.BuildString
                                 (
                file.subjectData.ExperimentTitle, "\n",
                Lib.Color(file.subjectData.SituationTitle, Lib.Kolor.LightGrey)
                                 );

            double exp_value = file.size * file.subjectData.SciencePerMB;

            if (file.subjectData.ScienceRemainingToRetrieve > 0f && file.size > 0.0)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n<b>", Lib.HumanReadableScience(exp_value, false), "</b>");
            }
            if (file.transmitRate > 0.0)
            {
                if (file.size > 0.0)
                {
                    exp_tooltip = Lib.Color(Lib.BuildString(exp_tooltip, "\n", Local.FILEMANAGER_TransmittingRate.Format(Lib.HumanReadableDataRate(file.transmitRate)), " : <i>", Lib.HumanReadableCountdown(file.size / file.transmitRate), "</i>"), Lib.Kolor.Cyan);                    //Transmitting at <<1>>
                }
                else
                {
                    exp_tooltip = Lib.Color(Lib.BuildString(exp_tooltip, "\n", Local.FILEMANAGER_TransmittingRate.Format(Lib.HumanReadableDataRate(file.transmitRate))), Lib.Kolor.Cyan);                    //Transmitting at <<1>>
                }
            }
            else if (v.KerbalismData().Connection.rate > 0.0)
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n", Local.FILEMANAGER_Transmitduration, "<i>", Lib.HumanReadableDuration(file.size / v.KerbalismData().Connection.rate), "</i>");                //Transmit duration :
            }
            if (!string.IsNullOrEmpty(file.resultText))
            {
                exp_tooltip = Lib.BuildString(exp_tooltip, "\n", Lib.WordWrapAtLength(file.resultText, 50));
            }

            string size;

            if (file.transmitRate > 0.0)
            {
                if (file.size == 0.0)
                {
                    size = Lib.Color(Lib.BuildString("↑ ", Lib.HumanReadableDataRate(file.transmitRate)), Lib.Kolor.Cyan);
                }
                else
                {
                    size = Lib.Color(Lib.BuildString("↑ ", Lib.HumanReadableDataSize(file.size)), Lib.Kolor.Cyan);
                }
            }
            else
            {
                size = Lib.HumanReadableDataSize(file.size);
            }

            p.AddContent(exp_label, size, exp_tooltip, (Action)null, () => Highlighter.Set(partId, Color.cyan));

            bool send = drive.GetFileSend(file.subjectData.Id);

            p.AddRightIcon(send ? Textures.send_cyan : Textures.send_black, Local.FILEMANAGER_send, () => { drive.Send(file.subjectData.Id, !send); }); //"Flag the file for transmission to <b>DSN</b>"
            p.AddRightIcon(Textures.toggle_red, Local.FILEMANAGER_Delete, () =>                                                                         //"Delete the file"
            {
                Lib.Popup(Local.FILEMANAGER_Warning_title,                                                                                              //"Warning!"
                          Local.FILEMANAGER_DeleteConfirm.Format(file.subjectData.FullTitle),                                                           //Lib.BuildString(, "?"),//"Do you really want to delete <<1>>",
                          new DialogGUIButton(Local.FILEMANAGER_DeleteConfirm_button1, () => drive.Delete_file(file.subjectData)),                      //"Delete it"
                          new DialogGUIButton(Local.FILEMANAGER_DeleteConfirm_button2, () => { }));                                                     //"Keep it"
            }
                           );
        }