Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3ce154a6d5b7
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 688453acb5a7
Choose a head ref
  • 10 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 13, 2019

  1. Add a dialog class.

    pleroy committed Mar 13, 2019
    Copy the full SHA
    b5a6578 View commit details

Commits on Mar 15, 2019

  1. Bad installation window.

    pleroy committed Mar 15, 2019
    Copy the full SHA
    54c84a1 View commit details
  2. Try to avoid DLL errors.

    pleroy committed Mar 15, 2019
    Copy the full SHA
    9af0fa7 View commit details

Commits on Mar 16, 2019

  1. Copy the full SHA
    18d318a View commit details
  2. Copy the full SHA
    e0298ef View commit details
  3. Static initial positions.

    pleroy committed Mar 16, 2019
    Copy the full SHA
    0326bd3 View commit details
  4. Print the current directory.

    pleroy committed Mar 16, 2019
    Copy the full SHA
    7d2fe5e View commit details
  5. After egg's review.

    pleroy committed Mar 16, 2019
    Copy the full SHA
    7419b2a View commit details
  6. Syntax error.

    pleroy committed Mar 16, 2019
    Copy the full SHA
    1cb7f94 View commit details
  7. Merge pull request #2095 from pleroy/UI

    Move two dialogs to a separate class
    pleroy authored Mar 16, 2019
    Copy the full SHA
    688453a View commit details
44 changes: 44 additions & 0 deletions ksp_plugin_adapter/dialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace principia {
namespace ksp_plugin_adapter {

// TODO(phl): Load and save the coordinates from a ConfigNode.
internal class Dialog {

public void Show(String message, ref int x, ref int y) {
UnityEngine.Rect dialog_window_rectangle = UnityEngine.Rect.zero;

UnityEngine.GUI.skin = null;
dialog_window_rectangle.xMin = x;
dialog_window_rectangle.yMin = y;
dialog_window_rectangle = UnityEngine.GUILayout.Window(
id: this.GetHashCode() + 1,
screenRect: dialog_window_rectangle,
func: (int id) => {
using (new VerticalLayout())
{
UnityEngine.GUILayout.TextArea(message);
}
UnityEngine.GUI.DragWindow(
position: new UnityEngine.Rect(x: 0f,
y: 0f,
width: 10000f,
height: 10000f));
},
text: "Principia",
options: UnityEngine.GUILayout.MinWidth(500));
WindowUtilities.EnsureOnScreen(ref dialog_window_rectangle);
x = (int)dialog_window_rectangle.xMin;
y = (int)dialog_window_rectangle.yMin;
}

public static int XCentre { get; } = UnityEngine.Screen.width / 2;
public static int YCentre { get; } = UnityEngine.Screen.height / 3;
}

} // namespace ksp_plugin_adapter
} // namespace principia
19 changes: 9 additions & 10 deletions ksp_plugin_adapter/differential_slider.cs
Original file line number Diff line number Diff line change
@@ -8,15 +8,14 @@ internal class DifferentialSlider {
public delegate string ValueFormatter(double value);

// Rates are in units of |value| per real-time second.
public
DifferentialSlider(string label,
string unit,
double log10_lower_rate,
double log10_upper_rate,
double min_value = double.NegativeInfinity,
double max_value = double.PositiveInfinity,
ValueFormatter formatter = null,
UnityEngine.Color? text_colour = null) {
public DifferentialSlider(string label,
string unit,
double log10_lower_rate,
double log10_upper_rate,
double min_value = double.NegativeInfinity,
double max_value = double.PositiveInfinity,
ValueFormatter formatter = null,
UnityEngine.Color? text_colour = null) {
label_ = label;
unit_ = unit;
if (formatter == null) {
@@ -29,7 +28,7 @@ internal class DifferentialSlider {
min_value_ = min_value;
max_value_ = max_value;
text_colour_ = text_colour;
}
}

public double value { get; set; }

88 changes: 37 additions & 51 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -183,8 +183,6 @@ internal IntPtr Plugin() {

private static Dictionary<CelestialBody, Orbit> unmodified_orbits_;

private String bad_installation_popup_;

private Krakensbane krakensbane_;
private Krakensbane krakensbane {
get {
@@ -223,17 +221,27 @@ private KSP.UI.Screens.SpaceTracking space_tracking {
private Dictionary<uint, QP> part_id_to_degrees_of_freedom_ =
new Dictionary<uint, QP>();

// UI for the apocalypse notification.
// The first apocalyptic error message.
[KSPField(isPersistant = true)]
private String revelation_ = "";
// Whether we have encountered an apocalypse already.
[KSPField(isPersistant = true)]
private bool is_post_apocalyptic_ = false;
[KSPField(isPersistant = true)]
private int apocalypse_window_x_ = UnityEngine.Screen.width / 2;
private int apocalypse_dialog_x_ = Dialog.XCentre;
[KSPField(isPersistant = true)]
private int apocalypse_window_y_ = UnityEngine.Screen.height / 3;
private UnityEngine.Rect apocalypse_window_rectangle_;
private int apocalypse_dialog_y_ = Dialog.YCentre;
private Dialog apocalypse_dialog_ = new Dialog();

// UI for the bad installation notification.
private String bad_installation_message_ = "";
private bool is_bad_installation_ = false;
[KSPField(isPersistant = true)]
private int bad_installation_dialog_x_ = Dialog.XCentre;
[KSPField(isPersistant = true)]
private int bad_installation_dialog_y_ = Dialog.YCentre;
private Dialog bad_installation_dialog_ = new Dialog();

public event Action render_windows;

@@ -243,9 +251,10 @@ private KSP.UI.Screens.SpaceTracking space_tracking {
System.IO.Directory.CreateDirectory("glog/Principia");
string load_error = Loader.LoadPrincipiaDllAndInitGoogleLogging();
if (load_error != null) {
bad_installation_popup_ =
is_bad_installation_ = true;
bad_installation_message_ =
"The Principia DLL failed to load.\n" + load_error;
UnityEngine.Debug.LogError(bad_installation_popup_);
UnityEngine.Debug.LogError(bad_installation_message_);
}
#if KSP_VERSION_1_3_1
if (Versioning.version_major != 1 ||
@@ -530,7 +539,7 @@ private void LoadTextureOrDie(out UnityEngine.Texture texture, String path) {

public override void OnAwake() {
base.OnAwake();
if (bad_installation_popup_ != null) {
if (is_bad_installation_) {
return;
}
// While we're here, we might as well log.
@@ -610,6 +619,9 @@ public override void OnSave(ConfigNode node) {

public override void OnLoad(ConfigNode node) {
base.OnLoad(node);
if (is_bad_installation_) {
return;
}
if (must_record_journal_) {
journaling_ = true;
Log.ActivateRecorder(true);
@@ -639,12 +651,12 @@ public override void OnLoad(ConfigNode node) {
ref plugin_,
serialization_compression_,
serialization_encoding_);
if (serialization_compression_ == "") {
serialization_compression_ = "gipfeli";
}
if (serialization_encoding_ == "hexadecimal") {
serialization_encoding_ = "base64";
}
if (serialization_compression_ == "") {
serialization_compression_ = "gipfeli";
}
if (serialization_encoding_ == "hexadecimal") {
serialization_encoding_ = "base64";
}

plotting_frame_selector_.reset(
new ReferenceFrameSelector(this,
@@ -669,46 +681,17 @@ public override void OnLoad(ConfigNode node) {
// http://docs.unity3d.com/Manual/ExecutionOrder.html

private void OnGUI() {
if (bad_installation_popup_ != null) {
UnityEngine.Debug.LogError("Spawning: " + bad_installation_popup_);
// No-one seems to understand what |anchorMin| and |anchorMax| do at this
// time.
PopupDialog.SpawnPopupDialog(
anchorMin : default(UnityEngine.Vector2),
anchorMax : default(UnityEngine.Vector2),
dialogName : "Principia error",
title : "Principia",
message : bad_installation_popup_,
buttonMessage : "OK",
persistAcrossScenes : true,
skin : null,
isModal : true);
bad_installation_popup_ = null;
if (is_bad_installation_) {
bad_installation_dialog_.Show(bad_installation_message_,
ref bad_installation_dialog_x_,
ref bad_installation_dialog_y_);
return;
}

if (is_post_apocalyptic_) {
UnityEngine.GUI.skin = null;
apocalypse_window_rectangle_.xMin = apocalypse_window_x_;
apocalypse_window_rectangle_.yMin = apocalypse_window_y_;
apocalypse_window_rectangle_ = UnityEngine.GUILayout.Window(
id : this.GetHashCode() + 1,
screenRect : apocalypse_window_rectangle_,
func : (int id) => {
using (new VerticalLayout()) {
UnityEngine.GUILayout.TextArea(revelation_);
}
UnityEngine.GUI.DragWindow(
position : new UnityEngine.Rect(x : 0f,
y : 0f,
width : 10000f,
height : 10000f));
},
text : "Principia",
options : UnityEngine.GUILayout.MinWidth(500));
WindowUtilities.EnsureOnScreen(ref apocalypse_window_rectangle_);
apocalypse_window_x_ = (int)apocalypse_window_rectangle_.xMin;
apocalypse_window_y_ = (int)apocalypse_window_rectangle_.yMin;
apocalypse_dialog_.Show(revelation_,
ref apocalypse_dialog_x_,
ref apocalypse_dialog_y_);
}

if (KSP.UI.Screens.ApplicationLauncher.Ready && toolbar_button_ == null) {
@@ -1007,6 +990,9 @@ private void LateUpdate() {
}

private void FixedUpdate() {
if (is_bad_installation_) {
return;
}
if (GameSettings.ORBIT_WARP_DOWN_AT_SOI) {
Log.Info("Setting GameSettings.ORBIT_WARP_DOWN_AT_SOI to false");
GameSettings.ORBIT_WARP_DOWN_AT_SOI = false;
@@ -1037,7 +1023,7 @@ private void FixedUpdate() {
}

private void OnDisable() {
if (bad_installation_popup_ != null) {
if (is_bad_installation_) {
return;
}
Log.Info("principia.ksp_plugin_adapter.PrincipiaPluginAdapter.OnDisable()");
1 change: 1 addition & 0 deletions ksp_plugin_adapter/ksp_plugin_adapter.csproj
Original file line number Diff line number Diff line change
@@ -102,6 +102,7 @@
<Compile Include="config_node_extensions.cs" />
<Compile Include="config_node_parsers.cs" />
<Compile Include="culture.cs" />
<Compile Include="dialog.cs" />
<Compile Include="differential_slider.cs" />
<Compile Include="disposable.cs" />
<Compile Include="disposable_marshaller.cs" />
3 changes: 2 additions & 1 deletion ksp_plugin_adapter/loader.cs
Original file line number Diff line number Diff line change
@@ -46,7 +46,8 @@ internal static string LoadPrincipiaDllAndInitGoogleLogging() {
}
if (!possible_dll_paths.Any(File.Exists)) {
return "The principia DLL was not found at '" +
String.Join("', '", possible_dll_paths) + "'.";
String.Join("', '", possible_dll_paths) + "' in directory '" +
Directory.GetCurrentDirectory() + "'.";
}
try {
loaded_principia_dll_ = true;