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: 688453acb5a7
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 9b3eb0348d43
Choose a head ref
  • 6 commits
  • 2 files changed
  • 1 contributor

Commits on Mar 17, 2019

  1. Copy the full SHA
    f159a2e View commit details
  2. Copy the full SHA
    89ea9b7 View commit details
  3. Copy the full SHA
    c9e8c23 View commit details
  4. Copy the full SHA
    6ad5a5f View commit details
  5. Revert "Pass the message at construction of the dialog."

    This reverts commit 6ad5a5f.
    pleroy committed Mar 17, 2019
    Copy the full SHA
    a2ea26f View commit details
  6. Merge pull request #2096 from pleroy/ConfigNode

    Change the Dialog class to persist its data using a ConfigNode
    pleroy authored Mar 17, 2019
    Copy the full SHA
    9b3eb03 View commit details
Showing with 54 additions and 45 deletions.
  1. +45 −24 ksp_plugin_adapter/dialog.cs
  2. +9 −21 ksp_plugin_adapter/ksp_plugin_adapter.cs
69 changes: 45 additions & 24 deletions ksp_plugin_adapter/dialog.cs
Original file line number Diff line number Diff line change
@@ -6,38 +6,59 @@
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;
internal class Dialog : IConfigNode {
public String Message {
set {
message_ = value;
UnityEngine.Debug.LogError(message_);
}
}

public void Show() {
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) => {
rectangle_ = UnityEngine.GUILayout.Window(
id : this.GetHashCode(),
screenRect : rectangle_,
func : (int id) => {
using (new VerticalLayout())
{
UnityEngine.GUILayout.TextArea(message);
UnityEngine.GUILayout.TextArea(message_ ?? "SHOW WITHOUT MESSAGE");
}
UnityEngine.GUI.DragWindow(
position: new UnityEngine.Rect(x: 0f,
y: 0f,
width: 10000f,
height: 10000f));
UnityEngine.GUI.DragWindow();
},
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;
text : "Principia");
WindowUtilities.EnsureOnScreen(ref rectangle_);
}

void IConfigNode.Load(ConfigNode node) {
String x_value = node.GetAtMostOneValue("x");
if (x_value != null) {
rectangle_.x = System.Convert.ToSingle(x_value);
}
String y_value = node.GetAtMostOneValue("y");
if (y_value != null) {
rectangle_.y = System.Convert.ToSingle(y_value);
}
message_ = node.GetAtMostOneValue("message");
}

public static int XCentre { get; } = UnityEngine.Screen.width / 2;
public static int YCentre { get; } = UnityEngine.Screen.height / 3;
void IConfigNode.Save(ConfigNode node) {
node.SetValue("x", rectangle_.x, createIfNotFound : true);
node.SetValue("y", rectangle_.y, createIfNotFound : true);
if (message_ != null) {
node.SetValue("message", message_, createIfNotFound : true);
}
}

private static readonly float min_width_ = 500;

// The message shown, if any.
private String message_;
private UnityEngine.Rect rectangle_ =
new UnityEngine.Rect(x : (UnityEngine.Screen.width - min_width_) / 2,
y : UnityEngine.Screen.height / 3,
width : min_width_,
height : 0);
}

} // namespace ksp_plugin_adapter
30 changes: 9 additions & 21 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -222,25 +222,15 @@ private KSP.UI.Screens.SpaceTracking space_tracking {
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_dialog_x_ = Dialog.XCentre;
[KSPField(isPersistant = true)]
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;
private bool is_bad_installation_ = false; // Don't persist.
[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;
@@ -252,9 +242,8 @@ private KSP.UI.Screens.SpaceTracking space_tracking {
string load_error = Loader.LoadPrincipiaDllAndInitGoogleLogging();
if (load_error != null) {
is_bad_installation_ = true;
bad_installation_message_ =
bad_installation_dialog_.Message =
"The Principia DLL failed to load.\n" + load_error;
UnityEngine.Debug.LogError(bad_installation_message_);
}
#if KSP_VERSION_1_3_1
if (Versioning.version_major != 1 ||
@@ -682,16 +671,12 @@ public override void OnLoad(ConfigNode node) {

private void OnGUI() {
if (is_bad_installation_) {
bad_installation_dialog_.Show(bad_installation_message_,
ref bad_installation_dialog_x_,
ref bad_installation_dialog_y_);
bad_installation_dialog_.Show();
return;
}

if (is_post_apocalyptic_) {
apocalypse_dialog_.Show(revelation_,
ref apocalypse_dialog_x_,
ref apocalypse_dialog_y_);
apocalypse_dialog_.Show();
}

if (KSP.UI.Screens.ApplicationLauncher.Ready && toolbar_button_ == null) {
@@ -1385,8 +1370,11 @@ private void Precalc() {
if (time_is_advancing_) {
plugin_.AdvanceTime(universal_time, Planetarium.InverseRotAngle);
if (!is_post_apocalyptic_) {
is_post_apocalyptic_ |=
plugin_.HasEncounteredApocalypse(out revelation_);
String revelation = "";
if (plugin_.HasEncounteredApocalypse(out revelation)) {
is_post_apocalyptic_ = true;
apocalypse_dialog_.Message = revelation;
}
}
foreach (var vessel in FlightGlobals.Vessels) {
if (vessel.packed && plugin_.HasVessel(vessel.id.ToString())) {