From 40021547e4345b3fd54647dd22b9abe6898e414c Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Sun, 24 Aug 2014 16:51:09 +0400 Subject: [PATCH] Use the new stock app launcher toolbar instead of a standalone button. --- PAPIPlugin/Impl/DefaultLightArrayManager.cs | 32 +++++++++++++++++--- assets/GameData/PAPIPlugin/icon_button.png | Bin 0 -> 530 bytes 2 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 assets/GameData/PAPIPlugin/icon_button.png diff --git a/PAPIPlugin/Impl/DefaultLightArrayManager.cs b/PAPIPlugin/Impl/DefaultLightArrayManager.cs index fdc6d47..d88fc80 100644 --- a/PAPIPlugin/Impl/DefaultLightArrayManager.cs +++ b/PAPIPlugin/Impl/DefaultLightArrayManager.cs @@ -15,7 +15,7 @@ namespace PAPIPlugin.Impl { public class DefaultLightArrayManager : ILightArrayManager { - private readonly Icon _groupWindowIcon; + private ApplicationLauncherButton _appButtonStock; private GroupWindow _groupWindow; @@ -23,9 +23,7 @@ public class DefaultLightArrayManager : ILightArrayManager public DefaultLightArrayManager() { - _groupWindowIcon = new Icon(new Rect(Screen.width * 0.8f, 0.0f, 80.0f, 20.0f), "icon.png", "Light groups", - "Opens the light group overview", OnIconClickHandler); - _groupWindowIcon.SetVisible(true); + GameEvents.onGUIApplicationLauncherReady.Add(OnGUIAppLauncherReady); } #region ILightArrayManager Members @@ -82,6 +80,25 @@ public void Dispose() #endregion + private void OnGUIAppLauncherReady() + { + if (ApplicationLauncher.Ready) + { + _appButtonStock = ApplicationLauncher.Instance.AddModApplication( + OnIconClickHandler, + OnIconClickHandler, + DummyVoid, + DummyVoid, + DummyVoid, + DummyVoid, + ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.SPACECENTER, + (Texture)GameDatabase.Instance.GetTexture("PAPIPlugin/icon_button", false) + ); + } + } + + private void DummyVoid() { } + private void OnIconClickHandler() { if (_groupWindow == null) @@ -93,6 +110,9 @@ private void OnIconClickHandler() { _groupWindow.ToggleVisible(); } + + // Don't lock highlight on the button since it's just a toggle + _appButtonStock.SetFalse(false); } private void InitializeConfig(ILightArrayConfig lightConfig) @@ -121,7 +141,9 @@ protected virtual void Dispose(bool disposing) { LightConfig.Destroy(); - _groupWindowIcon.SetVisible(false); + GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIAppLauncherReady); + if (_appButtonStock != null) + ApplicationLauncher.Instance.RemoveModApplication(_appButtonStock); if (_groupWindow != null) { diff --git a/assets/GameData/PAPIPlugin/icon_button.png b/assets/GameData/PAPIPlugin/icon_button.png new file mode 100644 index 0000000000000000000000000000000000000000..528b5a2550397bd0d103b900b8fd3a65d550f746 GIT binary patch literal 530 zcmV+t0`2{YP)VGd000McNliru-Ut{7G!JCET#x_&0iQ`k zK~z}7?Uu1h9YGX^zl|0`K$Q3p!L&kPxdaS$<^hB>@d;9dJVttB9>7K`v9K3HsuZFL zX-rb23u-_Gi+mQ&g~`3M%j^p4CF~Ce?#%z+Ge4X&bGA^KBs^fk&>Q-13=KliIj_c1 zdW-WAcFdC!mx;Y5dR&;|1mUB|0WI_#(5@Rg&cmMPVOx`01BW? zXiDHBldnP!e=vH>>YBD}z^9PIk2Q7GO(;9$DJrJ@ASz|2e9?b?v@m28SHKbQI-#8f z&VW;3u4SIF@=RA49bVBHU6CSQZ^=;Uj zQcu){NVlMV4_t1ZMkO2KNp!wa^OZ^hqOPB%p1MCJ(do(QBXLY59Uk;kqCF_T4Z>Tra8@g}Y0L!xF UKM+Q|nE(I)07*qoM6N<$f-R@tPXGV_ literal 0 HcmV?d00001