Skip to content

Commit

Permalink
Fixed inputlocks not being cleared when canceling the window
Browse files Browse the repository at this point in the history
 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
  • Loading branch information
linuxgurugamer committed Oct 7, 2020
1 parent 0d6f96d commit bf690f9
Show file tree
Hide file tree
Showing 22 changed files with 232 additions and 52 deletions.
9 changes: 7 additions & 2 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
ChangeLog

0.1.10.13 (unreleased)
Fixed inputlogs not being cleared when canceling the window
0.1.10.13
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

0.1.10.12
Fixed inputlocks not being cleared when setting FocusFollowsMouse
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": 12
"BUILD": 13
},
"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.11")]
[assembly: AssemblyVersion("0.1.10.12")]
2 changes: 1 addition & 1 deletion ClickThroughBlocker/CBTGlobalMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void FixedUpdate()
{
globalTimeTics++;

if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
if (ClearInputLocks.focusFollowsclick)
{
foreach (var w in FocusLock.focusLockDict)
{
Expand Down
15 changes: 7 additions & 8 deletions ClickThroughBlocker/CBTMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
#if !DUMMY
namespace ClickThroughFix
{
//[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
class CBTMonitor : MonoBehaviour
{
void Start()
{
//DontDestroyOnLoad(this);
// GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
DontDestroyOnLoad(this);
GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
ClickThruBlocker.CTBWin.activeBlockerCnt = 0;
}

Expand All @@ -26,10 +25,10 @@ void onGameSceneLoadRequested(GameScenes gs)
// the mouse moved over a protected window
void Update()
{
if (HighLogic.CurrentGame == null ||
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
if (HighLogic.LoadedSceneIsEditor && ClearInputLocks.focusFollowsclick) // ||
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
return;

{
if (ClickThruBlocker.CTBWin.activeBlockerCnt > 0)
{
Expand Down Expand Up @@ -69,8 +68,8 @@ void Update()
int d;
void LateUpdate()
{
if (HighLogic.CurrentGame == null ||
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
if (HighLogic.CurrentGame == null ||
ClearInputLocks.focusFollowsclick) // ||
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
return;

Expand Down
97 changes: 97 additions & 0 deletions ClickThroughBlocker/CBTMonitor.cs.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using UnityEngine;
using KSP.UI.Screens;

#if !DUMMY
namespace ClickThroughFix
{
//[KSPAddon(KSPAddon.Startup.SpaceCentre, true)]
[KSPAddon(KSPAddon.Startup.EditorAny, false)]
class CBTMonitor : MonoBehaviour
{
void Start()
{
//DontDestroyOnLoad(this);
// GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
ClickThruBlocker.CTBWin.activeBlockerCnt = 0;
}

void onGameSceneLoadRequested(GameScenes gs)
{
ClickThruBlocker.CTBWin.activeBlockerCnt = 0;
}

// this whole mess below is to work around a stock bug.
// The bug is that the editor ignores the lock when the Action Group pane is show.
// So we have to each time, clear all locks and then reset those which were active when
// the mouse moved over a protected window
void Update()
{
if (HighLogic.CurrentGame == null ||
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
return;
{
if (ClickThruBlocker.CTBWin.activeBlockerCnt > 0)
{
//Log.Info("Setting Mouse.HoveredPart to null & deselecting all parts");
Mouse.HoveredPart = null;

if (EditorLogic.fetch == null)
{
return;
}

for (int i = EditorLogic.fetch.ship.Parts.Count - 1; i >= 0; i--)
//for (int i = 0; i < EditorLogic.fetch.ship.Parts.Count; i++)
{
EditorActionPartSelector selector = EditorLogic.fetch.ship.Parts[i].GetComponent<EditorActionPartSelector>();
if (selector != null)
selector.Deselect();
}

if (EditorActionGroups.Instance != null)
{
EditorActionGroups.Instance.ClearSelection(true);
for (int i = ClickThruBlocker.CTBWin.selectedParts.Count - 1; i >= 0; i--)
//for (int i = 0; i < ClickThruBlocker.CTBWin.selectedParts.Count; i++)
{
EditorActionPartSelector selector = ClickThruBlocker.CTBWin.selectedParts[i].GetComponent<EditorActionPartSelector>();
if (selector != null)
EditorActionGroups.Instance.AddToSelection(selector);
}
}
}

}
}

//static internal long timeTics = 0;
int d;
void LateUpdate()
{
if (HighLogic.CurrentGame == null ||
HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick) // ||
//(!HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick && !HighLogic.LoadedSceneIsEditor))
return;

d = 0;
ClickThruBlocker.CTBWin win = null;
{
foreach (var w in ClickThruBlocker.winList)
{
if (w.Value.lastUpdated + 4 < CBTGlobalMonitor.globalTimeTics) //+ 0.05 < Planetarium.GetUniversalTime())
{
d = w.Key;
win = w.Value;
break;
}
}
if (d != 0)
{
win.OnDestroy();
}
}
}
}
}
#endif
49 changes: 41 additions & 8 deletions ClickThroughBlocker/ClearInputLocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,23 @@
using KSP.IO;
using UnityEngine;

namespace ClearAllInputLocks
namespace ClickThroughFix
{
[KSPAddon(KSPAddon.Startup.AllGameScenes, false)]
public class ClearInputLocks : MonoBehaviour
{
internal const string MODID = "ClearInputLocks_ns";
internal const string MODNAME = "Clear Input Locks";
internal const string MODID = "CTB_ClearInputLocks_ns";
internal const string MODID2 = "CTB_Toggle_ns";
internal const string MODNAME = "ClickThroughBlocker: Clear Input Locks";
internal const string MODNAME2 = "ClickThroughBlocker: Toggle Mode";
static internal ToolbarControl toolbarControl = null;
static internal ToolbarControl clickThroughToggleControl = null;
static internal bool focusFollowsclick = false;

const string FFC_38 = "000_ClickThroughBlocker/PluginData/FFC-38";
const string FFM_38 = "000_ClickThroughBlocker/PluginData/FFM-38";
const string FFC_24 = "000_ClickThroughBlocker/PluginData/FFC-24";
const string FFM_24 = "000_ClickThroughBlocker/PluginData/FFM-24";


void Start()
Expand All @@ -26,10 +35,6 @@ 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 |
Expand All @@ -42,9 +47,28 @@ void AddToolbarButton()
"ClearInputLocks",
"000_ClickThroughBlocker/PluginData/lock-38",
"000_ClickThroughBlocker/PluginData/lock-24",
"Clear all input locks"
MODNAME
);
toolbarControl.AddLeftRightClickCallbacks(ClearInputLocksToggle, CallModeWindow);



clickThroughToggleControl = gameObject.AddComponent<ToolbarControl>();
clickThroughToggleControl.AddToAllToolbars(ToggleFocusSetting, ToggleFocusSetting,
ApplicationLauncher.AppScenes.SPACECENTER |
ApplicationLauncher.AppScenes.FLIGHT |
ApplicationLauncher.AppScenes.MAPVIEW |
ApplicationLauncher.AppScenes.VAB |
ApplicationLauncher.AppScenes.SPH |
ApplicationLauncher.AppScenes.TRACKSTATION,
MODID2,
"CTBToggle",
FFC_38,
FFM_38,
FFC_24,
FFM_24,
MODNAME2
);
}
}

Expand All @@ -56,6 +80,15 @@ void OnDestroy()
Destroy(toolbarControl);
}
}

static internal void ToggleFocusSetting()
{
focusFollowsclick = !focusFollowsclick;
if (focusFollowsclick)
clickThroughToggleControl.SetTexture(FFC_38, FFC_24);
else
clickThroughToggleControl.SetTexture(FFM_38, FFM_24);
}
static internal void ClearInputLocksToggle()
{
InputLockManager.ClearControlLocks();
Expand Down
4 changes: 2 additions & 2 deletions ClickThroughBlocker/ClickThroughBlocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal void PreventEditorClickthrough(Rect r)
//Log.Info("ClickThruBlocker: PreventEditorClickthrough");
bool mouseOverWindow = MouseIsOverWindow(r);
//Log.Info("PreventEditorClickthrough, mouseOverWindow: " + mouseOverWindow);
if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
if (ClearInputLocks.focusFollowsclick)
{
bool mouseClicked = Input.GetMouseButton(0) || Input.GetMouseButton(1);
if (mouseClicked)
Expand Down Expand Up @@ -137,7 +137,7 @@ internal void PreventInFlightClickthrough(Rect r)
//
// This section for the Click to Focus option
//
if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
if (ClearInputLocks.focusFollowsclick)
{
bool mouseClicked = Input.GetMouseButton(0) || Input.GetMouseButton(1);
if (mouseClicked)
Expand Down
2 changes: 1 addition & 1 deletion ClickThroughBlocker/OnGUILoopCount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ private void Start()
long lastonGuiCnt;
private void DoGuiCounter()
{
if (HighLogic.CurrentGame == null || HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
if (HighLogic.CurrentGame == null || ClearInputLocks.focusFollowsclick)
return;

lastonGuiCnt = (onguiCnt++) - 1;
Expand Down
Loading

0 comments on commit bf690f9

Please sign in to comment.