PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/datatext/specswitcher.lua

http://github.com/Asphyxia/Tukui
Lua | 80 lines | 68 code | 11 blank | 1 comment | 12 complexity | abda8b1055b2495c0b13ebac1941cab3 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2
 3if C.datatext.enable_specswitcher then
 4	local Stat = CreateFrame("Frame")
 5	Stat:EnableMouse(true)
 6	Stat:SetFrameStrata("BACKGROUND")
 7	Stat:SetFrameLevel(3)
 8 
 9	local Text = TukuiSpecSwitcher:CreateFontString(nil, "OVERLAY")
10	Text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
11	Text:Point("CENTER", TukuiSpecSwitcher, 0, 0.5)
12 
13	local int = 1
14	local function Update(self, t)
15		if not GetPrimaryTalentTree() then
16			Text:SetText(T.datacolor..L.datatext_notalents) 
17		return end
18		int = int - t
19		if int < 0 then
20			local tree1num = select(5,GetTalentTabInfo(1))
21			local tree2num = select(5,GetTalentTabInfo(2))
22			local tree3num = select(5,GetTalentTabInfo(3))
23			local majorTree = GetPrimaryTalentTree()
24			Text:SetText(select(2,GetTalentTabInfo(majorTree))..": "..T.datacolor..tree1num.."/"..tree2num.."/"..tree3num)
25		end
26	end
27 
28	local function OnEvent(self, event, ...)
29		if event == "PLAYER_LOGIN" then
30			self:UnregisterEvent("PLAYER_LOGIN")
31		end
32 
33		local c = GetActiveTalentGroup(false,false)
34		local group1tree1 = select(5,GetTalentTabInfo(1,false,false,1))
35		local group1tree2 = select(5,GetTalentTabInfo(2,false,false,1))
36		local group1tree3 = select(5,GetTalentTabInfo(3,false,false,1))
37		local majorTree1 = GetPrimaryTalentTree(false,false,1)
38		local hs = (GetNumTalentGroups() == 2 and GetPrimaryTalentTree(false,false,2))
39		local group2tree1 = hs and select(5,GetTalentTabInfo(1,false,false,2))
40		local group2tree2 = hs and select(5,GetTalentTabInfo(2,false,false,2))
41		local group2tree3 = hs and select(5,GetTalentTabInfo(3,false,false,2))
42		local majorTree2 = 0
43		if hs then
44			majorTree2 = GetPrimaryTalentTree(false,false,2)
45		end
46 
47		-- Setup Talents Tooltip
48		self:SetAllPoints(Text)
49 
50		self:SetScript("OnEnter", function(self)
51			if not InCombatLockdown() then
52				local anchor, panel, xoff, yoff = T.DataTextTooltipAnchor(Text)	
53				GameTooltip:SetOwner(panel, anchor, xoff, yoff)
54				GameTooltip:ClearLines()
55 
56				if(not GetPrimaryTalentTree()) then
57					GameTooltip:AddLine(T.datacolor..L.datatext_notalents)
58				elseif(hs) then
59					GameTooltip:AddLine(T.datacolor..(c == 1 and "* " or "  ") .. "|r" .. select(2,GetTalentTabInfo(majorTree1))..": "..T.datacolor..group1tree1.."/"..group1tree2.."/"..group1tree3,1,1,1)
60					GameTooltip:AddLine(T.datacolor..(c == 2 and "* " or "  ") .. "|r" .. select(2,GetTalentTabInfo(majorTree2))..": "..T.datacolor..group2tree1.."/"..group2tree2.."/"..group2tree3,1,1,1)
61				else
62					GameTooltip:AddLine(select(2,GetTalentTabInfo(majorTree1))..": "..T.datacolor..group1tree1.."/"..group1tree2.."/"..group1tree3,1,1,1)
63				end
64 
65				GameTooltip:Show()
66			end
67 
68		end)
69		self:SetScript("OnLeave", function() GameTooltip:Hide() end)
70	end
71 
72	Stat:RegisterEvent("PLAYER_LOGIN")
73	Stat:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
74	Stat:SetScript("OnEvent", OnEvent)
75	Stat:SetScript("OnUpdate", Update)
76	Stat:SetScript("OnMouseDown", function()
77		c = GetActiveTalentGroup(false,false)
78		SetActiveTalentGroup(c == 1 and 2 or 1)
79	end)
80end