PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 37ms app.codeStats 0ms

/Tukui/modules/unitframes/core/oUF/elements/happiness.lua

http://github.com/Asphyxia/Tukui
Lua | 65 lines | 51 code | 14 blank | 0 comment | 14 complexity | 113fde63f388049671ec72ee933187b0 MD5 | raw file
 1local WoW41 = select(4, GetBuildInfo()) == 40100
 2if(WoW41) then return end
 3
 4local parent, ns = ...
 5local oUF = ns.oUF
 6
 7local Update = function(self, event, unit, powerType)
 8	if(self.unit ~= unit) then return end
 9
10	local happ = self.Happiness
11	if(happ and (powerType == 'HAPPINESS' or not powerType)) then
12		local happiness = GetPetHappiness()
13		local _, hunterPet = HasPetUI()
14
15		if(not (happiness or hunterPet)) then
16			return happ:Hide()
17		end
18
19		happ:Show()
20		if(happiness == 1) then
21			happ:SetTexCoord(0.375, 0.5625, 0, 0.359375)
22		elseif(happiness == 2) then
23			happ:SetTexCoord(0.1875, 0.375, 0, 0.359375)
24		elseif(happiness == 3) then
25			happ:SetTexCoord(0, 0.1875, 0, 0.359375)
26		end
27
28		if(happ.PostUpdate) then
29			return happ:PostUpdate(unit, happiness)
30		end
31	end
32end
33
34local Path = function(self, ...)
35	return (self.Happiness.Override or Update) (self, ...)
36end
37
38local ForceUpdate = function(element)
39	return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
40end
41
42local Enable = function(self)
43	local happiness = self.Happiness
44	if(happiness) then
45		happiness.__owner = self
46		happiness.ForceUpdate = ForceUpdate
47
48		self:RegisterEvent('UNIT_POWER', Path)
49
50		if(happiness:IsObjectType"Texture" and not happiness:GetTexture()) then
51			happiness:SetTexture[[Interface\PetPaperDollFrame\UI-PetHappiness]]
52		end
53
54		return true
55	end
56end
57
58local Disable = function(self)
59	local happiness = self.Happiness
60	if(happiness) then
61		self:UnregisterEvent('UNIT_POWER', Path)
62	end
63end
64
65oUF:AddElement('Happiness', Path, Enable, Disable)