Skip to content

Commit 02cc9cd

Browse files
committed
Added popup on start about ClickThruBlocker.
In case someone installs kOS without using CKAN, they won't know about the ClickThroughBlocker requirement. This addes a popup on Start() that will tell them what's going on with ClickThroughBlocker and warn them that kOS won't work without it.
1 parent f1399c9 commit 02cc9cd

File tree

3 files changed

+99
-1
lines changed

3 files changed

+99
-1
lines changed

src/kOS/Module/kOSCustomParameters.cs

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using KSP.IO;
22
using System;
33
using System.Reflection;
4+
using System.Linq;
45

56
namespace kOS.Module
67
{
@@ -46,6 +47,9 @@ public static kOSCustomParameters Instance
4647
[GameParameters.CustomIntParameterUI("")]
4748
public int version = 0;
4849

50+
[GameParameters.CustomParameterUI("")]
51+
public bool passedClickThroughCheck = false;
52+
4953
// these values constrain and back the InstructionsPerUpdate property so that it is clamped both in the
5054
// user interface and when set from within a script.
5155
private const int ipuMin = 50;
@@ -202,6 +206,95 @@ public void CheckMigrateSettings()
202206
}
203207
}
204208

209+
public void CheckClickThroughBlockerExists()
210+
{
211+
if (passedClickThroughCheck)
212+
return;
213+
bool clickThroughExists = false;
214+
215+
var loadedCTBAssembly = AssemblyLoader.loadedAssemblies.FirstOrDefault(a => a.dllName.Equals("ClickThroughBlocker"));
216+
if (loadedCTBAssembly != null)
217+
{
218+
// Must be at least version 0.10 of ClickThroughBlocker:
219+
if (loadedCTBAssembly.versionMajor > 0 || loadedCTBAssembly.versionMinor >= 10)
220+
{
221+
Type ctbType = loadedCTBAssembly.assembly.GetType("ClickThroughFix.CTB", false);
222+
if (ctbType != null)
223+
{
224+
if (ctbType.GetField("focusFollowsclick") != null)
225+
{
226+
clickThroughExists = true;
227+
}
228+
}
229+
}
230+
}
231+
232+
string popupText =
233+
"=======================================\n" +
234+
"<b><color=#ffffff>kOS is Checking for ClickThroughBlocker</color></b>\n" +
235+
"=======================================\n\n" +
236+
"Starting with kOS v1.3, kOS has become dependent on the existence of the ClickThroughBlocker mod. " +
237+
"(And it must be at least version 0.10 of ClickThroughBlocker.)\n\n";
238+
239+
if (clickThroughExists)
240+
{
241+
popupText +=
242+
" <b><color=#ddffdd><<<< CHECK SUCCEEDED >>>>></color></b>\n\n" +
243+
"kOS has found ClickThroughBlocker installed, and it appears to be a version that will work with kOS.\n" +
244+
"\n" +
245+
"Please note that while in the past the kOS terminal has always been click-to-focus, from now " +
246+
"on it will behave however ClickThroughBlocker is set to act, which may be focus-follows-mouse.\n" +
247+
"You can use ClickThroughBlocker's settings to change this behvior like this:\n\n" +
248+
"[Hit Escape] Settings ->\n" +
249+
" Difficulty Options ->\n" +
250+
" ClickThroughBlocker ->\n" +
251+
" [x] Focus Follows Click\n\n";
252+
}
253+
else
254+
{
255+
popupText +=
256+
" <b><color=#ffff88>!!! CHECK FAILED !!!</color></b>\n\n" +
257+
"kOS couldn't find a version of ClickThroughBlocker that works with kOS. This could be " +
258+
"because ClickThroughBlocker is not installed at all, or it could be because its version is too old " +
259+
"(or too new, if ClickThroughBlocker ever renames some things that kOS is using).\n" +
260+
"\n\n" +
261+
"To use kOS v1.3 or higher you'll need to quit Kerbal Space Program and install a version of ClickThroughBlocker that it supports.\n";
262+
}
263+
264+
string buttonText;
265+
global::Callback clickThroughAck;
266+
if (clickThroughExists)
267+
{
268+
clickThroughAck = AcceptClickThrough;
269+
buttonText = "Acknowledged.";
270+
}
271+
else
272+
{
273+
clickThroughAck = FailedClickThrough;
274+
buttonText = "Acknowledged. I'll have to quit and change my mods.";
275+
}
276+
277+
kOSSettingsChecker.QueueDialog(
278+
0.75f, 0.6f,
279+
new MultiOptionDialog(
280+
"ClickThroughBlockerCheck",
281+
popupText,
282+
"kOS ClickThroughBlocker Check",
283+
HighLogic.UISkin,
284+
new DialogGUIButton(buttonText, clickThroughAck, true)
285+
));
286+
}
287+
288+
public void AcceptClickThrough()
289+
{
290+
passedClickThroughCheck = true;
291+
}
292+
293+
public void FailedClickThrough()
294+
{
295+
passedClickThroughCheck = false;
296+
}
297+
205298
public void MigrateSettingsNormal()
206299
{
207300
MigrateSettings(false);

src/kOS/Module/kOSSettingsChecker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ private void CheckSettings()
2222
SafeHouse.Logger.SuperVerbose("kOSSettingsChecker.CheckSettings()");
2323
HighLogic.CurrentGame.Parameters.CustomParams<kOSCustomParameters>().CheckMigrateSettings();
2424
HighLogic.CurrentGame.Parameters.CustomParams<kOSConnectivityParameters>().CheckNewManagers();
25+
HighLogic.CurrentGame.Parameters.CustomParams<kOSCustomParameters>().CheckClickThroughBlockerExists();
2526
}
2627

2728
// Because rapidly showing dialogs can prevent some from being shown, we can just queue up

src/kOS/Properties/AssemblyInfo.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@
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)]
37+
38+
// No longer a hard dependancy, because we want to tell the user why kOS isn't working
39+
// if ClickThroughBlocker is not there, rather than just have it silently refuse to
40+
// load kOS with no explanation as would happen if this line was enabled:
41+
// [assembly: KSPAssemblyDependency("ClickThroughBlocker", 1, 0)]

0 commit comments

Comments
 (0)