Skip to content

Commit 1819daa

Browse files
committed
I will probably abandon this branch - will use reflection
instead so it can tolerate having no ClickThruBlocker installed.
1 parent 741c721 commit 1819daa

File tree

12 files changed

+47
-16
lines changed

12 files changed

+47
-16
lines changed

CONTRIBUTING.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,14 @@ Setting Up Your Environment
213213
* Click on the resulting link to go to that class's documentation page.
214214
* The Unity documentation for that class will start with some faint grey text at the top of the page that says, "Implemented in:", which tells you which DLL you need to reference to get code using that class to compile properly.
215215

216-
3. If you do not have a copy of KSP locally, you may
216+
3. Make sure your installation of KSP has LinuxGuruGamer's ClivkThroughBlocker
217+
mod installed. kOS now needs it in order to compile. After it is
218+
installed, create a reference for it in your kOS project's References
219+
like so:
220+
221+
* $KSP_INSTALL_DIR/GameData/00_ClickThroughBlocker/Plugins/ClickThroughBlocker.dll
222+
223+
4. If you do not have a copy of KSP locally, you may
217224
download dummy assemblies at https://github.com/KSP-KOS/KSP_LIB
218225

219226
3. Make sure you are targeting this version of .Net: ".Net 4.0 Framework".

src/kOS/Properties/AssemblyInfo.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@
3434
[assembly: AssemblyFileVersion("1.2.1.0")]
3535
[assembly: AssemblyVersion("1.2.1.0")]
3636
[assembly: KSPAssembly("kOS", 1, 7)]
37+
[assembly: KSPAssemblyDependency("ClickThroughBlocker", 1, 0)]

src/kOS/Screen/DelegateDialog.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
2+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
23
using UnityEngine;
34

45
namespace kOS.Screen
@@ -38,7 +39,7 @@ public void OnGUI()
3839
if (invoked)
3940
{
4041
float guessWidth = GUI.skin.label.CalcSize( new GUIContent(message) ).x;
41-
GUILayout.Window( parent.GetUniqueId()+1, new Rect( parent.GetRect().xMin+200,
42+
ClickThruBlocker.GUILayoutWindow( parent.GetUniqueId()+1, new Rect( parent.GetRect().xMin+200,
4243
parent.GetRect().yMin+10,
4344
guessWidth,
4445
0) , DrawConfirm, "Confirm", GUILayout.ExpandWidth(true) );

src/kOS/Screen/GUIWindow.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using kOS.Utilities;
1515
using kOS.Communication;
1616
using kOS.Safe;
17+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
1718

1819
namespace kOS.Screen
1920
{
@@ -116,15 +117,15 @@ void OnGUI()
116117

117118
GUI.skin = HighLogic.Skin;
118119

119-
WindowRect = GUILayout.Window(UniqueId, WindowRect, WidgetGui, TitleText, style);
120+
WindowRect = ClickThruBlocker.GUILayoutWindow(UniqueId, WindowRect, WidgetGui, TitleText, style);
120121

121122
if (currentPopup != null) {
122123
var r = RectExtensions.EnsureCompletelyVisible(currentPopup.popupRect);
123124
if (Event.current.type == EventType.MouseDown && !r.Contains(Event.current.mousePosition)) {
124125
currentPopup.PopDown();
125126
} else {
126127
GUI.BringWindowToFront(UniqueId + 1);
127-
currentPopup.popupRect = GUILayout.Window(UniqueId + 1, r, PopupGui, "", style);
128+
currentPopup.popupRect = ClickThruBlocker.GUILayoutWindow(UniqueId + 1, r, PopupGui, "", style);
128129
}
129130
}
130131
}

src/kOS/Screen/KOSManagedWindow.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
using System.Collections.Generic;
22
using UnityEngine;
3+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
34

45
namespace kOS.Screen
56
{
67
/// <summary>
78
/// kOSManagedWindow is for any Unity Monobehavior that you'd like to
8-
/// have contain a GUI.Window, and you need kOS to keep track of the
9+
/// have contain an IMGUI Window, and you need kOS to keep track of the
910
/// window stacking for which click is on top of which other click.
1011
/// Unity's built in systems for this don't work well at all, so
1112
/// we had to make up our own.
13+
///
14+
/// Issue #2697 - In addition to KOS's own system to handle this,
15+
/// This also is now layered on top of Linuxgurugamer's ClickThroughBlocker
16+
/// mod, so it uses its wrappers around GUI.Window. That was needed because
17+
/// if SOME mods use ClickThruBlocker windows, then those windows will get first
18+
/// dibs on events before kOS gets to, making kOS helpless to intercept events it's
19+
/// trying to protect other windows from seeing. ClickThruBlocker is a mod that
20+
/// once some mods use it, then all the other mods have to as well.
1221
/// </summary>
1322
public abstract class KOSManagedWindow : MonoBehaviour
1423
{

src/kOS/Screen/KOSNameTagWindow.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
using kOS.Utilities;
1+
using kOS.Utilities;
22
using UnityEngine;
33
using kOS.Module;
4+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
45
using System;
56

67
namespace kOS.Screen
@@ -124,7 +125,7 @@ public void OnGUI()
124125
EditorLogic.fetch.Lock(false, false, false, "KOSNameTagLock");
125126

126127
GUI.skin = HighLogic.Skin;
127-
GUILayout.Window(myWindowId, windowRect, DrawWindow,"KOS nametag");
128+
ClickThruBlocker.GUILayoutWindow(myWindowId, windowRect, DrawWindow,"KOS nametag");
128129

129130
// Ensure that the first time the window is made, it gets keybaord focus,
130131
// but allow the focus to leave the window after that:

src/kOS/Screen/KOSTextEditPopup.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using kOS.Safe.Exceptions;
77
using kOS.Safe.Utilities;
88
using kOS.Module;
9+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
910

1011
namespace kOS.Screen
1112
{
@@ -170,7 +171,7 @@ public void OnGUI()
170171
CalcOuterCoords(); // force windowRect to lock to bottom edge of the parents
171172
CalcInnerCoords();
172173

173-
WindowRect = GUI.Window(UniqueId, WindowRect, ProcessWindow, "");
174+
WindowRect = ClickThruBlocker.GUIWindow(UniqueId, WindowRect, ProcessWindow, "");
174175
// Some mouse global state data used by several of the checks:
175176

176177
if (consumeEvent)

src/kOS/Screen/KOSToolbarWindow.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
using System.Collections.Generic;
1111
using System.Linq;
1212
using UnityEngine;
13+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
14+
1315

1416
namespace kOS.Screen
1517
{
@@ -443,7 +445,7 @@ public void OnGUI()
443445

444446
GUI.skin = HighLogic.Skin;
445447

446-
windowRect = GUILayout.Window(UNIQUE_ID, windowRect, DrawWindow, "kOS " + versionString);
448+
windowRect = ClickThruBlocker.GUILayoutWindow(UNIQUE_ID, windowRect, DrawWindow, "kOS " + versionString);
447449
windowRect = RectExtensions.ClampToRectAngle(windowRect, rectToFit);
448450
}
449451

src/kOS/Screen/ListPickerDialog.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using UnityEngine;
3+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
4+
35

46
namespace kOS.Screen
57
{
@@ -110,7 +112,7 @@ public void OnGUI()
110112

111113
// Make sure it shifts enough to the left to fit the biggest string:
112114
outerWindowRect.x = Mathf.Min(outerWindowRect.x, UnityEngine.Screen.width - outerWindowRect.width - 60);
113-
outerWindowRect = GUILayout.Window(
115+
outerWindowRect = ClickThruBlocker.GUILayoutWindow(
114116
title.GetHashCode(),
115117
outerWindowRect,
116118
DrawInnards,

src/kOS/Screen/TermWindow.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using kOS.Safe.UserIO;
1111
using KSP.UI.Dialogs;
1212
using kOS.Safe.Utilities;
13+
using ClickThroughFix; // Needs ClickThroughBlocker DLL to be in the Reference directory.
1314

1415
namespace kOS.Screen
1516
{
@@ -360,7 +361,7 @@ void OnGUI()
360361
// Should probably make "gui screen name for my CPU part" into some sort of utility method:
361362
ChangeTitle(CalcualteTitle());
362363

363-
WindowRect = GUI.Window(UniqueId, WindowRect, TerminalGui, TitleText);
364+
WindowRect = ClickThruBlocker.GUIWindow(UniqueId, WindowRect, TerminalGui, TitleText);
364365

365366
if (consumeEvent)
366367
{

0 commit comments

Comments
 (0)