WoWInterface SVN zz_Actionbuttons

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

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 dragAble()
        return db['dragAble']
end
local function hideBlizz()
        local hide = {
                MainMenuBar,
                ReputationWatchBar,
                MainMenuExpBar,
                BonusActionBarFrame,
                BonusActionBarFrameTexture1,
                BonusActionBarFrameTexture2,
                BonusActionBarFrameTexture3,
                BonusActionBarFrameTexture4,
--              PossessBarFrame,
                VehicleMenuBar,
        }
        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 fadeIn(self)
        self:GetParent():SetAlpha(1)
end

local function fadeOut(self)
        local bname = self:GetParent():GetName()
        if(IsAltKeyDown() or not bname or not db['bars'][bname]['fadein']) then return end
        self:GetParent():SetAlpha(0)
end
local function fadeInOut(self)
        self:HookScript("OnEnter", fadeIn)
        self:HookScript("OnLeave", fadeOut)
        self:HookScript("OnShow", fadeOut)
end
local function fadeInHeader(self)
        self:SetAlpha(1)
end

local function fadeOutHeader(self)
        local bname = self:GetName()
        if(not bname or not db['bars'][bname]['fadein']) then return end
        self:SetAlpha(0)
end
local function fadeInOutHeader(self)
        self:HookScript("OnEnter", fadeInHeader)
        self:HookScript("OnLeave", fadeOutHeader)
        self:HookScript("OnShow", fadeOutHeader)
end

addon['fadeInOut'] = fadeInOut
addon['fadeInOutHeader'] = fadeInOutHeader
local function applySettings(bname)
        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
        local bh = f['sizeButton'] or 32
        _G[bname]:SetAttribute('fadeIn', db['bars'][bname]['fadein'])
        f:SetScale(db['bars'][bname]['scale'])
        if(f['sbuttons']) then
                for i = 1, #f['sbuttons'] do
                        local btn = f['sbuttons'][i]
                        bh = f['sizeButton'] or btn:GetHeight()
                        btn:SetParent(f)
                        btn:ClearAllPoints()
                        if(y == 1) then
                                btn:SetPoint("TOPLEFT", f, "TOPLEFT",xoffset , -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
        f['maxslots'] = f['maxslots'] or 12
        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)
        if(not f['skipMasque'] and addon['MSQ'] and addon['MSQGroup']) then
                addon['MSQGroup']:ReSkin() -- test if bags keep their skin or if I need to create new bag buttons
        end
end
addon['applySettings'] = applySettings
local function getButton(parent, id, offset)
        local btn
        if(offset <= NUM_ACTIONBAR_BUTTONS) then
                btn = _G['ActionButton'..id]
        elseif(offset <= NUM_ACTIONBAR_BUTTONS * 2) then
                
        elseif(offset <= NUM_ACTIONBAR_BUTTONS * 3) then
                btn = _G['MultiBarRightButton'..id]
        elseif(offset <= NUM_ACTIONBAR_BUTTONS * 4) then
                btn = _G['MultiBarLeftButton'..id]
        elseif(offset <= NUM_ACTIONBAR_BUTTONS * 5) then
                btn = _G['MultiBarBottomRightButton'..id]
        elseif(offset <= NUM_ACTIONBAR_BUTTONS * 6) then
                btn = _G['MultiBarBottomLeftButton'..id]
        elseif((offset > 190) and (offset <= 190 + NUM_SHAPESHIFT_SLOTS)) then
                btn = _G['ShapeshiftButton'..id]
        elseif((offset > 190 + NUM_SHAPESHIFT_SLOTS) and (offset <= 190 + NUM_SHAPESHIFT_SLOTS + NUM_PET_ACTION_SLOTS)) then
                btn = _G['PetActionButton'..id]
        elseif((offset > 190 + NUM_SHAPESHIFT_SLOTS + NUM_PET_ACTION_SLOTS) and (offset <= 190 + NUM_SHAPESHIFT_SLOTS + NUM_PET_ACTION_SLOTS + NUM_POSSESS_SLOTS)) then
                btn = _G['PossessButton'..id]
        end

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

local function createBar(bid,mb,bh)
        mb = mb or 12
        local yoff =-yoffset - 40 * (bid-1)
        db['bars']["zzABar"..bid] = db['bars']["zzABar"..bid] or {
                ['cols'] = 12,
                ['scale'] = 1,
                ['points'] = {},
        }
        db['bars']["zzABar"..bid]['points'] = db['bars']["zzABar"..bid]['points'] or {}
        local f = addon['CreateSecureFrame']({
                ['name'] = "zzABar"..bid,
                ['db'] = db['bars']["zzABar"..bid]['points'],
                ['id'] = bid == 1 and bid or nil,
                ['width'] = 1,
                ['height'] = 1,
                ['parent'] = UIParent,
                ['xoff'] = xoffset,
                ['yoff'] = yoff,
                ['dragAble'] = dragAble,
        })
--      local f = CreateFrame("Frame", "zzABar"..bid, UIParent, "SecureHandlerStateTemplate SecureHandlerEnterLeaveTemplate",bid == 1 and bid or nil)
        f['sbuttons'] = {}
        f['maxslots'] = mb
        f['sizeButton'] = bh or 32
        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,@player,nodead] 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
        f:SetAttribute('_onenter', [[
                self:SetAlpha(1)
        ]])
        f:SetAttribute('_onleave', [[
                if(self:GetAttribute('fadeIn')) then
                        self:SetAlpha(0)
                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)
                b:SetSize(32,32)
                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
        end
        addon['applySettings'](f:GetName(),32)
        if(db['bars'][f:GetName()]['fadein']) then fadeOut(lastbutton) end
        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')
        addon['applySettings']("zzABar20",32)
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
--              ShapeshiftButton1:SetSize(32,32)
                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)
                        addon['AddConfigEntry'](addon, name, 'toggle', 'fadein', 'Hide', 'Only show on mouseover', 0,1,12,1,false,o)
                end
                for i = 1,6 do
                        addP(createBar(i, NUM_ACTIONBAR_BUTTONS,32))
                end
                addP(createBar(20, NUM_SHAPESHIFT_SLOTS,32))
                addP(createBar(21, NUM_PET_ACTION_SLOTS,32))
--              addP(createBar(22, NUM_POSSESS_SLOTS,32))
                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("MultiActionBar_UpdateGridVisibility", function()
                local bar = _G['zzABar2']
                for i = 1, #bar['sbuttons'] do
                        local b = bar['sbuttons'][i]
                        if (ALWAYS_SHOW_MULTIBARS == "1" or ALWAYS_SHOW_MULTIBARS == 1 ) then
                                b:SetAttribute('showgrid',1)
                                ActionButton_ShowGrid(b)
                        else
                                b:SetAttribute('showgrid',0)
                                ActionButton_HideGrid(b)
                        end
                end
        end) 
        hideBlizz()
        local exitButton = CreateFrame("BUTTON", name.."ExitButton", UIParent, "SecureHandlerClickTemplate")
        exitButton:SetSize(64,64)
        exitButton:SetPoint("CENTER",0,0)
        exitButton:RegisterForClicks("AnyUp") -- UI-Vehicles-Button-Pitch-Up UI-VEHICLES-BUTTON-PITCHDOWN-UP
        exitButton:SetNormalTexture("Interface\\Vehicles\\UI-Vehicles-Button-Exit-Up")
        exitButton:SetScript("OnClick", function(self) VehicleExit() end)
        addon['addSimpleDrag'](exitButton,"FRAME")
        RegisterStateDriver(exitButton, "visibility", "[vehicleui] show;hide")
-- ExtraAction
        ExtraActionBarFrame:SetParent(UIParent)
        ExtraActionBarFrame:SetSize(64,64)
        ExtraActionBarFrame:SetPoint("CENTER",0,0)
        UIPARENT_MANAGED_FRAME_POSITIONS["ExtraActionBarFrame"] = nil
        addon['addSimpleDrag'](ExtraActionBarFrame,"FRAME")
        if(addon['MSQGroup']) then
                addon['MSQGroup']:AddButton(_G["ExtraActionButton1"])
        end
end

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

Compare with Previous | Blame