Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions PAPIPlugin/Impl/DefaultLightArrayManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,15 @@ namespace PAPIPlugin.Impl
{
public class DefaultLightArrayManager : ILightArrayManager
{
private readonly Icon<DefaultLightArrayManager> _groupWindowIcon;
private ApplicationLauncherButton _appButtonStock;

private GroupWindow<ILightArrayConfig> _groupWindow;

private ILightArrayConfig _lightConfig;

public DefaultLightArrayManager()
{
_groupWindowIcon = new Icon<DefaultLightArrayManager>(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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
Binary file added assets/GameData/PAPIPlugin/icon_button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.