Skip to content

Commit

Permalink
Part highlighting is available again.
Browse files Browse the repository at this point in the history
Blizzy’s toolbar support.
Hiding UI when F2 is pressed.
  • Loading branch information
formicant committed Sep 17, 2016
1 parent 89eb8b3 commit d323617
Show file tree
Hide file tree
Showing 20 changed files with 1,365 additions and 194 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"MAJOR": 1,
"MINOR": 1,
"PATCH": 3,
"BUILD": 3
"BUILD": 4
},
"KSP_VERSION":
{
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
131 changes: 131 additions & 0 deletions src/CriticalTemperatureGauge/AppLauncher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using System.Linq;
using KSP.UI.Screens;
using UnityEngine;

namespace CriticalTemperatureGauge
{
/// <summary>
/// Class that adds the AppLauncher button.
/// </summary>
[KSPAddon(KSPAddon.Startup.Flight, false)]
public class AppLauncher : MonoBehaviour
{
// Resources
static readonly Texture2D AppLauncherButtonTexture =
GameDatabase.Instance.GetTexture(Static.TexturePath + "AppLauncherButton", false);

ApplicationLauncherButton _appLauncherButton;
readonly SettingsWindow _settingsWindow = new SettingsWindow();

public void Update()
{
if(_appLauncherButton != null)
_appLauncherButton.VisibleInScenes = Static.Settings.ShowAppLauncherButton
? ApplicationLauncher.AppScenes.FLIGHT | ApplicationLauncher.AppScenes.MAPVIEW
: ApplicationLauncher.AppScenes.NEVER;
}

public bool ButtonState
{
get
{
return _settingsWindow.IsLogicallyVisible;
}
set
{
if(value)
_appLauncherButton?.SetTrue();
else
_appLauncherButton?.SetFalse();
}
}

// KSP events:

public void Start()
{
OnGUIApplicationLauncherReady();
Static.AppLauncher = this;
}

public void Awake()
{
GameEvents.onGUIApplicationLauncherReady.Add(OnGUIApplicationLauncherReady);
GameEvents.onGameSceneLoadRequested.Add(OnSceneChangeRequest);
GameEvents.onShowUI.Add(OnShowUI);
GameEvents.onHideUI.Add(OnHideUI);
}

internal void OnDestroy()
{
GameEvents.onGUIApplicationLauncherReady.Remove(OnGUIApplicationLauncherReady);
GameEvents.onGameSceneLoadRequested.Remove(OnSceneChangeRequest);
GameEvents.onShowUI.Remove(OnShowUI);
GameEvents.onHideUI.Remove(OnHideUI);
RemoveAppLauncherButton();
Static.AppLauncher = null;
}

public void OnGUI()
{
_settingsWindow.DrawGUI();
}

void OnGUIApplicationLauncherReady()
{
AddAppLauncherButton();
}

void OnSceneChangeRequest(GameScenes scene)
{
RemoveAppLauncherButton();
}

void OnShowUI()
{
_settingsWindow.CanShow = true;
}

void OnHideUI()
{
_settingsWindow.CanShow = false;
}

/// <summary>Shows the settings window when the button is pressed.</summary>
void OnButtonOn()
{
_settingsWindow.Show();
}

/// <summary>Hides the settings window when the button is pressed again.</summary>
void OnButtonOff()
{
_settingsWindow.Hide();
}

/// <summary>Adds the button to the appLauncher.</summary>
void AddAppLauncherButton()
{
if(_appLauncherButton == null)
_appLauncherButton = ApplicationLauncher.Instance.AddModApplication(
onTrue: OnButtonOn,
onFalse: OnButtonOff,
onHover: null,
onHoverOut: null,
onEnable: null,
onDisable: null,
visibleInScenes: ApplicationLauncher.AppScenes.NEVER,
texture: AppLauncherButtonTexture);
Update();
}

/// <summary>Removes the button from the appLauncher.</summary>
void RemoveAppLauncherButton()
{
if(_appLauncherButton != null)
ApplicationLauncher.Instance.RemoveModApplication(_appLauncherButton);
}
}
}
34 changes: 34 additions & 0 deletions src/CriticalTemperatureGauge/BlizzysToolbar.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;

namespace CriticalTemperatureGauge
{
public class BlizzysToolbar
{
const string ButtonId = "Settings";
const string ButtonTexturePath = Static.TexturePath + "BizzysToolbarButton";

IButton _toolbarButton;

public void Start()
{
if(ToolbarManager.ToolbarAvailable)
{
_toolbarButton = ToolbarManager.Instance.add(nameof(CriticalTemperatureGauge), nameof(CriticalTemperatureGauge) + ButtonId);
_toolbarButton.TexturePath = ButtonTexturePath;
_toolbarButton.ToolTip = Static.PluginTitle;
_toolbarButton.OnClick += e =>
{
if(Static.AppLauncher != null && e.MouseButton == 0 /* Left mouse button */)
Static.AppLauncher.ButtonState = !Static.AppLauncher.ButtonState;
};
}
}

public void Destroy()
{
_toolbarButton?.Destroy();
}
}
}
Loading

0 comments on commit d323617

Please sign in to comment.