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: 27e4b60e5aff
Choose a base ref
...
head repository: mockingbirdnest/Principia
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b991b85ffc74
Choose a head ref
  • 4 commits
  • 5 files changed
  • 1 contributor

Commits on Mar 17, 2019

  1. Separated managed and unmanaged window renderers and make Dialog an U…

    …nmanagedWindowRenderer. Also, add persistence to the renderer.
    pleroy committed Mar 17, 2019
    Copy the full SHA
    6c5eee2 View commit details

Commits on Mar 18, 2019

  1. Rename to supervised.

    pleroy committed Mar 18, 2019
    Copy the full SHA
    5f0b89e View commit details
  2. Missing rename.

    pleroy committed Mar 18, 2019
    Copy the full SHA
    2b23dc5 View commit details

Commits on Mar 19, 2019

  1. Merge pull request #2100 from pleroy/Dialog

    Make Dialog a WindowRenderer
    pleroy authored Mar 19, 2019
    Copy the full SHA
    b991b85 View commit details
51 changes: 18 additions & 33 deletions ksp_plugin_adapter/dialog.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
namespace principia {
namespace ksp_plugin_adapter {

internal class Dialog : IConfigNode {
internal class Dialog : UnsupervisedWindowRenderer, IConfigNode {
public String Message {
set {
message_ = value;
@@ -15,50 +15,35 @@ public String Message {
}

public void Show() {
RenderWindow();
}

protected override void RenderWindow() {
UnityEngine.GUI.skin = null;
rectangle_ = UnityEngine.GUILayout.Window(
id : this.GetHashCode(),
screenRect : rectangle_,
func : (int id) => {
using (new UnityEngine.GUILayout.VerticalScope())
{
UnityEngine.GUILayout.TextArea(message_ ?? "SHOW WITHOUT MESSAGE");
}
UnityEngine.GUI.DragWindow();
},
text : "Principia");
WindowUtilities.EnsureOnScreen(ref rectangle_);
Window(func : (int id) => {
using (new UnityEngine.GUILayout.VerticalScope())
{
UnityEngine.GUILayout.TextArea(
message_ ?? "SHOW WITHOUT MESSAGE");
}
UnityEngine.GUI.DragWindow();
},
text : "Principia");
}

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);
}
public new void Load(ConfigNode node) {
base.Load(node);
message_ = node.GetAtMostOneValue("message");
}

void IConfigNode.Save(ConfigNode node) {
node.SetValue("x", rectangle_.x, createIfNotFound : true);
node.SetValue("y", rectangle_.y, createIfNotFound : true);
public new void Save(ConfigNode node) {
base.Save(node);
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
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
namespace principia {
namespace ksp_plugin_adapter {

class FlightPlanner : WindowRenderer {
class FlightPlanner : SupervisedWindowRenderer {
public FlightPlanner(PrincipiaPluginAdapter adapter,
IntPtr plugin) : base(adapter) {
adapter_ = adapter;
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ namespace ksp_plugin_adapter {
GameScenes.TRACKSTATION})]
public partial class PrincipiaPluginAdapter
: ScenarioModule,
WindowRenderer.ManagerInterface {
SupervisedWindowRenderer.ISupervisor {

private const String next_release_name_ = "Fano";
private const int next_release_lunation_number_ = 238;
6 changes: 3 additions & 3 deletions ksp_plugin_adapter/reference_frame_selector.cs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ public static bool is_root(this CelestialBody celestial) {
}
}

class ReferenceFrameSelector : WindowRenderer {
class ReferenceFrameSelector : SupervisedWindowRenderer {
public enum FrameType {
BARYCENTRIC_ROTATING = 6001,
BODY_CENTRED_NON_ROTATING = 6000,
@@ -31,10 +31,10 @@ public enum FrameType {
public delegate void Callback(NavigationFrameParameters frame_parameters);

public ReferenceFrameSelector(
ManagerInterface manager,
ISupervisor supervisor,
IntPtr plugin,
Callback on_change,
string name) : base(manager) {
string name) : base(supervisor) {
plugin_ = plugin;
on_change_ = on_change;
name_ = name;
69 changes: 49 additions & 20 deletions ksp_plugin_adapter/window_renderer.cs
Original file line number Diff line number Diff line change
@@ -52,28 +52,11 @@ private static bool ContainsMouse(this UnityEngine.Rect window_rectangle) {
~ControlTypes.ALL_SHIP_CONTROLS;
};

internal abstract class WindowRenderer : IDisposable {
public interface ManagerInterface {
event Action render_windows;
}

public WindowRenderer(ManagerInterface manager) {
manager_ = manager;
manager_.render_windows += RenderWindow;
internal abstract class BaseWindowRenderer : IConfigNode {
protected BaseWindowRenderer() {
lock_name_ = GetType().ToString() + ":lock:" + GetHashCode();
}

~WindowRenderer() {
manager_.render_windows -= RenderWindow;
ClearLock();
}

public void Dispose() {
manager_.render_windows -= RenderWindow;
ClearLock();
GC.SuppressFinalize(this);
}

// Locking.

protected void ClearLock() {
@@ -120,6 +103,24 @@ protected void Shrink() {
rectangle_.width = 0.0f;
}

// Persistence.

public void 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);
}
}

public void Save(ConfigNode node) {
node.SetValue("x", rectangle_.x, createIfNotFound : true);
node.SetValue("y", rectangle_.y, createIfNotFound : true);
}

abstract protected void RenderWindow();

private static readonly ControlTypes PrincipiaLock =
@@ -131,7 +132,6 @@ protected void Shrink() {

private static readonly float min_width_ = 500;

private ManagerInterface manager_;
private String lock_name_;
private UnityEngine.Rect rectangle_ =
new UnityEngine.Rect(x : (UnityEngine.Screen.width - min_width_) / 2,
@@ -140,6 +140,35 @@ protected void Shrink() {
height : 0);
}

internal abstract class SupervisedWindowRenderer :
BaseWindowRenderer, IDisposable {
public interface ISupervisor {
event Action render_windows;
}

public SupervisedWindowRenderer(ISupervisor supervisor) : base() {
supervisor_ = supervisor;
supervisor_.render_windows += RenderWindow;
}

~SupervisedWindowRenderer() {
supervisor_.render_windows -= RenderWindow;
ClearLock();
}

public void Dispose() {
if (supervisor_ != null) {
supervisor_.render_windows -= RenderWindow;
}
ClearLock();
GC.SuppressFinalize(this);
}

private ISupervisor supervisor_;
}

internal abstract class UnsupervisedWindowRenderer : BaseWindowRenderer {}

internal struct Controlled<T> where T : class, IDisposable {
public T get() {
return all_;