2 // Radegast Metaverse Client
3 // Copyright (c) 2009, 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>();
55 public TabsConsole TabConsole
57 get { return tabsConsole; }
60 public MapConsole WorldMap
66 return (MapConsole)MapTab.Control;
72 public RadegastTab MapTab
76 if (tabsConsole.TabExists("map"))
78 return tabsConsole.Tabs["map"];
87 public MediaConsole MediaConsole { get { return mediaConsole; } }
90 /// Drop down that contains the tools menu
92 public ToolStripDropDownButton ToolsMenu
94 get { return tbnTools; }
98 /// Dropdown that contains the heelp menu
100 public ToolStripDropDownButton HelpMenu
102 get { return tbtnHelp; }
106 /// Drop down that contants the plugins menu. Make sure to set it Visible if
107 /// you add items to this menu, it's hidden by default
109 public ToolStripDropDownButton PluginsMenu
111 get { return tbnPlugins; }
116 #region Private members
117 private RadegastInstance instance;
118 private GridClient client { get { return instance.Client; } }
119 private RadegastNetcom netcom { get { return instance.Netcom; } }
120 private TabsConsole tabsConsole;
121 private System.Timers.Timer statusTimer;
122 private AutoPilot ap;
123 private bool AutoPilotActive = false;
124 private TransparentButton btnDialogNextControl;
125 private MediaConsole mediaConsole;
128 #region Constructor and disposal
129 public frmMain(RadegastInstance instance)
133 InitializeComponent();
134 Disposed += new EventHandler(frmMain_Disposed);
136 this.instance = instance;
137 this.instance.ClientChanged += new EventHandler<ClientChangedEventArgs>(instance_ClientChanged);
138 netcom.NetcomSync = this;
140 pnlDialog.Visible = false;
141 btnDialogNextControl = new TransparentButton();
142 pnlDialog.Controls.Add(btnDialogNextControl);
145 btnDialogNextControl.Size = new Size(35, 20);
146 btnDialogNextControl.BackColor = Color.Transparent;
147 btnDialogNextControl.ForeColor = Color.Gold;
148 btnDialogNextControl.FlatAppearance.BorderSize = 0;
149 btnDialogNextControl.FlatStyle = FlatStyle.Flat;
150 btnDialogNextControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
151 btnDialogNextControl.Text = ">>";
152 btnDialogNextControl.Font = new Font(btnDialogNextControl.Font, FontStyle.Bold);
153 btnDialogNextControl.Margin = new Padding(0);
154 btnDialogNextControl.Padding = new Padding(0);
155 btnDialogNextControl.UseVisualStyleBackColor = false;
156 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
157 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
158 btnDialogNextControl.Click += new EventHandler(btnDialogNextControl_Click);
160 if (instance.MonoRuntime)
162 statusStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
166 if (instance.GlobalSettings["transaction_notification_chat"].Type == OSDType.Unknown)
167 instance.GlobalSettings["transaction_notification_chat"] = OSD.FromBoolean(true);
169 if (instance.GlobalSettings["transaction_notification_dialog"].Type == OSDType.Unknown)
170 instance.GlobalSettings["transaction_notification_dialog"] = OSD.FromBoolean(true);
172 if (!instance.GlobalSettings.ContainsKey("minimize_to_tray"))
173 instance.GlobalSettings["minimize_to_tray"] = OSD.FromBoolean(false);
176 netcom.ClientLoginStatus += new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
177 netcom.ClientLoggedOut += new EventHandler(netcom_ClientLoggedOut);
178 netcom.ClientDisconnected += new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
179 RegisterClientEvents(client);
181 InitializeStatusTimer();
182 RefreshWindowTitle();
185 private void RegisterClientEvents(GridClient client)
187 client.Parcels.ParcelProperties += new EventHandler<ParcelPropertiesEventArgs>(Parcels_ParcelProperties);
188 client.Self.MoneyBalanceReply += new EventHandler<MoneyBalanceReplyEventArgs>(Self_MoneyBalanceReply);
191 private void UnregisterClientEvents(GridClient client)
193 client.Parcels.ParcelProperties -= new EventHandler<ParcelPropertiesEventArgs>(Parcels_ParcelProperties);
194 client.Self.MoneyBalanceReply -= new EventHandler<MoneyBalanceReplyEventArgs>(Self_MoneyBalanceReply);
197 void instance_ClientChanged(object sender, ClientChangedEventArgs e)
199 UnregisterClientEvents(e.OldClient);
200 RegisterClientEvents(client);
203 void frmMain_Disposed(object sender, EventArgs e)
207 netcom.NetcomSync = null;
208 netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
209 netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
210 netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
214 UnregisterClientEvents(client);
216 this.instance.CleanUp();
220 #region Event handlers
221 void Self_MoneyBalanceReply(object sender, MoneyBalanceReplyEventArgs e)
223 if (!String.IsNullOrEmpty(e.Description))
225 if (instance.GlobalSettings["transaction_notification_dialog"].AsBoolean())
226 AddNotification(new ntfGeneric(instance, e.Description));
227 if (instance.GlobalSettings["transaction_notification_chat"].AsBoolean())
228 TabConsole.DisplayNotificationInChat(e.Description);
232 public void InitializeControls()
234 InitializeTabsConsole();
236 if (instance.MediaManager.SoundSystemAvailable)
238 mediaConsole = new MediaConsole(instance);
239 tbtnMedia.Visible = true;
243 public bool InAutoReconnect { get; set; }
245 private void DisplayAutoReconnectForm()
247 if (IsDisposed) return;
251 BeginInvoke(new MethodInvoker(DisplayAutoReconnectForm));
255 InAutoReconnect = true;
256 frmReconnect dialog = new frmReconnect(instance, 120);
257 dialog.ShowDialog(this);
262 public void BeginAutoReconnect()
264 // Sleep for 3 seconds on a separate thread while things unwind on
265 // disconnect, since ShowDialog() blocks GUI thread
266 (new Thread(new ThreadStart(() =>
268 System.Threading.Thread.Sleep(3000);
269 DisplayAutoReconnectForm();
273 Name = "Reconnect Delay Thread",
279 private void netcom_ClientLoginStatus(object sender, LoginProgressEventArgs e)
281 if (e.Status == LoginStatus.Failed)
285 if (instance.GlobalSettings["auto_reconnect"].AsBoolean())
286 BeginAutoReconnect();
288 InAutoReconnect = false;
291 else if (e.Status == LoginStatus.Success)
293 InAutoReconnect = false;
294 tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
295 tbtnGroups.Enabled = tbnObjects.Enabled = tbtnWorld.Enabled = tbnTools.Enabled = tmnuImport.Enabled =
296 tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = true;
299 RefreshWindowTitle();
303 private void netcom_ClientLoggedOut(object sender, EventArgs e)
305 tbtnVoice.Enabled = disconnectToolStripMenuItem.Enabled =
306 tbtnGroups.Enabled = tbnObjects.Enabled = tbtnWorld.Enabled = tbnTools.Enabled = tmnuImport.Enabled =
307 tbtnFriends.Enabled = tbtnInventory.Enabled = tbtnSearch.Enabled = tbtnMap.Enabled = false;
309 reconnectToolStripMenuItem.Enabled = true;
310 InAutoReconnect = false;
312 if (statusTimer != null)
316 RefreshWindowTitle();
319 private void netcom_ClientDisconnected(object sender, DisconnectedEventArgs e)
321 if (e.Reason == NetworkManager.DisconnectType.ClientInitiated) return;
322 netcom_ClientLoggedOut(sender, EventArgs.Empty);
324 if (instance.GlobalSettings["auto_reconnect"].AsBoolean())
326 BeginAutoReconnect();
330 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
332 if (statusTimer != null)
335 statusTimer.Dispose();
339 if (mediaConsole != null)
341 if (tabsConsole.TabExists("media"))
343 tabsConsole.Tabs["media"].AllowClose = true;
344 tabsConsole.Tabs["media"].Close();
348 mediaConsole.Dispose();
353 if (netcom.IsLoggedIn)
355 Thread saveInvToDisk = new Thread(new ThreadStart(
358 client.Inventory.Store.SaveToDisk(instance.InventoryCacheFileName);
360 saveInvToDisk.Name = "Save inventory to disk";
361 saveInvToDisk.Start();
368 # region Update status
370 void Parcels_ParcelProperties(object sender, ParcelPropertiesEventArgs e)
372 if (e.Result != ParcelResult.Single) return;
375 BeginInvoke(new MethodInvoker(() => Parcels_ParcelProperties(sender, e)));
379 Parcel parcel = instance.State.Parcel = e.Parcel;
381 tlblParcel.Text = parcel.Name;
382 tlblParcel.ToolTipText = parcel.Desc;
384 if ((parcel.Flags & ParcelFlags.AllowFly) != ParcelFlags.AllowFly)
385 icoNoFly.Visible = true;
387 icoNoFly.Visible = false;
389 if ((parcel.Flags & ParcelFlags.CreateObjects) != ParcelFlags.CreateObjects)
390 icoNoBuild.Visible = true;
392 icoNoBuild.Visible = false;
394 if ((parcel.Flags & ParcelFlags.AllowOtherScripts) != ParcelFlags.AllowOtherScripts)
395 icoNoScript.Visible = true;
397 icoNoScript.Visible = false;
399 if ((parcel.Flags & ParcelFlags.RestrictPushObject) == ParcelFlags.RestrictPushObject)
400 icoNoPush.Visible = true;
402 icoNoPush.Visible = false;
404 if ((parcel.Flags & ParcelFlags.AllowDamage) == ParcelFlags.AllowDamage)
405 icoHealth.Visible = true;
407 icoHealth.Visible = false;
409 if ((parcel.Flags & ParcelFlags.AllowVoiceChat) != ParcelFlags.AllowVoiceChat)
410 icoNoVoice.Visible = true;
412 icoNoVoice.Visible = false;
415 private void RefreshStatusBar()
417 if (netcom.IsLoggedIn)
419 tlblLoginName.Text = netcom.LoginOptions.FullName;
420 tlblMoneyBalance.Text = client.Self.Balance.ToString();
421 icoHealth.Text = client.Self.Health.ToString() + "%";
423 tlblRegionInfo.Text =
424 client.Network.CurrentSim.Name +
425 " (" + Math.Floor(client.Self.SimPosition.X).ToString() + ", " +
426 Math.Floor(client.Self.SimPosition.Y).ToString() + ", " +
427 Math.Floor(client.Self.SimPosition.Z).ToString() + ")";
431 tlblLoginName.Text = "Offline";
432 tlblMoneyBalance.Text = "0";
433 icoHealth.Text = "0%";
434 tlblRegionInfo.Text = "No Region";
435 tlblParcel.Text = "No Parcel";
437 icoHealth.Visible = false;
438 icoNoBuild.Visible = false;
439 icoNoFly.Visible = false;
440 icoNoPush.Visible = false;
441 icoNoScript.Visible = false;
442 icoNoVoice.Visible = false;
446 private void RefreshWindowTitle()
448 StringBuilder sb = new StringBuilder();
449 sb.Append("Radegast - ");
451 if (netcom.IsLoggedIn)
453 sb.Append("[" + netcom.LoginOptions.FullName + "]");
455 if (instance.State.IsAway)
457 sb.Append(" - Away");
458 if (instance.State.IsBusy) sb.Append(", Busy");
460 else if (instance.State.IsBusy)
462 sb.Append(" - Busy");
465 if (instance.State.IsFollowing)
467 sb.Append(" - Following ");
468 sb.Append(instance.State.FollowName);
473 sb.Append("Logged Out");
476 this.Text = sb.ToString();
480 private void InitializeStatusTimer()
482 statusTimer = new System.Timers.Timer(250);
483 statusTimer.SynchronizingObject = this;
484 statusTimer.Elapsed += new ElapsedEventHandler(statusTimer_Elapsed);
487 private void statusTimer_Elapsed(object sender, ElapsedEventArgs e)
489 // Mono sometimes fires timer after is's disposed
492 RefreshWindowTitle();
499 #region Initialization, configuration, and key shortcuts
500 private void InitializeTabsConsole()
502 tabsConsole = new TabsConsole(instance);
503 tabsConsole.Dock = DockStyle.Fill;
504 toolStripContainer1.ContentPanel.Controls.Add(tabsConsole);
507 private void frmMain_KeyDown(object sender, KeyEventArgs e)
510 if (e.Modifiers == Keys.Control && e.KeyCode == Keys.W)
512 e.Handled = e.SuppressKeyPress = true;
513 RadegastTab tab = tabsConsole.SelectedTab;
519 else if (tab.AllowHide)
527 // Ctl-Shift-H: Teleport Home
528 if (e.Modifiers == (Keys.Control | Keys.Shift) && e.KeyCode == Keys.H)
530 e.Handled = e.SuppressKeyPress = true;
531 tmnuTeleportHome.PerformClick();
535 // Alt-Ctrl-D Open debug console
536 if (e.Modifiers == (Keys.Control | Keys.Alt) && e.KeyCode == Keys.D)
538 e.Handled = e.SuppressKeyPress = true;
539 debugConsoleToolStripMenuItem.PerformClick();
543 // Alt 1-8: Toggle various tabs
544 if (e.Modifiers == Keys.Alt)
549 e.Handled = e.SuppressKeyPress = true;
550 tabsConsole.Tabs["chat"].Select();
554 e.Handled = e.SuppressKeyPress = true;
555 tbtnFriends.PerformClick();
559 e.Handled = e.SuppressKeyPress = true;
560 tbtnGroups.PerformClick();
564 e.Handled = e.SuppressKeyPress = true;
565 tbtnInventory.PerformClick();
569 e.Handled = e.SuppressKeyPress = true;
570 tbtnSearch.PerformClick();
574 e.Handled = e.SuppressKeyPress = true;
575 tbtnMap.PerformClick();
579 e.Handled = e.SuppressKeyPress = true;
580 tbnObjects.PerformClick();
584 e.Handled = e.SuppressKeyPress = true;
585 tbtnMedia.PerformClick();
589 e.Handled = e.SuppressKeyPress = true;
590 tbtnVoice.PerformClick();
595 // ctrl-g, goto slurl
596 if (e.Control && e.KeyCode == Keys.G)
598 if (!ProcessLink(Clipboard.GetText(), true))
599 MapToCurrentLocation();
601 e.Handled = e.SuppressKeyPress = true;
605 // ctrl-(shift)-tab for next/previous tab
606 if (e.Control && e.KeyCode == Keys.Tab)
610 TabConsole.SelectPreviousTab();
614 TabConsole.SelectNextTab();
616 e.Handled = e.SuppressKeyPress = true;
621 bool firstLoad = true;
623 private void frmMain_Load(object sender, EventArgs e)
628 tabsConsole.SelectTab("login");
629 ResourceManager rm = Properties.Resources.ResourceManager;
630 ResourceSet set = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
631 System.Collections.IDictionaryEnumerator de = set.GetEnumerator();
632 while (de.MoveNext() == true)
634 if (de.Entry.Value is Image)
636 Bitmap bitMap = de.Entry.Value as Bitmap;
637 ResourceImages.Images.Add(bitMap);
638 ImageNames.Add(de.Entry.Key.ToString());
641 StartUpdateCheck(false);
646 #region Public methods
648 private Dictionary<UUID, frmProfile> shownProfiles = new Dictionary<UUID, frmProfile>();
650 public void ShowAgentProfile(string name, UUID agentID)
654 frmProfile profile = null;
655 if (shownProfiles.TryGetValue(agentID, out profile))
657 profile.WindowState = FormWindowState.Normal;
662 profile = new frmProfile(instance, name, agentID);
664 profile.Disposed += (object sender, EventArgs e) =>
668 frmProfile agentProfile = (frmProfile)sender;
669 if (shownProfiles.ContainsKey(agentProfile.AgentID))
670 shownProfiles.Remove(agentProfile.AgentID);
676 shownProfiles.Add(agentID, profile);
681 private Dictionary<UUID, frmGroupInfo> shownGroupProfiles = new Dictionary<UUID, frmGroupInfo>();
683 public void ShowGroupProfile(AvatarGroup group)
685 ShowGroupProfile(new OpenMetaverse.Group()
688 InsigniaID = group.GroupInsigniaID,
689 Name = group.GroupName
694 public void ShowGroupProfile(OpenMetaverse.Group group)
696 lock (shownGroupProfiles)
698 frmGroupInfo profile = null;
699 if (shownGroupProfiles.TryGetValue(group.ID, out profile))
701 profile.WindowState = FormWindowState.Normal;
706 profile = new frmGroupInfo(instance, group);
708 profile.Disposed += (object sender, EventArgs e) =>
710 lock (shownGroupProfiles)
712 frmGroupInfo groupProfile = (frmGroupInfo)sender;
713 if (shownGroupProfiles.ContainsKey(groupProfile.Group.ID))
714 shownGroupProfiles.Remove(groupProfile.Group.ID);
720 shownGroupProfiles.Add(group.ID, profile);
725 public void ProcessLink(string link)
727 ProcessLink(link, false);
730 public bool ProcessLink(string link, bool onlyMap)
732 if (!link.Contains("://"))
734 link = "http://" + link;
737 Regex r = new Regex(@"^(http://(slurl\.com|maps\.secondlife\.com)/secondlife/|secondlife://)(?<region>[^/]+)/(?<x>\d+)/(?<y>\d+)(/(?<z>\d+))?",
738 RegexOptions.CultureInvariant | RegexOptions.ExplicitCapture | RegexOptions.IgnoreCase
740 Match m = r.Match(link);
744 string region = HttpUtility.UrlDecode(m.Groups["region"].Value);
745 int x = int.Parse(m.Groups["x"].Value);
746 int y = int.Parse(m.Groups["y"].Value);
749 if (!string.IsNullOrEmpty(m.Groups["z"].Value))
751 z = int.Parse(m.Groups["z"].Value);
755 WorldMap.DisplayLocation(region, x, y, z);
760 System.Diagnostics.Process.Start(link);
766 #region Notifications
767 CircularList<Control> notifications = new CircularList<Control>();
769 public Color NotificationBackground
771 get { return pnlDialog.BackColor; }
774 void ResizeNotificationByControl(Control active)
776 int Width = active.Size.Width + 6;
777 int Height = notifications.Count > 1 ? active.Size.Height + 3 + btnDialogNextControl.Size.Height : active.Size.Height + 3;
778 pnlDialog.Size = new Size(Width, Height);
780 pnlDialog.Left = pnlDialog.Parent.ClientSize.Width - Width;
782 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
783 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
785 btnDialogNextControl.BringToFront();
788 public void AddNotification(Control control)
792 BeginInvoke(new MethodInvoker(delegate()
794 AddNotification(control);
800 FormFlash.StartFlash(this);
801 pnlDialog.Visible = true;
802 pnlDialog.BringToFront();
804 foreach (Control existing in notifications)
806 existing.Visible = false;
809 notifications.Add(control);
810 control.Visible = true;
811 control.Anchor = AnchorStyles.Top | AnchorStyles.Left;
814 pnlDialog.Controls.Add(control);
815 ResizeNotificationByControl(control);
817 btnDialogNextControl.Visible = notifications.Count > 1;
820 public void RemoveNotification(Control control)
822 pnlDialog.Controls.Remove(control);
823 notifications.Remove(control);
826 if (notifications.HasNext)
828 pnlDialog.Visible = true;
829 Control active = notifications.Next;
830 active.Visible = true;
831 ResizeNotificationByControl(active);
835 pnlDialog.Visible = false;
838 btnDialogNextControl.Visible = notifications.Count > 1;
841 private void btnDialogNextControl_Click(object sender, EventArgs e)
843 foreach (Control existing in notifications)
845 existing.Visible = false;
848 if (notifications.HasNext)
850 pnlDialog.Visible = true;
851 Control active = notifications.Next;
852 active.Visible = true;
853 ResizeNotificationByControl(active);
857 pnlDialog.Visible = false;
861 #endregion Notifications
863 #region Menu click handlers
865 private void tbtnTeleport_Click(object sender, EventArgs e)
867 (new frmTeleport(instance)).ShowDialog();
870 private void tmnuStatusAway_Click(object sender, EventArgs e)
872 instance.State.SetAway(tmnuStatusAway.Checked);
875 private void tmnuHelpReadme_Click(object sender, EventArgs e)
877 System.Diagnostics.Process.Start(Application.StartupPath + @"\Readme.txt");
880 private void tmnuStatusBusy_Click(object sender, EventArgs e)
882 instance.State.SetBusy(tmnuStatusBusy.Checked);
885 private void tmnuControlFly_Click(object sender, EventArgs e)
887 instance.State.SetFlying(tmnuControlFly.Checked);
890 private void tmnuControlAlwaysRun_Click(object sender, EventArgs e)
892 instance.State.SetAlwaysRun(tmnuControlAlwaysRun.Checked);
895 private void tmnuPrefs_Click(object sender, EventArgs e)
897 (new frmSettings(instance)).ShowDialog();
900 private void tbtnAppearance_Click(object sender, EventArgs e)
902 client.Appearance.RequestSetAppearance(false);
905 private void importObjectToolStripMenuItem_Click(object sender, EventArgs e)
907 PrimDeserializer.ImportFromFile(client);
910 private void autopilotToolStripMenuItem_Click(object sender, EventArgs e)
914 ap = new AutoPilot(client);
916 ap.InsertWaypoint(new Vector3(66, 163, 21));
917 ap.InsertWaypoint(new Vector3(66, 98, 21));
919 ap.InsertWaypoint(new Vector3(101, 98, 21));
920 ap.InsertWaypoint(new Vector3(101, 45, 21));
921 ap.InsertWaypoint(new Vector3(93, 27, 21));
922 ap.InsertWaypoint(new Vector3(106, 12, 21));
923 ap.InsertWaypoint(new Vector3(123, 24, 21));
924 ap.InsertWaypoint(new Vector3(114, 45, 21));
925 ap.InsertWaypoint(new Vector3(114, 98, 21));
927 ap.InsertWaypoint(new Vector3(130, 98, 21));
928 ap.InsertWaypoint(new Vector3(130, 163, 21));
930 ap.InsertWaypoint(new Vector3(64, 68, 21));
931 ap.InsertWaypoint(new Vector3(65, 20, 21));
932 ap.InsertWaypoint(new Vector3(33, 23, 21));
933 ap.InsertWaypoint(new Vector3(17, 39, 21));
934 ap.InsertWaypoint(new Vector3(17, 62, 21));
940 AutoPilotActive = false;
945 AutoPilotActive = true;
951 private void cleanCacheToolStripMenuItem_Click(object sender, EventArgs e)
953 client.Assets.Cache.Clear();
956 private void rebakeTexturesToolStripMenuItem_Click(object sender, EventArgs e)
958 client.Appearance.RequestSetAppearance(true);
961 public void MapToCurrentLocation()
963 if (MapTab != null && client.Network.Connected)
966 WorldMap.DisplayLocation(client.Network.CurrentSim.Name,
967 (int)client.Self.SimPosition.X,
968 (int)client.Self.SimPosition.Y,
969 (int)client.Self.SimPosition.Z);
973 private void standToolStripMenuItem_Click(object sender, EventArgs e)
978 private void groundSitToolStripMenuItem_Click(object sender, EventArgs e)
980 client.Self.SitOnGround();
983 private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)
985 try { System.Diagnostics.Process.Start(Application.ExecutablePath); }
986 catch (Exception) { }
989 private void tmnuExit_Click(object sender, EventArgs e)
994 private void tlblRegionInfo_Click(object sender, EventArgs e)
996 if (WorldMap != null && client.Network.Connected)
1002 private void scriptEditorToolStripMenuItem_Click(object sender, EventArgs e)
1004 ScriptEditor se = new ScriptEditor(instance);
1005 se.Dock = DockStyle.Fill;
1009 private void tmnuSetHome_Click(object sender, EventArgs e)
1011 client.Self.SetHome();
1014 private void tmnuCreateLandmark_Click(object sender, EventArgs e)
1016 string location = string.Format(", {0} ({1}, {2}, {3})",
1017 client.Network.CurrentSim.Name,
1018 (int)client.Self.SimPosition.X,
1019 (int)client.Self.SimPosition.Y,
1020 (int)client.Self.SimPosition.Z
1023 string name = tlblParcel.Text;
1024 int maxLen = 63 - location.Length;
1026 if (name.Length > maxLen)
1027 name = name.Substring(0, maxLen);
1031 client.Inventory.RequestCreateItem(
1032 client.Inventory.FindFolderForType(AssetType.Landmark),
1034 tlblParcel.ToolTipText,
1037 InventoryType.Landmark,
1039 (bool success, InventoryItem item) =>
1043 BeginInvoke(new MethodInvoker(() =>
1045 Landmark ln = new Landmark(instance, (InventoryLandmark)item);
1046 ln.Dock = DockStyle.Fill;
1054 private void tmnuTeleportHome_Click(object sender, EventArgs e)
1056 if (WorldMap != null)
1062 private TimeZoneInfo SLTime;
1064 private void GetSLTimeZone()
1068 foreach (TimeZoneInfo tz in TimeZoneInfo.GetSystemTimeZones())
1070 if (tz.Id == "Pacific Standard Time" || tz.Id == "America/Los_Angeles")
1077 catch (Exception) { }
1080 private void timerWorldClock_Tick(object sender, EventArgs e)
1086 now = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, SLTime);
1088 now = DateTime.UtcNow.AddHours(-7);
1092 now = DateTime.UtcNow.AddHours(-7);
1094 lblTime.Text = now.ToString("h:mm tt", System.Globalization.CultureInfo.InvariantCulture);
1097 private void reportBugsToolStripMenuItem_Click(object sender, EventArgs e)
1099 ProcessLink("http://jira.openmetaverse.org/browse/RAD");
1102 private void aboutRadegastToolStripMenuItem_Click(object sender, EventArgs e)
1104 (new frmAbout(instance)).ShowDialog();
1107 #region Update Checking
1108 private UpdateChecker updateChecker = null;
1109 private bool ManualUpdateCheck = false;
1111 public void StartUpdateCheck(bool userInitiated)
1113 ManualUpdateCheck = userInitiated;
1115 if (updateChecker != null)
1117 if (ManualUpdateCheck)
1118 tabsConsole.DisplayNotificationInChat("Update check already in progress.");
1122 if (ManualUpdateCheck)
1123 tabsConsole.DisplayNotificationInChat("Checking for updates...", ChatBufferTextStyle.StatusBlue);
1124 updateChecker = new UpdateChecker();
1125 updateChecker.OnUpdateInfoReceived += new UpdateChecker.UpdateInfoCallback(OnUpdateInfoReceived);
1126 updateChecker.StartCheck();
1129 private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
1131 tabsConsole.SelectTab("chat");
1132 StartUpdateCheck(true);
1135 void OnUpdateInfoReceived(object sender, UpdateCheckerArgs e)
1139 BeginInvoke(new MethodInvoker(() => OnUpdateInfoReceived(sender, e)));
1145 if (ManualUpdateCheck)
1146 tabsConsole.DisplayNotificationInChat("Error: Failed connecting to the update site.", ChatBufferTextStyle.StatusBlue);
1150 if (!ManualUpdateCheck && e.Info.DisplayMOTD)
1152 tabsConsole.DisplayNotificationInChat(e.Info.MOTD, ChatBufferTextStyle.StatusBlue);
1155 if (e.Info.UpdateAvailable)
1157 tabsConsole.DisplayNotificationInChat("New version available at " + e.Info.DownloadSite, ChatBufferTextStyle.Alert);
1161 if (ManualUpdateCheck)
1162 tabsConsole.DisplayNotificationInChat("Your version is up to date.", ChatBufferTextStyle.StatusBlue);
1166 updateChecker.Dispose();
1167 updateChecker = null;
1171 private void ToggleHidden(string tabName)
1173 if (!tabsConsole.TabExists(tabName)) return;
1175 RadegastTab tab = tabsConsole.Tabs[tabName];
1194 private void tbtnFriends_Click(object sender, EventArgs e)
1196 ToggleHidden("friends");
1199 private void tbtnInventory_Click(object sender, EventArgs e)
1201 ToggleHidden("inventory");
1204 private void tbtnSearch_Click(object sender, EventArgs e)
1206 ToggleHidden("search");
1209 private void tbtnGroups_Click(object sender, EventArgs e)
1211 ToggleHidden("groups");
1214 private void tbtnVoice_Click(object sender, EventArgs e)
1216 ToggleHidden("voice");
1219 private void tbtnMedia_Click(object sender, EventArgs e)
1221 if (tabsConsole.TabExists("media"))
1223 ToggleHidden("media");
1227 RadegastTab tab = tabsConsole.AddTab("media", "Media", mediaConsole);
1228 tab.AllowClose = false;
1229 tab.AllowHide = true;
1234 private void debugConsoleToolStripMenuItem_Click(object sender, EventArgs e)
1236 if (tabsConsole.TabExists("debug"))
1238 ToggleHidden("debug");
1242 RadegastTab tab = tabsConsole.AddTab("debug", "Debug", new DebugConsole(instance));
1243 tab.AllowClose = false;
1244 tab.AllowHide = true;
1249 private void tbnObjects_Click(object sender, EventArgs e)
1251 if (tabsConsole.TabExists("objects"))
1253 RadegastTab tab = tabsConsole.Tabs["objects"];
1257 ((ObjectsConsole)tab.Control).RefreshObjectList();
1266 RadegastTab tab = tabsConsole.AddTab("objects", "Objects", new ObjectsConsole(instance));
1267 tab.AllowClose = true;
1268 tab.AllowDetach = true;
1270 tab.AllowHide = false;
1272 ((ObjectsConsole)tab.Control).RefreshObjectList();
1276 private void tbtnMap_Click(object sender, EventArgs e)
1278 ToggleHidden("map");
1280 MapToCurrentLocation();
1283 private void disconnectToolStripMenuItem_Click(object sender, EventArgs e)
1285 if (client.Network.Connected)
1286 client.Network.RequestLogout();
1289 private void reconnectToolStripMenuItem_Click(object sender, EventArgs e)
1291 instance.Reconnect();
1294 private frmKeyboardShortcuts keyboardShortcutsForm = null;
1295 private void keyboardShortcutsToolStripMenuItem_Click(object sender, EventArgs e)
1297 if (keyboardShortcutsForm != null)
1299 keyboardShortcutsForm.Focus();
1303 keyboardShortcutsForm = new frmKeyboardShortcuts(instance);
1305 keyboardShortcutsForm.Disposed += (object senderx, EventArgs ex) =>
1307 if (components != null)
1309 components.Remove(keyboardShortcutsForm);
1311 keyboardShortcutsForm = null;
1314 keyboardShortcutsForm.Show(this);
1315 keyboardShortcutsForm.Top = Top + 100;
1316 keyboardShortcutsForm.Left = Left + 100;
1318 if (components != null)
1320 components.Add(keyboardShortcutsForm);
1325 // Menu item for testing out stuff
1326 private void testToolStripMenuItem_Click(object sender, EventArgs e)
1328 foreach (KeyValuePair<UUID, string> kvp in Sounds.ToDictionary())
1330 client.Assets.RequestAsset(kvp.Key, AssetType.Sound, true, (AssetDownload transfer, Asset asset) =>
1332 System.Console.WriteLine("Sound '{0}' download success: {1}", transfer.AssetID, transfer.Success);
1338 private void reloadInventoryToolStripMenuItem_Click(object sender, EventArgs e)
1340 if (tabsConsole.TabExists("inventory"))
1342 ((InventoryConsole)tabsConsole.Tabs["inventory"].Control).ReloadInventory();
1343 tabsConsole.Tabs["inventory"].Select();
1347 private void btnLoadScript_Click(object sender, EventArgs e)
1349 if (!TabConsole.TabExists("plugin_manager"))
1351 TabConsole.AddTab("plugin_manager", "Plugins", new PluginsTab(instance));
1353 TabConsole.Tabs["plugin_manager"].Select();
1356 private void frmMain_Resize(object sender, EventArgs e)
1358 if (WindowState == FormWindowState.Minimized && instance.GlobalSettings["minimize_to_tray"].AsBoolean())
1360 ShowInTaskbar = false;
1361 trayIcon.Visible = true;
1365 private void treyIcon_MouseDoubleClick(object sender, MouseEventArgs e)
1367 WindowState = FormWindowState.Normal;
1368 ShowInTaskbar = true;
1369 trayIcon.Visible = false;
1372 private void ctxTreyRestore_Click(object sender, EventArgs e)
1374 treyIcon_MouseDoubleClick(this, null);
1377 private void ctxTreyExit_Click(object sender, EventArgs e)
1379 tmnuExit_Click(this, EventArgs.Empty);