Skip to content

Commit

Permalink
Fixed Popupshown.cfg from having endless repeats of the popupshown =…
Browse files Browse the repository at this point in the history
… true appended

 Fixed error which caused buildings to be non-clickable if clicking on a control in the window closed it (such as an X or a Close button)
 Made all members of Log class to be internal, to avoid conflicts with KSP_Log
  • Loading branch information
linuxgurugamer committed Jul 12, 2020
1 parent 42368c7 commit 1daf4b0
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 44 deletions.
5 changes: 5 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
ChangeLog

0.1.10.9
Fixed Popupshown.cfg from having endless repeats of the popupshown = true appended
Fixed error which caused buildings to be non-clickable if clicking on a control in the window closed it (such as an X or a Close button)
Made all members of Log class to be internal, to avoid conflicts with KSP_Log

0.1.10.6
Added missing files

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": 6
"BUILD": 9
},
"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.5")]
[assembly: AssemblyVersion("0.1.10.9")]
10 changes: 3 additions & 7 deletions ClickThroughBlocker/CBTGlobalMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,13 @@ void FixedUpdate()

if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
{
if (FocusLock.focusLockDict.Count > 0)
//Log.Info("CBTGlobalMonitor.FixedUpate, focusFollowsClick, count: " + ClickThruBlocker.focusLockDict.Count + ", timeTics: " + timeTics);
foreach (var w in FocusLock.focusLockDict)
{
// Log.Info("CBTGlobalMonitor.FixedUpate, lockName: " + w.Key + ", lastUpdated: " + w.Value.win.lastUpdated);
if (w.Value.win.lastUpdated < globalTimeTics - 4)
{
Log.Info("CBTGlobalMonitor.FixedUpate, FreeLock lockName: " + w.Key + ", lastUpdated: " + w.Value.win.lastUpdated);
FocusLock.FreeLock(w.Key,1);
w.Value.win.OnDestroy();
break;
FocusLock.FreeLock(w.Key, 1);
w.Value.win.OnDestroy();
break;
}
}
}
Expand Down
10 changes: 2 additions & 8 deletions ClickThroughBlocker/CBTMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#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);
DontDestroyOnLoad(this);
// GameEvents.onGameSceneLoadRequested.Add(onGameSceneLoadRequested);
ClickThruBlocker.CTBWin.activeBlockerCnt = 0;
}
Expand All @@ -28,8 +27,6 @@ void Update()
{
if (HighLogic.CurrentGame.Parameters.CustomParams<CTB>().focusFollowsclick)
return;

//if (HighLogic.LoadedSceneIsEditor )
{
if (ClickThruBlocker.CTBWin.activeBlockerCnt > 0)
{
Expand All @@ -38,7 +35,6 @@ void Update()

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

Expand Down Expand Up @@ -75,9 +71,7 @@ void LateUpdate()

d = 0;
ClickThruBlocker.CTBWin win = null;
//timeTics++;
{

foreach (var w in ClickThruBlocker.winList)
{
if (w.Value.lastUpdated + 4 < CBTGlobalMonitor.globalTimeTics) //+ 0.05 < Planetarium.GetUniversalTime())
Expand Down
5 changes: 4 additions & 1 deletion ClickThroughBlocker/ClearInputLocks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ void ClearInputLocksToggle()
internal static MonoBehaviour modeWindow = null;
void CallModeWindow()
{
ClickThroughFix.Log.Info("CallModeWindow, modeWindow: " + (modeWindow != null));
//ClickThroughFix.Log.Info("CallModeWindow, modeWindow: " + (modeWindow != null));
if (modeWindow == null)
modeWindow = gameObject.AddComponent<OneTimePopup>();
else
{
Destroy(modeWindow);
InputLockManager.ClearControlLocks();
}
}
}
}
4 changes: 2 additions & 2 deletions ClickThroughBlocker/ClickThroughBlocker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ internal void PreventInFlightClickthrough(Rect r)
{
if (mouseOverWindow)
{
Log.Info("PreventInFlightClickthrough, mouse clicked and over window, weLockedFlightInputs:" + weLockedFlightInputs + ", lockName: " + lockName);
//Log.Info("PreventInFlightClickthrough, mouse clicked and over window, weLockedFlightInputs:" + weLockedFlightInputs + ", lockName: " + lockName);
if (!weLockedFlightInputs && !Input.GetMouseButton(1) && lockName != null)
{
//InputLockManager.SetControlLock(ControlTypes.ALLBUTCAMERAS, lockName);
Expand All @@ -154,7 +154,7 @@ internal void PreventInFlightClickthrough(Rect r)
}
else
{
Log.Info("PreventInFlightClickthrough, mouse clicked and NOT over window, weLockedFlightInputs:" + weLockedFlightInputs + ", lockName: " + lockName);
//Log.Info("PreventInFlightClickthrough, mouse clicked and NOT over window, weLockedFlightInputs:" + weLockedFlightInputs + ", lockName: " + lockName);

if (weLockedFlightInputs && lockName != null)
{
Expand Down
3 changes: 0 additions & 3 deletions ClickThroughBlocker/FocusLock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ internal FocusLock(string lockName, ClickThruBlocker.CTBWin win)

internal static void SetLock(string lockName, ClickThruBlocker.CTBWin win, int i)
{
Log.Info("SetLock: " + lockName + ", i: " + i);

FocusLock focusLock;
if (HighLogic.LoadedSceneIsEditor)
EditorLogic.fetch.Lock(true, true, true, lockName);
Expand All @@ -39,7 +37,6 @@ internal static void SetLock(string lockName, ClickThruBlocker.CTBWin win, int i
internal static void FreeLock(string lockName, int i)
{
focusLockDict.Remove(lockName);
Log.Info("FreeLock: " + lockName + ", i: " + i);
// flight
if (!HighLogic.LoadedSceneIsEditor)
InputLockManager.RemoveControlLock(lockName);
Expand Down
28 changes: 14 additions & 14 deletions ClickThroughBlocker/Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace ClickThroughFix
{
internal static class Log
{
public enum LEVEL
internal enum LEVEL
{
OFF = 0,
ERROR = 1,
Expand All @@ -20,27 +20,27 @@ public enum LEVEL
};
static string PREFIX = "ClickThroughBlocker: ";

public static void setTitle(string t)
internal static void setTitle(string t)
{
PREFIX = t + ": ";
}

public static LEVEL level = LEVEL.INFO;
internal static LEVEL level = LEVEL.INFO;



public static LEVEL GetLevel()
internal static LEVEL GetLevel()
{
return level;
}

public static void SetLevel(LEVEL level)
internal static void SetLevel(LEVEL level)
{
UnityEngine.Debug.Log("log level " + level);
Log.level = level;
}

public static LEVEL GetLogLevel()
internal static LEVEL GetLogLevel()
{
return level;
}
Expand All @@ -50,20 +50,20 @@ private static bool IsLevel(LEVEL level)
return level == Log.level;
}

public static bool IsLogable(LEVEL level)
internal static bool IsLogable(LEVEL level)
{
return level <= Log.level;
}

public static void Trace(String msg)
internal static void Trace(String msg)
{
if (IsLogable(LEVEL.TRACE))
{
UnityEngine.Debug.Log(PREFIX + msg);
}
}

public static void Detail(String msg)
internal static void Detail(String msg)
{
if (IsLogable(LEVEL.DETAIL))
{
Expand All @@ -72,7 +72,7 @@ public static void Detail(String msg)
}

[ConditionalAttribute("DEBUG")]
public static void Info(String msg)
internal static void Info(String msg)
{

if (IsLogable(LEVEL.INFO))
Expand All @@ -82,7 +82,7 @@ public static void Info(String msg)
}

// [ConditionalAttribute("DEBUG")]
public static void Test(String msg)
internal static void Test(String msg)
{
//if (IsLogable(LEVEL.INFO))
{
Expand All @@ -91,23 +91,23 @@ public static void Test(String msg)
}


public static void Warning(String msg)
internal static void Warning(String msg)
{
if (IsLogable(LEVEL.WARNING))
{
UnityEngine.Debug.LogWarning(PREFIX + msg);
}
}

public static void Error(String msg)
internal static void Error(String msg)
{
if (IsLogable(LEVEL.ERROR))
{
UnityEngine.Debug.LogError(PREFIX + msg);
}
}

public static void Exception(Exception e)
internal static void Exception(Exception e)
{
Log.Error("exception caught: " + e.GetType() + ": " + e.Message);
}
Expand Down
14 changes: 12 additions & 2 deletions ClickThroughBlocker/OneTimePopup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using KSP.IO;
using UnityEngine;
using ClickThroughFix;


namespace ClearAllInputLocks
Expand Down Expand Up @@ -37,12 +38,20 @@ public void Start()
popupRect.y = (Screen.height - HEIGHT) / 2;

}
#if false
void OnDestroy()
{
InputLockManager.ClearControlLocks();
}
#endif

public void OnGUI()
{
if (visible)
{
GUI.skin = HighLogic.Skin;
popupRect = ClickThroughFix.ClickThruBlocker.GUILayoutWindow(847733455, popupRect, PopUpWindow, "Click Through Blocker Focus Setting");
//popupRect = GUILayout.Window(847733455, popupRect, PopUpWindow, "Click Through Blocker Focus Setting");
popupRect = ClickThruBlocker.GUILayoutWindow(84733455, popupRect, PopUpWindow, "Click Through Blocker Focus Setting");
}
}

Expand Down Expand Up @@ -102,7 +111,8 @@ void PopUpWindow(int id)

void CreatePopUpFlagFile()
{
System.IO.File.AppendAllText(POPUP_FILE_FLAG, "popupshown = true");
RemovePopUpFlagFile(); // remove first to avoid any overwriting
System.IO.File.WriteAllText(POPUP_FILE_FLAG, "popupshown = true");
}

public static void RemovePopUpFlagFile()
Expand Down
4 changes: 0 additions & 4 deletions ClickThroughBlocker/SceneChangeCleanup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ void onGameSceneLoadRequested(GameScenes gs)
if (!ongameSceneLoadRequestedCalled)
{
ongameSceneLoadRequestedCalled = true;
ClickThroughFix.Log.Info("SceneChangeCleanup.onGameSceneLoadRequested");
InputLockManager.ClearControlLocks();
}
}
Expand All @@ -38,7 +37,6 @@ void onGUIApplicationLauncherReady()
if (!onGUIApplicationLauncherReadyCalled)
{
onGUIApplicationLauncherReadyCalled = true;
ClickThroughFix.Log.Info("SceneChangeCleanup.onGUIApplicationLauncherReady");
if (!isRunning)
StartCoroutine("CleanupInputLocks");
}
Expand All @@ -47,11 +45,9 @@ void onGUIApplicationLauncherReady()
bool onLevelWasLoadedGUIReadycalled = false;
void onLevelWasLoadedGUIReady(GameScenes gs)
{
Log.Info("onLevelWasLoadedGUIReady");
if (!onLevelWasLoadedGUIReadycalled)
{
onLevelWasLoadedGUIReadycalled = true;
ClickThroughFix.Log.Info("SceneChangeCleanup.onLevelWasLoadedGUIReady");
if (!isRunning)
StartCoroutine("CleanupInputLocks");
}
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": 5
"BUILD": 9
},
"KSP_VERSION_MIN": {
"MAJOR": 1,
Expand Down
31 changes: 31 additions & 0 deletions GameData/000_ClickThroughBlocker/changelog.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,38 @@ KERBALCHANGELOG
license = Lesser GPLv3
author = Linuxgurugamer

VERSION
{
version = 0.1.10.8
CHANGE
{
change = Fixed buildings being non-clickable after selecting FocusFollowsMouse
type = update
}
}

VERSION
{
version = 1.0.10.7
CHANGE
{
change = Internal cleanup
type = update
subchange = Made all members of Log class to be internal, to avoid conflicts with KSP_Log
}
}

VERSION
{
version = 1.0.10.6
CHANGE
{
change = Added missing files
type = update
}
}

VERSION
{
version = 1.0.10.5
CHANGE
Expand Down
Loading

0 comments on commit 1daf4b0

Please sign in to comment.