Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/flight_planner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace principia {
namespace ksp_plugin_adapter {

class FlightPlanner : VesselSupervisedWindowRenderer {
class FlightPlanner : RequiredVesselSupervisedWindowRenderer {
public FlightPlanner(PrincipiaPluginAdapter adapter,
PredictedVessel predicted_vessel) : base(
adapter,
Expand Down
3 changes: 2 additions & 1 deletion ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,10 @@ private void OnGUI() {

if (hide_all_gui_ || !in_principia_scene_) {
LockClearing();
} else if (main_window_.Shown()) {
} else if (WindowsRendering.GetInvocationList().Length > 0) {
WindowsRendering();
} else {
// There are no windows to render.
LockClearing();
}
}
Expand Down
6 changes: 5 additions & 1 deletion ksp_plugin_adapter/orbit_analyser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static bool TryParseMissionDuration(string str, out double seconds) {
}
}

internal abstract class OrbitAnalyser : VesselSupervisedWindowRenderer {
internal abstract class OrbitAnalyser : RequiredVesselSupervisedWindowRenderer {
protected OrbitAnalyser(PrincipiaPluginAdapter adapter,
PredictedVessel predicted_vessel) : base(
adapter,
Expand Down Expand Up @@ -222,6 +222,10 @@ protected override void RenderWindowContents(int window_id) {
using (new UnityEngine.GUILayout.VerticalScope(GUILayoutWidth(12))) {
if (should_request_analysis) {
mission_duration_.Render(enabled : true);
// If the main window is hidden, make sure that the orbit analyser
// refreshes (not at a reduced rate).
last_background_analysis_time_ = null;
RequestAnalysis();
}
var multiline_style = Style.Multiline(UnityEngine.GUI.skin.label);
float two_lines = multiline_style.CalcHeight(
Expand Down
23 changes: 21 additions & 2 deletions ksp_plugin_adapter/window_renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void RenderWindow() {
skin_ = MakeSkin(UnityEngine.GUI.skin);
}
UnityEngine.GUI.skin = skin_;
if (show_) {
if (Shown()) {
// NOTE: Calling `Shrink` here (in a Layout, before drawing the window)
// satisfies the conditions noted in its doc comment and is safe.
Shrink();
Expand Down Expand Up @@ -253,7 +253,8 @@ public void Show() {
show_ = true;
}

public bool Shown() {
// Virtual because subclasses may impose extra conditions to show a window.
public virtual bool Shown() {
return show_;
}

Expand Down Expand Up @@ -386,6 +387,24 @@ protected void RenderButton(string text,
private readonly PredictedVessel predicted_vessel_;
}

// Same as above, but the window is hidden if there is no predicted vessel.
// This avoids displaying stray close buttons and ephemeral windows.
internal abstract class
RequiredVesselSupervisedWindowRenderer : VesselSupervisedWindowRenderer {
protected RequiredVesselSupervisedWindowRenderer(
ISupervisor supervisor,
PredictedVessel predicted_vessel,
params UnityEngine.GUILayoutOption[] options) : base(
supervisor,
predicted_vessel,
options) {
}

public override bool Shown() {
return predicted_vessel != null && base.Shown();
}
}

// A window without a supervisor is effectively modal.
internal abstract class UnsupervisedWindowRenderer : BaseWindowRenderer {
protected UnsupervisedWindowRenderer(
Expand Down