PageRenderTime 143ms CodeModel.GetById 60ms app.highlight 8ms RepoModel.GetById 53ms app.codeStats 0ms

/Tukui/modules/actionbars/BarShift.lua

http://github.com/Asphyxia/Tukui
Lua | 137 lines | 119 code | 10 blank | 8 comment | 23 complexity | 589bb89281e6d3fb8c6ace510af04c9f MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2if not C["actionbar"].enable == true then return end
  3
  4---------------------------------------------------------------------------
  5-- Setup Shapeshift Bar
  6---------------------------------------------------------------------------
  7
  8local TukuiShift = CreateFrame("Frame", "TukuiShiftBar", UIParent)
  9if T.myclass ~= "SHAMAN" and C["actionbar"].vertical_shapeshift then
 10	TukuiShift:Width(T.stancebuttonsize + 10)
 11else
 12	TukuiShift:Height(T.stancebuttonsize + 10)
 13end
 14TukuiShift:Point("BOTTOMLEFT",  TukuiChatBackgroundLeft, "BOTTOMRIGHT", 3, 0)
 15-- TukuiShift:SetFrameLevel(20)
 16TukuiShift:SetFrameStrata("MEDIUM")
 17TukuiShift:SetMovable(true)
 18TukuiShift:SetClampedToScreen(true)
 19TukuiShift:SetScript("OnEvent", function(self, event, ...)
 20	if C["actionbar"].hideshapeshift then TukuiShift:Hide() return end
 21
 22	if T.myclass == "SHAMAN" then
 23		TukuiShift:Width(210)
 24
 25		TukuiShift:SetBackdropBorderColor(0,0,0,0)
 26		TukuiShift:SetBackdropBorderColor(0,0,0,0)
 27	else
 28		TukuiShift:SetTemplate("Transparent")
 29		TukuiShift:CreateShadow("Default")
 30		TukuiShift:CreateBorder(true, true)
 31
 32		local forms = GetNumShapeshiftForms()
 33		if forms > 0 then
 34			if InCombatLockdown() then return end
 35			if C["actionbar"].vertical_shapeshift then
 36				TukuiShift:Height((T.stancebuttonsize * forms) + (T.buttonspacing * forms + 1) + 5)
 37			else
 38				TukuiShift:Width((T.stancebuttonsize * forms) + (T.buttonspacing * forms + 1) + 5)
 39			end
 40			TukuiShift:Show()
 41		else
 42			if InCombatLockdown() then return end
 43			TukuiShift:Hide()
 44		end
 45	end
 46end)
 47TukuiShift:RegisterEvent("PLAYER_LOGIN")
 48TukuiShift:RegisterEvent("PLAYER_ENTERING_WORLD")
 49TukuiShift:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
 50TukuiShift:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
 51TukuiShift:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
 52TukuiShift:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR")
 53
 54
 55-- shapeshift command to move totem or shapeshift in-game
 56local ssmover = CreateFrame("Frame", "TukuiShapeShiftHolder", UIParent)
 57ssmover:SetParent(TukuiShift)
 58ssmover:SetAllPoints(TukuiShift)
 59ssmover:SetTemplate("Default")
 60ssmover:SetBackdropBorderColor(1,0,0)
 61ssmover:SetAlpha(0)
 62ssmover.text = T.SetFontString(ssmover, C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 63ssmover.text:SetPoint("CENTER")
 64ssmover.text:SetText(L.move_shapeshift)
 65
 66-- create the shapeshift bar if we enabled it
 67local bar = CreateFrame("Frame", "TukuiShapeShift", TukuiShift, "SecureHandlerStateTemplate")
 68bar:ClearAllPoints()
 69bar:SetAllPoints(TukuiShift)
 70
 71local States = {
 72	["DRUID"] = "show",
 73	["WARRIOR"] = "show",
 74	["PALADIN"] = "show",
 75	["DEATHKNIGHT"] = "show",
 76	["ROGUE"] = "show,",
 77	["PRIEST"] = "show,",
 78	["HUNTER"] = "show,",
 79	["WARLOCK"] = "show,",
 80}
 81
 82bar:RegisterEvent("PLAYER_LOGIN")
 83bar:RegisterEvent("PLAYER_ENTERING_WORLD")
 84bar:RegisterEvent("UPDATE_SHAPESHIFT_FORMS")
 85bar:RegisterEvent("UPDATE_SHAPESHIFT_USABLE")
 86bar:RegisterEvent("UPDATE_SHAPESHIFT_COOLDOWN")
 87bar:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
 88bar:RegisterEvent("ACTIONBAR_PAGE_CHANGED")
 89bar:SetScript("OnEvent", function(self, event, ...)
 90	if event == "PLAYER_LOGIN" then
 91		local button
 92		for i = 1, NUM_SHAPESHIFT_SLOTS do
 93			button = _G["ShapeshiftButton"..i]
 94			button:ClearAllPoints()
 95			button:SetParent(self)
 96			button:SetFrameStrata(TukuiShift:GetFrameStrata())
 97			if i == 1 then
 98				if C["actionbar"].vertical_shapeshift then
 99					button:Point("TOPLEFT", 5, -5)
100				else
101					button:Point("BOTTOMLEFT", 5, 5)
102				end
103			else
104				local previous = _G["ShapeshiftButton"..i-1]
105				if C["actionbar"].vertical_shapeshift then
106					button:Point("TOP", previous, "BOTTOM", 0, -T.buttonspacing)
107				else
108					button:Point("LEFT", previous, "RIGHT", T.buttonspacing, 0)
109				end
110			end
111			local _, name = GetShapeshiftFormInfo(i)
112			if name then
113				button:Show()
114			end
115		end
116		RegisterStateDriver(self, "visibility", States[T.myclass] or "hide")
117	elseif event == "UPDATE_SHAPESHIFT_FORMS" then
118		-- Update Shapeshift Bar Button Visibility
119		-- I seriously don't know if it's the best way to do it on spec changes or when we learn a new stance.
120		if InCombatLockdown() then return end -- > just to be safe ;p
121		local button
122		for i = 1, NUM_SHAPESHIFT_SLOTS do
123			button = _G["ShapeshiftButton"..i]
124			local _, name = GetShapeshiftFormInfo(i)
125			if name then
126				button:Show()
127			else
128				button:Hide()
129			end
130		end
131		T.TukuiShiftBarUpdate()
132	elseif event == "PLAYER_ENTERING_WORLD" then
133		T.StyleShift()
134	else
135		T.TukuiShiftBarUpdate()
136	end
137end)