WoWInterface SVN bdGrid

[/] [trunk/] [lib/] [oUF/] [elements/] [classicons.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: Class Icons
2 Blooblahguy-207965
 
3 Blooblahguy-207965
 Toggles the visibility of icons depending on the player's class and
4 Blooblahguy-207965
 specialization.
5 Blooblahguy-207965
 
6 Blooblahguy-207965
 Widget
7 Blooblahguy-207965
 
8 Blooblahguy-207965
 ClassIcons - An array consisting of as many UI Textures as the theoretical
9 Blooblahguy-207965
 maximum return of `UnitPowerMax`.
10 Blooblahguy-207965
 
11 Blooblahguy-207965
 Notes
12 Blooblahguy-207965
 
13 Blooblahguy-207965
 Monk    - Chi Orbs
14 Blooblahguy-207965
 Paladin - Holy Power
15 Blooblahguy-207965
 Priest  - Shadow Orbs
16 Blooblahguy-207965
 Warlock - Soul Shards
17 Blooblahguy-207965
 
18 Blooblahguy-207965
 Examples
19 Blooblahguy-207965
 
20 Blooblahguy-207965
   local ClassIcons = {}
21 Blooblahguy-207965
   for index = 1, 6 do
22 Blooblahguy-207965
      local Icon = self:CreateTexture(nil, 'BACKGROUND')
23 Blooblahguy-207965
 
24 Blooblahguy-207965
      -- Position and size.
25 Blooblahguy-207965
      Icon:SetSize(16, 16)
26 Blooblahguy-207965
      Icon:SetPoint('TOPLEFT', self, 'BOTTOMLEFT', index * Icon:GetWidth(), 0)
27 Blooblahguy-207965
 
28 Blooblahguy-207965
      ClassIcons[index] = Icon
29 Blooblahguy-207965
   end
30 Blooblahguy-207965
 
31 Blooblahguy-207965
   -- Register with oUF
32 Blooblahguy-207965
   self.ClassIcons = ClassIcons
33 Blooblahguy-207965
 
34 Blooblahguy-207965
 Hooks
35 Blooblahguy-207965
 
36 Blooblahguy-207965
 OverrideVisibility(self) - Used to completely override the internal visibility
37 Blooblahguy-207965
                            function. Removing the table key entry will make
38 Blooblahguy-207965
                            the element fall-back to its internal function
39 Blooblahguy-207965
                            again.
40 Blooblahguy-207965
 Override(self)           - Used to completely override the internal update
41 Blooblahguy-207965
                            function. Removing the table key entry will make the
42 Blooblahguy-207965
                            element fall-back to its internal function again.
43 Blooblahguy-207965
 UpdateTexture(element)   - Used to completely override the internal function
44 Blooblahguy-207965
                            for updating the power icon textures. Removing the
45 Blooblahguy-207965
                            table key entry will make the element fall-back to
46 Blooblahguy-207965
                            its internal function again.
47 Blooblahguy-207965
 
48 Blooblahguy-207965
]]
49 Blooblahguy-207965
 
50 Blooblahguy-207965
local parent, ns = ...
51 Blooblahguy-207965
local oUF = ns.oUF
52 Blooblahguy-207965
 
53 Blooblahguy-207965
local _, PlayerClass = UnitClass'player'
54 Blooblahguy-207965
 
55 Blooblahguy-207965
-- Holds the class specific stuff.
56 Blooblahguy-207965
local ClassPowerID, ClassPowerType
57 Blooblahguy-207965
local ClassPowerEnable, ClassPowerDisable
58 Blooblahguy-207965
local RequireSpec, RequireSpell
59 Blooblahguy-207965
 
60 Blooblahguy-207965
local UpdateTexture = function(element)
61 Blooblahguy-207965
        local red, green, blue, desaturated
62 Blooblahguy-207965
        if(PlayerClass == 'MONK') then
63 Blooblahguy-207965
                red, green, blue = 0, 1, .59
64 Blooblahguy-207965
                desaturated = true
65 Blooblahguy-207965
        elseif(PlayerClass == 'WARLOCK') then
66 Blooblahguy-207965
                red, green, blue = 1, .5, 1
67 Blooblahguy-207965
                desaturated = true
68 Blooblahguy-207965
        elseif(PlayerClass == 'PRIEST') then
69 Blooblahguy-207965
                red, green, blue = 1, 1, 1
70 Blooblahguy-207965
        elseif(PlayerClass == 'PALADIN') then
71 Blooblahguy-207965
                red, green, blue = 1, .96, .41
72 Blooblahguy-207965
                desaturated = true
73 Blooblahguy-207965
        end
74 Blooblahguy-207965
 
75 Blooblahguy-207965
        for i = 1, #element do
76 Blooblahguy-207965
                local icon = element[i]
77 Blooblahguy-207965
                if(icon.SetDesaturated) then
78 Blooblahguy-207965
                        icon:SetDesaturated(desaturated)
79 Blooblahguy-207965
                end
80 Blooblahguy-207965
 
81 Blooblahguy-207965
                icon:SetVertexColor(red, green, blue)
82 Blooblahguy-207965
        end
83 Blooblahguy-207965
end
84 Blooblahguy-207965
 
85 Blooblahguy-207965
local Update = function(self, event, unit, powerType)
86 Blooblahguy-207965
        if(unit ~= 'player' or powerType ~= ClassPowerType) then
87 Blooblahguy-207965
                return
88 Blooblahguy-207965
        end
89 Blooblahguy-207965
 
90 Blooblahguy-207965
        local element = self.ClassIcons
91 Blooblahguy-207965
 
92 Blooblahguy-207965
        --[[ :PreUpdate()
93 Blooblahguy-207965
 
94 Blooblahguy-207965
         Called before the element has been updated
95 Blooblahguy-207965
 
96 Blooblahguy-207965
         Arguments
97 Blooblahguy-207965
 
98 Blooblahguy-207965
         self  - The ClassIcons element
99 Blooblahguy-207965
         event - The event, that the update is being triggered for
100 Blooblahguy-207965
        ]]
101 Blooblahguy-207965
        if(element.PreUpdate) then
102 Blooblahguy-207965
                element:PreUpdate(event)
103 Blooblahguy-207965
        end
104 Blooblahguy-207965
 
105 Blooblahguy-207965
        local cur, max, oldMax
106 Blooblahguy-207965
        if(event ~= 'ClassPowerDisable') then
107 Blooblahguy-207965
                cur = UnitPower('player', ClassPowerID)
108 Blooblahguy-207965
                max = UnitPowerMax('player', ClassPowerID)
109 Blooblahguy-207965
 
110 Blooblahguy-207965
                for i = 1, max do
111 Blooblahguy-207965
                        if(i <= cur) then
112 Blooblahguy-207965
                                element[i]:Show()
113 Blooblahguy-207965
                        else
114 Blooblahguy-207965
                                element[i]:Hide()
115 Blooblahguy-207965
                        end
116 Blooblahguy-207965
                end
117 Blooblahguy-207965
 
118 Blooblahguy-207965
                oldMax = element.__max
119 Blooblahguy-207965
                if(max ~= oldMax) then
120 Blooblahguy-207965
                        if(max < oldMax) then
121 Blooblahguy-207965
                                for i = max + 1, oldMax do
122 Blooblahguy-207965
                                        element[i]:Hide()
123 Blooblahguy-207965
                                end
124 Blooblahguy-207965
                        end
125 Blooblahguy-207965
 
126 Blooblahguy-207965
                        element.__max = max
127 Blooblahguy-207965
                end
128 Blooblahguy-207965
        end
129 Blooblahguy-207965
        --[[ :PostUpdate(cur, max, hasMaxChanged, event)
130 Blooblahguy-207965
 
131 Blooblahguy-207965
         Called after the element has been updated
132 Blooblahguy-207965
 
133 Blooblahguy-207965
         Arguments
134 Blooblahguy-207965
 
135 Blooblahguy-207965
         self          - The ClassIcons element
136 Blooblahguy-207965
         cur           - The current amount of power
137 Blooblahguy-207965
         max           - The maximum amount of power
138 Blooblahguy-207965
         hasMaxChanged - Shows if the maximum amount has changed since the last
139 Blooblahguy-207965
                         update
140 Blooblahguy-207965
         event         - The event, which the update happened for
141 Blooblahguy-207965
        ]]
142 Blooblahguy-207965
        if(element.PostUpdate) then
143 Blooblahguy-207965
                return element:PostUpdate(cur, max, oldMax ~= max, event)
144 Blooblahguy-207965
        end
145 Blooblahguy-207965
end
146 Blooblahguy-207965
 
147 Blooblahguy-207965
local function Visibility(self, event, unit)
148 Blooblahguy-207965
        local element = self.ClassIcons
149 Blooblahguy-207965
        local shouldEnable
150 Blooblahguy-207965
 
151 Blooblahguy-207965
        if(not UnitHasVehicleUI('player')) then
152 Blooblahguy-207965
                if(not RequireSpec or RequireSpec == GetSpecialization()) then
153 Blooblahguy-207965
                        if(not RequireSpell or IsPlayerSpell(RequireSpell)) then
154 Blooblahguy-207965
                                self:UnregisterEvent('SPELLS_CHANGED', Visibility)
155 Blooblahguy-207965
                                shouldEnable = true
156 Blooblahguy-207965
                        else
157 Blooblahguy-207965
                                self:RegisterEvent('SPELLS_CHANGED', Visibility, true)
158 Blooblahguy-207965
                        end
159 Blooblahguy-207965
                end
160 Blooblahguy-207965
        end
161 Blooblahguy-207965
 
162 Blooblahguy-207965
        local isEnabled = element.isEnabled
163 Blooblahguy-207965
        if(shouldEnable and not isEnabled) then
164 Blooblahguy-207965
                ClassPowerEnable(self)
165 Blooblahguy-207965
        elseif(not shouldEnable and (isEnabled or isEnabled == nil)) then
166 Blooblahguy-207965
                ClassPowerDisable(self)
167 Blooblahguy-207965
        end
168 Blooblahguy-207965
end
169 Blooblahguy-207965
 
170 Blooblahguy-207965
local Path = function(self, ...)
171 Blooblahguy-207965
        return (self.ClassIcons.Override or Update) (self, ...)
172 Blooblahguy-207965
end
173 Blooblahguy-207965
 
174 Blooblahguy-207965
local VisibilityPath = function(self, ...)
175 Blooblahguy-207965
        return (self.ClassIcons.OverrideVisibility or Visibility) (self, ...)
176 Blooblahguy-207965
end
177 Blooblahguy-207965
 
178 Blooblahguy-207965
local ForceUpdate = function(element)
179 Blooblahguy-207965
        return VisibilityPath(element.__owner, 'ForceUpdate', element.__owner.unit)
180 Blooblahguy-207965
end
181 Blooblahguy-207965
 
182 Blooblahguy-207965
do
183 Blooblahguy-207965
        ClassPowerEnable = function(self)
184 Blooblahguy-207965
                self:RegisterEvent('UNIT_DISPLAYPOWER', Path)
185 Blooblahguy-207965
                self:RegisterEvent('UNIT_POWER_FREQUENT', Path)
186 Blooblahguy-207965
                Path(self, 'ClassPowerEnable', 'player', ClassPowerType)
187 Blooblahguy-207965
                self.ClassIcons.isEnabled = true
188 Blooblahguy-207965
        end
189 Blooblahguy-207965
 
190 Blooblahguy-207965
        ClassPowerDisable = function(self)
191 Blooblahguy-207965
                self:UnregisterEvent('UNIT_DISPLAYPOWER', Path)
192 Blooblahguy-207965
                self:UnregisterEvent('UNIT_POWER_FREQUENT', Path)
193 Blooblahguy-207965
 
194 Blooblahguy-207965
                local element = self.ClassIcons
195 Blooblahguy-207965
                for i = 1, #element do
196 Blooblahguy-207965
                        element[i]:Hide()
197 Blooblahguy-207965
                end
198 Blooblahguy-207965
 
199 Blooblahguy-207965
                Path(self, 'ClassPowerDisable', 'player', ClassPowerType)
200 Blooblahguy-207965
                self.ClassIcons.isEnabled = false
201 Blooblahguy-207965
        end
202 Blooblahguy-207965
 
203 Blooblahguy-207965
        if(PlayerClass == 'MONK') then
204 Blooblahguy-207965
                ClassPowerID = SPELL_POWER_CHI
205 Blooblahguy-207965
                ClassPowerType = "CHI"
206 Blooblahguy-207965
        elseif(PlayerClass == 'PALADIN') then
207 Blooblahguy-207965
                ClassPowerID = SPELL_POWER_HOLY_POWER
208 Blooblahguy-207965
                ClassPowerType = "HOLY_POWER"
209 Blooblahguy-207965
                RequireSpell = 85673 -- Word of Glory
210 Blooblahguy-207965
        elseif(PlayerClass == 'PRIEST') then
211 Blooblahguy-207965
                ClassPowerID = SPELL_POWER_SHADOW_ORBS
212 Blooblahguy-207965
                ClassPowerType = "SHADOW_ORBS"
213 Blooblahguy-207965
                RequireSpec = SPEC_PRIEST_SHADOW
214 Blooblahguy-207965
                RequireSpell = 95740 -- Shadow Orbs
215 Blooblahguy-207965
        elseif(PlayerClass == 'WARLOCK') then
216 Blooblahguy-207965
                ClassPowerID = SPELL_POWER_SOUL_SHARDS
217 Blooblahguy-207965
                ClassPowerType = "SOUL_SHARDS"
218 Blooblahguy-207965
                RequireSpec = SPEC_WARLOCK_AFFLICTION
219 Blooblahguy-207965
                RequireSpell = WARLOCK_SOULBURN
220 Blooblahguy-207965
        end
221 Blooblahguy-207965
end
222 Blooblahguy-207965
 
223 Blooblahguy-207965
local Enable = function(self, unit)
224 Blooblahguy-207965
        if(unit ~= 'player' or not ClassPowerID) then return end
225 Blooblahguy-207965
 
226 Blooblahguy-207965
        local element = self.ClassIcons
227 Blooblahguy-207965
        if(not element) then return end
228 Blooblahguy-207965
 
229 Blooblahguy-207965
        element.__owner = self
230 Blooblahguy-207965
        element.__max = #element
231 Blooblahguy-207965
        element.ForceUpdate = ForceUpdate
232 Blooblahguy-207965
 
233 Blooblahguy-207965
        if(RequireSpec) then
234 Blooblahguy-207965
                self:RegisterEvent('PLAYER_TALENT_UPDATE', VisibilityPath, true)
235 Blooblahguy-207965
        end
236 Blooblahguy-207965
 
237 Blooblahguy-207965
        element.ClassPowerEnable = ClassPowerEnable
238 Blooblahguy-207965
        element.ClassPowerDisable = ClassPowerDisable
239 Blooblahguy-207965
 
240 Blooblahguy-207965
        for i = 1, #element do
241 Blooblahguy-207965
                local icon = element[i]
242 Blooblahguy-207965
                if(icon:IsObjectType'Texture' and not icon:GetTexture()) then
243 Blooblahguy-207965
                        icon:SetTexCoord(0.45703125, 0.60546875, 0.44531250, 0.73437500)
244 Blooblahguy-207965
                        icon:SetTexture([[Interface\PlayerFrame\Priest-ShadowUI]])
245 Blooblahguy-207965
                end
246 Blooblahguy-207965
        end
247 Blooblahguy-207965
 
248 Blooblahguy-207965
        (element.UpdateTexture or UpdateTexture) (element)
249 Blooblahguy-207965
 
250 Blooblahguy-207965
        return true
251 Blooblahguy-207965
end
252 Blooblahguy-207965
 
253 Blooblahguy-207965
local Disable = function(self)
254 Blooblahguy-207965
        local element = self.ClassIcons
255 Blooblahguy-207965
        if(not element) then return end
256 Blooblahguy-207965
 
257 Blooblahguy-207965
        ClassPowerDisable(self)
258 Blooblahguy-207965
end
259 Blooblahguy-207965
 
260 Blooblahguy-207965
oUF:AddElement('ClassIcons', VisibilityPath, Enable, Disable)