2 // Radegast Metaverse Client
3 // Copyright (c) 2009-2013, Radegast Development Team
4 // All rights reserved.
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
9 // * Redistributions of source code must retain the above copyright notice,
10 // this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above copyright
12 // notice, this list of conditions and the following disclaimer in the
13 // documentation and/or other materials provided with the distribution.
14 // * Neither the name of the application "Radegast", nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 using System.Windows.Forms;
34 using OpenMetaverse.Assets;
38 public partial class Landmark : DettachableControl
40 private RadegastInstance instance;
41 private GridClient client { get { return instance.Client; } }
42 private InventoryLandmark landmark;
43 private AssetLandmark decodedLandmark;
44 private UUID parcelID;
45 private ParcelInfo parcel;
46 private Vector3 localPosition;
47 private bool parcelLocation = false;
49 public Landmark(RadegastInstance instance, InventoryLandmark landmark)
51 this.landmark = landmark;
53 client.Assets.RequestAsset(landmark.AssetUUID, landmark.AssetType, true, Assets_OnAssetReceived);
56 public Landmark(RadegastInstance instance, UUID parcelID)
58 this.parcelID = parcelID;
60 parcelLocation = true;
61 client.Parcels.RequestParcelInfo(parcelID);
64 void Init(RadegastInstance instance)
66 InitializeComponent();
67 Disposed += new EventHandler(Landmark_Disposed);
69 this.instance = instance;
72 client.Grid.RegionHandleReply += new EventHandler<RegionHandleReplyEventArgs>(Grid_RegionHandleReply);
73 client.Parcels.ParcelInfoReply += new EventHandler<ParcelInfoReplyEventArgs>(Parcels_ParcelInfoReply);
76 void Landmark_Disposed(object sender, EventArgs e)
78 client.Grid.RegionHandleReply -= new EventHandler<RegionHandleReplyEventArgs>(Grid_RegionHandleReply);
79 client.Parcels.ParcelInfoReply -= new EventHandler<ParcelInfoReplyEventArgs>(Parcels_ParcelInfoReply);
82 void Parcels_ParcelInfoReply(object sender, ParcelInfoReplyEventArgs e)
84 if (e.Parcel.ID != parcelID) return;
88 if (!instance.MonoRuntime || IsHandleCreated)
89 BeginInvoke(new MethodInvoker(() => Parcels_ParcelInfoReply(sender, e)));
93 this.parcel = e.Parcel;
95 pnlDetail.Visible = true;
96 if (parcel.SnapshotID != UUID.Zero)
98 SLImageHandler img = new SLImageHandler(instance, parcel.SnapshotID, "");
99 img.Dock = DockStyle.Fill;
100 pnlDetail.Controls.Add(img);
101 pnlDetail.Disposed += (object senderx, EventArgs ex) =>
108 btnTeleport.Enabled = true;
109 btnShowOnMap.Enabled = true;
113 localPosition = new Vector3();
114 localPosition.X = parcel.GlobalX % 256;
115 localPosition.Y = parcel.GlobalY % 256;
116 localPosition.Z = parcel.GlobalZ;
119 if (decodedLandmark == null)
121 txtParcelName.Text = string.Format("{0} - {1} ", parcel.Name, parcel.SimName);
125 txtParcelName.Text = string.Format("{0} - {1} ({2}, {3}, {4}) ", parcel.Name, parcel.SimName, (int)decodedLandmark.Position.X, (int)decodedLandmark.Position.Y, (int)decodedLandmark.Position.Z);
128 txtParcelDescription.Text = parcel.Description;
131 void Grid_RegionHandleReply(object sender, RegionHandleReplyEventArgs e)
133 if (decodedLandmark == null || decodedLandmark.RegionID != e.RegionID) return;
135 parcelID = client.Parcels.RequestRemoteParcelID(decodedLandmark.Position, e.RegionHandle, e.RegionID);
136 if (parcelID != UUID.Zero)
138 client.Parcels.RequestParcelInfo(parcelID);
142 void Assets_OnAssetReceived(AssetDownload transfer, Asset asset)
144 if (transfer.Success && asset.AssetType == AssetType.Landmark)
146 decodedLandmark = (AssetLandmark)asset;
147 decodedLandmark.Decode();
148 localPosition = decodedLandmark.Position;
149 client.Grid.RequestRegionHandle(decodedLandmark.RegionID);
153 private void btnTeleport_Click(object sender, EventArgs e)
155 instance.MainForm.WorldMap.DisplayLocation(parcel.SimName,
156 (int)localPosition.X,
157 (int)localPosition.Y,
158 (int)localPosition.Z);
159 instance.MainForm.WorldMap.DoTeleport();
162 private void btnShowOnMap_Click(object sender, EventArgs e)
164 instance.MainForm.WorldMap.Show();
165 instance.MainForm.WorldMap.DisplayLocation(parcel.SimName,
166 (int)localPosition.X,
167 (int)localPosition.Y,
168 (int)localPosition.Z);