OSDN Git Service

RAD-165: Added ability to find friends on the map
authorLatif Khalifa <latifer@streamgrid.net>
Wed, 25 Aug 2010 12:39:52 +0000 (12:39 +0000)
committerLatif Khalifa <latifer@streamgrid.net>
Wed, 25 Aug 2010 12:39:52 +0000 (12:39 +0000)
git-svn-id: https://radegast.googlecode.com/svn/trunk@729 f7a694da-4d33-11de-9ad6-1127a62b9fcd

Radegast/Core/Types/MapControl.cs
Radegast/GUI/Consoles/MapConsole.Designer.cs
Radegast/GUI/Consoles/MapConsole.cs

index b7fba1d..d1abd4d 100644 (file)
@@ -209,19 +209,39 @@ namespace Radegast
             }
         }
 
-        public void CenterMap(ulong regionHandle, uint localX, uint localY)
+        public void CenterMap(ulong regionHandle, uint localX, uint localY, bool setTarget)
         {
             uint regionX, regionY;
             Utils.LongToUInts(regionHandle, out regionX, out regionY);
-            CenterMap(regionX, regionY, localX, localY);
+            CenterMap(regionX, regionY, localX, localY, setTarget);
         }
 
-        public void CenterMap(uint regionX, uint regionY, uint localX, uint localY)
+        public void CenterMap(uint regionX, uint regionY, uint localX, uint localY, bool setTarget)
         {
             centerX = (double)regionX * 256 + (double)localX;
             centerY = (double)regionY * 256 + (double)localY;
             centered = true;
 
+            if (setTarget)
+            {
+                ulong handle = Utils.UIntsToLong(regionX * 256, regionY * 256);
+                if (regions.ContainsKey(handle))
+                {
+                    targetRegion = regions[handle];
+                    GetTargetParcel();
+                    if (MapTargetChanged != null)
+                    {
+                        MapTargetChanged(this, new MapTargetChangedEventArgs(targetRegion, (int)localX, (int)localY));
+                    }
+                }
+                else
+                {
+                    targetRegion = new GridRegion();
+                }
+                targetX = centerX;
+                targetY = centerY;
+            }
+
             // opensim grids need extra push
             if (Instance.Netcom.Grid.Platform == "OpenSim")
             {
index eea9b2f..9701955 100644 (file)
@@ -59,6 +59,7 @@ namespace Radegast
         private void InitializeComponent()
         {
             this.pnlSearch = new System.Windows.Forms.Panel();
+            this.ddOnlineFriends = new System.Windows.Forms.ComboBox();
             this.lblStatus = new System.Windows.Forms.Label();
             this.btnDestination = new System.Windows.Forms.Button();
             this.btnMyPos = new System.Windows.Forms.Button();
@@ -72,11 +73,11 @@ namespace Radegast
             this.label5 = new System.Windows.Forms.Label();
             this.nudZ = new System.Windows.Forms.NumericUpDown();
             this.label4 = new System.Windows.Forms.Label();
-            this.lstRegions = new Radegast.ListViewNoFlicker();
             this.btnSearch = new System.Windows.Forms.Button();
             this.txtRegion = new System.Windows.Forms.TextBox();
-            this.pnlMap = new System.Windows.Forms.Panel();
             this.zoomTracker = new System.Windows.Forms.TrackBar();
+            this.pnlMap = new System.Windows.Forms.Panel();
+            this.lstRegions = new Radegast.ListViewNoFlicker();
             this.pnlSearch.SuspendLayout();
             this.pnlProgress.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.nudX)).BeginInit();
@@ -87,6 +88,7 @@ namespace Radegast
             // 
             // pnlSearch
             // 
+            this.pnlSearch.Controls.Add(this.ddOnlineFriends);
             this.pnlSearch.Controls.Add(this.lblStatus);
             this.pnlSearch.Controls.Add(this.btnDestination);
             this.pnlSearch.Controls.Add(this.btnMyPos);
@@ -109,6 +111,19 @@ namespace Radegast
             this.pnlSearch.Size = new System.Drawing.Size(194, 412);
             this.pnlSearch.TabIndex = 0;
             // 
+            // ddOnlineFriends
+            // 
+            this.ddOnlineFriends.AccessibleName = "Find online friends on the grid";
+            this.ddOnlineFriends.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+            this.ddOnlineFriends.FormattingEnabled = true;
+            this.ddOnlineFriends.Items.AddRange(new object[] {
+            "Online Friends"});
+            this.ddOnlineFriends.Location = new System.Drawing.Point(6, 195);
+            this.ddOnlineFriends.Name = "ddOnlineFriends";
+            this.ddOnlineFriends.Size = new System.Drawing.Size(182, 21);
+            this.ddOnlineFriends.TabIndex = 3;
+            this.ddOnlineFriends.SelectedIndexChanged += new System.EventHandler(this.ddOnlineFriends_SelectedIndexChanged);
+            // 
             // lblStatus
             // 
             this.lblStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
@@ -125,7 +140,7 @@ namespace Radegast
             this.btnDestination.Location = new System.Drawing.Point(91, 299);
             this.btnDestination.Name = "btnDestination";
             this.btnDestination.Size = new System.Drawing.Size(75, 23);
-            this.btnDestination.TabIndex = 21;
+            this.btnDestination.TabIndex = 22;
             this.btnDestination.Text = "Destination";
             this.btnDestination.UseVisualStyleBackColor = true;
             this.btnDestination.Click += new System.EventHandler(this.btnDestination_Click);
@@ -145,7 +160,7 @@ namespace Radegast
             this.btnGoHome.Location = new System.Drawing.Point(91, 270);
             this.btnGoHome.Name = "btnGoHome";
             this.btnGoHome.Size = new System.Drawing.Size(75, 23);
-            this.btnGoHome.TabIndex = 21;
+            this.btnGoHome.TabIndex = 19;
             this.btnGoHome.Text = "Go home";
             this.btnGoHome.UseVisualStyleBackColor = true;
             this.btnGoHome.Click += new System.EventHandler(this.btnGoHome_Click);
@@ -252,21 +267,6 @@ namespace Radegast
             this.label4.TabIndex = 16;
             this.label4.Text = "Y";
             // 
-            // lstRegions
-            // 
-            this.lstRegions.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
-            this.lstRegions.Location = new System.Drawing.Point(6, 38);
-            this.lstRegions.MultiSelect = false;
-            this.lstRegions.Name = "lstRegions";
-            this.lstRegions.ShowGroups = false;
-            this.lstRegions.Size = new System.Drawing.Size(182, 175);
-            this.lstRegions.Sorting = System.Windows.Forms.SortOrder.Ascending;
-            this.lstRegions.TabIndex = 2;
-            this.lstRegions.UseCompatibleStateImageBehavior = false;
-            this.lstRegions.View = System.Windows.Forms.View.List;
-            this.lstRegions.SelectedIndexChanged += new System.EventHandler(this.lstRegions_SelectedIndexChanged);
-            this.lstRegions.Enter += new System.EventHandler(this.lstRegions_Enter);
-            // 
             // btnSearch
             // 
             this.btnSearch.Location = new System.Drawing.Point(136, 11);
@@ -285,14 +285,6 @@ namespace Radegast
             this.txtRegion.TabIndex = 0;
             this.txtRegion.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtRegion_KeyDown);
             // 
-            // pnlMap
-            // 
-            this.pnlMap.Dock = System.Windows.Forms.DockStyle.Fill;
-            this.pnlMap.Location = new System.Drawing.Point(0, 0);
-            this.pnlMap.Name = "pnlMap";
-            this.pnlMap.Size = new System.Drawing.Size(560, 412);
-            this.pnlMap.TabIndex = 1;
-            // 
             // zoomTracker
             // 
             this.zoomTracker.Location = new System.Drawing.Point(6, 331);
@@ -304,6 +296,29 @@ namespace Radegast
             this.zoomTracker.Visible = false;
             this.zoomTracker.Scroll += new System.EventHandler(this.zoomTracker_Scroll);
             // 
+            // pnlMap
+            // 
+            this.pnlMap.Dock = System.Windows.Forms.DockStyle.Fill;
+            this.pnlMap.Location = new System.Drawing.Point(0, 0);
+            this.pnlMap.Name = "pnlMap";
+            this.pnlMap.Size = new System.Drawing.Size(560, 412);
+            this.pnlMap.TabIndex = 1;
+            // 
+            // lstRegions
+            // 
+            this.lstRegions.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
+            this.lstRegions.Location = new System.Drawing.Point(6, 38);
+            this.lstRegions.MultiSelect = false;
+            this.lstRegions.Name = "lstRegions";
+            this.lstRegions.ShowGroups = false;
+            this.lstRegions.Size = new System.Drawing.Size(182, 151);
+            this.lstRegions.Sorting = System.Windows.Forms.SortOrder.Ascending;
+            this.lstRegions.TabIndex = 2;
+            this.lstRegions.UseCompatibleStateImageBehavior = false;
+            this.lstRegions.View = System.Windows.Forms.View.List;
+            this.lstRegions.SelectedIndexChanged += new System.EventHandler(this.lstRegions_SelectedIndexChanged);
+            this.lstRegions.Enter += new System.EventHandler(this.lstRegions_Enter);
+            // 
             // MapConsole
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -344,6 +359,7 @@ namespace Radegast
         public System.Windows.Forms.Button btnMyPos;
         public System.Windows.Forms.Label lblStatus;
         private System.Windows.Forms.TrackBar zoomTracker;
+        private System.Windows.Forms.ComboBox ddOnlineFriends;
 
     }
 }
\ No newline at end of file
index c8adba2..a2b5ffe 100644 (file)
@@ -74,6 +74,7 @@ namespace Radegast
             client.Grid.GridRegion += new EventHandler<GridRegionEventArgs>(Grid_GridRegion);
             client.Self.TeleportProgress += new EventHandler<TeleportEventArgs>(Self_TeleportProgress);
             client.Network.SimChanged += new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+            client.Friends.FriendFoundReply += new EventHandler<FriendFoundReplyEventArgs>(Friends_FriendFoundReply);
         }
 
         private void UnregisterClientEvents(GridClient client)
@@ -81,6 +82,7 @@ namespace Radegast
             client.Grid.GridRegion -= new EventHandler<GridRegionEventArgs>(Grid_GridRegion);
             client.Self.TeleportProgress -= new EventHandler<TeleportEventArgs>(Self_TeleportProgress);
             client.Network.SimChanged -= new EventHandler<SimChangedEventArgs>(Network_SimChanged);
+            client.Friends.FriendFoundReply -= new EventHandler<FriendFoundReplyEventArgs>(Friends_FriendFoundReply);
         }
 
         void instance_ClientChanged(object sender, ClientChangedEventArgs e)
@@ -322,7 +324,14 @@ namespace Radegast
                 return;
             }
 
-            if (e.Region.Name.ToLower().Contains(txtRegion.Text.ToLower())
+            if (e.Region.RegionHandle == friendRegionHandle)
+            {
+                txtRegion.Text = e.Region.Name;
+                friendRegionHandle = 0;
+            }
+
+            if (!string.IsNullOrEmpty(txtRegion.Text)
+                && e.Region.Name.ToLower().Contains(txtRegion.Text.ToLower())
                 && !lstRegions.Items.ContainsKey(e.Region.Name))
             {
                 ListViewItem item = new ListViewItem(e.Region.Name);
@@ -432,7 +441,7 @@ namespace Radegast
                     );
                     return;
                 }
-                mmap.CenterMap(regionHandles[regionName], (uint)simX, (uint)simY);
+                mmap.CenterMap(regionHandles[regionName], (uint)simX, (uint)simY, false);
                 return;
             }
 
@@ -523,6 +532,25 @@ namespace Radegast
 
         private void MapConsole_VisibleChanged(object sender, EventArgs e)
         {
+            if (Visible)
+            {
+                ddOnlineFriends.Items.Clear();
+                ddOnlineFriends.Items.Add("Online Friends");
+                ddOnlineFriends.SelectedIndex = 0;
+
+                var friends = client.Friends.FriendList.FindAll((FriendInfo f) => { return f.CanSeeThemOnMap && f.IsOnline; });
+                if (friends != null)
+                {
+                    foreach (var f in friends)
+                    {
+                        if (f.Name != null)
+                        {
+                            ddOnlineFriends.Items.Add(f.Name);
+                        }
+                    }
+                }
+            }
+
             if (!mapCreated && Visible)
             {
                 createMap();
@@ -543,5 +571,54 @@ namespace Radegast
         }
 
         #endregion GUIEvents
+
+        #region Map friends
+        FriendInfo mapFriend = null;
+        ulong friendRegionHandle = 0;
+
+        void Friends_FriendFoundReply(object sender, FriendFoundReplyEventArgs e)
+        {
+            if (mapFriend == null || mapFriend.UUID != e.AgentID) return;
+
+            if (InvokeRequired)
+            {
+                if (IsHandleCreated)
+                {
+                    BeginInvoke(new MethodInvoker(() => Friends_FriendFoundReply(sender, e)));
+                }
+                return;
+            }
+
+            txtRegion.Text = string.Empty;
+            nudX.Value = (int)e.Location.X;
+            nudY.Value = (int)e.Location.Y;
+            nudZ.Value = (int)e.Location.Z;
+            friendRegionHandle = e.RegionHandle;
+            uint x, y;
+            Utils.LongToUInts(e.RegionHandle, out x, out y);
+            x /= 256;
+            y /= 256;
+            ulong hndle = Utils.UIntsToLong(x, y);
+            foreach (KeyValuePair<string, ulong> kvp in regionHandles)
+            {
+                if (kvp.Value == hndle)
+                {
+                    txtRegion.Text = kvp.Key;
+                }
+            }
+            mmap.CenterMap(x, y, (uint)e.Location.X, (uint)e.Location.Y, true);
+        }
+
+        private void ddOnlineFriends_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            if (ddOnlineFriends.SelectedIndex < 1) return;
+            mapFriend = client.Friends.FriendList.Find((FriendInfo f) => { return f.Name == ddOnlineFriends.SelectedItem.ToString(); });
+            if (mapFriend != null)
+            {
+                friendRegionHandle = 0;
+                client.Friends.MapFriend(mapFriend.UUID);
+            }
+        }
+        #endregion Map friends
     }
 }