Skip to content

Commit

Permalink
Added cleanup class to cleanup all input locks after a delay, immedi…
Browse files Browse the repository at this point in the history
…ately upon changing scenes

 Added cleanup delay to settings page
  • Loading branch information
linuxgurugamer committed Jun 22, 2020
1 parent 274dc63 commit af957c7
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 74 deletions.
8 changes: 6 additions & 2 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
ChangeLog

0.1.10.4 (unreleased)
0.1.10.5
Added cleanup class to cleanup all input locks after a delay, immediately upon changing scenes
Added cleanup delay to settings page

0.1.10.4
Added MiniMod to clear input locks via toolbar button, right-click brings up window
Added one-time popup window
Added ToolbarController as a dependency

0.1.10.2 (unreleased)
0.1.10.2
Removed need to save window rect
Reorganized code a bit
Removed some unnecessary assignments
Expand Down
2 changes: 1 addition & 1 deletion ClickThroughBlocker.version
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"MAJOR": 0,
"MINOR": 1,
"PATCH": 10,
"BUILD": 4
"BUILD": 5
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
2 changes: 1 addition & 1 deletion ClickThroughBlocker/AssemblyVersion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

using System.Reflection;

[assembly: AssemblyVersion("0.1.10.3")]
[assembly: AssemblyVersion("0.1.10.5")]
67 changes: 67 additions & 0 deletions ClickThroughBlocker/ClearInputLocks.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using ToolbarControl_NS;
using KSP.UI.Screens;
using KSP.Localization;
using System;
using System.IO;

using KSP.IO;
using UnityEngine;

namespace ClearAllInputLocks
{
[KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
public class ClearInputLocks : MonoBehaviour
{
internal const string MODID = "ClearInputLocks_ns";
internal const string MODNAME = "Clear Input Locks";
static internal ToolbarControl toolbarControl = null;


void Start()
{
AddToolbarButton();
}

void AddToolbarButton()
{
if (toolbarControl == null)
{
#if false
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 = "");

#endif
toolbarControl = gameObject.AddComponent<ToolbarControl>();
toolbarControl.AddToAllToolbars(null, null,
ApplicationLauncher.AppScenes.SPACECENTER |
ApplicationLauncher.AppScenes.FLIGHT |
ApplicationLauncher.AppScenes.MAPVIEW |
ApplicationLauncher.AppScenes.VAB |
ApplicationLauncher.AppScenes.SPH |
ApplicationLauncher.AppScenes.TRACKSTATION,
MODID,
"ClearInputLocks",
"000_ClickThroughBlocker/PluginData/lock-38",
"000_ClickThroughBlocker/PluginData/lock-24",
"Clear all input locks"
);
toolbarControl.AddLeftRightClickCallbacks(ClearInputLocksToggle, CallModeWindow);
}
}

void ClearInputLocksToggle()
{
InputLockManager.ClearControlLocks();
ScreenMessages.PostScreenMessage("All Input Locks Cleared", 5);
}

internal static MonoBehaviour modeWindow = null;
void CallModeWindow()
{
ClickThroughFix.Log.Info("CallModeWindow, modeWindow: " + (modeWindow != null));
if (modeWindow == null)
modeWindow = gameObject.AddComponent<OneTimePopup>();
else
Destroy(modeWindow);
}
}
}
2 changes: 2 additions & 0 deletions ClickThroughBlocker/ClickThroughBlocker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
</Compile>
<Compile Include="CBTGlobalMonitor.cs" />
<Compile Include="CBTMonitor.cs" />
<Compile Include="ClearInputLocks.cs" />
<Compile Include="ClickThroughBlocker.cs" />
<Compile Include="FocusLock.cs" />
<Compile Include="GlobalFlagStorage.cs" />
Expand All @@ -62,6 +63,7 @@
<Compile Include="OnGUILoopCount.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RegisterToolbar.cs" />
<Compile Include="SceneChangeCleanup.cs" />
<Compile Include="Settings.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
14 changes: 7 additions & 7 deletions ClickThroughBlocker/OneTimePopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using UnityEngine;


namespace ClickThroughFix
namespace ClearAllInputLocks
{
[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
public class OneTimePopup : MonoBehaviour
Expand All @@ -19,12 +19,12 @@ public class OneTimePopup : MonoBehaviour

public void Start()
{
if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().showPopup || !System.IO.File.Exists(POPUP_FILE_FLAG))
if (HighLogic.CurrentGame.Parameters.CustomParams<ClickThroughFix.CTB>().showPopup || !System.IO.File.Exists(POPUP_FILE_FLAG))
visible = true;
if (ClearAllInputLocks.ClearInputLocks.modeWindow != null)
if (ClearInputLocks.modeWindow != null)
{
visible = true;
focusFollowsClick = oldFocusFollowsClick = HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick;
focusFollowsClick = oldFocusFollowsClick = HighLogic.CurrentGame.Parameters.CustomParams<ClickThroughFix.CTB>().focusFollowsclick;
focusFollowsMouse = oldFocusFollowsMouse = !focusFollowsClick;
cancelStr = "Cancel";
}
Expand All @@ -37,7 +37,7 @@ public void OnGUI()
if (visible)
{
GUI.skin = HighLogic.Skin;
popupRect = ClickThruBlocker.GUILayoutWindow(847733455, popupRect, PopUpWindow, "Click Through Blocker Focus Setting");
popupRect = ClickThroughFix.ClickThruBlocker.GUILayoutWindow(847733455, popupRect, PopUpWindow, "Click Through Blocker Focus Setting");
}
}

Expand Down Expand Up @@ -75,8 +75,8 @@ void PopUpWindow(int id)
GUILayout.BeginHorizontal();
if (GUILayout.Button("Accept"))
{
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick = focusFollowsClick;
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().showPopup = false;
HighLogic.CurrentGame.Parameters.CustomParams<ClickThroughFix.CTB>().focusFollowsclick = focusFollowsClick;
HighLogic.CurrentGame.Parameters.CustomParams<ClickThroughFix.CTB>().showPopup = false;
CreatePopUpFlagFile();
visible = false;
Destroy(this);
Expand Down
57 changes: 0 additions & 57 deletions ClickThroughBlocker/RegisterToolbar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

using KSP.IO;
using UnityEngine;
using ClickThroughFix;


namespace ClearAllInputLocks
Expand All @@ -19,60 +18,4 @@ void Start()
ToolbarControl.RegisterMod(ClearInputLocks.MODID, ClearInputLocks.MODNAME);
}
}

[KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
public class ClearInputLocks : MonoBehaviour
{
internal const string MODID = "ClearInputLocks_ns";
internal const string MODNAME = "Clear Input Locks";
static internal ToolbarControl toolbarControl = null;


void Start()
{
AddToolbarButton();
}

void AddToolbarButton()
{
if (toolbarControl == null)
{
#if false
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 = "");

#endif
toolbarControl = gameObject.AddComponent<ToolbarControl>();
toolbarControl.AddToAllToolbars(null,null,
ApplicationLauncher.AppScenes.SPACECENTER |
ApplicationLauncher.AppScenes.FLIGHT |
ApplicationLauncher.AppScenes.MAPVIEW |
ApplicationLauncher.AppScenes.VAB |
ApplicationLauncher.AppScenes.SPH |
ApplicationLauncher.AppScenes.TRACKSTATION,
MODID,
"ClearInputLocks",
"000_ClickThroughBlocker/PluginData/lock-38",
"000_ClickThroughBlocker/PluginData/lock-24",
"Clear all input locks"
);
toolbarControl.AddLeftRightClickCallbacks(ClearInputLocksToggle, CallModeWindow);
}
}

void ClearInputLocksToggle()
{
InputLockManager.ClearControlLocks();
ScreenMessages.PostScreenMessage("All Input Locks Cleared", 5);
}

internal static MonoBehaviour modeWindow = null;
void CallModeWindow()
{
Log.Info("CallModeWindow, modeWindow: " + (modeWindow != null));
if (modeWindow == null)
modeWindow = gameObject.AddComponent<OneTimePopup>();
else
Destroy(modeWindow);
}
}
}
45 changes: 45 additions & 0 deletions ClickThroughBlocker/SceneChangeCleanup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using System;
using System.Collections;
using UnityEngine;

namespace ClearAllInputLocks
{
[KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
class SceneChangeCleanup : MonoBehaviour
{
void Start()
{
GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
GameEvents.onGUIApplicationLauncherReady.Add(onGUIApplicationLauncherReady);
GameEvents.onLevelWasLoadedGUIReady.Add(onLevelWasLoadedGUIReady);
}

void onGameSceneLoadRequested(GameScenes gs)
{
ClickThroughFix.Log.Info("SceneChangeCleanup.onGameSceneLoadRequested");
InputLockManager.ClearControlLocks();
StartCoroutine(CleanupInputLocks());
}

void onGUIApplicationLauncherReady()
{
ClickThroughFix.Log.Info("SceneChangeCleanup.onGUIApplicationLauncherReady");
StartCoroutine(CleanupInputLocks());
}

void onLevelWasLoadedGUIReady(GameScenes gs)
{
ClickThroughFix.Log.Info("SceneChangeCleanup.onLevelWasLoadedGUIReady");
StartCoroutine(CleanupInputLocks());
}



IEnumerator CleanupInputLocks()
{
yield return new WaitForSeconds(HighLogic.CurrentGame.Parameters.CustomParams<ClickThroughFix.CTB>().cleanupDelay);
InputLockManager.ClearControlLocks();
yield return null;
}
}
}
6 changes: 4 additions & 2 deletions ClickThroughBlocker/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,16 @@ public class CTB : GameParameters.CustomParameterNode
toolTip = "Clearing this will allow the pop-up window to be displayed at the next game start.\nSetting it after clearing will allow the popup-window to be shown at the next start of a different save")]
public bool showPopup = true;


[GameParameters.CustomFloatParameterUI("Cleanup delay", minValue = 0.1f, maxValue = 5f, displayFormat = "F2",
toolTip = "Time to wait after scene change before clearing all the input locks")]
public float cleanupDelay = 0.5f;

public override bool Enabled(MemberInfo member, GameParameters parameters) { return true; }

public override bool Interactible(MemberInfo member, GameParameters parameters)
{
if (showPopup)
OneTimePopup.RemovePopUpFlagFile();
ClearAllInputLocks.OneTimePopup.RemovePopUpFlagFile();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"MAJOR": 0,
"MINOR": 1,
"PATCH": 10,
"BUILD": 3
"BUILD": 5
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
17 changes: 15 additions & 2 deletions GameData/000_ClickThroughBlocker/changelog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ KERBALCHANGELOG
modName = Click Through Blocker //required
license = Lesser GPLv3
author = Linuxgurugamer


VERSION
{
version = 1.0.10.5
CHANGE
{
change = Cleanup Input Locks
type = update
subchange = Added cleanup class to cleanup all input locks after a delay, immediately upon changing scenes
subchange = Added cleanup delay to settings page
}
}

VERSION
{
version = 1.0.10.3
version = 1.0.10.4
CHANGE
{
change = Minimod Input Locks
Expand Down Expand Up @@ -52,6 +64,7 @@ KERBALCHANGELOG
subchange = Added Settings page
subchange = Added new setting to specify Focus follows Click
subchange = Added code to have the focus follow the click instead of the mouse, for both editor and flight modes
subchange = Added initial window to select mode, shows one time only
}
}
}
14 changes: 13 additions & 1 deletion changelog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,19 @@ KERBALCHANGELOG
modName = Click Through Blocker //required
license = Lesser GPLv3
author = Linuxgurugamer


VERSION
{
version = 1.0.10.5
CHANGE
{
change = Cleanup Input Locks
type = update
subchange = Added cleanup class to cleanup all input locks after a delay, immediately upon changing scenes
subchange = Added cleanup delay to settings page
}
}

VERSION
{
version = 1.0.10.4
Expand Down

0 comments on commit af957c7

Please sign in to comment.