Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.76 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Radegast;
  10. using OpenMetaverse;
  11.  
  12. namespace DemoTab
  13. {
  14.     [Radegast.Plugin(Name = "Demo Tab", Description = "Demonstration of how to add a new tab via plugin", Version = "1.0")]
  15.     public partial class DemoTab : RadegastTabControl, IRadegastPlugin
  16.     {
  17.         ToolStripMenuItem ActivateTabButton;
  18.  
  19.         public DemoTab()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.  
  24.         public void StartPlugin(RadegastInstance inst)
  25.         {
  26.             this.instance = inst;
  27.             ActivateTabButton = new ToolStripMenuItem("Demo Tab", null, MenuButtonClicked);
  28.             instance.MainForm.PluginsMenu.DropDownItems.Add(ActivateTabButton);
  29.             instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);
  30.             RegisterClientEvents(client);
  31.         }
  32.  
  33.         public void StopPlugin(RadegastInstance inst)
  34.         {
  35.             ActivateTabButton.Dispose();
  36.             instance.TabConsole.RemoveTab("demo_tab");
  37.             UnregisterClientEvents(client);
  38.         }
  39.  
  40.         void instance_ClientChanged(object sender, ClientChangedEventArgs e)
  41.         {
  42.             UnregisterClientEvents(e.OldClient);
  43.             RegisterClientEvents(e.Client);
  44.         }
  45.  
  46.  
  47.         void RegisterClientEvents(GridClient client)
  48.         {
  49.             client.Self.ChatFromSimulator += new EventHandler<ChatEventArgs>(Self_ChatFromSimulator);
  50.         }
  51.  
  52.         void UnregisterClientEvents(GridClient client)
  53.         {
  54.             if (client == null) return;
  55.             client.Self.ChatFromSimulator -= new EventHandler<ChatEventArgs>(Self_ChatFromSimulator);
  56.         }
  57.  
  58.         void Self_ChatFromSimulator(object sender, ChatEventArgs e)
  59.         {
  60.             // Boilerplate, make sure to be on the GUI thread
  61.             if (InvokeRequired)
  62.             {
  63.                 BeginInvoke(new MethodInvoker(() => Self_ChatFromSimulator(sender, e)));
  64.                 return;
  65.             }
  66.  
  67.             txtChat.Text = e.Message;
  68.         }
  69.  
  70.  
  71.         void MenuButtonClicked(object sender, EventArgs e)
  72.         {
  73.             if (instance.TabConsole.TabExists("demo_tab"))
  74.             {
  75.                 instance.TabConsole.Tabs["demo_tab"].Select();
  76.             }
  77.             else
  78.             {
  79.                 instance.TabConsole.AddTab("demo_tab", "Demo Tab", this);
  80.                 instance.TabConsole.Tabs["demo_tab"].Select();
  81.             }
  82.         }
  83.  
  84.         private void btnSaySomething_Click(object sender, EventArgs e)
  85.         {
  86.             client.Self.Chat("Something", 0, ChatType.Normal);
  87.         }
  88.  
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement