|
1 | 1 | using KSP.IO;
|
2 | 2 | using System;
|
3 | 3 | using System.Reflection;
|
| 4 | +using System.Linq; |
4 | 5 |
|
5 | 6 | namespace kOS.Module
|
6 | 7 | {
|
@@ -46,6 +47,9 @@ public static kOSCustomParameters Instance
|
46 | 47 | [GameParameters.CustomIntParameterUI("")]
|
47 | 48 | public int version = 0;
|
48 | 49 |
|
| 50 | + [GameParameters.CustomParameterUI("")] |
| 51 | + public bool passedClickThroughCheck = false; |
| 52 | + |
49 | 53 | // these values constrain and back the InstructionsPerUpdate property so that it is clamped both in the
|
50 | 54 | // user interface and when set from within a script.
|
51 | 55 | private const int ipuMin = 50;
|
@@ -202,6 +206,95 @@ public void CheckMigrateSettings()
|
202 | 206 | }
|
203 | 207 | }
|
204 | 208 |
|
| 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 | + |
205 | 298 | public void MigrateSettingsNormal()
|
206 | 299 | {
|
207 | 300 | MigrateSettings(false);
|
|
0 commit comments