示例#1
0
            // Renders the |BurnEditor|.  Returns true if and only if the settings were
            // changed.
            public Event Render(string header,
                                bool anomalous,
                                double burn_final_time)
            {
                bool changed = false;

                previous_coast_duration_.max_value = burn_final_time - time_base;
                using (new UnityEngine.GUILayout.HorizontalScope()) {
                    if (UnityEngine.GUILayout.Button(
                            minimized ? "+" : "-", GUILayoutWidth(1)))
                    {
                        minimized = !minimized;
                        return(minimized ? Event.Minimized : Event.Maximized);
                    }
                    UnityEngine.GUILayout.Label(minimized ? $"{header} ({Δv():0.000} m/s)"
                                            : header);
                    string info = "";
                    if (!minimized &&
                        !reference_frame_selector_.FrameParameters().Equals(
                            adapter_.plotting_frame_selector_.FrameParameters()))
                    {
                        info = "Manœuvre frame differs from plotting frame";
                    }
                    UnityEngine.GUILayout.Label(
                        info,
                        Style.Info(UnityEngine.GUI.skin.label));
                    if (UnityEngine.GUILayout.Button("Delete", GUILayoutWidth(2)))
                    {
                        return(Event.Deleted);
                    }
                }
                if (minimized)
                {
                    return(Event.None);
                }
                using (new UnityEngine.GUILayout.VerticalScope()) {
                    // When we are first rendered, the |initial_mass_in_tonnes_| will just have
                    // been set.  If we have fallen back to instant impulse, we should use this
                    // mass to set the thrust.
                    if (first_time_rendering_)
                    {
                        first_time_rendering_ = false;
                        changed         = true;
                        engine_warning_ = "";
                        ComputeEngineCharacteristics();
                    }

                    // The frame selector is disabled for an anomalous manœuvre as is has no
                    // effect.
                    if (anomalous)
                    {
                        reference_frame_selector_.Hide();
                    }
                    else
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            if (UnityEngine.GUILayout.Button("Active Engines"))
                            {
                                engine_warning_ = "";
                                ComputeEngineCharacteristics();
                                changed = true;
                            }
                            else if (UnityEngine.GUILayout.Button("Active RCS"))
                            {
                                engine_warning_ = "";
                                ComputeRCSCharacteristics();
                                changed = true;
                            }
                            else if (UnityEngine.GUILayout.Button("Instant Impulse"))
                            {
                                engine_warning_ = "";
                                UseTheForceLuke();
                                changed = true;
                            }
                        }
                        reference_frame_selector_.RenderButton();
                    }
                    if (is_inertially_fixed_ !=
                        UnityEngine.GUILayout.Toggle(is_inertially_fixed_,
                                                     "Inertially fixed"))
                    {
                        changed = true;
                        is_inertially_fixed_ = !is_inertially_fixed_;
                    }
                    changed |= changed_reference_frame_;

                    // The Δv controls are disabled for an anomalous manœuvre as they have no
                    // effect.
                    changed |= Δv_tangent_.Render(enabled: !anomalous);
                    changed |= Δv_normal_.Render(enabled: !anomalous);
                    changed |= Δv_binormal_.Render(enabled: !anomalous);
                    {
                        var render_time_base = time_base;
                        previous_coast_duration_.value = initial_time_ - render_time_base;

                        // The duration of the previous coast is always enabled as it can make
                        // a manœuvre non-anomalous.
                        if (previous_coast_duration_.Render(enabled: true))
                        {
                            changed       = true;
                            initial_time_ = previous_coast_duration_.value + render_time_base;
                        }
                    }
                    UnityEngine.GUILayout.Label(
                        index == 0 ? "Time base: start of flight plan"
                     : $"Time base: end of manœuvre #{index}",
                        style: new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label)
                    {
                        alignment = UnityEngine.TextAnchor.UpperLeft
                    });
                    using (new UnityEngine.GUILayout.HorizontalScope()) {
                        UnityEngine.GUILayout.Label(
                            "Manœuvre Δv : " + Δv().ToString("0.000") + " m/s",
                            GUILayoutWidth(8));
                        UnityEngine.GUILayout.Label("Duration : " + duration_.ToString("0.0") +
                                                    " s");
                    }
                    UnityEngine.GUILayout.Label(engine_warning_,
                                                Style.Warning(UnityEngine.GUI.skin.label));
                    changed_reference_frame_ = false;
                }
                return(changed ? Event.Changed : Event.None);
            }
示例#2
0
            // Renders the |BurnEditor|.  Returns true if and only if the settings were
            // changed.
            public bool Render(string header,
                               bool enabled,
                               double?actual_final_time = null)
            {
                bool changed = false;

                previous_coast_duration_.max_value =
                    (actual_final_time ?? double.PositiveInfinity) - time_base;
                using (new UnityEngine.GUILayout.HorizontalScope()) {
                    UnityEngine.GUILayout.Label(header);
                    string frame_info = "";
                    if (!reference_frame_selector_.FrameParameters().Equals(
                            adapter_.plotting_frame_selector_.FrameParameters()))
                    {
                        frame_info = "Manœuvre frame differs from plotting frame";
                    }
                    UnityEngine.GUILayout.Label(
                        frame_info,
                        Style.RightAligned(Style.Info(UnityEngine.GUI.skin.label)));
                }
                using (new UnityEngine.GUILayout.VerticalScope()) {
                    // When we are first rendered, the |initial_mass_in_tonnes_| will just have
                    // been set.  If we have fallen back to instant impulse, we should use this
                    // mass to set the thrust.
                    if (first_time_rendering)
                    {
                        first_time_rendering = false;
                        changed         = true;
                        engine_warning_ = "";
                        ComputeEngineCharacteristics();
                    }
                    if (enabled)
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            if (UnityEngine.GUILayout.Button("Active Engines"))
                            {
                                engine_warning_ = "";
                                ComputeEngineCharacteristics();
                                changed = true;
                            }
                            else if (UnityEngine.GUILayout.Button("Active RCS"))
                            {
                                engine_warning_ = "";
                                ComputeRCSCharacteristics();
                                changed = true;
                            }
                            else if (UnityEngine.GUILayout.Button("Instant Impulse"))
                            {
                                engine_warning_ = "";
                                UseTheForceLuke();
                                changed = true;
                            }
                        }
                        reference_frame_selector_.RenderButton();
                    }
                    else
                    {
                        reference_frame_selector_.Hide();
                    }
                    if (is_inertially_fixed_ !=
                        UnityEngine.GUILayout.Toggle(is_inertially_fixed_,
                                                     "Inertially fixed"))
                    {
                        changed = true;
                        is_inertially_fixed_ = !is_inertially_fixed_;
                    }
                    changed |= changed_reference_frame_;
                    changed |= Δv_tangent_.Render(enabled);
                    changed |= Δv_normal_.Render(enabled);
                    changed |= Δv_binormal_.Render(enabled);
                    {
                        var render_time_base = time_base;
                        previous_coast_duration_.value = initial_time_ - render_time_base;
                        if (previous_coast_duration_.Render(enabled))
                        {
                            changed       = true;
                            initial_time_ = previous_coast_duration_.value + render_time_base;
                        }
                    }
                    UnityEngine.GUILayout.Label(
                        index_ == 0 ? "Time base: start of flight plan"
                      : $"Time base: end of manœuvre #{index_}",
                        style: new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label)
                    {
                        alignment = UnityEngine.TextAnchor.UpperLeft
                    });
                    using (new UnityEngine.GUILayout.HorizontalScope()) {
                        UnityEngine.GUILayout.Label(
                            "Manœuvre Δv : " + Δv().ToString("0.000") + " m/s",
                            GUILayoutWidth(8));
                        UnityEngine.GUILayout.Label("Duration : " + duration_.ToString("0.0") +
                                                    " s");
                    }
                    UnityEngine.GUILayout.Label(engine_warning_,
                                                Style.Warning(UnityEngine.GUI.skin.label));
                    changed_reference_frame_ = false;
                }
                return(changed && enabled);
            }
示例#3
0
            // Renders the |BurnEditor|.  Returns true if and only if the settings were
            // changed.
            public bool Render(bool enabled)
            {
                var old_skin = UnityEngine.GUI.skin;

                UnityEngine.GUI.skin = null;
                UnityEngine.GUILayout.BeginVertical();
                var warning_style = new UnityEngine.GUIStyle(UnityEngine.GUI.skin.textArea);

                warning_style.normal.textColor = XKCDColors.Orange;
                bool changed = false;

                // When we are first rendered, the |initial_mass_in_tonnes_| will just have
                // been set.  If we have fallen back to instant impulse, we should use this
                // mass to set the thrust.
                if (first_time_rendering)
                {
                    first_time_rendering = false;
                    changed         = true;
                    engine_warning_ = "";
                    ComputeEngineCharacteristics();
                }
                if (enabled)
                {
                    UnityEngine.GUILayout.BeginHorizontal();
                    if (UnityEngine.GUILayout.Button("Active Engines"))
                    {
                        engine_warning_ = "";
                        ComputeEngineCharacteristics();
                        changed = true;
                    }
                    else if (UnityEngine.GUILayout.Button("Active RCS"))
                    {
                        engine_warning_ = "";
                        ComputeRCSCharacteristics();
                        changed = true;
                    }
                    else if (UnityEngine.GUILayout.Button("Instant Impulse"))
                    {
                        engine_warning_ = "";
                        UseTheForceLuke();
                        changed = true;
                    }
                    UnityEngine.GUILayout.EndHorizontal();
                    UnityEngine.GUILayout.TextArea(engine_warning_, warning_style);
                    reference_frame_selector_.RenderButton();
                }
                else
                {
                    reference_frame_selector_.Hide();
                }
                string frame_warning = "";

                if (!reference_frame_selector_.FrameParameters().Equals(
                        adapter_.plotting_frame_selector_.get().FrameParameters()))
                {
                    frame_warning = "Manœuvre frame differs from plotting frame";
                }
                UnityEngine.GUILayout.TextArea(frame_warning, warning_style);
                changed |= Δv_tangent_.Render(enabled);
                changed |= Δv_normal_.Render(enabled);
                changed |= Δv_binormal_.Render(enabled);
                changed |= initial_time_.Render(enabled);
                changed |= changed_reference_frame_;
                UnityEngine.GUILayout.BeginHorizontal();
                UnityEngine.GUILayout.Label(
                    "Manœuvre Δv : " + Δv().ToString("0.000") + " m/s",
                    UnityEngine.GUILayout.Width(200));
                UnityEngine.GUILayout.Label("Duration : " + duration_.ToString("0.0") +
                                            " s");
                UnityEngine.GUILayout.EndHorizontal();
                changed_reference_frame_ = false;
                UnityEngine.GUILayout.EndVertical();
                UnityEngine.GUI.skin = old_skin;
                return(changed && enabled);
            }
示例#4
0
            // Renders the |BurnEditor|.  Returns true if and only if the settings were
            // changed.
            public Event Render(
                string header,
                bool anomalous,
                double burn_final_time,
                double?orbital_period)
            {
                bool changed = false;

                previous_coast_duration_.max_value = burn_final_time - time_base;
                using (new UnityEngine.GUILayout.HorizontalScope()) {
                    if (UnityEngine.GUILayout.Button(
                            minimized ? "+" : "−", GUILayoutWidth(1)))
                    {
                        minimized = !minimized;
                        return(minimized ? Event.Minimized : Event.Maximized);
                    }
                    UnityEngine.GUILayout.Label(
                        minimized ? L10N.CacheFormat("#Principia_BurnEditor_MinimizedHeader",
                                                     header,
                                                     Δv().ToString("0.000"))
                    : header);
                    string info = "";
                    if (!minimized &&
                        !reference_frame_selector_.FrameParameters().Equals(
                            adapter_.plotting_frame_selector_.FrameParameters()))
                    {
                        info = L10N.CacheFormat(
                            "#Principia_BurnEditor_Info_InconsistentFrames");
                    }
                    UnityEngine.GUILayout.Label(info, Style.Info(UnityEngine.GUI.skin.label));
                    if (UnityEngine.GUILayout.Button(
                            L10N.CacheFormat("#Principia_BurnEditor_Delete"),
                            GUILayoutWidth(2)))
                    {
                        return(Event.Deleted);
                    }
                }
                if (minimized)
                {
                    return(Event.None);
                }
                using (new UnityEngine.GUILayout.VerticalScope()) {
                    // When we are first rendered, the |initial_mass_in_tonnes_| will just have
                    // been set.  If we have fallen back to instant impulse, we should use this
                    // mass to set the thrust.
                    if (first_time_rendering_)
                    {
                        first_time_rendering_ = false;
                        changed         = true;
                        engine_warning_ = "";
                        ComputeEngineCharacteristics();
                        ReformatΔv();
                    }

                    // The frame selector is disabled for an anomalous manœuvre as is has no
                    // effect.
                    if (anomalous)
                    {
                        reference_frame_selector_.Hide();
                    }
                    else
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            if (UnityEngine.GUILayout.Button(
                                    L10N.CacheFormat("#Principia_BurnEditor_ActiveEngines")))
                            {
                                engine_warning_ = "";
                                ComputeEngineCharacteristics();
                                ReformatΔv();
                                changed = true;
                            }
                            else if (UnityEngine.GUILayout.Button(
                                         L10N.CacheFormat("#Principia_BurnEditor_ActiveRCS")))
                            {
                                engine_warning_ = "";
                                ComputeRCSCharacteristics();
                                ReformatΔv();
                                changed = true;
                            }
                            else if (UnityEngine.GUILayout.Button(
                                         L10N.CacheFormat("#Principia_BurnEditor_InstantImpulse")))
                            {
                                engine_warning_ = "";
                                UseTheForceLuke();
                                ReformatΔv();
                                changed = true;
                            }
                        }
                        reference_frame_selector_.RenderButton();
                    }
                    if (is_inertially_fixed_ !=
                        UnityEngine.GUILayout.Toggle(
                            is_inertially_fixed_,
                            L10N.CacheFormat("#Principia_BurnEditor_InertiallyFixed")))
                    {
                        changed = true;
                        is_inertially_fixed_ = !is_inertially_fixed_;
                    }
                    changed |= changed_reference_frame_;

                    // The Δv controls are disabled for an anomalous manœuvre as they have no
                    // effect.
                    changed |= Δv_tangent_.Render(enabled: !anomalous);
                    changed |= Δv_normal_.Render(enabled: !anomalous);
                    changed |= Δv_binormal_.Render(enabled: !anomalous);
                    {
                        var render_time_base = time_base;
                        previous_coast_duration_.value_if_different =
                            initial_time_ - render_time_base;
                        // The duration of the previous coast is always enabled as it can make
                        // a manœuvre non-anomalous.
                        if (previous_coast_duration_.Render(enabled: true))
                        {
                            changed       = true;
                            initial_time_ = previous_coast_duration_.value + render_time_base;
                        }
                    }
                    using (new UnityEngine.GUILayout.HorizontalScope()) {
                        UnityEngine.GUILayout.Label("", GUILayoutWidth(3));
                        if (decrement_revolution == null)
                        {
                            PrincipiaPluginAdapter.LoadTextureOrDie(out decrement_revolution,
                                                                    "decrement_revolution.png");
                        }
                        if (increment_revolution == null)
                        {
                            PrincipiaPluginAdapter.LoadTextureOrDie(out increment_revolution,
                                                                    "increment_revolution.png");
                        }
                        if (orbital_period is double period)
                        {
                            if (UnityEngine.GUILayout.Button(
                                    new UnityEngine.GUIContent(
                                        decrement_revolution,
                                        L10N.CacheFormat(
                                            "#Principia_BurnEditor_DecrementRevolution") +
                                        "\n(" + new PrincipiaTimeSpan(-period).Format(
                                            with_leading_zeroes: false,
                                            with_seconds: false) + ")"),
                                    GUILayoutWidth(1)))
                            {
                                changed        = true;
                                initial_time_ -= period;
                            }
                            UnityEngine.GUILayout.Space(Width(5));
                            if (UnityEngine.GUILayout.Button(
                                    new UnityEngine.GUIContent(
                                        increment_revolution,
                                        L10N.CacheFormat(
                                            "#Principia_BurnEditor_IncrementRevolution") +
                                        "\n(" + new PrincipiaTimeSpan(+period).Format(
                                            with_leading_zeroes: false,
                                            with_seconds: false) + ")"),
                                    GUILayoutWidth(1)))
                            {
                                changed        = true;
                                initial_time_ += period;
                            }
                        }
                        else
                        {
                            UnityEngine.GUILayout.Button("", GUILayoutWidth(1));
                            UnityEngine.GUILayout.Space(Width(5));
                            UnityEngine.GUILayout.Button("", GUILayoutWidth(1));
                        }
                        UnityEngine.GUILayout.Label(
                            index == 0
                ? L10N.CacheFormat(
                                "#Principia_BurnEditor_TimeBase_StartOfFlightPlan")
                : L10N.CacheFormat("#Principia_BurnEditor_TimeBase_EndOfManœuvre",
                                   index),
                            style: new UnityEngine.GUIStyle(UnityEngine.GUI.skin.label)
                        {
                            alignment = UnityEngine.TextAnchor.UpperLeft
                        });
                    }
                    using (new UnityEngine.GUILayout.HorizontalScope()) {
                        UnityEngine.GUILayout.Label(
                            L10N.CacheFormat("#Principia_BurnEditor_Δv",
                                             Δv().ToString("0.000")),
                            GUILayoutWidth(8));
                        UnityEngine.GUILayout.Label(L10N.CacheFormat(
                                                        "#Principia_BurnEditor_Duration",
                                                        duration_.ToString("0.0")));
                    }
                    UnityEngine.GUILayout.Label(engine_warning_,
                                                Style.Warning(UnityEngine.GUI.skin.label));
                    changed_reference_frame_ = false;
                }
                return(changed ? Event.Changed : Event.None);
            }