corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * - Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using System.Collections.Generic; |
||
29 | using System.Drawing; |
||
30 | using System.Windows.Forms; |
||
31 | using OpenMetaverse.Imaging; |
||
32 | using OpenMetaverse.Assets; |
||
33 | |||
34 | namespace OpenMetaverse.GUI |
||
35 | { |
||
36 | /// <summary> |
||
37 | /// PictureBox GUI component for displaying a client's mini-map |
||
38 | /// </summary> |
||
39 | public class MiniMap : PictureBox |
||
40 | { |
||
41 | private static Brush BG_COLOR = Brushes.Navy; |
||
42 | |||
43 | private UUID _MapImageID; |
||
44 | private GridClient _Client; |
||
45 | private Image _MapLayer; |
||
46 | //warning CS0414: The private field `OpenMetaverse.GUI.MiniMap._MousePosition' is assigned but its value is never used |
||
47 | //private Point _MousePosition; |
||
48 | ToolTip _ToolTip; |
||
49 | |||
50 | /// <summary> |
||
51 | /// Gets or sets the GridClient associated with this control |
||
52 | /// </summary> |
||
53 | public GridClient Client |
||
54 | { |
||
55 | get { return _Client; } |
||
56 | set { if (value != null) InitializeClient(value); } |
||
57 | } |
||
58 | |||
59 | /// <summary> |
||
60 | /// PictureBox control for an unspecified client's mini-map |
||
61 | /// </summary> |
||
62 | public MiniMap() |
||
63 | { |
||
64 | this.BorderStyle = BorderStyle.FixedSingle; |
||
65 | this.SizeMode = PictureBoxSizeMode.Zoom; |
||
66 | } |
||
67 | |||
68 | /// <summary> |
||
69 | /// PictureBox control for the specified client's mini-map |
||
70 | /// </summary> |
||
71 | public MiniMap(GridClient client) : this () |
||
72 | { |
||
73 | InitializeClient(client); |
||
74 | |||
75 | _ToolTip = new ToolTip(); |
||
76 | _ToolTip.Active = true; |
||
77 | _ToolTip.AutomaticDelay = 1; |
||
78 | |||
79 | this.MouseHover += new System.EventHandler(MiniMap_MouseHover); |
||
80 | this.MouseMove += new MouseEventHandler(MiniMap_MouseMove); |
||
81 | } |
||
82 | |||
83 | /// <summary>Sets the map layer to the specified bitmap image</summary> |
||
84 | /// <param name="mapImage"></param> |
||
85 | public void SetMapLayer(Bitmap mapImage) |
||
86 | { |
||
87 | if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { SetMapLayer(mapImage); }); |
||
88 | else |
||
89 | { |
||
90 | if (mapImage == null) |
||
91 | { |
||
92 | Bitmap bmp = new Bitmap(256, 256); |
||
93 | Graphics g = Graphics.FromImage(bmp); |
||
94 | g.Clear(this.BackColor); |
||
95 | g.FillRectangle(BG_COLOR, 0f, 0f, 256f, 256f); |
||
96 | g.DrawImage(bmp, 0, 0); |
||
97 | |||
98 | _MapLayer = bmp; |
||
99 | } |
||
100 | else _MapLayer = mapImage; |
||
101 | } |
||
102 | } |
||
103 | |||
104 | private void InitializeClient(GridClient client) |
||
105 | { |
||
106 | _Client = client; |
||
107 | _Client.Grid.CoarseLocationUpdate += Grid_CoarseLocationUpdate; |
||
108 | _Client.Network.SimChanged += Network_OnCurrentSimChanged; |
||
109 | } |
||
110 | |||
111 | void Grid_CoarseLocationUpdate(object sender, CoarseLocationUpdateEventArgs e) |
||
112 | { |
||
113 | UpdateMiniMap(e.Simulator); |
||
114 | } |
||
115 | |||
116 | private void UpdateMiniMap(Simulator sim) |
||
117 | { |
||
118 | if (!this.IsHandleCreated) return; |
||
119 | |||
120 | if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { UpdateMiniMap(sim); }); |
||
121 | else |
||
122 | { |
||
123 | if (_MapLayer == null) |
||
124 | SetMapLayer(null); |
||
125 | |||
126 | Bitmap bmp = (Bitmap)_MapLayer.Clone(); |
||
127 | Graphics g = Graphics.FromImage(bmp); |
||
128 | |||
129 | Vector3 myCoarsePos; |
||
130 | |||
131 | if (!sim.AvatarPositions.TryGetValue(Client.Self.AgentID, out myCoarsePos)) return; |
||
132 | |||
133 | int i = 0; |
||
134 | |||
135 | _Client.Network.CurrentSim.AvatarPositions.ForEach( |
||
136 | delegate(KeyValuePair<UUID, Vector3> coarse) |
||
137 | { |
||
138 | int x = (int)coarse.Value.X; |
||
139 | int y = 255 - (int)coarse.Value.Y; |
||
140 | if (coarse.Key == Client.Self.AgentID) |
||
141 | { |
||
142 | g.FillEllipse(Brushes.Yellow, x - 5, y - 5, 10, 10); |
||
143 | g.DrawEllipse(Pens.Khaki, x - 5, y - 5, 10, 10); |
||
144 | } |
||
145 | else |
||
146 | { |
||
147 | Pen penColor; |
||
148 | Brush brushColor; |
||
149 | |||
150 | if (Client.Network.CurrentSim.ObjectsAvatars.Find(delegate(Avatar av) { return av.ID == coarse.Key; }) != null) |
||
151 | { |
||
152 | brushColor = Brushes.PaleGreen; |
||
153 | penColor = Pens.Green; |
||
154 | } |
||
155 | else |
||
156 | { |
||
157 | brushColor = Brushes.LightGray; |
||
158 | penColor = Pens.Gray; |
||
159 | } |
||
160 | |||
161 | if (myCoarsePos.Z - coarse.Value.Z > 1) |
||
162 | { |
||
163 | Point[] points = new Point[3] { new Point(x - 6, y - 6), new Point(x + 6, y - 6), new Point(x, y + 6) }; |
||
164 | g.FillPolygon(brushColor, points); |
||
165 | g.DrawPolygon(penColor, points); |
||
166 | } |
||
167 | |||
168 | else if (myCoarsePos.Z - coarse.Value.Z < -1) |
||
169 | { |
||
170 | Point[] points = new Point[3] { new Point(x - 6, y + 6), new Point(x + 6, y + 6), new Point(x, y - 6) }; |
||
171 | g.FillPolygon(brushColor, points); |
||
172 | g.DrawPolygon(penColor, points); |
||
173 | } |
||
174 | |||
175 | else |
||
176 | { |
||
177 | g.FillEllipse(brushColor, x - 5, y - 5, 10, 10); |
||
178 | g.DrawEllipse(penColor, x - 5, y - 5, 10, 10); |
||
179 | } |
||
180 | } |
||
181 | i++; |
||
182 | } |
||
183 | ); |
||
184 | |||
185 | g.DrawImage(bmp, 0, 0); |
||
186 | this.Image = bmp; |
||
187 | } |
||
188 | } |
||
189 | |||
190 | void MiniMap_MouseHover(object sender, System.EventArgs e) |
||
191 | { |
||
192 | _ToolTip.SetToolTip(this, "test"); |
||
193 | _ToolTip.Show("test", this); |
||
194 | //TODO: tooltip popup with closest avatar's name, if within range |
||
195 | } |
||
196 | |||
197 | void MiniMap_MouseMove(object sender, MouseEventArgs e) |
||
198 | { |
||
199 | _ToolTip.Hide(this); |
||
200 | //warning CS0414: The private field `OpenMetaverse.GUI.MiniMap._MousePosition' is assigned but its value is never used |
||
201 | //_MousePosition = e.Location; |
||
202 | } |
||
203 | |||
204 | void Network_OnCurrentSimChanged(object sender, SimChangedEventArgs e) |
||
205 | { |
||
206 | if (_Client.Network.Connected) return; |
||
207 | |||
208 | GridRegion region; |
||
209 | if (Client.Grid.GetGridRegion(Client.Network.CurrentSim.Name, GridLayerType.Objects, out region)) |
||
210 | { |
||
211 | SetMapLayer(null); |
||
212 | |||
213 | _MapImageID = region.MapImageID; |
||
214 | ManagedImage nullImage; |
||
215 | |||
216 | Client.Assets.RequestImage(_MapImageID, ImageType.Baked, |
||
217 | delegate(TextureRequestState state, AssetTexture asset) |
||
218 | { |
||
219 | if(state == TextureRequestState.Finished) |
||
220 | OpenJPEG.DecodeToImage(asset.AssetData, out nullImage, out _MapLayer); |
||
221 | }); |
||
222 | } |
||
223 | } |
||
224 | |||
225 | } |
||
226 | } |