2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Collections.Generic;
35 using System.Text.RegularExpressions;
37 #if (COGBOT_LIBOMV || USE_STHREADS)
39 using Thread = ThreadPoolUtil.Thread;
40 using ThreadPool = ThreadPoolUtil.ThreadPool;
41 using Monitor = ThreadPoolUtil.Monitor;
43 using System.Threading;
45 using System.Windows.Forms;
46 using System.Resources;
49 using Radegast.Netcom;
51 using OpenMetaverse.StructuredData;
52 using OpenMetaverse.Assets;
56 public partial class frmMain : RadegastForm
58 #region Public members
59 public static ImageList ResourceImages = new ImageList();
60 public static List<string> ImageNames = new List<string>();
61 public bool PreventParcelUpdate = false;
62 public delegate void ProfileHandlerDelegate(string agentName, UUID agentID);
63 public ProfileHandlerDelegate ShowAgentProfile;
65 public TabsConsole TabConsole
67 get { return tabsConsole; }
70 public MapConsole WorldMap
76 return (MapConsole)MapTab.Control;
82 public RadegastTab MapTab
86 if (tabsConsole.TabExists("map"))
88 return tabsConsole.Tabs["map"];
97 public MediaConsole MediaConsole { get { return mediaConsole; } }
100 /// Drop down that contains the tools menu
102 public ToolStripDropDownButton ToolsMenu
104 get { return tbnTools; }
108 /// Dropdown that contains the heelp menu
110 public ToolStripDropDownButton HelpMenu
112 get { return tbtnHelp; }
116 /// Drop down that contants the plugins menu. Make sure to set it Visible if
117 /// you add items to this menu, it's hidden by default
119 public ToolStripDropDownButton PluginsMenu
121 get { return tbnPlugins; }
126 #region Private members
127 private RadegastInstance instance;
128 private GridClient client { get { return instance.Client; } }
129 private RadegastNetcom netcom { get { return instance.Netcom; } }
130 private TabsConsole tabsConsole;
131 private System.Timers.Timer statusTimer;
132 private AutoPilot ap;
133 private bool AutoPilotActive = false;
134 private TransparentButton btnDialogNextControl;
135 private MediaConsole mediaConsole;
138 #region Constructor and disposal
139 public frmMain(RadegastInstance instance)
142 InitializeComponent();
143 Disposed += new EventHandler(frmMain_Disposed);
145 this.instance = instance;
146 this.instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);
147 netcom.NetcomSync = this;
148 ShowAgentProfile = ShowAgentProfileInternal;
150 pnlDialog.Visible = false;
151 btnDialogNextControl = new TransparentButton();
152 pnlDialog.Controls.Add(btnDialogNextControl);
155 btnDialogNextControl.Size = new Size(35, 20);
156 btnDialogNextControl.BackColor = Color.Transparent;
157 btnDialogNextControl.ForeColor = Color.Gold;
158 btnDialogNextControl.FlatAppearance.BorderSize = 0;
159 btnDialogNextControl.FlatStyle = FlatStyle.Flat;
160 btnDialogNextControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
161 btnDialogNextControl.Text = ">>";
162 btnDialogNextControl.Font = new Font(btnDialogNextControl.Font, FontStyle.Bold);
163 btnDialogNextControl.Margin = new Padding(0);
164 btnDialogNextControl.Padding = new Padding(0);
165 btnDialogNextControl.UseVisualStyleBackColor = false;
166 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
167 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
168 btnDialogNextControl.Click += new EventHandler(btnDialogNextControl_Click);
170 if (instance.MonoRuntime)
172 statusStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
176 netcom.ClientLoginStatus += new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
177 netcom.ClientLoggedOut += new EventHandler(netcom_ClientLoggedOut);
178 netcom.ClientDisconnected += new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
179 instance.Names.NameUpdated += new EventHandler<UUIDNameReplyEventArgs>(Names_NameUpdated);
180 RegisterClientEvents(client);
182 InitializeStatusTimer();
183 RefreshWindowTitle();
186 private void RegisterClientEvents(GridClient client)
188 client.Parcels.ParcelProperties += new EventHandler<ParcelPropertiesEventArgs>(Parcels_ParcelProperties);
189 client.Self.MoneyBalanceReply += new EventHandler<MoneyBalanceReplyEventArgs>(Self_MoneyBalanceReply);
190 client.Self.MoneyBalance += new EventHandler<BalanceEventArgs>(Self_MoneyBalance);
193 private void UnregisterClientEvents(GridClient client)
195 client.Parcels.ParcelProperties -= new EventHandler<ParcelPropertiesEventArgs>(Parcels_ParcelProperties);
196 client.Self.MoneyBalanceReply -= new EventHandler<MoneyBalanceReplyEventArgs>(Self_MoneyBalanceReply);
197 client.Self.MoneyBalance -= new EventHandler<BalanceEventArgs>(Self_MoneyBalance);
200 void instance_ClientChanged(object sender, ClientChangedEventArgs e)
202 UnregisterClientEvents(e.OldClient);
203 RegisterClientEvents(client);
206 void frmMain_Disposed(object sender, EventArgs e)
210 netcom.NetcomSync = null;
211 netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
212 netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
213 netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
218 UnregisterClientEvents(client);
221 if (instance != null && instance.Names != null)
223 instance.Names.NameUpdated -= new EventHandler<UUIDNameReplyEventArgs>(Names_NameUpdated);
226 this.instance.CleanUp();
230 #region Event handlers
231 bool firstMoneyNotification = true;
232 void Self_MoneyBalance(object sender, BalanceEventArgs e)
235 int.TryParse(tlblMoneyBalance.Text, out oldBalance);
236 int delta = Math.Abs(oldBalance - e.Balance);
238 if (firstMoneyNotification)
240 firstMoneyNotification = false;
246 if (oldBalance > e.Balance)
248 instance.MediaManager.PlayUISound(UISounds.MoneyIn);
252 instance.MediaManager.PlayUISound(UISounds.MoneyOut);
258 void Names_NameUpdated(object sender, UUIDNameReplyEventArgs e)
260 if (!e.Names.ContainsKey(client.Self.AgentID)) return;
264 if (IsHandleCreated || !instance.MonoRuntime)
266 BeginInvoke(new MethodInvoker(() => Names_NameUpdated(sender, e)));
271 RefreshWindowTitle();
275 void Self_MoneyBalanceReply(object sender, MoneyBalanceReplyEventArgs e)
277 if (!String.IsNullOrEmpty(e.Description))
279 if (instance.GlobalSettings["transaction_notification_dialog"].AsBoolean())
280 AddNotification(new ntfGeneric(instance, e.Description));
281 if (instance.GlobalSettings["transaction_notification_chat"].AsBoolean())
282 TabConsole.DisplayNotificationInChat(e.Description);
286 public void InitializeControls()
288 InitializeTabsConsole();
290 if (instance.MediaManager.SoundSystemAvailable)
292 mediaConsole = new MediaConsole(instance);
293 tbtnMedia.Visible = true;
297 public bool InAutoReconnect { get; set; }
299 private void DisplayAutoReconnectForm()
301 if (IsDisposed) return;
305 BeginInvoke(new MethodInvoker(DisplayAutoReconnectForm));
309 InAutoReconnect = true;
310 frmReconnect dialog = new frmReconnect(instance, instance.GlobalSettings["reconnect_time"]);
311 dialog.ShowDialog(this);
316 public void BeginAutoReconnect()
318 // Sleep for 3 seconds on a separate thread while things unwind on
319 // disconnect, since ShowDialog() blocks GUI thread
320 (new Thread(new ThreadStart(() =>
322 System.Threading.Thread.Sleep(3000);
323 DisplayAutoReconnectForm();
327 Name = "Reconnect Delay Thread",
333 private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
335 if (e.Status == LoginStatus.Failed)
339 if (instance.GlobalSettings["auto_reconnect"].AsBoolean())
340 BeginAutoReconnect();
342 InAutoReconnect = false;
345 else if (e.Status == LoginStatus.Success)
347 InAutoReconnect = false;
348 reconnectToolStripMenuItem.Enabled = false;
349 loginToolStripMenuItem.Enabled = false;
350 tsb3D.Enabled = tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
351 tbtnGroups.Enabled = tbnObjects.Enabled = tbtnWorld.Enabled = tbnTools.Enabled = tmnuImport.Enabled =
352 tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = true;
355 RefreshWindowTitle();
359 private void netcom_ClientLoggedOut(object sender, EventArgs e)
361 tsb3D.Enabled = tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
362 tbtnGroups.Enabled = tbnObjects.Enabled = tbtnWorld.Enabled = tbnTools.Enabled = tmnuImport.Enabled =
363 tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = false;
365 reconnectToolStripMenuItem.Enabled = true;
366 loginToolStripMenuItem.Enabled = true;
367 InAutoReconnect = false;
369 if (statusTimer != null)
373 RefreshWindowTitle();
376 private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
378 firstMoneyNotification = true;
380 if (e.Reason == NetworkManager.DisconnectType.ClientInitiated) return;
381 netcom_ClientLoggedOut(sender, EventArgs.Empty);
383 if (instance.GlobalSettings["auto_reconnect"].AsBoolean())
385 BeginAutoReconnect();
389 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
391 if (statusTimer != null)
394 statusTimer.Dispose();
398 if (mediaConsole != null)
400 if (tabsConsole.TabExists("media"))
402 tabsConsole.Tabs["media"].AllowClose = true;
403 tabsConsole.Tabs["media"].Close();
407 mediaConsole.Dispose();
412 if (netcom.IsLoggedIn)
414 Thread saveInvToDisk = new Thread(new ThreadStart(
417 client.Inventory.Store.SaveToDisk(instance.InventoryCacheFileName);
419 saveInvToDisk.Name = "Save inventory to disk";
420 saveInvToDisk.Start();
427 # region Update status
429 void Parcels_ParcelProperties(object sender, ParcelPropertiesEventArgs e)
431 if (PreventParcelUpdate || e.Result != ParcelResult.Single) return;
434 BeginInvoke(new MethodInvoker(() => Parcels_ParcelProperties(sender, e)));
438 Parcel parcel = instance.State.Parcel = e.Parcel;
440 tlblParcel.Text = parcel.Name;
441 tlblParcel.ToolTipText = parcel.Desc;
443 if ((parcel.Flags & ParcelFlags.AllowFly) != ParcelFlags.AllowFly)
444 icoNoFly.Visible = true;
446 icoNoFly.Visible = false;
448 if ((parcel.Flags & ParcelFlags.CreateObjects) != ParcelFlags.CreateObjects)
449 icoNoBuild.Visible = true;
451 icoNoBuild.Visible = false;
453 if ((parcel.Flags & ParcelFlags.AllowOtherScripts) != ParcelFlags.AllowOtherScripts)
454 icoNoScript.Visible = true;
456 icoNoScript.Visible = false;
458 if ((parcel.Flags & ParcelFlags.RestrictPushObject) == ParcelFlags.RestrictPushObject)
459 icoNoPush.Visible = true;
461 icoNoPush.Visible = false;
463 if ((parcel.Flags & ParcelFlags.AllowDamage) == ParcelFlags.AllowDamage)
464 icoHealth.Visible = true;
466 icoHealth.Visible = false;
468 if ((parcel.Flags & ParcelFlags.AllowVoiceChat) != ParcelFlags.AllowVoiceChat)
469 icoNoVoice.Visible = true;
471 icoNoVoice.Visible = false;
474 private void RefreshStatusBar()
476 if (netcom.IsLoggedIn)
478 tlblLoginName.Text = instance.Names.Get(client.Self.AgentID, client.Self.Name);
479 tlblMoneyBalance.Text = client.Self.Balance.ToString();
480 icoHealth.Text = client.Self.Health.ToString() + "%";
482 var cs = client.Network.CurrentSim;
483 tlblRegionInfo.Text =
484 (cs == null ? "No region" : cs.Name) +
485 " (" + Math.Floor(client.Self.SimPosition.X).ToString() + ", " +
486 Math.Floor(client.Self.SimPosition.Y).ToString() + ", " +
487 Math.Floor(client.Self.SimPosition.Z).ToString() + ")";
491 tlblLoginName.Text = "Offline";
492 tlblMoneyBalance.Text = "0";
493 icoHealth.Text = "0%";
494 tlblRegionInfo.Text = "No Region";
495 tlblParcel.Text = "No Parcel";
497 icoHealth.Visible = false;
498 icoNoBuild.Visible = false;
499 icoNoFly.Visible = false;
500 icoNoPush.Visible = false;
501 icoNoScript.Visible = false;
502 icoNoVoice.Visible = false;
506 private void RefreshWindowTitle()
508 string name = instance.Names.Get(client.Self.AgentID, client.Self.Name);
509 StringBuilder sb = new StringBuilder();
510 sb.Append("Radegast - ");
512 if (netcom.IsLoggedIn)
514 sb.Append("[" + name + "]");
516 if (instance.State.IsAway)
518 sb.Append(" - Away");
519 if (instance.State.IsBusy) sb.Append(", Busy");
521 else if (instance.State.IsBusy)
523 sb.Append(" - Busy");
526 if (instance.State.IsFollowing)
528 sb.Append(" - Following ");
529 sb.Append(instance.State.FollowName);
534 sb.Append("Logged Out");
537 this.Text = sb.ToString();
539 // When minimized to tray, update tray tool tip also
540 if (WindowState == FormWindowState.Minimized && instance.GlobalSettings["minimize_to_tray"])
542 trayIcon.Text = sb.ToString();
543 ctxTrayMenuLabel.Text = sb.ToString();
549 private void InitializeStatusTimer()
551 statusTimer = new System.Timers.Timer(250);
552 statusTimer.SynchronizingObject = this;
553 statusTimer.Elapsed += new ElapsedEventHandler(statusTimer_Elapsed);
556 private void statusTimer_Elapsed(object sender, ElapsedEventArgs e)
558 // Mono sometimes fires timer after is's disposed
561 RefreshWindowTitle();
568 #region Initialization, configuration, and key shortcuts
569 private void InitializeTabsConsole()
571 tabsConsole = new TabsConsole(instance);
572 tabsConsole.Dock = DockStyle.Fill;
573 toolStripContainer1.ContentPanel.Controls.Add(tabsConsole);
576 private void frmMain_KeyDown(object sender, KeyEventArgs e)
578 // Ctrl-Alt-Shift-H Say "Hippos!" in chat
579 if (e.Modifiers == (Keys.Control | Keys.Shift | Keys.Alt) && e.KeyCode == Keys.H)
581 e.Handled = e.SuppressKeyPress = true;
582 netcom.ChatOut("Hippos!", ChatType.Normal, 0);
586 // Ctrl-Shift-1 (sim/parcel info)
587 if (e.Modifiers == (Keys.Control | Keys.Shift) && e.KeyCode == Keys.D1)
589 e.Handled = e.SuppressKeyPress = true;
590 DisplayRegionParcelConsole();
595 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.W)
597 e.Handled = e.SuppressKeyPress = true;
598 RadegastTab tab = tabsConsole.SelectedTab;
604 else if (tab.AllowHide)
612 // Ctl-Shift-H: Teleport Home
613 if (e.Modifiers == (Keys.Control | Keys.Shift) && e.KeyCode == Keys.H)
615 e.Handled = e.SuppressKeyPress = true;
616 tmnuTeleportHome.PerformClick();
620 // Alt-Ctrl-D Open debug console
621 if (e.Modifiers == (Keys.Control | Keys.Alt) && e.KeyCode == Keys.D)
623 e.Handled = e.SuppressKeyPress = true;
624 debugConsoleToolStripMenuItem.PerformClick();
628 // Alt 1-8: Toggle various tabs
629 if (e.Modifiers == Keys.Alt)
634 e.Handled = e.SuppressKeyPress = true;
635 tabsConsole.Tabs["chat"].Select();
639 e.Handled = e.SuppressKeyPress = true;
640 tbtnFriends.PerformClick();
644 e.Handled = e.SuppressKeyPress = true;
645 tbtnGroups.PerformClick();
649 e.Handled = e.SuppressKeyPress = true;
650 tbtnInventory.PerformClick();
654 e.Handled = e.SuppressKeyPress = true;
655 tbtnSearch.PerformClick();
659 e.Handled = e.SuppressKeyPress = true;
660 tbtnMap.PerformClick();
664 e.Handled = e.SuppressKeyPress = true;
665 tbnObjects.PerformClick();
669 e.Handled = e.SuppressKeyPress = true;
670 tbtnMedia.PerformClick();
674 e.Handled = e.SuppressKeyPress = true;
675 tbtnVoice.PerformClick();
680 // ctrl-g, goto slurl
681 if (e.Control && e.KeyCode == Keys.G)
683 if (!ProcessLink(Clipboard.GetText(), true))
684 MapToCurrentLocation();
686 e.Handled = e.SuppressKeyPress = true;
690 // ctrl-(shift)-tab for next/previous tab
691 if (e.Control && e.KeyCode == Keys.Tab)
695 TabConsole.SelectPreviousTab();
699 TabConsole.SelectNextTab();
701 e.Handled = e.SuppressKeyPress = true;
706 bool firstLoad = true;
708 private void frmMain_Load(object sender, EventArgs e)
713 tabsConsole.SelectTab("login");
714 ResourceManager rm = Properties.Resources.ResourceManager;
715 ResourceSet set = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
716 System.Collections.IDictionaryEnumerator de = set.GetEnumerator();
717 while (de.MoveNext() == true)
719 if (de.Entry.Value is Image)
721 Bitmap bitMap = de.Entry.Value as Bitmap;
722 ResourceImages.Images.Add(bitMap);
723 ImageNames.Add(de.Entry.Key.ToString());
726 StartUpdateCheck(false);
728 if (instance.PlainColors)
730 pnlDialog.BackColor = System.Drawing.Color.FromArgb(120, 220, 255);
737 #region Public methods
739 private Dictionary<UUID, frmProfile> shownProfiles = new Dictionary<UUID, frmProfile>();
741 void ShowAgentProfileInternal(string name, UUID agentID)
745 frmProfile profile = null;
746 if (shownProfiles.TryGetValue(agentID, out profile))
748 profile.WindowState = FormWindowState.Normal;
753 profile = new frmProfile(instance, name, agentID);
755 profile.Disposed += (object sender, EventArgs e) =>
759 frmProfile agentProfile = (frmProfile)sender;
760 if (shownProfiles.ContainsKey(agentProfile.AgentID))
761 shownProfiles.Remove(agentProfile.AgentID);
767 shownProfiles.Add(agentID, profile);
772 private Dictionary<UUID, frmGroupInfo> shownGroupProfiles = new Dictionary<UUID, frmGroupInfo>();
774 public void ShowGroupProfile(UUID id)
776 ShowGroupProfile(new OpenMetaverse.Group()
782 public void ShowGroupProfile(AvatarGroup group)
784 ShowGroupProfile(new OpenMetaverse.Group()
787 InsigniaID = group.GroupInsigniaID,
788 Name = group.GroupName
793 public void ShowGroupProfile(OpenMetaverse.Group group)
797 BeginInvoke(new MethodInvoker(() => ShowGroupProfile(group)));
801 lock (shownGroupProfiles)
803 frmGroupInfo profile = null;
804 if (shownGroupProfiles.TryGetValue(group.ID, out profile))
806 profile.WindowState = FormWindowState.Normal;
811 profile = new frmGroupInfo(instance, group);
813 profile.Disposed += (object sender, EventArgs e) =>
815 lock (shownGroupProfiles)
817 frmGroupInfo groupProfile = (frmGroupInfo)sender;
818 if (shownGroupProfiles.ContainsKey(groupProfile.Group.ID))
819 shownGroupProfiles.Remove(groupProfile.Group.ID);
825 shownGroupProfiles.Add(group.ID, profile);
830 public bool ProcessSecondlifeURI(string link)
832 // First try if we have a region name, assume it's a teleport link if we have
833 Regex r = new Regex(@"^(secondlife://)(?<region>[^/$]+)(/(?<x>\d+))?((/?<y>\d+))?(/(?<z>\d+))?",
834 RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
835 Match m = r.Match(link);
839 string region = HttpUtility.UrlDecode(m.Groups["region"].Value);
840 int x = string.IsNullOrEmpty(m.Groups["x"].Value) ? 128 : int.Parse(m.Groups["x"].Value);
841 int y = string.IsNullOrEmpty(m.Groups["y"].Value) ? 128 : int.Parse(m.Groups["y"].Value);
842 int z = string.IsNullOrEmpty(m.Groups["z"].Value) ? 0 : int.Parse(m.Groups["z"].Value);
844 WorldMap.DisplayLocation(region, x, y, z);
848 // Is it group profile link
849 r = new Regex(@"^secondlife:///app/group/(?<id>[^/]+)/about",
850 RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
856 if (UUID.TryParse(m.Groups["id"].Value, out id))
858 ShowGroupProfile(id);
864 // Is it user profile link
865 r = new Regex(@"^secondlife:///app/agent/(?<id>[^/]+)/about",
866 RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase);
872 if (UUID.TryParse(m.Groups["id"].Value, out id))
874 ShowAgentProfile(instance.Names.Get(id), id);
883 public void ProcessLink(string link)
885 ProcessLink(link, false);
888 public bool ProcessLink(string link, bool onlyMap)
890 var pos = link.IndexOf(RRichTextBox.LinkSeparator);
893 link = link.Substring(pos + 1);
896 if (link.StartsWith("secondlife://"))
898 return ProcessSecondlifeURI(link);
901 if (!link.Contains("://"))
903 link = "http://" + link;
906 Regex r = new Regex(@"^(http://(slurl\.com|maps\.secondlife\.com)/secondlife/|secondlife://)(?<region>[^/]+)/(?<x>\d+)/(?<y>\d+)(/(?<z>\d+))?",
907 RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase
909 Match m = r.Match(link);
913 string region = HttpUtility.UrlDecode(m.Groups["region"].Value);
914 int x = int.Parse(m.Groups["x"].Value);
915 int y = int.Parse(m.Groups["y"].Value);
918 if (!string.IsNullOrEmpty(m.Groups["z"].Value))
920 z = int.Parse(m.Groups["z"].Value);
924 WorldMap.DisplayLocation(region, x, y, z);
929 System.Diagnostics.Process.Start(link);
935 #region Notifications
936 CircularList<Control> notifications = new CircularList<Control>();
938 public Color NotificationBackground
940 get { return pnlDialog.BackColor; }
943 void ResizeNotificationByControl(Control active)
945 int Width = active.Size.Width + 6;
946 int Height = notifications.Count > 1 ? active.Size.Height + 3 + btnDialogNextControl.Size.Height : active.Size.Height + 3;
947 pnlDialog.Size = new Size(Width, Height);
949 pnlDialog.Left = pnlDialog.Parent.ClientSize.Width - Width;
951 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
952 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
954 btnDialogNextControl.BringToFront();
957 public void AddNotification(Control control)
961 BeginInvoke(new MethodInvoker(delegate()
963 AddNotification(control);
969 Control active = TabsConsole.FindFocusedControl(this);
971 FormFlash.StartFlash(this);
972 pnlDialog.Visible = true;
973 pnlDialog.BringToFront();
975 foreach (Control existing in notifications)
977 existing.Visible = false;
980 notifications.Add(control);
981 control.Visible = true;
982 control.Anchor = AnchorStyles.Top | AnchorStyles.Left;
985 pnlDialog.Controls.Add(control);
986 ResizeNotificationByControl(control);
988 btnDialogNextControl.Visible = notifications.Count > 1;
996 public void RemoveNotification(Control control)
998 pnlDialog.Controls.Remove(control);
999 notifications.Remove(control);
1002 if (notifications.HasNext)
1004 pnlDialog.Visible = true;
1005 Control active = notifications.Next;
1006 active.Visible = true;
1007 ResizeNotificationByControl(active);
1011 pnlDialog.Visible = false;
1014 btnDialogNextControl.Visible = notifications.Count > 1;
1017 private void btnDialogNextControl_Click(object sender, EventArgs e)
1019 foreach (Control existing in notifications)
1021 existing.Visible = false;
1024 if (notifications.HasNext)
1026 pnlDialog.Visible = true;
1027 Control active = notifications.Next;
1028 active.Visible = true;
1029 ResizeNotificationByControl(active);
1033 pnlDialog.Visible = false;
1037 #endregion Notifications
1039 #region Menu click handlers
1041 private void tmnuStatusAway_Click(object sender, EventArgs e)
1043 instance.State.SetAway(tmnuStatusAway.Checked);
1046 private void tmnuHelpReadme_Click(object sender, EventArgs e)
1048 System.Diagnostics.Process.Start(Application.StartupPath + @"\Readme.txt");
1051 private void tmnuStatusBusy_Click(object sender, EventArgs e)
1053 instance.State.SetBusy(tmnuStatusBusy.Checked);
1056 private void tmnuControlFly_Click(object sender, EventArgs e)
1058 instance.State.SetFlying(tmnuControlFly.Checked);
1061 private void tmnuControlAlwaysRun_Click(object sender, EventArgs e)
1063 instance.State.SetAlwaysRun(tmnuControlAlwaysRun.Checked);
1066 private void tmnuPrefs_Click(object sender, EventArgs e)
1068 (new frmSettings(instance)).ShowDialog();
1071 private void tbtnAppearance_Click(object sender, EventArgs e)
1073 client.Appearance.RequestSetAppearance(false);
1076 private void importObjectToolStripMenuItem_Click(object sender, EventArgs e)
1078 PrimDeserializer.ImportFromFile(client);
1081 private void autopilotToolStripMenuItem_Click(object sender, EventArgs e)
1085 ap = new AutoPilot(client);
1087 ap.InsertWaypoint(new Vector3(66, 163, 21));
1088 ap.InsertWaypoint(new Vector3(66, 98, 21));
1090 ap.InsertWaypoint(new Vector3(101, 98, 21));
1091 ap.InsertWaypoint(new Vector3(101, 45, 21));
1092 ap.InsertWaypoint(new Vector3(93, 27, 21));
1093 ap.InsertWaypoint(new Vector3(106, 12, 21));
1094 ap.InsertWaypoint(new Vector3(123, 24, 21));
1095 ap.InsertWaypoint(new Vector3(114, 45, 21));
1096 ap.InsertWaypoint(new Vector3(114, 98, 21));
1098 ap.InsertWaypoint(new Vector3(130, 98, 21));
1099 ap.InsertWaypoint(new Vector3(130, 163, 21));
1101 ap.InsertWaypoint(new Vector3(64, 68, 21));
1102 ap.InsertWaypoint(new Vector3(65, 20, 21));
1103 ap.InsertWaypoint(new Vector3(33, 23, 21));
1104 ap.InsertWaypoint(new Vector3(17, 39, 21));
1105 ap.InsertWaypoint(new Vector3(17, 62, 21));
1109 if (AutoPilotActive)
1111 AutoPilotActive = false;
1116 AutoPilotActive = true;
1122 private void cleanCacheToolStripMenuItem_Click(object sender, EventArgs e)
1124 WorkPool.QueueUserWorkItem(sync => client.Assets.Cache.Clear());
1125 instance.Names.CleanCache();
1128 private void rebakeTexturesToolStripMenuItem_Click(object sender, EventArgs e)
1130 instance.COF.RebakeTextures();
1133 public void MapToCurrentLocation()
1135 if (MapTab != null && client.Network.Connected)
1138 WorldMap.DisplayLocation(client.Network.CurrentSim.Name,
1139 (int)client.Self.SimPosition.X,
1140 (int)client.Self.SimPosition.Y,
1141 (int)client.Self.SimPosition.Z);
1145 private void standToolStripMenuItem_Click(object sender, EventArgs e)
1147 instance.State.SetSitting(false, UUID.Zero);
1150 private void groundSitToolStripMenuItem_Click(object sender, EventArgs e)
1152 client.Self.SitOnGround();
1155 private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)
1157 try { System.Diagnostics.Process.Start(Application.ExecutablePath); }
1158 catch (Exception) { }
1161 private void tmnuExit_Click(object sender, EventArgs e)
1166 private void tlblRegionInfo_Click(object sender, EventArgs e)
1168 if (WorldMap != null && client.Network.Connected)
1174 private void scriptEditorToolStripMenuItem_Click(object sender, EventArgs e)
1176 ScriptEditor se = new ScriptEditor(instance);
1177 se.Dock = DockStyle.Fill;
1181 private void tmnuSetHome_Click(object sender, EventArgs e)
1183 client.Self.SetHome();
1186 private void tmnuCreateLandmark_Click(object sender, EventArgs e)
1188 string location = string.Format(", {0} ({1}, {2}, {3})",
1189 client.Network.CurrentSim.Name,
1190 (int)client.Self.SimPosition.X,
1191 (int)client.Self.SimPosition.Y,
1192 (int)client.Self.SimPosition.Z
1195 string name = tlblParcel.Text;
1196 int maxLen = 63 - location.Length;
1198 if (name.Length > maxLen)
1199 name = name.Substring(0, maxLen);
1203 client.Inventory.RequestCreateItem(
1204 client.Inventory.FindFolderForType(AssetType.Landmark),
1206 tlblParcel.ToolTipText,
1209 InventoryType.Landmark,
1211 (bool success, InventoryItem item) =>
1215 BeginInvoke(new MethodInvoker(() =>
1217 Landmark ln = new Landmark(instance, (InventoryLandmark)item);
1218 ln.Dock = DockStyle.Fill;
1227 private void timerWorldClock_Tick(object sender, EventArgs e)
1229 lblTime.Text = instance.GetWorldTime().ToString("h:mm tt", System.Globalization.CultureInfo.InvariantCulture);
1232 private void reportBugsToolStripMenuItem_Click(object sender, EventArgs e)
1234 ProcessLink("http://jira.openmetaverse.org/browse/RAD");
1237 private void aboutRadegastToolStripMenuItem_Click(object sender, EventArgs e)
1239 (new frmAbout(instance)).ShowDialog();
1242 #region Update Checking
1243 private UpdateChecker updateChecker = null;
1244 private bool ManualUpdateCheck = false;
1246 public void StartUpdateCheck(bool userInitiated)
1248 ManualUpdateCheck = userInitiated;
1250 if (updateChecker != null)
1252 if (ManualUpdateCheck)
1253 tabsConsole.DisplayNotificationInChat("Update check already in progress.");
1257 if (ManualUpdateCheck)
1258 tabsConsole.DisplayNotificationInChat("Checking for updates...", ChatBufferTextStyle.StatusBlue);
1259 updateChecker = new UpdateChecker();
1260 updateChecker.OnUpdateInfoReceived += new UpdateChecker.UpdateInfoCallback(OnUpdateInfoReceived);
1261 updateChecker.StartCheck();
1264 private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
1266 tabsConsole.SelectTab("chat");
1267 StartUpdateCheck(true);
1270 void OnUpdateInfoReceived(object sender, UpdateCheckerArgs e)
1274 BeginInvoke(new MethodInvoker(() => OnUpdateInfoReceived(sender, e)));
1280 if (ManualUpdateCheck)
1281 tabsConsole.DisplayNotificationInChat("Error: Failed connecting to the update site.", ChatBufferTextStyle.StatusBlue);
1285 if (!ManualUpdateCheck && e.Info.DisplayMOTD)
1287 tabsConsole.DisplayNotificationInChat(e.Info.MOTD, ChatBufferTextStyle.StatusBlue);
1290 if (e.Info.UpdateAvailable)
1292 tabsConsole.DisplayNotificationInChat("New version available at " + e.Info.DownloadSite, ChatBufferTextStyle.Alert);
1296 if (ManualUpdateCheck)
1297 tabsConsole.DisplayNotificationInChat("Your version is up to date.", ChatBufferTextStyle.StatusBlue);
1301 updateChecker.Dispose();
1302 updateChecker = null;
1306 private void ToggleHidden(string tabName)
1308 if (!tabsConsole.TabExists(tabName)) return;
1310 RadegastTab tab = tabsConsole.Tabs[tabName];
1329 private void tbtnFriends_Click(object sender, EventArgs e)
1331 ToggleHidden("friends");
1334 private void tbtnInventory_Click(object sender, EventArgs e)
1336 ToggleHidden("inventory");
1339 private void tbtnSearch_Click(object sender, EventArgs e)
1341 ToggleHidden("search");
1344 private void tbtnGroups_Click(object sender, EventArgs e)
1346 ToggleHidden("groups");
1349 private void tbtnVoice_Click(object sender, EventArgs e)
1351 ToggleHidden("voice");
1354 private void tbtnMedia_Click(object sender, EventArgs e)
1356 if (tabsConsole.TabExists("media"))
1358 ToggleHidden("media");
1362 RadegastTab tab = tabsConsole.AddTab("media", "Media", mediaConsole);
1363 tab.AllowClose = false;
1364 tab.AllowHide = true;
1369 private void debugConsoleToolStripMenuItem_Click(object sender, EventArgs e)
1371 if (tabsConsole.TabExists("debug"))
1373 ToggleHidden("debug");
1377 RadegastTab tab = tabsConsole.AddTab("debug", "Debug", new DebugConsole(instance));
1378 tab.AllowClose = false;
1379 tab.AllowHide = true;
1384 private void tbnObjects_Click(object sender, EventArgs e)
1386 if (tabsConsole.TabExists("objects"))
1388 RadegastTab tab = tabsConsole.Tabs["objects"];
1392 ((ObjectsConsole)tab.Control).RefreshObjectList();
1401 RadegastTab tab = tabsConsole.AddTab("objects", "Objects", new ObjectsConsole(instance));
1402 tab.AllowClose = true;
1403 tab.AllowDetach = true;
1405 tab.AllowHide = false;
1407 ((ObjectsConsole)tab.Control).RefreshObjectList();
1411 private void tbtnMap_Click(object sender, EventArgs e)
1413 if (MapTab == null) return; // too soon!
1415 ToggleHidden("map");
1417 MapToCurrentLocation();
1420 private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
1422 if (client.Network.Connected)
1423 client.Network.RequestLogout();
1426 private void reconnectToolStripMenuItem_Click(object sender, EventArgs e)
1428 if (!client.Network.Connected)
1430 instance.Reconnect();
1434 private frmKeyboardShortcuts keyboardShortcutsForm = null;
1435 private void keyboardShortcutsToolStripMenuItem_Click(object sender, EventArgs e)
1437 if (keyboardShortcutsForm != null)
1439 keyboardShortcutsForm.Focus();
1443 keyboardShortcutsForm = new frmKeyboardShortcuts(instance);
1445 keyboardShortcutsForm.Disposed += (object senderx, EventArgs ex) =>
1447 if (components != null)
1449 components.Remove(keyboardShortcutsForm);
1451 keyboardShortcutsForm = null;
1454 keyboardShortcutsForm.Show(this);
1455 keyboardShortcutsForm.Top = Top + 100;
1456 keyboardShortcutsForm.Left = Left + 100;
1458 if (components != null)
1460 components.Add(keyboardShortcutsForm);
1465 // Menu item for testing out stuff
1466 private void testToolStripMenuItem_Click(object sender, EventArgs e)
1470 private void reloadInventoryToolStripMenuItem_Click(object sender, EventArgs e)
1472 if (tabsConsole.TabExists("inventory"))
1474 ((InventoryConsole)tabsConsole.Tabs["inventory"].Control).ReloadInventory();
1475 tabsConsole.Tabs["inventory"].Select();
1479 private void btnLoadScript_Click(object sender, EventArgs e)
1481 if (!TabConsole.TabExists("plugin_manager"))
1483 TabConsole.AddTab("plugin_manager", "Plugins", new PluginsTab(instance));
1485 TabConsole.Tabs["plugin_manager"].Select();
1488 private void frmMain_Resize(object sender, EventArgs e)
1490 if (WindowState == FormWindowState.Minimized && instance.GlobalSettings["minimize_to_tray"].AsBoolean())
1492 if (TabConsole.TabExists("scene_window") && !TabConsole.Tabs["scene_window"].Detached)
1494 TabConsole.Tabs["scene_window"].Close();
1496 ShowInTaskbar = false;
1497 trayIcon.Visible = true;
1498 FormBorderStyle = FormBorderStyle.SizableToolWindow;
1502 private void treyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
1504 WindowState = FormWindowState.Normal;
1505 ShowInTaskbar = true;
1506 trayIcon.Visible = false;
1507 FormBorderStyle = FormBorderStyle.Sizable;
1510 private void ctxTreyRestore_Click(object sender, EventArgs e)
1512 treyIcon_MouseDoubleClick(this, null);
1515 private void ctxTreyExit_Click(object sender, EventArgs e)
1517 tmnuExit_Click(this, EventArgs.Empty);
1520 private void tmnuTeleportHome_Click(object sender, EventArgs e)
1522 TabConsole.DisplayNotificationInChat("Teleporting home...");
1523 client.Self.RequestTeleport(UUID.Zero);
1526 private void stopAllAnimationsToolStripMenuItem_Click(object sender, EventArgs e)
1528 instance.State.StopAllAnimations();
1531 public void DisplayRegionParcelConsole()
1533 if (tabsConsole.TabExists("current region info"))
1535 tabsConsole.Tabs["current region info"].Select();
1536 (tabsConsole.Tabs["current region info"].Control as RegionInfo).UpdateDisplay();
1540 tabsConsole.AddTab("current region info", "Region info", new RegionInfo(instance));
1541 tabsConsole.Tabs["current region info"].Select();
1545 private void regionParcelToolStripMenuItem_Click(object sender, EventArgs e)
1547 DisplayRegionParcelConsole();
1550 private void tlblParcel_Click(object sender, EventArgs e)
1552 DisplayRegionParcelConsole();
1555 private void changeMyDisplayNameToolStripMenuItem_Click(object sender, EventArgs e)
1557 if (!client.Avatars.DisplayNamesAvailable())
1559 tabsConsole.DisplayNotificationInChat("This grid does not support display names.", ChatBufferTextStyle.Error);
1563 var dlg = new DisplayNameChange(instance);
1567 private void muteListToolStripMenuItem_Click(object sender, EventArgs e)
1569 if (!tabsConsole.TabExists("mute list console"))
1571 tabsConsole.AddTab("mute list console", "Mute list", new MuteList(instance));
1573 tabsConsole.Tabs["mute list console"].Select();
1576 private void uploadImageToolStripMenuItem_Click(object sender, EventArgs e)
1578 if (!tabsConsole.TabExists("image upload console"))
1580 tabsConsole.AddTab("image upload console", "Upload image", new ImageUploadConsole(instance));
1582 tabsConsole.Tabs["image upload console"].Select();
1586 private void myAttachmentsToolStripMenuItem_Click(object sender, EventArgs e)
1588 Avatar av = client.Network.CurrentSim.ObjectsAvatars.Find((Avatar a) => { return a.ID == client.Self.AgentID; });
1592 tabsConsole.DisplayNotificationInChat("Unable to find my avatar!", ChatBufferTextStyle.Error);
1596 if (!instance.TabConsole.TabExists("AT: " + av.ID.ToString()))
1598 instance.TabConsole.AddTab("AT: " + av.ID.ToString(), "My Attachments", new AttachmentTab(instance, av));
1600 instance.TabConsole.SelectTab("AT: " + av.ID.ToString());
1604 private void tsb3D_Click(object sender, EventArgs e)
1606 if (instance.TabConsole.TabExists("scene_window"))
1608 instance.TabConsole.Tabs["scene_window"].Select();
1612 var control = new Rendering.SceneWindow(instance);
1613 control.Dock = DockStyle.Fill;
1614 instance.TabConsole.AddTab("scene_window", "Scene Viewer", control);
1615 instance.TabConsole.Tabs["scene_window"].Floater = false;
1616 instance.TabConsole.Tabs["scene_window"].CloseOnDetachedClose = true;
1617 control.RegisterTabEvents();
1619 if (instance.GlobalSettings["scene_window_docked"])
1621 instance.TabConsole.Tabs["scene_window"].Select();
1625 instance.TabConsole.Tabs["scene_window"].Detach(instance);
1630 private void loginToolStripMenuItem_Click(object sender, EventArgs e)
1632 // We are logging in without exiting the client
1633 // Mark last run as successful
1634 instance.MarkEndExecution();
1635 TabConsole.InitializeMainTab();
1636 TabConsole.Tabs["login"].Select();