All pastes #35739 Raw Edit

Haste

public lua v1 · immutable
#35739 ·published 2006-01-04 19:30 UTC
rendered paste body
--<< ================================================= >>---- Section I: Initialize the AddOn Object.               ----<< ================================================= >>--TimexBar = Timex:new({})function TimexBar:Enable()	self.barsDB = {}	self.bars   = {}	table.setn(self.bars, 20)	self:RegisterEvent("TIMEX_UPDATE")  for id = 1,20,1 do SetEffectiveScale(getglobal("TimexBar"..id),0.8) end   for id = 1,20,1 do getglobal("TimexBar"..id):SetFrameStrata("TOOLTIP") end	end--<< ================================================= >>---- Section II: The Start and Stop Bar Functions.         ----<< ================================================= >>--function TimexBar:StartBar(txt, tmr, r, g, blu, x, y, pr, a1, a2, re, tex)	if not tmr or not txt or txt == "" then return end	local b	for k, v in self.bars do		if v == txt 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] = txt end	end) end	if not b then error("No more bars available!") return end	self.barsDB[b] = {		bar = b, n  = txt, t  = re and (tmr / re) or tmr, 		v  = re and (tmr / re) or tmr, r = r, g  = g, 		b  = blu, x  = x,	y = y, pr = pr, a1 = a1,  a2 = a2, 		re = re, tex = tex	}	self:BarHandler(self.barsDB[b])	Timex:AddNamedSchedule("TimexBar"..b, 0.1, nil, tmr*10, "doTimexEvent")	return "TimexBar"..bendfunction TimexBar:StopBar(txt)	for k, v in self.bars do		if v == txt then			Timex:DeleteNamedSchedule("TimexBar"..k)			getglobal("TimexBar"..k):Hide()			self.bars[k] = nil  		self.barsDB[k] = nil		end	endendfunction TimexBar:CheckBar(txt, r)	for _, v in self.bars do		if v == txt then			r = r and self.bars[k].v or TRUE return r		end	endend --<< ================================================= >>---- Section III: The BarHandler Function.                 ----<< ================================================= >>--function TimexBar:BarHandler(db)	local bar  = getglobal("TimexBar"..db.bar)	local sbar = getglobal("TimexBar"..db.bar.."StatusBar")	local txt  = getglobal("TimexBar"..db.bar.."Text")	local ttxt = getglobal("TimexBar"..db.bar.."TimerText")	local btn  = getglobal("TimexBar"..db.bar.."Button")	local tex  = getglobal("TimexBar"..db.bar.."ButtonTexture")	bar:Show()	if db.x and db.y then		bar:ClearAllPoints()		bar:SetPoint((db.a1 or "CENTER"), (db.pr or "UIParent"), (db.a2 or "BOTTOMLEFT"), db.x, db.y)	end	local settext = ceil(db.v)	settext = settext > 60 and (format("%d", settext / 60)..":"..format("%02d", mod(settext, 60))) or settext	sbar:SetMinMaxValues(0, db.t)	sbar:SetStatusBarColor((db.r or 0.1), (db.g or 0.2), (db.b or 0.8))   if db.tex then btn:Show() tex:SetTexture(db.tex) else      btn:Hide()   end	txt:SetText("| "..db.n)	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].re then  		getglobal("TimexBar"..n):Hide()  		self.barsDB[n] = nil  		Timex:DeleteNamedSchedule("TimexBar"..n)  		self.bars[n] = nil return    else      self.barsDB[n].re = self.barsDB[n].re > 2 and (self.barsDB[n].re - 1) or nil      self.barsDB[n].v = self.barsDB[n].t    end	end	self:BarHandler(self.barsDB[n])endfunction GetEffectiveScale(frame)	return frame:GetEffectiveScale()endfunction SetEffectiveScale(frame, scale)	frame.scale = scale;  -- Saved in case it needs to be re-calculated when the parent's scale changes.	local parent = frame:GetParent()	if ( parent ) then		scale = scale / GetEffectiveScale(parent)	end	frame:SetScale(scale)end--<< ================================================= >>---- Section Omega: Register the AddOn Object.             ----<< ================================================= >>--TimexBar:RegisterForLoad()