--- /dev/null
+#region Copyright\r
+// \r
+// Radegast SimpleBuilder plugin extension\r
+//\r
+// Copyright (c) 2014, Ano Nymous <anonymously@hotmail.de> | SecondLife-IM: anno1986 Resident\r
+// All rights reserved.\r
+// \r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are met:\r
+// \r
+// * Redistributions of source code must retain the above copyright notice,\r
+// this list of conditions and the following disclaimer.\r
+// * Redistributions in binary form must reproduce the above copyright\r
+// notice, this list of conditions and the following disclaimer in the\r
+// documentation and/or other materials provided with the distribution.\r
+// * Neither the name of the application "Radegast", nor the names of its\r
+// contributors may be used to endorse or promote products derived from\r
+// this software without specific prior written permission.\r
+// \r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+//\r
+// $Id$\r
+//\r
+#endregion\r
+\r
+#region Usings\r
+using System;\r
+using System.Collections.Generic;\r
+using System.ComponentModel;\r
+using System.Drawing;\r
+using System.Data;\r
+using System.Linq;\r
+using System.Text;\r
+using System.Windows.Forms;\r
+using Radegast;\r
+using OpenMetaverse;\r
+#endregion\r
+\r
+namespace SimpleBuilderNamespace\r
+{\r
+ /// <summary>\r
+ /// Example implementation of a control that can be used\r
+ /// as Radegast tab and loeaded as a plugin\r
+ /// </summary>\r
+ [Radegast.Plugin(Name = "SimpleBuilder Plugin", Description = "Allows you to build some basic prims, like boxes, cylinder, tubes, ... (requires permission!)", Version = "1.0")]\r
+ public partial class SimpleBuilder : RadegastTabControl, IRadegastPlugin\r
+ {\r
+ private string pluginName = "SimpleBuilder";\r
+ // Methods needed for proper registration of a GUI tab\r
+ #region Template for GUI radegast tab\r
+ /// <summary>String for internal identification of the tab (change this!)</summary>\r
+ static string tabID = "demo_tab";\r
+ /// <summary>Text displayed in the plugins menu and the tab label (change this!)</summary>\r
+ static string tabLabel = "Build Prims";\r
+\r
+ /// <summary>Menu item that gets added to the Plugins menu</summary>\r
+ ToolStripMenuItem ActivateTabButton;\r
+\r
+ /// <summary>Default constructor. Never used. Needed for VS designer</summary>\r
+ public SimpleBuilder()\r
+ {\r
+ }\r
+\r
+ /// <summary>\r
+ /// Main constructor used when actually creating the tab control for display\r
+ /// Register client and instance events\r
+ /// </summary>\r
+ /// <param name="instance">RadegastInstance</param>\r
+ /// <param name="unused">This param is not used, but needs to be there to keep the constructor signature</param>\r
+ public SimpleBuilder(RadegastInstance instance, bool unused)\r
+ : base(instance)\r
+ {\r
+ InitializeComponent();\r
+ Disposed += new EventHandler(DemoTab_Disposed);\r
+ instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);\r
+ RegisterClientEvents(client);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Cleanup after the tab is closed\r
+ /// Unregister event handler hooks we have installed\r
+ /// </summary>\r
+ /// <param name="sender"></param>\r
+ /// <param name="e"></param>\r
+ void DemoTab_Disposed(object sender, EventArgs e)\r
+ {\r
+ UnregisterClientEvents(client);\r
+ instance.ClientChanged -= new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Plugin loader calls this at the time plugin gets created\r
+ /// We add a button to the Plugins menu on the main window\r
+ /// for this tab\r
+ /// </summary>\r
+ /// <param name="inst">Main RadegastInstance</param>\r
+ public void StartPlugin(RadegastInstance inst)\r
+ {\r
+ this.instance = inst;\r
+ ActivateTabButton = new ToolStripMenuItem(tabLabel, null, MenuButtonClicked);\r
+ instance.MainForm.PluginsMenu.DropDownItems.Add(ActivateTabButton);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Called when the plugin manager unloads our plugin. \r
+ /// Close the tab if it's active and remove the menu button\r
+ /// </summary>\r
+ /// <param name="inst"></param>\r
+ public void StopPlugin(RadegastInstance inst)\r
+ {\r
+ ActivateTabButton.Dispose();\r
+ instance.TabConsole.Tabs[tabID].Close();\r
+ }\r
+\r
+ /// <summary>\r
+ /// Hadle case when GridClient is changed (relog haa occured without\r
+ /// quiting Radegast). We need to unregister events from the old client\r
+ /// and re-register them with the new\r
+ /// </summary>\r
+ /// <param name="sender"></param>\r
+ /// <param name="e"></param>\r
+ void instance_ClientChanged(object sender, ClientChangedEventArgs e)\r
+ {\r
+ UnregisterClientEvents(e.OldClient);\r
+ RegisterClientEvents(e.Client);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Registration of all GridClient (libomv) events go here\r
+ /// </summary>\r
+ /// <param name="client"></param>\r
+ void RegisterClientEvents(GridClient client)\r
+ {\r
+ client.Self.ChatFromSimulator += new EventHandler<ChatEventArgs>(Self_ChatFromSimulator);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Unregistration of GridClient (libomv) events.\r
+ /// Important that this be symetric to RegisterClientEvents() calls\r
+ /// </summary>\r
+ /// <param name="client"></param>\r
+ void UnregisterClientEvents(GridClient client)\r
+ {\r
+ if (client == null) return;\r
+ client.Self.ChatFromSimulator -= new EventHandler<ChatEventArgs>(Self_ChatFromSimulator);\r
+ }\r
+\r
+ /// <summary>\r
+ /// Handling the click on Plugins -> Demo Tab button\r
+ /// Check if we already have a tab. If we do make it active tab.\r
+ /// If not, create a new tab and make it active.\r
+ /// </summary>\r
+ /// <param name="sender"></param>\r
+ /// <param name="e"></param>\r
+ void MenuButtonClicked(object sender, EventArgs e)\r
+ {\r
+ if (instance.TabConsole.TabExists(tabID))\r
+ {\r
+ instance.TabConsole.Tabs[tabID].Select();\r
+ }\r
+ else\r
+ {\r
+ instance.TabConsole.AddTab(tabID, tabLabel, new SimpleBuilder(instance, true));\r
+ instance.TabConsole.Tabs[tabID].Select();\r
+ }\r
+ }\r
+ #endregion Template for GUI radegast tab\r
+\r
+ #region Implementation of the custom tab functionality\r
+ void Self_ChatFromSimulator(object sender, ChatEventArgs e)\r
+ {\r
+ // Boilerplate, make sure to be on the GUI thread\r
+ if (InvokeRequired)\r
+ {\r
+ BeginInvoke(new MethodInvoker(() => Self_ChatFromSimulator(sender, e)));\r
+ return;\r
+ }\r
+\r
+ //txtChat.Text = e.Message;\r
+ }\r
+\r
+ private void btnBuild_Click(object sender, EventArgs e)\r
+ {\r
+ Button btn = sender as Button;\r
+\r
+ if (btn == null) return;\r
+\r
+ PrimType primType = (PrimType)Enum.Parse(typeof(PrimType), btn.Text);\r
+\r
+ this.BuildAndRez(primType);\r
+ }\r
+\r
+ private void BuildAndRez(PrimType primType)\r
+ {\r
+ float size, distance;\r
+ if (!float.TryParse(tbox_Size.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out size))\r
+ {\r
+ instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Invalid size", ChatBufferTextStyle.Error);\r
+ return;\r
+ }\r
+\r
+ if (!float.TryParse(tbox_Distance.Text, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out distance))\r
+ {\r
+ instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Invalid distance", ChatBufferTextStyle.Error);\r
+ return;\r
+ }\r
+\r
+ Primitive.ConstructionData primData = ObjectManager.BuildBasicShape(primType);\r
+\r
+ Vector3 rezpos = new Vector3(distance, 0, 0);\r
+ rezpos = client.Self.SimPosition + rezpos * client.Self.Movement.BodyRotation;\r
+\r
+ client.Objects.AddPrim(client.Network.CurrentSim, primData, UUID.Zero, rezpos, new Vector3(size), Quaternion.Identity);\r
+\r
+ instance.MainForm.TabConsole.DisplayNotificationInChat(pluginName + ": Object built and rezzed", ChatBufferTextStyle.Normal);\r
+ }\r
+\r
+ #endregion Implementation of the custom tab functionality\r
+\r
+ \r
+ }\r
+}\r