Mercurial > wow > minimap-range
comparison MinimapRange.lua @ 0:6fdb0c5751ab
Importing old repo data under /trunk
author | root@5e7f7089-49ba-45b1-8616-21aa0651eee7 |
---|---|
date | Mon, 29 Sep 2008 20:58:24 +0000 |
parents | |
children | 596068b6b1bf |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6fdb0c5751ab |
---|---|
1 -- | |
2 -- MinimapRange 1.00 - Steve Kaye | |
3 -- | |
4 -- Shows a circle on the minimap to indicate spell range | |
5 -- | |
6 | |
7 MinimapRange = AceLibrary("AceAddon-2.0"):new("AceHook-2.1", "AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "AceDebug-2.0") | |
8 | |
9 MinimapRange.outdoorRanges = | |
10 { | |
11 [0] = { | |
12 [5] = 13, | |
13 [8] = 15, | |
14 [45] = 35, | |
15 [100] = 70 | |
16 }, | |
17 [1] = { | |
18 [5] = 13.5, | |
19 [8] = 15.5, | |
20 [45] = 40, | |
21 [100] = 80 | |
22 }, | |
23 [2] = { | |
24 [5] = 14, | |
25 [8] = 16, | |
26 [45] = 45, | |
27 [100] = 94 | |
28 }, | |
29 [3] = { | |
30 [5] = 15, | |
31 [8] = 18, | |
32 [45] = 57, | |
33 [100] = 115 | |
34 }, | |
35 [4] = { | |
36 [5] = 16, | |
37 [8] = 22, | |
38 [45] = 73 | |
39 }, | |
40 [5] = { | |
41 [5] = 20, | |
42 [8] = 30, | |
43 [45] = 105 | |
44 } | |
45 } | |
46 | |
47 MinimapRange.indoorRanges = | |
48 { | |
49 [0] = { | |
50 [5] = 13, | |
51 [8] = 16, | |
52 [30] = 37, | |
53 [36] = 43, | |
54 [45] = 52, | |
55 [100] = 70 -- suspect | |
56 }, | |
57 [1] = { | |
58 [5] = 15, | |
59 [8] = 19, | |
60 [30] = 43, | |
61 [36] = 53, | |
62 [45] = 63, | |
63 [100] = 80 -- suspect | |
64 }, | |
65 [2] = { | |
66 [5] = 15, | |
67 [8] = 23, | |
68 [30] = 54, | |
69 [36] = 66, | |
70 [45] = 84, | |
71 [100] = 94 -- suspect | |
72 }, | |
73 [3] = { | |
74 [5] = 20, | |
75 [8] = 34, | |
76 [30] = 75, | |
77 [36] = 94, | |
78 [45] = 118 -- suspect | |
79 }, | |
80 [4] = { | |
81 [5] = 26, | |
82 [8] = 90, | |
83 [24] = 98, | |
84 [30] = 105, | |
85 [36] = 118 | |
86 }, | |
87 [5] = { | |
88 [5] = 35, | |
89 [8] = 100, | |
90 [24] = 130 -- off the minimap | |
91 } | |
92 } | |
93 | |
94 | |
95 -- Set up our chat command arguments | |
96 | |
97 function MinimapRange:OnInitialize() | |
98 | |
99 self:Debug("MinimapRange:OnInitialize()") | |
100 | |
101 local defaults = { | |
102 colorRed = 1, | |
103 colorGreen = 0, | |
104 colorBlue = 0, | |
105 colorAlpha = 0.25, | |
106 range = 30, | |
107 indoors = true | |
108 } | |
109 | |
110 local args = { | |
111 type = 'group', | |
112 args = { | |
113 color = { | |
114 type = 'color', | |
115 name = 'color', | |
116 desc = "Set the color of the range circle.", | |
117 get = function() | |
118 return self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha | |
119 end, | |
120 set = function(r, g, b, a) | |
121 self:SetColour(r, g, b, a) | |
122 end, | |
123 hasAlpha = true | |
124 }, | |
125 range = { | |
126 type = 'range', | |
127 name = 'range', | |
128 desc = "The range of the circle (in yards)", | |
129 min = 5, | |
130 max = 100, | |
131 step = 1, | |
132 get = function() | |
133 return self.db.profile.range | |
134 end, | |
135 set = function(value) | |
136 self:SetRange(value) | |
137 end | |
138 }, | |
139 indoors = { | |
140 type = 'toggle', | |
141 name = 'indoors', | |
142 desc = 'Whether you are indoors or outdoors. Once you tell it which you are in it will try to keep track but you can fix it with this.', | |
143 get = function() | |
144 return self.db.profile.indoors | |
145 end, | |
146 set = function(value) | |
147 self:SetIndoors(value) | |
148 end | |
149 }, | |
150 }, | |
151 } | |
152 | |
153 self:RegisterDB("MinimapRangeDB") | |
154 self:RegisterDefaults('profile', defaults ) | |
155 | |
156 self:RegisterChatCommand({"/mmr" }, args) | |
157 end | |
158 | |
159 -- Enable the addon | |
160 function MinimapRange:OnEnable() | |
161 | |
162 self:CreateFrame() | |
163 | |
164 self:SecureHook(Minimap, "SetZoom") | |
165 self:RegisterEvent("MINIMAP_UPDATE_ZOOM","UpdateZoom") | |
166 end | |
167 | |
168 function MinimapRange:OnDisable() | |
169 if self.rangeFrame ~= nil then | |
170 self.rangeFrame:Hide() | |
171 end | |
172 end | |
173 | |
174 function MinimapRange:CreateFrame() | |
175 | |
176 if self.rangeFrame == nil then | |
177 -- Create our frame | |
178 self.rangeFrame = CreateFrame('Frame', 'MinimapRangeFrame', Minimap) | |
179 | |
180 -- Set the properties | |
181 self.rangeFrame:SetFrameStrata("LOW") | |
182 | |
183 -- Add the texture | |
184 local t = self.rangeFrame:CreateTexture(nil, "BACKGROUND") | |
185 t:SetTexture("Interface\\AddOns\\MinimapRange\\MM") | |
186 t:SetVertexColor(self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha) | |
187 t:SetAllPoints(self.rangeFrame) | |
188 self.rangeFrame.texture = t | |
189 | |
190 self.rangeFrame:SetPoint("CENTER",0,0) | |
191 self:UpdateCircle(self.db.profile.range) | |
192 end | |
193 | |
194 self.rangeFrame:Show() | |
195 end | |
196 | |
197 function MinimapRange:SetColour(r, g, b, a) | |
198 -- Save the setting | |
199 self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha = r, g, b, a | |
200 | |
201 -- Set the colour of the circle | |
202 if self.rangeFrame ~= nil then | |
203 self.rangeFrame.texture:SetVertexColor(r, g, b, a) | |
204 end | |
205 end | |
206 | |
207 function MinimapRange:SetRange(value) | |
208 -- Save the setting | |
209 self.db.profile.range = value | |
210 | |
211 -- Show the new range | |
212 self:UpdateCircle(value) | |
213 end | |
214 | |
215 function MinimapRange:SetIndoors(value) | |
216 -- Save the setting | |
217 self.db.profile.indoors = value | |
218 | |
219 if value then | |
220 self:Debug("Indoors: TRUE") | |
221 else | |
222 self:Debug("Indoors: FALSE") | |
223 end | |
224 | |
225 -- Show the new range | |
226 self:UpdateCircle(self.db.profile.range) | |
227 end | |
228 | |
229 function MinimapRange:SetCircle(range, size) | |
230 if self.rangeFrame ~= nil then | |
231 | |
232 local rangeTable = self.outdoorRanges | |
233 if self.db.profile.indoors then | |
234 rangeTable = self.indoorRanges | |
235 end | |
236 | |
237 rangeTable[Minimap:GetZoom()][range] = size | |
238 | |
239 self:UpdateCircle(range) | |
240 end | |
241 end | |
242 | |
243 function MinimapRange:UpdateCircle(range) | |
244 self:Debug(string.format('Z: %s S: %s', Minimap:GetZoom(), range)) | |
245 | |
246 if self.rangeFrame ~= nil then | |
247 local lowerKey, lowerValue = 0, 0 | |
248 local upperKey, upperValue = 100, 140 | |
249 | |
250 -- Get the corrct range table to work with | |
251 local rangeTable = self.outdoorRanges | |
252 if self.db.profile.indoors then | |
253 rangeTable = self.indoorRanges | |
254 end | |
255 | |
256 -- Find two numbers to interpolate between | |
257 for k, v in pairs(rangeTable[Minimap:GetZoom()]) do | |
258 self:Debug(string.format("K: %s LK: %s R: %s", k, lowerKey, range)) | |
259 if k > lowerKey and k <= range then | |
260 lowerKey = k | |
261 lowerValue = v | |
262 end | |
263 | |
264 if k < upperKey and k >= range then | |
265 upperKey = k | |
266 upperValue = v | |
267 end | |
268 end | |
269 | |
270 local size | |
271 | |
272 -- Do the interpolation if we haven't found an exact match | |
273 if lowerKey == upperKey then | |
274 size = lowerValue | |
275 else | |
276 size = lowerValue + ((upperValue - lowerValue) / (upperKey - lowerKey)) * (range - lowerKey) | |
277 end | |
278 | |
279 self:Debug("Size: "..size) | |
280 -- Change the circle size | |
281 if size ~= nil then | |
282 self.rangeFrame:SetWidth(size) | |
283 self.rangeFrame:SetHeight(size) | |
284 end | |
285 end | |
286 end | |
287 | |
288 function MinimapRange:SetZoom(minimap, level) | |
289 -- Resize the circle | |
290 self:UpdateCircle(self.db.profile.range) | |
291 end | |
292 | |
293 function MinimapRange:UpdateZoom() | |
294 | |
295 -- Try to detect whether we are indoors or outdoors | |
296 local zoom = Minimap:GetZoom() | |
297 local indoorsZoom = tonumber(GetCVar("minimapInsideZoom")) | |
298 local outdoorsZoom = tonumber(GetCVar("minimapZoom")) | |
299 | |
300 -- Have we detected whether we are inside or outside? | |
301 if indoorsZoom ~= outdoorsZoom then | |
302 self:Debug("Using detected location") | |
303 | |
304 -- Yes, use the detected value | |
305 self:SetIndoors(indoorsZoom == zoom) | |
306 | |
307 else | |
308 self:Debug("Using best guess location") | |
309 | |
310 -- If this is not the first time that we have had this message | |
311 -- then we must assume that we have moved from indoors to outdoors | |
312 -- or vice versa | |
313 if self.firstUpdateZoomComplete == true then | |
314 self.db.profile.indoors = not self.db.profile.indoors | |
315 end | |
316 | |
317 self:SetIndoors(self.db.profile.indoors) | |
318 end | |
319 | |
320 -- Resize the circle | |
321 self:UpdateCircle(self.db.profile.range) | |
322 | |
323 -- Note that the first update after a reload has been done | |
324 self.firstUpdateZoomComplete = true | |
325 end | |
326 |