Mercurial > wow > minimap-range
changeset 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 | a964d88047e2 |
files | MinimapRange.lua MinimapRange.toc mm.tga |
diffstat | 3 files changed, 346 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MinimapRange.lua Mon Sep 29 20:58:24 2008 +0000 @@ -0,0 +1,326 @@ +-- +-- MinimapRange 1.00 - Steve Kaye +-- +-- Shows a circle on the minimap to indicate spell range +-- + +MinimapRange = AceLibrary("AceAddon-2.0"):new("AceHook-2.1", "AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "AceDebug-2.0") + +MinimapRange.outdoorRanges = +{ + [0] = { + [5] = 13, + [8] = 15, + [45] = 35, + [100] = 70 + }, + [1] = { + [5] = 13.5, + [8] = 15.5, + [45] = 40, + [100] = 80 + }, + [2] = { + [5] = 14, + [8] = 16, + [45] = 45, + [100] = 94 + }, + [3] = { + [5] = 15, + [8] = 18, + [45] = 57, + [100] = 115 + }, + [4] = { + [5] = 16, + [8] = 22, + [45] = 73 + }, + [5] = { + [5] = 20, + [8] = 30, + [45] = 105 + } +} + +MinimapRange.indoorRanges = +{ + [0] = { + [5] = 13, + [8] = 16, + [30] = 37, + [36] = 43, + [45] = 52, + [100] = 70 -- suspect + }, + [1] = { + [5] = 15, + [8] = 19, + [30] = 43, + [36] = 53, + [45] = 63, + [100] = 80 -- suspect + }, + [2] = { + [5] = 15, + [8] = 23, + [30] = 54, + [36] = 66, + [45] = 84, + [100] = 94 -- suspect + }, + [3] = { + [5] = 20, + [8] = 34, + [30] = 75, + [36] = 94, + [45] = 118 -- suspect + }, + [4] = { + [5] = 26, + [8] = 90, + [24] = 98, + [30] = 105, + [36] = 118 + }, + [5] = { + [5] = 35, + [8] = 100, + [24] = 130 -- off the minimap + } +} + + +-- Set up our chat command arguments + +function MinimapRange:OnInitialize() + + self:Debug("MinimapRange:OnInitialize()") + + local defaults = { + colorRed = 1, + colorGreen = 0, + colorBlue = 0, + colorAlpha = 0.25, + range = 30, + indoors = true + } + + local args = { + type = 'group', + args = { + color = { + type = 'color', + name = 'color', + desc = "Set the color of the range circle.", + get = function() + return self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha + end, + set = function(r, g, b, a) + self:SetColour(r, g, b, a) + end, + hasAlpha = true + }, + range = { + type = 'range', + name = 'range', + desc = "The range of the circle (in yards)", + min = 5, + max = 100, + step = 1, + get = function() + return self.db.profile.range + end, + set = function(value) + self:SetRange(value) + end + }, + indoors = { + type = 'toggle', + name = 'indoors', + 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.', + get = function() + return self.db.profile.indoors + end, + set = function(value) + self:SetIndoors(value) + end + }, + }, + } + + self:RegisterDB("MinimapRangeDB") + self:RegisterDefaults('profile', defaults ) + + self:RegisterChatCommand({"/mmr" }, args) +end + +-- Enable the addon +function MinimapRange:OnEnable() + + self:CreateFrame() + + self:SecureHook(Minimap, "SetZoom") + self:RegisterEvent("MINIMAP_UPDATE_ZOOM","UpdateZoom") +end + +function MinimapRange:OnDisable() + if self.rangeFrame ~= nil then + self.rangeFrame:Hide() + end +end + +function MinimapRange:CreateFrame() + + if self.rangeFrame == nil then + -- Create our frame + self.rangeFrame = CreateFrame('Frame', 'MinimapRangeFrame', Minimap) + + -- Set the properties + self.rangeFrame:SetFrameStrata("LOW") + + -- Add the texture + local t = self.rangeFrame:CreateTexture(nil, "BACKGROUND") + t:SetTexture("Interface\\AddOns\\MinimapRange\\MM") + t:SetVertexColor(self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha) + t:SetAllPoints(self.rangeFrame) + self.rangeFrame.texture = t + + self.rangeFrame:SetPoint("CENTER",0,0) + self:UpdateCircle(self.db.profile.range) + end + + self.rangeFrame:Show() +end + +function MinimapRange:SetColour(r, g, b, a) + -- Save the setting + self.db.profile.colorRed, self.db.profile.colorGreen, self.db.profile.colorBlue, self.db.profile.colorAlpha = r, g, b, a + + -- Set the colour of the circle + if self.rangeFrame ~= nil then + self.rangeFrame.texture:SetVertexColor(r, g, b, a) + end +end + +function MinimapRange:SetRange(value) + -- Save the setting + self.db.profile.range = value + + -- Show the new range + self:UpdateCircle(value) +end + +function MinimapRange:SetIndoors(value) + -- Save the setting + self.db.profile.indoors = value + + if value then + self:Debug("Indoors: TRUE") + else + self:Debug("Indoors: FALSE") + end + + -- Show the new range + self:UpdateCircle(self.db.profile.range) +end + +function MinimapRange:SetCircle(range, size) + if self.rangeFrame ~= nil then + + local rangeTable = self.outdoorRanges + if self.db.profile.indoors then + rangeTable = self.indoorRanges + end + + rangeTable[Minimap:GetZoom()][range] = size + + self:UpdateCircle(range) + end +end + +function MinimapRange:UpdateCircle(range) + self:Debug(string.format('Z: %s S: %s', Minimap:GetZoom(), range)) + + if self.rangeFrame ~= nil then + local lowerKey, lowerValue = 0, 0 + local upperKey, upperValue = 100, 140 + + -- Get the corrct range table to work with + local rangeTable = self.outdoorRanges + if self.db.profile.indoors then + rangeTable = self.indoorRanges + end + + -- Find two numbers to interpolate between + for k, v in pairs(rangeTable[Minimap:GetZoom()]) do + self:Debug(string.format("K: %s LK: %s R: %s", k, lowerKey, range)) + if k > lowerKey and k <= range then + lowerKey = k + lowerValue = v + end + + if k < upperKey and k >= range then + upperKey = k + upperValue = v + end + end + + local size + + -- Do the interpolation if we haven't found an exact match + if lowerKey == upperKey then + size = lowerValue + else + size = lowerValue + ((upperValue - lowerValue) / (upperKey - lowerKey)) * (range - lowerKey) + end + + self:Debug("Size: "..size) + -- Change the circle size + if size ~= nil then + self.rangeFrame:SetWidth(size) + self.rangeFrame:SetHeight(size) + end + end +end + +function MinimapRange:SetZoom(minimap, level) + -- Resize the circle + self:UpdateCircle(self.db.profile.range) +end + +function MinimapRange:UpdateZoom() + + -- Try to detect whether we are indoors or outdoors + local zoom = Minimap:GetZoom() + local indoorsZoom = tonumber(GetCVar("minimapInsideZoom")) + local outdoorsZoom = tonumber(GetCVar("minimapZoom")) + + -- Have we detected whether we are inside or outside? + if indoorsZoom ~= outdoorsZoom then + self:Debug("Using detected location") + + -- Yes, use the detected value + self:SetIndoors(indoorsZoom == zoom) + + else + self:Debug("Using best guess location") + + -- If this is not the first time that we have had this message + -- then we must assume that we have moved from indoors to outdoors + -- or vice versa + if self.firstUpdateZoomComplete == true then + self.db.profile.indoors = not self.db.profile.indoors + end + + self:SetIndoors(self.db.profile.indoors) + end + + -- Resize the circle + self:UpdateCircle(self.db.profile.range) + + -- Note that the first update after a reload has been done + self.firstUpdateZoomComplete = true +end +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MinimapRange.toc Mon Sep 29 20:58:24 2008 +0000 @@ -0,0 +1,20 @@ +## Interface: 20000 +## Author: Steve Kaye +## Title: MinimapRange +## Version: 1.0 +## Notes: Shows a circle on the minimap to indicate spell range +## OptionalDeps: Ace2 +## Dependencies: +## SavedVariables: MinimapRangeDB +## X-Category: Map +## X-Credits: Carpone +## X-Embeds: Ace2 +## X-AceForum: 3519 +libs\AceLibrary\AceLibrary.lua +libs\AceEvent-2.0\AceEvent-2.0.lua +libs\AceAddon-2.0\AceAddon-2.0.lua +libs\AceConsole-2.0\AceConsole-2.0.lua +libs\AceDB-2.0\AceDB-2.0.lua +libs\AceHook-2.1\AceHook-2.1.lua +libs\AceDebug-2.0\AceDebug-2.0.lua +MinimapRange.lua