2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2011, 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 using System.Threading;
38 using System.Windows.Forms;
39 using System.Resources;
42 using Radegast.Netcom;
44 using OpenMetaverse.StructuredData;
45 using OpenMetaverse.Assets;
49 public partial class frmMain : RadegastForm
51 #region Public members
52 public static ImageList ResourceImages = new ImageList();
53 public static List<string> ImageNames = new List<string>();
54 public bool PreventParcelUpdate = false;
55 public delegate void ProfileHandlerDelegate(string agentName, UUID agentID);
56 public ProfileHandlerDelegate ShowAgentProfile;
58 public TabsConsole TabConsole
60 get { return tabsConsole; }
63 public MapConsole WorldMap
69 return (MapConsole)MapTab.Control;
75 public RadegastTab MapTab
79 if (tabsConsole.TabExists("map"))
81 return tabsConsole.Tabs["map"];
90 public MediaConsole MediaConsole { get { return mediaConsole; } }
93 /// Drop down that contains the tools menu
95 public ToolStripDropDownButton ToolsMenu
97 get { return tbnTools; }
101 /// Dropdown that contains the heelp menu
103 public ToolStripDropDownButton HelpMenu
105 get { return tbtnHelp; }
109 /// Drop down that contants the plugins menu. Make sure to set it Visible if
110 /// you add items to this menu, it's hidden by default
112 public ToolStripDropDownButton PluginsMenu
114 get { return tbnPlugins; }
119 #region Private members
120 private RadegastInstance instance;
121 private GridClient client { get { return instance.Client; } }
122 private RadegastNetcom netcom { get { return instance.Netcom; } }
123 private TabsConsole tabsConsole;
124 private System.Timers.Timer statusTimer;
125 private AutoPilot ap;
126 private bool AutoPilotActive = false;
127 private TransparentButton btnDialogNextControl;
128 private MediaConsole mediaConsole;
131 #region Constructor and disposal
132 public frmMain(RadegastInstance instance)
135 InitializeComponent();
136 Disposed += new EventHandler(frmMain_Disposed);
138 this.instance = instance;
139 this.instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);
140 netcom.NetcomSync = this;
141 ShowAgentProfile = ShowAgentProfileInternal;
143 pnlDialog.Visible = false;
144 btnDialogNextControl = new TransparentButton();
145 pnlDialog.Controls.Add(btnDialogNextControl);
148 btnDialogNextControl.Size = new Size(35, 20);
149 btnDialogNextControl.BackColor = Color.Transparent;
150 btnDialogNextControl.ForeColor = Color.Gold;
151 btnDialogNextControl.FlatAppearance.BorderSize = 0;
152 btnDialogNextControl.FlatStyle = FlatStyle.Flat;
153 btnDialogNextControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
154 btnDialogNextControl.Text = ">>";
155 btnDialogNextControl.Font = new Font(btnDialogNextControl.Font, FontStyle.Bold);
156 btnDialogNextControl.Margin = new Padding(0);
157 btnDialogNextControl.Padding = new Padding(0);
158 btnDialogNextControl.UseVisualStyleBackColor = false;
159 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
160 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
161 btnDialogNextControl.Click += new EventHandler(btnDialogNextControl_Click);
163 if (instance.MonoRuntime)
165 statusStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
169 if (instance.GlobalSettings["transaction_notification_chat"].Type == OSDType.Unknown)
170 instance.GlobalSettings["transaction_notification_chat"] = OSD.FromBoolean(true);
172 if (instance.GlobalSettings["transaction_notification_dialog"].Type == OSDType.Unknown)
173 instance.GlobalSettings["transaction_notification_dialog"] = OSD.FromBoolean(true);
175 if (!instance.GlobalSettings.ContainsKey("minimize_to_tray"))
176 instance.GlobalSettings["minimize_to_tray"] = OSD.FromBoolean(false);
179 netcom.ClientLoginStatus += new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
180 netcom.ClientLoggedOut += new EventHandler(netcom_ClientLoggedOut);
181 netcom.ClientDisconnected += new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
182 instance.Names.NameUpdated += new EventHandler<UUIDNameReplyEventArgs>(Names_NameUpdated);
183 RegisterClientEvents(client);
185 InitializeStatusTimer();
186 RefreshWindowTitle();
189 private void RegisterClientEvents(GridClient client)
191 client.Parcels.ParcelProperties += new EventHandler<ParcelPropertiesEventArgs>(Parcels_ParcelProperties);
192 client.Self.MoneyBalanceReply += new EventHandler<MoneyBalanceReplyEventArgs>(Self_MoneyBalanceReply);
193 client.Self.MoneyBalance += new EventHandler<BalanceEventArgs>(Self_MoneyBalance);
196 private void UnregisterClientEvents(GridClient client)
198 client.Parcels.ParcelProperties -= new EventHandler<ParcelPropertiesEventArgs>(Parcels_ParcelProperties);
199 client.Self.MoneyBalanceReply -= new EventHandler<MoneyBalanceReplyEventArgs>(Self_MoneyBalanceReply);
200 client.Self.MoneyBalance -= new EventHandler<BalanceEventArgs>(Self_MoneyBalance);
203 void instance_ClientChanged(object sender, ClientChangedEventArgs e)
205 UnregisterClientEvents(e.OldClient);
206 RegisterClientEvents(client);
209 void frmMain_Disposed(object sender, EventArgs e)
213 netcom.NetcomSync = null;
214 netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
215 netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
216 netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
221 UnregisterClientEvents(client);
224 if (instance != null && instance.Names != null)
226 instance.Names.NameUpdated -= new EventHandler<UUIDNameReplyEventArgs>(Names_NameUpdated);
229 this.instance.CleanUp();
233 #region Event handlers
234 bool firstMoneyNotification = true;
235 void Self_MoneyBalance(object sender, BalanceEventArgs e)
238 int.TryParse(tlblMoneyBalance.Text, out oldBalance);
239 int delta = Math.Abs(oldBalance - e.Balance);
241 if (firstMoneyNotification)
243 firstMoneyNotification = false;
249 if (oldBalance > e.Balance)
251 instance.MediaManager.PlayUISound(UISounds.MoneyIn);
255 instance.MediaManager.PlayUISound(UISounds.MoneyOut);
261 void Names_NameUpdated(object sender, UUIDNameReplyEventArgs e)
263 if (!e.Names.ContainsKey(client.Self.AgentID)) return;
267 if (IsHandleCreated || !instance.MonoRuntime)
269 BeginInvoke(new MethodInvoker(() => Names_NameUpdated(sender, e)));
274 RefreshWindowTitle();
278 void Self_MoneyBalanceReply(object sender, MoneyBalanceReplyEventArgs e)
280 if (!String.IsNullOrEmpty(e.Description))
282 if (instance.GlobalSettings["transaction_notification_dialog"].AsBoolean())
283 AddNotification(new ntfGeneric(instance, e.Description));
284 if (instance.GlobalSettings["transaction_notification_chat"].AsBoolean())
285 TabConsole.DisplayNotificationInChat(e.Description);
289 public void InitializeControls()
291 InitializeTabsConsole();
293 if (instance.MediaManager.SoundSystemAvailable)
295 mediaConsole = new MediaConsole(instance);
296 tbtnMedia.Visible = true;
300 public bool InAutoReconnect { get; set; }
302 private void DisplayAutoReconnectForm()
304 if (IsDisposed) return;
308 BeginInvoke(new MethodInvoker(DisplayAutoReconnectForm));
312 InAutoReconnect = true;
313 frmReconnect dialog = new frmReconnect(instance, 120);
314 dialog.ShowDialog(this);
319 public void BeginAutoReconnect()
321 // Sleep for 3 seconds on a separate thread while things unwind on
322 // disconnect, since ShowDialog() blocks GUI thread
323 (new Thread(new ThreadStart(() =>
325 System.Threading.Thread.Sleep(3000);
326 DisplayAutoReconnectForm();
330 Name = "Reconnect Delay Thread",
336 private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
338 if (e.Status == LoginStatus.Failed)
342 if (instance.GlobalSettings["auto_reconnect"].AsBoolean())
343 BeginAutoReconnect();
345 InAutoReconnect = false;
348 else if (e.Status == LoginStatus.Success)
350 InAutoReconnect = false;
351 tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
352 tbtnGroups.Enabled = tbnObjects.Enabled = tbtnWorld.Enabled = tbnTools.Enabled = tmnuImport.Enabled =
353 tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = true;
356 RefreshWindowTitle();
360 private void netcom_ClientLoggedOut(object sender, EventArgs e)
362 tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
363 tbtnGroups.Enabled = tbnObjects.Enabled = tbtnWorld.Enabled = tbnTools.Enabled = tmnuImport.Enabled =
364 tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = false;
366 reconnectToolStripMenuItem.Enabled = true;
367 InAutoReconnect = false;
369 if (statusTimer != null)
373 RefreshWindowTitle();
376 private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
378 if (e.Reason == NetworkManager.DisconnectType.ClientInitiated) return;
379 netcom_ClientLoggedOut(sender, EventArgs.Empty);
381 if (instance.GlobalSettings["auto_reconnect"].AsBoolean())
383 BeginAutoReconnect();
387 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
389 if (statusTimer != null)
392 statusTimer.Dispose();
396 if (mediaConsole != null)
398 if (tabsConsole.TabExists("media"))
400 tabsConsole.Tabs["media"].AllowClose = true;
401 tabsConsole.Tabs["media"].Close();
405 mediaConsole.Dispose();
410 if (netcom.IsLoggedIn)
412 Thread saveInvToDisk = new Thread(new ThreadStart(
415 client.Inventory.Store.SaveToDisk(instance.InventoryCacheFileName);
417 saveInvToDisk.Name = "Save inventory to disk";
418 saveInvToDisk.Start();
425 # region Update status
427 void Parcels_ParcelProperties(object sender, ParcelPropertiesEventArgs e)
429 if (PreventParcelUpdate || e.Result != ParcelResult.Single) return;
432 BeginInvoke(new MethodInvoker(() => Parcels_ParcelProperties(sender, e)));
436 Parcel parcel = instance.State.Parcel = e.Parcel;
438 tlblParcel.Text = parcel.Name;
439 tlblParcel.ToolTipText = parcel.Desc;
441 if ((parcel.Flags & ParcelFlags.AllowFly) != ParcelFlags.AllowFly)
442 icoNoFly.Visible = true;
444 icoNoFly.Visible = false;
446 if ((parcel.Flags & ParcelFlags.CreateObjects) != ParcelFlags.CreateObjects)
447 icoNoBuild.Visible = true;
449 icoNoBuild.Visible = false;
451 if ((parcel.Flags & ParcelFlags.AllowOtherScripts) != ParcelFlags.AllowOtherScripts)
452 icoNoScript.Visible = true;
454 icoNoScript.Visible = false;
456 if ((parcel.Flags & ParcelFlags.RestrictPushObject) == ParcelFlags.RestrictPushObject)
457 icoNoPush.Visible = true;
459 icoNoPush.Visible = false;
461 if ((parcel.Flags & ParcelFlags.AllowDamage) == ParcelFlags.AllowDamage)
462 icoHealth.Visible = true;
464 icoHealth.Visible = false;
466 if ((parcel.Flags & ParcelFlags.AllowVoiceChat) != ParcelFlags.AllowVoiceChat)
467 icoNoVoice.Visible = true;
469 icoNoVoice.Visible = false;
472 private void RefreshStatusBar()
474 if (netcom.IsLoggedIn)
476 tlblLoginName.Text = instance.Names.Get(client.Self.AgentID, client.Self.Name);
477 tlblMoneyBalance.Text = client.Self.Balance.ToString();
478 icoHealth.Text = client.Self.Health.ToString() + "%";
480 tlblRegionInfo.Text =
481 client.Network.CurrentSim.Name +
482 " (" + Math.Floor(client.Self.SimPosition.X).ToString() + ", " +
483 Math.Floor(client.Self.SimPosition.Y).ToString() + ", " +
484 Math.Floor(client.Self.SimPosition.Z).ToString() + ")";
488 tlblLoginName.Text = "Offline";
489 tlblMoneyBalance.Text = "0";
490 icoHealth.Text = "0%";
491 tlblRegionInfo.Text = "No Region";
492 tlblParcel.Text = "No Parcel";
494 icoHealth.Visible = false;
495 icoNoBuild.Visible = false;
496 icoNoFly.Visible = false;
497 icoNoPush.Visible = false;
498 icoNoScript.Visible = false;
499 icoNoVoice.Visible = false;
503 private void RefreshWindowTitle()
505 string name = instance.Names.Get(client.Self.AgentID, client.Self.Name);
506 StringBuilder sb = new StringBuilder();
507 sb.Append("Radegast - ");
509 if (netcom.IsLoggedIn)
511 sb.Append("[" + name + "]");
513 if (instance.State.IsAway)
515 sb.Append(" - Away");
516 if (instance.State.IsBusy) sb.Append(", Busy");
518 else if (instance.State.IsBusy)
520 sb.Append(" - Busy");
523 if (instance.State.IsFollowing)
525 sb.Append(" - Following ");
526 sb.Append(instance.State.FollowName);
531 sb.Append("Logged Out");
534 this.Text = sb.ToString();
536 // When minimized to tray, update tray tool tip also
537 if (WindowState == FormWindowState.Minimized && instance.GlobalSettings["minimize_to_tray"])
539 trayIcon.Text = sb.ToString();
540 ctxTrayMenuLabel.Text = sb.ToString();
546 private void InitializeStatusTimer()
548 statusTimer = new System.Timers.Timer(250);
549 statusTimer.SynchronizingObject = this;
550 statusTimer.Elapsed += new ElapsedEventHandler(statusTimer_Elapsed);
553 private void statusTimer_Elapsed(object sender, ElapsedEventArgs e)
555 // Mono sometimes fires timer after is's disposed
558 RefreshWindowTitle();
565 #region Initialization, configuration, and key shortcuts
566 private void InitializeTabsConsole()
568 tabsConsole = new TabsConsole(instance);
569 tabsConsole.Dock = DockStyle.Fill;
570 toolStripContainer1.ContentPanel.Controls.Add(tabsConsole);
573 private void frmMain_KeyDown(object sender, KeyEventArgs e)
575 // Ctrl-Shift-1 (sim/parcel info)
576 if (e.Modifiers == (Keys.Control | Keys.Shift) && e.KeyCode == Keys.D1)
578 e.Handled = e.SuppressKeyPress = true;
579 DisplayRegionParcelConsole();
584 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.W)
586 e.Handled = e.SuppressKeyPress = true;
587 RadegastTab tab = tabsConsole.SelectedTab;
593 else if (tab.AllowHide)
601 // Ctl-Shift-H: Teleport Home
602 if (e.Modifiers == (Keys.Control | Keys.Shift) && e.KeyCode == Keys.H)
604 e.Handled = e.SuppressKeyPress = true;
605 tmnuTeleportHome.PerformClick();
609 // Alt-Ctrl-D Open debug console
610 if (e.Modifiers == (Keys.Control | Keys.Alt) && e.KeyCode == Keys.D)
612 e.Handled = e.SuppressKeyPress = true;
613 debugConsoleToolStripMenuItem.PerformClick();
617 // Alt 1-8: Toggle various tabs
618 if (e.Modifiers == Keys.Alt)
623 e.Handled = e.SuppressKeyPress = true;
624 tabsConsole.Tabs["chat"].Select();
628 e.Handled = e.SuppressKeyPress = true;
629 tbtnFriends.PerformClick();
633 e.Handled = e.SuppressKeyPress = true;
634 tbtnGroups.PerformClick();
638 e.Handled = e.SuppressKeyPress = true;
639 tbtnInventory.PerformClick();
643 e.Handled = e.SuppressKeyPress = true;
644 tbtnSearch.PerformClick();
648 e.Handled = e.SuppressKeyPress = true;
649 tbtnMap.PerformClick();
653 e.Handled = e.SuppressKeyPress = true;
654 tbnObjects.PerformClick();
658 e.Handled = e.SuppressKeyPress = true;
659 tbtnMedia.PerformClick();
663 e.Handled = e.SuppressKeyPress = true;
664 tbtnVoice.PerformClick();
669 // ctrl-g, goto slurl
670 if (e.Control && e.KeyCode == Keys.G)
672 if (!ProcessLink(Clipboard.GetText(), true))
673 MapToCurrentLocation();
675 e.Handled = e.SuppressKeyPress = true;
679 // ctrl-(shift)-tab for next/previous tab
680 if (e.Control && e.KeyCode == Keys.Tab)
684 TabConsole.SelectPreviousTab();
688 TabConsole.SelectNextTab();
690 e.Handled = e.SuppressKeyPress = true;
695 bool firstLoad = true;
697 private void frmMain_Load(object sender, EventArgs e)
702 tabsConsole.SelectTab("login");
703 ResourceManager rm = Properties.Resources.ResourceManager;
704 ResourceSet set = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
705 System.Collections.IDictionaryEnumerator de = set.GetEnumerator();
706 while (de.MoveNext() == true)
708 if (de.Entry.Value is Image)
710 Bitmap bitMap = de.Entry.Value as Bitmap;
711 ResourceImages.Images.Add(bitMap);
712 ImageNames.Add(de.Entry.Key.ToString());
715 StartUpdateCheck(false);
717 if (instance.PlainColors)
719 pnlDialog.BackColor = System.Drawing.Color.FromArgb(120, 220, 255);
726 #region Public methods
728 private Dictionary<UUID, frmProfile> shownProfiles = new Dictionary<UUID, frmProfile>();
730 void ShowAgentProfileInternal(string name, UUID agentID)
734 frmProfile profile = null;
735 if (shownProfiles.TryGetValue(agentID, out profile))
737 profile.WindowState = FormWindowState.Normal;
742 profile = new frmProfile(instance, name, agentID);
744 profile.Disposed += (object sender, EventArgs e) =>
748 frmProfile agentProfile = (frmProfile)sender;
749 if (shownProfiles.ContainsKey(agentProfile.AgentID))
750 shownProfiles.Remove(agentProfile.AgentID);
756 shownProfiles.Add(agentID, profile);
761 private Dictionary<UUID, frmGroupInfo> shownGroupProfiles = new Dictionary<UUID, frmGroupInfo>();
763 public void ShowGroupProfile(AvatarGroup group)
765 ShowGroupProfile(new OpenMetaverse.Group()
768 InsigniaID = group.GroupInsigniaID,
769 Name = group.GroupName
774 public void ShowGroupProfile(OpenMetaverse.Group group)
776 lock (shownGroupProfiles)
778 frmGroupInfo profile = null;
779 if (shownGroupProfiles.TryGetValue(group.ID, out profile))
781 profile.WindowState = FormWindowState.Normal;
786 profile = new frmGroupInfo(instance, group);
788 profile.Disposed += (object sender, EventArgs e) =>
790 lock (shownGroupProfiles)
792 frmGroupInfo groupProfile = (frmGroupInfo)sender;
793 if (shownGroupProfiles.ContainsKey(groupProfile.Group.ID))
794 shownGroupProfiles.Remove(groupProfile.Group.ID);
800 shownGroupProfiles.Add(group.ID, profile);
805 public void ProcessLink(string link)
807 ProcessLink(link, false);
810 public bool ProcessLink(string link, bool onlyMap)
812 if (!link.Contains("://"))
814 link = "http://" + link;
817 Regex r = new Regex(@"^(http://(slurl\.com|maps\.secondlife\.com)/secondlife/|secondlife://)(?<region>[^/]+)/(?<x>\d+)/(?<y>\d+)(/(?<z>\d+))?",
818 RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase
820 Match m = r.Match(link);
824 string region = HttpUtility.UrlDecode(m.Groups["region"].Value);
825 int x = int.Parse(m.Groups["x"].Value);
826 int y = int.Parse(m.Groups["y"].Value);
829 if (!string.IsNullOrEmpty(m.Groups["z"].Value))
831 z = int.Parse(m.Groups["z"].Value);
835 WorldMap.DisplayLocation(region, x, y, z);
840 System.Diagnostics.Process.Start(link);
846 #region Notifications
847 CircularList<Control> notifications = new CircularList<Control>();
849 public Color NotificationBackground
851 get { return pnlDialog.BackColor; }
854 void ResizeNotificationByControl(Control active)
856 int Width = active.Size.Width + 6;
857 int Height = notifications.Count > 1 ? active.Size.Height + 3 + btnDialogNextControl.Size.Height : active.Size.Height + 3;
858 pnlDialog.Size = new Size(Width, Height);
860 pnlDialog.Left = pnlDialog.Parent.ClientSize.Width - Width;
862 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
863 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
865 btnDialogNextControl.BringToFront();
868 public void AddNotification(Control control)
872 BeginInvoke(new MethodInvoker(delegate()
874 AddNotification(control);
880 FormFlash.StartFlash(this);
881 pnlDialog.Visible = true;
882 pnlDialog.BringToFront();
884 foreach (Control existing in notifications)
886 existing.Visible = false;
889 notifications.Add(control);
890 control.Visible = true;
891 control.Anchor = AnchorStyles.Top | AnchorStyles.Left;
894 pnlDialog.Controls.Add(control);
895 ResizeNotificationByControl(control);
897 btnDialogNextControl.Visible = notifications.Count > 1;
900 public void RemoveNotification(Control control)
902 pnlDialog.Controls.Remove(control);
903 notifications.Remove(control);
906 if (notifications.HasNext)
908 pnlDialog.Visible = true;
909 Control active = notifications.Next;
910 active.Visible = true;
911 ResizeNotificationByControl(active);
915 pnlDialog.Visible = false;
918 btnDialogNextControl.Visible = notifications.Count > 1;
921 private void btnDialogNextControl_Click(object sender, EventArgs e)
923 foreach (Control existing in notifications)
925 existing.Visible = false;
928 if (notifications.HasNext)
930 pnlDialog.Visible = true;
931 Control active = notifications.Next;
932 active.Visible = true;
933 ResizeNotificationByControl(active);
937 pnlDialog.Visible = false;
941 #endregion Notifications
943 #region Menu click handlers
945 private void tmnuStatusAway_Click(object sender, EventArgs e)
947 instance.State.SetAway(tmnuStatusAway.Checked);
950 private void tmnuHelpReadme_Click(object sender, EventArgs e)
952 System.Diagnostics.Process.Start(Application.StartupPath + @"\Readme.txt");
955 private void tmnuStatusBusy_Click(object sender, EventArgs e)
957 instance.State.SetBusy(tmnuStatusBusy.Checked);
960 private void tmnuControlFly_Click(object sender, EventArgs e)
962 instance.State.SetFlying(tmnuControlFly.Checked);
965 private void tmnuControlAlwaysRun_Click(object sender, EventArgs e)
967 instance.State.SetAlwaysRun(tmnuControlAlwaysRun.Checked);
970 private void tmnuPrefs_Click(object sender, EventArgs e)
972 (new frmSettings(instance)).ShowDialog();
975 private void tbtnAppearance_Click(object sender, EventArgs e)
977 client.Appearance.RequestSetAppearance(false);
980 private void importObjectToolStripMenuItem_Click(object sender, EventArgs e)
982 PrimDeserializer.ImportFromFile(client);
985 private void autopilotToolStripMenuItem_Click(object sender, EventArgs e)
989 ap = new AutoPilot(client);
991 ap.InsertWaypoint(new Vector3(66, 163, 21));
992 ap.InsertWaypoint(new Vector3(66, 98, 21));
994 ap.InsertWaypoint(new Vector3(101, 98, 21));
995 ap.InsertWaypoint(new Vector3(101, 45, 21));
996 ap.InsertWaypoint(new Vector3(93, 27, 21));
997 ap.InsertWaypoint(new Vector3(106, 12, 21));
998 ap.InsertWaypoint(new Vector3(123, 24, 21));
999 ap.InsertWaypoint(new Vector3(114, 45, 21));
1000 ap.InsertWaypoint(new Vector3(114, 98, 21));
1002 ap.InsertWaypoint(new Vector3(130, 98, 21));
1003 ap.InsertWaypoint(new Vector3(130, 163, 21));
1005 ap.InsertWaypoint(new Vector3(64, 68, 21));
1006 ap.InsertWaypoint(new Vector3(65, 20, 21));
1007 ap.InsertWaypoint(new Vector3(33, 23, 21));
1008 ap.InsertWaypoint(new Vector3(17, 39, 21));
1009 ap.InsertWaypoint(new Vector3(17, 62, 21));
1013 if (AutoPilotActive)
1015 AutoPilotActive = false;
1020 AutoPilotActive = true;
1026 private void cleanCacheToolStripMenuItem_Click(object sender, EventArgs e)
1028 client.Assets.Cache.Clear();
1031 private void rebakeTexturesToolStripMenuItem_Click(object sender, EventArgs e)
1033 client.Appearance.RequestSetAppearance(true);
1036 public void MapToCurrentLocation()
1038 if (MapTab != null && client.Network.Connected)
1041 WorldMap.DisplayLocation(client.Network.CurrentSim.Name,
1042 (int)client.Self.SimPosition.X,
1043 (int)client.Self.SimPosition.Y,
1044 (int)client.Self.SimPosition.Z);
1048 private void standToolStripMenuItem_Click(object sender, EventArgs e)
1050 instance.State.SetSitting(false, UUID.Zero);
1053 private void groundSitToolStripMenuItem_Click(object sender, EventArgs e)
1055 client.Self.SitOnGround();
1058 private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)
1060 try { System.Diagnostics.Process.Start(Application.ExecutablePath); }
1061 catch (Exception) { }
1064 private void tmnuExit_Click(object sender, EventArgs e)
1069 private void tlblRegionInfo_Click(object sender, EventArgs e)
1071 if (WorldMap != null && client.Network.Connected)
1077 private void scriptEditorToolStripMenuItem_Click(object sender, EventArgs e)
1079 ScriptEditor se = new ScriptEditor(instance);
1080 se.Dock = DockStyle.Fill;
1084 private void tmnuSetHome_Click(object sender, EventArgs e)
1086 client.Self.SetHome();
1089 private void tmnuCreateLandmark_Click(object sender, EventArgs e)
1091 string location = string.Format(", {0} ({1}, {2}, {3})",
1092 client.Network.CurrentSim.Name,
1093 (int)client.Self.SimPosition.X,
1094 (int)client.Self.SimPosition.Y,
1095 (int)client.Self.SimPosition.Z
1098 string name = tlblParcel.Text;
1099 int maxLen = 63 - location.Length;
1101 if (name.Length > maxLen)
1102 name = name.Substring(0, maxLen);
1106 client.Inventory.RequestCreateItem(
1107 client.Inventory.FindFolderForType(AssetType.Landmark),
1109 tlblParcel.ToolTipText,
1112 InventoryType.Landmark,
1114 (bool success, InventoryItem item) =>
1118 BeginInvoke(new MethodInvoker(() =>
1120 Landmark ln = new Landmark(instance, (InventoryLandmark)item);
1121 ln.Dock = DockStyle.Fill;
1130 private void timerWorldClock_Tick(object sender, EventArgs e)
1132 lblTime.Text = instance.GetWorldTime().ToString("h:mm tt", System.Globalization.CultureInfo.InvariantCulture);
1135 private void reportBugsToolStripMenuItem_Click(object sender, EventArgs e)
1137 ProcessLink("http://jira.openmetaverse.org/browse/RAD");
1140 private void aboutRadegastToolStripMenuItem_Click(object sender, EventArgs e)
1142 (new frmAbout(instance)).ShowDialog();
1145 #region Update Checking
1146 private UpdateChecker updateChecker = null;
1147 private bool ManualUpdateCheck = false;
1149 public void StartUpdateCheck(bool userInitiated)
1151 ManualUpdateCheck = userInitiated;
1153 if (updateChecker != null)
1155 if (ManualUpdateCheck)
1156 tabsConsole.DisplayNotificationInChat("Update check already in progress.");
1160 if (ManualUpdateCheck)
1161 tabsConsole.DisplayNotificationInChat("Checking for updates...", ChatBufferTextStyle.StatusBlue);
1162 updateChecker = new UpdateChecker();
1163 updateChecker.OnUpdateInfoReceived += new UpdateChecker.UpdateInfoCallback(OnUpdateInfoReceived);
1164 updateChecker.StartCheck();
1167 private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
1169 tabsConsole.SelectTab("chat");
1170 StartUpdateCheck(true);
1173 void OnUpdateInfoReceived(object sender, UpdateCheckerArgs e)
1177 BeginInvoke(new MethodInvoker(() => OnUpdateInfoReceived(sender, e)));
1183 if (ManualUpdateCheck)
1184 tabsConsole.DisplayNotificationInChat("Error: Failed connecting to the update site.", ChatBufferTextStyle.StatusBlue);
1188 if (!ManualUpdateCheck && e.Info.DisplayMOTD)
1190 tabsConsole.DisplayNotificationInChat(e.Info.MOTD, ChatBufferTextStyle.StatusBlue);
1193 if (e.Info.UpdateAvailable)
1195 tabsConsole.DisplayNotificationInChat("New version available at " + e.Info.DownloadSite, ChatBufferTextStyle.Alert);
1199 if (ManualUpdateCheck)
1200 tabsConsole.DisplayNotificationInChat("Your version is up to date.", ChatBufferTextStyle.StatusBlue);
1204 updateChecker.Dispose();
1205 updateChecker = null;
1209 private void ToggleHidden(string tabName)
1211 if (!tabsConsole.TabExists(tabName)) return;
1213 RadegastTab tab = tabsConsole.Tabs[tabName];
1232 private void tbtnFriends_Click(object sender, EventArgs e)
1234 ToggleHidden("friends");
1237 private void tbtnInventory_Click(object sender, EventArgs e)
1239 ToggleHidden("inventory");
1242 private void tbtnSearch_Click(object sender, EventArgs e)
1244 ToggleHidden("search");
1247 private void tbtnGroups_Click(object sender, EventArgs e)
1249 ToggleHidden("groups");
1252 private void tbtnVoice_Click(object sender, EventArgs e)
1254 ToggleHidden("voice");
1257 private void tbtnMedia_Click(object sender, EventArgs e)
1259 if (tabsConsole.TabExists("media"))
1261 ToggleHidden("media");
1265 RadegastTab tab = tabsConsole.AddTab("media", "Media", mediaConsole);
1266 tab.AllowClose = false;
1267 tab.AllowHide = true;
1272 private void debugConsoleToolStripMenuItem_Click(object sender, EventArgs e)
1274 if (tabsConsole.TabExists("debug"))
1276 ToggleHidden("debug");
1280 RadegastTab tab = tabsConsole.AddTab("debug", "Debug", new DebugConsole(instance));
1281 tab.AllowClose = false;
1282 tab.AllowHide = true;
1287 private void tbnObjects_Click(object sender, EventArgs e)
1289 if (tabsConsole.TabExists("objects"))
1291 RadegastTab tab = tabsConsole.Tabs["objects"];
1295 ((ObjectsConsole)tab.Control).RefreshObjectList();
1304 RadegastTab tab = tabsConsole.AddTab("objects", "Objects", new ObjectsConsole(instance));
1305 tab.AllowClose = true;
1306 tab.AllowDetach = true;
1308 tab.AllowHide = false;
1310 ((ObjectsConsole)tab.Control).RefreshObjectList();
1314 private void tbtnMap_Click(object sender, EventArgs e)
1316 ToggleHidden("map");
1318 MapToCurrentLocation();
1321 private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
1323 if (client.Network.Connected)
1324 client.Network.RequestLogout();
1327 private void reconnectToolStripMenuItem_Click(object sender, EventArgs e)
1329 instance.Reconnect();
1332 private frmKeyboardShortcuts keyboardShortcutsForm = null;
1333 private void keyboardShortcutsToolStripMenuItem_Click(object sender, EventArgs e)
1335 if (keyboardShortcutsForm != null)
1337 keyboardShortcutsForm.Focus();
1341 keyboardShortcutsForm = new frmKeyboardShortcuts(instance);
1343 keyboardShortcutsForm.Disposed += (object senderx, EventArgs ex) =>
1345 if (components != null)
1347 components.Remove(keyboardShortcutsForm);
1349 keyboardShortcutsForm = null;
1352 keyboardShortcutsForm.Show(this);
1353 keyboardShortcutsForm.Top = Top + 100;
1354 keyboardShortcutsForm.Left = Left + 100;
1356 if (components != null)
1358 components.Add(keyboardShortcutsForm);
1363 // Menu item for testing out stuff
1364 private void testToolStripMenuItem_Click(object sender, EventArgs e)
1366 //instance.MediaManager.PlayUISound(UISounds.IM);
1367 //Random r = new Random();
1368 //client.Self.RequestMuteList((uint)r.Next());
1371 private void reloadInventoryToolStripMenuItem_Click(object sender, EventArgs e)
1373 if (tabsConsole.TabExists("inventory"))
1375 ((InventoryConsole)tabsConsole.Tabs["inventory"].Control).ReloadInventory();
1376 tabsConsole.Tabs["inventory"].Select();
1380 private void btnLoadScript_Click(object sender, EventArgs e)
1382 if (!TabConsole.TabExists("plugin_manager"))
1384 TabConsole.AddTab("plugin_manager", "Plugins", new PluginsTab(instance));
1386 TabConsole.Tabs["plugin_manager"].Select();
1389 private void frmMain_Resize(object sender, EventArgs e)
1391 if (WindowState == FormWindowState.Minimized && instance.GlobalSettings["minimize_to_tray"].AsBoolean())
1393 ShowInTaskbar = false;
1394 trayIcon.Visible = true;
1395 FormBorderStyle = FormBorderStyle.SizableToolWindow;
1399 private void treyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
1401 WindowState = FormWindowState.Normal;
1402 ShowInTaskbar = true;
1403 trayIcon.Visible = false;
1404 FormBorderStyle = FormBorderStyle.Sizable;
1407 private void ctxTreyRestore_Click(object sender, EventArgs e)
1409 treyIcon_MouseDoubleClick(this, null);
1412 private void ctxTreyExit_Click(object sender, EventArgs e)
1414 tmnuExit_Click(this, EventArgs.Empty);
1417 private void tmnuTeleportHome_Click(object sender, EventArgs e)
1419 TabConsole.DisplayNotificationInChat("Teleporting home...");
1420 client.Self.RequestTeleport(UUID.Zero);
1423 private void stopAllAnimationsToolStripMenuItem_Click(object sender, EventArgs e)
1425 instance.State.StopAllAnimations();
1428 public void DisplayRegionParcelConsole()
1430 if (tabsConsole.TabExists("current region info"))
1432 tabsConsole.Tabs["current region info"].Select();
1433 (tabsConsole.Tabs["current region info"].Control as RegionInfo).UpdateDisplay();
1437 tabsConsole.AddTab("current region info", "Region info", new RegionInfo(instance));
1438 tabsConsole.Tabs["current region info"].Select();
1442 private void regionParcelToolStripMenuItem_Click(object sender, EventArgs e)
1444 DisplayRegionParcelConsole();
1447 private void tlblParcel_Click(object sender, EventArgs e)
1449 DisplayRegionParcelConsole();
1452 private void changeMyDisplayNameToolStripMenuItem_Click(object sender, EventArgs e)
1454 if (!client.Avatars.DisplayNamesAvailable())
1456 tabsConsole.DisplayNotificationInChat("This grid does not support display names.", ChatBufferTextStyle.Error);
1460 var dlg = new DisplayNameChange(instance);
1464 private void muteListToolStripMenuItem_Click(object sender, EventArgs e)
1466 if (!tabsConsole.TabExists("mute list console"))
1468 tabsConsole.AddTab("mute list console", "Mute List", new MuteList(instance));
1470 tabsConsole.Tabs["mute list console"].Select();