ToolbarButtonWrapper: Added XML comments for the new OnMouse events, and rearranged the file a little bit.
ToolbarButtonWrapper: Added XML comments for the new OnMouse events, and rearranged the file a little bit.

// //
// ToolbarWrapper.cs // ToolbarWrapper.cs
// //
// Author: // Author:
// toadicus <> // toadicus <>
// //
// Copyright (c) 2013 toadicus // Copyright (c) 2013 toadicus
// //
// This program is free software: you can redistribute it and/or modify // 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 // it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or // the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version. // (at your option) any later version.
// //
// This program is distributed in the hope that it will be useful, // This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of // but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. // GNU General Public License for more details.
// //
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using UnityEngine; using UnityEngine;
   
namespace VOID namespace VOID
{ {
/// <summary> /// <summary>
/// Wraps a Toolbar clickable button, after fetching it from a foreign assembly. /// Wraps a Toolbar clickable button, after fetching it from a foreign assembly.
/// </summary> /// </summary>
internal class ToolbarButtonWrapper internal class ToolbarButtonWrapper
{ {
protected static System.Type ToolbarManager; protected static System.Type ToolbarManager;
protected static object TBManagerInstance; protected static object TBManagerInstance;
protected static MethodInfo TBManagerAdd; protected static MethodInfo TBManagerAdd;
   
/// <summary> /// <summary>
/// Wraps the ToolbarManager class, if present. /// Wraps the ToolbarManager class, if present.
/// </summary> /// </summary>
/// <returns><c>true</c>, if ToolbarManager is wrapped, <c>false</c> otherwise.</returns> /// <returns><c>true</c>, if ToolbarManager is wrapped, <c>false</c> otherwise.</returns>
protected static bool TryWrapToolbarManager() protected static bool TryWrapToolbarManager()
{ {
if (ToolbarManager == null) if (ToolbarManager == null)
{ {
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Loading ToolbarManager.", "{0}: Loading ToolbarManager.",
"ToolbarButtonWrapper" "ToolbarButtonWrapper"
)); ));
   
ToolbarManager = AssemblyLoader.loadedAssemblies ToolbarManager = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes()) .Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t) .SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "Toolbar.ToolbarManager"); .FirstOrDefault(t => t.FullName == "Toolbar.ToolbarManager");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Loaded ToolbarManager. Getting Instance.", "{0}: Loaded ToolbarManager. Getting Instance.",
"ToolbarButtonWrapper" "ToolbarButtonWrapper"
)); ));
   
if (ToolbarManager == null) if (ToolbarManager == null)
{ {
return false; return false;
} }
   
TBManagerInstance = ToolbarManager.GetProperty( TBManagerInstance = ToolbarManager.GetProperty(
"Instance", "Instance",
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static
) )
.GetValue(null, null); .GetValue(null, null);
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got ToolbarManager Instance '{1}'. Getting 'add' method.", "{0}: Got ToolbarManager Instance '{1}'. Getting 'add' method.",
"ToolbarButtonWrapper", "ToolbarButtonWrapper",
TBManagerInstance TBManagerInstance
)); ));
   
TBManagerAdd = ToolbarManager.GetMethod("add"); TBManagerAdd = ToolbarManager.GetMethod("add");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got ToolbarManager Instance 'add' method. Loading IButton.", "{0}: Got ToolbarManager Instance 'add' method. Loading IButton.",
"ToolbarButtonWrapper" "ToolbarButtonWrapper"
)); ));
} }
   
return true; return true;
} }
   
/// <summary> /// <summary>
/// Gets a value indicating whether <see cref="Toolbar.ToolbarManager"/> is present. /// Gets a value indicating whether <see cref="Toolbar.ToolbarManager"/> is present.
/// </summary> /// </summary>
/// <value><c>true</c>, if ToolbarManager is wrapped, <c>false</c> otherwise.</value> /// <value><c>true</c>, if ToolbarManager is wrapped, <c>false</c> otherwise.</value>
public static bool ToolbarManagerPresent public static bool ToolbarManagerPresent
{ {
get get
{ {
return TryWrapToolbarManager(); return TryWrapToolbarManager();
} }
} }
   
/// <summary> /// <summary>
/// If ToolbarManager is present, initializes a new instance of the <see cref="VOID.ToolbarButtonWrapper"/> class. /// If ToolbarManager is present, initializes a new instance of the <see cref="VOID.ToolbarButtonWrapper"/> class.
/// </summary> /// </summary>
/// <param name="ns">Namespace, usually the plugin name.</param> /// <param name="ns">Namespace, usually the plugin name.</param>
/// <param name="id">Identifier, unique per namespace.</param> /// <param name="id">Identifier, unique per namespace.</param>
/// <returns>If ToolbarManager is present, a new <see cref="Toolbar.IButton"/> object, <c>null</c> otherwise.</returns> /// <returns>If ToolbarManager is present, a new <see cref="Toolbar.IButton"/> object, <c>null</c> otherwise.</returns>
public static ToolbarButtonWrapper TryWrapToolbarButton(string ns, string id) public static ToolbarButtonWrapper TryWrapToolbarButton(string ns, string id)
{ {
if (ToolbarManagerPresent) if (ToolbarManagerPresent)
{ {
object button = TBManagerAdd.Invoke(TBManagerInstance, new object[] { ns, id }); object button = TBManagerAdd.Invoke(TBManagerInstance, new object[] { ns, id });
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Added Button '{1}' with ToolbarManager. Getting 'Text' property", "{0}: Added Button '{1}' with ToolbarManager. Getting 'Text' property",
"ToolbarButtonWrapper", "ToolbarButtonWrapper",
button.ToString() button.ToString()
)); ));
   
return new ToolbarButtonWrapper(button); return new ToolbarButtonWrapper(button);
} }
else else
{ {
return null; return null;
} }
} }
   
protected System.Type IButton; protected System.Type IButton;
protected object Button; protected object Button;
protected PropertyInfo ButtonText; protected PropertyInfo ButtonText;
protected PropertyInfo ButtonTextColor; protected PropertyInfo ButtonTextColor;
protected PropertyInfo ButtonTexturePath; protected PropertyInfo ButtonTexturePath;
protected PropertyInfo ButtonToolTip; protected PropertyInfo ButtonToolTip;
protected PropertyInfo ButtonVisible; protected PropertyInfo ButtonVisible;
protected PropertyInfo ButtonVisibility; protected PropertyInfo ButtonVisibility;
protected PropertyInfo ButtonEnalbed; protected PropertyInfo ButtonEnalbed;
protected PropertyInfo ButtonImportant; protected PropertyInfo ButtonImportant;
protected EventInfo ButtonOnClick; protected EventInfo ButtonOnClick;
protected System.Type ClickHandlerType; protected System.Type ClickHandlerType;
protected EventInfo ButtonOnMouseEnter; protected EventInfo ButtonOnMouseEnter;
protected System.Type MouseEnterHandlerType; protected System.Type MouseEnterHandlerType;
protected EventInfo ButtonOnMouseLeave; protected EventInfo ButtonOnMouseLeave;
protected System.Type MouseLeaveHandlerType; protected System.Type MouseLeaveHandlerType;
protected MethodInfo ButtonDestroy; protected MethodInfo ButtonDestroy;
protected System.Type GameScenesVisibilityType; protected System.Type GameScenesVisibilityType;
   
/// <summary> /// <summary>
/// The text displayed on the button. Set to null to hide text. /// The text displayed on the button. Set to null to hide text.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The text can be changed at any time to modify the button's appearance. Note that since this will also /// 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. /// modify the button's size, this feature should be used sparingly, if at all.
/// </remarks> /// </remarks>
/// <seealso cref="TexturePath"/> /// <seealso cref="TexturePath"/>
public string Text public string Text
{ {
get get
{ {
return this.ButtonText.GetValue(this.Button, null) as String; return this.ButtonText.GetValue(this.Button, null) as String;
} }
set set
{ {
this.ButtonText.SetValue(this.Button, value, null); this.ButtonText.SetValue(this.Button, value, null);
} }
} }
   
/// <summary> /// <summary>
/// The color the button text is displayed with. Defaults to Color.white. /// The color the button text is displayed with. Defaults to Color.white.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The text color can be changed at any time to modify the button's appearance. /// The text color can be changed at any time to modify the button's appearance.
/// </remarks> /// </remarks>
public Color TextColor public Color TextColor
{ {
get get
{ {
return (Color)this.ButtonTextColor.GetValue(this.Button, null); return (Color)this.ButtonTextColor.GetValue(this.Button, null);
} }
set set
{ {
this.ButtonTextColor.SetValue(this.Button, value, null); this.ButtonTextColor.SetValue(this.Button, value, null);
} }
} }
   
/// <summary> /// <summary>
/// The path of a texture file to display an icon on the button. Set to null to hide icon. /// The path of a texture file to display an icon on the button. Set to null to hide icon.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// A texture path on a button will have precedence over text. That is, if both text and texture path /// 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. /// have been set on a button, the button will show the texture, not the text.
/// </para> /// </para>
/// <para> /// <para>
/// The texture size must not exceed 24x24 pixels. /// The texture size must not exceed 24x24 pixels.
/// </para> /// </para>
/// <para> /// <para>
/// The texture path must be relative to the "GameData" directory, and must not specify a file name suffix. /// The texture path must be relative to the "GameData" directory, and must not specify a file name suffix.
/// Valid example: MyAddon/Textures/icon_mybutton /// Valid example: MyAddon/Textures/icon_mybutton
/// </para> /// </para>
/// <para> /// <para>
/// The texture path can be changed at any time to modify the button's appearance. /// The texture path can be changed at any time to modify the button's appearance.
/// </para> /// </para>
/// </remarks> /// </remarks>
/// <seealso cref="Text"/> /// <seealso cref="Text"/>
public string TexturePath public string TexturePath
{ {
get get
{ {
return this.ButtonTexturePath.GetValue(this.Button, null) as string; return this.ButtonTexturePath.GetValue(this.Button, null) as string;
} }
set set
{ {
this.ButtonTexturePath.SetValue(this.Button, value, null); this.ButtonTexturePath.SetValue(this.Button, value, null);
} }
} }
   
/// <summary> /// <summary>
/// The button's tool tip text. Set to null if no tool tip is desired. /// The button's tool tip text. Set to null if no tool tip is desired.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// Tool Tip Text Should Always Use Headline Style Like This. /// Tool Tip Text Should Always Use Headline Style Like This.
/// </remarks> /// </remarks>
public string ToolTip public string ToolTip
{ {
get get
{ {
return this.ButtonToolTip.GetValue(this.Button, null) as string; return this.ButtonToolTip.GetValue(this.Button, null) as string;
} }
set set
{ {
this.ButtonToolTip.SetValue(this.Button, value, null); this.ButtonToolTip.SetValue(this.Button, value, null);
} }
} }
   
/// <summary> /// <summary>
/// Whether this button is currently visible or not. Can be used in addition to or as a replacement for <see cref="Visibility"/>. /// Whether this button is currently visible or not. Can be used in addition to or as a replacement for <see cref="Visibility"/>.
/// </summary> /// </summary>
public bool Visible public bool Visible
{ {
get get
{ {
return (bool)this.ButtonVisible.GetValue(this.Button, null); return (bool)this.ButtonVisible.GetValue(this.Button, null);
} }
set set
{ {
this.ButtonVisible.SetValue(this.Button, value, null); this.ButtonVisible.SetValue(this.Button, value, null);
} }
} }
   
/// <summary> /// <summary>
/// Whether this button is currently enabled (clickable) or not. This will not affect the player's ability to /// Whether this button is currently enabled (clickable) or not. This will not affect the player's ability to
/// position the button on their screen. /// position the button on their screen.
/// </summary> /// </summary>
public bool Enabled public bool Enabled
{ {
get get
{ {
return (bool)this.ButtonEnalbed.GetValue(this.Button, null); return (bool)this.ButtonEnalbed.GetValue(this.Button, null);
} }
set set
{ {
this.ButtonEnalbed.SetValue(this.Button, value, null); this.ButtonEnalbed.SetValue(this.Button, value, null);
} }
} }
   
/// <summary> /// <summary>
/// Whether this button is currently "important." Set to false to return to normal button behaviour. /// Whether this button is currently "important." Set to false to return to normal button behaviour.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// This can be used to temporarily force the button to be shown on the screen regardless of the toolbar being /// This can be used to temporarily force the button to be shown on the 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 /// 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. /// chat room could mark itself as "important" as long as the message has not been read.
/// </para> /// </para>
/// <para> /// <para>
/// Setting this property does not change the appearance of the button. use <see cref="TexturePath"/> to /// Setting this property does not change the appearance of the button. use <see cref="TexturePath"/> to
/// change the button's icon. /// change the button's icon.
/// </para> /// </para>
/// <para> /// <para>
/// This feature should be used only sparingly, if at all, since it forces the button to be displayed on screen /// 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. /// even when it normally wouldn't.
/// </para> /// </para>
/// </remarks> /// </remarks>
/// <value><c>true</c> if important; otherwise, <c>false</c>.</value> /// <value><c>true</c> if important; otherwise, <c>false</c>.</value>
public bool Important public bool Important
{ {
get get
{ {
return (bool)this.ButtonImportant.GetValue(this.Button, null); return (bool)this.ButtonImportant.GetValue(this.Button, null);
} }
set set
{ {
this.ButtonImportant.SetValue(this.Button, value, null); this.ButtonImportant.SetValue(this.Button, value, null);
} }
} }
   
private ToolbarButtonWrapper() private ToolbarButtonWrapper()
{ {
} }
   
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="VOID.ToolbarButtonWrapper"/> class. /// Initializes a new instance of the <see cref="VOID.ToolbarButtonWrapper"/> class.
/// </summary> /// </summary>
/// <param name="ns">Namespace, usually the plugin name.</param> /// <param name="ns">Namespace, usually the plugin name.</param>
/// <param name="id">Identifier, unique per namespace.</param> /// <param name="id">Identifier, unique per namespace.</param>
protected ToolbarButtonWrapper(object button) protected ToolbarButtonWrapper(object button)
{ {
this.Button = button; this.Button = button;
   
this.IButton = AssemblyLoader.loadedAssemblies this.IButton = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes()) .Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t) .SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "Toolbar.IButton"); .FirstOrDefault(t => t.FullName == "Toolbar.IButton");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Loaded IButton. Adding Button with ToolbarManager.", "{0}: Loaded IButton. Adding Button with ToolbarManager.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonText = this.IButton.GetProperty("Text"); this.ButtonText = this.IButton.GetProperty("Text");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'Text' property. Getting 'TextColor' property.", "{0}: Got 'Text' property. Getting 'TextColor' property.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonTextColor = this.IButton.GetProperty("TextColor"); this.ButtonTextColor = this.IButton.GetProperty("TextColor");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'TextColor' property. Getting 'TexturePath' property.", "{0}: Got 'TextColor' property. Getting 'TexturePath' property.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonTexturePath = this.IButton.GetProperty("TexturePath"); this.ButtonTexturePath = this.IButton.GetProperty("TexturePath");
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'TexturePath' property. Getting 'ToolTip' property.", "{0}: Got 'TexturePath' property. Getting 'ToolTip' property.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonToolTip = this.IButton.GetProperty("ToolTip"); this.ButtonToolTip = this.IButton.GetProperty("ToolTip");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'ToolTip' property. Getting 'Visible' property.", "{0}: Got 'ToolTip' property. Getting 'Visible' property.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonVisible = this.IButton.GetProperty("Visible"); this.ButtonVisible = this.IButton.GetProperty("Visible");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'Visible' property. Getting 'Visibility' property.", "{0}: Got 'Visible' property. Getting 'Visibility' property.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonVisibility = this.IButton.GetProperty("Visibility"); this.ButtonVisibility = this.IButton.GetProperty("Visibility");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'Visibility' property. Getting 'Enabled' property.", "{0}: Got 'Visibility' property. Getting 'Enabled' property.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonEnalbed = this.IButton.GetProperty("Enabled"); this.ButtonEnalbed = this.IButton.GetProperty("Enabled");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'Enabled' property. Getting 'OnClick' event.", "{0}: Got 'Enabled' property. Getting 'OnClick' event.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonImportant = this.IButton.GetProperty("Important"); this.ButtonImportant = this.IButton.GetProperty("Important");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'Enabled' property. Getting 'OnClick' event.", "{0}: Got 'Enabled' property. Getting 'OnClick' event.",
this.GetType().Name this.GetType().Name
)); ));
   
this.ButtonOnClick = this.IButton.GetEvent("OnClick"); this.ButtonOnClick = this.IButton.GetEvent("OnClick");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'OnClick' event '{1}'. Getting 'OnMouseEnter' event.", "{0}: Got 'OnClick' event '{1}'. Getting 'OnMouseEnter' event.",
this.GetType().Name, this.GetType().Name,
this.ButtonOnClick.ToString() this.ButtonOnClick.ToString()
)); ));
   
this.ButtonOnMouseEnter = this.IButton.GetEvent("OnMouseEnter"); this.ButtonOnMouseEnter = this.IButton.GetEvent("OnMouseEnter");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'OnMouseEnter' event '{1}'. Getting 'OnMouseLeave' event.", "{0}: Got 'OnMouseEnter' event '{1}'. Getting 'OnMouseLeave' event.",
this.GetType().Name, this.GetType().Name,
this.ButtonOnClick.ToString() this.ButtonOnClick.ToString()
)); ));
   
this.ButtonOnMouseLeave = this.IButton.GetEvent("OnMouseLeave"); this.ButtonOnMouseLeave = this.IButton.GetEvent("OnMouseLeave");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'OnMouseLeave' event '{1}'. Getting 'Destroy' method.", "{0}: Got 'OnMouseLeave' event '{1}'. Getting 'Destroy' method.",
this.GetType().Name, this.GetType().Name,
this.ButtonOnClick.ToString() this.ButtonOnClick.ToString()
)); ));
   
this.ButtonDestroy = this.IButton.GetMethod("Destroy"); this.ButtonDestroy = this.IButton.GetMethod("Destroy");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'Destroy' property '{1}'. Loading GameScenesVisibility class.", "{0}: Got 'Destroy' property '{1}'. Loading GameScenesVisibility class.",
this.GetType().Name, this.GetType().Name,
this.ButtonDestroy.ToString() this.ButtonDestroy.ToString()
)); ));
   
this.GameScenesVisibilityType = AssemblyLoader.loadedAssemblies this.GameScenesVisibilityType = AssemblyLoader.loadedAssemblies
.Select(a => a.assembly.GetExportedTypes()) .Select(a => a.assembly.GetExportedTypes())
.SelectMany(t => t) .SelectMany(t => t)
.FirstOrDefault(t => t.FullName == "Toolbar.GameScenesVisibility"); .FirstOrDefault(t => t.FullName == "Toolbar.GameScenesVisibility");
   
Tools.PostDebugMessage(string.Format( Tools.PostDebugMessage(string.Format(
"{0}: Got 'GameScenesVisibility' class '{1}'.", "{0}: Got 'GameScenesVisibility' class '{1}'.",
this.GetType().Name, this.GetType().Name,
this.GameScenesVisibilityType.ToString() this.GameScenesVisibilityType.ToString()
)); ));
   
Tools.PostDebugMessage("ToolbarButtonWrapper built!"); Tools.PostDebugMessage("ToolbarButtonWrapper built!");
} }
   
/// <summary> /// <summary>
/// Adds event handler to receive "on click" events. /// Adds event handler to receive "on click" events.
/// </summary> /// </summary>
/// <example> /// <example>
/// <code> /// <code>
/// ToolbarButtonWrapper button = ... /// ToolbarButtonWrapper button = ...
/// button.AddButtonClickHandler( /// button.AddButtonClickHandler(
/// (e) => /// (e) =>
/// { /// {
/// Debug.Log("button clicked, mouseButton: " + e.Mousebutton"); /// Debug.Log("button clicked, mouseButton: " + e.Mousebutton");
/// } /// }
/// ); /// );
/// </code> /// </code>
/// </example> /// </example>
/// <param name="Handler">Delegate to handle "on click" events</param> /// <param name="Handler">Delegate to handle "on click" events</param>
public void AddButtonClickHandler(Action<object> Handler) public void AddButtonClickHandler(Action<object> Handler)
{ {
this.AddButtonEventHandler(this.ButtonOnClick, Handler); this.AddButtonEventHandler(this.ButtonOnClick, Handler);
} }
   
  /// <summary>
  /// Adds event handler that can be registered with to receive "on mouse enter" events.
  /// </summary>
  /// <example>
  /// <code>
  /// ToolbarWrapperButton button = ...
  /// button.AddButtonOnMouseEnterHandler(
  /// (e) =>
  /// {
  /// Debug.Log("mouse entered button");
  /// }
  /// );
  /// </code>
  /// </example>
  /// <param name="Handler">Delegate to handle "OnMouseEnter" events.</param>
public void AddButtonOnMouseEnterHandler(Action<object> Handler) public void AddButtonOnMouseEnterHandler(Action<object> Handler)
{ {
this.AddButtonEventHandler(this.ButtonOnMouseEnter, Handler); this.AddButtonEventHandler(this.ButtonOnMouseEnter, Handler);
} }
   
  /// <summary>
  /// Adds event handler that can be registered with to receive "on mouse leave" events.
  /// </summary>
  /// <example>
  /// <code>
  /// ToolbarWrapperButton button = ...
  /// button.AddButtonOnMouseLeaveHandler(
  /// (e) =>
  /// {
  /// Debug.Log("mouse left button");
  /// }
  /// );
  /// </code>
  /// </example>
  /// <param name="Handler">Delegate to handle "OnMouseLeave" events.</param>
public void AddButtonOnMouseLeaveHandler(Action<object> Handler) public void AddButtonOnMouseLeaveHandler(Action<object> Handler)
{ {
this.AddButtonEventHandler(this.ButtonOnMouseLeave, Handler); this.AddButtonEventHandler(this.ButtonOnMouseLeave, Handler);
} }
   
  /// <summary>
  /// Sets this button's visibility. Can be used in addition to or as a replacement for <see cref="Visible"/>.
  /// </summary>
  /// <param name="gameScenes">Array of GameScene objects in which the button should be visible.</param>
  public void SetButtonVisibility(params GameScenes[] gameScenes)
  {
  object GameScenesVisibilityObj = Activator.CreateInstance(this.GameScenesVisibilityType, gameScenes);
  this.ButtonVisibility.SetValue(this.Button, GameScenesVisibilityObj, null);
  }
   
  /// <summary>
  /// Permanently destroys this button so that it is no longer displayed.
  /// Should be used when a plugin is stopped to remove leftover buttons.
  /// </summary>
  public void Destroy()
  {
  this.ButtonDestroy.Invoke(this.Button, null);
  }
   
  // Utility method for use with the AddButton<event>Handler API methods.
protected void AddButtonEventHandler(EventInfo Event, Action<object> Handler) protected void AddButtonEventHandler(EventInfo Event, Action<object> Handler)
{ {
Delegate d = Delegate.CreateDelegate(Event.EventHandlerType, Handler.Target, Handler.Method); Delegate d = Delegate.CreateDelegate(Event.EventHandlerType, Handler.Target, Handler.Method);
MethodInfo addHandler = Event.GetAddMethod(); MethodInfo addHandler = Event.GetAddMethod();
addHandler.Invoke(this.Button, new object[] { d }); addHandler.Invoke(this.Button, new object[] { d });
} }
   
/// <summary>  
/// Sets this button's visibility. Can be used in addition to or as a replacement for <see cref="Visible"/>.  
/// </summary>  
/// <param name="gameScenes">Array of GameScene objects in which the button should be visible.</param>  
public void SetButtonVisibility(params GameScenes[] gameScenes)  
{  
object GameScenesVisibilityObj = Activator.CreateInstance(this.GameScenesVisibilityType, gameScenes);  
this.ButtonVisibility.SetValue(this.Button, GameScenesVisibilityObj, null);  
}  
   
/// <summary>  
/// Permanently destroys this button so that it is no longer displayed.  
/// Should be used when a plugin is stopped to remove leftover buttons.  
/// </summary>  
public void Destroy()  
{  
this.ButtonDestroy.Invoke(this.Button, null);  
}  
} }
} }