2 // Radegast Metaverse Client
\r
3 // Copyright (c) 2009, Radegast Development Team
\r
4 // All rights reserved.
\r
6 // Redistribution and use in source and binary forms, with or without
\r
7 // modification, are permitted provided that the following conditions are met:
\r
9 // * Redistributions of source code must retain the above copyright notice,
\r
10 // this list of conditions and the following disclaimer.
\r
11 // * Redistributions in binary form must reproduce the above copyright
\r
12 // notice, this list of conditions and the following disclaimer in the
\r
13 // documentation and/or other materials provided with the distribution.
\r
14 // * Neither the name of the application "Radegast", nor the names of its
\r
15 // contributors may be used to endorse or promote products derived from
\r
16 // this software without specific prior written permission.
\r
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 using System.Collections.Generic;
\r
33 using System.ComponentModel;
\r
34 using System.Configuration;
\r
36 using System.Drawing;
\r
38 using System.Text.RegularExpressions;
\r
39 using System.Timers;
\r
40 using System.Windows.Forms;
\r
41 using System.Resources;
\r
44 using OpenMetaverse;
\r
45 using OpenMetaverse.Imaging;
\r
49 public partial class frmMain : Form
\r
51 #region Public members
\r
52 public static ImageList ResourceImages = new ImageList();
\r
53 public static List<string> ImageNames = new List<string>();
\r
54 public frmMap worldMap;
\r
55 public TabsConsole TabConsole
\r
57 get { return tabsConsole; }
\r
61 #region Private members
\r
62 private RadegastInstance instance;
\r
63 private RadegastNetcom netcom;
\r
64 private GridClient client;
\r
65 private TabsConsole tabsConsole;
\r
66 private frmDebugLog debugLogForm;
\r
67 private System.Timers.Timer statusTimer;
\r
68 private AutoPilot ap;
\r
69 private bool AutoPilotActive = false;
\r
70 private TransparentButton btnDialogNextControl;
\r
73 #region Constructor and disposal
\r
74 public frmMain(RadegastInstance instance)
\r
76 InitializeComponent();
\r
77 Disposed += new EventHandler(frmMain_Disposed);
\r
79 this.instance = instance;
\r
80 client = this.instance.Client;
\r
81 netcom = this.instance.Netcom;
\r
82 netcom.NetcomSync = this;
\r
84 pnlDialog.Visible = false;
\r
85 btnDialogNextControl = new TransparentButton();
\r
86 pnlDialog.Controls.Add(btnDialogNextControl);
\r
88 btnDialogNextControl.Size = new Size(35, 20);
\r
89 btnDialogNextControl.BackColor = Color.Transparent;
\r
90 btnDialogNextControl.ForeColor = Color.Gold;
\r
91 btnDialogNextControl.FlatAppearance.BorderSize = 0;
\r
92 btnDialogNextControl.FlatStyle = FlatStyle.Flat;
\r
93 btnDialogNextControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
\r
94 btnDialogNextControl.Text = ">>";
\r
95 btnDialogNextControl.Font = new Font(btnDialogNextControl.Font, FontStyle.Bold);
\r
96 btnDialogNextControl.Margin = new Padding(0);
\r
97 btnDialogNextControl.Padding = new Padding(0);
\r
98 btnDialogNextControl.UseVisualStyleBackColor = false;
\r
99 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
\r
100 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
\r
101 btnDialogNextControl.Click += new EventHandler(btnDialogNextControl_Click);
\r
103 if (instance.MonoRuntime)
\r
105 statusStrip1.LayoutStyle = ToolStripLayoutStyle.Table;
\r
109 netcom.ClientLoginStatus += new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);
\r
110 netcom.ClientLoggedOut += new EventHandler(netcom_ClientLoggedOut);
\r
111 netcom.ClientDisconnected += new EventHandler<ClientDisconnectEventArgs>(netcom_ClientDisconnected);
\r
112 client.Parcels.OnParcelProperties += new ParcelManager.ParcelPropertiesCallback(Parcels_OnParcelProperties);
\r
113 client.Self.OnMoneyBalanceReplyReceived += new AgentManager.MoneyBalanceReplyCallback(Self_OnMoneyBalanceReplyReceived);
\r
115 InitializeStatusTimer();
\r
116 RefreshWindowTitle();
\r
118 ApplyConfig(this.instance.Config.CurrentConfig, true);
\r
119 this.instance.Config.ConfigApplied += new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);
\r
122 void frmMain_Disposed(object sender, EventArgs e)
\r
124 netcom.ClientLoginStatus -= new EventHandler<ClientLoginEventArgs>(netcom_ClientLoginStatus);
\r
125 netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
\r
126 netcom.ClientDisconnected -= new EventHandler<ClientDisconnectEventArgs>(netcom_ClientDisconnected);
\r
127 client.Parcels.OnParcelProperties -= new ParcelManager.ParcelPropertiesCallback(Parcels_OnParcelProperties);
\r
128 client.Self.OnMoneyBalanceReplyReceived -= new AgentManager.MoneyBalanceReplyCallback(Self_OnMoneyBalanceReplyReceived);
\r
130 this.instance.Config.ConfigApplied -= new EventHandler<ConfigAppliedEventArgs>(Config_ConfigApplied);
\r
131 this.instance.CleanUp();
\r
135 #region Event handlers
\r
136 void Self_OnMoneyBalanceReplyReceived(UUID transactionID, bool transactionSuccess, int balance, int metersCredit, int metersCommitted, string description)
\r
138 if (!String.IsNullOrEmpty(description))
\r
140 AddNotification(new ntfGeneric(instance, description));
\r
144 private void Config_ConfigApplied(object sender, ConfigAppliedEventArgs e)
\r
146 ApplyConfig(e.AppliedConfig, false);
\r
149 private void ApplyConfig(Config config, bool doingInit)
\r
152 this.WindowState = (FormWindowState)config.MainWindowState;
\r
154 if (config.InterfaceStyle == 0) //System
\r
155 toolStrip1.RenderMode = ToolStripRenderMode.System;
\r
156 else if (config.InterfaceStyle == 1) //Office 2003
\r
157 toolStrip1.RenderMode = ToolStripRenderMode.ManagerRenderMode;
\r
158 aLICEToolStripMenuItem.Checked = config.UseAlice;
\r
161 public void InitializeControls()
\r
163 InitializeTabsConsole();
\r
164 InitializeDebugLogForm();
\r
167 private void netcom_ClientLoginStatus(object sender, ClientLoginEventArgs e)
\r
169 if (e.Status != LoginStatus.Success) return;
\r
171 tbnObjects.Enabled = tbtnStatus.Enabled = tbtnControl.Enabled = tbnTeleprotMulti.Enabled = tmnuImport.Enabled = true;
\r
172 statusTimer.Start();
\r
173 RefreshWindowTitle();
\r
176 private void netcom_ClientLoggedOut(object sender, EventArgs e)
\r
178 tbnObjects.Enabled = tbtnStatus.Enabled = tbtnControl.Enabled = tbnTeleprotMulti.Enabled = tmnuImport.Enabled = false;
\r
180 statusTimer.Stop();
\r
182 RefreshStatusBar();
\r
183 RefreshWindowTitle();
\r
186 private void netcom_ClientDisconnected(object sender, ClientDisconnectEventArgs e)
\r
188 if (e.Type == NetworkManager.DisconnectType.ClientInitiated) return;
\r
190 tbnObjects.Enabled = tbtnStatus.Enabled = tbtnControl.Enabled = tbnTeleprotMulti.Enabled = false;
\r
192 statusTimer.Stop();
\r
194 RefreshStatusBar();
\r
195 RefreshWindowTitle();
\r
198 private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
\r
200 if (debugLogForm != null) {
\r
201 debugLogForm.Close();
\r
202 debugLogForm = null;
\r
205 if (worldMap != null)
\r
211 if (netcom.IsLoggedIn) netcom.Logout();
\r
213 instance.Config.CurrentConfig.MainWindowState = (int)this.WindowState;
\r
217 # region Update status
\r
219 private void Parcels_OnParcelProperties(Simulator simulator, Parcel parcel, ParcelResult result, int selectedPrims,
\r
220 int sequenceID, bool snapSelection)
\r
222 if (result != ParcelResult.Single) return;
\r
223 if (InvokeRequired)
\r
225 BeginInvoke(new MethodInvoker(delegate()
\r
227 Parcels_OnParcelProperties(simulator, parcel, result, selectedPrims, sequenceID, snapSelection);
\r
233 tlblParcel.Text = parcel.Name;
\r
234 tlblParcel.ToolTipText = parcel.Desc;
\r
236 if ((parcel.Flags & ParcelFlags.AllowFly) != ParcelFlags.AllowFly)
\r
237 icoNoFly.Visible = true;
\r
239 icoNoFly.Visible = false;
\r
241 if ((parcel.Flags & ParcelFlags.CreateObjects) != ParcelFlags.CreateObjects)
\r
242 icoNoBuild.Visible = true;
\r
244 icoNoBuild.Visible = false;
\r
246 if ((parcel.Flags & ParcelFlags.AllowOtherScripts) != ParcelFlags.AllowOtherScripts)
\r
247 icoNoScript.Visible = true;
\r
249 icoNoScript.Visible = false;
\r
251 if ((parcel.Flags & ParcelFlags.RestrictPushObject) == ParcelFlags.RestrictPushObject)
\r
252 icoNoPush.Visible = true;
\r
254 icoNoPush.Visible = false;
\r
256 if ((parcel.Flags & ParcelFlags.AllowDamage) == ParcelFlags.AllowDamage)
\r
257 icoHealth.Visible = true;
\r
259 icoHealth.Visible = false;
\r
261 if ((parcel.Flags & ParcelFlags.AllowVoiceChat) != ParcelFlags.AllowVoiceChat)
\r
262 icoNoVoice.Visible = true;
\r
264 icoNoVoice.Visible = false;
\r
267 private void RefreshStatusBar()
\r
269 if (netcom.IsLoggedIn)
\r
271 tlblLoginName.Text = netcom.LoginOptions.FullName;
\r
272 tlblMoneyBalance.Text = client.Self.Balance.ToString();
\r
273 icoHealth.Text = client.Self.Health.ToString() + "%";
\r
275 tlblRegionInfo.Text =
\r
276 client.Network.CurrentSim.Name +
\r
277 " (" + Math.Floor(client.Self.SimPosition.X).ToString() + ", " +
\r
278 Math.Floor(client.Self.SimPosition.Y).ToString() + ", " +
\r
279 Math.Floor(client.Self.SimPosition.Z).ToString() + ")";
\r
283 tlblLoginName.Text = "Offline";
\r
284 tlblMoneyBalance.Text = "0";
\r
285 icoHealth.Text = "0%";
\r
286 tlblRegionInfo.Text = "No Region";
\r
287 tlblParcel.Text = "No Parcel";
\r
289 icoHealth.Visible = false;
\r
290 icoNoBuild.Visible = false;
\r
291 icoNoFly.Visible = false;
\r
292 icoNoPush.Visible = false;
\r
293 icoNoScript.Visible = false;
\r
294 icoNoVoice.Visible = false;
\r
298 private void RefreshWindowTitle()
\r
300 StringBuilder sb = new StringBuilder();
\r
301 sb.Append("Radegast - ");
\r
303 if (netcom.IsLoggedIn)
\r
305 sb.Append("[" + netcom.LoginOptions.FullName + "]");
\r
307 if (instance.State.IsAway)
\r
309 sb.Append(" - Away");
\r
310 if (instance.State.IsBusy) sb.Append(", Busy");
\r
312 else if (instance.State.IsBusy)
\r
314 sb.Append(" - Busy");
\r
317 if (instance.State.IsFollowing)
\r
319 sb.Append(" - Following ");
\r
320 sb.Append(instance.State.FollowName);
\r
325 sb.Append("Logged Out");
\r
328 this.Text = sb.ToString();
\r
332 private void InitializeStatusTimer()
\r
334 statusTimer = new System.Timers.Timer(250);
\r
335 statusTimer.SynchronizingObject = this;
\r
336 statusTimer.Elapsed += new ElapsedEventHandler(statusTimer_Elapsed);
\r
339 private void statusTimer_Elapsed(object sender, ElapsedEventArgs e)
\r
341 RefreshWindowTitle();
\r
342 RefreshStatusBar();
\r
346 #region Initialization, configuration, and key shortcuts
\r
347 private void InitializeTabsConsole()
\r
349 tabsConsole = new TabsConsole(instance);
\r
350 tabsConsole.Dock = DockStyle.Fill;
\r
351 toolStripContainer1.ContentPanel.Controls.Add(tabsConsole);
\r
354 private void InitializeDebugLogForm()
\r
356 debugLogForm = new frmDebugLog(instance);
\r
359 private void frmMain_KeyUp(object sender, KeyEventArgs e)
\r
361 if (e.Control && e.Alt && e.KeyCode == Keys.D)
\r
362 tbtnDebug.Visible = !tbtnDebug.Visible;
\r
364 if (e.Control && e.KeyCode == Keys.O && client.Network.Connected)
\r
366 (new frmObjects(instance)).Show();
\r
371 private void frmMain_Load(object sender, EventArgs e)
\r
373 worldMap = new frmMap(instance);
\r
374 tabsConsole.SelectTab("Main");
\r
375 ResourceManager rm = Properties.Resources.ResourceManager;
\r
376 ResourceSet set = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentCulture, true, true);
\r
377 System.Collections.IDictionaryEnumerator de = set.GetEnumerator();
\r
378 while (de.MoveNext() == true)
\r
380 if (de.Entry.Value is Image)
\r
382 Bitmap bitMap = de.Entry.Value as Bitmap;
\r
383 ResourceImages.Images.Add(bitMap);
\r
384 ImageNames.Add(de.Entry.Key.ToString());
\r
390 #region Public methods
\r
391 public void processLink(string link)
\r
393 if (!(link.StartsWith("http://") || link.StartsWith("ftp://")))
\r
395 link = "http://" + link;
\r
398 Regex r = new Regex(@"^(http://slurl.com/secondlife/|secondlife://)([^/]+)/(\d+)/(\d+)(/(\d+))?");
\r
399 Match m = r.Match(link);
\r
403 string region = Uri.UnescapeDataString(m.Groups[2].Value);
\r
404 int x = int.Parse(m.Groups[3].Value);
\r
405 int y = int.Parse(m.Groups[4].Value);
\r
408 if (m.Groups.Count > 5 && m.Groups[6].Value != String.Empty)
\r
410 z = int.Parse(m.Groups[6].Value);
\r
415 worldMap.displayLocation(region, x, y, z);
\r
419 System.Diagnostics.Process.Start(link);
\r
425 #region Notifications
\r
426 CircularList<Control> notifications = new CircularList<Control>();
\r
428 public Color NotificationBackground
\r
430 get { return pnlDialog.BackColor; }
\r
433 void ResizeNotificationByControl(Control active)
\r
435 int Width = active.Size.Width + 6;
\r
436 int Height = notifications.Count > 1 ? active.Size.Height + 3 + btnDialogNextControl.Size.Height : active.Size.Height + 3;
\r
437 pnlDialog.Size = new Size(Width, Height);
\r
439 pnlDialog.Left = pnlDialog.Parent.ClientSize.Width - Width;
\r
441 btnDialogNextControl.Top = btnDialogNextControl.Parent.ClientSize.Height - btnDialogNextControl.Size.Height;
\r
442 btnDialogNextControl.Left = btnDialogNextControl.Parent.ClientSize.Width - btnDialogNextControl.Size.Width;
\r
444 btnDialogNextControl.BringToFront();
\r
447 public void AddNotification(Control control)
\r
449 if (InvokeRequired)
\r
451 BeginInvoke(new MethodInvoker(delegate()
\r
453 AddNotification(control);
\r
459 FormFlash.StartFlash(this);
\r
460 pnlDialog.Visible = true;
\r
461 pnlDialog.BringToFront();
\r
463 foreach (Control existing in notifications)
\r
465 existing.Visible = false;
\r
468 notifications.Add(control);
\r
469 control.Visible = true;
\r
470 control.Anchor = AnchorStyles.Top | AnchorStyles.Left;
\r
473 pnlDialog.Controls.Add(control);
\r
474 ResizeNotificationByControl(control);
\r
476 btnDialogNextControl.Visible = notifications.Count > 1;
\r
479 public void RemoveNotification(Control control)
\r
481 pnlDialog.Controls.Remove(control);
\r
482 notifications.Remove(control);
\r
485 if (notifications.HasNext)
\r
487 pnlDialog.Visible = true;
\r
488 Control active = notifications.Next;
\r
489 active.Visible = true;
\r
490 ResizeNotificationByControl(active);
\r
494 pnlDialog.Visible = false;
\r
497 btnDialogNextControl.Visible = notifications.Count > 1;
\r
500 private void btnDialogNextControl_Click(object sender, EventArgs e)
\r
502 foreach (Control existing in notifications)
\r
504 existing.Visible = false;
\r
507 if (notifications.HasNext)
\r
509 pnlDialog.Visible = true;
\r
510 Control active = notifications.Next;
\r
511 active.Visible = true;
\r
512 ResizeNotificationByControl(active);
\r
516 pnlDialog.Visible = false;
\r
520 #endregion Notifications
\r
522 #region Menu click handlers
\r
524 private void tbtnTeleport_Click(object sender, EventArgs e)
\r
526 (new frmTeleport(instance)).ShowDialog();
\r
529 private void tmnuStatusAway_Click(object sender, EventArgs e)
\r
531 instance.State.SetAway(tmnuStatusAway.Checked);
\r
534 private void tmnuHelpReadme_Click(object sender, EventArgs e)
\r
536 System.Diagnostics.Process.Start(Application.StartupPath + @"\Readme.txt");
\r
539 private void tmnuStatusBusy_Click(object sender, EventArgs e)
\r
541 instance.State.SetBusy(tmnuStatusBusy.Checked);
\r
544 private void tmnuControlFly_Click(object sender, EventArgs e)
\r
546 instance.State.SetFlying(tmnuControlFly.Checked);
\r
549 private void tmnuControlAlwaysRun_Click(object sender, EventArgs e)
\r
551 instance.State.SetAlwaysRun(tmnuControlAlwaysRun.Checked);
\r
554 private void tmnuDebugLog_Click(object sender, EventArgs e)
\r
556 debugLogForm.Show();
\r
559 private void tmnuPrefs_Click(object sender, EventArgs e)
\r
561 (new frmPreferences(instance)).ShowDialog();
\r
564 private void tbtnObjects_Click(object sender, EventArgs e)
\r
566 (new frmObjects(instance)).Show();
\r
569 private void tbtnAppearance_Click(object sender, EventArgs e)
\r
571 client.Appearance.SetPreviousAppearance(true);
\r
574 private void groupsToolStripMenuItem_Click(object sender, EventArgs e)
\r
576 (new GroupsDialog(instance)).Show();
\r
579 private void homeToolStripMenuItem_Click(object sender, EventArgs e)
\r
584 private void importObjectToolStripMenuItem_Click(object sender, EventArgs e)
\r
586 PrimDeserializer.ImportFromFile(client);
\r
589 private void autopilotToolStripMenuItem_Click(object sender, EventArgs e)
\r
592 ap = new AutoPilot(client);
\r
594 ap.InsertWaypoint(new Vector3(66, 163, 21));
\r
595 ap.InsertWaypoint(new Vector3(66, 98, 21));
\r
597 ap.InsertWaypoint(new Vector3(101, 98, 21));
\r
598 ap.InsertWaypoint(new Vector3(101, 45, 21));
\r
599 ap.InsertWaypoint(new Vector3(93, 27, 21));
\r
600 ap.InsertWaypoint(new Vector3(106, 12, 21));
\r
601 ap.InsertWaypoint(new Vector3(123, 24, 21));
\r
602 ap.InsertWaypoint(new Vector3(114, 45, 21));
\r
603 ap.InsertWaypoint(new Vector3(114, 98, 21));
\r
605 ap.InsertWaypoint(new Vector3(130, 98, 21));
\r
606 ap.InsertWaypoint(new Vector3(130, 163, 21));
\r
608 ap.InsertWaypoint(new Vector3(64, 68, 21));
\r
609 ap.InsertWaypoint(new Vector3(65, 20, 21));
\r
610 ap.InsertWaypoint(new Vector3(33, 23, 21));
\r
611 ap.InsertWaypoint(new Vector3(17, 39, 21));
\r
612 ap.InsertWaypoint(new Vector3(17, 62, 21));
\r
616 if (AutoPilotActive) {
\r
617 AutoPilotActive = false;
\r
620 AutoPilotActive = true;
\r
626 private void aLICEToolStripMenuItem_Click(object sender, EventArgs e)
\r
628 if (instance.Config.CurrentConfig.UseAlice == false) {
\r
629 instance.Config.CurrentConfig.UseAlice = true;
\r
630 aLICEToolStripMenuItem.Checked = true;
\r
632 instance.Config.CurrentConfig.UseAlice = false;
\r
633 aLICEToolStripMenuItem.Checked = false;
\r
635 instance.Config.SaveCurrentConfig();
\r
638 private void cleanCacheToolStripMenuItem_Click(object sender, EventArgs e)
\r
640 client.Assets.Cache.Clear();
\r
641 DirectoryInfo di = new DirectoryInfo(instance.AnimCacheDir);
\r
642 FileInfo[] files = di.GetFiles();
\r
645 foreach (FileInfo file in files)
\r
651 Logger.Log("Wiped out " + num + " files from the anim cache directory.", Helpers.LogLevel.Debug);
\r
655 private void rebakeTexturesToolStripMenuItem_Click(object sender, EventArgs e)
\r
657 client.Appearance.ForceRebakeAvatarTextures();
\r
660 private void mapToolStripMenuItem_Click(object sender, EventArgs e)
\r
662 if (!worldMap.Visible)
\r
672 private void standToolStripMenuItem_Click(object sender, EventArgs e)
\r
674 client.Self.Stand();
\r
677 private void groundSitToolStripMenuItem_Click(object sender, EventArgs e)
\r
679 client.Self.SitOnGround();
\r
682 private void tbnObjects_Click(object sender, EventArgs e)
\r
684 (new frmObjects(instance)).Show();
\r
687 private void newWindowToolStripMenuItem_Click(object sender, EventArgs e)
\r
689 try { System.Diagnostics.Process.Start(Application.ExecutablePath); }
\r
690 catch (Exception) { }
\r
693 private void tmnuExit_Click(object sender, EventArgs e)
\r
698 private void tlblRegionInfo_Click(object sender, EventArgs e)
\r
700 if (worldMap != null && client.Network.Connected)
\r