Mercurial > wow > kbf
comparison KBF.lua @ 4:75634f25a762
correctly update values when timed
author | Chris Mellon <arkanes@gmai.com> |
---|---|
date | Tue, 12 Oct 2010 17:45:59 -0500 |
parents | bb1143608eb4 |
children | 43340216545c |
comparison
equal
deleted
inserted
replaced
3:bb1143608eb4 | 4:75634f25a762 |
---|---|
12 } | 12 } |
13 self.anchor = self:CreateAnchorFrame() | 13 self.anchor = self:CreateAnchorFrame() |
14 self.buffBars = {} | 14 self.buffBars = {} |
15 self.anchor:Show() | 15 self.anchor:Show() |
16 self:RegisterEvent("UNIT_AURA") | 16 self:RegisterEvent("UNIT_AURA") |
17 -- set up the countdown timer | |
18 -- TODO: Fancy enable/disable based on whether you have any timed buffs. | |
19 -- Not a big deal, how often do you care about that | |
20 self.anchor:SetScript("OnUpdate", function() self:OnUpdate() end) | |
17 end | 21 end |
18 -- naming convention | 22 -- naming convention |
19 -- "frame" is the secure aura button created by the group handler | 23 -- "frame" is the secure aura button created by the group handler |
20 -- "bar" is the set of icon + status bars that we create to show the buff time | 24 -- "bar" is the set of icon + status bars that we create to show the buff time |
25 | |
26 function kbf:OnUpdate() | |
27 for idx=1,99 do | |
28 local frame = self.secureFrame:GetAttribute("child"..idx) | |
29 if not (frame and frame.expirationTime) then break end | |
30 local remaining = frame.expirationTime - GetTime() | |
31 remaining = math.max(0, remaining) | |
32 local perc = remaining / frame.duration | |
33 frame.timertext:SetText(self:FormatTimeText(remaining)) | |
34 frame.statusbar:SetValue(remaining) | |
35 end | |
36 end | |
21 | 37 |
22 function kbf:UNIT_AURA(event, unit) | 38 function kbf:UNIT_AURA(event, unit) |
23 if unit ~= self.secureFrame:GetAttribute("unit") then return end | 39 if unit ~= self.secureFrame:GetAttribute("unit") then return end |
24 for idx=1,99 do | 40 for idx=1,99 do |
25 local frame = self.secureFrame:GetAttribute("child"..idx) | 41 local frame = self.secureFrame:GetAttribute("child"..idx) |
31 function kbf:BindBarToBuff(parentFrame, unit) | 47 function kbf:BindBarToBuff(parentFrame, unit) |
32 local index = parentFrame:GetAttribute("index") | 48 local index = parentFrame:GetAttribute("index") |
33 local filter = parentFrame:GetAttribute("filter") | 49 local filter = parentFrame:GetAttribute("filter") |
34 local name, rank, icon, count, debuffType, duration, expirationTime, | 50 local name, rank, icon, count, debuffType, duration, expirationTime, |
35 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter) | 51 unitCaster, isStealable, shouldConsolidate, spellId = UnitAura(unit, index, filter) |
36 -- This shouldn't be neccesary as the bar is parented to the frame, which is | |
37 -- hidden by the group handler | |
38 if not parentFrame.icon then | 52 if not parentFrame.icon then |
39 self:ConstructBar(parentFrame) | 53 self:ConstructBar(parentFrame) |
40 end | 54 end |
41 parentFrame.icon:SetNormalTexture(icon) | 55 parentFrame.icon:SetNormalTexture(icon) |
42 if stacks and stacks > 0 then | 56 if stacks and stacks > 0 then |
43 parentFrame.text:SetText(string.format("%s(%d)", name, stacks)) | 57 parentFrame.text:SetText(string.format("%s(%d)", name, stacks)) |
44 else | 58 else |
45 parentFrame.text:SetText(name) | 59 parentFrame.text:SetText(name) |
46 end | 60 end |
61 parentFrame.timertext:SetText(self:FormatTimeText(duration)) | |
62 -- store duration information | |
63 if duration > 0 then | |
64 parentFrame.expirationTime = expirationTime | |
65 parentFrame.duration = duration | |
66 parentFrame.statusbar:SetMinMaxValues(0, duration) | |
67 parentFrame.statusbar:SetValue(duration) | |
68 else | |
69 parentFrame.expirationTime = nil | |
70 parentFrame.duration = 0 | |
71 parentFrame.statusbar:SetMinMaxValues(0,1) | |
72 parentFrame.statusbar:SetValue(1) | |
73 end | |
74 end | |
75 | |
76 function kbf:FormatTimeText(time) | |
77 if not time or time == 0 then return "" end | |
78 local timetext | |
79 local h = floor(time/3600) | |
80 local m = time - (h*3600) | |
81 m = floor(m/60) | |
82 local s = time - ((h*3600) + (m*60)) | |
83 if h > 0 then | |
84 timetext = ("%d:%02d"):format(h, m) | |
85 elseif m > 0 then | |
86 timetext = string.format("%d:%02d", m, floor(s)) | |
87 elseif s < 10 then | |
88 timetext = string.format("%1.1f", s) | |
89 else | |
90 timetext = string.format("%.0f", floor(s)) | |
91 end | |
92 return timetext | |
47 end | 93 end |
48 | 94 |
49 -- creates a icon + statusbar bar | 95 -- creates a icon + statusbar bar |
50 function kbf:ConstructBar(frame) | 96 function kbf:ConstructBar(frame) |
51 local texture = "Interface\\TargetingFrame\\UI-StatusBar" | 97 local texture = "Interface\\TargetingFrame\\UI-StatusBar" |