diff --git a/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.dll b/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.dll
index 0f74c7c..4d0f6c3 100644
Binary files a/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.dll and b/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.dll differ
diff --git a/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.version b/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.version
index 7c1e701..b017916 100644
--- a/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.version
+++ b/GameData/CriticalTemperatureGauge/Plugins/CriticalTemperatureGauge.version
@@ -13,7 +13,7 @@
"MAJOR": 1,
"MINOR": 1,
"PATCH": 3,
- "BUILD": 3
+ "BUILD": 4
},
"KSP_VERSION":
{
diff --git a/GameData/CriticalTemperatureGauge/Textures/AppLauncherButton.png b/GameData/CriticalTemperatureGauge/Textures/AppLauncherButton.png
new file mode 100644
index 0000000..b5258a0
Binary files /dev/null and b/GameData/CriticalTemperatureGauge/Textures/AppLauncherButton.png differ
diff --git a/GameData/CriticalTemperatureGauge/Textures/BizzysToolbarButton.png b/GameData/CriticalTemperatureGauge/Textures/BizzysToolbarButton.png
new file mode 100644
index 0000000..adbdea1
Binary files /dev/null and b/GameData/CriticalTemperatureGauge/Textures/BizzysToolbarButton.png differ
diff --git a/GameData/CriticalTemperatureGauge/Textures/ToolbarButton.png b/GameData/CriticalTemperatureGauge/Textures/ToolbarButton.png
deleted file mode 100644
index 6129240..0000000
Binary files a/GameData/CriticalTemperatureGauge/Textures/ToolbarButton.png and /dev/null differ
diff --git a/src/CriticalTemperatureGauge/AppLauncher.cs b/src/CriticalTemperatureGauge/AppLauncher.cs
new file mode 100644
index 0000000..833eaf7
--- /dev/null
+++ b/src/CriticalTemperatureGauge/AppLauncher.cs
@@ -0,0 +1,131 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using KSP.UI.Screens;
+using UnityEngine;
+
+namespace CriticalTemperatureGauge
+{
+ ///
+ /// Class that adds the AppLauncher button.
+ ///
+ [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;
+ }
+
+ /// Shows the settings window when the button is pressed.
+ void OnButtonOn()
+ {
+ _settingsWindow.Show();
+ }
+
+ /// Hides the settings window when the button is pressed again.
+ void OnButtonOff()
+ {
+ _settingsWindow.Hide();
+ }
+
+ /// Adds the button to the appLauncher.
+ 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();
+ }
+
+ /// Removes the button from the appLauncher.
+ void RemoveAppLauncherButton()
+ {
+ if(_appLauncherButton != null)
+ ApplicationLauncher.Instance.RemoveModApplication(_appLauncherButton);
+ }
+ }
+}
diff --git a/src/CriticalTemperatureGauge/BlizzysToolbar.cs b/src/CriticalTemperatureGauge/BlizzysToolbar.cs
new file mode 100644
index 0000000..5d756e3
--- /dev/null
+++ b/src/CriticalTemperatureGauge/BlizzysToolbar.cs
@@ -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();
+ }
+ }
+}
diff --git a/src/CriticalTemperatureGauge/BlizzysToolbarWrapper.cs b/src/CriticalTemperatureGauge/BlizzysToolbarWrapper.cs
new file mode 100644
index 0000000..0e8ac9e
--- /dev/null
+++ b/src/CriticalTemperatureGauge/BlizzysToolbarWrapper.cs
@@ -0,0 +1,893 @@
+/*
+Copyright (c) 2013-2016, Maik Schreiber
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using UnityEngine;
+
+
+// TODO: Change to your plugin's namespace here.
+namespace CriticalTemperatureGauge
+{
+
+
+
+ /**********************************************************\
+ * --- DO NOT EDIT BELOW THIS COMMENT --- *
+ * *
+ * This file contains classes and interfaces to use the *
+ * Toolbar Plugin without creating a hard dependency on it. *
+ * *
+ * There is nothing in this file that needs to be edited *
+ * by hand. *
+ * *
+ * --- DO NOT EDIT BELOW THIS COMMENT --- *
+ \**********************************************************/
+
+
+
+ ///
+ /// The global tool bar manager.
+ ///
+ public partial class ToolbarManager : IToolbarManager
+ {
+ ///
+ /// Whether the Toolbar Plugin is available.
+ ///
+ public static bool ToolbarAvailable
+ {
+ get
+ {
+ if(toolbarAvailable == null)
+ {
+ toolbarAvailable = Instance != null;
+ }
+ return (bool)toolbarAvailable;
+ }
+ }
+
+ ///
+ /// The global tool bar manager instance.
+ ///
+ public static IToolbarManager Instance
+ {
+ get
+ {
+ if((toolbarAvailable != false) && (instance_ == null))
+ {
+ Type type = ToolbarTypes.getType("Toolbar.ToolbarManager");
+ if(type != null)
+ {
+ object realToolbarManager = ToolbarTypes.getStaticProperty(type, "Instance").GetValue(null, null);
+ instance_ = new ToolbarManager(realToolbarManager);
+ }
+ }
+ return instance_;
+ }
+ }
+ }
+
+ #region interfaces
+
+ ///
+ /// A toolbar manager.
+ ///
+ public interface IToolbarManager
+ {
+ ///
+ /// Adds a new button.
+ ///
+ ///
+ /// To replace an existing button, just add a new button using the old button's namespace and ID.
+ /// Note that the new button will inherit the screen position of the old button.
+ ///
+ /// The new button's namespace. This is usually the plugin's name. Must not include special characters like '.'
+ /// The new button's ID. This ID must be unique across all buttons in the namespace. Must not include special characters like '.'
+ /// The button created.
+ IButton add(string ns, string id);
+ }
+
+ ///
+ /// Represents a clickable button.
+ ///
+ public interface IButton
+ {
+ ///
+ /// The text displayed on the button. Set to null to hide text.
+ ///
+ ///
+ /// The text can be changed at any time to modify the button's appearance. Note that since this will also
+ /// modify the button's size, this feature should be used sparingly, if at all.
+ ///
+ ///
+ string Text
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// The color the button text is displayed with. Defaults to Color.white.
+ ///
+ ///
+ /// The text color can be changed at any time to modify the button's appearance.
+ ///
+ Color TextColor
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// The path of a texture file to display an icon on the button. Set to null to hide icon.
+ ///
+ ///
+ ///
+ /// A texture path on a button will have precedence over text. That is, if both text and texture path
+ /// have been set on a button, the button will show the texture, not the text.
+ ///
+ ///
+ /// The texture size must not exceed 24x24 pixels.
+ ///
+ ///
+ /// The texture path must be relative to the "GameData" directory, and must not specify a file name suffix.
+ /// Valid example: MyAddon/Textures/icon_mybutton
+ ///
+ ///
+ /// The texture path can be changed at any time to modify the button's appearance.
+ ///
+ ///
+ ///
+ string TexturePath
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// The button's tool tip text. Set to null if no tool tip is desired.
+ ///
+ ///
+ /// Tool Tip Text Should Always Use Headline Style Like This.
+ ///
+ string ToolTip
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// Whether this button is currently visible or not. Can be used in addition to or as a replacement for .
+ ///
+ ///
+ /// Setting this property to true does not affect the player's ability to hide the button using the configuration.
+ /// Conversely, setting this property to false does not enable the player to show the button using the configuration.
+ ///
+ bool Visible
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// Determines this button's visibility. Can be used in addition to or as a replacement for .
+ ///
+ ///
+ /// The return value from IVisibility.Visible is subject to the same rules as outlined for
+ /// .
+ ///
+ IVisibility Visibility
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// Whether this button is currently effectively visible or not. This is a combination of
+ /// and .
+ ///
+ ///
+ /// Note that the toolbar is not visible in certain game scenes, for example the loading screens. This property
+ /// does not reflect button invisibility in those scenes. In addition, this property does not reflect the
+ /// player's configuration of the button's visibility.
+ ///
+ bool EffectivelyVisible
+ {
+ get;
+ }
+
+ ///
+ /// Whether this button is currently enabled (clickable) or not. This does not affect the player's ability to
+ /// position the button on their toolbar.
+ ///
+ bool Enabled
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// Whether this button is currently "important." Set to false to return to normal button behaviour.
+ ///
+ ///
+ ///
+ /// This can be used to temporarily force the button to be shown on screen regardless of the toolbar being
+ /// currently in auto-hidden mode. For example, a button that signals the arrival of a private message in
+ /// a chat room could mark itself as "important" as long as the message has not been read.
+ ///
+ ///
+ /// Setting this property does not change the appearance of the button. Use to
+ /// change the button's icon.
+ ///
+ ///
+ /// Setting this property to true does not affect the player's ability to hide the button using the
+ /// configuration.
+ ///
+ ///
+ /// This feature should be used only sparingly, if at all, since it forces the button to be displayed on
+ /// screen even when it normally wouldn't.
+ ///
+ ///
+ bool Important
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// A drawable that is tied to the current button. This can be anything from a popup menu to
+ /// an informational window. Set to null to hide the drawable.
+ ///
+ IDrawable Drawable
+ {
+ set;
+ get;
+ }
+
+ ///
+ /// Event handler that can be registered with to receive "on click" events.
+ ///
+ ///
+ ///
+ /// IButton button = ...
+ /// button.OnClick += (e) => {
+ /// Debug.Log("button clicked, mouseButton: " + e.MouseButton);
+ /// };
+ ///
+ ///
+ event ClickHandler OnClick;
+
+ ///
+ /// Event handler that can be registered with to receive "on mouse enter" events.
+ ///
+ ///
+ ///
+ /// IButton button = ...
+ /// button.OnMouseEnter += (e) => {
+ /// Debug.Log("mouse entered button");
+ /// };
+ ///
+ ///
+ event MouseEnterHandler OnMouseEnter;
+
+ ///
+ /// Event handler that can be registered with to receive "on mouse leave" events.
+ ///
+ ///
+ ///
+ /// IButton button = ...
+ /// button.OnMouseLeave += (e) => {
+ /// Debug.Log("mouse left button");
+ /// };
+ ///
+ ///
+ event MouseLeaveHandler OnMouseLeave;
+
+ ///
+ /// Permanently destroys this button so that it is no longer displayed.
+ /// Should be used when a plugin is stopped to remove leftover buttons.
+ ///
+ void Destroy();
+ }
+
+ ///
+ /// A drawable that is tied to a particular button. This can be anything from a popup menu
+ /// to an informational window.
+ ///
+ public interface IDrawable
+ {
+ ///
+ /// Update any information. This is called once per frame.
+ ///
+ void Update();
+
+ ///
+ /// Draws GUI widgets for this drawable. This is the equivalent to the OnGUI() message in
+ /// .
+ ///
+ ///
+ /// The drawable will be positioned near its parent toolbar according to the drawable's current
+ /// width/height.
+ ///
+ /// The left/top position of where to draw this drawable.
+ /// The current width/height of this drawable.
+ Vector2 Draw(Vector2 position);
+ }
+
+ #endregion
+
+ #region events
+
+ ///
+ /// Event describing a click on a button.
+ ///
+ public partial class ClickEvent : EventArgs
+ {
+ ///
+ /// The button that has been clicked.
+ ///
+ public readonly IButton Button;
+
+ ///
+ /// The mouse button which the button was clicked with.
+ ///
+ ///
+ /// Is 0 for left mouse button, 1 for right mouse button, and 2 for middle mouse button.
+ ///
+ public readonly int MouseButton;
+ }
+
+ ///
+ /// An event handler that is invoked whenever a button has been clicked.
+ ///
+ /// An event describing the button click.
+ public delegate void ClickHandler(ClickEvent e);
+
+ ///
+ /// Event describing the mouse pointer moving about a button.
+ ///
+ public abstract partial class MouseMoveEvent
+ {
+ ///
+ /// The button in question.
+ ///
+ public readonly IButton button;
+ }
+
+ ///
+ /// Event describing the mouse pointer entering a button's area.
+ ///
+ public partial class MouseEnterEvent : MouseMoveEvent
+ {
+ }
+
+ ///
+ /// Event describing the mouse pointer leaving a button's area.
+ ///
+ public partial class MouseLeaveEvent : MouseMoveEvent
+ {
+ }
+
+ ///
+ /// An event handler that is invoked whenever the mouse pointer enters a button's area.
+ ///
+ /// An event describing the mouse pointer entering.
+ public delegate void MouseEnterHandler(MouseEnterEvent e);
+
+ ///
+ /// An event handler that is invoked whenever the mouse pointer leaves a button's area.
+ ///
+ /// An event describing the mouse pointer leaving.
+ public delegate void MouseLeaveHandler(MouseLeaveEvent e);
+
+ #endregion
+
+ #region visibility
+
+ ///
+ /// Determines visibility of a button.
+ ///
+ ///
+ public interface IVisibility
+ {
+ ///
+ /// Whether a button is currently visible or not.
+ ///
+ ///
+ bool Visible
+ {
+ get;
+ }
+ }
+
+ ///
+ /// Determines visibility of a button in relation to the currently running game scene.
+ ///
+ ///
+ ///
+ /// IButton button = ...
+ /// button.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.FLIGHT);
+ ///
+ ///
+ ///
+ public class GameScenesVisibility : IVisibility
+ {
+ public bool Visible
+ {
+ get
+ {
+ return (bool)visibleProperty.GetValue(realGameScenesVisibility, null);
+ }
+ }
+
+ private object realGameScenesVisibility;
+ private PropertyInfo visibleProperty;
+
+ public GameScenesVisibility(params GameScenes[] gameScenes)
+ {
+ Type gameScenesVisibilityType = ToolbarTypes.getType("Toolbar.GameScenesVisibility");
+ realGameScenesVisibility = Activator.CreateInstance(gameScenesVisibilityType, new object[] { gameScenes });
+ visibleProperty = ToolbarTypes.getProperty(gameScenesVisibilityType, "Visible");
+ }
+ }
+
+ #endregion
+
+ #region drawable
+
+ ///
+ /// A drawable that draws a popup menu.
+ ///
+ public partial class PopupMenuDrawable : IDrawable
+ {
+ ///
+ /// Event handler that can be registered with to receive "any menu option clicked" events.
+ ///
+ public event Action OnAnyOptionClicked
+ {
+ add
+ {
+ onAnyOptionClickedEvent.AddEventHandler(realPopupMenuDrawable, value);
+ }
+ remove
+ {
+ onAnyOptionClickedEvent.RemoveEventHandler(realPopupMenuDrawable, value);
+ }
+ }
+
+ private object realPopupMenuDrawable;
+ private MethodInfo updateMethod;
+ private MethodInfo drawMethod;
+ private MethodInfo addOptionMethod;
+ private MethodInfo addSeparatorMethod;
+ private MethodInfo destroyMethod;
+ private EventInfo onAnyOptionClickedEvent;
+
+ public PopupMenuDrawable()
+ {
+ Type popupMenuDrawableType = ToolbarTypes.getType("Toolbar.PopupMenuDrawable");
+ realPopupMenuDrawable = Activator.CreateInstance(popupMenuDrawableType, null);
+ updateMethod = ToolbarTypes.getMethod(popupMenuDrawableType, "Update");
+ drawMethod = ToolbarTypes.getMethod(popupMenuDrawableType, "Draw");
+ addOptionMethod = ToolbarTypes.getMethod(popupMenuDrawableType, "AddOption");
+ addSeparatorMethod = ToolbarTypes.getMethod(popupMenuDrawableType, "AddSeparator");
+ destroyMethod = ToolbarTypes.getMethod(popupMenuDrawableType, "Destroy");
+ onAnyOptionClickedEvent = ToolbarTypes.getEvent(popupMenuDrawableType, "OnAnyOptionClicked");
+ }
+
+ public void Update()
+ {
+ updateMethod.Invoke(realPopupMenuDrawable, null);
+ }
+
+ public Vector2 Draw(Vector2 position)
+ {
+ return (Vector2)drawMethod.Invoke(realPopupMenuDrawable, new object[] { position });
+ }
+
+ ///
+ /// Adds a new option to the popup menu.
+ ///
+ /// The text of the option.
+ /// A button that can be used to register clicks on the menu option.
+ public IButton AddOption(string text)
+ {
+ object realButton = addOptionMethod.Invoke(realPopupMenuDrawable, new object[] { text });
+ return new Button(realButton, new ToolbarTypes());
+ }
+
+ ///
+ /// Adds a separator to the popup menu.
+ ///
+ public void AddSeparator()
+ {
+ addSeparatorMethod.Invoke(realPopupMenuDrawable, null);
+ }
+
+ ///
+ /// Destroys this drawable. This must always be called before disposing of this drawable.
+ ///
+ public void Destroy()
+ {
+ destroyMethod.Invoke(realPopupMenuDrawable, null);
+ }
+ }
+
+ #endregion
+
+ #region private implementations
+
+ public partial class ToolbarManager : IToolbarManager
+ {
+ private static bool? toolbarAvailable = null;
+ private static IToolbarManager instance_;
+
+ private object realToolbarManager;
+ private MethodInfo addMethod;
+ private Dictionary