WoWInterface SVN SliceCommander

[/] [trunk/] [SliceCommander.lua] - Rev 252

Compare with Previous | Blame | View Log

SliceCommander = LibStub("AceAddon-3.0"):NewAddon("SliceCommander", "AceEvent-3.0", "AceHook-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("SliceCommander")
local LSM = LibStub("LibSharedMedia-3.0")
local _G = getfenv(0)

function SliceCommander:BarTexture()
        return LSM:Fetch("statusbar", _G['SC'].SET.BarTexture)
end

function SliceCommander:PlayCDSound(BAR)
        if BAR['sound'] ~= nil and not _G['SC'].preventSound then
                local name = BAR['sound']['available']
                if (SliceCommander:isCombat() or _G['SC'].SET.ForceCDSpellSound) and name ~= 'None' and name ~= nil then
                        PlaySoundFile(LSM:Fetch("sound", name), _G['SC'].SET.soundChannel)
                end
        end
end

function SliceCommander:PlaySoundReal(name)
        local _
        if _G['SC'].previousSound then
                StopSound(_G['SC'].previousSound)
        end
        _, _G['SC'].previousSound = PlaySoundFile(LSM:Fetch("sound", name), _G['SC'].SET.soundChannel)
end

function SliceCommander:PlaySound(name)
        if SliceCommander:isCombat() and name ~= 'None' and name ~= nil then
                SliceCommander:PlaySoundReal(name)
        end
end

function SliceCommander:ChangeAnchor()
        local offSetSize, numberPos, numberNeg, alignPos, alignNeg
        offSetSize = _G['SC'].SET.BarMargin+_G['SC'].SET.TimerHeight
        numberPos = 0
        numberNeg = 0

        for i = 1, _G['SC'].countBars do
                for j,v in pairs(_G['SC'].BARS) do
                        if v['obj']:IsVisible() and v['expire'] == nil then
                                v['obj']:Hide()
                                if v['type'] == 4 or v['type'] == 5 then                                        
                                        SliceCommander:PlayCDSound(v)
                                end
                        end
                        if _G['SC'].SET.Pos[j] == i and v['obj']:IsVisible() then
                                alignPos = -1*numberNeg*offSetSize-_G['SC'].SET.BarMargin
                                v['obj']:ClearAllPoints()
                                v['obj']:SCPoint("TOPRIGHT", VTimerEnergy, "BOTTOMRIGHT", 0, alignPos)
                                numberNeg = numberNeg +1
                        end
                        if _G['SC'].SET.Pos[j] == i*-1 and v['obj']:IsVisible() then
                                alignNeg = numberPos*offSetSize+_G['SC'].SET.BarMargin
                                v['obj']:ClearAllPoints()
                                v['obj']:SCPoint("BOTTOMRIGHT", VTimerEnergy, "TOPRIGHT", 0, alignNeg)
                                numberPos = numberPos +1
                        end
                end
        end
end

function SliceCommander:isCombat()
        if _G['SC'].SET.SoundCombat==true then
                return UnitAffectingCombat("player")
        else
                return true
        end
end

function SliceCommander:SetComboPts()
        local points = UnitPower("player", Enum.PowerType.ComboPoints)
        local maxCP = UnitPowerMax("player", Enum.PowerType.ComboPoints)
        
        for i = 1, maxCP do
                _G['SC'].BARS['CP']['obj'].combos[i].bg:Hide()
        end
        _G['SC'].BARS['CP']['obj']:Hide()
        local text = points
        if text == 0 then
                text = ''
        end
        
        if points < _G['SC'].BARS['CP']['expire'] then
                _G['SC'].BARS['CP']['last'] = _G['SC'].BARS['CP']['expire']
        end
        _G['SC'].BARS['CP']['expire'] = points
        
        SliceCommander_Combo:SetText(text)
        _G['SC'].BARS['CP']['obj'].comboText:SetText(text)
        
        if _G['SC'].SET.display.CP == true then
                for i = 1, points do
                        _G['SC'].BARS['CP']['obj'].combos[i].bg:Show()
                end
                _G['SC'].BARS['CP']['obj']:Show()
        end
end

function SliceCommander:OnDisable()
        SliceCommander:UnregisterAllEvents()
end

function SliceCommander:DEBUG(spell, message)
        if spell == 'SND' then
                print(spell.. ' => ' ..tostring(message))
        end
end

function SliceCommander:AbilityCDBar(spell)
        local BAR = _G['SC'].BARS[spell]
        local display = _G['SC'].SET.display[spell]
        
        if display ~= true then
                BAR['expire'] = 0
                if BAR['obj']:IsVisible() then
                        SliceCommander:HideBar(BAR)
                        SliceCommander:PlayCDSound(BAR)
                end
                return
        end

        local start, duration = GetSpellCooldown(BAR['name'])
        if start == nil or duration == nil then--not in this spec
                BAR['expire'] = 0
                if BAR['obj']:IsVisible() then--if you respect when a cd is enabled
                        SliceCommander:HideBar(BAR)
                        SliceCommander:PlayCDSound(BAR)
                end
                return
        end
        if start ~= 0 and duration >= 2 and (not BAR['obj']:IsVisible() or BAR['obj'].anim:IsPlaying()) then
                if BAR['obj'].anim:IsPlaying() then
                        BAR['obj'].anim:Stop()
                end
                SliceCommander:EnableBar(BAR, duration, BAR['name'].." (CD)", (start+duration))
                return
        end
        if start == 0 then
                if _G['SC'].SET.flash[spell] == true and UnitAffectingCombat("player") then
                        if not BAR['obj'].anim:IsPlaying() then
                                BAR['obj']:SetValue(500)
                                BAR['obj'].text:SetText('')
                                if BAR['expire'] ~= -1 then
                                        BAR['expire'] = -1
                                        if BAR['obj']:IsVisible() then
                                                SliceCommander:PlayCDSound(BAR)
                                        end
                                end
                                if not BAR['obj']:IsVisible() then
                                        if _G['SC'].SET.SpellText == true then
                                                BAR['obj'].text2:SetText(string.format("%s", BAR['name'].." (CD)"))
                                        else
                                                BAR['obj'].text2:SetText('')
                                        end
                                        BAR['obj']:Show()
                                        SliceCommander:ChangeAnchor()
                                end
                                BAR['obj'].anim:Play()
                        end
                else
                        BAR['expire'] = 0
                        if BAR['obj']:IsVisible() then
                                if BAR['obj'].anim:IsPlaying() then
                                        BAR['obj'].anim:Stop()
                                else
                                        SliceCommander:PlayCDSound(BAR)
                                end
                                SliceCommander:HideBar(BAR)
                        end
                end
                return
        end
        if start == 0 or duration < 2 then
                if BAR['expire'] ~= -1 then
                        BAR['expire'] = 0
                end
                return
        end
        BAR['expire'] = (start+duration)
        local x
        if BAR['expire'] > 0 and _G['SC'].tNow < BAR['expire'] then
                x = BAR['expire'] - _G['SC'].tNow
        else
                x = 0
        end
        BAR['obj']:SetValue(x)
        BAR['obj'].text:SetText(string.format("%0.1f", x))
end

function SliceCommander:ChargeAbilityCDBar(spell)
        local BAR = _G['SC'].BARS[spell]
        local display = _G['SC'].SET.display[spell]
        
        if display ~= true then
                BAR['expire'] = 0
                if BAR['obj']:IsVisible() then
                        SliceCommander:HideBar(BAR)
                        SliceCommander:PlayCDSound(BAR)
                end
                return
        end

        local charges, maxCharges, start, duration  = GetSpellCharges(BAR['name'])
        if start == nil or duration == nil then--not in this spec
                BAR['expire'] = 0
                if BAR['obj']:IsVisible() then--if you respect when a cd is enabled
                        SliceCommander:HideBar(BAR)
                        SliceCommander:PlayCDSound(BAR)
                end
                return
        end
        if charges ~= maxCharges and (not BAR['obj']:IsVisible() or BAR['obj'].anim:IsPlaying()) then
                if BAR['obj'].anim:IsPlaying() then
                        BAR['obj'].anim:Stop()
                end
                SliceCommander:EnableBar(BAR, duration, BAR['name'].." (CD)", (start+duration))
                return
        end
        if charges == maxCharges then
                if _G['SC'].SET.flash[spell] == true and UnitAffectingCombat("player") then
                        if not BAR['obj'].anim:IsPlaying() then
                                BAR['obj']:SetValue(500)
                                BAR['obj'].text:SetText('')
                                if BAR['expire'] ~= -1 then
                                        BAR['expire'] = -1
                                        if BAR['obj']:IsVisible() then
                                                SliceCommander:PlayCDSound(BAR)
                                        end
                                end
                                if not BAR['obj']:IsVisible() then
                                        if _G['SC'].SET.SpellText == true then
                                                BAR['obj'].text2:SetText(string.format("%s", BAR['name'].." (CD)"))
                                        else
                                                BAR['obj'].text2:SetText('')
                                        end
                                        BAR['obj']:Show()
                                        SliceCommander:ChangeAnchor()
                                end
                                BAR['obj'].anim:Play()
                        end
                else
                        BAR['expire'] = 0
                        if BAR['obj']:IsVisible() then
                                if BAR['obj'].anim:IsPlaying() then
                                        BAR['obj'].anim:Stop()
                                else
                                        SliceCommander:PlayCDSound(BAR)
                                end
                                SliceCommander:HideBar(BAR)
                        end
                end
                return
        end
        
        BAR['expire'] = (start+duration)
        local x
        if BAR['expire'] > 0 and _G['SC'].tNow < BAR['expire'] then
                x = BAR['expire'] - _G['SC'].tNow
        else
                x = 0
        end
        
        local textcount = ''
        if charges > 0 then
                textcount = ' x'..charges
        end
        if not BAR['count'] or BAR['count'] ~= charges then
                if _G['SC'].SET.SpellText == true then
                        BAR['obj'].text2:SetText(string.format("%s", BAR['name'].." (CD)"..textcount))
                else
                        BAR['obj'].text2:SetText(textcount)
                end
        end
        
        BAR['obj']:SetValue(x)
        BAR['obj'].text:SetText(string.format("%0.1f", x))
end

function SliceCommander:EnableBar(BAR, duration, text, expire)
        BAR['expire'] = expire
        if _G['SC'].SET.FullTimer == true and duration then
                BAR['obj']:SetMinMaxValues(0, duration)
        else
                BAR['obj']:SetMinMaxValues(0, 6.0)
        end
        if _G['SC'].SET.SpellText == true then
                BAR['obj'].text2:SetText(string.format("%s", text))
        else
                BAR['obj'].text2:SetText('')
        end
        BAR['obj']:Show()
        SliceCommander:ChangeAnchor()
end

function SliceCommander:HideBar(BAR)
        if BAR['obj'].anim:IsPlaying() then
                BAR['obj'].anim:Stop()
        end
        BAR['expire'] = 0
        BAR['obj']:Hide()
        BAR['obj'].text:SetText("")
        SliceCommander:ChangeAnchor()
end

function SliceCommander:HideIcon(BAR)
        if BAR['obj'].anim:IsPlaying() then
                BAR['obj'].anim:Stop()
        end
        BAR['expire'] = 0
        BAR['obj']:Hide()
        BAR['obj'].text:SetText("")
end

function SliceCommander:UpdateBar(spell, typespell)
        local BAR, name, expire, icon, count, duration, unitCaster, x, _, maxValue, widthSeconde, value1, value2, value3, spellId, last, spellIds, currentId
        if typespell == 'BARS' then
                BAR = _G['SC'].BARS[spell]
        elseif typespell == 'ICONS' then
                BAR = _G['SC'].ICONS[spell]
        end

        if _G['SC'].SET.display[spell] ~= true then
                BAR['expire'] = 0
                if BAR['obj']:IsVisible() then
                        SliceCommander:HideBar(BAR)
                end
                return
        end
        if _G['SC'].tNow == nil then
                _G['SC'].tNow = GetTime()
        end

        value1, value2, value3 = 0 , 0, 0
        last = BAR['expire']
        local spellIds
        if type(BAR['id']) == "table" then
                spellIds = BAR['id']
        else
                spellIds = {BAR['id']}
        end
        
        for _,currentId in pairs(spellIds) do
                if BAR['type'] == 1 then
                        _, icon, count, _, duration, expire, unitCaster, _, _, _, _, _, _, _, _, value1, value2, value3 = SliceCommander:UnitAura("player", currentId, "HELPFUL PLAYER")
                elseif BAR['type'] == 2 then
                        _, icon, count, _, duration, expire, unitCaster, _, _, spellId = SliceCommander:UnitAura("target", currentId, "HARMFUL PLAYER")
                elseif BAR['type'] == 3 then
                        _, icon, count, _, duration, expire, unitCaster = SliceCommander:UnitAura("player", currentId, "HARMFUL")
                end
                if expire then break end
        end
        
        if unitCaster ~= "player" and BAR['type'] ~= 3 and unitCaster ~= nil then
                expire = last
        end

        BAR['expire'] = expire
        if expire == nil then
                if _G['SC'].SET.flash[spell] == true and UnitAffectingCombat("player") then
                        if not BAR['obj'].anim:IsPlaying() then
                                if typespell == 'BARS' then
                                        BAR['obj']:SetValue(500)
                                end
                                BAR['obj'].text:SetText('')
                                if BAR['expire'] ~= -1 then
                                        BAR['expire'] = -1
                                        if BAR['obj']:IsVisible() then
                                                if BAR['sound'] ~= nil then
                                                        SliceCommander:PlaySound(BAR['sound']['expired'])
                                                end
                                        end
                                end
                                if not BAR['obj']:IsVisible() then
                                        if _G['SC'].SET.SpellText == true then
                                                BAR['obj'].text2:SetText(string.format("%s", BAR['name']))
                                        else
                                                BAR['obj'].text2:SetText('')
                                        end
                                        BAR['obj'].icon:SetTexture(SC_SPELL_ICON[spell])
                                        BAR['obj']:Show()
                                        if typespell == 'BARS' then
                                                SliceCommander:ChangeAnchor()
                                        end
                                end
                                BAR['obj'].anim:Play()
                        end
                else
                        BAR['expire'] = expire
                        if BAR['obj']:IsVisible() then
                                if BAR['obj'].anim:IsPlaying() then
                                        BAR['obj'].anim:Stop()
                                elseif BAR['sound'] ~= nil then
                                        SliceCommander:PlaySound(BAR['sound']['expired'])
                                end
                                if typespell == 'BARS' then
                                        SliceCommander:HideBar(BAR)
                                else
                                        SliceCommander:HideIcon(BAR)
                                end
                        end
                end
        else    
                if expire > 0 and _G['SC'].tNow < expire then
                        x = expire - _G['SC'].tNow
                else
                        x = 0
                end
                
                if x >= 0 then
                        local xlast
                        if typespell == 'BARS' then
                                xlast = SliceCommander:ShowBar(BAR, duration, icon)
                        else
                                xlast = SliceCommander:ShowIcon(BAR, icon)
                        end
                        
                        if typespell == 'BARS' then
                                local textcount = ''
                                if count and count > 1 then
                                        textcount = ' x'..count
                                end
                                if value1 == 162 and value2 == 0 and value3 == 19 then
                                        textcount = textcount..' - '..L['Empowered']
                                        count = value1..value2..value3
                                end
                                if not BAR['count'] or BAR['count'] ~= count then
                                        if _G['SC'].SET.SpellText == true then
                                                BAR['obj'].text2:SetText(string.format("%s", BAR['name']..textcount))
                                        else
                                                BAR['obj'].text2:SetText(textcount)
                                        end
                                end
                                BAR['count'] = count
                        end
                        
                        if x > 0 then
                                if typespell == 'BARS' then
                                        BAR['obj']:SetValue(x)
                                end
                                BAR['obj'].text:SetText(string.format("%0.1f", x))
                        else
                                if typespell == 'BARS' then
                                        BAR['obj']:SetValue(6)
                                end
                                BAR['obj'].text:SetText('')
                        end
                        
                        if typespell == 'BARS' then
                                SliceCommander:Tick(BAR, x)
                                SliceCommander:Pandemic(BAR, x)
                                SliceCommander:SoundBar(BAR, x, xlast)
                        end
                end             
        end
end

function SliceCommander:CreateTOTMacro()
        if not UnitAffectingCombat("player") then
                local alreadyExist = GetMacroBody("SC_TOT")
                if alreadyExist then
                        EditMacro("SC_TOT", "SC_TOT", "INV_MISC_QUESTIONMARK", "#showtooltip\n/cast [@".._G['SC'].SET.TOTTarget..",modifier:alt] [help] [@targettarget, help][@none,@".._G['SC'].SET.TOTTarget.."] "..GetSpellInfo(SC_SPELL['TOTCD']), 1, 1)
                else
                        CreateMacro("SC_TOT", "INV_MISC_QUESTIONMARK", "#showtooltip\n/cast [@".._G['SC'].SET.TOTTarget..",modifier:alt] [help] [@targettarget, help][@none,@".._G['SC'].SET.TOTTarget.."] "..GetSpellInfo(SC_SPELL['TOTCD']), 1, 1)
                end
        end
end

function SliceCommander:HealthBar(bar)
        if _G['SC'].SET.display[bar] then
                local HP, maxHP, pourcentHP, hexCol, rCol, gCol, bCol, healthText
                HP = UnitHealth(_G['SC'].BARS[bar]['target'])
                maxHP = UnitHealthMax(_G['SC'].BARS[bar]['target'])
                if maxHP ~= 0 then
                        pourcentHP = (HP / maxHP) * 100
                else
                        pourcentHP = 0
                end
                if maxHP == nil then
                        maxHP = 0
                end
                if HP == nil then
                        HP = 0
                end
                if HP == 0 then
                        if _G['SC'].BARS[bar]['obj']:IsVisible() then
                                _G['SC'].BARS[bar]['obj']:Hide()
                        end
                        _G['SC'].BARS[bar]['expire'] = 0
                else
                        if _G['SC'].BARS[bar]['expire'] > 35 and pourcentHP < 35 then
                                SliceCommander:PlaySound(_G['SC'].SET[bar].LowUnder)
                        elseif _G['SC'].BARS[bar]['expire'] > 50 and pourcentHP < 50 then
                                SliceCommander:PlaySound(_G['SC'].SET[bar].MidUnder)
                        end
                        hexCol = (100-pourcentHP)*(255/100)
                        rCol = hexCol
                        gCol = 255-hexCol
                        if rCol > 210 then
                                rCol = 210
                        end
                        if rCol < 50 then
                                rCol = 50
                        end
                        if gCol > 210 then
                                gCol = 210
                        end
                        if gCol < 50 then
                                gCol = 50
                        end
                        bCol = 50

                        if _G['SC'].SET[bar].HideCombat and not UnitAffectingCombat("player") then
                                if _G['SC'].BARS[bar]['obj']:IsVisible() then
                                        _G['SC'].BARS[bar]['obj']:Hide()
                                end
                                _G['SC'].BARS[bar]['expire'] = 0
                        else
                                if not _G['SC'].BARS[bar]['obj']:IsVisible() then
                                        _G['SC'].BARS[bar]['obj']:Show()
                                end
                                _G['SC'].BARS[bar]['expire'] = pourcentHP
                        end
                        _G['SC'].BARS[bar]['obj']:SetValue(pourcentHP)
                        if _G['SC'].SET[bar].value then
                                if HP > 1000000000 then
                                        healthText = string.format("%0.1f", HP/1000000000)..'G'
                                elseif HP > 1000000 then
                                        healthText = string.format("%0.1f", HP/1000000)..'M'
                                elseif HP > 1000 then
                                        healthText = string.format("%0.1f", HP/1000)..'K'
                                else
                                        healthText = HP
                                end
                        else
                                healthText = string.format("%0.1f", pourcentHP)
                        end
                        _G['SC'].BARS[bar]['obj'].text:SetText(healthText)
                        _G['SC'].BARS[bar]['obj']:SetStatusBarColor(rCol/255,gCol/255,bCol/255)
                end
        else
                _G['SC'].BARS[bar]['expire'] = 0
                _G['SC'].BARS[bar]['obj']:Hide()
        end
end


function SliceCommander:TargetThreat()
    local hexCol, rCol, gCol, bCol
        if _G['SC'].SET.display.THREAT == false or (_G['SC'].SET.ThreatGroupOnly and IsInRaid() == false and IsInGroup() == false) then
                _G['SC'].BARS['THREAT']['expire'] = 0
        else
                local isTanking, status, threatpct, rawthreatpct, threatvalue = UnitDetailedThreatSituation("player", "target")
                if rawthreatpct == nil then
                        _G['SC'].BARS['THREAT']['expire'] = 0
                else
                        hexCol = rawthreatpct *(255/110)
                        rCol = hexCol-45
                        gCol = 255-hexCol+50
                        if isTanking == 1 then
                                rCol = 210
                                gCol = 50
                                rawthreatpct = 100
                        end
                        if rCol > 210 then
                                rCol = 210
                        end
                        if rCol < 50 then
                                rCol = 50
                        end
                        if gCol > 210 then
                                gCol = 210
                        end
                        if gCol < 50 then
                                gCol = 50
                        end
                        bCol = 50
                        _G['SC'].BARS['THREAT']['expire'] = rawthreatpct
                end
        end
        if _G['SC'].BARS['THREAT']['expire'] == 0 then
                _G['SC'].BARS['THREAT']['obj']:Hide()
        else
                _G['SC'].BARS['THREAT']['obj']:SetValue(_G['SC'].BARS['THREAT']['expire'])
                _G['SC'].BARS['THREAT']['obj'].text:SetText(string.format("%0.1f", _G['SC'].BARS['THREAT']['expire']))
                _G['SC'].BARS['THREAT']['obj']:SetStatusBarColor(rCol/255,gCol/255,bCol/255)
                _G['SC'].BARS['THREAT']['obj']:Show()
                SliceCommander:ChangeAnchor()
        end
end

function SliceCommander:SetTransparency(value)
        VTimerEnergy:SetAlpha(value/100)
        _G['SC'].OTHER['AS']['obj']:SetAlpha(value/100)
end

function SliceCommander:TestDP()
        local combat = UnitAffectingCombat("player")
        if _G['SC'].SET.display.DPICON then --and GetSpecialization() == 1
                local aSpec = GetSpecialization()
                local mhPoison = _G['SC'].SET.poison.mh[aSpec]
                local ohPoison = _G['SC'].SET.poison.oh[aSpec]
                local _, _, _, selected = GetTalentInfo(4, 1, 1)
                if not selected and ohPoison == SC_SPELL['LP'] then
                        ohPoison = 'CRP'
                end
                
                local name, _, _, _, _, expirationTime = SliceCommander:UnitAura("player", SC_SPELLID[mhPoison], "HELPFUL PLAYER")
                local name2, _, _, _, _, expirationTime2 = SliceCommander:UnitAura("player", SC_SPELLID[ohPoison], "HELPFUL PLAYER")
                
                local minimalTime = _G['SC'].SET.display.DPTIME*60

                if IsMounted() or ((name and ((expirationTime-_G['SC'].tNow) > minimalTime or combat)) and (name2 and ((expirationTime2-_G['SC'].tNow) > minimalTime or combat))) then
                        if _G['SC'].SET.IsLocked == true then
                                if _G['SC'].OTHER['POISON']['obj']:GetAlpha() == 1 then
                                        _G['SC'].OTHER['POISON']['obj']:SetAlpha(0)
                                        _G['SC'].OTHER['POISON']['obj'].anim:Stop()
                                end
                                if not combat and _G['SC'].OTHER['POISON']['obj'].button:IsMouseEnabled() then
                                        _G['SC'].OTHER['POISON']['obj'].button:EnableMouse(false)
                                        _G['SC'].OTHER['POISON']['obj'].anim:Stop()
                                end
                        end
                elseif not name or not name2 or (((expirationTime-_G['SC'].tNow) < minimalTime or (expirationTime2-_G['SC'].tNow) < minimalTime) and not combat) and not IsMounted() then
                        if _G['SC'].OTHER['POISON']['obj']:GetAlpha() ~= 1 then
                                SliceCommander:PlaySoundReal(_G['SC'].SET.DPSound)
                                _G['SC'].OTHER['POISON']['obj']:SetAlpha(1)
                                _G['SC'].OTHER['POISON']['obj'].anim:Play()
                        end
                        if not combat and not _G['SC'].OTHER['POISON']['obj'].button:IsMouseEnabled() and _G['SC'].SET.display.DPBUT then
                                _G['SC'].OTHER['POISON']['obj'].button:EnableMouse(true)
                                _G['SC'].OTHER['POISON']['obj'].anim:Play()
                        end
                end
        else
                if _G['SC'].SET.IsLocked == true then
                        if _G['SC'].OTHER['POISON']['obj']:GetAlpha() == 1 then
                                _G['SC'].OTHER['POISON']['obj']:SetAlpha(0)
                                _G['SC'].OTHER['POISON']['obj'].anim:Stop()
                        end
                        if not combat and _G['SC'].OTHER['POISON']['obj'].button:IsMouseEnabled() then
                                _G['SC'].OTHER['POISON']['obj'].button:EnableMouse(false)
                                _G['SC'].OTHER['POISON']['obj'].anim:Stop()
                        end
                end
        end
end

function SliceCommander:UnitAura(target, spell, filter) 
        local i, name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod
        i = 1
        repeat
                name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod = UnitAura(target, i, filter)
                i = i+1
        until not name or spellId == spell
        return name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, nameplateShowPersonal, spellId, canApplyAura, isBossDebuff, isCastByPlayer, nameplateShowAll, timeMod
end

function SliceCommander:Latency()
        local _
        _G['SC'].tNow = GetTime()
        if (_G['SC'].SET.PadLatency) then
                 _, _, _G['SC'].lag = GetNetStats()
                _G['SC'].tNow = _G['SC'].tNow + (_G['SC'].lag*2/1000)
        end
end

function SliceCommander:Energy()
        local value = UnitPower("player", Enum.PowerType.Energy)
        VTimerEnergy:SetValue(value)
        VTimerEnergy:SetMinMaxValues(0,UnitPowerMax("player", Enum.PowerType.Energy))
        VTimerEnergyTxt:SetText(value)

        if UnitPowerMax("player", Enum.PowerType.Energy) == UnitPower("player", Enum.PowerType.Energy) and not UnitAffectingCombat("player") then
                SliceCommander:SetTransparency(_G['SC'].SET.EnergyTrans)
        else
                SliceCommander:SetTransparency(_G['SC'].SET.FrameOpacity)
        end
end

function SliceCommander:GCD()
        if not _G['SC'].OTHER['AS']['expire'] then return _G['SC'].OTHER['AS']['obj']:Hide() end

        local val = (_G['SC'].OTHER['AS']['expire']-GetTime())
        if val < 0 then
                _G['SC'].OTHER['AS']['expire'] = nil
        else
                _G['SC'].OTHER['AS']['obj']:SetValue(val)
        end
end

function SliceCommander:SoundBar(BAR, current, previous)
        if BAR['sound'] ~= nil then
                if previous >= 3 and current < 3 then
                        SliceCommander:PlaySound(BAR['sound']['alert3'])
                elseif previous >= 2 and current < 2 then
                        SliceCommander:PlaySound(BAR['sound']['alert2'])
                elseif previous >= 1 and current < 1 then
                        SliceCommander:PlaySound(BAR['sound']['alert1'])
                end

                if previous > 0 and previous <= 1 and current > 1 then
                        SliceCommander:PlaySound(BAR['sound']['refresh1'])
                elseif previous <= 2 and current > 2 then
                        SliceCommander:PlaySound(BAR['sound']['refresh2'])
                elseif previous <= 3 and current > 3 then
                        SliceCommander:PlaySound(BAR['sound']['refresh3'])
                end
        end
end

function SliceCommander:Pandemic(BAR, current)
        if _G['SC'].SET.Pandemic and BAR['pandemic'] then
                local timers = BAR['pandemictimer']
                local maxCP = UnitPowerMax("player", Enum.PowerType.ComboPoints)
                if maxCP > 6 then
                        maxCP = 5
                end
                if type(timers) ~= 'table' then
                        timers = {}
                        for i = 0, maxCP do
                                timers[i] = BAR['pandemictimer']
                        end
                end
                if BAR['pandemicobj']  == nil then
                        BAR['pandemicobj'] = SliceCommander:NewTickArray(BAR)
                        BAR['pandemicobj']:SetVertexColor(1, 0, 0, 1)
                end
                local _, maxValue = BAR['obj']:GetMinMaxValues()
                local widthSeconde = (BAR['obj']:GetWidth())/maxValue
                local value = current-(timers[maxCP]*.3)
                if value >= 0 and value <= maxValue then
                        BAR['pandemicobj']:Show()
                        BAR['pandemicobj']:SetPoint("LEFT", BAR['obj'], "LEFT", widthSeconde*value, 0)
                else
                        BAR['pandemicobj']:Hide()
                end
                if value <= 0 then
                        BAR['obj'].text:SetTextColor(0, 1, 0)
                else
                        BAR['obj'].text:SetTextColor(.835, .784, .722)
                end
        end
end

function SliceCommander:Tick(BAR, current)
        if _G['SC'].SET.Tick and BAR['tick'] ~= nil and BAR['tick']['value'] ~= nil then
                local tick = BAR['tick']['value']
                local _, maxValue = BAR['obj']:GetMinMaxValues()
                local widthSeconde = (BAR['obj']:GetWidth())/maxValue
                local value = (current % tick)
                if value == 0 then
                        value = tick
                end
                local j = maxValue/BAR['tick']['value'];
                for i = 1,j do
                        if BAR['tick']['obj'][i] == nil then
                                BAR['tick']['obj'][i] = SliceCommander:NewTickArray(BAR)--CREATE TICK OBJECT IF NECESSARY
                        end
                        if value > current or value > maxValue then
                                BAR['tick']['obj'][i]:Hide()
                        else
                                BAR['tick']['obj'][i]:Show()
                                BAR['tick']['obj'][i]:SetPoint("LEFT", BAR['obj'], "LEFT", widthSeconde*value, 0)
                                value = value+tick
                        end
                end
        end
end

function SliceCommander:ShowBar(BAR, duration, icon)
        if not BAR['obj']:IsVisible() or BAR['obj'].anim:IsPlaying() then
                if BAR['obj'].anim:IsPlaying() then
                        BAR['obj'].anim:Stop()
                end
                if BAR['sound'] ~= nil then
                        SliceCommander:PlaySound(BAR['sound']['applied'])
                end
                if icon then
                        BAR['obj'].icon:SetTexture(icon)
                end
                SliceCommander:EnableBar(BAR, duration, BAR['name'], BAR['expire'])

                return 0
        else
                return BAR['obj']:GetValue()
        end
end

function SliceCommander:ShowIcon(ITEM, icon)
        if not ITEM['obj']:IsVisible() then
                if ITEM['obj'].anim:IsPlaying() then
                        ITEM['obj'].anim:Stop()
                end
                ITEM['obj'].anim:Play()
                if ITEM['sound'] ~= nil then
                        SliceCommander:PlaySound(ITEM['sound']['applied'])
                end
                if icon then
                        ITEM['obj'].icon:SetTexture(icon)
                end
                ITEM['obj'].overlay:Show()
                ITEM['obj']:Show()
                
                return 0
        end
        return 1
end

function SliceCommander:MultipleAbilityBar(spell)
        local BAR = _G['SC'].BARS[spell]
        local expire, duration, tempDuration, x, _, expire
        if _G['SC'].SET.display[spell] ~= true then
                BAR['expire'] = 0
                if BAR['obj']:IsVisible() then
                        SliceCommander:HideBar(BAR)
                end
                return
        end

        local last = BAR['expire']
        local spellname = {}
        BAR['expire'] = 0
        
        local spellduration = {}
        
        for k, v in pairs(BAR.subbar) do
                _, _, _, _, tempDuration, expire = SliceCommander:UnitAura("player", k, "HELPFUL PLAYER")
                if expire ~= nil then
                        if _G['SC'].SET.RB[v] then
                                spellname[v] = _G['SC'].SET.RB[v]
                                spellduration[v] = expire
                        end
                        if expire > BAR['expire'] then
                                duration = tempDuration
                                BAR['expire'] = expire
                        end
                end
        end
        
        if _G['SC'].tNow == nil then
                _G['SC'].tNow = GetTime()
        end
        if BAR['expire'] > 0 and _G['SC'].tNow < BAR['expire'] then
                x = BAR['expire'] - _G['SC'].tNow
        else
                x = 0
        end
        if x > 0 then
                local xlast = SliceCommander:ShowBar(BAR, duration, false)

                if _G['SC'].SET.SpellText == true then
                        local displayConcatName = spell..'Name'
                        if _G['SC'].SET.display[displayConcatName] and next(spellname) ~= nil then
                                local label = ''
                                for k, v in pairs(spellduration) do
                                        if v == BAR['expire'] then
                                                if label ~= '' then
                                                        label = label .. ' - '
                                                end
                                                label = label .. spellname[k]
                                        end
                                end
                                for k, v in pairs(spellduration) do
                                        if v ~= BAR['expire'] then
                                                local xOther = v - _G['SC'].tNow
                                                label = label .. ' - |cff33bb33' .. spellname[k] .. '|r'-- .. ' (' .. string.format("%0.1f", xOther) .. ')|r'
                                        end
                                end
                                BAR['obj'].text2:SetText(label)
                        else
                                BAR['obj'].text2:SetText(BAR['name'])
                        end
                end
                BAR['obj']:SetValue(x)
                BAR['obj'].text:SetText(string.format("%0.1f", x))

                SliceCommander:Pandemic(BAR, x)
                SliceCommander:SoundBar(BAR, x, xlast)
        else
                if _G['SC'].SET.flash[spell] == true and UnitAffectingCombat("player") then
                        if not BAR['obj'].anim:IsPlaying() then
                                BAR['obj']:SetValue(500)
                                BAR['obj'].text:SetText('')
                                if BAR['expire'] ~= -1 then
                                        BAR['expire'] = -1
                                        if BAR['obj']:IsVisible() then
                                                SliceCommander:PlaySound(BAR['sound']['expired'])
                                        end
                                end
                                if not BAR['obj']:IsVisible() then
                                        if _G['SC'].SET.SpellText == true then
                                                BAR['obj'].text2:SetText(string.format("%s", BAR['name']))
                                        else
                                                BAR['obj'].text2:SetText('')
                                        end
                                        BAR['obj']:Show()
                                        SliceCommander:ChangeAnchor()
                                end
                                BAR['obj'].anim:Play()
                        end
                else
                        if BAR['obj']:IsVisible() then
                                if BAR['obj'].anim:IsPlaying() then
                                        BAR['obj'].anim:Stop()
                                end
                                if BAR['sound'] ~= nil and BAR['expire'] ~= -1 then
                                        SliceCommander:PlaySound(BAR['sound']['expired'])
                                end
                                SliceCommander:HideBar(BAR)
                        end
                end
        end
end

--MAIN
SLASH_RELOADUI1 = "/rl"
SlashCmdList.RELOADUI = ReloadUI

SLASH_SLICECOMMANDER1 = "/slicecommander"
SLASH_SLICECOMMANDER2 = "/sc"
SlashCmdList["SLICECOMMANDER"] = function(msg, editbox)
        local command, rest = msg:match("^(%S*)%s*(.-)$")
        if command == "lock" or command == "unlock" then
                SliceCommander:LockCkecked(not _G['SC'].SET.IsLocked)
        elseif command == "eyefinity" and tonumber(rest) then
                _G['SC'].SET.eyefinity = rest
                ReloadUI()
        elseif command == "tot" then
                if rest == nil or rest == '' or not tostring(rest) then
                        name, realm = UnitName("target")
                        if name then
                                rest = name
                                if realm then
                                        rest = name..'-'..realm
                                end
                        end
                end
                if rest and tostring(rest) then
                        rest = tostring(rest)
                        _G['SC'].SET.TOTTarget = rest
                        SliceCommander:CreateTOTMacro()
                        print(L['Macro update'])
                else
                        print(L['Macro update failed!'])
                end
        elseif command == "resolution" and tostring(rest) then
                _G['SC'].SET.fixedResolution = rest
                ReloadUI()
        else
                InterfaceOptionsFrame_OpenToCategory("SliceCommander "..GetAddOnMetadata("SliceCommander", "Version"))
                InterfaceOptionsFrame_OpenToCategory("SliceCommander "..GetAddOnMetadata("SliceCommander", "Version"))
        end
end

Compare with Previous | Blame