WoWInterface SVN bdGrid

[/] [trunk/] [lib/] [oUF/] [elements/] [leader.lua] - Blame information for rev 2

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 Blooblahguy-207965
--[[ Element: Leader Icon
2 Blooblahguy-207965
 
3 Blooblahguy-207965
 Toggles visibility based on the units leader status.
4 Blooblahguy-207965
 
5 Blooblahguy-207965
 Widget
6 Blooblahguy-207965
 
7 Blooblahguy-207965
 Leader - Any UI widget.
8 Blooblahguy-207965
 
9 Blooblahguy-207965
 Notes
10 Blooblahguy-207965
 
11 Blooblahguy-207965
 The default leader icon will be applied if the UI widget is a texture and
12 Blooblahguy-207965
 doesn't have a texture or color defined.
13 Blooblahguy-207965
 
14 Blooblahguy-207965
 Examples
15 Blooblahguy-207965
 
16 Blooblahguy-207965
   -- Position and size
17 Blooblahguy-207965
   local Leader = self:CreateTexture(nil, "OVERLAY")
18 Blooblahguy-207965
   Leader:SetSize(16, 16)
19 Blooblahguy-207965
   Leader:SetPoint("BOTTOM", self, "TOP")
20 Blooblahguy-207965
 
21 Blooblahguy-207965
   -- Register it with oUF
22 Blooblahguy-207965
   self.Leader = Leadera
23 Blooblahguy-207965
 
24 Blooblahguy-207965
 Hooks
25 Blooblahguy-207965
 
26 Blooblahguy-207965
 Override(self) - Used to completely override the internal update function.
27 Blooblahguy-207965
                  Removing the table key entry will make the element fall-back
28 Blooblahguy-207965
                  to its internal function again.
29 Blooblahguy-207965
]]
30 Blooblahguy-207965
 
31 Blooblahguy-207965
local parent, ns = ...
32 Blooblahguy-207965
local oUF = ns.oUF
33 Blooblahguy-207965
 
34 Blooblahguy-207965
local Update = function(self, event)
35 Blooblahguy-207965
        local leader = self.Leader
36 Blooblahguy-207965
        if(leader.PreUpdate) then
37 Blooblahguy-207965
                leader:PreUpdate()
38 Blooblahguy-207965
        end
39 Blooblahguy-207965
 
40 Blooblahguy-207965
        local unit = self.unit
41 Blooblahguy-207965
        local isLeader = (UnitInParty(unit) or UnitInRaid(unit)) and UnitIsGroupLeader(unit)
42 Blooblahguy-207965
        if(isLeader) then
43 Blooblahguy-207965
                leader:Show()
44 Blooblahguy-207965
        else
45 Blooblahguy-207965
                leader:Hide()
46 Blooblahguy-207965
        end
47 Blooblahguy-207965
 
48 Blooblahguy-207965
        if(leader.PostUpdate) then
49 Blooblahguy-207965
                return leader:PostUpdate(isLeader)
50 Blooblahguy-207965
        end
51 Blooblahguy-207965
end
52 Blooblahguy-207965
 
53 Blooblahguy-207965
local Path = function(self, ...)
54 Blooblahguy-207965
        return (self.Leader.Override or Update) (self, ...)
55 Blooblahguy-207965
end
56 Blooblahguy-207965
 
57 Blooblahguy-207965
local ForceUpdate = function(element)
58 Blooblahguy-207965
        return Path(element.__owner, 'ForceUpdate')
59 Blooblahguy-207965
end
60 Blooblahguy-207965
 
61 Blooblahguy-207965
local Enable = function(self)
62 Blooblahguy-207965
        local leader = self.Leader
63 Blooblahguy-207965
        if(leader) then
64 Blooblahguy-207965
                leader.__owner = self
65 Blooblahguy-207965
                leader.ForceUpdate = ForceUpdate
66 Blooblahguy-207965
 
67 Blooblahguy-207965
                self:RegisterEvent("PARTY_LEADER_CHANGED", Path, true)
68 Blooblahguy-207965
                self:RegisterEvent("GROUP_ROSTER_UPDATE", Path, true)
69 Blooblahguy-207965
 
70 Blooblahguy-207965
                if(leader:IsObjectType"Texture" and not leader:GetTexture()) then
71 Blooblahguy-207965
                        leader:SetTexture[[Interface\GroupFrame\UI-Group-LeaderIcon]]
72 Blooblahguy-207965
                end
73 Blooblahguy-207965
 
74 Blooblahguy-207965
                return true
75 Blooblahguy-207965
        end
76 Blooblahguy-207965
end
77 Blooblahguy-207965
 
78 Blooblahguy-207965
local Disable = function(self)
79 Blooblahguy-207965
        local leader = self.Leader
80 Blooblahguy-207965
        if(leader) then
81 Blooblahguy-207965
                leader:Hide()
82 Blooblahguy-207965
                self:UnregisterEvent("PARTY_LEADER_CHANGED", Path)
83 Blooblahguy-207965
                self:UnregisterEvent("GROUP_ROSTER_UPDATE", Path)
84 Blooblahguy-207965
        end
85 Blooblahguy-207965
end
86 Blooblahguy-207965
 
87 Blooblahguy-207965
oUF:AddElement('Leader', Path, Enable, Disable)