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 0000000..528b5a2 Binary files /dev/null and b/assets/GameData/PAPIPlugin/icon_button.png differ