PageRenderTime 103ms CodeModel.GetById 80ms app.highlight 5ms RepoModel.GetById 16ms app.codeStats 0ms

/Tukui/modules/blizzard/achievements.lua

http://github.com/Asphyxia/Tukui
Lua | 81 lines | 70 code | 11 blank | 0 comment | 16 complexity | 90a92a861ff232b0088605081a71ed39 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2
 3local AchievementHolder = CreateFrame("Frame", "TukuiAchievementHolder", UIParent)
 4AchievementHolder:Width(180)
 5AchievementHolder:Height(20)
 6AchievementHolder:SetPoint("CENTER", UIParent, "CENTER", 0, 170)
 7AchievementHolder:SetTemplate("Default")
 8AchievementHolder:SetBackdropBorderColor(1, 0, 0)
 9AchievementHolder:SetClampedToScreen(true)
10AchievementHolder:SetMovable(true)
11AchievementHolder:SetAlpha(0)
12AchievementHolder.text = T.SetFontString(AchievementHolder, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
13AchievementHolder.text:SetPoint("CENTER")
14AchievementHolder.text:SetText(L.move_achievements)
15
16local pos = "TOP"
17
18function T.AchievementMove(self, event, ...)
19	local previousFrame
20	for i=1, MAX_ACHIEVEMENT_ALERTS do
21		local aFrame = _G["AchievementAlertFrame"..i]
22		if ( aFrame ) then
23			aFrame:ClearAllPoints()
24			if pos == "TOP" then
25				if ( previousFrame and previousFrame:IsShown() ) then
26					aFrame:SetPoint("TOP", previousFrame, "BOTTOM", 0, -10)
27				else
28					aFrame:SetPoint("TOP", AchievementHolder, "BOTTOM")
29				end
30			else
31				if ( previousFrame and previousFrame:IsShown() ) then
32					aFrame:SetPoint("BOTTOM", previousFrame, "TOP", 0, 10)
33				else
34					aFrame:SetPoint("BOTTOM", AchievementHolder, "TOP")	
35				end			
36			end
37			
38			previousFrame = aFrame
39		end		
40	end
41	
42end
43hooksecurefunc("AchievementAlertFrame_FixAnchors", T.AchievementMove)
44
45hooksecurefunc("DungeonCompletionAlertFrame_FixAnchors", function()
46	for i=MAX_ACHIEVEMENT_ALERTS, 1, -1 do
47		local aFrame = _G["AchievementAlertFrame"..i]
48		if ( aFrame and aFrame:IsShown() ) then
49			DungeonCompletionAlertFrame1:ClearAllPoints()
50			if pos == "TOP" then
51				DungeonCompletionAlertFrame1:SetPoint("TOP", aFrame, "BOTTOM", 0, -10)
52			else
53				DungeonCompletionAlertFrame1:SetPoint("BOTTOM", aFrame, "TOP", 0, 10)
54			end
55			
56			return
57		end
58		
59		DungeonCompletionAlertFrame1:ClearAllPoints()	
60		if pos == "TOP" then
61			DungeonCompletionAlertFrame1:SetPoint("TOP", AchievementHolder, "BOTTOM")
62		else
63			DungeonCompletionAlertFrame1:SetPoint("BOTTOM", AchievementHolder, "TOP")
64		end
65	end
66end)
67
68function T.PostAchievementMove(frame)
69	local point = select(1, frame:GetPoint())
70
71	if string.find(point, "TOP") or point == "CENTER" or point == "LEFT" or point == "RIGHT" then
72		pos = "TOP"
73	else
74		pos = "BOTTOM"
75	end
76	T.AchievementMove()
77end
78
79local frame = CreateFrame("Frame")
80frame:RegisterEvent("ACHIEVEMENT_EARNED")
81frame:SetScript("OnEvent", function(self, event, ...) T.AchievementMove(self, event, ...) end)