PageRenderTime 17ms CodeModel.GetById 12ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Tukui/modules/unitframes/plugins/oUF_Reputation/oUF_Reputation.lua

http://github.com/Asphyxia/Tukui
Lua | 75 lines | 49 code | 12 blank | 14 comment | 11 complexity | e226f1be4594bd1567e30537926d874d MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2if C.unitframes.enable ~= true then return end
 3--[[
 4
 5	Elements handled:
 6	 .Reputation [statusbar]
 7	 .Reputation.Text [fontstring] (optional)
 8
 9	Booleans:
10	 - Tooltip
11
12	Functions that can be overridden from within a layout:
13	 - PostUpdate(self, event, unit, bar, min, max, value, name, id)
14	 - OverrideText(bar, min, max, value, name, id)
15
16--]]
17local _, ns = ...
18local oUF = ns.oUF or oUF
19
20if not oUF then return end
21
22local function tooltip(self)
23	local name, id, min, max, value = GetWatchedFactionInfo()
24	GameTooltip:SetOwner(self, 'ANCHOR_BOTTOM', 0, -5)
25	GameTooltip:AddLine(string.format('%s (%s)', name, _G['FACTION_STANDING_LABEL'..id]))
26	GameTooltip:AddLine(string.format('%d / %d (%d%%)', value - min, max - min, (value - min) / (max - min) * 100))
27	GameTooltip:Show()
28end
29
30local function update(self, event, unit)
31	local bar = self.Reputation
32	if(not GetWatchedFactionInfo()) then return bar:Hide() end
33
34	local name, id, min, max, value = GetWatchedFactionInfo()
35	bar:SetMinMaxValues(min, max)
36	bar:SetValue(value)
37	bar:Show()
38
39	if(bar.Text) then
40		if(bar.OverrideText) then
41			bar:OverrideText(min, max, value, name, id)
42		else
43			bar.Text:SetFormattedText('%d / %d - %s', value - min, max - min, name)
44		end
45	end
46
47	if(bar.PostUpdate) then bar.PostUpdate(self, event, unit, bar, min, max, value, name, id) end
48end
49
50local function enable(self, unit)
51	local bar = self.Reputation
52	if(bar and unit == 'player') then
53		if(not bar:GetStatusBarTexture()) then
54			bar:SetStatusBarTexture([=[Interface\TargetingFrame\UI-StatusBar]=])
55		end
56
57		self:RegisterEvent('UPDATE_FACTION', update)
58
59		if(bar.Tooltip) then
60			bar:EnableMouse()
61			bar:HookScript('OnLeave', GameTooltip_Hide)
62			bar:HookScript('OnEnter', tooltip)
63		end
64
65		return true
66	end
67end
68
69local function disable(self)
70	if(self.Reputation) then
71		self:UnregisterEvent('UPDATE_FACTION', update)
72	end
73end
74
75oUF:AddElement('Reputation', update, enable, disable)