Quantcast
WoWInterface: SVN - zz_Actionbuttons - Rev 13 - /trunk/zz_Actionbuttons/core.lua

WoWInterface SVN zz_Actionbuttons

[/] [trunk/] [zz_Actionbuttons/] [core.lua] - Rev 13

Go to most recent revision | Compare with Previous | Blame | View Log

local name, addon = ...
local defaults = {}
local options, db
local _,class = UnitClass('player')
local _G = _G
local xoffset, yoffset = 4,4
local buttons = {}

addon['MSQ'] = LibStub("Masque",true)
if(addon['MSQ']) then addon['MSQGroup'] = addon['MSQ']:Group(name,name) end

local function hideBlizz()
        local hide = {
                MainMenuBar,
                ReputationWatchBar,
                MainMenuExpBar,
                BonusActionBarFrame,
                BonusActionBarFrameTexture1,
                BonusActionBarFrameTexture2,
                BonusActionBarFrameTexture3,
                BonusActionBarFrameTexture4,
        }
        for i = 1, #hide do
                local f = hide[i]
                if(type(f.UnregisterAllEvents) == 'function') then f:UnregisterAllEvents() end
                f.Show = f.Hide
                f:Hide()
        end
end

local function applySettings(bname, bh)
        
        db = addon['updateDB'](addon['db']['profile'])
        local f = _G[bname]
        if(not f) then return end
        local spr = db['bars'][bname]['cols']
        local y,row = 1,0
        local lastbutton = f
        f:SetScale(db['bars'][bname]['scale'])
        if(f['sbuttons']) then
                for i = 1, #f['sbuttons'] do
                        local btn = f['sbuttons'][i]
                        bh = bh or btn:GetHeight()
                        btn:SetParent(f)
                        btn:ClearAllPoints()
                        if(y == 1) then
                                
                                btn:SetPoint("TOPLEFT", f, "TOPLEFT",0 , -row * bh + yoffset)
                        else
                                btn:SetPoint("TOPLEFT", lastbutton, "TOPRIGHT",xoffset,0)
                        end
                        y = y + 1
                        if(not f['skipMasque'] and addon['MSQ'] and addon['MSQGroup'] and not buttons[btn]) then
                                buttons[btn] = true
                                addon['MSQGroup']:AddButton(btn)
                        end
                        lastbutton = btn
                        if(y > spr) then
                                y = 1
                                row = row + 1
                        end
                end
        end
        if(row < 1) then row = 1 end
        if(db['bars'][bname]['cols'] > f['maxslots']) then db['bars'][bname]['cols'] = f['maxslots'] end
        bh = bh or 0
        f:SetWidth(db['bars'][bname]['cols']*(lastbutton:GetWidth() + xoffset) -xoffset)
        f:SetHeight(row * (bh + yoffset) - yoffset)
end
addon['applySettings'] = applySettings
local function getButton(parent, id, offset)
        local btn
        if(offset <= 12) then
                btn = _G['ActionButton'..id]
        elseif(offset <= 24) then
                
        elseif(offset <= 36) then
                btn = _G['MultiBarRightButton'..id]
        elseif(offset <= 48) then
                btn = _G['MultiBarLeftButton'..id]
        elseif(offset <= 60) then
                btn = _G['MultiBarBottomRightButton'..id]
        elseif(offset <= 72) then
                btn = _G['MultiBarBottomLeftButton'..id]
        elseif((offset > 190) and (offset <= 200)) then
                btn = _G['ShapeshiftButton'..id]
        elseif((offset > 200) and (offset <= 210)) then
                btn = _G['PetActionButton'..id]
        end

        if(not btn) then
                btn = CreateFrame("CheckButton", "$PARENTActionButton"..offset, parent, "ActionButtonTemplate ActionBarButtonCodeTemplate",id)
                btn['buttonType'] = "ZZACTIONBUTTON"
        else
--              btn:GetParent():UnregisterAllEvents()
                btn:GetParent():Hide()
                btn:GetParent().Show = btn:GetParent().Hide
                btn:ClearAllPoints()
                btn:SetParent(parent)
        end
--      print(parent, id, offset, btn:GetName())
        return btn
end

local function createBar(bid,mb)
        mb = mb or 12
        local yoff =-yoffset - 40 * (bid-1)
        local f = CreateFrame("Frame", "zzABar"..bid, UIParent, "SecureHandlerStateTemplate SecureHandlerBaseTemplate",bid == 1 and bid or nil)
        f['sbuttons'] = {}
        f['maxslots'] = mb
        f:SetWidth(1)
        f:SetHeight(1)
        f:SetPoint("CENTER", xoffset, yoff)
        if(bid > 1 and bid < 7) then
                f:SetAttribute('actionpage', bid)
        end
        if(bid == 1) then
                f:SetAttribute('_onstate-page', [[
                        if(self:GetID() == 1) then
                                self:SetAttribute('actionpage', newstate)
                                control:ChildUpdate('actionpage', newstate)
                        else
                                control:ChildUpdate('actionpage', self:GetID())
                        end
                ]])
                f:SetAttribute('_onstate-possess', [[
                        if(self:GetID() == 1) then
                                self:SetAttribute('actionpage', newstate)
                                control:ChildUpdate('actionpage', newstate)
                        else
                                control:ChildUpdate('actionpage', self:GetID())
                        end
                ]])
                f:SetAttribute('_onstate-vehicle', [[
                        self:SetAttribute("state",newstate)
                        if(newstate == 'player') then
                                self:SetAttribute('actionpage', nil)
                                control:ChildUpdate('actionpage', nil)
                        else
                                self:SetAttribute('actionpage', 11)
                        end
                        control:ChildUpdate('actionpage', self:GetID())
                ]])
                RegisterStateDriver(f, "vehicle", "[vehicleui]vehicle;player")
                if(class == "WARRIOR") then
                        RegisterStateDriver(f, "page", "[bonusbar:1] 7;[bonusbar:2] 8;[bonusbar:3] 9;1")
                elseif(class == "DRUID") then
                        RegisterStateDriver(f, "page", "[stance:1] 9;[stance:3,stealth] 8;[stance:3] 7;[stance:5] 10;1") -- 1 bear/ 3 cat/ 5 moonkin
                elseif(class == "ROGUE") then
                        RegisterStateDriver(f, "page", "[stance:1] 7;[stance:3] 8; 1") -- 1 stealth/ 3 shadow dance
                elseif(class == "PRIEST") then
                        RegisterStateDriver(f, "page", "[stance:1] 7; 1")
                end
                RegisterStateDriver(f, "possess", "[bonusbar:5] 11")
        else

                f:SetAttribute('_onstate-showvehicle', [[
                        if(newstate=='hide') then
                                self:Hide()
                        else
                                self:Show()
                        end
                ]])
                RegisterStateDriver(f, "showvehicle", "[vehicleui]hide;show")
                RegisterAutoHide(f,0.2)
        end
        local lastbutton = f
        
        for i = 1, mb do
                local offset = bid*mb-mb+i
                local b = getButton(f, i, offset)
                b:SetPoint("TOPLEFT", lastbutton, "TOPRIGHT", xoffset,0)
                yoff = 0
                lastbutton = b
                b:SetAttribute('action--base',b:GetAttribute('action') or i)
                if(bid == 1) then
                        b:SetAttribute('_childupdate-actionpage', [[
                                self:SetAttribute('action--dummy', self:GetAttribute('action--dummy'))
                        ]])
                elseif(bid<7) then
                        b:SetAttribute('_childupdate-actionpage', [[
                                
                        ]])
                end
                f['sbuttons'][#f['sbuttons'] + 1] = b
--              b:SetAttribute('action', i)
        end
        addon['addDrag'](f)
        addon['applySettings'](f:GetName())
        
        return f:GetName()
end

local function getBarPref(pref)
        return db['bars'][pref[#pref-1]][pref[#pref]]
end

local function setBarPref(pref,value)
        db['bars'][pref[#pref-1]][pref[#pref]] = value
        applySettings(pref[#pref-1])
end

local function resetCenter(pref)
        _G[pref[#pref-1]]:center()
end

local function init(self, event, ...)
        _,class = UnitClass('player')
end
addon['updateDB'] = function(db)
        db['bars'] = db['bars'] or {}
        db['bars']['MultiCastActionBarFrame'] = db['bars']['MultiCastActionBarFrame'] or {
                ['cols'] = 12,
                ['scale'] = 1,                  
        }
        return db
end
addon['preloads'][#addon['preloads'] + 1] = function(self,event,...)
        options = addon['InitConfig'](addon, name, true, {
                ['type'] = "launcher",
        }, getPref, setPref)
        db = addon['updateDB'](addon['db']['profile'])
        
        db['bars']['MultiCastActionBarFrame']['cols'] = db['bars']['MultiCastActionBarFrame']['cols'] or 12
        addon['AddConfigEntry'](addon, name, 'toggle', 'dragAble', 'Unlocked', 'Use alt+click to move your bars', 0)
        do
                local function addP(bname)
                        local o = addon['AddConfigMenu'](addon, {
                                ['name'] = bname,
                                ['menuGet'] = getBarPref,
                                ['menuSet'] = setBarPref,
                        }, addon['options']['args'][name])
                        addon['AddConfigEntry'](addon, name, 'range', 'cols', 'Colums', 'Number of columns', 0,1,12,1,false,o)
                        addon['AddConfigEntry'](addon, name, 'range', 'scale', 'Scale', 'Scale of this bar', 1,0.1,3,0.1,true,o)
                        addon['AddConfigEntry'](addon, name, 'execute', 'center', 'Center', 'Reset position', 2,resetCenter,nil,nil,nil,o)
                end
                for i = 1,6 do
                        addP(createBar(i, NUM_ACTIONBAR_BUTTONS))
                end
                addP(createBar(20, NUM_SHAPESHIFT_SLOTS))
                addP(createBar(21, NUM_PET_ACTION_SLOTS))
                
                addP("MultiCastActionBarFrame")
                addP(name.."MicroMenu")
                addP(name.."BagBar")
        end
        MultiCastActionBarFrame:ClearAllPoints()
        MultiCastActionBarFrame:SetPoint("CENTER")
        UIPARENT_MANAGED_FRAME_POSITIONS["MultiCastActionBarFrame"] = nil
        addon['addDrag'](MultiCastActionBarFrame)
        MoveMicroButtons = function() end
        VehicleMenuBar_MoveMicroButtons = function() end
--      hooksecurefunc("ChangeMultiCastActionPage", updateMCB)
        hideBlizz()
end

addon['startup'](addon, name, name, init, true, defaults)

Go to most recent revision | Compare with Previous | Blame