private void RenderSubtree(CelestialBody celestial, int depth)
            {
                // Horizontal offset between a node and its children.
                const int offset = 20;

                UnityEngine.GUILayout.BeginHorizontal();
                if (!celestial.is_root())
                {
                    UnityEngine.GUILayout.Label(
                        "",
                        UnityEngine.GUILayout.Width(offset * (depth - 1)));
                    string button_text;
                    if (celestial.is_leaf())
                    {
                        button_text = "";
                    }
                    else if (expanded_[celestial])
                    {
                        button_text = "-";
                    }
                    else
                    {
                        button_text = "+";
                    }
                    if (UnityEngine.GUILayout.Button(button_text,
                                                     UnityEngine.GUILayout.Width(offset)))
                    {
                        Shrink();
                        expanded_[celestial] = !expanded_[celestial];
                    }
                }
                if (UnityEngine.GUILayout.Toggle(selected_celestial_ == celestial,
                                                 celestial.name))
                {
                    if (selected_celestial_ != celestial)
                    {
                        selected_celestial_ = celestial;
                        on_change_(FrameParameters());
                    }
                }
                UnityEngine.GUILayout.EndHorizontal();
                if (celestial.is_root() || (!celestial.is_leaf() && expanded_[celestial]))
                {
                    foreach (CelestialBody child in celestial.orbitingBodies)
                    {
                        RenderSubtree(child, depth + 1);
                    }
                }
            }
Example #2
0
 public ReferenceFrameSelector(
     ManagerInterface manager,
     IntPtr plugin,
     Callback on_change,
     string name) : base(manager)
 {
     plugin_    = plugin;
     on_change_ = on_change;
     name_      = name;
     frame_type = FrameType.BODY_CENTRED_NON_ROTATING;
     expanded_  = new Dictionary <CelestialBody, bool>();
     foreach (CelestialBody celestial in FlightGlobals.Bodies)
     {
         if (!celestial.is_leaf() && !celestial.is_root())
         {
             expanded_.Add(celestial, false);
         }
     }
     selected_celestial_ =
         FlightGlobals.currentMainBody ?? Planetarium.fetch.Sun;
     for (CelestialBody celestial = selected_celestial_;
          celestial.orbit != null;
          celestial = celestial.orbit.referenceBody)
     {
         if (!celestial.is_leaf())
         {
             expanded_[celestial] = true;
         }
     }
     on_change_(FrameParameters());
     window_rectangle_.x = UnityEngine.Screen.width / 2;
     window_rectangle_.y = UnityEngine.Screen.height / 3;
 }
 public void UpdateMainBody()
 {
     frame_type         = FrameType.BODY_CENTRED_NON_ROTATING;
     selected_celestial =
         FlightGlobals.currentMainBody ?? FlightGlobals.GetHomeBody();
     for (CelestialBody celestial = selected_celestial;
          celestial.orbit != null;
          celestial = celestial.orbit.referenceBody)
     {
         if (!celestial.is_leaf())
         {
             expanded_[celestial] = true;
         }
     }
     on_change_(FrameParameters());
 }
 private void RenderSubtree(CelestialBody celestial, int depth) {
   // Horizontal offset between a node and its children.
   const int offset = 20;
   UnityEngine.GUILayout.BeginHorizontal();
   if (!celestial.is_root()) {
     UnityEngine.GUILayout.Label(
         "",
         UnityEngine.GUILayout.Width(offset * (depth - 1)));
     string button_text;
     if (celestial.is_leaf()) {
       button_text = "";
     } else if (expanded_[celestial]) {
       button_text = "-";
     } else {
       button_text = "+";
     }
     if (UnityEngine.GUILayout.Button(button_text,
                                      UnityEngine.GUILayout.Width(offset))) {
       Shrink();
       expanded_[celestial] = !expanded_[celestial];
     }
   }
   if (UnityEngine.GUILayout.Toggle(selected_celestial_ == celestial,
                                    celestial.name)) {
     if (selected_celestial_ != celestial) {
       selected_celestial_ = celestial;
       on_change_(FrameParameters());
     }
   }
   UnityEngine.GUILayout.EndHorizontal();
   if (celestial.is_root() || (!celestial.is_leaf() && expanded_[celestial])) {
     foreach (CelestialBody child in celestial.orbitingBodies) {
       RenderSubtree(child, depth + 1);
     }
   }
 }
            private void RenderSubtreeToggleGrid(CelestialBody celestial)
            {
                int column_width = 2;

                using (new UnityEngine.GUILayout.HorizontalScope()) {
                    if (ToggleButton(
                            SelectedFrameIs(celestial, FrameType.BODY_CENTRED_NON_ROTATING),
                            new UnityEngine.GUIContent(
                                SelectorText(FrameType.BODY_CENTRED_NON_ROTATING, celestial),
                                SelectorTooltip(FrameType.BODY_CENTRED_NON_ROTATING, celestial)),
                            GUILayoutWidth(column_width)))
                    {
                        EffectChange(() => {
                            target_frame_selected = false;
                            selected_celestial    = celestial;
                            frame_type            = FrameType.BODY_CENTRED_NON_ROTATING;
                        });
                    }
                    if (ToggleButton(
                            SelectedFrameIs(celestial, FrameType.BODY_SURFACE),
                            new UnityEngine.GUIContent(
                                SelectorText(FrameType.BODY_SURFACE, celestial),
                                SelectorTooltip(FrameType.BODY_SURFACE, celestial)),
                            GUILayoutWidth(column_width)))
                    {
                        EffectChange(() => {
                            target_frame_selected = false;
                            selected_celestial    = celestial;
                            frame_type            = FrameType.BODY_SURFACE;
                        });
                    }
                    if (!celestial.is_root() &&
                        ToggleButton(
                            SelectedFrameIs(celestial,
                                            FrameType.BODY_CENTRED_PARENT_DIRECTION),
                            new UnityEngine.GUIContent(
                                SelectorText(FrameType.BODY_CENTRED_PARENT_DIRECTION, celestial),
                                SelectorTooltip(FrameType.BODY_CENTRED_PARENT_DIRECTION, celestial)),
                            GUILayoutWidth(column_width)))
                    {
                        EffectChange(() => {
                            target_frame_selected = false;
                            selected_celestial    = celestial;
                            frame_type            = FrameType.BODY_CENTRED_PARENT_DIRECTION;
                        });
                    }
                }
                if (!celestial.is_leaf(target))
                {
                    if ((expanded_[celestial] || target_pinned_) &&
                        target?.orbit.referenceBody == celestial)
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            UnityEngine.GUILayout.Button("", UnityEngine.GUI.skin.label, GUILayoutWidth(column_width));
                            UnityEngine.GUILayout.Button("", UnityEngine.GUI.skin.label, GUILayoutWidth(column_width));
                            if (ToggleButton(
                                    target_frame_selected,
                                    new UnityEngine.GUIContent(
                                        TargetFrameSelectorText(target),
                                        TargetFrameSelectorTooltip(target)),
                                    GUILayoutWidth(column_width)))
                            {
                                EffectChange(() => {
                                    target_frame_selected = true;
                                });
                            }
                        }
                    }
                    foreach (CelestialBody child in celestial.orbitingBodies)
                    {
                        if (expanded_[celestial] || AnyDescendantPinned(child))
                        {
                            RenderSubtreeToggleGrid(child);
                        }
                    }
                }
            }
            private void RenderSubtree(CelestialBody celestial, int depth)
            {
                // Horizontal offset between a node and its children.
                const int offset = 1;

                using (new UnityEngine.GUILayout.HorizontalScope()) {
                    UnityEngine.GUILayout.Space(Width(offset * depth));
                    if (celestial.is_leaf(target))
                    {
                        UnityEngine.GUILayout.Button(
                            "", UnityEngine.GUI.skin.label, GUILayoutWidth(offset));
                    }
                    else
                    {
                        string button_text = expanded_[celestial] ? "−" : "+";
                        if (UnityEngine.GUILayout.Button(
                                button_text, GUILayoutWidth(offset)))
                        {
                            Shrink();
                            expanded_[celestial] = !expanded_[celestial];
                        }
                    }
                    UnityEngine.GUILayout.Label(celestial.StandaloneName());
                    UnityEngine.GUILayout.FlexibleSpace();
                    if (celestial.is_root())
                    {
                        UnityEngine.GUILayout.Label(
                            L10N.CacheFormat("#Principia_ReferenceFrameSelector_Pin"));
                    }
                    else if (UnityEngine.GUILayout.Toggle(pinned[celestial], "") !=
                             pinned[celestial])
                    {
                        pinned[celestial] = !pinned[celestial];
                        Shrink();
                    }
                }
                if (!celestial.is_leaf(target))
                {
                    if ((expanded_[celestial] || target_pinned_) &&
                        target?.orbit.referenceBody == celestial)
                    {
                        using (new UnityEngine.GUILayout.HorizontalScope()) {
                            UnityEngine.GUILayout.Space(Width(offset * (depth + 1)));
                            UnityEngine.GUILayout.Button(
                                "", UnityEngine.GUI.skin.label, GUILayoutWidth(offset));
                            UnityEngine.GUILayout.Label(
                                L10N.CacheFormat("#Principia_ReferenceFrameSelector_Target",
                                                 target.vesselName));
                            UnityEngine.GUILayout.FlexibleSpace();
                            if (UnityEngine.GUILayout.Toggle(target_pinned_, "") !=
                                target_pinned_)
                            {
                                target_pinned_ = !target_pinned_;
                                Shrink();
                            }
                        }
                    }
                    foreach (CelestialBody child in celestial.orbitingBodies)
                    {
                        if (expanded_[celestial] || AnyDescendantPinned(child))
                        {
                            RenderSubtree(child, depth + 1);
                        }
                    }
                }
            }