Quantcast

Merge remote branch 'origin/master'

yaroot [11-26-10 - 16:27]
Merge remote branch 'origin/master'
Filename
.gitignore
Cenote.toc
core.lua
embeds.xml
updatelib.sh
diff --git a/.gitignore b/.gitignore
index 9e1a885..bee3e51 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
 *.sw[a-z]
+libs
diff --git a/Cenote.toc b/Cenote.toc
index 032c26c..3e75e7f 100644
--- a/Cenote.toc
+++ b/Cenote.toc
@@ -1,6 +1,8 @@
 ## Interface: 40000
 ## Title: Spell Activation Timer
+## Notes: Add timer to the build-in spell alert
 ## SavedVariables: SATimerDB
+## Version: 4.0.3.1-beta

 core.lua

diff --git a/core.lua b/core.lua
index 7120297..4e713ac 100644
--- a/core.lua
+++ b/core.lua
@@ -1,31 +1,44 @@

 local L = setmetatable({}, {__index=function(t, i) return i end})
 local SATimer = LibStub('AceAddon-3.0'):NewAddon('SATimer')
-
-local db
-local defaults = {
-    profile = {
-        enabled = true,
-    },
+local debug
+
+--local db
+--local defaults = {
+--    profile = {
+--        enabled = true,
+--    },
+--}
+
+local complexLocationTable = {
+	['RIGHT (FLIPPED)'] = 'RIGHT',
+	['BOTTOM (FLIPPED)'] = 'BOTTOM',
+	['LEFT + RIGHT (FLIPPED)'] = 'BOTTOM',
+	['TOP + BOTTOM (FLIPPED)'] = 'BOTTOM',
 }

-SATimer.all = {}
-SATimer.unused = {}
-SATimer.using = {}
-
 function SATimer:OnInitialize()
-    self.db = LibStub("AceDB-3.0"):New('SATimerDB', defaults, UnitName'player' .. '-' .. GetRealmName())
-    db = self.db.profile
+    local debugf = tekDebug and tekDebug:GetFrame'SATimer'
+    debug = debugf and function(...)
+        debugf:AddMessage(string.join(', ', tostringall(...)))
+    end or function() end
+
+    debug'OnLoad'
+    --self.db = LibStub("AceDB-3.0"):New('SATimerDB', defaults, UnitName'player' .. '-' .. GetRealmName())
+    --db = self.db.profile

     --self:SetupOption()

-    --hooksecurefunc('SpellActivationOverlay_OnEvent', function(...) print(...) end)
+    self.timers = {}
+    self.SAFrame = SpellActivationOverlayFrame
+
     SpellActivationOverlayFrame:HookScript('OnEvent', function(...)
         SATimer:OnSAOFEvent(...)
     end)
 end

 function SATimer:OnSAOFEvent(_, event, ...)
+    debug('OnEvent', event)
     if(event and self[event]) then
         self[event](self, ...)
     end
@@ -34,21 +47,24 @@ end
 function SATimer:SPELL_ACTIVATION_OVERLAY_SHOW(spellID, texture, position, scale, r, g, b)
     local f = self:Get(spellID)
     local endTime = self:GetTimeLeft(spellID)
+    local POS = strupper(position)
+    debug('SHOW', f, endTime, spellID, texture, position, complexLocationTable[POS], scale, r, g, b)

     if(endTime) then
         if(not f) then
             f = self:GetUnused()
-            self:SetUsing(f)
+            f.using = true
         end
         f.spellID = spellID
         f.position = position
+        f.endTime = endTime
+        f.realPosition = complexLocationTable[POS] or POS
         f.scale = scale
-        f.r = r
-        f.g = g
-        f.b = b
+        --f.r = r
+        --f.g = g
+        --f.b = b

         self:Update(f)
-        self:UpdateTimers()
     else
         if(f) then
             self:Remove(f)
@@ -58,16 +74,13 @@ function SATimer:SPELL_ACTIVATION_OVERLAY_SHOW(spellID, texture, position, scale
 end

 function SATimer:SPELL_ACTIVATION_OVERLAY_HIDE(spellID)
+    debug('HIDE', spellID)
     local f = self:Get(spellID)
     if(f) then
         self:Remove(f)
-        self:UpdateTimers()
     end
 end

-function SATimer:UpdateTimers()
-end
-
 do
     local _SPELLS = setmetatable({}, {__index=function(t,i)
         local n = GetSpellInfo(i)
@@ -77,54 +90,91 @@ do

     function SATimer:GetTimeLeft(spellID)
         local spell = _SPELLS[spellID]
+        debug('SPELLID', spellID, spell)
         if(not spell) then return end

-        local name, _, _, duration, expiration, caster = UnitAura('player', spell, 'PLAYER')
+        local name, rank, icon, count, debuffType, duration, expiration, caster = UnitAura('player', spell)
+        debug('SPELL', spellID, spell, name, duration, expiration, caster)
         if(name and duration>0 and expiration>GetTime()) then
             return expiration
         end
     end
-end

-function SATimer:Update(f)
+    local function update(self)
+        local timeLeft = self.endTime - GetTime()
+        if(timeLeft > 0) then
+            self.text:SetText(floor(timeLeft) .. '.')
+
+            local s = timeLeft - floor(timeLeft)
+            self.text2:SetText(floor(s*1000))
+
+            --self.nextUpdate = timeLeft - floor(timeLeft)
+        else
+            SATimer:Remove(self)
+        end
+    end
+
+    --local function onUpdate(self, elps)
+    --    update(self)
+    --end
+
+    function SATimer:Update(f)
+        debug('UPDATE', f.spellID)
+        --f.text:SetTextColor(f.r, f.g, f.b)
+        f:ClearAllPoints()
+        f:SetPoint(f.realPosition, self.SAFrame)
+        f:Show()
+
+        f.nextUpdate = 0
+        update(f)
+        f:SetScript('OnUpdate', update)
+    end
 end

 function SATimer:Remove(f)
+    debug('REMOVE', f, f.spellID)
     f:Hide()
     f:SetScript('OnUpdate', nil)
-    self:SetUnused(f)
-end
-
-function SATimer:SetUsing(f)
-    self.using[f] = true
-    self.unused[f] = nil
-end
-
-function SATimer:SetUnused(f)
-    self.using[f] = nil
-    self.unused[f] = true
+    f.using = nil
 end

 function SATimer:Get(spellID)
-    for f in next, self.using do
-        if(f.spellID == spellID) then
-            return f
+    for k, v in ipairs(self.timers) do
+        if(v.using and v.spellID == spellID) then
+            return v
         end
     end
 end

 function SATimer:GetUnused()
-    local f = next(self.unused)
-    if(not f) then
-        f = self:CreateTimer()
+    for k, v in ipairs(self.timers) do
+        if(not v.using) then return v end
     end
-
-    return f
+    return self:CreateTimer()
 end

+local r, g, b, m = 1, .1, .1, .7
+local font = QuestFont_Large:GetFont()
 function SATimer:CreateTimer()
-    local f = CreateFrame('Frame', nil, 'SpellActivationOverlayFrame')
-    self:SetUnused(f)
+    --debug'OnCreateTimer'
+    local f = CreateFrame('Frame', nil, self.SAFrame)
+    tinsert(self.timers, f)
+    f:SetWidth(2)
+    f:SetHeight(2)
+
+    f.text = f:CreateFontString(nil, 'OVERLAY')
+    f.text:SetFont(font, 32, 'OUTLINE')
+    f.text:SetPoint('BOTTOMRIGHT', f)
+    f.text:SetJustifyH('RIGHT')
+    f.text:SetJustifyV('BOTTOM')
+    f.text:SetTextColor(r, g, b)
+
+    f.text2 = f:CreateFontString(nil, 'OVERLAY')
+    f.text2:SetFont(font, 20, 'OUTLINE')
+    f.text2:SetPoint('BOTTOMLEFT', f, 'BOTTOMRIGHT', 0, 3)
+    f.text2:SetJustifyH('LEFT')
+    f.text2:SetJustifyV('BOTTOM')
+    f.text2:SetTextColor(r, g, b)

     return f
 end
diff --git a/embeds.xml b/embeds.xml
new file mode 100644
index 0000000..9c8e557
--- /dev/null
+++ b/embeds.xml
@@ -0,0 +1,6 @@
+<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
+..\FrameXML\UI.xsd">
+<Script file="libs\LibStub\LibStub.lua"/>
+<Include file="libs\CallbackHandler-1.0\CallbackHandler-1.0.xml" />
+<Include file="libs\AceAddon-3.0\AceAddon-3.0.xml" />
+</Ui>
diff --git a/updatelib.sh b/updatelib.sh
new file mode 100755
index 0000000..ce83920
--- /dev/null
+++ b/updatelib.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+function co()
+{
+    if [ -d libs/$2 ]; then
+        svn update libs/$2
+    else
+        svn co $1 libs/$2
+    fi
+}
+
+if [ ! -d libs ]; then
+    mkdir libs
+fi
+co 'svn://svn.wowace.com/wow/ace3/mainline/trunk/LibStub' 'LibStub'
+co 'svn://svn.wowace.com/wow/ace3/mainline/trunk/CallbackHandler-1.0' 'CallbackHandler-1.0'
+co 'svn://svn.wowace.com/wow/ace3/mainline/trunk/AceAddon-3.0' 'AceAddon-3.0'
+
+