Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A close window button. #3384

Merged
merged 2 commits into from
Jun 24, 2022
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.
Jump to
Jump to file
Failed to load files.
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 @@ -52,7 +52,7 @@ class FlightPlanner : VesselSupervisedWindowRenderer {
protected override string Title =>
L10N.CacheFormat("#Principia_FlightPlan_Title");

protected override void RenderWindow(int window_id) {
protected override void RenderWindowContents(int window_id) {
// We must ensure that the GUI elements don't change between Layout and
// Repaint. This means that any state change must occur before Layout or
// after Repaint. This if statement implements the former. It updates the
Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/main_window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ internal class MainWindow : VesselSupervisedWindowRenderer {

protected override string Title => "Principia";

protected override void RenderWindow(int window_id) {
protected override void RenderWindowContents(int window_id) {
using (new UnityEngine.GUILayout.VerticalScope()) {
if (!adapter_.PluginRunning()) {
UnityEngine.GUILayout.Label(
Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/orbit_analyser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ internal abstract class OrbitAnalyser : VesselSupervisedWindowRenderer {
ToUpper() +
orbit_description_.Substring(1);

protected override void RenderWindow(int window_id) {
protected override void RenderWindowContents(int window_id) {
string vessel_guid = predicted_vessel?.id.ToString();
if (vessel_guid == null) {
return;
Expand Down
2 changes: 1 addition & 1 deletion ksp_plugin_adapter/reference_frame_selector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ public enum FrameType {
Name(),
NavballName());

protected override void RenderWindow(int window_id) {
protected override void RenderWindowContents(int window_id) {
using (new UnityEngine.GUILayout.VerticalScope()) {
UnityEngine.GUILayout.Label(
L10N.CacheFormat(
Expand Down
19 changes: 17 additions & 2 deletions ksp_plugin_adapter/window_renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,15 @@ internal abstract class BaseWindowRenderer : ScalingRenderer, IConfigNode {
private UnityEngine.GUISkin skin_;
private bool must_centre_ = true;
private bool show_ = false;
private UnityEngine.Rect rectangle_;
protected UnityEngine.Rect rectangle_;
private DateTime tooltip_begin_;
private string tooltip_ = "";
private UnityEngine.Rect tooltip_rectangle_;
}

// The supervisor of a window decides when to clear input locks, when to render
// the window and when to delete it.
// the window and when to delete it. A supervised window has a “Hide” button,
// in addition to the external toggle handled by the supervisor.
internal abstract class SupervisedWindowRenderer : BaseWindowRenderer {
public interface ISupervisor {
event Action LockClearing;
Expand All @@ -291,6 +292,20 @@ public interface ISupervisor {
supervisor_.WindowsRendering += RenderWindow;
}

protected abstract void RenderWindowContents(int window_id);

protected sealed override void RenderWindow(int window_id) {
if (UnityEngine.GUI.Button(new UnityEngine.Rect(
x: rectangle_.width - Width(1),
y: 0,
width: Width(1),
height: Width(1)),
"×")) {
Hide();
}
RenderWindowContents(window_id);
}

public void DisposeWindow() {
supervisor_.LockClearing -= ClearLock;
supervisor_.WindowsDisposal -= DisposeWindow;
Expand Down