Mercurial > wow > minimap-range
comparison MinimapRange.lua @ 3:596068b6b1bf 2.0
Converted to Ace 3 and added it to the standard interface/addons configuration UI.
| author | stevekaye@5e7f7089-49ba-45b1-8616-21aa0651eee7 | 
|---|---|
| date | Fri, 07 Nov 2008 14:27:31 +0000 | 
| parents | 6fdb0c5751ab | 
| children | 2748e92d13f0 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 2:f3e03407f27b | 3:596068b6b1bf | 
|---|---|
| 1 -- | 1 -- | 
| 2 -- MinimapRange 1.00 - Steve Kaye | 2 -- MinimapRange 2.00 - Steve Kaye | 
| 3 -- | 3 -- | 
| 4 -- Shows a circle on the minimap to indicate spell range | 4 -- Shows a circle on the minimap to indicate spell range | 
| 5 -- | 5 -- | 
| 6 | 6 | 
| 7 MinimapRange = AceLibrary("AceAddon-2.0"):new("AceHook-2.1", "AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "AceDebug-2.0") | 7 MinimapRange = LibStub("AceAddon-3.0"):NewAddon("MinimapRange", "AceHook-3.0", "AceEvent-3.0", "AceConsole-3.0") | 
| 8 | 8 | 
| 9 MinimapRange.outdoorRanges = | 9 MinimapRange.outdoorRanges = | 
| 10 { | 10 { | 
| 11 [0] = { | 11 [0] = { | 
| 12 [5] = 13, | 12 [5] = 13, | 
| 69 [36] = 66, | 69 [36] = 66, | 
| 70 [45] = 84, | 70 [45] = 84, | 
| 71 [100] = 94 -- suspect | 71 [100] = 94 -- suspect | 
| 72 }, | 72 }, | 
| 73 [3] = { | 73 [3] = { | 
| 74 [5] = 20, | 74 [5] = 20, | 
| 75 [8] = 34, | 75 [8] = 34, | 
| 76 [30] = 75, | 76 [30] = 75, | 
| 77 [36] = 94, | 77 [36] = 94, | 
| 78 [45] = 118 -- suspect | 78 [45] = 118 -- suspect | 
| 79 }, | 79 }, | 
| 89 [8] = 100, | 89 [8] = 100, | 
| 90 [24] = 130 -- off the minimap | 90 [24] = 130 -- off the minimap | 
| 91 } | 91 } | 
| 92 } | 92 } | 
| 93 | 93 | 
| 94 | 94 -- Default settings | 
| 95 -- Set up our chat command arguments | 95 local defaults = { | 
| 96 | 96 profile = { | 
| 97 function MinimapRange:OnInitialize() | |
| 98 | |
| 99 self:Debug("MinimapRange:OnInitialize()") | |
| 100 | |
| 101 local defaults = { | |
| 102 colorRed = 1, | 97 colorRed = 1, | 
| 103 colorGreen = 0, | 98 colorGreen = 0, | 
| 104 colorBlue = 0, | 99 colorBlue = 0, | 
| 105 colorAlpha = 0.25, | 100 colorAlpha = 0.25, | 
| 106 range = 30, | 101 range = 30 | 
| 107 indoors = true | |
| 108 } | 102 } | 
| 109 | 103 } | 
| 110 local args = { | 104 | 
| 111 type = 'group', | 105 -- The available options | 
| 112 args = { | 106 local options = { | 
| 113 color = { | 107 name = "MinimapRange", | 
| 114 type = 'color', | 108 handler = MinimapRange, | 
| 115 name = 'color', | 109 icon = "Interface\\Icons\\Ability_Warrior_Defensivestance.jpg", | 
| 116 desc = "Set the color of the range circle.", | 110 type = "group", | 
| 117 get = function() | 111 args = { | 
| 118 return self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha | 112 version = { | 
| 119 end, | 113 order = 1, | 
| 120 set = function(r, g, b, a) | 114 type = "description", | 
| 121 self:SetColour(r, g, b, a) | 115 name = "X" | 
| 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 }, | 116 }, | 
| 151 } | 117 description = { | 
| 152 | 118 order = 2, | 
| 153 self:RegisterDB("MinimapRangeDB") | 119 type = "description", | 
| 154 self:RegisterDefaults('profile', defaults ) | 120 name = "Descriptive text" | 
| 155 | 121 }, | 
| 156 self:RegisterChatCommand({"/mmr" }, args) | 122 color = { | 
| 123 order = 3, | |
| 124 type = "color", | |
| 125 name = "Circle Color", | |
| 126 desc = "Set the color of the range circle.", | |
| 127 get = function(info) | |
| 128 return MinimapRange.db.profile.colorRed, MinimapRange.db.profile.colorGreen, MinimapRange.db.profile.colorBlue, MinimapRange.db.profile.colorAlpha | |
| 129 end, | |
| 130 set = function(info, r, g, b, a) | |
| 131 MinimapRange:SetColour(r, g, b, a) | |
| 132 end, | |
| 133 hasAlpha = true | |
| 134 }, | |
| 135 range = { | |
| 136 order = 4, | |
| 137 type = "range", | |
| 138 name = "Circle Radius", | |
| 139 desc = "The range that the circle indicates (in yards)", | |
| 140 min = 5, | |
| 141 max = 100, | |
| 142 step = 1, | |
| 143 get = function() | |
| 144 return MinimapRange.db.profile.range | |
| 145 end, | |
| 146 set = function(info, value) | |
| 147 MinimapRange:SetRange(value) | |
| 148 end | |
| 149 }, | |
| 150 }, | |
| 151 } | |
| 152 | |
| 153 function MinimapRange:OnInitialize() | |
| 154 | |
| 155 -- Get the version number for the TOC | |
| 156 options.args.version.name = string.format("Version %s", GetAddOnMetadata("MinimapRange", "Version")) | |
| 157 options.args.description.name = GetAddOnMetadata("MinimapRange", "Notes") | |
| 158 | |
| 159 -- Register the database | |
| 160 self.db = LibStub("AceDB-3.0"):New("MinimapRangeDB", defaults, "Default") | |
| 161 | |
| 162 local acreg = LibStub("AceConfigRegistry-3.0") | |
| 163 | |
| 164 -- Register the options | |
| 165 acreg:RegisterOptionsTable("MinimapRange", options) | |
| 166 acreg:RegisterOptionsTable("MinimapRange Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)) | |
| 167 | |
| 168 LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MinimapRange", "MinimapRange") | |
| 169 LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MinimapRange Profiles", "Profiles", "MinimapRange") | |
| 170 | |
| 171 -- Register the chat command | |
| 172 self:RegisterChatCommand("mmr", "ChatCommand") | |
| 157 end | 173 end | 
| 158 | 174 | 
| 159 -- Enable the addon | 175 -- Enable the addon | 
| 160 function MinimapRange:OnEnable() | 176 function MinimapRange:OnEnable() | 
| 161 | 177 | 
| 167 | 183 | 
| 168 function MinimapRange:OnDisable() | 184 function MinimapRange:OnDisable() | 
| 169 if self.rangeFrame ~= nil then | 185 if self.rangeFrame ~= nil then | 
| 170 self.rangeFrame:Hide() | 186 self.rangeFrame:Hide() | 
| 171 end | 187 end | 
| 188 end | |
| 189 | |
| 190 function MinimapRange:ChatCommand(input) | |
| 191 LibStub("AceConfigCmd-3.0").HandleCommand(MinimapRange, "mmr", "MinimapRange", input) | |
| 172 end | 192 end | 
| 173 | 193 | 
| 174 function MinimapRange:CreateFrame() | 194 function MinimapRange:CreateFrame() | 
| 175 | 195 | 
| 176 if self.rangeFrame == nil then | 196 if self.rangeFrame == nil then | 
| 186 t:SetVertexColor(self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha) | 206 t:SetVertexColor(self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha) | 
| 187 t:SetAllPoints(self.rangeFrame) | 207 t:SetAllPoints(self.rangeFrame) | 
| 188 self.rangeFrame.texture = t | 208 self.rangeFrame.texture = t | 
| 189 | 209 | 
| 190 self.rangeFrame:SetPoint("CENTER",0,0) | 210 self.rangeFrame:SetPoint("CENTER",0,0) | 
| 191 self:UpdateCircle(self.db.profile.range) | 211 self:UpdateCircle(self.db.profile.range, self:GetIndoors()) | 
| 192 end | 212 end | 
| 193 | 213 | 
| 194 self.rangeFrame:Show() | 214 self.rangeFrame:Show() | 
| 195 end | 215 end | 
| 196 | 216 | 
| 210 | 230 | 
| 211 -- Show the new range | 231 -- Show the new range | 
| 212 self:UpdateCircle(value) | 232 self:UpdateCircle(value) | 
| 213 end | 233 end | 
| 214 | 234 | 
| 215 function MinimapRange:SetIndoors(value) | 235 function MinimapRange:UpdateCircle(range, indoors) | 
| 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 | 236 | 
| 246 if self.rangeFrame ~= nil then | 237 if self.rangeFrame ~= nil then | 
| 247 local lowerKey, lowerValue = 0, 0 | 238 local lowerKey, lowerValue = 0, 0 | 
| 248 local upperKey, upperValue = 100, 140 | 239 local upperKey, upperValue = 100, 140 | 
| 249 | 240 | 
| 250 -- Get the corrct range table to work with | 241 -- Get the corrct range table to work with | 
| 251 local rangeTable = self.outdoorRanges | 242 local rangeTable = self.outdoorRanges | 
| 252 if self.db.profile.indoors then | 243 if indoors then | 
| 253 rangeTable = self.indoorRanges | 244 rangeTable = self.indoorRanges | 
| 254 end | 245 end | 
| 255 | 246 | 
| 256 -- Find two numbers to interpolate between | 247 -- Find two numbers to interpolate between | 
| 257 for k, v in pairs(rangeTable[Minimap:GetZoom()]) do | 248 for k, v in pairs(rangeTable[Minimap:GetZoom()]) do | 
| 258 self:Debug(string.format("K: %s LK: %s R: %s", k, lowerKey, range)) | 249 | 
| 259 if k > lowerKey and k <= range then | 250 if k > lowerKey and k <= range then | 
| 260 lowerKey = k | 251 lowerKey = k | 
| 261 lowerValue = v | 252 lowerValue = v | 
| 262 end | 253 end | 
| 263 | 254 | 
| 274 size = lowerValue | 265 size = lowerValue | 
| 275 else | 266 else | 
| 276 size = lowerValue + ((upperValue - lowerValue) / (upperKey - lowerKey)) * (range - lowerKey) | 267 size = lowerValue + ((upperValue - lowerValue) / (upperKey - lowerKey)) * (range - lowerKey) | 
| 277 end | 268 end | 
| 278 | 269 | 
| 279 self:Debug("Size: "..size) | |
| 280 -- Change the circle size | 270 -- Change the circle size | 
| 281 if size ~= nil then | 271 if size ~= nil then | 
| 282 self.rangeFrame:SetWidth(size) | 272 self.rangeFrame:SetWidth(size) | 
| 283 self.rangeFrame:SetHeight(size) | 273 self.rangeFrame:SetHeight(size) | 
| 284 end | 274 end | 
| 285 end | 275 end | 
| 286 end | 276 end | 
| 287 | 277 | 
| 288 function MinimapRange:SetZoom(minimap, level) | 278 function MinimapRange:SetZoom(minimap, level) | 
| 279 | |
| 280 -- Prevent recursion into GetIndoors() | |
| 281 if self.inGetIndoors == nil then | |
| 282 -- Resize the circle | |
| 283 self:UpdateCircle(self.db.profile.range, self:GetIndoors()) | |
| 284 end | |
| 285 end | |
| 286 | |
| 287 function MinimapRange:UpdateZoom() | |
| 288 | |
| 289 -- Resize the circle | 289 -- Resize the circle | 
| 290 self:UpdateCircle(self.db.profile.range) | 290 self:UpdateCircle(self.db.profile.range, self:GetIndoors()) | 
| 291 end | 291 | 
| 292 | 292 end | 
| 293 function MinimapRange:UpdateZoom() | 293 | 
| 294 | 294 -- | 
| 295 -- Test to see if we are indoors | |
| 296 -- | |
| 297 function MinimapRange:GetIndoors() | |
| 298 | |
| 299 local indoors = true | |
| 300 | |
| 301 -- Prevent recursion | |
| 302 self.inGetIndoors = true | |
| 303 | |
| 295 -- Try to detect whether we are indoors or outdoors | 304 -- Try to detect whether we are indoors or outdoors | 
| 296 local zoom = Minimap:GetZoom() | 305 local zoom = Minimap:GetZoom() | 
| 297 local indoorsZoom = tonumber(GetCVar("minimapInsideZoom")) | 306 local indoorsZoom = tonumber(GetCVar("minimapInsideZoom")) | 
| 298 local outdoorsZoom = tonumber(GetCVar("minimapZoom")) | 307 local outdoorsZoom = tonumber(GetCVar("minimapZoom")) | 
| 308 local newZoom | |
| 299 | 309 | 
| 300 -- Have we detected whether we are inside or outside? | 310 -- Have we detected whether we are inside or outside? | 
| 301 if indoorsZoom ~= outdoorsZoom then | 311 if indoorsZoom ~= outdoorsZoom then | 
| 302 self:Debug("Using detected location") | |
| 303 | 312 | 
| 304 -- Yes, use the detected value | 313 -- Yes, use the detected value | 
| 305 self:SetIndoors(indoorsZoom == zoom) | 314 indoors = indoorsZoom == zoom | 
| 306 | |
| 307 else | 315 else | 
| 308 self:Debug("Using best guess location") | 316 | 
| 309 | 317 -- What shall we set the new zoom to? | 
| 310 -- If this is not the first time that we have had this message | 318 if zoom == 1 then | 
| 311 -- then we must assume that we have moved from indoors to outdoors | 319 newZoom = 2 | 
| 312 -- or vice versa | 320 else | 
| 313 if self.firstUpdateZoomComplete == true then | 321 newZoom = 1 | 
| 314 self.db.profile.indoors = not self.db.profile.indoors | 322 end | 
| 315 end | 323 | 
| 316 | 324 -- Set the new zoom | 
| 317 self:SetIndoors(self.db.profile.indoors) | 325 Minimap:SetZoom(newZoom) | 
| 318 end | 326 | 
| 319 | 327 -- Did the indoors zoom change? | 
| 320 -- Resize the circle | 328 indoorsZoom = tonumber(GetCVar("minimapInsideZoom")) | 
| 321 self:UpdateCircle(self.db.profile.range) | 329 indoors = indoorsZoom == newZoom | 
| 322 | 330 | 
| 323 -- Note that the first update after a reload has been done | 331 -- Set the zoom back | 
| 324 self.firstUpdateZoomComplete = true | 332 Minimap:SetZoom(zoom) | 
| 325 end | 333 end | 
| 326 | 334 | 
| 335 self.inGetIndoors = nil | |
| 336 return indoors | |
| 337 end | |
| 338 | |
| 339 -- | |
| 340 -- This function was just used for helping determine the original circle sizes | |
| 341 -- | |
| 342 function MinimapRange:SetCircle(range, size) | |
| 343 if self.rangeFrame ~= nil then | |
| 344 | |
| 345 local rangeTable = self.outdoorRanges | |
| 346 if self.db.profile.indoors then | |
| 347 rangeTable = self.indoorRanges | |
| 348 end | |
| 349 | |
| 350 rangeTable[Minimap:GetZoom()][range] = size | |
| 351 | |
| 352 self:UpdateCircle(range) | |
| 353 end | |
| 354 end | |
| 355 | 
