vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 local AceOO = AceLibrary("AceOO-2.0")
2 local L = AceLibrary("AceLocale-2.0"):new("ag_UnitFrames")
3  
4 local print = function(msg) if msg then DEFAULT_CHAT_FRAME:AddMessage(msg) end end
5  
6 -- UNIT CLASS
7  
8 ---- init
9 ---- CreateFrame (creates the unit frame)
10 ---- LoadPosition (loads frame position from DB)
11 ---- ApplyTheme (reads and applies theme from ag_Themes.lua)
12 ---- BorderBackground (sets a border and a background for the unit frame)
13  
14 ---- UpdateAll (calls all update methods for the unit)
15 ---- UpdateName (updates the name string)
16 ---- UpdateClass (updates the class string)
17 ---- UpdateHealth (updates the health bar)
18 ---- UpdatePower (updates the mana bar)
19  
20 ---- OnDragStop
21 ---- OnDragStart
22  
23 aUF.classes = {}
24 aUF.classes.aUFunit = AceOO.Class("AceEvent-2.0","AceHook-2.0")
25 aUF.classes.aUFunitXP = AceOO.Class(aUF.classes.aUFunit)
26 aUF.classes.aUFunitCombo = AceOO.Class(aUF.classes.aUFunit)
27 aUF.classes.aUFunitMetro = AceOO.Class(aUF.classes.aUFunit)
28 aUF.classes.aUFunitRaid = AceOO.Class(aUF.classes.aUFunit)
29  
30 aUF.hooks = {}
31  
32 function aUF.hooks.hookShowHide(frame)
33 local show, hide = frame.Show, frame.Hide;
34 frame.Show = function(self)
35 if (not self.isVisibleFlag) then
36 show(self);
37 self.isVisibleFlag = true;
38 end
39 end
40 frame.Hide = function(self)
41 if (self.isVisibleFlag) then
42 hide(self);
43 self.isVisibleFlag = false;
44 end
45 end
46 frame.WillHide = function(self)
47 self.doShow = false;
48 end
49 frame.WillShow = function(self)
50 self.doShow = true;
51 end
52 frame.DoShowHide = function(self)
53 if (self.doShow) then self:Show() else self:Hide() end
54 end
55  
56 frame:Show()
57 end
58  
59 --[[function aUF.hooks.hookSetText(frame)
60 local settext = frame.SetText
61 frame.SetText = function(self, text)
62 if (self.lasttext ~= text) then
63 self.lasttext = text
64 settext(self, text)
65 end
66 end
67 end]]
68  
69 function aUF.hooks.hookSetTexture(frame)
70 local settexture = frame.SetTexture
71 frame.SetTexture = function(self, texture)
72 if (self.lasttexture ~= texture) then
73 self.lasttexture = texture
74 settexture(self, texture)
75 end
76 end
77 end
78  
79 --[[function aUF.hooks.hookSetVertexColor(frame)
80 local setvertexcolor = frame.SetVertexColor;
81 frame.SetVertexColor = function(self, r, g, b)
82 if (self.lastr ~= r or self.lastg ~= g or self.lastb ~= b) then
83 self.lastr, self.lastg, self.lastb = r, g, b
84 setvertexcolor(self, r, g, b)
85 end
86 end
87 end]]
88  
89 function aUF.classes.aUFunit.prototype:init(name,unit,db)
90 aUF.classes.aUFunit.super.prototype.init(self)
91  
92 self.name = name
93 self:CreateFrame()
94 self:Reset(unit,db)
95 self.eventsRegistered = false
96 self:RegisterEvents(true)
97 end
98  
99 function aUF.classes.aUFunit.prototype:Reset(unit,db)
100 if unit then
101 self.unit = unit
102 if not db then
103 self.type = string.gsub(unit, "%d", "")
104 else
105 self.type = db
106 end
107 _,_,self.number = string.find(unit, "(%d+)")
108 if not self.number then
109 self.number = 1
110 end
111 if string.find(unit,"pet") then
112 if self.type == "partypet" or self.type == "raidpet" then
113 self.parent = string.gsub(unit,"pet","")
114 else
115 self.parent = "player"
116 end
117 end
118 end
119 self.flags = {}
120 self.aCount = 0
121 self.database = aUF.db.profile[self.type]
122 self:LoadScale()
123 self:LoadPosition()
124 self:ApplyTheme()
125 self:BorderBackground()
126 self:BarTexture()
127 self:StatusBarsColor()
128 self:UpdateAll()
129 end
130  
131 function aUF.classes.aUFunit.prototype:RegisterEvents(allEvents,unregister)
132 if not unregister and self.eventsRegistered == false then
133 if self.unit == "player" or self.unit == "target" then
134 self:RegisterEvent("UNIT_HEALTH", "UpdateHealth")
135 self:RegisterEvent("UNIT_MANA", "UpdatePower")
136 self:RegisterEvent("UNIT_RAGE", "UpdatePower")
137 self:RegisterEvent("UNIT_FOCUS", "UpdatePower")
138 self:RegisterEvent("UNIT_ENERGY", "UpdatePower")
139 else
140 self:RegisterBucketEvent("UNIT_HEALTH",0.3, "UpdateHealth")
141 self:RegisterBucketEvent({"UNIT_MANA","UNIT_RAGE","UNIT_FOCUS","UNIT_ENERGY"},0.5, "UpdatePower")
142 end
143 self:RegisterEvent("UNIT_AURA", "UpdateAuras")
144 self:RegisterEvent("UNIT_COMBAT","UnitCombat")
145 self:RegisterEvent("UNIT_SPELLMISS","UnitSpellmiss")
146 self:RegisterEvent("UNIT_LEVEL", "UpdateTextStrings")
147 self:RegisterEvent("UNIT_NAME_UPDATE", "UpdateTextStrings")
148 self:RegisterEvent("UPDATE_FACTION", "UpdatePvP")
149 self:RegisterEvent("PLAYER_FLAGS_CHANGED", "UpdatePvP")
150 self:RegisterEvent("UNIT_FACTION", "UpdatePvP")
151 self:RegisterEvent("PARTY_LEADER_CHANGED", "LabelsCheckLeader")
152 self:RegisterEvent("PARTY_LOOT_METHOD_CHANGED", "LabelsCheckLoot")
153 self:RegisterEvent("RAID_TARGET_UPDATE", "UpdateRaidTargetIcon")
154  
155 -- Specific Events :(
156 if self.type == "player" then
157 self:RegisterEvent("PLAYER_REGEN_ENABLED", "UpdateInCombat")
158 self:RegisterEvent("PLAYER_REGEN_DISABLED", "UpdateInCombat")
159 self:RegisterEvent("PLAYER_UPDATE_RESTING", "UpdateResting")
160 else
161 if not self.inCombatSchedule then
162 self.inCombatSchedule = self:ScheduleRepeatingEvent(self.UpdateInCombat, 0.5, self)
163 end
164 end
165 if self.type == "partypet" or self.type == "pet" then
166 self:RegisterEvent("UNIT_PET","UpdatePetAll")
167 end
168  
169 if self.type == "pet" then
170 self:RegisterEvent("UNIT_HAPPINESS","StatusBarsColor")
171 end
172  
173 if allEvents == true then
174 self:RegisterEvent("PLAYER_TARGET_CHANGED","UpdateHighlight")
175 self:RegisterEvent("PARTY_MEMBERS_CHANGED","UpdateAll")
176 self:RegisterEvent("RAID_ROSTER_UPDATE","UpdateAll")
177 self:RegisterEvent("agUF_UpdateGroups", "UpdateVisibility")
178 end
179 self.eventsRegistered = true
180 elseif self.eventsRegistered == true and unregister then
181 local events = {
182 "UNIT_AURA", "UNIT_HEALTH", "UNIT_MANA", "UNIT_RAGE",
183 "UNIT_FOCUS", "UNIT_ENERGY", "UNIT_COMBAT", "UNIT_SPELLMISS",
184 "UNIT_LEVEL", "UNIT_NAME_UPDATE", "UPDATE_FACTION",
185 "PLAYER_FLAGS_CHANGED",
186 "PARTY_LEADER_CHANGED", "PARTY_LOOT_METHOD_CHANGED",
187 "PLAYER_REGEN_ENABLED", "PLAYER_REGEN_DISABLED",
188 "PLAYER_UPDATE_RESTING", "RAID_TARGET_UPDATE",
189 }
190 for k,v in pairs(events) do
191 if self:IsEventRegistered(v) then
192 self:UnregisterEvent(v)
193 end
194 end
195 if self.inCombatSchedule then
196 self:CancelScheduledEvent(self.inCombatSchedule)
197 self.inCombatSchedule = nil
198 end
199 self:UnregisterAllBucketEvents()
200 self.eventsRegistered = false
201 end
202 end
203  
204 function aUF.classes.aUFunit.prototype:CreateFrame()
205 local frameName = "aUF"..self.name
206 self.framename = frameName
207  
208 self.frame = CreateFrame("Button",frameName,UIParent,"AGUnitTemplate")
209 self.frame.name = self.name
210  
211 self.ClassText = getglobal(frameName.."_ClassText")
212 self.NameLabel = getglobal(frameName.."_NameLabel")
213 self.HitIndicator = getglobal(frameName.."_HitIndicator")
214 self.HealthBar_BG = getglobal(frameName.."_HealthBar_BG")
215 self.ManaBar_BG = getglobal(frameName.."_ManaBar_BG")
216 self.XPBar_BG = getglobal(frameName.."_XPBar_BG")
217 self.HealthBar = getglobal(frameName.."_HealthBar")
218 self.HealthBar:SetScript("OnValueChanged",function() self:StatusBarsOnValueChanged(arg1) end)
219 self.HealthBar:SetMinMaxValues(0,100)
220 self.ManaBar = getglobal(frameName.."_ManaBar")
221 self.ManaBar:SetMinMaxValues(0,100)
222 self.XPBar = getglobal(frameName.."_XPBar")
223 self.XPBar:SetMinMaxValues(0, 100)
224 self.HealthText = getglobal(frameName.."_HealthText")
225 self.ManaText = getglobal(frameName.."_ManaText")
226 self.StatusText = getglobal(frameName.."_StatusText")
227 self.Highlight = getglobal(frameName.."Highlight")
228 self.Highlight:SetAlpha(0.5)
229 self.DebuffHighlight = getglobal(frameName.."Debuff")
230 self.DebuffHighlight:SetAlpha(0.7)
231 self.RaidTargetIcon = getglobal(frameName.."_RaidTargetIcon")
232 self.InCombatIcon = getglobal(frameName.."_InCombatIcon")
233 self.PVPIcon = getglobal(frameName.."_PVPIcon")
234 self.LeaderIcon = getglobal(frameName.."_LeaderIcon")
235 self.MasterIcon = getglobal(frameName.."_MasterIcon")
236 self.frame:SetScript("OnEnter",function() self:OnEnter() end)
237 self.frame:SetScript("OnLeave",function() self:OnLeave() end)
238 self.frame:SetScript("OnDragStart",function() self:OnDragStart(arg1) end)
239 self.frame:SetScript("OnDragStop",function() self:OnDragStop(arg1) end)
240 self.frame:SetScript("OnClick",function() self:OnClick(arg1) end)
241 self.frame:SetScript("OnHide",function() this:StopMovingOrSizing() end)
242  
243 for i =1,20 do
244 self["Aura"..i] = getglobal(frameName.."_Aura"..i)
245 self["Aura"..i].Icon = getglobal(frameName.."_Aura"..i.."Icon")
246 self["Aura"..i].Overlay = getglobal(frameName.."_Aura"..i.."Overlay")
247 self["Aura"..i].Count = getglobal(frameName.."_Aura"..i.."Count")
248 self["Aura"..i]:SetScript("OnEnter",function() self:AuraOnEnter() end)
249 self["Aura"..i]:SetScript("OnLeave",function() GameTooltip:Hide() end)
250  
251 aUF.hooks.hookShowHide(self["Aura"..i])
252 aUF.hooks.hookSetTexture(self["Aura"..i].Icon)
253  
254 self["Aura"..i]:Hide()
255 end
256  
257 if string.find(self.name,"player") then
258 self.XPBar_Rest = CreateFrame("StatusBar",frameName.."_XPBar_Rest",self.frame)
259 self.XPBar_Rest:SetMinMaxValues(0, 100)
260 self.XPBar:SetParent(self.XPBar_Rest)
261 end
262  
263 if AceOO.inherits(self, aUF.classes.aUFunitCombo) then
264 self:CreateCombos()
265 end
266  
267 self.frame:SetMovable(true)
268 self.frame:EnableMouse(true)
269 self.frame:RegisterForDrag("LeftButton")
270 self.frame:RegisterForClicks("LeftButtonUp","RightButtonUp","MiddleButtonUp","Button4Up","Button5Up")
271 end
272  
273 function aUF.classes.aUFunit.prototype:LoadScale()
274 self.frame:SetScale(self.database.Scale)
275 if self.subgroup then
276 aUF.subgroups[self.subgroup]:LoadPosition()
277 aUF.subgroups[self.subgroup]:UpdateScale()
278 end
279 end
280  
281 function aUF.classes.aUFunit.prototype:LoadPosition()
282 if self.subgroup then return end
283 if(aUF.db.profile.Positions[self.unit]) then
284 local x = aUF.db.profile.Positions[self.unit].x
285 local y = aUF.db.profile.Positions[self.unit].y
286 local scale = self.frame:GetEffectiveScale()
287  
288 self.frame:SetPoint("TOPLEFT", UIParent,"TOPLEFT", x/scale, y/scale)
289 else
290 self.frame:SetPoint("CENTER", UIParent, "CENTER")
291 end
292 end
293  
294 function aUF.classes.aUFunit.prototype:SavePosition()
295 local scale = self.frame:GetEffectiveScale()
296 local worldscale = UIParent:GetEffectiveScale()
297  
298 local x,y = self.frame:GetLeft()*scale,self.frame:GetTop()*scale - (UIParent:GetTop())*worldscale
299 if not aUF.db.profile.Positions[self.unit] then
300 aUF.db.profile.Positions[self.unit] = {}
301 end
302  
303 aUF.db.profile.Positions[self.unit].x = x
304 aUF.db.profile.Positions[self.unit].y = y
305 end
306  
307 function aUF.classes.aUFunit.prototype:ApplyTheme()
308 local themetable = aUF.Layouts[self.database.FrameStyle]
309 if not themetable then return end
310  
311 local hiddens = {}
312  
313 local manabarhide = false
314 local xpbarhide = false
315 local height = 0
316 local width = 0
317  
318 if self.database.HideMana == true then
319 manabarhide = true
320 end
321  
322 if (self.unit ~= "player" and self.unit ~= "pet") or ((self.unit == "pet" or self.unit == "player") and self.database.ShowXP == false) then
323 xpbarhide = true
324 end
325  
326 self.flags.ResizableBar = themetable.ResizableBar
327 self.flags.BackgroundBarColor = themetable.BackgroundBarColor
328 self.flags.AlphaBar = themetable.AlphaBar
329 self.flags.RaidColorName = themetable.RaidColorName
330 self.flags.ThemeName = themetable.Name
331 self.flags.PetClassName = themetable.PetClassName
332 self.flags.HappinessBar = themetable.HappinessBar
333  
334 if self.unit == "target" then
335 if themetable.ComboGFX == true then
336 comboGFX = 1
337 else
338 comboGFX = 0
339 end
340 end
341  
342 height = themetable.ThemeData.all.FrameHeight
343 width = themetable.ThemeData.all.FrameWidth
344  
345 if themetable.ThemeData[self.type] then
346 if themetable.ThemeData[self.type].FrameHeight then
347 height = themetable.ThemeData[self.type].FrameHeight
348 end
349 if themetable.ThemeData[self.type].FrameWidth then
350 width = themetable.ThemeData[self.type].FrameWidth
351 end
352 end
353  
354 if manabarhide == true then
355 self.flags.RaidColorName = true
356 end
357  
358 for k,v in themetable.ThemeData.all do
359 if self[k] then self[k]:ClearAllPoints() end
360 end
361 local index = "all"
362 for j = 1,2 do
363 if j == 2 then
364 index = self.type
365 end
366 if themetable.ThemeData[index] then
367 for key, value in pairs(themetable.ThemeData[index]) do
368 if self[key] and value.Hidden ~= true and not (key == "ManaBar_BG" and manabarhide == true) and not (key == "XPBar_BG" and xpbarhide == true) and not hiddens[key] then
369  
370 if value.Hide then
371 hiddens[value.Hide] = true
372 end
373 if value.HeightAdd then
374 height = height + value.HeightAdd
375 end
376 if value.Width then
377 self[key]:SetWidth(value.Width)
378 end
379 if value.Height then
380 self[key]:SetHeight(value.Height)
381 end
382 if value.Font then
383 self[key]:SetFont(value.Font,value.FontSize)
384 end
385 local RelativeTo
386 if value.RelativeTo then
387 if themetable.ThemeData[index][value.RelativeTo] and (themetable.ThemeData[index][value.RelativeTo].Hidden == true or (value.RelativeTo == "ManaBar_BG" and manabarhide)) and value.RelativeToSecondary then
388 RelativeTo = self.framename.."_"..value.RelativeToSecondary
389 else
390 RelativeTo = self.framename.."_"..value.RelativeTo
391 end
392 else
393 RelativeTo = self.framename
394 end
395 if value.x and value.y and value.Point and value.RelativePoint then
396 local point
397 if themetable.ResizableBar == true and self.database.LongStatusbars == false and (key == "HealthText" or key == "ManaText") then
398 if value.Point == "RIGHT" then
399 point = "LEFT"
400 elseif value.Point == "LEFT" then
401 point = "RIGHT"
402 else
403 point = value.Point
404 end
405 else
406 point = value.Point
407 end
408 self[key]:SetPoint(point, RelativeTo, value.RelativePoint, value.x, value.y)
409 end
410 if value.Visibility then
411 for k, v in pairs(value.Visibility) do
412 if self[v] then
413 self[v]:Show()
414 end
415 end
416 end
417 if value.Justify then
418 self[key]:SetJustifyH(value.Justify)
419 end
420 elseif self[key] and (value.Hidden or (key == "ManaBar_BG" and manabarhide == true) or (key == "XPBar_BG" and xpbarhide == true) ) then
421 self[key]:Hide()
422 if value.Visibility then
423 for k, v in pairs(value.Visibility) do
424 if self[v] then
425 self[v]:Hide()
426 end
427 end
428 end
429 end
430 end
431 end
432 end
433  
434 for key,value in pairs(hiddens) do
435 self[key]:Hide()
436 end
437  
438 self.frame:SetHeight(height)
439 self.frame:SetWidth(100)
440 if self.widthAdd then
441 self.database.Width = width
442 end
443  
444 if self.flags.ResizableBar == true and self.database.LongStatusbars == false then
445 self.HealthBar_BG:SetWidth(self.HealthBar_BG:GetWidth() - self.HealthText:GetWidth())
446 self.ManaBar_BG:SetWidth(self.ManaBar_BG:GetWidth() - self.ManaText:GetWidth())
447 end
448  
449 self.widthAdd = 0
450 self:SetWidth()
451 end
452  
453 function aUF.classes.aUFunit.prototype:BorderBackground()
454 local colortable
455 local bordercolor = aUF.db.profile.FrameBorderColors
456 local borderstyle = aUF.db.profile.BorderStyle
457  
458 if self.unit == "target" then
459 colortable = aUF.db.profile.TargetFrameColors
460 else
461 colortable = aUF.db.profile.PartyFrameColors
462 end
463  
464 self.frame:SetBackdrop({
465 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
466 edgeFile = aUF.Borders[borderstyle].texture, edgeSize = aUF.Borders[borderstyle].size,
467 insets = {left = aUF.Borders[borderstyle].insets, right = aUF.Borders[borderstyle].insets, top = aUF.Borders[borderstyle].insets, bottom = aUF.Borders[borderstyle].insets},
468 })
469  
470 self.frame:SetBackdropColor(colortable.r,colortable.g,colortable.b,colortable.a)
471 self.frame:SetBackdropBorderColor(bordercolor.r,bordercolor.g,bordercolor.b,bordercolor.a)
472 end
473  
474 function aUF.classes.aUFunit.prototype:SetWidth()
475 local widthAdd = 100
476 if self.database.Width then widthAdd = self.database.Width end
477 if not self.widthAdd then self.widthAdd = 0 end
478 widthAdd = widthAdd - 100
479  
480 widthAdd = widthAdd - self.widthAdd
481 self.widthAdd = self.widthAdd + widthAdd
482  
483 self.frame:SetWidth(self.frame:GetWidth() + widthAdd)
484 self.HealthBar_BG:SetWidth(self.HealthBar_BG:GetWidth() + widthAdd)
485 self.ManaBar_BG:SetWidth(self.ManaBar_BG:GetWidth() + widthAdd)
486 self.XPBar_BG:SetWidth(self.XPBar_BG:GetWidth() + widthAdd)
487  
488 if self.XPBar_Rest then
489 self.XPBar_Rest:ClearAllPoints()
490 self.XPBar_Rest:SetPoint("LEFT",self.XPBar_BG,"LEFT")
491 self.XPBar_Rest:SetHeight(self.XPBar_BG:GetHeight())
492 self.XPBar_Rest:SetWidth(self.XPBar_BG:GetWidth())
493 end
494 if self.XPBar then
495 self.XPBar:ClearAllPoints()
496 self.XPBar:SetPoint("LEFT",self.XPBar_BG,"LEFT")
497 self.XPBar:SetHeight(self.XPBar_BG:GetHeight())
498 self.XPBar:SetWidth(self.XPBar_BG:GetWidth())
499 end
500 if self.HealthBar then
501 self.HealthBar:ClearAllPoints()
502 self.HealthBar:SetPoint("LEFT",self.HealthBar_BG,"LEFT")
503 self.HealthBar:SetHeight(self.HealthBar_BG:GetHeight())
504 self.HealthBar:SetWidth(self.HealthBar_BG:GetWidth())
505 end
506 if self.ManaBar then
507 self.ManaBar:ClearAllPoints()
508 self.ManaBar:SetPoint("LEFT",self.ManaBar_BG,"LEFT")
509 self.ManaBar:SetHeight(self.ManaBar_BG:GetHeight())
510 self.ManaBar:SetWidth(self.ManaBar_BG:GetWidth())
511 end
512 self.Highlight:SetHeight(self.frame:GetHeight()-10)
513 self.Highlight:SetWidth(self.frame:GetWidth()-10)
514 self.DebuffHighlight:SetHeight(self.frame:GetHeight()-10)
515 self.DebuffHighlight:SetWidth(self.frame:GetWidth()-10)
516  
517 if self.subgroup then
518 aUF.subgroups[self.subgroup]:UpdateWidth()
519 end
520  
521 self:AuraPosition()
522 end
523  
524 function aUF.classes.aUFunit.prototype:BarTexture()
525 local barstyle = aUF.db.profile.BarStyle
526  
527 self.HealthBar:SetStatusBarTexture(aUF.Bars[barstyle])
528 self.ManaBar:SetStatusBarTexture(aUF.Bars[barstyle])
529 self.XPBar:SetStatusBarTexture(aUF.Bars[barstyle])
530 if self.XPBar_Rest then
531 self.XPBar_Rest:SetStatusBarTexture(aUF.Bars[barstyle])
532 end
533 self.HealthBar_BG:SetTexture(aUF.Bars[barstyle])
534 self.ManaBar_BG:SetTexture(aUF.Bars[barstyle])
535 self.XPBar_BG:SetTexture(aUF.Bars[barstyle])
536 end
537  
538 -- CLASS UPDATES
539  
540 function aUF.classes.aUFunit.prototype:UpdateHighlight(entered)
541 if (UnitExists("target") and UnitName("target") == UnitName(self.unit) and not (string.find(self.unit,"target")) and aUF.db.profile.HighlightSelected == true) or (entered == true and aUF.db.profile.HighlightSelected == true) then
542 self.Highlight:Show()
543 else
544 self.Highlight:Hide()
545 end
546 end
547  
548 function aUF.classes.aUFunit.prototype:UpdatePetAll()
549 if arg1 ~= self.parent then return end
550 self:UpdateAll()
551 end
552  
553 function aUF.classes.aUFunit.prototype:UpdateAll()
554 if self:SetVisibility() then
555 self:GroupingUpdate()
556 self:StatusBarsColor()
557 self:UpdateHealth(true)
558 self:UpdatePower(true)
559 self:UpdatePvP(true)
560 self:UpdateAuras(true)
561 self:UpdateRaidTargetIcon(true)
562 self:UpdateResting()
563 self:UpdateInCombat()
564 self:LabelsCheckLeader()
565 self:UpdateHighlight()
566 self:UpdateTextStrings()
567 self:RegisterEvents()
568 return true
569 else
570 self:GroupingUpdate(true)
571 self:RegisterEvents(false,true)
572 return false
573 end
574 end
575  
576 function aUF.classes.aUFunit.prototype:GroupingUpdate(hide)
577 local oldGroup = self.subgroup
578  
579 if hide then
580 self.subgroup = nil
581 elseif string.find(self.type,"raid") then
582  
583 if aUF.db.profile.RaidGrouping == "byclass" then
584 _, _, _, _, _, self.subgroup = GetRaidRosterInfo(self.number)
585 elseif aUF.db.profile.RaidGrouping == "nogroup" then
586 self.subgroup = nil
587 elseif aUF.db.profile.RaidGrouping == "onebiggroup" then
588 self.subgroup = "Raid"
589 elseif aUF.db.profile.RaidGrouping == "byrole" then
590 local _,eClass = UnitClass(self.unit)
591 self.subgroup = "Raid"..(aUF.RaidRole[eClass] or "none")
592 else
593 _,_,self.subgroup = GetRaidRosterInfo(self.number)
594 end
595  
596 elseif self.type == "party" or self.type == "partypet" then
597  
598 if aUF.db.profile.PartyGrouping == "withoutplayer" then
599 self.subgroup = "partyParty"
600 elseif aUF.db.profile.PartyGrouping == "nogroup" then
601 self.subgroup = nil
602 else
603 self.subgroup = "partyPlayer"
604 end
605  
606 elseif self.type == "pet" then
607  
608 if aUF.db.profile.PetGrouping == "nogroup" then
609 self.subgroup = nil
610 else
611 self.subgroup = "partyPlayer"
612 end
613  
614 elseif self.type == "player" then
615  
616 self.subgroup = "partyPlayer"
617  
618 end
619  
620 if oldGroup ~= self.subgroup then
621 if oldGroup then
622 aUF.changedSubgroups[oldGroup] = true
623 if aUF.subgroups[oldGroup].group[self.type] and aUF.subgroups[oldGroup].group[self.type][self.name] then
624 aUF.subgroups[oldGroup].group[self.type][self.name] = nil
625 end
626 end
627  
628 if self.subgroup then
629 if not aUF.subgroups[self.subgroup] then
630 aUF.subgroups[self.subgroup] = aUF.classes.aUFgroup:new(self.subgroup)
631 end
632 if not aUF.subgroups[self.subgroup].group[self.type] then
633 aUF.subgroups[self.subgroup].group[self.type] = {}
634 end
635 aUF.subgroups[self.subgroup].group[self.type][self.name] = self
636 aUF.changedSubgroups[self.subgroup] = true
637 end
638  
639 self:ScheduleEvent("UpdateGroups", function() aUF:TriggerEvent("agUF_UpdateGroups") end, 0.1, self)
640 elseif self.subgroup then
641 self:UpdateVisibility()
642 end
643 if self.subgroup == nil then
644 self:LoadPosition()
645 self:UpdateVisibility()
646 end
647 end
648  
649 function aUF.classes.aUFunit.prototype:SetVisibility()
650 if aUF:CheckVisibility(self.unit) == true then
651 self.visible = true
652 return true
653 else
654 self.visible = false
655 return false
656 end
657 end
658  
659 function aUF.classes.aUFunit.prototype:UpdateVisibility()
660 if self.visible == true then
661 self.frame:Show()
662 else
663 self.frame:Hide()
664 end
665 end
666  
667 function aUF.classes.aUFunit.prototype:LabelsCheckLeader()
668 self.LeaderIcon:Hide()
669 if not ( self.type == "raid" or self.type == "party" or self.unit == "player") then return end
670 if aUF.db.profile.ShowGroupIcons == true then
671 if self.type == "raid" then
672 local _, rank = GetRaidRosterInfo(self.number)
673 if rank == 2 then
674 self.LeaderIcon:Show()
675 end
676 elseif self.type == "party" and tonumber(GetPartyLeaderIndex()) == tonumber(self.number) then
677 self.LeaderIcon:Show()
678 elseif self.unit == "player" and IsPartyLeader() then
679 self.LeaderIcon:Show()
680 end
681 end
682 end
683  
684 function aUF.classes.aUFunit.prototype:LabelsCheckLoot()
685 self.MasterIcon:Hide()
686 if not ( self.unit == "player" or self.type == "party") then return end
687 if aUF.db.profile.ShowGroupIcons == true then
688 local _, lootMaster = GetLootMethod()
689 if lootMaster then
690 if self.unit == "player" and lootMaster == 0 then
691 self.MasterIcon:Show()
692 elseif self.unit ~= "player" and lootMaster > 0 then
693 if lootMaster == self.number and not (string.find(self.unit,"pet")) then
694 self.MasterIcon:Show()
695 end
696 end
697 end
698 end
699 end
700  
701 function aUF.classes.aUFunit.prototype:UpdateRaidTargetIcon(byevent)
702 if type(byevent) == "string" and byevent ~= self.unit then return end
703  
704 local index = GetRaidTargetIndex(self.unit)
705 if ( index ) and aUF.db.profile[self.type].ShowRaidTargetIcon == true then
706 SetRaidTargetIconTexture(self.RaidTargetIcon, index)
707 self.RaidTargetIcon:Show()
708 else
709 self.RaidTargetIcon:Hide()
710 end
711 end
712  
713 function aUF.classes.aUFunit.prototype:UpdateInCombat()
714 if aUF.db.profile[self.type].ShowInCombatIcon == true and UnitAffectingCombat(self.unit) then
715 self.combat = true
716 -- print(self.unit)
717 else
718 self.combat = false
719 end
720 self:UpdateStatusIcon()
721 end
722  
723 function aUF.classes.aUFunit.prototype:UpdateResting()
724 if self.unit ~= "player" then return end
725 if IsResting() then
726 self.resting = true
727 else
728 self.resting = false
729 end
730 self:UpdateStatusIcon()
731 end
732  
733 function aUF.classes.aUFunit.prototype:UpdateStatusIcon()
734 if self.combat == true then
735 self.InCombatIcon:Show()
736 self.InCombatIcon:SetTexCoord(0.5,1,0,0.5)
737 elseif self.resting == true then
738 self.InCombatIcon:Show()
739 self.InCombatIcon:SetTexCoord(0,0.5,0,0.421875)
740 else
741 self.InCombatIcon:Hide()
742 end
743 end
744  
745 function aUF.classes.aUFunit.prototype:UpdatePvP(byevent)
746 if type(byevent) == "string" and byevent ~= self.unit then return end
747 if aUF.db.profile.ShowPvPIcon == true then
748 if ( UnitIsPVPFreeForAll(self.unit) ) then
749 self.PVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-FFA")
750 self.PVPIcon:Show()
751 elseif ( UnitFactionGroup(self.unit) and UnitIsPVP(self.unit) ) then
752 self.PVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-"..UnitFactionGroup(self.unit))
753 self.PVPIcon:Show()
754 else
755 self.PVPIcon:Hide()
756 end
757 else
758 self.PVPIcon:Hide()
759 end
760 end
761  
762 function aUF.classes.aUFunit.prototype:UpdateTextStrings()
763 if self.visible then
764 if aUF.HelperFunctions[self.type] then
765 if aUF.HelperFunctions[self.type].HealthText and self.HealthText:IsShown() then
766 aUF.HelperFunctions[self.type].HealthText(self.unit,self.HealthText)
767 end
768 if aUF.HelperFunctions[self.type].ManaText and self.ManaText:IsShown() then
769 aUF.HelperFunctions[self.type].ManaText(self.unit,self.ManaText)
770 end
771 if aUF.HelperFunctions[self.type].NameText and self.NameLabel:IsShown() then
772 aUF.HelperFunctions[self.type].NameText(self.unit,self.NameLabel)
773 end
774 if aUF.HelperFunctions[self.type].ClassText and self.ClassText:IsShown() then
775 aUF.HelperFunctions[self.type].ClassText(self.unit,self.ClassText)
776 end
777 end
778 end
779 end
780  
781 function aUF.classes.aUFunit.prototype:UpdateHealth(byevent)
782 if type(byevent) =="table" and not byevent[self.unit] then return end
783 local currValue,maxValue = UnitHealth(self.unit),UnitHealthMax(self.unit)
784 local perc = currValue/maxValue * 100
785  
786 if ( not UnitExists(self.unit) or UnitIsDead(self.unit) or UnitIsGhost(self.unit) or not UnitIsConnected(self.unit) or maxValue == 1) then
787 self.HealthBar:SetValue(0)
788 else
789 self.HealthBar:SetValue(perc)
790 end
791  
792 self:UpdateTextStrings()
793 end
794  
795 function aUF.classes.aUFunit.prototype:UpdatePower(byevent)
796 if type(byevent) =="table" and not byevent[self.unit] then return end
797 local currValue,maxValue = UnitMana(self.unit),UnitManaMax(self.unit)
798 local perc = currValue/maxValue * 100
799 local db = aUF.db.profile
800  
801 if ( not UnitExists(self.unit) or UnitIsDead(self.unit) or UnitIsGhost(self.unit) or not UnitIsConnected(self.unit) or (currValue == 1 and maxValue == 1) ) then
802 self.ManaBar:SetValue(0)
803 else
804 if maxValue == 0 then
805 self.ManaBar:SetValue(0)
806 else
807 self.ManaBar:SetValue(perc)
808 end
809 end
810  
811 local powertype = UnitPowerType(self.unit)
812 if (self.powertype ~= powertype) then
813 self.powertype = powertype
814  
815 local info = db.ManaColor[powertype]
816 if self.flags.AlphaBar == true then
817 self.ManaBar_BG:SetVertexColor(info.r,info.g,info.b,0.25)
818 else
819 self.ManaBar_BG:SetVertexColor(0,0,0,0.25)
820 end
821 self.ManaBar:SetStatusBarColor(info.r,info.g,info.b,0.8)
822 end
823 self:UpdateTextStrings()
824 end
825  
826 function aUF.classes.aUFunit.prototype:AuraPosition()
827 local scale = (self.frame:GetWidth()/170)
828 local style,position = self.database.AuraStyle,self.database.AuraPos
829 local yadjust = 0
830  
831 for i=1,20 do
832 self["Aura"..i]:SetScale(scale)
833 end
834  
835 if not (style == "OneLine") and (position == "Right" or position == "Left") then
836 yadjust = (self.Aura1:GetHeight()/2)
837 end
838  
839 self.Aura1:ClearAllPoints()
840  
841 if ( position == "Below" ) then
842 self.Aura1:SetPoint("TOPLEFT",self.frame,"BOTTOMLEFT",5, 0)
843 elseif ( position == "Above" ) then
844 self.Aura1:SetPoint("BOTTOMLEFT",self.frame,"TOPLEFT",5, 0)
845 elseif ( position == "Left" ) then
846 self.Aura1:SetPoint("RIGHT",self.frame,"LEFT",0, yadjust)
847 elseif ( position == "Right" ) then
848 self.Aura1:SetPoint("LEFT",self.frame,"RIGHT",0, yadjust)
849 end
850  
851 if ( position == "Left" ) then
852 for i=2,20 do
853 self["Aura"..i]:ClearAllPoints()
854 if i == 11 then
855 self["Aura"..i]:SetPoint("TOP",self.Aura1,"BOTTOM",0,-1)
856 else
857 self["Aura"..i]:SetPoint("RIGHT",self["Aura"..i-1],"LEFT",1,0)
858 end
859 end
860 else
861 for i=2,20 do
862 self["Aura"..i]:ClearAllPoints()
863 if i == 11 then
864 if position == "Above" then
865 self["Aura"..i]:SetPoint("BOTTOM",self.Aura1,"TOP",0,1)
866 else
867 self["Aura"..i]:SetPoint("TOP",self.Aura1,"BOTTOM",0,-1)
868 end
869 else
870 self["Aura"..i]:SetPoint("LEFT",self["Aura"..i-1],"RIGHT",1,0)
871 end
872 end
873 end
874 end
875  
876 function aUF.classes.aUFunit.prototype:UpdateAuras(byevent)
877 if type(byevent) == "string" and byevent ~= self.unit then return end
878  
879 if aUF.auraUpdates > 4 then
880 aUF.auraUpdatePool[self.name] = true
881 -- print(self.name.." add to pool")
882 return
883 else
884 -- print(self.name.." update "..aUF.auraUpdates)
885 aUF.auraUpdatePool[self.name] = nil
886 aUF.auraUpdates = aUF.auraUpdates + 1
887 end
888  
889 local filter,style,AuraDebuffC = self.database.AuraFilter,self.database.AuraStyle,self.database.AuraDebuffC
890 local dbcount,bcount,lastDebuff = 0,0,0
891 local buttons,dFound
892  
893 self.DebuffHighlight:Hide()
894 local hide = style == "Hide"
895  
896 for i=1,20 do
897 if (not self.hidden) then self["Aura"..i]:Hide() end
898 local debuff, _, t = aUF:UnitDebuff(self.unit,i,filter)
899 if debuff then
900 dbcount = dbcount + 1
901 lastDebuff = i
902 if not dFound then
903 if t and AuraDebuffC == true and UnitIsFriend("player",self.unit) then
904 self.DebuffHighlight:Show()
905 self.DebuffHighlight:SetVertexColor(DebuffTypeColor[t].r, DebuffTypeColor[t].g, DebuffTypeColor[t].b)
906 dFound = true
907 end
908 end
909 end
910 if UnitBuff(self.unit,i,filter) then
911 bcount = bcount + 1
912 end
913 end
914  
915 if hide or bcount + dbcount == 0 then
916 self.hidden = true
917 return
918 end
919 self.hidden = false
920  
921 local position = self.database.AuraPos
922  
923 if (position == "Above" or position == "Below") and bcount + dbcount <= 10 then
924 buttons = 10
925 elseif style == "OneLine" then
926 if (position == "Right" or position == "Left") and bcount + dbcount <= 10 then
927 buttons = bcount + dbcount
928 else
929 buttons = 10
930 end
931 else
932 buttons = 20
933 end
934  
935 local x,z,a,borderColor
936 local b = 1
937  
938 if (buttons > 10 and dbcount <= 10) then
939 x = 11
940 z = 1
941 a = 10
942 else
943 x = buttons
944 z = -1
945 a = bcount
946 end
947  
948 for i=1,max(lastDebuff,a) do
949 local buff, count, class = aUF:UnitDebuff(self.unit,i,filter)
950 local buffFrame = self["Aura"..x]
951 if buff and buffFrame then
952 buffFrame.Icon:SetTexture(buff)
953 buffFrame:Show()
954 buffFrame.buffFilter = "HARMFUL"
955 buffFrame.id = i
956 if count > 1 then
957 buffFrame.Count:SetText(count)
958 else
959 buffFrame.Count:SetText("")
960 end
961 if class then
962 borderColor = DebuffTypeColor[class]
963 else
964 borderColor = DebuffTypeColor["none"];
965 end
966 buffFrame.Overlay:SetVertexColor(borderColor.r, borderColor.g, borderColor.b);
967 buffFrame.Overlay:Show()
968 x = x + z
969 end
970 buff, count = UnitBuff(self.unit,i,filter)
971 buffFrame = self["Aura"..b]
972 if buff and b <= a then
973 buffFrame.Icon:SetTexture(buff)
974 buffFrame:Show()
975 buffFrame.buffFilter = "HELPFUL"
976 buffFrame.id = i
977 if count > 1 then
978 buffFrame.Count:SetText(count)
979 else
980 buffFrame.Count:SetText("")
981 end
982 buffFrame.Overlay:Hide()
983 b = b + 1
984 end
985 end
986 end
987  
988 -- STATUSBAR STUFF
989  
990 function aUF.classes.aUFunit.prototype:StatusBarsColor()
991 local db = aUF.db.profile
992 local healthColor
993 local _,Eclass = UnitClass(self.unit)
994  
995 if string.find(self.unit,"target") and not UnitIsFriend(self.unit, "player") and (aUF.db.profile.TargetShowHostile == true ) then
996 healthColor = aUF:UtilFactionColors(self.unit)
997 self.flags.BarColor = 1
998 elseif self.unit == "pet" and self.flags.HappinessBar == true and class ~= "WARLOCK" then
999 local happiness = GetPetHappiness()
1000 if ( happiness == 1 ) then
1001 healthColor = aUF.ManaColor[1]
1002 elseif ( happiness == 2 ) then
1003 healthColor = aUF.ManaColor[3]
1004 else
1005 healthColor = db.HealthColor
1006 end
1007 self.flags.BarColor = 2
1008 elseif UnitIsFriend(self.unit, "player") and UnitIsPlayer(self.unit) and self.database.ClassColorBars == true and RAID_CLASS_COLORS[Eclass] then
1009 healthColor = RAID_CLASS_COLORS[Eclass]
1010 self.flags.BarColor = 3
1011 else
1012 healthColor = db.HealthColor
1013 self.flags.BarColor = 4
1014 end
1015  
1016 self.HealthBar:SetStatusBarColor(healthColor.r,healthColor.g,healthColor.b, 1)
1017 if self.flags.BackgroundBarColor == true then
1018 self.HealthBar_BG:SetVertexColor(healthColor.r,healthColor.g,healthColor.b,0.25)
1019 else
1020 self.HealthBar_BG:SetVertexColor(0,0,0,0.25)
1021 end
1022  
1023 -- mana
1024 local powertype = UnitPowerType(self.unit)
1025 local info = db.ManaColor[powertype]
1026 if self.flags.AlphaBar == true then
1027 self.ManaBar_BG:SetVertexColor(info.r,info.g,info.b,0.25)
1028 else
1029 self.ManaBar_BG:SetVertexColor(0,0,0,0.25)
1030 end
1031 self.ManaBar:SetStatusBarColor(info.r,info.g,info.b,0.8)
1032 end
1033  
1034 function aUF.classes.aUFunit.prototype:StatusBarsOnValueChanged(value)
1035 if ( aUF.db.profile.SmoothHealthBars == true ) then
1036 if self.flags.BarColor == 1 then
1037 self:SmoothTargetHealthBarOnValueChanged(value,aUF:UtilFactionColors(self.unit))
1038 elseif self.flags.BarColor == 4 then
1039 self:SmoothHealthBarOnValueChanged(value)
1040 end
1041 end
1042 end
1043  
1044 function aUF.classes.aUFunit.prototype:SmoothTargetHealthBarOnValueChanged(value,colortable)
1045 if ( not value ) then
1046 return
1047 end
1048 local r, g, b
1049 local min, max = this:GetMinMaxValues()
1050 if ( (value < min) or (value > max) ) then
1051 return
1052 end
1053 if ( (max - min) > 0 ) then
1054 value = (value - min) / (max - min)
1055 else
1056 value = 0
1057 end
1058  
1059 r = colortable.r*(0.35*value+0.65)
1060 g = colortable.g*(0.35*value+0.65)
1061 b = colortable.b*(0.35*value+0.65)
1062 this:SetStatusBarColor(r, g, b)
1063 end
1064  
1065 function aUF.classes.aUFunit.prototype:SmoothHealthBarOnValueChanged(value)
1066 if ( not value ) then
1067 return
1068 end
1069 local db = aUF.db.profile
1070 local r, g, b
1071 local min, max = this:GetMinMaxValues()
1072 if ( (value < min) or (value > max) ) then
1073 return
1074 end
1075 if ( (max - min) > 0 ) then
1076 value = (value - min) / (max - min)
1077 else
1078 value = 0
1079 end
1080 if(value > 0.5) then
1081 r = (db.HealthColor.r) + (((1-value) * 2)* (1-(db.HealthColor.r)))
1082 g = db.HealthColor.g
1083 else
1084 r = 1.0
1085 g = (db.HealthColor.g) - (0.5 - value)* 2 * (db.HealthColor.g)
1086 end
1087 b = db.HealthColor.b
1088 this:SetStatusBarColor(r, g, b)
1089 end
1090  
1091 -- MOUSE INTERACTION
1092  
1093 function aUF.classes.aUFunit.prototype:OnDragStart(button)
1094 if self.subgroup then
1095 aUF.subgroups[self.subgroup]:OnDragStart(button)
1096 return
1097 end
1098 if ( button == "LeftButton" ) and aUF.db.profile.Locked == false then
1099 self.frame:StartMoving()
1100 end
1101 end
1102  
1103 function aUF.classes.aUFunit.prototype:OnDragStop(button)
1104 if self.subgroup then
1105 aUF.subgroups[self.subgroup]:OnDragStop(button)
1106 return
1107 end
1108 self.frame:StopMovingOrSizing()
1109 self:SavePosition()
1110 end
1111  
1112 function aUF.classes.aUFunit.prototype:OnClick(button)
1113 if (IsAltKeyDown() or IsControlKeyDown()) and (button == "LeftButton" or button == "RightButton") then
1114 aUF.dewdrop:Open(self.frame, 'children', aUF:CreateDewdrop(self.type),'cursorX', true, 'cursorY', true)
1115 return
1116 end
1117 if button == "LeftButton" then
1118 if SpellIsTargeting() then
1119 SpellTargetUnit(self.unit)
1120 elseif CursorHasItem() then
1121 if UnitIsUnit(self.unit, "player") then
1122 AutoEquipCursorItem()
1123 elseif UnitIsFriend(self.unit, "player") and UnitIsPlayer(self.unit) then
1124 DropItemOnUnit("target")
1125 end
1126 else
1127 TargetUnit(self.unit)
1128 end
1129 elseif button == "RightButton" then
1130 self:DropDownUnit(self.unit)
1131 end
1132 end
1133  
1134 function aUF.classes.aUFunit.prototype:OnEnter()
1135 self.frame.unit = self.unit
1136 self:UpdateHighlight(true)
1137 UnitFrame_OnEnter()
1138 end
1139  
1140 function aUF.classes.aUFunit.prototype:OnLeave()
1141 self:UpdateHighlight()
1142 UnitFrame_OnLeave()
1143 end
1144  
1145 function aUF.classes.aUFunit.prototype:DropDownUnit()
1146 local type = nil
1147  
1148 if self.unit == "player" then
1149 type = PlayerFrameDropDown
1150 elseif self.unit == "target" then
1151 type = TargetFrameDropDown
1152 elseif self.unit == "pet" then
1153 type = PetFrameDropDown
1154 elseif self.type == "party" then
1155 type = getglobal("PartyMemberFrame"..self.number.."DropDown")
1156 elseif string.find(self.unit, "raid") then
1157 type = FriendsDropDown
1158 this.unit = self.unit
1159 this.name = UnitName(self.unit)
1160 this.id = this:GetID()
1161 FriendsDropDown.displayMode = "MENU"
1162 FriendsDropDown.initialize = RaidFrameDropDown_Initialize
1163 end
1164  
1165 if self.number then this:SetID(self.number) end
1166  
1167 if type then
1168 HideDropDownMenu(1);
1169 type.unit = self.unit
1170 type.name = UnitName(self.unit)
1171 ToggleDropDownMenu(1, nil, type,"cursor")
1172 return true
1173 end
1174 end
1175  
1176 function aUF.classes.aUFunit.prototype:AuraOnEnter()
1177 if (not this:IsVisible()) then return end
1178 GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
1179 if ( this.buffFilter == "HELPFUL") then
1180 GameTooltip:SetUnitBuff(self.unit, this.id, self.database.AuraFilter)
1181 elseif ( this.buffFilter == "HARMFUL") then
1182 GameTooltip:SetUnitDebuff(self.unit, this.id, 0)
1183 end
1184 end
1185  
1186 function aUF.classes.aUFunit.prototype:UnitCombat(unit)
1187 if unit ~= self.unit then return end
1188 if not ( self.database.ShowCombat ) then return end
1189 self:CombatFeedback_OnCombatEvent(arg1, arg2, arg3, arg4, arg5)
1190 end
1191  
1192 function aUF.classes.aUFunit.prototype:UnitSpellmiss(unit)
1193 if unit ~= self.unit then return end
1194 if not ( self.database.ShowCombat ) then return end
1195 self:CombatFeedback_OnSpellMissEvent(arg1, arg2)
1196 end
1197  
1198 function aUF.classes.aUFunit.prototype:CombatFeedback_OnCombatEvent(unit, event, flags, amount, type)
1199 local fontHeight = 13
1200 local text = ""
1201 local r,g,b = 1,1,1
1202 if( event == "IMMUNE" ) then
1203 fontHeight = fontHeight * 0.75
1204 text = CombatFeedbackText[event]
1205 elseif ( event == "WOUND" ) then
1206 if ( amount ~= 0 ) then
1207 if ( flags == "CRITICAL" or flags == "CRUSHING" ) then
1208 fontHeight = fontHeight * 1.5
1209 elseif ( flags == "GLANCING" ) then
1210 fontHeight = fontHeight * 0.75
1211 end
1212 if ( type > 0 ) then
1213 r = 1.0
1214 g = 1.0
1215 b = 0.0
1216 end
1217 if UnitInParty(self.unit) or UnitInRaid(self.unit) then
1218 r = 1.0
1219 g = 0.0
1220 b = 0.0
1221 end
1222 text = "-"..amount
1223 elseif ( flags == "ABSORB" ) then
1224 fontHeight = fontHeight * 0.75
1225 text = CombatFeedbackText["ABSORB"]
1226 elseif ( flags == "BLOCK" ) then
1227 fontHeight = fontHeight * 0.75
1228 text = CombatFeedbackText["BLOCK"]
1229 elseif ( flags == "RESIST" ) then
1230 fontHeight = fontHeight * 0.75
1231 text = CombatFeedbackText["RESIST"]
1232 else
1233 text = CombatFeedbackText["MISS"]
1234 end
1235 elseif ( event == "BLOCK" ) then
1236 fontHeight = fontHeight * 0.75
1237 text = CombatFeedbackText[event]
1238 elseif ( event == "HEAL" ) then
1239 text = "+"..amount
1240 r = 0.0
1241 g = 1.0
1242 b = 0.0
1243 if ( flags == "CRITICAL" ) then
1244 fontHeight = fontHeight * 1.3
1245 end
1246 elseif ( event == "ENERGIZE" ) then
1247 text = amount
1248 r = 0.41
1249 g = 0.8
1250 b = 0.94
1251 if ( flags == "CRITICAL" ) then
1252 fontHeight = fontHeight * 1.3
1253 end
1254 else
1255 text = CombatFeedbackText[event]
1256 end
1257  
1258 self.feedbackStartTime = GetTime()
1259  
1260 local font = self.HitIndicator:GetFont()
1261 self.HitIndicator:SetFont(font,fontHeight,"OUTLINE")
1262 self.HitIndicator:SetText(text)
1263 self.HitIndicator:SetTextColor(r, g, b)
1264 self.HitIndicator:SetAlpha(0)
1265 self.HitIndicator:Show()
1266 self.HitIndicator:SetPoint("CENTER",self.frame,"CENTER")
1267  
1268 aUF.feedback[self.name] = true
1269 aUF:ScheduleRepeatingEvent("agUF_CombatSchedule",aUF.FeedbackUpdate, 0.05, aUF)
1270 end
1271  
1272 -- UNITXP CLASS
1273  
1274 function aUF.classes.aUFunitXP.prototype:init(name,unit)
1275 aUF.classes.aUFunitXP.super.prototype.init(self,name,unit)
1276 self:RegisterXPEvents()
1277 self:UpdateXP()
1278 self:UpdateRep()
1279 end
1280  
1281 function aUF.classes.aUFunitXP.prototype:RegisterXPEvents()
1282 if self.unit == "player" then
1283 self:RegisterEvent("PLAYER_XP_UPDATE","UpdateXP")
1284 self:RegisterEvent("UPDATE_EXHAUSTION","UpdateXP")
1285 self:RegisterEvent("PLAYER_LEVEL_UP","UpdateXP")
1286 elseif self.unit == "pet" then
1287 self:RegisterEvent("UNIT_PET_EXPERIENCE","UpdateXP")
1288 end
1289 end
1290  
1291 function aUF.classes.aUFunitXP.prototype:UpdateRep(newLevel)
1292 if self.hooks["ReputationWatchBar_Update"] then
1293 self.hooks["ReputationWatchBar_Update"].orig(tonumber(newLevel))
1294 else
1295 self:Hook("ReputationWatchBar_Update", "UpdateRep")
1296 end
1297 local repname, repreaction, repmin, repmax, repvalue = GetWatchedFactionInfo()
1298 if ( repname and UnitLevel("player") == 60) then
1299 local color = aUF.RepColor[repreaction]
1300 repmax = repmax - repmin;
1301 repvalue = repvalue - repmin;
1302 repmin = 0
1303  
1304 if self.XPBar_Rest or repmax == 0 then
1305 self.XPBar_Rest:Hide()
1306 end
1307  
1308 self.XPBar:SetParent(self.frame)
1309 self.XPBar:Show()
1310 if repmax ~= 0 then
1311 self.XPBar:SetValue((repvalue/repmax)*100)
1312 else
1313 self.XPBar:SetValue(0)
1314 end
1315 self.XPBar:SetStatusBarColor(color.r, color.g, color.b)
1316 self.XPBar_BG:SetVertexColor(color.r, color.g, color.b, 0.25)
1317 end
1318 self:UpdateXP()
1319 end
1320  
1321 function aUF.classes.aUFunitXP.prototype:UpdateXP()
1322 local _,eClass = UnitClass("player")
1323 if self.unit == "pet" and eClass == "HUNTER" then
1324 return
1325 end
1326 local repname, repreaction, repmin, repmax, repvalue = GetWatchedFactionInfo();
1327 if ( self.database.ShowXP == true ) then
1328 if ((( UnitLevel("player") < MAX_PLAYER_LEVEL ) or not repname) and self.unit == "player") or (self.unit == "pet") then
1329 local priorXP = self.XPBar:GetValue()
1330 local restXP
1331 local currXP, nextXP
1332  
1333 if self.unit == "player" then
1334 self.XPBar:SetParent(self.XPBar_Rest)
1335 currXP = UnitXP(self.unit)
1336 nextXP = UnitXPMax(self.unit)
1337 restXP = GetXPExhaustion()
1338 else
1339 currXP, nextXP = GetPetExperience()
1340 end
1341  
1342 if nextXP ~= 0 then
1343 self.XPBar:SetValue((currXP/nextXP)*100)
1344 else
1345 self.XPBar:SetValue(0)
1346 end
1347  
1348 if self.XPBar_Rest then
1349 if ( restXP and self.unit == "player" ) then
1350 self.XPBar_Rest:Show()
1351 if nextXP ~= 0 then
1352 self.XPBar_Rest:SetValue(((currXP+restXP)/nextXP)*100)
1353 else
1354 self.XPBar_Rest:SetValue(0)
1355 end
1356 else
1357 self.XPBar:SetParent(self.frame)
1358 self.XPBar:Show()
1359 self.XPBar_Rest:Hide()
1360 end
1361 end
1362  
1363 self.XPBar:SetStatusBarColor(0.8, 0, 0.7)
1364 if self.flags.BackgroundBarColor == true then
1365 self.XPBar_BG:SetVertexColor(0.8, 0, 0.7, 0.25)
1366 else
1367 self.XPBar_BG:SetVertexColor(0, 0, 0, 0.25)
1368 end
1369 end
1370 else
1371 self.XPBar:Hide()
1372 self.XPBar_BG:Hide()
1373 if self.XPBar_Rest then
1374 self.XPBar_Rest:Hide()
1375 end
1376 end
1377 end
1378  
1379 function aUF.classes.aUFunitCombo.prototype:init(name,unit)
1380 aUF.classes.aUFunitCombo.super.prototype.init(self,name,unit)
1381 self:RegisterComboEvents()
1382 end
1383  
1384 function aUF.classes.aUFunitCombo.prototype:RegisterComboEvents()
1385 self:RegisterEvent("PLAYER_COMBO_POINTS","UpdateComboPoints")
1386 end
1387  
1388 function aUF.classes.aUFunitCombo.prototype:CreateCombos()
1389 for i=1,5 do
1390 self["Combo"..i] = self.frame:CreateTexture(nil,"OVERLAY")
1391 self["Combo"..i]:SetTexture(aUF.imagePath.."combo.tga")
1392 self["Combo"..i]:SetHeight(10)
1393 self["Combo"..i]:SetWidth(10)
1394 self["Combo"..i]:Hide()
1395 if i > 1 then
1396 self["Combo"..i]:SetPoint("BOTTOMRIGHT",self["Combo"..i-1],"BOTTOMLEFT")
1397 end
1398 end
1399 end
1400  
1401 function aUF.classes.aUFunitCombo.prototype:UpdateComboPoints()
1402 local points = GetComboPoints()
1403 for i=0,4 do
1404 if points > i then
1405 self["Combo"..i+1]:Show()
1406 else
1407 self["Combo"..i+1]:Hide()
1408 end
1409 end
1410 end
1411  
1412 function aUF.classes.aUFunitMetro.prototype:init(name,unit)
1413 aUF.classes.aUFunitMetro.super.prototype.init(self,name,unit)
1414 end
1415  
1416 function aUF.classes.aUFunitMetro.prototype:UpdateMetro()
1417 if self:SetVisibility() then
1418 self:UpdateHealth(true)
1419 self:UpdatePower(true)
1420 self:UpdateAuras(true)
1421 self:UpdateRaidTargetIcon(true)
1422 self:StatusBarsColor()
1423 self:UpdateTextStrings()
1424 end
1425 self:UpdateVisibility()
1426 end
1427  
1428 function aUF.classes.aUFunitMetro.prototype:Start()
1429 if not self.database.HideFrame == true then
1430 self:UpdateMetro()
1431 if not self.schedule then
1432 self.schedule = self:ScheduleRepeatingEvent(self.UpdateMetro, 0.8, self)
1433 end
1434 end
1435 end
1436  
1437 function aUF.classes.aUFunitMetro.prototype:Stop()
1438 if self.schedule and self:IsEventScheduled(self.schedule) then
1439 self:CancelScheduledEvent(self.schedule)
1440 self.schedule = nil
1441 end
1442 self:UpdateMetro()
1443 end
1444  
1445 -- UNITRAID CLASS
1446  
1447 function aUF.classes.aUFunitRaid.prototype:init(name,unit)
1448 aUF.classes.aUFunitRaid.super.prototype.init(self,name,unit)
1449 self:RegisterEvent("RAID_ROSTER_UPDATE","RosterUpdate")
1450 self:RosterUpdate()
1451 end
1452  
1453 function aUF.classes.aUFunitRaid.prototype:RosterUpdate()
1454 if aUF:CheckVisibility(self.unit) then
1455 self.inRaid = true
1456 end
1457 if self.inRaid == true then
1458 if self:UpdateAll() == true then
1459 self.inRaid = true
1460 else
1461 self.inRaid = false
1462 end
1463 end
1464 end
1465  
1466  
1467 -- Group class
1468  
1469 aUF.classes.aUFgroup = AceOO.Class("AceEvent-2.0","AceHook-2.0")
1470  
1471 function aUF.classes.aUFgroup.prototype:init(objectName)
1472 aUF.classes.aUFgroup.super.prototype.init(self)
1473  
1474 self.name = objectName
1475 self.variableName = self.name.."_aUFgroup"
1476 self.index = {}
1477 self.group = {}
1478 self.raid = true
1479  
1480 self:CreateFrame()
1481 self:BorderBackground()
1482 self:UpdateTitle()
1483 end
1484  
1485 function aUF.classes.aUFgroup.prototype:CreateFrame()
1486 local frameName = "aUFgroup"..self.name
1487 self.anchor = CreateFrame("Button",frameName,UIParent,"AGraidAnchorTemplate")
1488 self.anchor:SetScript("OnDragStart",function() self:OnDragStart(arg1) end)
1489 self.anchor:SetScript("OnDragStop",function() self:OnDragStop(arg1) end)
1490 self.anchor:SetScript("OnClick",function() self:OnClick(arg1) end)
1491 self.anchor:SetMovable(true)
1492 self.anchor:EnableMouse(true)
1493 self.anchor:RegisterForDrag("LeftButton")
1494 self.anchor:RegisterForClicks("LeftButtonUp","RightButtonUp","MiddleButtonUp","Button4Up","Button5Up")
1495  
1496 self.title = getglobal("aUFgroup"..self.name.."Title")
1497 end
1498  
1499 function aUF.classes.aUFgroup.prototype:Reset()
1500 self:UpdateTitle()
1501 self:LoadPosition()
1502 end
1503  
1504 function aUF.classes.aUFgroup.prototype:UpdateTitle(player)
1505 if self.raid then
1506 if player == true then
1507 self.title:SetText("Group "..self.name.." *")
1508 else
1509 self.title:SetText("Group "..self.name)
1510 end
1511 else
1512 self.title:SetText("Group "..self.name)
1513 end
1514 end
1515  
1516 --[[
1517 function aUF.classes.aUFgroup.prototype.groupSortClosure()
1518 local unitIdIndex = {
1519 ["player"] = 1,
1520 ["playerpet"] = 2,
1521 ["party1"] = 3,
1522 ["party1pet"] = 4,
1523 ["party2"] = 5,
1524 ["party2pet"] = 6,
1525 ["party3"] = 7,
1526 ["party3pet"] = 8,
1527 ["party4"] = 9,
1528 ["party4pet"] = 10,
1529 }
1530  
1531 return function (a, b)
1532 return (unitIdIndex[a.unit] or 99) < (unitIdIndex[b.unit] or 99)
1533 end
1534 end
1535  
1536 function aUF.classes.aUFgroup.prototype:EachMember(group)
1537 local i = 0
1538 local sortedGroup = {}
1539  
1540 for _,member in pairs(group) do
1541 table.insert(sortedGroup, member)
1542 end
1543  
1544 if not self.groupSort then
1545 self.groupSort = self.groupSortClosure()
1546 end
1547  
1548 if self.groupSort then
1549 table.sort(sortedGroup, self.groupSort)
1550 end
1551  
1552 return function ()
1553 i = i + 1
1554 return sortedGroup[i]
1555 end
1556 end ]]
1557  
1558 function aUF.classes.aUFgroup.prototype:Update()
1559 if self.lastFrame then
1560 self.lastFrame:StopMovingOrSizing()
1561 end
1562 self.lastFrame = nil
1563  
1564 local grow = "down"
1565 local relation1, relation2,x,y
1566 local space = 5
1567 local player = false
1568  
1569 if grow == "up" then
1570 relation1 = "BOTTOMLEFT"
1571 relation2 = "TOPLEFT"
1572 x = 0
1573 y = -(space)
1574 elseif grow == "down" then
1575 relation1 = "TOPLEFT"
1576 relation2 = "BOTTOMLEFT"
1577 x = 0
1578 y = space
1579 elseif grow == "left" then
1580 relation1 = "TOPRIGHT"
1581 relation2 = "TOPLEFT"
1582 x = space
1583 y = 0
1584 elseif grow == "right" then
1585 relation1 = "TOPLEFT"
1586 relation2 = "TOPRIGHT"
1587 x = -(space)
1588 y = 0
1589 end
1590  
1591 self.index = {}
1592  
1593 if self.group.player and self.group.player.player then
1594 table.insert(self.index, self.group.player.player)
1595 end
1596 if self.group.pet and self.group.pet.pet then
1597 table.insert(self.index, self.group.pet.pet)
1598 end
1599  
1600 if self.group.party then
1601 for _,unitObject in self.group.party do
1602 table.insert(self.index, unitObject)
1603 if self.group.partypet then
1604 for _, unitPetObject in self.group.partypet do
1605 if unitPetObject.parent and unitPetObject.parent == unitObject.unit then
1606 table.insert(self.index, unitPetObject)
1607 end
1608 end
1609 end
1610 end
1611 end
1612 if self.group.raid then
1613 for _,unitObject in self.group.raid do
1614 table.insert(self.index, unitObject)
1615 if UnitName(unitObject.unit) == UnitName("player") then
1616 player = true
1617 end
1618 if self.group.raidpet then
1619 for _, unitPetObject in self.group.raidpet do
1620 if unitPetObject.parent and unitPetObject.parent == unitObject.unit then
1621 table.insert(self.index, unitPetObject)
1622 end
1623 end
1624 end
1625 end
1626 end
1627  
1628 -- print("---"..self.name)
1629 local empty = true
1630 for k,v in ipairs(self.index) do
1631 -- print(UnitName(v.unit))
1632 v.frame:ClearAllPoints()
1633 if self.index[k-1] then
1634 v.frame:SetPoint(relation1, self.index[k-1].frame,relation2,x,y)
1635 else
1636 empty = false
1637 self.lastFrame = v.frame
1638 self:LoadPosition()
1639 if self.raid then
1640 self.anchor:ClearAllPoints()
1641 self.anchor:SetPoint(relation2, self.lastFrame,relation1,-x,-y)
1642 self.anchor:Show()
1643 end
1644 end
1645 end
1646 if self.lastFrame then
1647 self.anchor:SetHeight(20)
1648 self:UpdateWidth()
1649 self:UpdateScale()
1650 self:UpdateTitle(player)
1651 end
1652 if empty == true or not self.lastFrame then
1653 self.anchor:Hide()
1654 end
1655 end
1656  
1657 function aUF.classes.aUFgroup.prototype:UpdateWidth()
1658 local width = 0
1659 local scale = 0
1660 if self.index then
1661 for _,unitObject in ipairs(self.index) do
1662 local lwidth = unitObject.frame:GetWidth()
1663 local swidth = unitObject.frame:GetWidth()*unitObject.frame:GetWidth()
1664 if lwidth > width then
1665 width = lwidth
1666 scale = unitObject.frame:GetScale()
1667 end
1668 end
1669 end
1670 self.anchor:SetWidth(width)
1671 if scale > 0 then
1672 self.anchor:SetScale(scale)
1673 end
1674 end
1675  
1676 function aUF.classes.aUFgroup.prototype:UpdateScale()
1677 self:UpdateWidth()
1678 end
1679  
1680 function aUF.classes.aUFgroup.prototype:BorderBackground()
1681 local colortable
1682 local borderstyle = aUF.db.profile.BorderStyle
1683  
1684 colortable = aUF.db.profile.PartyFrameColors
1685  
1686 self.anchor:SetBackdrop({
1687 bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16,
1688 edgeFile = aUF.Borders[borderstyle].texture, edgeSize = aUF.Borders[borderstyle].size,
1689 insets = {left = aUF.Borders[borderstyle].insets, right = aUF.Borders[borderstyle].insets, top = aUF.Borders[borderstyle].insets, bottom = aUF.Borders[borderstyle].insets},
1690 })
1691  
1692 self.anchor:SetBackdropColor(colortable.r,colortable.g,colortable.b,colortable.a)
1693 self.anchor:SetBackdropBorderColor(TOOLTIP_DEFAULT_COLOR.r,TOOLTIP_DEFAULT_COLOR.g,TOOLTIP_DEFAULT_COLOR.b,colortable.a)
1694 end
1695  
1696 function aUF.classes.aUFgroup.prototype:OnClick(button)
1697 for k,v in self.index do
1698 -- print(v.name)
1699 end
1700 end
1701  
1702 function aUF.classes.aUFgroup.prototype:OnDragStart(button)
1703 if ( button == "LeftButton" ) and aUF.db.profile.Locked == false then
1704 self.lastFrame:StartMoving()
1705 end
1706 end
1707  
1708 function aUF.classes.aUFgroup.prototype:OnDragStop(button)
1709 if self.lastFrame then
1710 self.lastFrame:StopMovingOrSizing()
1711 self:SavePosition()
1712 end
1713 end
1714  
1715 function aUF.classes.aUFgroup.prototype:LoadPosition()
1716 if self.lastFrame then
1717 if (aUF.db.profile.Positions[self.variableName]) then
1718 local x = aUF.db.profile.Positions[self.variableName].x
1719 local y = aUF.db.profile.Positions[self.variableName].y
1720 local scale = self.lastFrame:GetEffectiveScale()
1721  
1722 self.lastFrame:SetPoint("TOPLEFT", UIParent,"TOPLEFT", x/scale, y/scale)
1723 else
1724 self.lastFrame:SetPoint("CENTER", UIParent, "CENTER")
1725 end
1726 end
1727 end
1728  
1729 function aUF.classes.aUFgroup.prototype:SavePosition()
1730 local scale = self.lastFrame:GetEffectiveScale()
1731 local worldscale = UIParent:GetEffectiveScale()
1732  
1733 local x,y = self.lastFrame:GetLeft()*scale,self.lastFrame:GetTop()*scale - (UIParent:GetTop())*worldscale
1734  
1735 if not aUF.db.profile.Positions[self.variableName] then
1736 aUF.db.profile.Positions[self.variableName] = {}
1737 end
1738  
1739 aUF.db.profile.Positions[self.variableName].x = x
1740 aUF.db.profile.Positions[self.variableName].y = y
1741 end