Quantcast

Added Ace3 and SharedMedia as optionaldeps

p3lim-52096 [04-05-09 - 23:06]
Added Ace3 and SharedMedia as optionaldeps
Removed the clock option from blizzard
Fixed the calendar invite "popup"
Fixed the savedvariable handling

git-svn-id: svn://svn.wowinterface.com/pMinimap-54/trunk@88 ae24c21f-2f0c-4c94-9256-0092abe71e0d
Filename
pMinimap/pMinimap.lua
pMinimap/pMinimap.toc
diff --git a/pMinimap/pMinimap.lua b/pMinimap/pMinimap.lua
index 296117b..625aed2 100644
--- a/pMinimap/pMinimap.lua
+++ b/pMinimap/pMinimap.lua
@@ -2,9 +2,6 @@ pMinimap = CreateFrame('Frame', 'pMinimap', UIParent)
 pMinimap:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end)
 pMinimap:RegisterEvent('ADDON_LOADED')

-local dummy = CreateFrame('Frame', nil, InterfaceOptionsFrame)
-dummy:SetScript('OnShow', function(self) if(not IsAddOnLoaded('pMinimap_Config')) then LoadAddOn('pMinimap_Config') end self:SetScript('OnShow', nil) end)
-
 local LSM = LibStub('LibSharedMedia-3.0')

 local onUpdate, onClickClock, onClickCoord, onMouseWheel
@@ -79,34 +76,10 @@ do
 end


-local function DisableBlizzard()
-	for k,v in next, {InterfaceOptionsDisplayPanelShowClock} do
-		local warning = v:CreateFontString(nil, 'OVERLAY', 'GameFontNormal')
-		warning:SetPoint('TOPLEFT', v, 0, 10)
-		warning:SetText('|cff00ff33OVERRID BY PMINIMAP!|r')
-
-		v:SetButtonState('DISABLED', true)
-	end
-
-	InterfaceOptionsDisplayPanelShowClock.setFunc('1')
-	InterfaceOptionsDisplayPanelShowClock.setFunc = function() end
-end
-
-local function LoadDefaults()
-	pMinimapDB = pMinimapDB or {}
-	for k,v in pairs(defaults) do
-		if(type(pMinimapDB[k]) == 'nil') then
-			pMinimapDB[k] = v
-		end
-	end
-
-	pMinimapDB.unlocked = false
-end
-
-local function SlashCommand(str)
+local function slashHandler(str)
 	if(str == 'reset') then
-		pMinimapDB = {}
-		LoadDefaults()
+		pMinimapDB = nil
+		pMinimap:LoadDefaults()
 		print('|cffff8080pMinimap:|r Savedvariables is now reset. You should reload/relog to affect changes.')
 	elseif(str == 'refresh') then
 		Minimap:SetMaskTexture([=[Interface\ChatFrame\ChatFrameBackground]=])
@@ -119,77 +92,14 @@ local function SlashCommand(str)
 	end
 end

-
-local function CreateClock(self)
-	TimeManager_LoadUI()
-
-	TimeManagerClockButton:SetWidth(40)
-	TimeManagerClockButton:SetHeight(14)
-	TimeManagerClockButton:ClearAllPoints()
-	TimeManagerClockButton:SetPoint(pMinimapDB.coords and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
-	TimeManagerClockButton:GetRegions():Hide()
-	TimeManagerClockButton:Show()
-	TimeManagerClockButton:SetScript('OnClick', onClickClock)
-
-	TimeManagerClockTicker:SetPoint('CENTER', TimeManagerClockButton)
-	TimeManagerClockTicker:SetFont(LSM:Fetch('font', pMinimapDB.smfont), pMinimapDB.fontsize, pMinimapDB.fontflag)
-	TimeManagerClockTicker:SetShadowOffset(0, 0)
-
-	TimeManagerAlarmFiredTexture.Show = function() TimeManagerClockTicker:SetTextColor(1, 0, 0) end
-	TimeManagerAlarmFiredTexture.Hide = function() TimeManagerClockTicker:SetTextColor(1, 1, 1) end
-
-	self:RegisterEvent('CALENDAR_UPDATE_PENDING_INVITES')
-	self.CALENDAR_UPDATE_PENDING_INVITES()
-
-	self.RunClock = true
-end
-
-local function CreateCoords(self)
-	self.Coord = CreateFrame('Button', nil, Minimap)
-	self.Coord:SetPoint(pMinimapDB.clock and 'BOTTOMRIGHT' or 'BOTTOM', Minimap)
-	self.Coord:SetWidth(40)
-	self.Coord:SetHeight(14)
-	self.Coord:RegisterForClicks('AnyUp')
-
-	self.Coord.Text = self.Coord:CreateFontString(nil, 'OVERLAY')
-	self.Coord.Text:SetPoint('CENTER', self.Coord)
-	self.Coord.Text:SetFont(LSM:Fetch('font', pMinimapDB.smfont), pMinimapDB.fontsize, pMinimapDB.fontflag)
-	self.Coord.Text:SetTextColor(1, 1, 1)
-
-	self.Coord:SetScript('OnClick', onClickCoord)
-	self.Coord:SetScript('OnUpdate', onUpdate)
-
-	self:RegisterEvent('ZONE_CHANGED_NEW_AREA')
-	self.RunCoords = true
-end
-
-function pMinimap:CALENDAR_UPDATE_PENDING_INVITES()
-	if(CalendarGetNumPendingInvites() ~= 0) then
-		TimeManagerClockTicker:SetTextColor(0, 1, 0)
-	else
-		TimeManagerClockTicker:SetTextColor(1, 1, 1)
-	end
-end
-
-function pMinimap:ZONE_CHANGED_NEW_AREA()
-	SetMapToCurrentZone()
-end
-
-function pMinimap:UPDATE_INVENTORY_ALERTS()
-	local highstatus = 0
-	for i in next, INVENTORY_ALERT_STATUS_SLOTS do
-		local status = GetInventoryAlertStatus(i)
-		if(status > highstatus) then
-			highstatus = status
-		end
+local function optionsPanel(self)
+	if(not IsAddOnLoaded('pMinimap_Config')) then
+		LoadAddOn('pMinimap_Config')
 	end
+	self:SetScript('OnShow', nil)

-	local color = INVENTORY_ALERT_COLORS[highstatus]
-	if(color) then
-		Minimap:SetBackdropColor(color.r, color.g, color.b)
-	else
-		Minimap:SetBackdropColor(unpack(pMinimapDB.colors))
-	end
+	InterfaceOptionsDisplayPanelShowClock:Disable()
+	InterfaceOptionsDisplayPanelShowClock:Hide()
 end

 local function Initialize(self)
@@ -218,19 +128,19 @@ local function Initialize(self)
 	MiniMapMailFrame:SetHeight(8)

 	MiniMapMailText = MiniMapMailFrame:CreateFontString(nil, 'OVERLAY')
-	MiniMapMailText:SetFont(LSM:Fetch('font', pMinimapDB.smfont), pMinimapDB.fontsize, pMinimapDB.fontflag)
+	MiniMapMailText:SetFont(LSM:Fetch('font', self.db.smfont), self.db.fontsize, self.db.fontflag)
 	MiniMapMailText:SetPoint('BOTTOM', 0, 2)
 	MiniMapMailText:SetText('New Mail!')
 	MiniMapMailText:SetTextColor(1, 1, 1)

 	MinimapZoneTextButton:SetParent(Minimap)
 	MinimapZoneTextButton:ClearAllPoints()
-	MinimapZoneTextButton:SetPoint(pMinimapDB.zonePoint == 'BOTTOM' and 'TOP' or 'BOTTOM', Minimap, pMinimapDB.zonePoint, 0, pMinimapDB.zoneOffset)
+	MinimapZoneTextButton:SetPoint(self.db.zonePoint == 'BOTTOM' and 'TOP' or 'BOTTOM', Minimap, self.db.zonePoint, 0, self.db.zoneOffset)
 	MinimapZoneTextButton:SetWidth(Minimap:GetWidth() * 1.5)

 	MinimapZoneText:ClearAllPoints()
 	MinimapZoneText:SetAllPoints(MinimapZoneTextButton)
-	MinimapZoneText:SetFont(LSM:Fetch('font', pMinimapDB.smfont), pMinimapDB.fontsize, pMinimapDB.fontflag)
+	MinimapZoneText:SetFont(LSM:Fetch('font', self.db.smfont), self.db.fontsize, self.db.fontflag)
 	MinimapZoneText:SetShadowOffset(0, 0)

 	MinimapBorder:SetTexture('')
@@ -246,12 +156,12 @@ local function Initialize(self)

 	Minimap:EnableMouseWheel()
 	Minimap:SetScript('OnMouseWheel', onMouseWheel)
-	Minimap:SetScale(pMinimapDB.scale)
-	Minimap:SetFrameLevel(pMinimapDB.level)
-	Minimap:SetFrameStrata(pMinimapDB.strata)
+	Minimap:SetScale(self.db.scale)
+	Minimap:SetFrameLevel(self.db.level)
+	Minimap:SetFrameStrata(self.db.strata)
 	Minimap:SetMaskTexture([=[Interface\ChatFrame\ChatFrameBackground]=])
-	Minimap:SetBackdrop({bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=], insets = {top = - pMinimapDB.offset, left = - pMinimapDB.offset, bottom = - pMinimapDB.offset, right = - pMinimapDB.offset}})
-	Minimap:SetBackdropColor(unpack(pMinimapDB.colors))
+	Minimap:SetBackdrop({bgFile = [=[Interface\ChatFrame\ChatFrameBackground]=], insets = {top = - self.db.offset, left = - self.db.offset, bottom = - self.db.offset, right = - self.db.offset}})
+	Minimap:SetBackdropColor(unpack(self.db.colors))

 	MinimapCluster:EnableMouse(false)
 	Minimap:SetMovable(true)
@@ -259,28 +169,28 @@ local function Initialize(self)
 	Minimap:SetScript('OnDragStop', function() if(pMinimapDB.unlocked) then Minimap:StopMovingOrSizing() end end)
 	Minimap:SetScript('OnDragStart', function() if(pMinimapDB.unlocked) then Minimap:StartMoving() end end)

-	if(not pMinimapDB.zone) then
+	if(not self.db.zone) then
 		MinimapZoneTextButton:Hide()
 	end

-	if(pMinimapDB.dura) then
+	if(self.db.dura) then
 		DurabilityFrame:SetAlpha(0)

 		self:RegisterEvent('UPDATE_INVENTORY_ALERTS')
 		self.UPDATE_INVENTORY_ALERTS()
 	end

-	if(pMinimapDB.coords) then
-		CreateCoords(self)
+	if(self.db.coords) then
+		self:CreateCoords()
 	end

-	if(pMinimapDB.clock) then
-		CreateClock(self)
+	if(self.db.clock) then
+		self:CreateClock()
 	else
 		TimeManagerClockButton:Hide()
 	end

-	if(pMinimapDB.mail) then
+	if(self.db.mail) then
 		MiniMapMailIcon:Hide()
 	else
 		MiniMapMailText:Hide()
@@ -288,23 +198,103 @@ local function Initialize(self)
 end


+function pMinimap:LoadDefaults()
+	pMinimapDB = setmetatable(pMinimapDB or {}, {__index = defaults})
+	pMinimapDB.unlocked = false
+
+	self.db = pMinimapDB
+end
+
+function pMinimap:CreateClock()
+	TimeManager_LoadUI()
+
+	TimeManagerClockButton:SetWidth(40)
+	TimeManagerClockButton:SetHeight(14)
+	TimeManagerClockButton:ClearAllPoints()
+	TimeManagerClockButton:SetPoint(self.db.coords and 'BOTTOMLEFT' or 'BOTTOM', Minimap)
+	TimeManagerClockButton:GetRegions():Hide()
+	TimeManagerClockButton:Show()
+	TimeManagerClockButton:SetScript('OnClick', onClickClock)
+
+	TimeManagerClockTicker:SetPoint('CENTER', TimeManagerClockButton)
+	TimeManagerClockTicker:SetFont(LSM:Fetch('font', self.db.smfont), self.db.fontsize, self.db.fontflag)
+	TimeManagerClockTicker:SetShadowOffset(0, 0)
+
+	TimeManagerAlarmFiredTexture.Show = function() TimeManagerClockTicker:SetTextColor(1, 0, 0) end
+	TimeManagerAlarmFiredTexture.Hide = function() TimeManagerClockTicker:SetTextColor(1, 1, 1) end
+
+	self:RegisterEvent('CALENDAR_UPDATE_PENDING_INVITES')
+	self.CALENDAR_UPDATE_PENDING_INVITES()
+
+	self.RunClock = true
+end
+
+function pMinimap:CreateCoords()
+	self.Coord = CreateFrame('Button', nil, Minimap)
+	self.Coord:SetPoint(self.db.clock and 'BOTTOMRIGHT' or 'BOTTOM', Minimap)
+	self.Coord:SetWidth(40)
+	self.Coord:SetHeight(14)
+	self.Coord:RegisterForClicks('AnyUp')
+
+	self.Coord.Text = self.Coord:CreateFontString(nil, 'OVERLAY')
+	self.Coord.Text:SetPoint('CENTER', self.Coord)
+	self.Coord.Text:SetFont(LSM:Fetch('font', self.db.smfont), self.db.fontsize, self.db.fontflag)
+	self.Coord.Text:SetTextColor(1, 1, 1)
+
+	self.Coord:SetScript('OnClick', onClickCoord)
+	self.Coord:SetScript('OnUpdate', onUpdate)
+
+	self:RegisterEvent('ZONE_CHANGED_NEW_AREA')
+end
+
+
 function pMinimap:ADDON_LOADED(event, addon)
 	if(addon ~= 'pMinimap') then return end
+	self:UnregisterEvent(event)

-	self.onUpdate = onUpdate
-	self:UnregisterEvent(event)
-	DisableBlizzard()
+	CreateFrame('Frame', nil, InterfaceOptionsFrame):SetScript('OnShow', optionsPanel)
+	LSM:Register('font', 'Visitor TT1', [=[Interface\AddOns\pMinimap\font.ttf]=])

 	SLASH_PMINIMAP1 = '/pmm'
 	SLASH_PMINIMAP2 = '/pminimap'
-	SlashCmdList.PMINIMAP = SlashCommand
+	SlashCmdList.PMINIMAP = slashHandler
+
+	self:LoadDefaults()
+	self.onCoordUpdate = onUpdate
+
+	InterfaceOptionsDisplayPanelShowClock.setFunc('1')
+	InterfaceOptionsDisplayPanelShowClock.setFunc = function() end

-	LSM:Register('font', 'Visitor TT1', [=[Interface\AddOns\pMinimap\font.ttf]=])
-	LoadDefaults()
 	Initialize(self)
+end

-	self.CreateClock = CreateClock
-	self.CreateCoords = CreateCoords
+function pMinimap:CALENDAR_UPDATE_PENDING_INVITES()
+	if(CalendarGetNumPendingInvites() ~= 0) then
+		TimeManagerClockTicker:SetTextColor(0, 1, 0)
+	else
+		TimeManagerClockTicker:SetTextColor(1, 1, 1)
+	end
+end
+
+function pMinimap:ZONE_CHANGED_NEW_AREA()
+	SetMapToCurrentZone()
+end
+
+function pMinimap:UPDATE_INVENTORY_ALERTS()
+	local highstatus = 0
+	for i in next, INVENTORY_ALERT_STATUS_SLOTS do
+		local status = GetInventoryAlertStatus(i)
+		if(status > highstatus) then
+			highstatus = status
+		end
+	end
+
+	local color = INVENTORY_ALERT_COLORS[highstatus]
+	if(color) then
+		Minimap:SetBackdropColor(color.r, color.g, color.b)
+	else
+		Minimap:SetBackdropColor(unpack(pMinimapDB.colors))
+	end
 end


diff --git a/pMinimap/pMinimap.toc b/pMinimap/pMinimap.toc
index 5399c60..35c95f3 100644
--- a/pMinimap/pMinimap.toc
+++ b/pMinimap/pMinimap.toc
@@ -4,7 +4,7 @@
 ## Title: |cffff6000p|rMinimap
 ## Notes: Yet another square minimap addon
 ## SavedVariablesPerCharacter: pMinimapDB
-## OptionalDeps: LibSharedMedia-3.0
+## OptionalDeps: Ace3, LibSharedMedia-3.0, SharedMedia

 libs\LibStub\LibStub.lua
 libs\CallbackHandler-1.0\CallbackHandler-1.0.xml