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

Commits on Mar 17, 2019

  1. Tighten visibility.

    pleroy committed Mar 17, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1b5e486 View commit details
  2. Copy the full SHA
    a383f28 View commit details
  3. Revert most changes.

    pleroy committed Mar 17, 2019
    Copy the full SHA
    5be60f7 View commit details
  4. Bring back WindowUtilities.

    pleroy committed Mar 17, 2019
    Copy the full SHA
    5ff55bd View commit details
  5. Add a rectangle and locking to WindowRenderer, and use these for clas…

    …ses that inherit from WindowRenderer.
    pleroy committed Mar 17, 2019
    Copy the full SHA
    3b720b2 View commit details
  6. Merge pull request #2098 from pleroy/Utilities2

    Add a rectangle and locking to WindowRenderer
    pleroy authored Mar 17, 2019
    Copy the full SHA
    27e4b60 View commit details
Showing with 80 additions and 45 deletions.
  1. +3 −17 ksp_plugin_adapter/flight_planner.cs
  2. +3 −17 ksp_plugin_adapter/reference_frame_selector.cs
  3. +74 −11 ksp_plugin_adapter/window_renderer.cs
20 changes: 3 additions & 17 deletions ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
@@ -12,8 +12,6 @@ public FlightPlanner(PrincipiaPluginAdapter adapter,
IntPtr plugin) : base(adapter) {
adapter_ = adapter;
plugin_ = plugin;
window_rectangle_.x = UnityEngine.Screen.width / 2;
window_rectangle_.y = UnityEngine.Screen.height / 3;
final_time_ = new DifferentialSlider(
label : "Plan length",
unit : null,
@@ -33,16 +31,10 @@ protected override void RenderWindow() {
var old_skin = UnityEngine.GUI.skin;
UnityEngine.GUI.skin = null;
if (show_planner_) {
window_rectangle_ = UnityEngine.GUILayout.Window(
id : this.GetHashCode(),
screenRect : window_rectangle_,
func : RenderPlanner,
text : "Flight plan",
options : UnityEngine.GUILayout.MinWidth(500));
WindowUtilities.EnsureOnScreen(ref window_rectangle_);
window_rectangle_.InputLock(this);
Window(func : RenderPlanner,
text : "Flight plan");
} else {
WindowUtilities.ClearLock(this);
ClearLock();
}
UnityEngine.GUI.skin = old_skin;
}
@@ -344,11 +336,6 @@ private void Reset() {
vessel_ = FlightGlobals.ActiveVessel;
}

private void Shrink() {
window_rectangle_.height = 0.0f;
window_rectangle_.width = 0.0f;
}

internal static string FormatPositiveTimeSpan (TimeSpan span) {
return (GameSettings.KERBIN_TIME
? (span.Days * 4 + span.Hours / 6).ToString("0000;0000") +
@@ -375,7 +362,6 @@ internal static string FormatTimeSpan (TimeSpan span) {
private bool show_planner_ = false;
private bool show_guidance_ = false;
private ManeuverNode guidance_node_;
private UnityEngine.Rect window_rectangle_;

private const double Log10TimeLowerRate = 0.0;
private const double Log10TimeUpperRate = 7.0;
20 changes: 3 additions & 17 deletions ksp_plugin_adapter/reference_frame_selector.cs
Original file line number Diff line number Diff line change
@@ -55,8 +55,6 @@ public ReferenceFrameSelector(
}
}
on_change_(FrameParameters());
window_rectangle_.x = UnityEngine.Screen.width / 2;
window_rectangle_.y = UnityEngine.Screen.height / 3;
}

public FrameType frame_type { get; private set; }
@@ -276,16 +274,10 @@ protected override void RenderWindow() {
var old_skin = UnityEngine.GUI.skin;
UnityEngine.GUI.skin = null;
if (show_selector_) {
window_rectangle_ = UnityEngine.GUILayout.Window(
id : this.GetHashCode(),
screenRect : window_rectangle_,
func : RenderSelector,
text : name_ + " selection (" + Name() +
")");
WindowUtilities.EnsureOnScreen(ref window_rectangle_);
window_rectangle_.InputLock(this);
Window(func : RenderSelector,
text : name_ + " selection (" + Name() + ")");
} else {
WindowUtilities.ClearLock(this);
ClearLock();
}
UnityEngine.GUI.skin = old_skin;
}
@@ -389,16 +381,10 @@ private void TypeSelector(FrameType value) {
UnityEngine.GUI.skin.toggle.wordWrap = old_wrap;
}

private void Shrink() {
window_rectangle_.height = 0.0f;
window_rectangle_.width = 0.0f;
}

private Callback on_change_;
// Not owned.
private IntPtr plugin_;
private bool show_selector_;
private UnityEngine.Rect window_rectangle_;
private Dictionary<CelestialBody, bool> expanded_;
private readonly string name_;
}
85 changes: 74 additions & 11 deletions ksp_plugin_adapter/window_renderer.cs
Original file line number Diff line number Diff line change
@@ -9,12 +9,6 @@ namespace ksp_plugin_adapter {
// TODO(egg): eventually |WindowRenderer| should own a rectangle and this should
// not be static.
internal static class WindowUtilities {
public static bool ContainsMouse(this UnityEngine.Rect window_rectangle) {
UnityEngine.Vector3 mouse = UnityEngine.Input.mousePosition;
mouse.y = UnityEngine.Screen.height - mouse.y;
return window_rectangle.Contains(mouse);
}

public static void EnsureOnScreen(ref UnityEngine.Rect window_rectangle) {
const float min_width_on_screen = 50;
const float min_height_on_screen = 50;
@@ -30,9 +24,6 @@ public static void EnsureOnScreen(ref UnityEngine.Rect window_rectangle) {
UnityEngine.Screen.height - min_height_on_screen);
}

const ControlTypes PrincipiaLock = ControlTypes.ALLBUTCAMERAS &
~ControlTypes.ALL_SHIP_CONTROLS;

public static void InputLock(this UnityEngine.Rect window_rectangle,
object window_owner) {
string name = window_owner.GetType().ToString() + ":lock:" +
@@ -49,6 +40,16 @@ public static void ClearLock(object window_owner) {
window_owner.GetHashCode();
InputLockManager.RemoveControlLock(name);
}

private static bool ContainsMouse(this UnityEngine.Rect window_rectangle) {
UnityEngine.Vector3 mouse = UnityEngine.Input.mousePosition;
mouse.y = UnityEngine.Screen.height - mouse.y;
return window_rectangle.Contains(mouse);
}

private static readonly ControlTypes PrincipiaLock =
ControlTypes.ALLBUTCAMERAS &
~ControlTypes.ALL_SHIP_CONTROLS;
};

internal abstract class WindowRenderer : IDisposable {
@@ -59,22 +60,84 @@ public interface ManagerInterface {
public WindowRenderer(ManagerInterface manager) {
manager_ = manager;
manager_.render_windows += RenderWindow;
lock_name_ = GetType().ToString() + ":lock:" + GetHashCode();
}

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

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

// Locking.

protected void ClearLock() {
InputLockManager.RemoveControlLock(lock_name_);
}

private void InputLock() {
UnityEngine.Vector3 mouse = UnityEngine.Input.mousePosition;
mouse.y = UnityEngine.Screen.height - mouse.y;
if (rectangle_.Contains(mouse)) {
InputLockManager.SetControlLock(PrincipiaLock, lock_name_);
} else {
InputLockManager.RemoveControlLock(lock_name_);
}
}

// Rendering.

protected void Window(UnityEngine.GUI.WindowFunction func,
String text) {
rectangle_ = UnityEngine.GUILayout.Window(
id : this.GetHashCode(),
screenRect : rectangle_,
func : func,
text : text,
options : UnityEngine.GUILayout.MinWidth(min_width_));
EnsureOnScreen();
InputLock();
}

private void EnsureOnScreen() {
rectangle_.x = UnityEngine.Mathf.Clamp(
rectangle_.x,
-rectangle_.width + min_width_on_screen_,
UnityEngine.Screen.width - min_width_on_screen_);
rectangle_.y = UnityEngine.Mathf.Clamp(
rectangle_.y,
-rectangle_.height + min_height_on_screen_,
UnityEngine.Screen.height - min_height_on_screen_);
}

protected void Shrink() {
rectangle_.height = 0.0f;
rectangle_.width = 0.0f;
}

abstract protected void RenderWindow();

private static readonly ControlTypes PrincipiaLock =
ControlTypes.ALLBUTCAMERAS &
~ControlTypes.ALL_SHIP_CONTROLS;

private static readonly float min_height_on_screen_ = 50;
private static readonly float min_width_on_screen_ = 50;

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,
y : UnityEngine.Screen.height / 3,
width : min_width_,
height : 0);
}

internal struct Controlled<T> where T : class, IDisposable {