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() && e.FailReason != "tos")
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);
1079 DisplayImportConsole();
1082 private void autopilotToolStripMenuItem_Click(object sender, EventArgs e)
1086 ap = new AutoPilot(client);
1088 ap.InsertWaypoint(new Vector3(66, 163, 21));
1089 ap.InsertWaypoint(new Vector3(66, 98, 21));
1091 ap.InsertWaypoint(new Vector3(101, 98, 21));
1092 ap.InsertWaypoint(new Vector3(101, 45, 21));
1093 ap.InsertWaypoint(new Vector3(93, 27, 21));
1094 ap.InsertWaypoint(new Vector3(106, 12, 21));
1095 ap.InsertWaypoint(new Vector3(123, 24, 21));
1096 ap.InsertWaypoint(new Vector3(114, 45, 21));
1097 ap.InsertWaypoint(new Vector3(114, 98, 21));
1099 ap.InsertWaypoint(new Vector3(130, 98, 21));
1100 ap.InsertWaypoint(new Vector3(130, 163, 21));
1102 ap.InsertWaypoint(new Vector3(64, 68, 21));
1103 ap.InsertWaypoint(new Vector3(65, 20, 21));
1104 ap.InsertWaypoint(new Vector3(33, 23, 21));
1105 ap.InsertWaypoint(new Vector3(17, 39, 21));
1106 ap.InsertWaypoint(new Vector3(17, 62, 21));
1110 if (AutoPilotActive)
1112 AutoPilotActive = false;
1117 AutoPilotActive = true;
1125 private void deleteFolder(DirectoryInfo dir)
1127 foreach (var file in dir.GetFiles())
1137 foreach (var subDir in dir.GetDirectories())
1139 deleteFolder(subDir);
1142 try { dir.Delete(); }
1146 private void cleanCacheToolStripMenuItem_Click(object sender, EventArgs e)
1148 WorkPool.QueueUserWorkItem(sync =>
1151 try { deleteFolder(new DirectoryInfo(client.Settings.ASSET_CACHE_DIR)); }
1153 Logger.DebugLog("Wiped out " + filesDeleted + " files from the cache directory.");
1155 instance.Names.CleanCache();
1158 private void rebakeTexturesToolStripMenuItem_Click(object sender, EventArgs e)
1160 instance.COF.RebakeTextures();
1163 public void MapToCurrentLocation()
1165 if (MapTab != null && client.Network.Connected)
1168 WorldMap.DisplayLocation(client.Network.CurrentSim.Name,
1169 (int)client.Self.SimPosition.X,
1170 (int)client.Self.SimPosition.Y,
1171 (int)client.Self.SimPosition.Z);
1175 private void standToolStripMenuItem_Click(object sender, EventArgs e)
1177 instance.State.SetSitting(false, UUID.Zero);
1180 private void groundSitToolStripMenuItem_Click(object sender, EventArgs e)
1182 client.Self.SitOnGround();
1185 private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)
1187 try { System.Diagnostics.Process.Start(Application.ExecutablePath); }
1188 catch (Exception) { }
1191 private void tmnuExit_Click(object sender, EventArgs e)
1196 private void tlblRegionInfo_Click(object sender, EventArgs e)
1198 if (WorldMap != null && client.Network.Connected)
1204 private void scriptEditorToolStripMenuItem_Click(object sender, EventArgs e)
1206 ScriptEditor se = new ScriptEditor(instance);
1207 se.Dock = DockStyle.Fill;
1211 private void tmnuSetHome_Click(object sender, EventArgs e)
1213 client.Self.SetHome();
1216 private void tmnuCreateLandmark_Click(object sender, EventArgs e)
1218 string location = string.Format(", {0} ({1}, {2}, {3})",
1219 client.Network.CurrentSim.Name,
1220 (int)client.Self.SimPosition.X,
1221 (int)client.Self.SimPosition.Y,
1222 (int)client.Self.SimPosition.Z
1225 string name = tlblParcel.Text;
1226 int maxLen = 63 - location.Length;
1228 if (name.Length > maxLen)
1229 name = name.Substring(0, maxLen);
1233 client.Inventory.RequestCreateItem(
1234 client.Inventory.FindFolderForType(AssetType.Landmark),
1236 tlblParcel.ToolTipText,
1239 InventoryType.Landmark,
1241 (bool success, InventoryItem item) =>
1245 BeginInvoke(new MethodInvoker(() =>
1247 Landmark ln = new Landmark(instance, (InventoryLandmark)item);
1248 ln.Dock = DockStyle.Fill;
1257 private void timerWorldClock_Tick(object sender, EventArgs e)
1259 lblTime.Text = instance.GetWorldTime().ToString("h:mm tt", System.Globalization.CultureInfo.InvariantCulture);
1262 private void reportBugsToolStripMenuItem_Click(object sender, EventArgs e)
1264 ProcessLink("http://jira.openmetaverse.org/browse/RAD");
1267 private void accessibilityGuideToolStripMenuItem_Click(object sender, EventArgs e)
1269 ProcessLink("http://radegast.org/wiki/Accessibility_Guide");
1272 private void aboutRadegastToolStripMenuItem_Click(object sender, EventArgs e)
1274 (new frmAbout(instance)).ShowDialog();
1277 #region Update Checking
1278 private UpdateChecker updateChecker = null;
1279 private bool ManualUpdateCheck = false;
1281 public void StartUpdateCheck(bool userInitiated)
1283 ManualUpdateCheck = userInitiated;
1285 if (updateChecker != null)
1287 if (ManualUpdateCheck)
1288 tabsConsole.DisplayNotificationInChat("Update check already in progress.");
1292 if (ManualUpdateCheck)
1293 tabsConsole.DisplayNotificationInChat("Checking for updates...", ChatBufferTextStyle.StatusBlue);
1294 updateChecker = new UpdateChecker();
1295 updateChecker.OnUpdateInfoReceived += new UpdateChecker.UpdateInfoCallback(OnUpdateInfoReceived);
1296 updateChecker.StartCheck();
1299 private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
1301 tabsConsole.SelectTab("chat");
1302 StartUpdateCheck(true);
1305 void OnUpdateInfoReceived(object sender, UpdateCheckerArgs e)
1309 BeginInvoke(new MethodInvoker(() => OnUpdateInfoReceived(sender, e)));
1315 if (ManualUpdateCheck)
1316 tabsConsole.DisplayNotificationInChat("Error: Failed connecting to the update site.", ChatBufferTextStyle.StatusBlue);
1320 if (!ManualUpdateCheck && e.Info.DisplayMOTD)
1322 tabsConsole.DisplayNotificationInChat(e.Info.MOTD, ChatBufferTextStyle.StatusBlue);
1325 if (e.Info.UpdateAvailable)
1327 tabsConsole.DisplayNotificationInChat("New version available at " + e.Info.DownloadSite, ChatBufferTextStyle.Alert);
1331 if (ManualUpdateCheck)
1332 tabsConsole.DisplayNotificationInChat("Your version is up to date.", ChatBufferTextStyle.StatusBlue);
1336 updateChecker.Dispose();
1337 updateChecker = null;
1341 private void ToggleHidden(string tabName)
1343 if (!tabsConsole.TabExists(tabName)) return;
1345 RadegastTab tab = tabsConsole.Tabs[tabName];
1364 private void tbtnFriends_Click(object sender, EventArgs e)
1366 ToggleHidden("friends");
1369 private void tbtnInventory_Click(object sender, EventArgs e)
1371 ToggleHidden("inventory");
1374 private void tbtnSearch_Click(object sender, EventArgs e)
1376 ToggleHidden("search");
1379 private void tbtnGroups_Click(object sender, EventArgs e)
1381 ToggleHidden("groups");
1384 private void tbtnVoice_Click(object sender, EventArgs e)
1386 ToggleHidden("voice");
1389 private void tbtnMedia_Click(object sender, EventArgs e)
1391 if (tabsConsole.TabExists("media"))
1393 ToggleHidden("media");
1397 RadegastTab tab = tabsConsole.AddTab("media", "Media", mediaConsole);
1398 tab.AllowClose = false;
1399 tab.AllowHide = true;
1404 private void debugConsoleToolStripMenuItem_Click(object sender, EventArgs e)
1406 if (tabsConsole.TabExists("debug"))
1408 ToggleHidden("debug");
1412 RadegastTab tab = tabsConsole.AddTab("debug", "Debug", new DebugConsole(instance));
1413 tab.AllowClose = false;
1414 tab.AllowHide = true;
1419 private void tbnObjects_Click(object sender, EventArgs e)
1421 if (tabsConsole.TabExists("objects"))
1423 RadegastTab tab = tabsConsole.Tabs["objects"];
1427 ((ObjectsConsole)tab.Control).RefreshObjectList();
1436 RadegastTab tab = tabsConsole.AddTab("objects", "Objects", new ObjectsConsole(instance));
1437 tab.AllowClose = true;
1438 tab.AllowDetach = true;
1440 tab.AllowHide = false;
1442 ((ObjectsConsole)tab.Control).RefreshObjectList();
1446 private void tbtnMap_Click(object sender, EventArgs e)
1448 if (MapTab == null) return; // too soon!
1450 ToggleHidden("map");
1452 MapToCurrentLocation();
1455 private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
1457 if (client.Network.Connected)
1458 client.Network.RequestLogout();
1461 private void reconnectToolStripMenuItem_Click(object sender, EventArgs e)
1463 if (!client.Network.Connected)
1465 instance.Reconnect();
1469 private frmKeyboardShortcuts keyboardShortcutsForm = null;
1470 private void keyboardShortcutsToolStripMenuItem_Click(object sender, EventArgs e)
1472 if (keyboardShortcutsForm != null)
1474 keyboardShortcutsForm.Focus();
1478 keyboardShortcutsForm = new frmKeyboardShortcuts(instance);
1480 keyboardShortcutsForm.Disposed += (object senderx, EventArgs ex) =>
1482 if (components != null)
1484 components.Remove(keyboardShortcutsForm);
1486 keyboardShortcutsForm = null;
1489 keyboardShortcutsForm.Show(this);
1490 keyboardShortcutsForm.Top = Top + 100;
1491 keyboardShortcutsForm.Left = Left + 100;
1493 if (components != null)
1495 components.Add(keyboardShortcutsForm);
1500 // Menu item for testing out stuff
1501 private void testToolStripMenuItem_Click(object sender, EventArgs e)
1505 private void reloadInventoryToolStripMenuItem_Click(object sender, EventArgs e)
1507 if (tabsConsole.TabExists("inventory"))
1509 ((InventoryConsole)tabsConsole.Tabs["inventory"].Control).ReloadInventory();
1510 tabsConsole.Tabs["inventory"].Select();
1514 private void btnLoadScript_Click(object sender, EventArgs e)
1516 if (!TabConsole.TabExists("plugin_manager"))
1518 TabConsole.AddTab("plugin_manager", "Plugins", new PluginsTab(instance));
1520 TabConsole.Tabs["plugin_manager"].Select();
1523 private void frmMain_Resize(object sender, EventArgs e)
1525 if (WindowState == FormWindowState.Minimized && instance.GlobalSettings["minimize_to_tray"].AsBoolean())
1527 if (TabConsole.TabExists("scene_window") && !TabConsole.Tabs["scene_window"].Detached)
1529 TabConsole.Tabs["scene_window"].Close();
1531 ShowInTaskbar = false;
1532 trayIcon.Visible = true;
1533 FormBorderStyle = FormBorderStyle.SizableToolWindow;
1537 private void treyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
1539 WindowState = FormWindowState.Normal;
1540 ShowInTaskbar = true;
1541 trayIcon.Visible = false;
1542 FormBorderStyle = FormBorderStyle.Sizable;
1545 private void ctxTreyRestore_Click(object sender, EventArgs e)
1547 treyIcon_MouseDoubleClick(this, null);
1550 private void ctxTreyExit_Click(object sender, EventArgs e)
1552 tmnuExit_Click(this, EventArgs.Empty);
1555 private void tmnuTeleportHome_Click(object sender, EventArgs e)
1557 TabConsole.DisplayNotificationInChat("Teleporting home...");
1558 client.Self.RequestTeleport(UUID.Zero);
1561 private void stopAllAnimationsToolStripMenuItem_Click(object sender, EventArgs e)
1563 instance.State.StopAllAnimations();
1566 public void DisplayRegionParcelConsole()
1568 if (tabsConsole.TabExists("current region info"))
1570 tabsConsole.Tabs["current region info"].Select();
1571 (tabsConsole.Tabs["current region info"].Control as RegionInfo).UpdateDisplay();
1575 tabsConsole.AddTab("current region info", "Region info", new RegionInfo(instance));
1576 tabsConsole.Tabs["current region info"].Select();
1580 public void DisplayExportConsole(uint localID)
1584 if (IsHandleCreated || !instance.MonoRuntime)
1585 BeginInvoke(new MethodInvoker(() => DisplayExportConsole(localID)));
1589 if (tabsConsole.TabExists("export console"))
1591 tabsConsole.Tabs["export console"].Close();
1593 RadegastTab tab = tabsConsole.AddTab("export console", "Export Object", new ExportConsole(client, localID));
1597 public void DisplayImportConsole()
1599 if (TabConsole.TabExists("import console"))
1601 TabConsole.Tabs["import console"].Select();
1605 RadegastTab tab = tabsConsole.AddTab("import console", "Import Object", new ImportConsole(client));
1606 tab.AllowClose = false;
1607 tab.AllowHide = true;
1612 public void DisplayColladaConsole(Primitive prim)
1616 if (IsHandleCreated || !instance.MonoRuntime)
1617 BeginInvoke(new MethodInvoker(() => DisplayColladaConsole(prim)));
1621 if (tabsConsole.TabExists("collada console"))
1623 tabsConsole.Tabs["collada console"].Close();
1625 RadegastTab tab = tabsConsole.AddTab("collada console", "Export Collada", new ExportCollada(instance, prim));
1629 private void regionParcelToolStripMenuItem_Click(object sender, EventArgs e)
1631 DisplayRegionParcelConsole();
1634 private void tlblParcel_Click(object sender, EventArgs e)
1636 if (!client.Network.Connected) return;
1637 DisplayRegionParcelConsole();
1640 private void changeMyDisplayNameToolStripMenuItem_Click(object sender, EventArgs e)
1642 if (!client.Avatars.DisplayNamesAvailable())
1644 tabsConsole.DisplayNotificationInChat("This grid does not support display names.", ChatBufferTextStyle.Error);
1648 var dlg = new DisplayNameChange(instance);
1652 private void muteListToolStripMenuItem_Click(object sender, EventArgs e)
1654 if (!tabsConsole.TabExists("mute list console"))
1656 tabsConsole.AddTab("mute list console", "Mute list", new MuteList(instance));
1658 tabsConsole.Tabs["mute list console"].Select();
1661 private void uploadImageToolStripMenuItem_Click(object sender, EventArgs e)
1663 if (!tabsConsole.TabExists("image upload console"))
1665 tabsConsole.AddTab("image upload console", "Upload image", new ImageUploadConsole(instance));
1667 tabsConsole.Tabs["image upload console"].Select();
1671 private void myAttachmentsToolStripMenuItem_Click(object sender, EventArgs e)
1673 Avatar av = client.Network.CurrentSim.ObjectsAvatars.Find((Avatar a) => { return a.ID == client.Self.AgentID; });
1677 tabsConsole.DisplayNotificationInChat("Unable to find my avatar!", ChatBufferTextStyle.Error);
1681 if (!instance.TabConsole.TabExists("AT: " + av.ID.ToString()))
1683 instance.TabConsole.AddTab("AT: " + av.ID.ToString(), "My Attachments", new AttachmentTab(instance, av));
1685 instance.TabConsole.SelectTab("AT: " + av.ID.ToString());
1689 private void tsb3D_Click(object sender, EventArgs e)
1691 if (instance.TabConsole.TabExists("scene_window"))
1693 instance.TabConsole.Tabs["scene_window"].Select();
1697 var control = new Rendering.SceneWindow(instance);
1698 control.Dock = DockStyle.Fill;
1699 instance.TabConsole.AddTab("scene_window", "Scene Viewer", control);
1700 instance.TabConsole.Tabs["scene_window"].Floater = false;
1701 instance.TabConsole.Tabs["scene_window"].CloseOnDetachedClose = true;
1702 control.RegisterTabEvents();
1704 if (instance.GlobalSettings["scene_window_docked"])
1706 instance.TabConsole.Tabs["scene_window"].Select();
1710 instance.TabConsole.Tabs["scene_window"].Detach(instance);
1715 private void loginToolStripMenuItem_Click(object sender, EventArgs e)
1717 // We are logging in without exiting the client
1718 // Mark last run as successful
1719 instance.MarkEndExecution();
1720 TabConsole.InitializeMainTab();
1721 TabConsole.Tabs["login"].Select();