changeset 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 f3e03407f27b
children 24b5040a8867
files .pkgmeta MinimapRange.lua MinimapRange.toc embeds.xml
diffstat 4 files changed, 168 insertions(+), 131 deletions(-) [+]
line wrap: on
line diff
--- a/.pkgmeta	Tue Sep 30 16:04:32 2008 +0000
+++ b/.pkgmeta	Fri Nov 07 14:27:31 2008 +0000
@@ -1,10 +1,12 @@
-package-as: MinimapRange
-
-externals:
-    libs/AceAddon-2.0: svn://svn.wowace.com/wow/ace2/mainline/trunk/AceAddon-2.0
-    libs/AceConsole-2.0: svn://svn.wowace.com/wow/ace2/mainline/trunk/AceConsole-2.0
-    libs/AceDB-2.0: svn://svn.wowace.com/wow/ace2/mainline/trunk/AceDB-2.0
-    libs/AceDebug-2.0: svn://svn.wowace.com/wow/ace2/mainline/trunk/AceDebug-2.0
-    libs/AceEvent-2.0: svn://svn.wowace.com/wow/ace2/mainline/trunk/AceEvent-2.0
-    libs/AceHook-2.1: svn://svn.wowace.com/wow/ace2/mainline/trunk/AceHook-2.1
-    libs/AceLibrary: svn://svn.wowace.com/wow/ace2/mainline/trunk/AceLibrary
+package-as: MinimapRange
+
+externals:
+    libs/LibStub: svn://svn.wowace.com/wow/libstub/mainline/tags/1.0
+    libs/AceAddon-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceAddon-3.0
+    libs/AceConsole-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConsole-3.0
+    libs/AceEvent-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceEvent-3.0
+    libs/AceDB-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDB-3.0
+    libs/AceDBOptions-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDBOptions-3.0
+    libs/AceHook-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceHook-3.0
+    
+
--- a/MinimapRange.lua	Tue Sep 30 16:04:32 2008 +0000
+++ b/MinimapRange.lua	Fri Nov 07 14:27:31 2008 +0000
@@ -1,10 +1,10 @@
 --
---		MinimapRange 1.00 - Steve Kaye
+--		MinimapRange 2.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 = LibStub("AceAddon-3.0"):NewAddon("MinimapRange", "AceHook-3.0", "AceEvent-3.0", "AceConsole-3.0")
 
 MinimapRange.outdoorRanges = 
 {
@@ -71,7 +71,7 @@
 		[100] = 94 -- suspect
 	},
 	[3] = {
-		[5] = 20,
+		[5] = 20,	
 		[8] = 34,
 		[30] = 75,
 		[36] = 94,
@@ -91,69 +91,85 @@
 	}
 }
 
-
--- Set up our chat command arguments
-
-function MinimapRange:OnInitialize()
-
-	self:Debug("MinimapRange:OnInitialize()")
-	
-	local defaults = {
+-- Default settings
+local defaults = {
+	profile = {
 		colorRed = 1,
 		colorGreen = 0,
 		colorBlue = 0,
 		colorAlpha = 0.25,
-		range = 30,
-		indoors = true
+		range = 30
 	}
+}
+
+-- The available options
+local options = {
+	name = "MinimapRange",
+	handler = MinimapRange,
+	icon =  "Interface\\Icons\\Ability_Warrior_Defensivestance.jpg",
+	type = "group",	
+	args = {
+		version = {
+			order = 1,
+			type = "description",
+			name = "X"
+		},
+		description = {
+			order = 2,
+			type = "description",
+			name = "Descriptive text"
+		},
+		color = {
+			order = 3,
+			type = "color",
+			name = "Circle Color",
+			desc = "Set the color of the range circle.",
+			get = function(info)
+				return MinimapRange.db.profile.colorRed, MinimapRange.db.profile.colorGreen, MinimapRange.db.profile.colorBlue, MinimapRange.db.profile.colorAlpha
+			end,
+			set = function(info, r, g, b, a)
+				MinimapRange:SetColour(r, g, b, a)
+			end,
+			hasAlpha = true
+		},
+		range = {
+			order = 4,
+			type = "range",
+			name = "Circle Radius",
+			desc = "The range that the circle indicates (in yards)",
+			min = 5,
+			max = 100,
+			step = 1,
+			get = function()
+				return MinimapRange.db.profile.range
+			end,
+			set = function(info, value)
+				MinimapRange:SetRange(value)
+			end
+		},
+	},
+}
+
+function MinimapRange:OnInitialize()
+
+	-- Get the version number for the TOC
+	options.args.version.name = string.format("Version %s", GetAddOnMetadata("MinimapRange", "Version"))
+	options.args.description.name = GetAddOnMetadata("MinimapRange", "Notes")
+
+	-- Register the database	
+	self.db = LibStub("AceDB-3.0"):New("MinimapRangeDB", defaults, "Default")	
 	
-	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
-			},
-		},
-	}
+	local acreg = LibStub("AceConfigRegistry-3.0")
 	
-	self:RegisterDB("MinimapRangeDB")
-	self:RegisterDefaults('profile', defaults )
-	
-	self:RegisterChatCommand({"/mmr" }, args)
+	-- Register the options
+    acreg:RegisterOptionsTable("MinimapRange", options)
+    acreg:RegisterOptionsTable("MinimapRange Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db))
+    
+    LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MinimapRange", "MinimapRange")
+    LibStub("AceConfigDialog-3.0"):AddToBlizOptions("MinimapRange Profiles", "Profiles", "MinimapRange")
+    
+    -- Register the chat command
+	self:RegisterChatCommand("mmr", "ChatCommand")
 end
 
 -- Enable the addon
@@ -171,6 +187,10 @@
 	end
 end
 
+function MinimapRange:ChatCommand(input)
+    LibStub("AceConfigCmd-3.0").HandleCommand(MinimapRange, "mmr", "MinimapRange", input)
+end
+
 function MinimapRange:CreateFrame()
 
 	if self.rangeFrame == nil then
@@ -188,7 +208,7 @@
 		self.rangeFrame.texture = t
 	
 		self.rangeFrame:SetPoint("CENTER",0,0)
-		self:UpdateCircle(self.db.profile.range)
+		self:UpdateCircle(self.db.profile.range, self:GetIndoors())
 	end
 	
 	self.rangeFrame:Show() 
@@ -212,36 +232,7 @@
 	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))
+function MinimapRange:UpdateCircle(range, indoors)
 	
 	if self.rangeFrame ~= nil then
 		local lowerKey, lowerValue = 0, 0
@@ -249,13 +240,13 @@
 		
 		-- Get the corrct range table to work with
 		local rangeTable = self.outdoorRanges
-		if self.db.profile.indoors then
+		if 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
@@ -276,7 +267,6 @@
 			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)
@@ -286,41 +276,80 @@
 end
 
 function MinimapRange:SetZoom(minimap, level)
-	-- Resize the circle
-	self:UpdateCircle(self.db.profile.range)
+
+	-- Prevent recursion into GetIndoors()
+	if self.inGetIndoors == nil then
+		-- Resize the circle
+		self:UpdateCircle(self.db.profile.range, self:GetIndoors())
+	end
 end
 
 function MinimapRange:UpdateZoom()
 	
+	-- Resize the circle
+	self:UpdateCircle(self.db.profile.range, self:GetIndoors())
+	
+end
+
+--
+-- Test to see if we are indoors
+--
+function MinimapRange:GetIndoors()
+
+	local indoors = true
+	
+	-- Prevent recursion
+	self.inGetIndoors = true
+		
 	-- Try to detect whether we are indoors or outdoors
 	local zoom = Minimap:GetZoom()
 	local indoorsZoom = tonumber(GetCVar("minimapInsideZoom")) 
 	local outdoorsZoom = tonumber(GetCVar("minimapZoom"))
+	local newZoom
 	
 	-- 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)
+		indoors = indoorsZoom == zoom
+	else
 		
-	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 
+		-- What shall we set the new zoom to?		
+		if zoom == 1 then
+			newZoom = 2
+		else
+			newZoom = 1
 		end
 		
-		self:SetIndoors(self.db.profile.indoors)
+		-- Set the new zoom
+		Minimap:SetZoom(newZoom)
+		
+		-- Did the indoors zoom change?
+		indoorsZoom = tonumber(GetCVar("minimapInsideZoom")) 
+		indoors = indoorsZoom == newZoom
+		
+		-- Set the zoom back
+		Minimap:SetZoom(zoom)
 	end
 	
-	-- Resize the circle
-	self:UpdateCircle(self.db.profile.range)
-	
-	-- Note that the first update after a reload has been done
-	self.firstUpdateZoomComplete = true
+	self.inGetIndoors = nil
+	return indoors
 end
 
+--
+-- This function was just used for helping determine the original circle sizes
+--
+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
+
--- a/MinimapRange.toc	Tue Sep 30 16:04:32 2008 +0000
+++ b/MinimapRange.toc	Fri Nov 07 14:27:31 2008 +0000
@@ -1,20 +1,16 @@
-## Interface: 20000
+## Interface: 30000
 ## Author: Steve Kaye
 ## Title: MinimapRange
-## Version: 1.0
+## Version: 2.0
 ## Notes: Shows a circle on the minimap to indicate spell range
-## OptionalDeps: Ace2
 ## Dependencies:
+## OptionalDeps: Ace3
 ## 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
+## X-Embeds: Ace3
+
+embeds.xml
+
 MinimapRange.lua
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/embeds.xml	Fri Nov 07 14:27:31 2008 +0000
@@ -0,0 +1,9 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/..\FrameXML\UI.xsd">
+  <Script file="libs\LibStub\LibStub.lua"/>
+  <Include file="libs\AceAddon-3.0\AceAddon-3.0.xml"/>
+  <Include file="libs\AceConsole-3.0\AceConsole-3.0.xml"/>
+  <Include file="libs\AceEvent-3.0\AceEvent-3.0.xml"/>
+  <Include file="libs\AceDB-3.0\AceDB-3.0.xml"/>
+  <Include file="libs\AceDBOptions-3.0\AceDBOptions-3.0.xml"/>
+  <Include file="libs\AceHook-3.0\AceHook-3.0.xml"/>
+</Ui>