public static String Name(FrameType type, CelestialBody selected) {
  switch (type) {
    case FrameType.BODY_CENTRED_NON_ROTATING:
      return selected.name + "-Centred Inertial";
    case FrameType.BARYCENTRIC_ROTATING:
       if (selected.is_root()) {
         throw Log.Fatal("Naming barycentric rotating frame of root body");
       } else {
         return selected.referenceBody.name + "-" + selected.name +
                " Barycentric";
       }
    case FrameType.BODY_CENTRED_PARENT_DIRECTION:
       if (selected.is_root()) {
         throw Log.Fatal(
             "Naming parent-direction rotating frame of root body");
       } else {
         // TODO(egg): find a proper name...
         return selected.name + "-Centred " + selected.referenceBody.name +
                "-Fixed";
       }
    case FrameType.BODY_SURFACE:
      return selected.name + "-Centred " + selected.name + "-Fixed";
    default:
      throw Log.Fatal("Unexpected type " + type.ToString());
  }
 }
            private void RenderSubtree(CelestialBody celestial, int depth)
            {
                // Horizontal offset between a node and its children.
                const int offset = 20;

                using (new HorizontalLayout()) {
                    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();
                            if (!celestial.is_leaf())
                            {
                                expanded_[celestial] = !expanded_[celestial];
                            }
                        }
                    }
                    if (UnityEngine.GUILayout.Toggle(selected_celestial == celestial,
                                                     celestial.name))
                    {
                        if (selected_celestial != celestial)
                        {
                            selected_celestial = celestial;
                            if (celestial.is_root() && frame_type != FrameType.BODY_SURFACE)
                            {
                                frame_type = FrameType.BODY_CENTRED_NON_ROTATING;
                            }
                            on_change_(FrameParameters());
                        }
                    }
                }
                if (celestial.is_root() || (!celestial.is_leaf() && expanded_[celestial]))
                {
                    foreach (CelestialBody child in celestial.orbitingBodies)
                    {
                        RenderSubtree(child, depth + 1);
                    }
                }
            }
Example #3
0
            public static string Description(FrameType type,
                                             CelestialBody selected,
                                             Vessel target_override)
            {
                if (target_override)
                {
                    return(Localizer.Format(
                               "#Principia_ReferenceFrameSelector_Description_Target",
                               target_override.vesselName,
                               selected.NameWithArticle()));
                }
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return(Localizer.Format(
                               "#Principia_ReferenceFrameSelector_Description_BodyCentredNonRotating",
                               selected.NameWithArticle()));

                case FrameType.BARYCENTRIC_ROTATING:
                    if (selected.is_root())
                    {
                        throw Log.Fatal("Describing barycentric rotating frame of root body");
                    }
                    else
                    {
                        return(Localizer.Format(
                                   "#Principia_ReferenceFrameSelector_Description_BarycentricRotating",
                                   selected.NameWithArticle(),
                                   selected.referenceBody.NameWithArticle()));
                    }

                case FrameType.BODY_CENTRED_PARENT_DIRECTION:
                    if (selected.is_root())
                    {
                        throw Log.Fatal(
                                  "Describing parent-direction rotating frame of root body");
                    }
                    else
                    {
                        return(Localizer.Format(
                                   "#Principia_ReferenceFrameSelector_Description_BodyCentredParentDirection",
                                   selected.NameWithArticle(),
                                   selected.referenceBody.NameWithArticle()));
                    }

                case FrameType.BODY_SURFACE:
                    return(Localizer.Format(
                               "#Principia_ReferenceFrameSelector_Description_BodySurface",
                               selected.NameWithArticle()));

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
            public static String Description(FrameType type,
                                             CelestialBody selected,
                                             Vessel target_override)
            {
                if (target_override)
                {
                    return("Reference frame fixing the target vessel (" +
                           target_override.vesselName + "), the plane of its orbit around " +
                           selected.NameWithArticle() + ", and the line between them");
                }
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return("Non-rotating reference frame fixing the centre of " +
                           selected.NameWithArticle());

                case FrameType.BARYCENTRIC_ROTATING:
                    if (selected.is_root())
                    {
                        throw Log.Fatal("Describing barycentric rotating frame of root body");
                    }
                    else
                    {
                        return("Reference frame fixing the barycentre of " +
                               selected.NameWithArticle() + " and " +
                               selected.referenceBody.NameWithArticle() +
                               ", the plane in which they move about the barycentre, and" +
                               " the line between them");
                    }

                case FrameType.BODY_CENTRED_PARENT_DIRECTION:
                    if (selected.is_root())
                    {
                        throw Log.Fatal(
                                  "Describing parent-direction rotating frame of root body");
                    }
                    else
                    {
                        return("Reference frame fixing the centre of " +
                               selected.NameWithArticle() +
                               ", the plane of its orbit around " +
                               selected.referenceBody.NameWithArticle() +
                               ", and the line between them");
                    }

                case FrameType.BODY_SURFACE:
                    return("Reference frame fixing the surface of " +
                           selected.NameWithArticle());

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
            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 static string Description(FrameType type,
                                              CelestialBody selected)
            {
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return(L10N.CelestialString(
                               "#Principia_ReferenceFrameSelector_Description_BodyCentredNonRotating",
                               new[] { selected }));

                case FrameType.BARYCENTRIC_ROTATING:
                    return("DEPRECATED");

                case FrameType.BODY_CENTRED_PARENT_DIRECTION:
                    if (selected.is_root())
                    {
                        throw Log.Fatal(
                                  "Describing parent-direction rotating frame of root body");
                    }
                    else
                    {
                        return(L10N.CelestialString(
                                   "#Principia_ReferenceFrameSelector_Description_BodyCentredParentDirection",
                                   new[] { selected, selected.referenceBody }));
                    }

                case FrameType.BODY_SURFACE:
                    return(L10N.CelestialString(
                               "#Principia_ReferenceFrameSelector_Description_BodySurface",
                               new[] { selected }));

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
Example #7
0
            public static String Description(FrameType type, CelestialBody selected)
            {
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return("Non-rotating reference frame fixing the centre of " +
                           selected.theName);

                case FrameType.BARYCENTRIC_ROTATING:
                    if (selected.is_root())
                    {
                        throw Log.Fatal("Describing barycentric rotating frame of root body");
                    }
                    else
                    {
                        return("Reference frame fixing the barycentre of " +
                               selected.theName + " and " + selected.referenceBody.theName +
                               ", the plane in which they move about the barycentre, and" +
                               " the line between them");
                    }

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
            public static String Name(FrameType type,
                                      CelestialBody selected,
                                      Vessel target_override)
            {
                if (target_override)
                {
                    return("Target Local Vert./Horiz. at " + selected.NameWithArticle());
                }
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return(selected.name + "-Centred Inertial");

                case FrameType.BARYCENTRIC_ROTATING:
                    if (selected.is_root())
                    {
                        throw Log.Fatal("Naming barycentric rotating frame of root body");
                    }
                    else
                    {
                        return(selected.referenceBody.name + "-" + selected.name +
                               " Barycentric");
                    }

                case FrameType.BODY_CENTRED_PARENT_DIRECTION:
                    if (selected.is_root())
                    {
                        throw Log.Fatal(
                                  "Naming parent-direction rotating frame of root body");
                    }
                    else
                    {
                        return(selected.name + "-Centred " + selected.referenceBody.name +
                               "-Aligned");
                    }

                case FrameType.BODY_SURFACE:
                    return(selected.name + "-Centred " + selected.name + "-Fixed");

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
            public static String ShortName(FrameType type,
                                           CelestialBody selected,
                                           Vessel target_override)
            {
                if (target_override)
                {
                    return("Tgt LVLH@" + selected.name[0]);
                }
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return(selected.name[0] + "CI");

                case FrameType.BARYCENTRIC_ROTATING:
                    if (selected.is_root())
                    {
                        throw Log.Fatal("Naming barycentric rotating frame of root body");
                    }
                    else
                    {
                        return(selected.referenceBody.name[0] + (selected.name[0] + "B"));
                    }

                case FrameType.BODY_CENTRED_PARENT_DIRECTION:
                    if (selected.is_root())
                    {
                        throw Log.Fatal(
                                  "Naming parent-direction rotating frame of root body");
                    }
                    else
                    {
                        return(selected.name[0] + "C" + selected.referenceBody.name[0] +
                               "A");
                    }

                case FrameType.BODY_SURFACE:
                    return(selected.name[0] + "C" + selected.name[0] + "F");

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
Example #10
0
            public static String Name(FrameType type, CelestialBody selected)
            {
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return(selected.name + "-Centred Inertial");

                case FrameType.BARYCENTRIC_ROTATING:
                    if (selected.is_root())
                    {
                        throw Log.Fatal("Naming barycentric rotating frame of root body");
                    }
                    else
                    {
                        return(selected.referenceBody.name + "-" + selected.name +
                               " Barycentric");
                    }

                case FrameType.BODY_CENTRED_PARENT_DIRECTION:
                    if (selected.is_root())
                    {
                        throw Log.Fatal(
                                  "Naming parent-direction rotating frame of root body");
                    }
                    else
                    {
                        // TODO(egg): find a proper name...
                        return(selected.name + "-Centred " + selected.referenceBody.name +
                               "-Fixed");
                    }

                case FrameType.BODY_SURFACE:
                    return(selected.name + "-Centred " + selected.name + "-Fixed");

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
            private static string NavballName(FrameType type,
                                              CelestialBody selected)
            {
                string result = Abbreviation(type, selected);

                if (result != null)
                {
                    return(result);
                }
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    result = L10N.CelestialStringOrNull(
                        "#Principia_ReferenceFrameSelector_NavballName_BodyCentredNonRotating",
                        new[] { selected });
                    break;

                case FrameType.BARYCENTRIC_ROTATING:
                    result = "DEPRECATED";
                    break;

                case FrameType.BODY_CENTRED_PARENT_DIRECTION:
                    if (selected.is_root())
                    {
                        throw Log.Fatal(
                                  "Naming parent-direction rotating frame of root body");
                    }
                    else
                    {
                        result = L10N.CelestialStringOrNull(
                            "#Principia_ReferenceFrameSelector_NavballName_BodyCentredParentDirection",
                            new[] { selected, selected.referenceBody });
                    }
                    break;

                case FrameType.BODY_SURFACE:
                    result = L10N.CelestialStringOrNull(
                        "#Principia_ReferenceFrameSelector_NavballName_BodySurface",
                        new[] { selected });
                    break;

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
                if (result != null)
                {
                    return(result);
                }
                return(Name(type, selected));
            }
 public static String Name(FrameType type, CelestialBody selected) {
  switch (type) {
    case FrameType.BODY_CENTRED_NON_ROTATING:
      return selected.name + "-Centred Inertial";
    case FrameType.BARYCENTRIC_ROTATING:
       if (selected.is_root()) {
         throw Log.Fatal("Naming barycentric rotating frame of root body");
       } else {
         return selected.referenceBody.name + "-" + selected.name +
                " Barycentric";
       }
    default:
      throw Log.Fatal("Unexpected type " + type.ToString());
  }
 }
Example #13
0
            public static String ShortName(FrameType type, CelestialBody selected)
            {
                switch (type)
                {
                case FrameType.BODY_CENTRED_NON_ROTATING:
                    return(selected.name[0] + "CI");

                case FrameType.BARYCENTRIC_ROTATING:
                    if (selected.is_root())
                    {
                        throw Log.Fatal("Naming barycentric rotating frame of root body");
                    }
                    else
                    {
                        return(selected.referenceBody.name[0] + (selected.name[0] + "B"));
                    }

                default:
                    throw Log.Fatal("Unexpected type " + type.ToString());
                }
            }
 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);
                        }
                    }
                }
            }
 public static String ShortName(FrameType type, CelestialBody selected) {
   switch (type) {
     case FrameType.BODY_CENTRED_NON_ROTATING:
       return selected.name[0] + "CI";
     case FrameType.BARYCENTRIC_ROTATING:
       if (selected.is_root()) {
         throw Log.Fatal(
             "Naming parent-direction rotating frame of root body");
       } else {
         return selected.referenceBody.name[0] + (selected.name[0] + "B");
       }
     case FrameType.BODY_CENTRED_PARENT_DIRECTION:
       if (selected.is_root()) {
         throw Log.Fatal("Naming barycentric rotating frame of root body");
       } else {
         return selected.name[0] + "C" + selected.referenceBody.name[0] +
                "F";
       }
     case FrameType.BODY_SURFACE:
       return selected.name[0] + "C" + selected.name[0] + "F";
     default:
       throw Log.Fatal("Unexpected type " + type.ToString());
   }
 }
 public static String Description(FrameType type, CelestialBody selected) {
   switch (type) {
     case FrameType.BODY_CENTRED_NON_ROTATING:
       return "Non-rotating reference frame fixing the centre of " +
              selected.theName;
     case FrameType.BARYCENTRIC_ROTATING:
       if (selected.is_root()) {
         throw Log.Fatal("Describing barycentric rotating frame of root body");
       } else {
         return "Reference frame fixing the barycentre of " +
                selected.theName + " and " + selected.referenceBody.theName +
                ", the plane in which they move about the barycentre, and" +
                " the line between them";
       }
     default:
       throw Log.Fatal("Unexpected type " + type.ToString());
   }
 }