PageRenderTime 213ms CodeModel.GetById 121ms app.highlight 3ms RepoModel.GetById 87ms app.codeStats 0ms

/Tukui/modules/actionbars/Bar1.lua

http://github.com/Asphyxia/Tukui
Lua | 98 lines | 72 code | 10 blank | 16 comment | 15 complexity | 0a244aef01ac42d993718d9528900434 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2
 3if not C["actionbar"].enable == true then return end
 4
 5---------------------------------------------------------------------------
 6-- Setup Main Action Bar.
 7-- Now used for stances, Bonus, Vehicle at the same time.
 8-- Since t12, it's also working for druid cat stealth. (a lot requested)
 9---------------------------------------------------------------------------
10
11local bar = TukuiBar1
12--[[ 
13	Bonus bar classes id
14
15	DRUID: Caster: 0, Cat: 1, Tree of Life: 0, Bear: 3, Moonkin: 4
16	WARRIOR: Battle Stance: 1, Defensive Stance: 2, Berserker Stance: 3 
17	ROGUE: Normal: 0, Stealthed: 1
18	PRIEST: Normal: 0, Shadowform: 1
19	
20	When Possessing a Target: 5
21]]--
22
23local Page = {
24	["DRUID"] = "[bonusbar:1,nostealth] 7; [bonusbar:1,stealth] 8; [bonusbar:2] 8; [bonusbar:3] 9; [bonusbar:4] 10;",
25	["WARRIOR"] = "[bonusbar:1] 7; [bonusbar:2] 8; [bonusbar:3] 9;",
26	["PRIEST"] = "[bonusbar:1] 7;",
27	["ROGUE"] = "[bonusbar:1] 7; [form:3] 7;",
28	["DEFAULT"] = "[bonusbar:5] 11; [bar:2] 2; [bar:3] 3; [bar:4] 4; [bar:5] 5; [bar:6] 6;",
29}
30
31local function GetBar()
32	local condition = Page["DEFAULT"]
33	local class = T.myclass
34	local page = Page[class]
35	if page then
36		condition = condition.." "..page
37	end
38	condition = condition.." 1"
39	return condition
40end
41
42bar:RegisterEvent("PLAYER_LOGIN")
43bar:RegisterEvent("PLAYER_ENTERING_WORLD")
44bar:RegisterEvent("KNOWN_CURRENCY_TYPES_UPDATE")
45bar:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
46bar:RegisterEvent("BAG_UPDATE")
47bar:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
48bar:SetScript("OnEvent", function(self, event, ...)
49	if event == "PLAYER_LOGIN" then
50		local button
51		for i = 1, NUM_ACTIONBAR_BUTTONS do
52			button = _G["ActionButton"..i]
53			self:SetFrameRef("ActionButton"..i, button)
54		end	
55
56		self:Execute([[
57			buttons = table.new()
58			for i = 1, 12 do
59				table.insert(buttons, self:GetFrameRef("ActionButton"..i))
60			end
61		]])
62
63		self:SetAttribute("_onstate-page", [[ 
64			for i, button in ipairs(buttons) do
65				button:SetAttribute("actionpage", tonumber(newstate))
66			end
67		]])
68			
69		RegisterStateDriver(self, "page", GetBar())
70	elseif event == "PLAYER_ENTERING_WORLD" then
71		if T.toc < 40200 then MainMenuBar_UpdateKeyRing() end
72		
73		local button
74		for i = 1, 12 do
75			button = _G["ActionButton"..i]
76			button:Size(T.buttonsize, T.buttonsize)
77			button:ClearAllPoints()
78			button:SetParent(bar)
79			button:SetFrameStrata("BACKGROUND")
80			button:SetFrameLevel(15)
81			if i == 1 then
82				if C["actionbar"].mainswap then
83					button:Point("TOPLEFT", 5, -5)
84				else
85					button:Point("BOTTOMLEFT", 5, 5)
86				end
87			else
88				local previous = _G["ActionButton"..i-1]
89				button:Point("LEFT", previous, "RIGHT", T.buttonspacing, 0)
90			end
91		end
92	elseif event == "ACTIVE_TALENT_GROUP_CHANGED" then
93		-- attempt to fix blocked glyph change after switching spec.
94		LoadAddOn("Blizzard_GlyphUI")
95	else
96		MainMenuBar_OnEvent(self, event, ...)
97	end
98end)