Quantcast WoWInterface: SVN - ProcWatch - Rev 9 - /trunk/zz_ProcWatch/core.lua

WoWInterface SVN ProcWatch

[/] [trunk/] [zz_ProcWatch/] [core.lua] - Rev 9

Compare with Previous | Blame | View Log

-- pong.wav source http://www.freesound.org/samplesViewSingle.php?id=88381
-- oops.wav, Laugh.wav, amazing.wav source ftp://ftp.team17.com/pub/t17/worms2/sounds/MKWorm.ZIP
local addonname, addontable = ...
local addon = LibStub("LibzzAddOnInit"):Init(...)
local LBF = LibStub("LibButtonFacade", true)
local LSM = LibStub("LibSharedMedia-3.0",true)
local LBFGroup
local L
local button = {}
local buttonCount = 0
local timeElapsed = 0
local buffs = {}
local invSlot = 0
local auras = {}
local enchantDuration = 1
local hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges, hasThrownEnchant, thrownExpiration, thrownCharges
local nameWeaponEnchant,iconWeaponEnchant,expirationTimeWeaponEnchant,countWeaponEnchant
local idSpellCD, nameSpellCD, rankSpellCD, iconSpellCD, costSpellCD, isFunnelSpellCD, powerTypeSpellCD, castTimeSpellCD, minRangeSpellCD, maxRangeSpellCD, startSpellCD, durationSpellCD, enabledSpellCD
local txt,index,lsort
local tbl,ex = {},false
local spellBook = {}
local spellName, spellRank
local checkTime, lastTime
local spellInfoDB = {}
local tooltipSort1, tooltipSort2,tooltipCount
local whitelistAura = {}
local buttonAnchor, buttonParentanchor
local pb
local buttonSpacing, buttonSpacing2
local scannedUnits = {}
local _G = _G
local pairs = pairs
local type = type
local tostring = tostring
local GetTime = GetTime
local GetInventoryItemTexture = GetInventoryItemTexture
local GetWeaponEnchantInfo = GetWeaponEnchantInfo
local GetSpellCooldown = GetSpellCooldown
local GetSpellBookItemName = GetSpellBookItemName
local IsUsableSpell = IsUsableSpell
local IsSpellInRange = IsSpellInRange
local UnitExists = UnitExists
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local UnitAura = UnitAura
local PlaySoundFile = PlaySoundFile
local PlaySound = PlaySound
local UnitAffectingCombat = UnitAffectingCombat

local scanning = false
addon['nextUpdate'] = 0
addon['nextEvent'] = 0
function addon:ADDON_LOADED()
  L = self['L']
  addon:set("Debug",false)
end

function addon:PLAYER_LOGIN()
  addon:checkDBDefault()
        if(LBF) then
                LBFGroup = LBF:Group(addon:GetName())
                LBFGroup:Skin(addon['db']['global']['lbfSkin'] or "Blizzard",addon['db']['global']['lbfGloss'] or .4,addon['db']['global']['lbfBackdrop'],addon['db']['global']['lbfColors'])
                LBF:RegisterSkinCallback(addon:GetName(), function(a, SkinID, Gloss, Backdrop, Group, Button, Colors) 
                        addon['db']['global']['lbfSkin'] = SkinID ;
                        addon['db']['global']['lbfGloss'] = Gloss ;
                        addon['db']['global']['lbfBackdrop'] = Backdrop ;
                        addon['db']['global']['lbfColors'] = Colors ;
                        addon:updateBar(true)
                end, "1")
        end
        if(LSM) then
                LSM:Register("sound","ProcWatch Pong","Interface\\AddOns\\"..addon:GetName().."\\pong.ogg")
                LSM:Register("sound","ProcWatch Oops","Interface\\AddOns\\"..addon:GetName().."\\oops.ogg")
                LSM:Register("sound","ProcWatch Laugh","Interface\\AddOns\\"..addon:GetName().."\\Laugh.ogg")
                LSM:Register("sound","ProcWatch Amazing","Interface\\AddOns\\"..addon:GetName().."\\amazing.ogg")
        end
  addon['mainframe'] = addon:getMainframe()
  addon:checkDualskill()
        
        addon:buildConfig()
    
        addon:RegisterEvent("SPELL_UPDATE_COOLDOWN")
        addon:RegisterEvent("SPELLS_CHANGED","buildSpellBook")
  addon:RegisterEvent("PLAYER_TALENT_UPDATE","checkDualskill")
        addon:RegisterEvent("PLAYER_REGEN_ENABLED")
        addon:RegisterEvent("PLAYER_REGEN_DISABLED")
        addon['configDone'] = true
        
        addon:SetScript("OnUpdate", function(self, elapsed) self:OnUpdate(elapsed) end)

        addon:PLAYER_REGEN_ENABLED()
end

local function resetDB()
        addon['db']['profile']['update'] = 0.2
        addon['db']['global']['update'] = 0.2
end

function addon:checkUpdate()
        if(addon['db']['profile']['lastVersion'] and addon['db']['profile']['lastVersion'] ~= addon['AddOnTable']['version']) then
                if(addon['AddOnTable']['version'] == "1.4") then
                        resetDB()
                end
        elseif(not addon['db']['profile']['lastVersion']) then
                resetDB()
        end
--      print("v",addon['db']['profile']['lastVersion'],addon['AddOnTable']['version'])
        addon['db']['profile']['lastVersion'] = addon['AddOnTable']['version']
end


function addon:buildConfig()
  addon['menu'] = addon:AddConfigMenu({
      ['name'] = L['Spells'],
      ['order'] = 2,
      ['childGroups'] = 'tab',
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref2",
      ['menuSet'] = "setPref2"
  })
  addon['whitelist'] = addon:AddConfigMenu({
      ['name'] = L['Whitelist'],
      ['order'] = 1,
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref2",
      ['menuSet'] = "setPref2"
  },addon['menu'])
  addon['blacklist'] = addon:AddConfigMenu({
      ['name'] = L['Blacklist'],
      ['order'] = 2,
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref2",
      ['menuSet'] = "setPref2"
  },addon['menu'])
  addon['spellsettings'] = addon:AddConfigMenu({
      ['name'] = L['Spellsettings'],
      ['order'] = 2,
      ['childGroups'] = 'tab',
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref3",
      ['menuSet'] = "setPref3"
  })
        addon['displaysetting'] = addon:AddConfigMenu({
      ['name'] = L['Display'],
      ['order'] = 3,
                        ['childGroups'] = 'tab',
      ['menuHandler'] = addon,
  })
  addon['listTools'] = addon:AddConfigMenu({
      ['name'] = L['List Tools'],
      ['order'] = 3,
      ['menuHandler'] = addon,
  },addon['menu'])
  addon['spelldefaults'] = addon:AddConfigMenu({
      ['name'] = L['Defaults'],
      ['order'] = 4,
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref3",
      ['menuSet'] = "setPref3"
  },addon['spellsettings'])
  addon['spelllist'] = addon:AddConfigMenu({
      ['name'] = L['Spellsettings'],
      ['order'] = 1,
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref3",
      ['menuSet'] = "setPref3"
  },addon['spellsettings'])
  addon['chargesSettings'] = addon:AddConfigMenu({
      ['name'] = L['Charges'],
      ['order'] = 2,
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref5",
      ['menuSet'] = "setPref5"
  },addon['displaysetting'])
  addon['timerSettings'] = addon:AddConfigMenu({
      ['name'] = L['Timer'],
      ['order'] = 3,
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref5",
      ['menuSet'] = "setPref5"
  },addon['displaysetting'])
  addon:AddConfigEntry("toggle","dragAble",L['Dragable'],L['This unlocks the spellbar'],2)
  addon:AddConfigEntry("toggle","showTooltip",L['Show Tooltip'],L['Shows the spells tooltip'],2)
  addon:AddConfigEntry("range","scale",L['Scale'],L['Scales the spellbar'],1,.25,2,.01,true)
  addon:AddConfigEntry("range","update",L['Refresh'],L['Sets Refreshrate of the spellbar.'],1,.1,2,.1,false)
  addon:AddConfigEntry("select","whitelist",L['Listmode'],L['Whitelist means only spells added to the whitelist are displayed and new spells are put on blacklist. Blacklist will add new spells to the whitelist.'],3,"buildSelect")
  addon:AddConfigEntry("select","sorting",L['Sorting'],L['Sort the displayed buffs'],3,"buildSort")
  addon:AddConfigEntry("toggle","reverse",L['Reverse'],L['Reverse the sorting.'],4)
        addon:AddConfigEntry("toggle","removeAura",L['Cancel Aura'],L['Allows Mouseclick to cancel a spell'],4)
  addon:AddConfigEntry("range","spacing",L['Spacing'],L['Sets the spacing between two spells'],5,-32,32,1,false)
        addon:AddConfigEntry("toggle","vertical",L['Vertical'],L['Display spells vertically'],6)
        addon:AddConfigEntry("toggle","growth",L['Growth'],L['Invert the growth direction of spells'],7)
        
  addon:AddConfigEntry("toggle","charges",L['Charges'],L['Show charges'],1,nil,nil,nil,nil,addon['spelldefaults'])
        addon:AddConfigEntry("toggle","showTextTimer",L['Timer'],L['Show Text Timer'],4,nil,nil,nil,nil,addon['spelldefaults'])
  addon:AddConfigEntry("toggle","static",L['Static'],L['Show spell when inactive'],2,nil,nil,nil,nil,addon['spelldefaults'])
        addon:AddConfigEntry("toggle","playSound",L['Play Sound'],L['Play a sound when this spell is active'],5,nil,nil,nil,nil,addon['spelldefaults'])
  addon:AddConfigEntry("range","priority",L['Order'],L['Defines the priority on the spellbar.'],3,1,100,1,false,addon['spelldefaults'])
  addon:AddConfigEntry("select","soundEffect",L['Sound'],nil,6,"buildSoundlist",nil,nil,nil,addon['spelldefaults'])
        addon:AddConfigEntry("toggle","ignoreMeOmniCC",L['Disable OmniCC'],nil,7,nil,nil,nil,nil,addon['spelldefaults'])
        addon:AddConfigEntry("select","warning",L['Warning'],L['Show a warning when missing'],8,"buildWarning",nil,nil,nil,addon['spelldefaults'])
        addon:AddConfigEntry("toggle","warningOnly",L['Warning only'],L['Hide spell until warning'],9,nil,nil,nil,nil,addon['spelldefaults'])
        
        addon:AddConfigEntry("execute","exe1",L['Reset to Blacklist'],L['All spells are moved to whitelist'],1,"resetToBlackList",nil,nil,nil,addon['listTools'])
        addon:AddConfigEntry("execute","exe2",L['Reset to Whitelist'],L['All spells are moved to blacklist'],2,"resetToWhiteList",nil,nil,nil,addon['listTools'])
        addon:AddConfigEntry("execute","exe3",L['Delete Blacklist'],L['All spells removed from blacklist'],3,"deleteBlackList",nil,nil,nil,addon['listTools'])
        addon:AddConfigEntry("execute","exe4",L['Delete Whitelist'],L['All spells removed from whitelist'],4,"deleteWhiteList",nil,nil,nil,addon['listTools'])

        addon:AddConfigEntry("select","chargesFont",L['Font'],nil,1,"buildFontlist",nil,nil,nil,addon['chargesSettings'])
        addon:AddConfigEntry("range","chargesSize",L['Size'],nil,2,16,41,1,false,addon['chargesSettings'])
        addon:AddConfigEntry("color","chargesColor",L['Color'],nil,3,
                function() 
                        return addon['db']['global']['chargesColor'][1],addon['db']['global']['chargesColor'][2],addon['db']['global']['chargesColor'][3],addon['db']['global']['chargesColor'][4]
                end,
                function(self,a,b,c,d) 
                        addon['db']['global']['chargesColor'] = { a,b,c,d }
                        addon:updateBar(true)
                end,
        nil,nil,addon['chargesSettings'])
        addon:AddConfigEntry("select","chargesAnchor",L['Anchor'],nil,4,"buildAnchor",nil,nil,nil,addon['chargesSettings'])
        addon:AddConfigEntry("range","xOffset",L['X-Offset'],nil,5,-64,64,1,false,addon['chargesSettings'])
        addon:AddConfigEntry("range","yOffset",L['Y-Offset'],nil,6,-64,64,1,false,addon['chargesSettings'])
        addon:AddConfigEntry("select","fontAnchorX",L['Font Anchor X'],nil,4,"buildFontAnchor",nil,nil,nil,addon['chargesSettings'])
        addon:AddConfigEntry("select","fontAnchorY",L['Font Anchor Y'],nil,4,"buildFontAnchorY",nil,nil,nil,addon['chargesSettings'])
        
        addon:AddConfigEntry("select","timerFont",L['Font'],nil,1,"buildFontlist",nil,nil,nil,addon['timerSettings'])
        addon:AddConfigEntry("range","timerSize",L['Size'],nil,2,16,41,1,false,addon['timerSettings'])
        addon:AddConfigEntry("color","timerColor",L['Color'],nil,3,
                function() 
                        return addon['db']['global']['timerColor'][1],addon['db']['global']['timerColor'][2],addon['db']['global']['timerColor'][3],addon['db']['global']['timerColor'][4]
                end,
                function(self,a,b,c,d) 
                        addon['db']['global']['timerColor'] = { a,b,c,d }
                        addon:updateBar(true)
                end,
        nil,nil,addon['timerSettings'])
        addon:AddConfigEntry("select","timerAnchor",L['Anchor'],nil,4,"buildAnchor",nil,nil,nil,addon['timerSettings'])
        addon:AddConfigEntry("range","timerxOffset",L['X-Offset'],nil,5,-64,64,1,false,addon['timerSettings'])
        addon:AddConfigEntry("range","timeryOffset",L['Y-Offset'],nil,6,-64,64,1,false,addon['timerSettings'])
        addon:AddConfigEntry("select","timerfontAnchorX",L['Font Anchor X'],nil,4,"buildFontAnchor",nil,nil,nil,addon['timerSettings'])
        addon:AddConfigEntry("select","timerfontAnchorY",L['Font Anchor Y'],nil,4,"buildFontAnchorY",nil,nil,nil,addon['timerSettings'])
        
  if(GetNumTalentGroups(false, false) > 1) then
    addon['dualskill'] = addon:AddConfigMenu({
      ['name'] = L['Dualskill'],
      ['order'] = 3,
      ['menuHandler'] = addon,
      ['menuGet'] = "getPref4",
      ['menuSet'] = "setPref4"
    })
    addon:AddConfigEntry("toggle","autoProfileSwitch",L['Automatic'],L['Switches profiles automaticly'],1,nil,nil,nil,nil,addon['dualskill'])
    addon:AddConfigEntry("toggle","silent",L['Quiet switching'],L['Does not announce a (needed) switch.'],2,nil,nil,nil,nil,addon['dualskill'])
    addon:AddConfigEntry("select","primaryProfile",L['Primary Profile'],nil,3,"buildProfiles",nil,nil,nil,addon['dualskill'])
    addon:AddConfigEntry("select","secondaryProfile",L['Secondary Profile'],nil,4,"buildProfiles",nil,nil,nil,addon['dualskill'])
  end
        addon:buildSpellList()
        addon:buildSpellBook()
        addon:resetSpellCDsound()
        addon.lastProfile = addon['db']:GetCurrentProfile()
end

function addon:SPELL_UPDATE_COOLDOWN()
        for k,v in pairs(spellBook) do
                if(not spellInfoDB[k]) then
                        nameSpellCD, rankSpellCD, iconSpellCD, costSpellCD, isFunnelSpellCD, powerTypeSpellCD, castTimeSpellCD, minRangeSpellCD, maxRangeSpellCD = GetSpellInfo(k)
                        spellInfoDB[k] = {
                                [1] = nameSpellCD,
                                [2] = rankSpellCD,
                                [3] = iconSpellCD,
                                [4] = costSpellCD,
                                [5] = isFunnelSpellCD,
                                [6] = powerTypeSpellCD,
                                [7] = castTimeSpellCD,
                                [8] = minRangeSpellCD,
                                [9] = maxRangeSpellCD
                        }
                else
                        nameSpellCD = spellInfoDB[k][1]
                        rankSpellCD = spellInfoDB[k][2]
                        iconSpellCD = spellInfoDB[k][3]
                        costSpellCD = spellInfoDB[k][4]
                        isFunnelSpellCD = spellInfoDB[k][5]
                        powerTypeSpellCD = spellInfoDB[k][6]
                        castTimeSpellCD = spellInfoDB[k][7]
                        minRangeSpellCD = spellInfoDB[k][8]
                        maxRangeSpellCD = spellInfoDB[k][9]
                end
                if(nameSpellCD) then
                        spellName = "SpellCD_"..k
                        startSpellCD, durationSpellCD, enabledSpellCD = GetSpellCooldown(nameSpellCD)
                        if((startSpellCD and startSpellCD > 0) and ((durationSpellCD and durationSpellCD > 1.5) or (addon['db']['profile']['auras'][spellName] and addon['db']['profile']['auras'][spellName]['static']))) then
                    ex = false
                                if(not addon['db']['profile']['auras'][spellName]) then
                                        addon['db']['profile']['auras'][spellName] = {
                                                ['warning'] = addon['db']['profile']['auras'][L['Defaults']]['warning'],
                                                ['priority'] = addon['db']['profile']['auras'][L['Defaults']]['priority'],
                                                ['charges'] = addon['db']['profile']['auras'][L['Defaults']]['charges'],
                                                ['ignoreMeOmniCC'] = addon['db']['profile']['auras'][L['Defaults']]['ignoreMeOmniCC'],
                                                ['whitelist'] = 0,
                                                ['soundPlayed'] = true,
                                                ['static'] = false
                                        }
                                        ex = true
                                end

                                addon['db']['profile']['auras'][spellName] = {
                                        ['icon'] = iconSpellCD,
                                        ['duration'] = durationSpellCD,
                                        ['expirationTime'] = startSpellCD + durationSpellCD,
                                        ['unitCaster'] = "player",
                                        ['filter'] = "HELPFUL",
                                        ['target'] = "target",
                                        ['spellCD'] = true,
                                        ['spellCDName'] = nameSpellCD,
                                        ['spellCDId'] = v,
                                        ['static'] = addon['db']['profile']['auras'][spellName]['static'],
                                        ['priority'] = addon['db']['profile']['auras'][spellName]['priority'] or addon['db']['profile']['priority'],
                                        ['whitelist'] = addon['db']['profile']['auras'][spellName]['whitelist'] or 0,
                                        ['lastTime'] = addon['db']['profile']['auras'][spellName]['lastTime'],
                                        ['lastexpirationTime'] = addon['db']['profile']['auras'][spellName]['lastexpirationTime'],
                                        ['soundEffect'] = addon['db']['profile']['auras'][spellName]['soundEffect'],
                                        ['playSound'] = addon['db']['profile']['auras'][spellName]['playSound'],
                                        ['soundPlayed'] = addon['db']['profile']['auras'][spellName]['soundPlayed'],
                                        ['showTextTimer'] = addon['db']['profile']['auras'][spellName]['showTextTimer'],
                                        ['ignoreMeOmniCC'] = addon['db']['profile']['auras'][spellName]['ignoreMeOmniCC'],
                                        ['warning'] = addon['db']['profile']['auras'][spellName]['warning'],
                                        ['spellcounter'] = addon['db']['profile']['auras'][spellName]['spellcounter'] or 0,
                                        ['spellcount'] = addon['db']['profile']['auras'][spellName]['spellcount'] or 0,
                                }
                                if(ex == true) then
                                        addon:buildSpellList()
                                end
                        end
                end
        end
end

local function addonEvent(event,arg1)
--      print(event,"-",arg1)
        if(addon['nextEvent'] < GetTime()) then
                if(event == "UNIT_AURA") then
                        if(arg1 and (UnitIsUnit(arg1,"player") or UnitIsUnit(arg1,"target") or UnitIsUnit(arg1,"focus"))) then
        --              print("sa")
                                addon['nextEvent'] = GetTime() + .2
                                addon:scanAll()
                        end
                elseif(event == "UNIT_INVENTORY_CHANGED") then
                        if(arg1 and UnitIsUnit(arg1,"player")) then
        --              print("ic")
                                addon['nextEvent'] = GetTime() + .2
                                addon:scanAll()
                        end
                end
        end
end

local function checkEvent(self,event,func)
        if(not self:IsEventRegistered(event) and type(func) == "function") then
                self:RegisterEvent(event,func)
--              print("reg", event)
        elseif(not func) then
                self:UnregisterEvent(event)
--              print("unreg", event)
        end
end

function addon:destroyButtons()
-- print("destroy")
        buttonCount = 0
        for k,v in pairs(button) do
                addon:removeButton(k, true)
        end
--      addon:checkDBDefault()
        addon:updateBar()
end

function addon:PLAYER_REGEN_ENABLED(event)
        if(event) then
                addon:destroyButtons()
        end
--      addon:SetScript("OnUpdate", nil)
--      checkEvent(addon,"UNIT_AURA",addonEvent)
--      checkEvent(addon,"UNIT_INVENTORY_CHANGED",addonEvent)
end

function addon:PLAYER_REGEN_DISABLED()
--      addon:SetScript("OnUpdate", function(self, elapsed) self:OnUpdate(elapsed) end)
--      checkEvent(addon,"UNIT_AURA",func)
end

function addon:resetToWhiteList()
        addon:resetTo(0)
end

function addon:resetToBlackList()
        addon:resetTo(1)
end

function addon:resetTo(list)
        for k,v in pairs(addon['db']['profile']['auras']) do
                if(k ~= L['Defaults']) then
                        addon['db']['profile']['auras'][k]['whitelist'] = list
                end
        end
        addon:resetSpellCD()
        addon:buildSpellList()
        addon:destroyButtons()
end

function addon:deleteBlackList()
        addon:deleteList(0)
end

function addon:deleteWhiteList()
        addon:deleteList(1)
end

function addon:deleteList(list)
        for k,v in pairs(addon['db']['profile']['auras']) do
                if(addon['db']['profile']['auras'][k]['whitelist'] == list and k ~= L['Defaults']) then
                        addon['db']['profile']['auras'][k] = nil
                end
        end
        addon:buildSpellList()
        addon:destroyButtons()
end

function addon:resetSpellCD()
        for k,v in pairs(addon['db']['profile']['auras']) do
                if(addon['db']['profile']['auras'][k]['SpellCD'] and k ~= L['Defaults']) then
                        addon['db']['profile']['auras'][k]['whitelist'] = 0
                end
        end
end

function addon:buildSpellBook()
        spellBook = {}
        spellBookCount = 0
        while true do
                spellBookCount = spellBookCount + 1
                spellName, spellRank = GetSpellBookItemName(spellBookCount, BOOKTYPE_SPELL)
                if(not spellName) then
                        break
                end
                spellBook[spellName] = spellBookCount
        end
        addon:SPELL_UPDATE_COOLDOWN()
end

function addon:resetSpellCDsound()
        for k,v in pairs(spellBook) do
                spellName = "SpellCD_"..k
                if(addon['db']['profile']['auras'][spellName]) then
                        addon['db']['profile']['auras'][spellName]['soundPlayed'] = true
                        addon['db']['profile']['auras'][spellName]['expirationTime'] = 0
                        addon['db']['profile']['auras'][spellName]['lastexpirationTime'] = 0
                end
        end
end

function addon:checkButtonSpellCD()
        if(button) then
                for k,v in pairs(button) do
                        if(addon['db']['profile']['auras'][k]) then
                                if(addon['db']['profile']['auras'][k]['spellCD']) then
                                        startSpellCD, durationSpellCD, enabledSpellCD = GetSpellCooldown(addon['db']['profile']['auras'][k]['spellCDName'])
                                        if(type(durationSpellCD) == "number" and type(startSpellCD) == "number" and startSpellCD > 0 and durationSpellCD > 1.5) then
                                                addon['db']['profile']['auras'][k]['soundPlayed'] = false
                                        elseif(type(enabledSpellCD) == "number" and type(startSpellCD) == "number" and type(durationSpellCD) == "number" and enabledSpellCD == 1 and startSpellCD == 0 and durationSpellCD == 0) then
                                                addon:auraAdded(k,false,true)
                                        end
                                end
                        end
                end
        end
end

function addon:buildWarning()
        return {
                [1] = L['Dont warn'],
                [2] = L['Only in Combat'],
                [3] = L['Only out of Combat'],
                [4] = L['Always'],
        }
end

function addon:buildFontAnchor()
        return {
                ['LEFT'] = "LEFT",
                ['RIGHT'] = "RIGHT",
                ['CENTER'] = "CENTER"
        }
end

function addon:buildFontAnchorY()
        return {
                ['TOP'] = "TOP",
                ['BOTTOM'] = "BOTTOM",
                ['MIDDLE'] = "MIDDLE"
        }
end

function addon:buildAnchor()
        return {
                "TOPLEFT",
                "TOP",
                "TOPRIGHT",
                "LEFT",
                "CENTER",
                "RIGHT",
                "BOTTOMLEFT",
                "BOTTOM",
                "BOTTOMRIGHT"
        }
end

function addon:buildSoundlist()
        if(LSM) then
                return LSM:List("sound")
        else
                return {}
        end
end

function addon:buildFontlist()
        if(LSM) then
                return LSM:List("font")
        else
                return {
                        "FRIZQT__.TTF",
                        "ARIALN.TTF",
                        "skurri.ttf",
                        "MORPHEUS.ttf",
                }
        end
end

function addon:buildProfiles()
  ex = {}
  for k,v in pairs(addon['db']['profiles']) do
    ex[k] = k
  end
  return ex
end

function addon:checkDualskill()
  addon['TalentGroup'] = GetActiveTalentGroup(false,false)
  addon['db']['global']['primaryProfile'] = addon['db']['global']['primaryProfile'] or addon['db']:GetCurrentProfile()
  addon['db']['global']['secondaryProfile'] = addon['db']['global']['secondaryProfile'] or addon['db']:GetCurrentProfile()
  if(addon['TalentGroup'] == 1 and addon['db']['global']['primaryProfile'] ~= self['db']:GetCurrentProfile()) then
    if(addon['db']['global']['autoProfileSwitch']) then
      if(not addon['db']['global']['silent']) then
        addon:Print(L['Detected a talent spec change. Switching profile.'])
      end
      addon['db']:SetProfile(addon['db']['global']['primaryProfile'])
      addon:buildSpellList()
      addontable['loadFrame'](addon.mainframe)
    else
      if(not addon['db']['global']['silent']) then
        addon:Print(L['Detected a talent spec change. You should switch profile.'])
      end
    end
  elseif(addon['TalentGroup'] == 2 and addon['db']['global']['secondaryProfile'] ~= self['db']:GetCurrentProfile()) then
    if(addon['db']['global']['autoProfileSwitch']) then
      if(not addon['db']['global']['silent']) then
        addon:Print(L['Detected a talent spec change. Switching profile.'])
      end
      addon['db']:SetProfile(addon['db']['global']['secondaryProfile'])
      addon:buildSpellList()
      addontable['loadFrame'](addon.mainframe)
    else
      if(not addon['db']['global']['silent']) then
        addon:Print(L['Detected a talent spec change. You should switch profile.'])
      end
    end
  end
        addon:checkUpdate()
end

function addon:checkDBDefault()
        addon['db']['global']['displayMode'] = addon['db']['global']['displayMode'] or 1
        addon['db']['global']['spacing'] = addon['db']['profile']['spacing'] or 8
        addon['db']['profile']['spacing'] = addon['db']['global']['spacing']
        addon['db']['global']['vertical'] = addon['db']['profile']['vertical'] or false
        addon['db']['profile']['vertical'] = addon['db']['global']['vertical']
        addon['db']['global']['growth'] = addon['db']['profile']['growth'] or false
        addon['db']['profile']['growth'] = addon['db']['global']['growth']
        addon['db']['global']['fontAnchorX'] = addon['db']['global']['fontAnchorX'] or "RIGHT"
        addon['db']['global']['fontAnchorY'] = addon['db']['global']['fontAnchorY'] or "BOTTOM"
        addon['db']['global']['chargesFont'] = addon['db']['global']['chargesFont'] or "Fonts\\SKURRI.TTF"
        addon['db']['global']['chargesSize'] = addon['db']['global']['chargesSize'] or 32
        addon['db']['global']['chargesMode'] = addon['db']['global']['chargesMode'] or "OUTLINE"
        addon['db']['global']['chargesColor'] = addon['db']['global']['chargesColor'] or { 1,1,1,1 }
        addon['db']['global']['timerfontAnchorX'] = addon['db']['global']['timerfontAnchorX'] or "LEFT"
        addon['db']['global']['timerfontAnchorY'] = addon['db']['global']['timerfontAnchorY'] or "TOP"
        addon['db']['global']['timerxOffset'] = addon['db']['global']['timerxOffset'] or -10
        addon['db']['global']['timeryOffset'] = addon['db']['global']['timeryOffset'] or 10
        addon['db']['global']['timerFont'] = addon['db']['global']['timerFont'] or "Fonts\\FRIZQT__.TTF"
        addon['db']['global']['timerSize'] = addon['db']['global']['timerSize'] or 20
        addon['db']['global']['timerMode'] = addon['db']['global']['timerMode'] or "OUTLINE"
        addon['db']['global']['timerColor'] = addon['db']['global']['timerColor'] or { 1,1,0,1 }
  addon['db']['profile']['update'] = addon['db']['profile']['update'] or 1
  addon['db']['profile']['scale'] = addon['db']['profile']['scale'] or .75
  addon['db']['profile']['whitelist'] = addon['db']['profile']['whitelist'] or 0
  addon['db']['profile']['priority'] = addon['db']['profile']['priority'] or 0
  addon['db']['profile']['sorting'] = addon['db']['profile']['sorting'] or 0
  addon['db']['profile']['auras'] = addon['db']['profile']['auras'] or {}
  addon['db']['profile']['auras'][L['Defaults']] = addon['db']['profile']['auras'][L['Defaults']] or {
                ['warningOnly'] = false,
                ['warning'] = 1,
    ['charges'] = true,
    ['static'] = false,
                ['ignoreMeOmniCC'] = false,
    ['priority'] = 1,
                ['playSound'] = false,
                ['soundEffect'] = LSM:GetDefault('sound') or nil,
                ['showTextTimer'] = false
  }
end

function addon:OnUpdate(elapsed)
--  timeElapsed = timeElapsed + elapsed
--      addon['db']['profile']['update'] = addon['db']['profile']['update'] or 1
  if(addon['nextUpdate'] < GetTime()) then
                if(addon['db']:GetCurrentProfile() ~= addon.lastProfile) then
                        addon:checkDBDefault()
                        addon:buildConfig()
                        addon:destroyButtons()
                end
    addon:scanAll()
--    timeElapsed = 0
  end
end

function addon:getListIndex(index,typ,list,def)
        for k,v in pairs(list) do
                if(LSM:Fetch(typ,v) == addon['db']['global'][index]) then
                        return k
                end
        end
        return def or 1
end

function addon:getListIndex2(index,list,def)
        for k,v in pairs(list) do
                if(list[k] == addon['db']['global'][index]) then
                        return k
                end
        end
        return def or 1
end

function addon:getPref5(info)
        if(info[#info] == 'chargesFont' or info[#info] == 'timerFont') then
                return addon:getListIndex(info[#info],"font",addon:buildFontlist(),1)
        elseif(info[#info] == 'chargesAnchor' or info[#info] == 'timerAnchor') then
                return addon:getListIndex2(info[#info],addon:buildAnchor(),1)
        end
        return addon['db']['global'][info[#info]]
end

function addon:setListIndex(index,typ,list,value)
        for k,v in pairs(list) do
                if(k == value) then
                        addon['db']['global'][index] = LSM:Fetch(typ,v)
                        break
                end
        end
end

function addon:setListIndex2(index,list,value)
        for k,v in pairs(list) do
                if(k == value) then
                        addon['db']['global'][index] = list[value]
                        break
                end
        end
end

function addon:setPref5(info,value)
        if(UnitAffectingCombat("player") ~= 1) then
                if(info[#info] == 'chargesFont' or info[#info] == 'timerFont') then
                        addon:setListIndex(info[#info],"font",addon:buildFontlist(),value)
                elseif(info[#info] == 'chargesAnchor' or info[#info] == 'timerAnchor') then
                        addon:setListIndex2(info[#info],addon:buildAnchor(),value)
                else
                        addon['db']['global'][info[#info]] = value
                end
                addon:destroyButtons()
        else
                addon:Print(L['You cant do this in combat'])
        end
end

function addon:getPref4(info)
  return addon['db']['global'][info[#info]]
end

function addon:setPref4(info,value)
  addon['db']['global'][info[#info]] = value
  addon:buildSpellList()
end

function addon:getPref3(info)
        if(info[#info] == 'soundEffect') then
                for k,v in pairs(addon:buildSoundlist()) do
                        if(LSM:Fetch("sound",v) == addon['db']['profile']['auras'][info[#info-1]]['soundEffect']) then
                                return k
                        end
                end
                return 1
        end
  return addon['db']['profile']['auras'][info[#info-1]][info[#info]]
end

function addon:setPref3(info,value)
-- print("set2",info[#info],value)
        if(UnitAffectingCombat("player") ~= 1) then
                if(info[#info] == 'soundEffect') then
                        for k,v in pairs(addon:buildSoundlist()) do
                                if(k == value) then
                                        addon['db']['profile']['auras'][info[#info-1]]['soundEffect'] = LSM:Fetch("sound",v)
                                        break
                                end
                        end
                else
                        addon['db']['profile']['auras'][info[#info-1]][info[#info]] = value
                        if(info[#info] == "warning") then
                                addon['db']['profile']['auras'][info[#info-1]]["warningIcon"] = nil
                        end                     
                end
                addon:destroyButtons()
                addon:buildSpellList()
                addon:SPELL_UPDATE_COOLDOWN()
        else
                addon:Print(L['You cant do this in combat'])
        end
end

function addon:getPref2(info)
  addon:buildSpellList()
        if(addon['db']['profile']['auras'][info[#info]]) then
                if(addon['db']['profile']['auras'][info[#info]]['whitelist'] == 1) then
                        return true
                else
                        return false
                end
        else
                        return false
        end
end

function addon:setPref2(info,value)
        if(UnitAffectingCombat("player") ~= 1) then
                if(addon['db']['profile']['auras'][info[#info]]) then
                        if(value) then
                                addon['db']['profile']['auras'][info[#info]]['whitelist'] = 1
                        else
                                addon['db']['profile']['auras'][info[#info]]['whitelist'] = 0
                        end
                end
                addon:destroyButtons()
                addon:buildSpellList()
                addon:SPELL_UPDATE_COOLDOWN()
        else
                addon:Print(L['You cant do this in combat'])
        end
end



function addon:buildSpellList()
        if(not addon.whitelist or not addon.blacklist or not addon.spelllist) then
                addon:buildConfig()
        end
  addon['whitelist']['args'] = {}
  addon['blacklist']['args'] = {}
  addon['spelllist']['args'] = {}
  addon['spellprefs'] = {}
  for k,v in pairs(addon['db']['profile']['auras']) do
    if(k ~= L['Defaults']) then
                        if(addon['db']['profile']['auras'][k]) then
                                if(addon['db']['profile']['auras'][k]['whitelist'] == 1) then
                                        addon:AddConfigEntry("toggle",k,k,nil,1,nil,nil,nil,nil,addon['whitelist'])
                                        addon['spellprefs'][k] = addon:AddConfigMenu({
                                                ['name'] = k,
                                                ['order'] = addon['db']['profile']['auras'][k]['priority'] or addon['db']['profile']['auras'][L['Defaults']]['priority'],
                                                ['menuHandler'] = addon,
                                                ['menuGet'] = "getPref3",
                                                ['menuSet'] = "setPref3"
                                        },addon['spelllist'])
                                        addon:AddConfigEntry("toggle","charges",L['Charges'],L['Show charges'],1,nil,nil,nil,nil,addon['spellprefs'][k])
                                        addon:AddConfigEntry("toggle","static",L['Static'],L['Show spell when inactive'],2,nil,nil,nil,nil,addon['spellprefs'][k])
        --                              if(not addon['db']['profile']['auras'][k]['spellCD']) then
                                                addon:AddConfigEntry("toggle","playSound",L['Play Sound'],L['Play a sound when this spell is active'],5,nil,nil,nil,nil,addon['spellprefs'][k])
                                                addon:AddConfigEntry("select","soundEffect",L['Sound'],nil,6,"buildSoundlist",nil,nil,nil,addon['spellprefs'][k])
        --                              end
                                        addon:AddConfigEntry("range","priority",L['Order'],L['Defines the priority on the spellbar.'],4,1,100,1,false,addon['spellprefs'][k])
                                        addon:AddConfigEntry("toggle","showTextTimer",L['Timer'],L['Show Text Timer'],3,nil,nil,nil,nil,addon['spellprefs'][k])
                                        addon:AddConfigEntry("toggle","ignoreMeOmniCC",L['Disable OmniCC'],L['Disable OmniCC for this spell'],7,nil,nil,nil,nil,addon['spellprefs'][k])
                                        if(not addon['db']['profile']['auras'][k]['spellCD']) then
                                                addon:AddConfigEntry("select","warning",L['Warning'],L['Show a warning when missing'],8,"buildWarning",nil,nil,nil,addon['spellprefs'][k])
                                                addon:AddConfigEntry("toggle","warningOnly",L['Warning only'],L['Hide spell until warning'],9,nil,nil,nil,nil,addon['spellprefs'][k])
                                        end
                                else
                                        addon:AddConfigEntry("toggle",k,k,nil,1,nil,nil,nil,nil,addon['blacklist'])
                                end
                        end
    end
  end
end

function addon:buildSort()
  return { [0] = L['Time'], [1] = L['Priority']}
end
function addon:buildSelect()
  return { [0] = L['Blacklist'],[1] = L['Whitelist']}
end

local function skullReset(self)
-- print("reset",self:GetName())
        self['elapsed'] = 0
        self['animSpeed'] = .1
        self['animStep'] = -0.2
        self:SetAlpha(.5)
end



function addon:scanAll()
        if scanning then return end
        scanning = true
        scannedUnits = { ['HELPFUL'] = {}, ['HARMFUL'] = {}}
--      print("update", addon['nextUpdate'],addon['db']['profile']['update'])
        addon['nextUpdate'] = GetTime() + addon['db']['profile']['update']
  auras = addon:joinTable(addon:joinTable(addon:joinTable(addon:scanBuffs("player","HELPFUL"),addon:scanBuffs("player","HARMFUL")),addon:joinTable(addon:scanBuffs("target","HELPFUL"),addon:scanBuffs("target","HARMFUL"))),addon:joinTable(addon:scanBuffs("focus","HELPFUL"),addon:scanBuffs("focus","HARMFUL")))
  hasMainHandEnchant, mainHandExpiration, mainHandCharges, hasOffHandEnchant, offHandExpiration, offHandCharges, hasThrownEnchant, thrownExpiration, thrownCharges = GetWeaponEnchantInfo()
  if(hasMainHandEnchant) then
    addon:addWeaponEnchant(L['mainhand'], GetInventoryItemTexture("player", 16), GetTime() + mainHandExpiration/1000, mainHandCharges)
    auras[#auras+1] = L['mainhand']
        else
                if(addon['db']['profile']['auras'][L['mainhand']]) then
                        addon['db']['profile']['auras'][L['mainhand']]['expirationTime'] = GetTime() - 1
                        addon['db']['profile']['auras'][L['mainhand']]['lastexpirationTime'] = addon['db']['profile']['auras'][L['mainhand']]['expirationTime']
                        addon['db']['profile']['auras'][L['mainhand']]['count'] = 0
                end
  end
  if(hasOffHandEnchant) then
    addon:addWeaponEnchant(L['offhand'], GetInventoryItemTexture("player", 17), GetTime() + offHandExpiration/1000, offHandCharges)
    auras[#auras+1] = L['offhand']
        else
                if(addon['db']['profile']['auras'][L['offhand']]) then
                        addon['db']['profile']['auras'][L['offhand']]['expirationTime'] = GetTime() - 1
                        addon['db']['profile']['auras'][L['offhand']]['lastexpirationTime'] = addon['db']['profile']['auras'][L['offhand']]['expirationTime']
                        addon['db']['profile']['auras'][L['offhand']]['count'] = 0
                end
  end
  if(hasThrownEnchant) then
    addon:addWeaponEnchant(L['thrown'], GetInventoryItemTexture("player", 18), GetTime() + thrownExpiration/1000, thrownCharges)
    auras[#auras+1] = L['thrown']
        else
                if(addon['db']['profile']['auras'][L['thrown']]) then
                        addon['db']['profile']['auras'][L['thrown']]['expirationTime'] = GetTime() - 1
                        addon['db']['profile']['auras'][L['thrown']]['lastexpirationTime'] = addon['db']['profile']['auras'][L['thrown']]['expirationTime']
                        addon['db']['profile']['auras'][L['thrown']]['count'] = 0
                end
  end
        for k,v in pairs(spellBook) do
                spellName = "SpellCD_"..k
                if((addon['db']['profile']['auras'][spellName]) and (addon['db']['profile']['auras'][spellName]['expirationTime'] > GetTime() or addon['db']['profile']['auras'][spellName]['static'])) then
                        auras[#auras+1] = spellName
                else
                        if(addon['db']['profile']['auras'][spellName]) then
                                addon['db']['profile']['auras'][spellName]['lastTime'] = checkTime
                        end
                end
        end
  
        for k,v in pairs(addon['db']['profile']['auras']) do
                addon['db']['profile']['auras'][k]['warningIcon'] = nil
                if(addon['db']['profile']['auras'][k]['warning'] and addon['db']['profile']['auras'][k]['warning'] > 1) then
                        ex = true
                  for r,s in pairs(auras) do
                                if(s == k) then
                                        ex = false
                                        break
                                end
                        end
--                      print("+",k,v['warning'],ex)
                        if(ex and (v['warning']==4 or (UnitAffectingCombat("player") and v['warning'] == 2) or (not UnitAffectingCombat("player") and v['warning'] == 3))) then
        auras[#auras+1] = k
        addon['db']['profile']['auras'][k]['expirationTime'] = 0
        addon['db']['profile']['auras'][k]['count'] = 0
                                addon['db']['profile']['auras'][k]['warningIcon'] = true
                        end
                end
                if(addon['db']['profile']['whitelist'] == 1) then
      if(k ~= 'Defaults') then
        ex = true
        for r,s in pairs(auras) do
          if(s == k) then
            ex = false
            break
          end
        end
        if(ex and ((addon['db']['profile']['auras'][k]['static'] and addon['db']['profile']['auras'][k]['whitelist']==1))) then
          auras[#auras+1] = k
          addon['db']['profile']['auras'][k]['expirationTime'] = GetTime() - 1
          addon['db']['profile']['auras'][k]['count'] = 0
        end
      end
    end
--              [1] = L['Dont warn'],
--              [2] = L['Only in Combat'],
--              [3] = L['Only out of Combat'],
--              [4] = L['Always'],

  end
        if(UnitIsDeadOrGhost("player")) then
                auras = {}
                addon:updateBar(true)
        else
                addon:updateBar()
        end
        scanning = nil
end

function addon:addWeaponEnchant(nameWeaponEnchant,iconWeaponEnchant,expirationTimeWeaponEnchant,countWeaponEnchant)
                if(not addon['db']['profile']['auras'][nameWeaponEnchant]) then
                        addon['db']['profile']['auras'][nameWeaponEnchant] = {}
                        for k,v in pairs(addon['db']['profile']['auras'][L['Defaults']]) do
                                addon['db']['profile']['auras'][nameWeaponEnchant][k] = v
                        end
    end
    enchantDuration = addon['db']['profile']['auras'][nameWeaponEnchant]['duration'] or 1
    if(expirationTimeWeaponEnchant - GetTime() > enchantDuration) then
      enchantDuration = addon:round(expirationTimeWeaponEnchant - GetTime())
    end 
    addon['db']['profile']['auras'][nameWeaponEnchant] = {
      ['icon'] = iconWeaponEnchant,
      ['count'] = countWeaponEnchant,
      ['duration'] = enchantDuration,
      ['expirationTime'] = addon:round(expirationTimeWeaponEnchant,2),
      ['unitCaster'] = "player",
      ['filter'] = "HELPFUL",
      ['target'] = "player",
                        ['weaponEnchant'] = true,
      ['priority'] = addon['db']['profile']['auras'][nameWeaponEnchant]['priority'] or addon['db']['profile']['priority'],
      ['whitelist'] = addon['db']['profile']['auras'][nameWeaponEnchant]['whitelist'] or addon['db']['profile']['whitelist'],
                        ['lastTime'] = addon['db']['profile']['auras'][nameWeaponEnchant]['lastTime'],
                        ['lastexpirationTime'] = addon['db']['profile']['auras'][nameWeaponEnchant]['lastexpirationTime'],
                        ['soundEffect'] = addon['db']['profile']['auras'][nameWeaponEnchant]['soundEffect'],
                        ['playSound'] = addon['db']['profile']['auras'][nameWeaponEnchant]['playSound'],
                        ['ignoreMeOmniCC'] = addon['db']['profile']['auras'][nameWeaponEnchant]['ignoreMeOmniCC'],
                        ['warning'] = addon['db']['profile']['auras'][nameWeaponEnchant]['warning'],
                        ['warningOnly'] = addon['db']['profile']['auras'][nameWeaponEnchant]['warningOnly'],
                        ['showTextTimer'] = addon['db']['profile']['auras'][nameWeaponEnchant]['showTextTimer'],
                        ['spellcounter'] = addon['db']['profile']['auras'][nameWeaponEnchant]['spellcounter'] or 0,
                        ['spellcount'] = addon['db']['profile']['auras'][nameWeaponEnchant]['spellcount'] or 0,
    }
                
--      print(addon['db']['profile']['auras'][nameWeaponEnchant]['lastexpirationTime'],addon['db']['profile']['auras'][nameWeaponEnchant]['expirationTime'])
end

local function sortByTime(a,b)
        if(addon['db']['profile']['auras'][a] and addon['db']['profile']['auras'][b]) then
                if(addon['db']['profile']['reverse']) then
                        return addon['db']['profile']['auras'][a]['expirationTime'] < addon['db']['profile']['auras'][b]['expirationTime']
                else
                        return addon['db']['profile']['auras'][a]['expirationTime'] > addon['db']['profile']['auras'][b]['expirationTime']
                end
        else
                return false
        end
end

local function sortByPrio(a,b)
        if(addon['db']['profile']['auras'][a] and addon['db']['profile']['auras'][b]) then
                if(addon['db']['profile']['reverse']) then
                        return addon['db']['profile']['auras'][a]['priority'] < addon['db']['profile']['auras'][b]['priority']
                else
                        return addon['db']['profile']['auras'][a]['priority'] > addon['db']['profile']['auras'][b]['priority']
                end
        else
                return false
        end
end

function addon:updateBar(reset)
        addon:checkButtonSpellCD()
        buttonCount = 0
  for k,v in pairs(button) do
                if(addon['db']['profile']['auras'][k]) then
                        if((addon['db']['profile']['auras'][k]['spellCD'] and not addon['db']['profile']['auras'][k]['static']) or (not addon['db']['profile']['auras'][k]['spellCD'])) then
                                if(not addon['db']['profile']['auras'][k]['static']) then
                                        addon:removeButton(k, reset)
                                else
                                        buttonCount = buttonCount + 1
                                end
                        else
                                buttonCount = buttonCount + 1
                        end
                end
  end
        lastTime = checkTime
  checkTime = GetTime()
  if(auras) then
    if(addon['db']['profile']['sorting'] == 1) then
      lsort = sortByPrio
    else
      lsort = sortByTime
    end
    table.sort(auras,function(a,b) return sortByPrio(a,b) end)
                for k,v in pairs(auras) do
                        if(addon['db']['profile']['auras'][v] and addon['db']['profile']['auras'][v]['whitelist'] == 1 and (addon['db']['profile']['auras'][v]['expirationTime'] > checkTime or (addon['db']['profile']['auras'][v]['static']))) then
                                if(addon['db']['profile']['auras'][v]['lastTime'] ~= lastTime) then
                                        addon:auraAdded(v)
                                elseif(addon['db']['profile']['auras'][v]['lastexpirationTime'] and addon['db']['profile']['auras'][v]['expirationTime'] > addon['db']['profile']['auras'][v]['lastexpirationTime'] and addon['db']['profile']['auras'][v]['expirationTime'] > GetTime()) then
                                        addon:auraAdded(v,true)
                                end
--                              addon['db']['profile']['auras'][v]['lastexpirationTime'] = addon['db']['profile']['auras'][v]['expirationTime']
                                if(not addon['db']['profile']['auras'][v]['warningIcon']) then
                                        addon['db']['profile']['auras'][v]['lastTime'] = checkTime
                                end
                                if(addon['db']['profile']['auras'][v]['spellCD'] and addon['db']['profile']['auras'][v]['static']) then
                                        if(addon['db']['profile']['auras'][v]['whitelist']==1) then
                                                if(not button[v]) then
                                                        buttonCount = buttonCount + 1
                                                        addon:getButton(v)
                                                        button[v]['nr'] = buttonCount
                                                        button[v]['Icon']:SetTexture(addon['db']['profile']['auras'][v]['icon'] or "Interface\\Icons\\Ability_Warrior_PunishingBlow")
                                                        if(not addon['db']['profile']['auras'][v]['static']) then
                                                                button[v]:Show()
                                                        end
                                                end
                                                if(button[v]['Cooldown']) then
                                                        if(addon['db']['profile']['auras'][v]['expirationTime'] > GetTime() and addon['db']['profile']['auras'][v]['duration'] > 0) then
                                                                if(addon['db']['profile']['auras'][v]['showTextTimer']) then
                                                                        button[v]['TextTimer']:ClearAllPoints()
                                                                        button[v]['TextTimer']:SetPoint(addon['db']['global']['timerAnchor'] or "TOPLEFT",button[v],addon['db']['global']['timerAnchor'] or "TOPLEFT",addon['db']['global']['timerxOffset'],addon['db']['global']['timeryOffset'])
                                                                        button[v]['TextTimer']:SetJustifyH(addon['db']['global']['timerfontAnchorX'] or "TOP")
                                                                        button[v]['TextTimer']:SetJustifyV(addon['db']['global']['timerfontAnchorY'] or "LEFT")
                                                                        button[v]['TextTimer']:Show()
                                                                        button[v]['TextTimer']:SetTextColor(addon['db']['global']['timerColor'][1],addon['db']['global']['timerColor'][2],addon['db']['global']['timerColor'][3],addon['db']['global']['timerColor'][4])
                                                                        button[v]['TextTimer']:SetText(addon:formatTextTimer(addon:round(addon['db']['profile']['auras'][v]['expirationTime'] - GetTime())))
                                                                end
                                                                CooldownFrame_SetTimer(button[v]['Cooldown'], addon['db']['profile']['auras'][v]['expirationTime'] - addon['db']['profile']['auras'][v]['duration'], addon['db']['profile']['auras'][v]['duration'], 1)
                                                        elseif(addon['db']['profile']['auras'][v]['static']) then
                                                                if(not addon['db']['profile']['auras'][v]['spellCD']) then
                                                                        CooldownFrame_SetTimer(button[v]['Cooldown'], 360, 360, 1)
                                                                end
                                                                button[v]['TextTimer']:Hide()
                                                        end
                                                end
                                                if(IsUsableSpell(string.sub(v,9)) and IsSpellInRange(addon['db']['profile']['auras'][v]['spellCDId'],"spell", UnitExists("target") and "target" or "player") == 1) then
                                                        button[v]['Icon']:SetVertexColor(1, 1, 1, 1)
                                                else
                                                        if(not IsUsableSpell(string.sub(v,9))) then
                                                                button[v]['Icon']:SetVertexColor(1, 1, 1, .25)
                                                        else
                                                                button[v]['Icon']:SetVertexColor(1, 0, 0, 1)
                                                        end
                                                end
                                        end
                                end
                        end
                        if(addon['db']['profile']['auras'][v]) then
                                addon['db']['profile']['auras'][v]['lastexpirationTime'] = addon['db']['profile']['auras'][v]['expirationTime']
                        end
                end
                addon:resetSpellCDLastTime()
    table.sort(auras,function(a,b) return lsort(a,b) end)
    for k,v in pairs(auras) do
                        if(addon['db']['profile']['auras'][v]) then
                                if(addon['db']['profile']['auras'][v]['whitelist']==1) then
                                        if((addon['db']['profile']['auras'][v]['spellCD'] and not addon['db']['profile']['auras'][v]['static']) or (not addon['db']['profile']['auras'][v]['spellCD']) or addon['db']['profile']['auras'][v]['warningIcon']) then
-- print(v,addon['db']['profile']['auras'][v]['warningOnly'])
                                                if(not addon['db']['profile']['auras'][v]['warningOnly']) then
                                                                                                buttonCount = buttonCount + 1
                                                addon:getButton(v)
                                                button[v]['nr'] = buttonCount
                                                button[v]['Icon']:SetTexture(addon['db']['profile']['auras'][v]['icon'] or "Interface\\Icons\\Ability_Warrior_PunishingBlow")
                                                if(not addon['db']['profile']['auras'][v]['static']) then
                                                        button[v]:Show()
                                                end
                                                        txt = addon['db']['profile']['auras'][v]['count'] or 0
        --                                              txt = 15
                                                        if(txt < 2) then
                                                                txt = "" 
                                                        end

                                                        if(button[v]['Count']) then
                                                                if(not addon['db']['profile']['auras'][v]['charges']) then
                                                                        button[v]['Count']:Hide()
                                                                else    
                                                                        button[v]['Count']:ClearAllPoints()
                                                                        button[v]['Count']:SetPoint(addon['db']['global']['chargesAnchor'] or "BOTTOMRIGHT",button[v],addon['db']['global']['chargesAnchor'] or "BOTTOMRIGHT",addon['db']['global']['xOffset'],addon['db']['global']['yOffset'])
                                                                        button[v]['Count']:SetJustifyH(addon['db']['global']['fontAnchorX'] or "BOTTOM")
                                                                        button[v]['Count']:SetJustifyV(addon['db']['global']['fontAnchorY'] or "RIGHT")
                                                                        button[v]['Count']:Show()
                                                                        button[v]['Count']:SetTextColor(addon['db']['global']['chargesColor'][1],addon['db']['global']['chargesColor'][2],addon['db']['global']['chargesColor'][3],addon['db']['global']['chargesColor'][4])
                                                                        button[v]['Count']:SetText(txt)
                                                                end
                                                        end
                                                        if(button[v]['Cooldown']) then
                                                                if(addon['db']['profile']['auras'][v]['expirationTime'] > GetTime()) then
                                                                        if(addon['db']['profile']['auras'][v]['showTextTimer']) then
                                                                                button[v]['TextTimer']:ClearAllPoints()
                                                                                button[v]['TextTimer']:SetPoint(addon['db']['global']['timerAnchor'] or "TOPLEFT",button[v],addon['db']['global']['timerAnchor'] or "TOPLEFT",addon['db']['global']['timerxOffset'],addon['db']['global']['timeryOffset'])
                                                                                button[v]['TextTimer']:SetJustifyH(addon['db']['global']['timerfontAnchorX'] or "TOP")
                                                                                button[v]['TextTimer']:SetJustifyV(addon['db']['global']['timerfontAnchorY'] or "LEFT")
                                                                                button[v]['TextTimer']:Show()
                                                                                button[v]['TextTimer']:SetTextColor(addon['db']['global']['timerColor'][1],addon['db']['global']['timerColor'][2],addon['db']['global']['timerColor'][3],addon['db']['global']['timerColor'][4])
                                                                                button[v]['TextTimer']:SetText(addon:formatTextTimer(addon:round(addon['db']['profile']['auras'][v]['expirationTime'] - GetTime())))
                                                                        end
        -- print(v,addon['db']['profile']['auras'][v]['expirationTime'],addon['db']['profile']['auras'][v]['duration'])
                                                                        CooldownFrame_SetTimer(button[v]['Cooldown'], addon['db']['profile']['auras'][v]['expirationTime'] - addon['db']['profile']['auras'][v]['duration'], addon['db']['profile']['auras'][v]['duration'], 1)
                                                                elseif(addon['db']['profile']['auras'][v]['static'] or addon['db']['profile']['auras'][v]['warning']) then
                                                                        if(not addon['db']['profile']['auras'][v]['spellCD']) then
                                                                                CooldownFrame_SetTimer(button[v]['Cooldown'], 360, 360, 1)
                                                                        end
                                                                        button[v]['TextTimer']:Hide()
                                                                end
                                                        end
                                                elseif(addon['db']['profile']['auras'][v]['warningIcon']) then
                                                        buttonCount = buttonCount + 1
                                                        addon:getButton(v)
                                                        button[v]['nr'] = buttonCount
                                                        button[v]['Icon']:SetTexture(addon['db']['profile']['auras'][v]['icon'] or "Interface\\Icons\\Ability_Warrior_PunishingBlow")
                                                        button[v]:Show()
                                                end
                                        end
                                end
--                              print(v,addon['db']['profile']['auras'][v]['warning'],addon['db']['profile']['auras'][v]['warningIcon'])
                                if(button[v] and addon['db']['profile']['auras'][v]['warningIcon']) then
                                        button[v]['Warning']:Show()
                                end
                        end
                end
        end
end

function addon:formatTextTimer(text)
        if(text == 0 or not text) then return "" end
        if(addon['db']['global']['displayMode'] == 1) then
                if(text>60) then
                        text = tostring(addon:round(text/60).."m") 
                end
        end
        return text
end

function addon:auraAdded(name,refreshed,spell)
        if(not spell) then
                if(addon['db']['profile']['auras'][name]['spellCD']) then return end
        end
        if(not addon['configDone']) then return end
        if(addon['db']['profile']['auras'][name]['soundPlayed']) then return end
        addon['db']['profile']['auras'][name]['soundPlayed'] = true
        if(refreshed) then
                if(addon['db']['profile']['auras'][name]['lastTime'] == lastTime) then
                        addon['db']['profile']['auras'][name]['spellcounter'] = addon['db']['profile']['auras'][name]['spellcounter'] or 0
                        addon['db']['profile']['auras'][name]['spellcounter'] = addon['db']['profile']['auras'][name]['spellcounter'] + 1
                end
        else
                if(button[name])then
                        skullReset(button[name]['Warning'])
                        button[name]['Warning']:Hide()
                end
                addon['db']['profile']['auras'][name]['spellcount'] = addon['db']['profile']['auras'][name]['spellcount'] or 0
                addon['db']['profile']['auras'][name]['spellcount'] = addon['db']['profile']['auras'][name]['spellcount'] + 1
        end
        if(addon['db']['profile']['auras'][name]['playSound'] and addon['db']['profile']['auras'][name]['soundEffect']) then
                if(LSM) then
                        PlaySoundFile(addon['db']['profile']['auras'][name]['soundEffect'])
--                      addon:pdebug(tostring(name).." "..tostring(refreshed).." "..tostring(spell).."-"..tostring(addon['db']['profile']['auras'][name]['soundPlayed']))
--                      addon:pdebug(tostring(checkTime).."/"..tostring(GetTime()).."-"..tostring(addon['db']['profile']['auras'][name]['expirationTime']).."/"..tostring(addon['db']['profile']['auras'][name]['lastexpirationTime']))
                else
                        PlaySound("FriendJoinGame")
                end
        end
        addon:resetSpellCDLastTime()
end

function addon:resetSpellCDLastTime()
        for k,v in pairs(spellBook) do
                spellName = "SpellCD_"..k
                if(addon['db']['profile']['auras'][spellName]) then
                        addon['db']['profile']['auras'][spellName]['lastTime'] = checkTime
                end
        end
end

function addon:joinTable(t1,t2)
  if(type(t1) == 'table' and type(t2) ~= 'table') then return t1 end
  if(type(t2) == 'table' and type(t1) ~= 'table') then return t2 end
  if(type(t1) ~= 'table' and type(t2) ~= 'table') then return {} end
  tbl = t1
  for k,v in pairs(t2) do
    ex = true
    for r,s in pairs(t1) do
      if(v == s) then
        ex = false
        break
      end
    end
    if(ex) then
      tbl[#tbl+1] = v
    end
  end
  return tbl
end

function addon:scanBuffs(target, filter)
  if(UnitIsDeadOrGhost(target)) then return {} end
  if(not UnitExists(target)) then return {} end
  buffs = {}
        if(scannedUnits[filter][UnitGUID(target)] == true) then 
                return {}
        end
        scannedUnits[filter][UnitGUID(target)] = true
  target = target or "player"
  filter = filter or "HELPFUL"
  for i = 1,40 do
    buffs[#buffs+1] = addon:storeBuff(target, filter, UnitAura(target, i, filter))
  end
  return buffs
end

function addon:storeBuff(target, filter, name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, isStealable, shouldConsolidate, spellId)
  if(name and unitCaster == 'player') then
    ex = false
    if(not addon['db']['profile']['auras'][name]) then
      addon['db']['profile']['auras'][name] = {}
                        for k,v in pairs(addon['db']['profile']['auras'][L['Defaults']]) do
                                addon['db']['profile']['auras'][name][k] = v
                        end
      ex = true
    end
                if(not addon['db']['profile']['auras'][name]['spellCD']) then
                        if(duration == 0 or not duration) then
                                duration = 9999
                                expirationTime = GetTime() + duration
                        end
                end
    addon['db']['profile']['auras'][name] = {
      ['rank'] = rank,
      ['icon'] = icon,
      ['count'] = count,
      ['debuffType'] = debuffType,
      ['duration'] = duration,
      ['expirationTime'] = expirationTime,
      ['unitCaster'] = unitCaster,
      ['isStealable'] = isStealable,
      ['shouldConsolidate'] = shouldConsolidate,
      ['spellId'] = spellId,
      ['filter'] = filter,
      ['target'] = target,
      ['priority'] = addon['db']['profile']['auras'][name]['priority'],
      ['charges'] = addon['db']['profile']['auras'][name]['charges'],
      ['static'] = addon['db']['profile']['auras'][name]['static'],
      ['whitelist'] = addon['db']['profile']['auras'][name]['whitelist'] or txt,
                        ['lastTime'] = addon['db']['profile']['auras'][name]['lastTime'],
                        ['lastexpirationTime'] = addon['db']['profile']['auras'][name]['lastexpirationTime'],
                        ['soundEffect'] = addon['db']['profile']['auras'][name]['soundEffect'],
                        ['playSound'] = addon['db']['profile']['auras'][name]['playSound'],
                        ['ignoreMeOmniCC'] = addon['db']['profile']['auras'][name]['ignoreMeOmniCC'],
                        ['warning'] = addon['db']['profile']['auras'][name]['warning'],
                        ['warningOnly'] = addon['db']['profile']['auras'][name]['warningOnly'],
                        ['showTextTimer'] = addon['db']['profile']['auras'][name]['showTextTimer'],
                        ['spellcounter'] = addon['db']['profile']['auras'][name]['spellcounter'] or 0,
                        ['spellcount'] = addon['db']['profile']['auras'][name]['spellcount'] or 0,
    }
    if(ex) then
      addon:buildSpellList()
    end
    return name
  end
  return nil
end

function addon:positionButton(bt)
        bt:ClearAllPoints()
        if(addon['db']['global']['vertical']) then
                buttonSpacing = 0
                buttonSpacing2 = addon['db']['global']['spacing'] or 8
                if(addon['db']['global']['growth']) then
                        buttonAnchor = "BOTTOMLEFT"
                        buttonParentanchor = "TOPLEFT"
                else
                        buttonSpacing2 = buttonSpacing2 * -1
                        buttonAnchor = "TOPLEFT"
                        buttonParentanchor = "BOTTOMLEFT"                                       
                end
        else
                buttonSpacing = addon['db']['global']['spacing'] or 8
                buttonSpacing2 = 0
                if(addon['db']['global']['growth']) then
                        buttonAnchor = "TOPRIGHT"
                        buttonParentanchor = "TOPLEFT"          
                        buttonSpacing = buttonSpacing * -1
                else
                        buttonAnchor = "TOPLEFT"
                        buttonParentanchor = "TOPRIGHT"
                end
        end
        pb = addon:getButtonByNumber(buttonCount-1)
        while(pb == bt) do
                buttonCount = buttonCount - 1
                pb = addon:getButtonByNumber(buttonCount-1)
        end
        bt:SetPoint(buttonAnchor,pb,buttonParentanchor,buttonSpacing,buttonSpacing2)
end

function addon:getButton(name)
  if(button[name]) then
        if(not addon['db']['profile']['auras'][name]['static']) then
                addon:positionButton(button[name])
        end
    return button[name]
  else
    return addon:createButton(name)
  end
end

local function buttonRightClick(self, buttonClick, down)
        if(buttonClick == 'RightButton' and addon['db']['profile']['removeAura']) then
                if(addon['db']['profile']['auras'][self['name']]['target'] == 'player') then
                        if(self['name'] == L['mainhand']) then
                                CancelItemTempEnchantment(1)
                        elseif(self['name'] == L['offhand']) then
                                CancelItemTempEnchantment(2)
                        else
                                CancelUnitBuff('player',self['name'])
                        end
                end
        end
end

local function skullFade(self,elapsed)
        self['elapsed'] = self['elapsed'] + elapsed
        if self['elapsed'] < self['animSpeed'] then return end
        alpha = self:GetAlpha()
        alpha = alpha + self['animStep']
        if(alpha > 1) then
                alpha = 1
                self['animStep'] = -self['animStep']
        elseif(alpha < 0) then
                alpha = 0
                self['animStep'] = -self['animStep']
        end
        self['elapsed'] = 0

        self:SetAlpha(alpha)
end

local function gametooltiphide()
        GameTooltip:Hide()
end

local function gametooltipshow(self)
        name = self['name']
  if(not addon['db']['profile']['showTooltip']) then return end
  if(name and addon['db']['profile']['auras'][name]) then
                GameTooltip:SetOwner(button[name],"ANCHOR_TOPRIGHT")
                GameTooltip:ClearLines()
                if(addon['db']['profile']['auras'][name]['spellCD']) then
                        GameTooltip:SetSpellBookItem(addon['db']['profile']['auras'][name]['spellCDId'], BOOKTYPE_SPELL)
                else
                        index = nil
                        for i=1,40 do
                                if(select(1,UnitAura(addon['db']['profile']['auras'][name]['target'],i,addon['db']['profile']['auras'][name]['filter'])) == name) then
                                        index = i
                                        break
                                end
                        end

                        if(index) then
                                GameTooltip:SetUnitAura(addon['db']['profile']['auras'][name]['target'],index,addon['db']['profile']['auras'][name]['filter'])
                        elseif(name==L['mainhand'] or name==L['offhand']) then
                                if(name==L['mainhand']) then
                                        invSlot = 16
                                else
                                        invSlot = 17
                                end
                                GameTooltip:SetInventoryItem("player", invSlot)
                        else
                                GameTooltip:AddLine(name)
                        end
                end
    GameTooltip:Show()
  end
end

function addon:createButton(name)
        if(addon['db']['profile']['auras'][name]['spellCD'] and addon['db']['profile']['auras'][name]['static']) then
                button[name] = CreateFrame("Button","PWB_"..name, addon['mainframe'],"ActionButtonTemplate SecureActionButtonTemplate")
                button[name]:SetAttribute("type", "spell")
                button[name]:SetAttribute("checkselfcast", true)
                button[name]:SetAttribute("spell", string.sub(name,9))
        elseif(addon['db']['profile']['auras'][name]['static']) then
                button[name] = CreateFrame("Button","PWB_"..name, addon['mainframe'],"ActionButtonTemplate SecureActionButtonTemplate")
                button[name]:SetAttribute("type", "cancelaura")
                button[name]:SetAttribute("spell", name)
                button[name]:SetAttribute("unit", "player")
                button[name]:RegisterForClicks("RightButtonUp")
        else
                button[name] = CreateFrame("Button","PWB_"..name, addon['mainframe'],"ActionButtonTemplate")
                button[name]:EnableMouse(true)
                button[name]:SetScript("OnMouseDown", buttonRightClick)
        end
        button[name]['name'] = name
  button[name]:SetWidth(64)
  button[name]:SetHeight(64)

  button[name]:SetScript("OnEnter", gametooltipshow)
  button[name]:SetScript("OnLeave", gametooltiphide)
  addon:positionButton(button[name])
        button[name]['Warning'] = CreateFrame("Frame","$PARENTWarning",button[name])
        button[name]['Warning']:SetWidth(96)
        button[name]['Warning']:SetHeight(96)
        button[name]['Warning']:SetPoint("CENTER",button[name],"CENTER",0,0)
        button[name]['Warning']:SetFrameStrata("HIGH")
        button[name]['Warning']:SetScript("OnUpdate", skullFade)
--      button[name]['Warning']:SetScript("OnHide", skullReset)
        skullReset(button[name]['Warning'])
        button[name]['Warning']:Hide()
        button[name]['WarningTexture'] = button[name]['Warning']:CreateTexture()
        button[name]['WarningTexture']:SetAllPoints(button[name]['Warning'])
        button[name]['WarningTexture']:SetTexture("Interface\\AddOns\\zz_ProcWatch\\skull.tga")

        button[name]['Icon'] = _G["PWB_"..name.."Icon"]
        button[name]['Icon']:SetTexture(addon['db']['profile']['auras'][name]['icon'] or "Interface\\Icons\\Ability_Warrior_PunishingBlow")
  
        button[name]['Cooldown'] = _G["PWB_"..name.."Cooldown"]
        if(not addon['db']['profile']['auras'][name]['spellCD']) then
                button[name]['Cooldown']:SetReverse(true)
        else
                button[name]['Cooldown']:SetReverse(false)
        end
        button[name]['Cooldown']['noCooldownCount'] = addon['db']['profile']['auras'][name]['ignoreMeOmniCC']
        button[name]['Count'] = _G["PWB_"..name.."Count"]
        button[name]['Count']:SetFont(addon['db']['global']['chargesFont'], addon['db']['global']['chargesSize'], addon['db']['global']['chargesMode'])
        if(LBF and LBFGroup) then
                LBFGroup:AddButton(button[name])
        end
        button[name]['TextTimer'] = button[name]:CreateFontString("PWB_"..name.."TextTimer","OVERLAY")
        button[name]['TextTimer']:SetFont(addon['db']['global']['timerFont'], addon['db']['global']['timerSize'], addon['db']['global']['timerMode'])
        button[name]['TextTimer']:SetPoint("TOPLEFT",button[name],"TOPLEFT",0,0)
  return button[name]
end



function addon:removeButton(name,reset)
  if(button[name]) then
    button[name]:Hide()
    button[name]['nr'] = nil
                if(reset) then
                        if(LBF and LBFGroup) then
                                LBFGroup:RemoveButton(button[name])
                        end
                        button[name]:SetParent(nil)
                        button[name] = nil
                        _G["PWB_"..name.."Icon"] = nil
                        _G["PWB_"..name.."Cooldown"] = nil
                        _G["PWB_"..name.."Count"] = nil
                        _G["PWB_"..name.."TextTimer"] = nil
                end
  end
end

function addon:getButtonByNumber(nr)
  if(nr == 0) then
    return addon['mainframe']
  end
  for k,v in pairs(button) do
    if(button[k]['nr'] == nr) then
      return button[k]
    end
  end
  return false
end

function addon:getMainframe()
  local mainframe
  mainframe = CreateFrame("Frame", "Layout"..addon:get('title'),UIParent)
  mainframe:SetWidth(64)
  mainframe:SetHeight(64)
  mainframe:SetPoint("CENTER",UIParent,"CENTER",0,0)
        mainframe['tab'] = addon['db']['profile']
        local tab = {
                ['width'] = 64,
                ['height'] = 64,
                ['anchor'] = "TOPLEFT",
                ['parentanchor'] = "TOPLEFT",
        }
        addontable['addDrag'](mainframe,"BOX",tab)
  mainframe['nr'] = 0
  mainframe:SetScale(addon['db']['profile']['scale'] or 1)
  addontable['loadFrame'](mainframe)
  return mainframe
end

local function tooltipSort(a,b)
        if(not a or not b) then return false end
        tooltipSort1 = addon['db']['profile']['auras'][a]['spellcount'] or 0
        tooltipSort2 = addon['db']['profile']['auras'][b]['spellcount'] or 0
        return  tooltipSort1 >  tooltipSort2
end

function addon:OnTooltip()
        GameTooltip:ClearLines()
        GameTooltip:AddDoubleLine(addon:get('title'), L['Proc'].."("..L['Refresh']..")")
        
        whitelistAura = {}
        for k in pairs(addon['db']['profile']['auras']) do
                if(k~=L['Defaults']) then
                        if(addon['db']['profile']['auras'][k]['whitelist'] and addon['db']['profile']['auras'][k]['spellcount'] and addon['db']['profile']['auras'][k]['spellcount'] > 0 and not addon['db']['profile']['auras'][k]['spellCD']) then
                                whitelistAura[#whitelistAura + 1] = k
                        end
                end
        end
        sort(whitelistAura, tooltipSort)
        tooltipCount = 0
        for _,k in pairs(whitelistAura) do
                GameTooltip:AddDoubleLine(k,(addon['db']['profile']['auras'][k]['spellcount'] or 0) .."("..(addon['db']['profile']['auras'][k]['spellcounter'] or 0)..")")
                tooltipCount = tooltipCount + 1
                if(tooltipCount > 20) then
                        break
                end
        end
end

local map_global_local = {
        ['spacing'] = true,
        ['vertical'] = true,
        ['growth'] = true,
}

function addon:Updated_Pref(value)
        if(map_global_local[value]) then
                addon['db']['global'][value] = addon['db']['profile'][value]
                addon:destroyButtons()
        elseif(value=='scale') then
    addon.mainframe:SetScale(addon['db']['profile']['scale'] or 1)
  end
end

function addon:round(num, idp)
  return math.floor(num * (10^(idp or 0)) + 0.5) / (10^(idp or 0))
end

Compare with Previous | Blame