Skip to content

Commit bf690f9

Browse files
Fixed inputlocks not being cleared when canceling the window
Added mode toggle on new button to allow toggling between different modes during the game Updated settings to make it clear if popup will be shown next time in the space center Added code to disable the ShowPopup flag if the focusFollowsClick is changed in the settings Thanks to github user @SteveBenz for this: Make the configuration file not depend on Environment.CurrentDirectory and instead depend on the deployment location of the DLL
1 parent 0d6f96d commit bf690f9

22 files changed

+232
-52
lines changed

Changelog.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
ChangeLog
22

3-
0.1.10.13 (unreleased)
4-
Fixed inputlogs not being cleared when canceling the window
3+
0.1.10.13
4+
Fixed inputlocks not being cleared when canceling the window
5+
Added mode toggle on new button to allow toggling between different modes during the game
6+
Updated settings to make it clear if popup will be shown next time in the space center
7+
Added code to disable the ShowPopup flag if the focusFollowsClick is changed in the settings
8+
Thanks to github user @SteveBenz for this:
9+
Make the configuration file not depend on Environment.CurrentDirectory and instead depend on the deployment location of the DLL
510

611
0.1.10.12
712
Fixed inputlocks not being cleared when setting FocusFollowsMouse

ClickThroughBlocker.version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"MAJOR": 0,
1111
"MINOR": 1,
1212
"PATCH": 10,
13-
"BUILD": 12
13+
"BUILD": 13
1414
},
1515
"KSP_VERSION_MIN": {
1616
"MAJOR": 1,

ClickThroughBlocker/AssemblyVersion.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55

66
using System.Reflection;
77

8-
[assembly: AssemblyVersion("0.1.10.11")]
8+
[assembly: AssemblyVersion("0.1.10.12")]

ClickThroughBlocker/CBTGlobalMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void FixedUpdate()
2929
{
3030
globalTimeTics++;
3131

32-
if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
32+
if (ClearInputLocks.focusFollowsclick)
3333
{
3434
foreach (var w in FocusLock.focusLockDict)
3535
{

ClickThroughBlocker/CBTMonitor.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
#if !DUMMY
55
namespace ClickThroughFix
66
{
7-
//[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
8-
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
7+
[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
98
class CBTMonitor : MonoBehaviour
109
{
1110
void Start()
1211
{
13-
//DontDestroyOnLoad(this);
14-
// GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
12+
DontDestroyOnLoad(this);
13+
GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
1514
ClickThruBlocker.CTBWin.activeBlockerCnt = 0;
1615
}
1716

@@ -26,10 +25,10 @@ void onGameSceneLoadRequested(GameScenes gs)
2625
// the mouse moved over a protected window
2726
void Update()
2827
{
29-
if (HighLogic.CurrentGame == null ||
30-
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
28+
if (HighLogic.LoadedSceneIsEditor && ClearInputLocks.focusFollowsclick) // ||
3129
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
3230
return;
31+
3332
{
3433
if (ClickThruBlocker.CTBWin.activeBlockerCnt > 0)
3534
{
@@ -69,8 +68,8 @@ void Update()
6968
int d;
7069
void LateUpdate()
7170
{
72-
if (HighLogic.CurrentGame == null ||
73-
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
71+
if (HighLogic.CurrentGame == null ||
72+
ClearInputLocks.focusFollowsclick) // ||
7473
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
7574
return;
7675

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using UnityEngine;
2+
using KSP.UI.Screens;
3+
4+
#if !DUMMY
5+
namespace ClickThroughFix
6+
{
7+
//[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
8+
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
9+
class CBTMonitor : MonoBehaviour
10+
{
11+
void Start()
12+
{
13+
//DontDestroyOnLoad(this);
14+
// GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
15+
ClickThruBlocker.CTBWin.activeBlockerCnt = 0;
16+
}
17+
18+
void onGameSceneLoadRequested(GameScenes gs)
19+
{
20+
ClickThruBlocker.CTBWin.activeBlockerCnt = 0;
21+
}
22+
23+
// this whole mess below is to work around a stock bug.
24+
// The bug is that the editor ignores the lock when the Action Group pane is show.
25+
// So we have to each time, clear all locks and then reset those which were active when
26+
// the mouse moved over a protected window
27+
void Update()
28+
{
29+
if (HighLogic.CurrentGame == null ||
30+
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
31+
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
32+
return;
33+
{
34+
if (ClickThruBlocker.CTBWin.activeBlockerCnt > 0)
35+
{
36+
//Log.Info("Setting Mouse.HoveredPart to null & deselecting all parts");
37+
Mouse.HoveredPart = null;
38+
39+
if (EditorLogic.fetch == null)
40+
{
41+
return;
42+
}
43+
44+
for (int i = EditorLogic.fetch.ship.Parts.Count - 1; i >= 0; i--)
45+
//for (int i = 0; i < EditorLogic.fetch.ship.Parts.Count; i++)
46+
{
47+
EditorActionPartSelector selector = EditorLogic.fetch.ship.Parts[i].GetComponent<EditorActionPartSelector>();
48+
if (selector != null)
49+
selector.Deselect();
50+
}
51+
52+
if (EditorActionGroups.Instance != null)
53+
{
54+
EditorActionGroups.Instance.ClearSelection(true);
55+
for (int i = ClickThruBlocker.CTBWin.selectedParts.Count - 1; i >= 0; i--)
56+
//for (int i = 0; i < ClickThruBlocker.CTBWin.selectedParts.Count; i++)
57+
{
58+
EditorActionPartSelector selector = ClickThruBlocker.CTBWin.selectedParts[i].GetComponent<EditorActionPartSelector>();
59+
if (selector != null)
60+
EditorActionGroups.Instance.AddToSelection(selector);
61+
}
62+
}
63+
}
64+
65+
}
66+
}
67+
68+
//static internal long timeTics = 0;
69+
int d;
70+
void LateUpdate()
71+
{
72+
if (HighLogic.CurrentGame == null ||
73+
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
74+
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
75+
return;
76+
77+
d = 0;
78+
ClickThruBlocker.CTBWin win = null;
79+
{
80+
foreach (var w in ClickThruBlocker.winList)
81+
{
82+
if (w.Value.lastUpdated + 4 < CBTGlobalMonitor.globalTimeTics) //+ 0.05 < Planetarium.GetUniversalTime())
83+
{
84+
d = w.Key;
85+
win = w.Value;
86+
break;
87+
}
88+
}
89+
if (d != 0)
90+
{
91+
win.OnDestroy();
92+
}
93+
}
94+
}
95+
}
96+
}
97+
#endif

ClickThroughBlocker/ClearInputLocks.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77
using KSP.IO;
88
using UnityEngine;
99

10-
namespace ClearAllInputLocks
10+
namespace ClickThroughFix
1111
{
1212
[KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
1313
public class ClearInputLocks : MonoBehaviour
1414
{
15-
internal const string MODID = "ClearInputLocks_ns";
16-
internal const string MODNAME = "Clear Input Locks";
15+
internal const string MODID = "CTB_ClearInputLocks_ns";
16+
internal const string MODID2 = "CTB_Toggle_ns";
17+
internal const string MODNAME = "ClickThroughBlocker: Clear Input Locks";
18+
internal const string MODNAME2 = "ClickThroughBlocker: Toggle Mode";
1719
static internal ToolbarControl toolbarControl = null;
20+
static internal ToolbarControl clickThroughToggleControl = null;
21+
static internal bool focusFollowsclick = false;
22+
23+
const string FFC_38 = "000_ClickThroughBlocker/PluginData/FFC-38";
24+
const string FFM_38 = "000_ClickThroughBlocker/PluginData/FFM-38";
25+
const string FFC_24 = "000_ClickThroughBlocker/PluginData/FFC-24";
26+
const string FFM_24 = "000_ClickThroughBlocker/PluginData/FFM-24";
1827

1928

2029
void Start()
@@ -26,10 +35,6 @@ void AddToolbarButton()
2635
{
2736
if (toolbarControl == null)
2837
{
29-
#if false
30-
public void AddToAllToolbars(TC_ClickHandler onTrue, TC_ClickHandler onFalse, TC_ClickHandler onHover, TC_ClickHandler onHoverOut, TC_ClickHandler onEnable, TC_ClickHandler onDisable, ApplicationLauncher.AppScenes visibleInScenes, string nameSpace, string toolbarId, string largeToolbarIcon, string smallToolbarIcon, string toolTip = "");
31-
32-
#endif
3338
toolbarControl = gameObject.AddComponent<ToolbarControl>();
3439
toolbarControl.AddToAllToolbars(null, null,
3540
ApplicationLauncher.AppScenes.SPACECENTER |
@@ -42,9 +47,28 @@ void AddToolbarButton()
4247
"ClearInputLocks",
4348
"000_ClickThroughBlocker/PluginData/lock-38",
4449
"000_ClickThroughBlocker/PluginData/lock-24",
45-
"Clear all input locks"
50+
MODNAME
4651
);
4752
toolbarControl.AddLeftRightClickCallbacks(ClearInputLocksToggle, CallModeWindow);
53+
54+
55+
56+
clickThroughToggleControl = gameObject.AddComponent<ToolbarControl>();
57+
clickThroughToggleControl.AddToAllToolbars(ToggleFocusSetting, ToggleFocusSetting,
58+
ApplicationLauncher.AppScenes.SPACECENTER |
59+
ApplicationLauncher.AppScenes.FLIGHT |
60+
ApplicationLauncher.AppScenes.MAPVIEW |
61+
ApplicationLauncher.AppScenes.VAB |
62+
ApplicationLauncher.AppScenes.SPH |
63+
ApplicationLauncher.AppScenes.TRACKSTATION,
64+
MODID2,
65+
"CTBToggle",
66+
FFC_38,
67+
FFM_38,
68+
FFC_24,
69+
FFM_24,
70+
MODNAME2
71+
);
4872
}
4973
}
5074

@@ -56,6 +80,15 @@ void OnDestroy()
5680
Destroy(toolbarControl);
5781
}
5882
}
83+
84+
static internal void ToggleFocusSetting()
85+
{
86+
focusFollowsclick = !focusFollowsclick;
87+
if (focusFollowsclick)
88+
clickThroughToggleControl.SetTexture(FFC_38, FFC_24);
89+
else
90+
clickThroughToggleControl.SetTexture(FFM_38, FFM_24);
91+
}
5992
static internal void ClearInputLocksToggle()
6093
{
6194
InputLockManager.ClearControlLocks();

ClickThroughBlocker/ClickThroughBlocker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal void PreventEditorClickthrough(Rect r)
6969
//Log.Info("ClickThruBlocker: PreventEditorClickthrough");
7070
bool mouseOverWindow = MouseIsOverWindow(r);
7171
//Log.Info("PreventEditorClickthrough, mouseOverWindow: " + mouseOverWindow);
72-
if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
72+
if (ClearInputLocks.focusFollowsclick)
7373
{
7474
bool mouseClicked = Input.GetMouseButton(0) || Input.GetMouseButton(1);
7575
if (mouseClicked)
@@ -137,7 +137,7 @@ internal void PreventInFlightClickthrough(Rect r)
137137
//
138138
// This section for the Click to Focus option
139139
//
140-
if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
140+
if (ClearInputLocks.focusFollowsclick)
141141
{
142142
bool mouseClicked = Input.GetMouseButton(0) || Input.GetMouseButton(1);
143143
if (mouseClicked)

ClickThroughBlocker/OnGUILoopCount.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private void Start()
2222
long lastonGuiCnt;
2323
private void DoGuiCounter()
2424
{
25-
if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
25+
if (HighLogic.CurrentGame == null || ClearInputLocks.focusFollowsclick)
2626
return;
2727

2828
lastonGuiCnt = (onguiCnt++) - 1;

0 commit comments

Comments
 (0)