Created
July 24, 2014 01:26
-
-
Save ragzilla/3e3e10e65a67583a6ad7 to your computer and use it in GitHub Desktop.
DockingPortAlignmentIndicator Stock AppLauncher Patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/DockingPortAlignment.cs b/DockingPortAlignment.cs | |
index e9aaa0d..f4a35b6 100644 | |
--- a/DockingPortAlignment.cs | |
+++ b/DockingPortAlignment.cs | |
@@ -120,7 +120,8 @@ public class DockingPortAlignment : MonoBehaviour | |
private static bool toolbarAvailable = false; | |
private static IButton toolbarButton; | |
- private static CustomButton customButton; | |
+ private static ApplicationLauncherButton stockButton; | |
+ // private static CustomButton customButton; | |
//static List<ModuleDockingNode> dockingModulesList = new List<ModuleDockingNode>(); | |
@@ -183,10 +184,7 @@ public void Awake() | |
{ | |
indicatorIsHidden = false; | |
toolbarAvailable = false; | |
- Byte[] arrBytes = KSP.IO.File.ReadAllBytes<DockingPortAlignment>("toolbarIcon.png", null); | |
- customToolbarIcon = new Texture2D(24, 24, TextureFormat.ARGB32, false); | |
- customToolbarIcon.LoadImage(arrBytes); | |
- customButton = new CustomButton(); | |
+ GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady); // add button in AppLauncherReady | |
} | |
if (!hasInitializedStyles) initStyles(); | |
@@ -227,7 +225,7 @@ public void Update() | |
{ | |
toolbarButton.Enabled = true; | |
} else { | |
- customButton.Enabled = true; | |
+ stockButton.Enable(true); | |
} | |
} | |
else | |
@@ -238,7 +236,7 @@ public void Update() | |
} | |
else | |
{ | |
- customButton.Enabled = false; | |
+ stockButton.Disable(false); | |
} | |
} | |
@@ -251,6 +249,42 @@ public void Update() | |
//print("Update: End"); | |
} | |
+ public void OnGUIAppLauncherReady() | |
+ { | |
+ if (ApplicationLauncher.Ready && HighLogic.LoadedSceneIsFlight && stockButton == null) | |
+ { | |
+ stockButton = ApplicationLauncher.Instance.AddModApplication( | |
+ onAppLaunchToggle, // on | |
+ onAppLaunchToggle, // off | |
+ DummyVoid, | |
+ DummyVoid, | |
+ DummyVoid, | |
+ DummyVoid, | |
+ ApplicationLauncher.AppScenes.FLIGHT, | |
+ (Texture)GameDatabase.Instance.GetTexture("NavyFish/Plugins/ToolbarIcons/toolbarIcon", false)); | |
+ stockButton.Disable(); | |
+ GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady); | |
+ GameEvents.onGameSceneLoadRequested.Add(OnGameSceneLoadRequested); | |
+ } | |
+ } | |
+ | |
+ public void OnGameSceneLoadRequested(GameScenes scene) | |
+ { | |
+ if (stockButton != null) | |
+ { | |
+ ApplicationLauncher.Instance.RemoveModApplication(stockButton); | |
+ GameEvents.onGameSceneLoadRequested.Remove(OnGameSceneLoadRequested); | |
+ GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady); | |
+ } | |
+ } | |
+ | |
+ public void onAppLaunchToggle() | |
+ { | |
+ indicatorIsHidden = !indicatorIsHidden; | |
+ } | |
+ | |
+ public void DummyVoid() { } | |
+ | |
private static void determineTargetPort() | |
{ | |
if (portWasCycled) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment