Skip to content

Commit 6bc9489

Browse files
committed
Expose universal-blocking toggle in CTB toolbar popup
The CTB toolbar button (right-click) opens the focus-follows-mouse/ focus-follows-click dialog. Add the universal IMGUI click-through blocking toggle there too so users can flip it without opening the stock settings panel. Extend the existing "Focus change is global" option to also save and restore universalClickBlocking via Global.cfg. SaveGlobalDefault now takes both flags and writes both keys; a new GetGlobalDefaultUniversal mirror reads it back. RegisterToolbar's OnGameSettingsWritten / OnGameNewStart / OnGameStateCreated propagate both flags. Popup height bumped 350→400 to fit the extra toggle.
1 parent 6bc02a6 commit 6bc9489

2 files changed

Lines changed: 34 additions & 4 deletions

File tree

ClickThroughBlocker/OneTimePopup.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class OneTimePopup : MonoBehaviour
1313
{
1414
internal static OneTimePopup Instance = null;
1515
const int WIDTH = 600;
16-
const int HEIGHT = 350;
16+
const int HEIGHT = 400;
1717
Rect popupRect = new Rect(300, 50, WIDTH, HEIGHT);
1818
bool visible = false;
1919
static string popUpShownCfgPath { get {
@@ -41,6 +41,7 @@ public void Start()
4141
{
4242

4343
visible = true;
44+
universalClickBlocking = HighLogic.CurrentGame.Parameters.CustomParams<CTB>().universalClickBlocking;
4445
if (ClearInputLocks.modeWindow != null)
4546
{
4647
visible = true;
@@ -78,6 +79,7 @@ public void OnGUI()
7879
bool focusFollowsClick = false;
7980
bool oldFocusFollowsMouse = false;
8081
bool oldFocusFollowsClick = false;
82+
bool universalClickBlocking = false;
8183
void PopUpWindow(int id)
8284
{
8385
GUILayout.BeginVertical();
@@ -103,16 +105,21 @@ void PopUpWindow(int id)
103105
oldFocusFollowsClick = true;
104106
focusFollowsMouse = oldFocusFollowsMouse = false;
105107
}
108+
GUILayout.Space(10);
109+
universalClickBlocking = GUILayout.Toggle(universalClickBlocking,
110+
"Universal IMGUI click-through blocking (covers mods that don't use CTB)");
106111
if (!focusFollowsClick && !focusFollowsMouse)
107112
GUI.enabled = false;
108113
GUILayout.BeginHorizontal();
109114
if (GUILayout.Button("Save as global default for all new saves"))
110115
{
111-
SaveGlobalDefault(focusFollowsClick);
116+
SaveGlobalDefault(focusFollowsClick, universalClickBlocking);
112117
}
113118
if (GUILayout.Button("Accept"))
114119
{
115120
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick = focusFollowsClick;
121+
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().universalClickBlocking = universalClickBlocking;
122+
ClearInputLocks.universalClickBlocking = universalClickBlocking;
116123
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().showPopup = false;
117124
CreatePopUpFlagFile();
118125
ClearInputLocks.ClearInputLocksToggle();
@@ -140,10 +147,11 @@ static string GlobalDefaultFile
140147
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/../Global.cfg";
141148
}
142149
}
143-
static internal void SaveGlobalDefault(bool focusFollowsClick)
150+
static internal void SaveGlobalDefault(bool focusFollowsClick, bool universalClickBlocking)
144151
{
145152
ConfigNode node = new ConfigNode();
146153
node.AddValue("focusFollowsClick", focusFollowsClick);
154+
node.AddValue("universalClickBlocking", universalClickBlocking);
147155
node.Save(GlobalDefaultFile);
148156
}
149157

@@ -164,6 +172,20 @@ static internal bool GetGlobalDefault(ref bool b)
164172
}
165173
return false;
166174
}
175+
176+
static internal bool GetGlobalDefaultUniversal(ref bool b)
177+
{
178+
if (System.IO.File.Exists(GlobalDefaultFile))
179+
{
180+
if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.Parameters.CustomParams<CTB>().global)
181+
{
182+
ConfigNode node = ConfigNode.Load(GlobalDefaultFile);
183+
if (node.TryGetValue("universalClickBlocking", ref b))
184+
return true;
185+
}
186+
}
187+
return false;
188+
}
167189
static internal void CreatePopUpFlagFile()
168190
{
169191
RemovePopUpFlagFile(); // remove first to avoid any overwriting

ClickThroughBlocker/RegisterToolbar.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ void Start()
1919
void OnGameSettingsWritten()
2020
{
2121
if (HighLogic.CurrentGame != null && HighLogic.CurrentGame.Parameters.CustomParams<CTB>().global)
22-
OneTimePopup.SaveGlobalDefault (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick);
22+
OneTimePopup.SaveGlobalDefault(
23+
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick,
24+
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().universalClickBlocking);
2325
}
2426

2527
void OnGameNewStart()
@@ -31,6 +33,9 @@ void OnGameNewStart()
3133
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().showPopup = false;
3234
OneTimePopup.CreatePopUpFlagFile();
3335
}
36+
bool u = false;
37+
if (OneTimePopup.GetGlobalDefaultUniversal(ref u))
38+
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().universalClickBlocking = u;
3439
}
3540
void OnGameStateCreated(Game g)
3641
{
@@ -41,6 +46,9 @@ void OnGameStateCreated(Game g)
4146
g.Parameters.CustomParams<CTB>().showPopup = false;
4247
OneTimePopup.CreatePopUpFlagFile();
4348
}
49+
bool u = false;
50+
if (OneTimePopup.GetGlobalDefaultUniversal(ref u))
51+
g.Parameters.CustomParams<CTB>().universalClickBlocking = u;
4452
}
4553
}
4654
}

0 commit comments

Comments
 (0)