From 253d7b92722a1c1713fe780ea29fa0402abd2996 Mon Sep 17 00:00:00 2001 From: Xruptor Date: Mon, 26 Jul 2010 12:05:38 -0400 Subject: [PATCH] -Changed the way that auras are processed. COMBAT_LOG_EVENT_UNFILTERED is now used. -Added a new slash command /xdt sort - toggles the sorting ASCENDING/DESCENDING. -Made DESCENDING default. -Made bar growth up default. -Removed UNIT_AURA -Added SPELL_AURA_APPLIED, SPELL_AURA_REMOVED, SPELL_AURA_REFRESH -Added checks for overflow in bar length. -Updated getBarColor() -Bar visual has been modified to MONOCHROME to make it easier to see. -ProcessGrowth() has been removed. -Fixed the sorting depending on direction of bars UP/DOWN. -Fixed a slight issue with anchor positioning. --- XanDebuffTimers.lua | 124 +++++++++++++++++++++++---------------------------- XanDebuffTimers.toc | 2 +- 2 files changed, 56 insertions(+), 70 deletions(-) diff --git a/XanDebuffTimers.lua b/XanDebuffTimers.lua index b3adbae..43c2480 100644 --- a/XanDebuffTimers.lua +++ b/XanDebuffTimers.lua @@ -1,4 +1,4 @@ ---Inspired by TextTimers +--Inspired by TextTimers, Please give credit to Sagewind where possible local timers = {} local timersFocus = {} @@ -6,6 +6,7 @@ local MAX_TIMERS = 15 local ICON_SIZE = 20 local BAR_ADJUST = 25 local BAR_TEXT = "llllllllllllllllllllllllllllllllllllllll" +local band = bit.band local targetGUID = 0 local focusGUID = 0 @@ -23,7 +24,8 @@ function f:PLAYER_LOGIN() if not XDT_DB then XDT_DB = {} end if XDT_DB.scale == nil then XDT_DB.scale = 1 end - if XDT_DB.grow == nil then XDT_DB.grow = true end + if XDT_DB.grow == nil then XDT_DB.grow = false end + if XDT_DB.sort == nil then XDT_DB.sort = false end --create our anchors f:CreateAnchor("XDT_Anchor", UIParent) @@ -35,14 +37,13 @@ function f:PLAYER_LOGIN() timersFocus[i] = f:CreateDebuffTimers() end - --do our growth process for the debuff bars (SETPOINT) - f:ProcessGrowth() + f:UnregisterEvent("PLAYER_LOGIN") + f.PLAYER_LOGIN = nil f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") f:RegisterEvent("PLAYER_TARGET_CHANGED") f:RegisterEvent("PLAYER_FOCUS_CHANGED") - f:RegisterEvent("UNIT_AURA") - + SLASH_XANDEBUFFTIMERS1 = "/xandebufftimers" SLASH_XANDEBUFFTIMERS2 = "/xdt" SLASH_XANDEBUFFTIMERS3 = "/xandt" @@ -81,7 +82,15 @@ function f:PLAYER_LOGIN() XDT_DB.grow = true DEFAULT_CHAT_FRAME:AddMessage("XanDebuffTimers: Bars will now grow [|cFF99CC33DOWN|r]") end - f:ProcessGrowth() + return true + elseif c and c:lower() == "sort" then + if XDT_DB.sort then + XDT_DB.sort = false + DEFAULT_CHAT_FRAME:AddMessage("XanDebuffTimers: Bars sort [|cFF99CC33DESCENDING|r]") + else + XDT_DB.sort = true + DEFAULT_CHAT_FRAME:AddMessage("XanDebuffTimers: Bars sort [|cFF99CC33ASCENDING|r]") + end return true end end @@ -90,22 +99,11 @@ function f:PLAYER_LOGIN() DEFAULT_CHAT_FRAME:AddMessage("/xdt anchor - toggles a movable anchor") DEFAULT_CHAT_FRAME:AddMessage("/xdt scale # - sets the scale size of the bars") DEFAULT_CHAT_FRAME:AddMessage("/xdt grow - changes the direction in which the bars grow (UP/DOWN)") + DEFAULT_CHAT_FRAME:AddMessage("/xdt sort - changes the sorting of the bars. (ASCENDING/DESCENDING)") end local ver = tonumber(GetAddOnMetadata("XanDebuffTimers","Version")) or 'Unknown' DEFAULT_CHAT_FRAME:AddMessage("|cFF99CC33XanDebuffTimers|r [v|cFFDF2B2B"..ver.."|r] loaded: /xdt") - - f:UnregisterEvent("PLAYER_LOGIN") - f.PLAYER_LOGIN = nil -end - -function f:UNIT_AURA(event, unit) - if not unit then return end - if unit == "target" and UnitGUID(unit) and UnitGUID(unit) == targetGUID then - f:ProcessDebuffs("target", timers) - elseif unit == "focus" and UnitGUID(unit) and UnitGUID(unit) == focusGUID then - f:ProcessDebuffs("focus", timersFocus) - end end function f:PLAYER_TARGET_CHANGED() @@ -142,7 +140,16 @@ function f:COMBAT_LOG_EVENT_UNFILTERED(event, timestamp, eventType, srcGUID, src f:ClearDebuffs(timersFocus) focusGUID = 0 end + + elseif eventType == "SPELL_AURA_APPLIED" or eventType == "SPELL_AURA_REMOVED" or eventType == "SPELL_AURA_REFRESH" and band(srcFlags, COMBATLOG_OBJECT_AFFILIATION_MINE) ~= 0 then + --process the spells based on GUID + if dstGUID == targetGUID then + f:ProcessDebuffs("target", timers) + elseif dstGUID == focusGUID then + f:ProcessDebuffs("focus", timersFocus) + end end + end ---------------------- @@ -226,6 +233,7 @@ local TimerOnUpdate = function(self, time) local beforeEnd = self.endTime - GetTime() local barLength = ceil( string.len(BAR_TEXT) * (beforeEnd / self.durationTime) ) + if barLength > string.len(BAR_TEXT) then barLength = string.len(BAR_TEXT) end if barLength <= 0 then self.active = false @@ -236,7 +244,7 @@ local TimerOnUpdate = function(self, time) self.tmpBL = barLength self.Bar:SetText( string.sub(BAR_TEXT, 1, barLength) ) - self.Bar:SetTextColor(f:getBarColor(self.durationTime, beforeEnd, false)) + self.Bar:SetTextColor(f:getBarColor(self.durationTime, beforeEnd)) if self.stacks > 0 then self.stacktext:SetText(self.stacks) else @@ -279,7 +287,7 @@ function f:CreateDebuffTimers() Frm.timetext:SetPoint("RIGHT", Frm.icon, "LEFT" , -5, 0) Frm.Bar = Frm:CreateFontString(nil, "GameFontNormal") - Frm.Bar:SetFont(STANDARD_TEXT_FONT, 14, "OUTLINE") + Frm.Bar:SetFont(STANDARD_TEXT_FONT, 14, "OUTLINE, MONOCHROME") Frm.Bar:SetText(BAR_TEXT) Frm.Bar:SetPoint("LEFT", Frm.icon, "RIGHT", 1, 0) @@ -291,37 +299,16 @@ function f:CreateDebuffTimers() end -function f:ProcessGrowth() - local adj = 0 - for i=1,MAX_TIMERS do - if XDT_DB.grow then - timers[i]:ClearAllPoints() - timers[i]:SetPoint("TOPLEFT", "XDT_Anchor", "BOTTOMRIGHT", 0, adj) - --FOCUS - timersFocus[i]:ClearAllPoints() - timersFocus[i]:SetPoint("TOPLEFT", "XDT_FocusAnchor", "BOTTOMRIGHT", 0, adj) - else - timers[i]:ClearAllPoints() - timers[i]:SetPoint("BOTTOMLEFT", "XDT_Anchor", "TOPRIGHT", 0, (adj * -1)) - --FOCUS - timersFocus[i]:ClearAllPoints() - timersFocus[i]:SetPoint("BOTTOMLEFT", "XDT_FocusAnchor", "TOPRIGHT", 0, (adj * -1)) - end - adj = adj - BAR_ADJUST - end -end ---------------------- -- Debuff Functions -- ---------------------- function f:ProcessDebuffs(sT, sdTimer) - if f.selfProcessingBuffs then return end - f.selfProcessingBuffs = true - --only process for as many timers as we are using local countBuffs = 0 for i=1, MAX_TIMERS do - local name, _, icon, count, _, duration, expTime, unitCaster, _, _, spellId = UnitAura(sT, i, 'HARMFUL|PLAYER') + local name, _, icon, count, _, duration, expTime, unitCaster, _, _, spellId = UnitAura(sT, i, 'HARMFUL|PLAYER') + --UnitIsUnit is used JUST IN CASE (you never know lol) if name and unitCaster and UnitIsUnit(unitCaster, "player") then sdTimer[i].id = sT sdTimer[i].spellName = name @@ -333,6 +320,7 @@ function f:ProcessDebuffs(sT, sdTimer) sdTimer[i].endTime = expTime sdTimer[i].stacks = count or 0 local tmpBL = ceil( string.len(BAR_TEXT) * ( (expTime - GetTime()) / duration ) ) + if tmpBL > string.len(BAR_TEXT) then tmpBL = string.len(BAR_TEXT) end sdTimer[i].tmpBL = tmpBL sdTimer[i].active = true if not sdTimer[i]:IsVisible() then sdTimer[i]:Show() end @@ -342,9 +330,6 @@ function f:ProcessDebuffs(sT, sdTimer) if sdTimer[i]:IsVisible() then sdTimer[i]:Hide() end end end - - f.selfProcessingBuffs = nil - if countBuffs > 0 then f:ArrangeDebuffs(false, sT) end @@ -360,8 +345,6 @@ function f:ClearDebuffs(sdTimer) end function f:ArrangeDebuffs(throttle, id) - if f.selfProcessingBuffs then return end - --to prevent spam and reduce CPU use if throttle then if not f.ADT then f.ADT = GetTime() end @@ -395,9 +378,20 @@ function f:ArrangeDebuffs(throttle, id) end --sort by the size of the progressbar... duh - table.sort(active, function(a,b) return (a.tmpBL > b.tmpBL) end) + if XDT_DB.grow then + if XDT_DB.sort then + table.sort(active, function(a,b) return (a.tmpBL < b.tmpBL) end) + else + table.sort(active, function(a,b) return (a.tmpBL > b.tmpBL) end) + end + else + if XDT_DB.sort then + table.sort(active, function(a,b) return (a.tmpBL > b.tmpBL) end) + else + table.sort(active, function(a,b) return (a.tmpBL < b.tmpBL) end) + end + end - --rearrange order for i=1, #active do if XDT_DB.grow then @@ -426,8 +420,8 @@ function f:SaveLayout(frame) XDT_DB[frame] = { ["point"] = "CENTER", ["relativePoint"] = "CENTER", - ["xOfs"] = 0, - ["yOfs"] = 0, + ["PosX"] = 0, + ["PosY"] = 0, } opt = XDT_DB[frame]; end @@ -436,9 +430,7 @@ function f:SaveLayout(frame) local scale = f:GetEffectiveScale(); opt.PosX = f:GetLeft() * scale; opt.PosY = f:GetTop() * scale; - --opt.Width = f:GetWidth(); - --opt.Height = f:GetHeight(); - + end function f:RestoreLayout(frame) @@ -452,8 +444,8 @@ function f:RestoreLayout(frame) XDT_DB[frame] = { ["point"] = "CENTER", ["relativePoint"] = "CENTER", - ["xOfs"] = 0, - ["yOfs"] = 0, + ["PosX"] = 0, + ["PosY"] = 0, } opt = XDT_DB[frame]; end @@ -462,11 +454,11 @@ function f:RestoreLayout(frame) local y = opt.PosY; local s = f:GetEffectiveScale(); - if not x or not y then + if not x or not y then f:ClearAllPoints(); f:SetPoint("CENTER", UIParent, "CENTER", 0, 0); return - end + end --calculate the scale x,y = x/s,y/s; @@ -477,20 +469,14 @@ function f:RestoreLayout(frame) end -function f:getBarColor(dur, expR, reverse) +function f:getBarColor(dur, expR) local r local g = 1 local cur = 2 * expR/dur if cur > 1 then - r = 2 - cur - else - r = 1 - g = cur - end - if reverse then - return g, r, 0 + return 2 - cur, 1, 0 else - return r, g, 0 + return 1, cur, 0 end end diff --git a/XanDebuffTimers.toc b/XanDebuffTimers.toc index a7f1181..d20e72b 100644 --- a/XanDebuffTimers.toc +++ b/XanDebuffTimers.toc @@ -2,7 +2,7 @@ ## Title: XanDebuffTimers ## Notes: A small text based progress bar system for target debuffs. ## Author: Xanthos -## Version: 1.6 +## Version: 1.5 ## SavedVariablesPerCharacter: XDT_DB XanDebuffTimers.lua -- 1.7.9.5