--<< ================================================= >>---- Section I: Initialize the AddOn Object. ----<< ================================================= >>--TimexBar = Timex:new({})function TimexBar:Enable() self.barsDB = {} self.bars = {} self.done = {} table.setn(self.bars, 20) self:RegisterEvent("TIMEX_UPDATE") for id = 1,20,1 do self:SetEffectiveScale(getglobal("TimexBar"..id),0.8) end for id = 1,20,1 do getglobal("TimexBar"..id):SetFrameStrata("TOOLTIP") endend--<< ================================================= >>---- Section II: The Start and Stop Bar Functions. ----<< ================================================= >>--function TimexBar:StartBar(i, c, tc, a, s, f, tex) if not (i or {})[1] or i[1] == "" then return end local b for k, v in self.bars do if v == i[1] then b = k break end end if not b then foreachi(self.bars, function(k, v) if not b and not v then b = k self.bars[k] = i[1] end end) end if not b then error("No more bars available!") return end self.barsDB[b] = { i = i or {}, c = c or {}, tc = tc or {}, a = a or {}, s = s or {}, f = f, tex = tex, b = b, v = i[4] and (i[3] / i[4]) or i[3], t = i[4] and (i[3] / i[4]) or i[3] } self:BarHandler(self.barsDB[b]) Timex:AddNamedSchedule("TimexBar"..b, 0.1, nil, i[3]*10, "doTimexEvent") return "TimexBar"..bendfunction TimexBar:StopBar(id) for k, v in self.bars do if v == id then Timex:DeleteNamedSchedule("TimexBar"..k) getglobal("TimexBar"..k):Hide() self.bars[k] = nil self.barsDB[k] = nil self.done[k] = nil end endendfunction TimexBar:CheckBar(id, r) for k, v in self.bars do if v == id then r = r and "TimexBar"..k or TRUE return r end endendfunction TimexBar:ChangeDuration(id, t, mt) for k, v in self.bars do if v == id then self.barsDB[id].i[3] = mt self.barsDB[id].v = t end endend--<< ================================================= >>---- Section III: The BarHandler Function. ----<< ================================================= >>--function TimexBar:BarHandler(db, s) local bar = getglobal("TimexBar"..db.b) local sbar = getglobal("TimexBar"..db.b.."StatusBar") local stex = getglobal("TimexBar"..db.b.."Background") local txt = getglobal("TimexBar"..db.b.."Text") local ttxt = getglobal("TimexBar"..db.b.."TimerText") local btn = getglobal("TimexBar"..db.b.."Button") local tex = getglobal("TimexBar"..db.b.."ButtonTexture") if not self.done[db.b] or s then self.done[db.b] = self.done[db.b] or {} local sdb = self.done[db.b] if db.s[1] or sdb.a then sdb.a = db.s[1] or bar:GetWidth() bar:SetWidth(sdb.a) end if db.s[2] or sdb.b then sdb.b = db.s[2] or bar:GetHeight() bar:SetHeight(sdb.b) end if db.s[3] or sdb.c then sdb.c = db.s[3] or sbar:GetWidth() sbar:SetWidth(sdb.c) end if db.s[4] or sdb.d then sdb.d = db.s[4] or sbar:GetHeight() sbar:SetHeight(sdb.d) end if db.s[5] or sdb.e then sdb.e = db.s[5] or stex:GetWidth() stex:SetWidth(sdb.e) end if db.s[6] or sdb.f then sdb.f = db.s[6] or stex:GetHeight() stex:SetHeight(sdb.f) end if db.s[7] or sdb.g then sdb.g = db.s[7] or txt:GetWidth() txt:SetWidth(sdb.g) end if db.s[8] or sdb.h then sdb.h = db.s[8] or txt:GetHeight() txt:SetHeight(sdb.h) end if db.s[9] or sdb.i then sdb.i = db.s[9] or ttxt:GetWidth() ttxt:SetWidth(sdb.i) end if db.s[10] or sdb.j then sdb.j = db.s[10] or ttxt:GetHeight() ttxt:SetHeight(sdb.j) end if s then return end bar:Show() if db.a[1] and db.a[2] then bar:ClearAllPoints() bar:SetPoint((db.a[4] or "CENTER"), (db.a[3] or "UIParent"), (db.a[5] or "BOTTOMLEFT"), db.a[1], db.a[2]) end if db.tex then btn:Show() tex:SetTexture(db.tex) else btn:Hide() end sbar:SetStatusBarColor((db.c[1] or 0.1), (db.c[2] or 0.2), (db.c[3] or 0.8)) ttxt:SetTextColor((db.tc[1] or 1.0), (db.tc[2] or 1.0), (db.tc[3] or 1.0)) sbar:SetMinMaxValues(0, db.t) end local settext = ceil(db.v) settext = settext > 60 and (format("%d", settext / 60)..":"..format("%02d", mod(settext, 60))) or settext if db.i[2] then txt:SetText("| "..db.i[2]) end ttxt:SetText(settext) sbar:SetValue(db.v)end--<< ================================================= >>---- Section IV: The Time-Event Handler. ----<< ================================================= >>--function TimexBar:TIMEX_UPDATE(a, c, n, x) if not strfind(n, "TimexBar") then return end n = gsub(n, "TimexBar", "") n = tonumber(n) self.barsDB[n].v = self.barsDB[n].v - x if self.barsDB[n].v <= 0.1 then if not self.barsDB[n].i[4] then if self.barsDB[n].f then local func = self.barsDB[n].f[1] tremove(self.barsDB[n].f, 1) func(unpack(self.barsDB[n].f or {})) end local s for k in self.barsDB[n].s do if k then self:BarHandler({b = n}, TRUE) end end getglobal("TimexBar"..n):Hide() self.barsDB[n] = nil self.done[n] = nil Timex:DeleteNamedSchedule("TimexBar"..n) self.bars[n] = nil return else self.barsDB[n].i[4] = self.barsDB[n].i[4] > 2 and (self.barsDB[n].i[4] - 1) or nil self.barsDB[n].v = self.barsDB[n].t end end self:BarHandler(self.barsDB[n])end--<< ================================================= >>---- Section V: Fix the scale for 1.9. ----<< ================================================= >>--function TimexBar:GetEffectiveScale(frame) return frame:GetEffectiveScale()endfunction TimexBar:SetEffectiveScale(frame, scale) frame.scale = scale local parent = frame:GetParent() if ( parent ) then scale = scale / self:GetEffectiveScale(parent) end frame:SetScale(scale)end--<< ================================================= >>---- Section Omega: Register the AddOn Object. ----<< ================================================= >>--TimexBar:RegisterForLoad()