ToolbarWrapper: New class that anonymously wraps Blizzy's Toolbar.
ToolbarWrapper: New class that anonymously wraps Blizzy's Toolbar.

--- a/IntCollection.cs
+++ b/IntCollection.cs
@@ -59,7 +59,6 @@
 				return (ushort)((this.collection & (this.mask << idx)) >> idx);
 			}
 			set {
-				Console.WriteLine (value);
 				if (idx < 0) {
 					idx += this.maxCount;
 				}
@@ -71,7 +70,6 @@
 				idx *= wordLength;
 
 				long packvalue = value & this.mask;
-				Console.WriteLine (packvalue);
 
 				this.collection &= ~(this.mask << idx);
 				this.collection |= packvalue << idx;

file:b/ToolbarWrapper.cs (new)
--- /dev/null
+++ b/ToolbarWrapper.cs
@@ -1,1 +1,191 @@
+//
+//  ToolbarWrapper.cs
+//
+//  Author:
+//       toadicus <>
+//
+//  Copyright (c) 2013 toadicus
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+using KSP;
+using System;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Reflection;
+using UnityEngine;
 
+namespace VOID
+{
+	internal class ToolbarButtonWrapper
+	{
+		protected System.Type ToolbarManager;
+		protected object TBManagerInstance;
+		protected MethodInfo TBManagerAdd;
+		protected System.Type IButton;
+		protected object Button;
+		protected PropertyInfo ButtonText;
+		protected PropertyInfo ButtonTextColor;
+		protected PropertyInfo ButtonTexturePath;
+		protected EventInfo ButtonOnClick;
+		protected System.Type ClickHandlerType;
+		protected MethodInfo ButtonDestroy;
+
+		public string Text
+		{
+			get
+			{
+				return this.ButtonText.GetValue(this.Button, null) as String;
+			}
+			set
+			{
+				this.ButtonText.SetValue(this.Button, value, null);
+			}
+		}
+
+		public Color TextColor
+		{
+			get
+			{
+				return (Color)this.ButtonTextColor.GetValue(this.Button, null);
+			}
+			set
+			{
+				this.ButtonTextColor.SetValue(this.Button, value, null);
+			}
+		}
+
+		public string TexturePath
+		{
+			get
+			{
+				return this.ButtonTexturePath.GetValue(this.Button, null) as string;
+			}
+			set
+			{
+				this.ButtonTexturePath.SetValue(this.Button, value, null);
+			}
+		}
+
+		private ToolbarButtonWrapper() {}
+
+		public ToolbarButtonWrapper(string ns, string id)
+		{
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Loading ToolbarManager.",
+				this.GetType().Name
+			));
+
+			this.ToolbarManager = AssemblyLoader.loadedAssemblies
+				.Select(a => a.assembly.GetExportedTypes())
+				.SelectMany(t => t)
+				.FirstOrDefault(t => t.FullName == "Toolbar.ToolbarManager");
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Loaded ToolbarManager.  Getting Instance.",
+				this.GetType().Name
+				));
+
+			this.TBManagerInstance = this.ToolbarManager.GetProperty(
+					"Instance",
+					System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static
+				)
+				.GetValue(null, null);
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Got ToolbarManager Instance '{1}'.  Getting 'add' method.",
+				this.GetType().Name,
+				this.TBManagerInstance
+				));
+
+			this.TBManagerAdd = this.ToolbarManager.GetMethod("add");
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Got ToolbarManager Instance 'add' method.  Loading IButton.",
+				this.GetType().Name
+				));
+
+			this.IButton = AssemblyLoader.loadedAssemblies
+				.Select(a => a.assembly.GetExportedTypes())
+				.SelectMany(t => t)
+				.FirstOrDefault(t => t.FullName == "Toolbar.IButton");
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Loaded IButton.  Adding Button with ToolbarManager.",
+				this.GetType().Name
+				));
+
+			this.Button = this.TBManagerAdd.Invoke(this.TBManagerInstance, new object[] {ns, id});
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Added Button '{1}' with ToolbarManager.  Getting 'Text' property",
+				this.GetType().Name,
+				this.Button.ToString()
+				));
+
+			this.ButtonText = this.IButton.GetProperty("Text");
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Got 'Text' property.  Getting 'TextColor' property.",
+				this.GetType().Name
+				));
+
+			this.ButtonTextColor = this.IButton.GetProperty("TextColor");
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Got 'TextColor' property.  Getting 'TexturePath' property.",
+				this.GetType().Name
+				));
+
+			this.ButtonTexturePath = this.IButton.GetProperty("TexturePath");
+			
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Got 'TexturePath' property.  Getting 'OnClick' property.",
+				this.GetType().Name
+				));
+
+			this.ButtonOnClick = this.IButton.GetEvent("OnClick");
+			this.ClickHandlerType = this.ButtonOnClick.EventHandlerType;
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Got 'OnClick' property '{1}'.  Getting 'Destroy' method.",
+				this.GetType().Name,
+				this.ButtonOnClick.ToString()
+				));
+
+			this.ButtonDestroy = this.IButton.GetMethod("Destroy");
+
+			Tools.PostDebugMessage(string.Format(
+				"{0}: Got 'Destroy' property '{1}'.",
+				this.GetType().Name,
+				this.ButtonDestroy.ToString()
+				));
+
+			Tools.PostDebugMessage("ToolbarButtonWrapper built!");
+		}
+
+		public void AddButtonClickHandler(Action<object> Handler)
+		{
+			Delegate d = Delegate.CreateDelegate(this.ClickHandlerType, Handler.Target, Handler.Method);
+			MethodInfo addHandler = this.ButtonOnClick.GetAddMethod();
+			addHandler.Invoke(this.Button, new object[] { d });
+		}
+
+		public void Destroy()
+		{
+			this.ButtonDestroy.Invoke(this.Button, null);
+		}
+	}
+}
+
+

--- a/VOID_Module.cs
+++ b/VOID_Module.cs
@@ -200,23 +200,13 @@
 		public virtual void ModuleWindow(int _)
 		{
 			if (VOID_Core.Instance.updateTimer - this.lastUpdate > VOID_Core.Instance.updatePeriod) {
-				Tools.PostDebugMessage(string.Format(
-					"{0}: refreshing VOID_DataValues.",
-					this.GetType().Name
-				));
-
 				foreach (var fieldinfo in this.GetType().GetFields(
 					BindingFlags.Instance |
 					BindingFlags.NonPublic |
 					BindingFlags.Public |
 					BindingFlags.FlattenHierarchy
-				)) {
-					Tools.PostDebugMessage(string.Format(
-						"{0}: checking field {1}.",
-						this.GetType().Name,
-						fieldinfo.Name
-					));
-
+				))
+				{
 					object field = null;
 
 					try
@@ -236,19 +226,7 @@
 					}
 
 					if (typeof(IVOID_DataValue).IsAssignableFrom (field.GetType ())) {
-						Tools.PostDebugMessage(string.Format(
-							"{0}: found field {1}.",
-							this.GetType().Name,
-							fieldinfo.Name
-						));
-
 						(field as IVOID_DataValue).Refresh ();
-
-						Tools.PostDebugMessage(string.Format(
-							"{0}: refreshed field {1}.",
-							this.GetType().Name,
-							fieldinfo.Name
-						));
 					}
 				}
 

--- a/VOID_Orbital.cs
+++ b/VOID_Orbital.cs
@@ -68,7 +68,7 @@
 		);
 
 		protected VOID_StrValue timeToPeri = new VOID_StrValue(
-			"Time to Apoapsis",
+			"Time to Periapsis",
 			new Func<string>(() => Tools.ConvertInterval(VOID_Core.Instance.vessel.orbit.timeToPe))
 		);