PageRenderTime 103ms CodeModel.GetById 40ms app.highlight 9ms RepoModel.GetById 51ms app.codeStats 0ms

/Tukui/modules/misc/sCombo.lua

http://github.com/Asphyxia/Tukui
Lua | 138 lines | 125 code | 9 blank | 4 comment | 18 complexity | 48ac3f8dd68fec1a6fae430b6c3068b7 MD5 | raw file
  1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
  2
  3-- sCombo (Minimal Combo Bar Replacement)
  4-- Author: Smelly
  5
  6if not C.sCombo.enable or not C.unitframes.enable then return end
  7
  8TukuiTarget:DisableElement('CPoints') 
  9local Options = {
 10	comboWidth = T.Scale(40),
 11	comboHeight = T.Scale(11),
 12	spacing = T.Scale(3), 
 13	colors = {
 14		[1] = {0.60, 0, 0, 1},
 15		[2] = {0.60, 0.30, 0, 1},
 16		[3] = {0.60, 0.60, 0, 1},
 17		[4] = {0.30, 0.60, 0, 1},
 18		[5] = {0, 0.60, 0, 1},
 19	},
 20}
 21
 22local Anchor = CreateFrame("Frame", "sComboAnchor", UIParent)
 23Anchor:CreatePanel("", ((Options.comboWidth + Options.spacing)*5)-Options.spacing, 12, "CENTER", UIParent, "CENTER", 0, -175)
 24Anchor:SetBackdropBorderColor(1,0,0)
 25Anchor:CreateShadow("")
 26Anchor:SetMovable(true)
 27Anchor:Hide()
 28Anchor.text = Anchor:CreateFontString(nil, "OVERLAY")
 29Anchor.text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 30Anchor.text:SetPoint("CENTER", 0, 1)
 31Anchor.text:SetText(T.datacolor.."Move CP-Bar (sCombo)")
 32
 33local sCombo = CreateFrame("Frame", "sCombo", UIParent)
 34for i = 1, 5 do
 35	sCombo[i] = CreateFrame("Frame", "sCombo"..i, UIParent)
 36	sCombo[i]:CreatePanel("Default", Options.comboWidth, Options.comboHeight, "CENTER", UIParent, "CENTER", 0, 0)
 37	sCombo[i]:CreateShadow("Default")
 38	if C.datatext.fontsize == 8 then
 39		sCombo[i].text = sCombo[i]:CreateFontString(nil, "OVERLAY")
 40		sCombo[i].text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
 41		sCombo[i].text:SetPoint("CENTER")
 42		sCombo[i].text:SetText(i)
 43	end
 44		
 45	if i == 1 then
 46		sCombo[i]:Point("TOPLEFT", Anchor, "BOTTOMLEFT", 0, -3)
 47	else
 48		sCombo[i]:Point("LEFT", sCombo[i-1], "RIGHT", Options.spacing, 0)
 49	end
 50	
 51	sCombo[i]:SetBackdropBorderColor(unpack(Options.colors[i]))
 52	sCombo[i]:RegisterEvent("PLAYER_ENTERING_WORLD")
 53	sCombo[i]:RegisterEvent("UNIT_COMBO_POINTS")
 54	sCombo[i]:RegisterEvent("PLAYER_TARGET_CHANGED")
 55	sCombo[i]:SetScript("OnEvent", function(self, event)
 56	local points, pt = 0, GetComboPoints("player", "target")
 57		if pt == points then
 58			sCombo[i]:Hide()
 59		elseif pt > points then
 60			for i = points + 1, pt do
 61				sCombo[i]:Show()
 62			end
 63		else
 64			for i = pt + 1, points do
 65				sCombo[i]:Hide()
 66			end
 67		end
 68		points = pt	
 69	end)
 70end
 71
 72-- slash command
 73local move = false
 74SLASH_MOVESCOMBO1 = "/scp"
 75SlashCmdList.MOVESCOMBO = function()
 76if InCombatLockdown() then print(ERR_NOT_IN_COMBAT) return end
 77	if not move then
 78		move = true
 79		Anchor:EnableMouse(true)
 80		Anchor:Show()
 81		Anchor:SetScript("OnMouseDown", function(self) self:StartMoving() end)
 82		Anchor:SetScript("OnMouseUp", function(self) self:StopMovingOrSizing() end)
 83		for i = 1,5 do 
 84			sCombo[i]:Show() 
 85			sCombo[i]:UnregisterAllEvents()
 86		end
 87	else
 88		move = false
 89		Anchor:EnableMouse(false)
 90		Anchor:Hide()
 91		for i = 1,5 do 
 92			sCombo[i]:Hide() 
 93			sCombo[i]:RegisterEvent("PLAYER_ENTERING_WORLD")
 94			sCombo[i]:RegisterEvent("UNIT_COMBO_POINTS")
 95			sCombo[i]:RegisterEvent("PLAYER_TARGET_CHANGED")
 96		end
 97	end
 98end
 99
100-- energy bar
101if not C.sCombo.energybar or not C.unitframes.enable then return end
102local sPowerBG = CreateFrame("Frame", "sPowerBG", TukuiTarget)
103sPowerBG:CreatePanel(nil, (Options.comboWidth * 5) + (Options.spacing * 5) - Options.spacing, Options.comboHeight, "TOPLEFT", Anchor, "BOTTOMLEFT", 0, -(Options.comboHeight+6))
104sPowerBG:CreateShadow()
105local sPowerStatus = CreateFrame("StatusBar", "sPowerStatus", TukuiTarget)
106sPowerStatus:SetStatusBarTexture(C.media.normTex)
107sPowerStatus:SetFrameLevel(6)
108sPowerStatus:Point("TOPLEFT", sPowerBG, "TOPLEFT", 2, -2)
109sPowerStatus:Point("BOTTOMRIGHT", sPowerBG, "BOTTOMRIGHT", -2, 2)
110sPowerStatus.t = sPowerStatus:CreateFontString(nil, "OVERLAY")
111sPowerStatus.t:SetPoint("CENTER")
112sPowerStatus.t:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE")
113sPowerStatus.t:SetShadowOffset(0.5, -0.5)
114sPowerStatus.t:SetShadowColor(0,0,0)
115local color = RAID_CLASS_COLORS[T.myclass]
116sPowerStatus:SetStatusBarColor(color.r, color.g, color.b)
117local t = 0
118sPowerStatus:SetScript("OnUpdate", function(self, elapsed)
119    t = t + elapsed;
120    if (t > 0.07) then
121        sPowerStatus:SetMinMaxValues(0, UnitPowerMax("player"))
122        local power = UnitPower("player")
123        sPowerStatus:SetValue(power)
124		sPowerStatus.t:SetText(power)
125    end
126end)
127sPowerBG:RegisterEvent("PLAYER_ENTERING_WORLD")
128sPowerBG:RegisterEvent("UNIT_DISPLAYPOWER")
129sPowerBG:SetScript("OnEvent", function(self, event)
130local p, _ = UnitPowerType("player")
131    if p == SPELL_POWER_ENERGY then
132        sPowerBG:Show()
133        sPowerStatus:Show()
134    else
135        sPowerBG:Hide()
136        sPowerStatus:Hide()
137    end
138end)