WoWInterface SVN zz_Actionbuttons

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

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

local name, addon = ...
local childName = name
local defaults = {}
local options, db
local _G = _G
local buttons = {}
local defBars = {
        'Action','MultiBarBottomLeft','MultiBarBottomRight','MultiBarLeft','MultiBarRight','Shapeshift','PetAction' ,'BonusAction'
}

local privFrame = {
        ['Action'] = true,
        ['MultiBarRight'] = true,
        ['BonusAction'] = "BonusActionBarFrame",
        ['Shapeshift'] = "ShapeshiftBarFrame",
}

local bagButtons = {
        MainMenuBarBackpackButton,
        CharacterBag0Slot,
        CharacterBag1Slot,
        CharacterBag2Slot,
        CharacterBag3Slot,
}
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 hooked = {}
local dummy = function() end

local function addDrag(self)
        if(not hooked[self]) then
                local bname = self:GetName()
                self:SetParent(UIParent)
                self:SetWidth(1)
                self:SetHeight(1)
                self:SetPoint("CENTER")
                if(not _G[bname.."drag"]) then
                        db['bars'][bname] = db['bars'][bname] or {
                                ['rows'] = 1,
                                ['scale'] = 1,
                        }
                        self['db'] = db['bars'][bname]
                        self['dragAble'] = dragAble
                        self:SetScale(self['db']['scale'])
                        addon['AddDrag'](self,"BOX",{
                                ['width'] = 64,
                                ['height'] = 64,
                                ['anchor'] = "TOPLEFT",
                                ['parentanchor'] = "TOPLEFT",
                                ['xOffset'] = 16,
                                ['yOffset'] = 16,
                                ['offset'] = 16,
                        })
                end
                hooked[self] = true
        else
                self:SetScale(self['db']['scale'])
        end
end

local function getBarname(bname)
        return (_G[bname] and privFrame[bname] == nil) and bname or ( type(privFrame[bname]) == 'string' and privFrame[bname] or name..bname.."Bar")
end

local function localButtons()
        wipe(buttons)
        local lastbutton
        for b = 1, #defBars do
                local barname = getBarname(defBars[b])
                local f = _G[barname] or CreateFrame("Frame", barname, UIParent, "SecureHandlerStateTemplate")
                UIPARENT_MANAGED_FRAME_POSITIONS[barname] = nil
                if(f) then
                        if(defBars[b]=='Action' and not hooked[f]) then
                                f:SetAttribute("actionpage",b)
                        end
                        f:SetFrameStrata("MEDIUM")
                        f:SetParent(UIParent)
                        if(defBars[b] == 'BonusAction' and not hooked[f]) then
                                f:HookScript("OnShow", function(self,...)
                                        for i = 1, 12 do
                                                _G["ActionButton"..i]:SetAlpha(0)
                                                _G["ActionButton"..i]:EnableMouse(false)
                                        end
                                end)
                                f:HookScript("OnHide", function(self,...)
                                        for i = 1, 12 do
                                                _G["ActionButton"..i]:SetAlpha(1)
                                                _G["ActionButton"..i]:EnableMouse(true)
                                        end
                                end)
                        end
                        addDrag(f)
                        local i,y = 1,1
                        local row = 0
                        local spr = 12/f['db']['rows']
                        lastbutton = f
                        while(_G[defBars[b]..'Button'..i]) do
                                local button = _G[defBars[b]..'Button'..i]
                                UIPARENT_MANAGED_FRAME_POSITIONS[button:GetName()] = nil
                                button:SetParent(f)
                                if(defBars[b] == 'Action') then
                                        button:SetID(i)
                                else
                                        button:SetID(0)
                                end
                                buttons[#buttons + 1] = button
                                if(addon['MSQ'] and addon['MSQGroup']) then
                                        addon['MSQGroup']:AddButton(button)
                                end
                                button:ClearAllPoints()
                                if(y == 1) then
                                        button:SetPoint("TOPLEFT", f, "TOPLEFT",0 , -row * button:GetHeight())
                                else
                                        button:SetPoint("TOPLEFT", lastbutton, "TOPRIGHT")
                                end
                                lastbutton = button
                                i = i + 1
                                y = y + 1
                                if(y > spr) then
                                        y = 1
                                        row = row + 1
                                end
                        end
                end
        end
        local f = _G[name.."MicroMenu"] or CreateFrame("Frame", name.."MicroMenu", UIParent)
        addDrag(f)

        local spr = 12/db['bars'][f:GetName()]['rows']
        lastbutton = f
        local y,row = 1,0
        for _, bname in pairs(MICRO_BUTTONS) do
                local btn = _G[bname]
                if(btn) then
                        UIPARENT_MANAGED_FRAME_POSITIONS[btn:GetName()] = nil
                        btn:SetParent(f)
                        btn:ClearAllPoints()
                        if(y == 1) then
                                btn:SetPoint("TOPLEFT", f, "TOPLEFT",0 , -row * 34)
                        else
                                btn:SetPoint("TOPLEFT", lastbutton, "TOPRIGHT")
                        end
                        y = y + 1
                        lastbutton = btn
                        if(y > spr) then
                                y = 1
                                row = row + 1
                        end
                end
        end
        f = _G[name.."BagBar"] or CreateFrame("Frame", name.."BagBar", UIParent)
        addDrag(f)
        local spr = 12/db['bars'][f:GetName()]['rows']
        lastbutton = f
        local y,row = 1,0
        for i = 1, #bagButtons do
                local btn = _G[bagButtons[i]]
                print(i,bagButtons[i], btn)
                if(btn) then
                        UIPARENT_MANAGED_FRAME_POSITIONS[btn:GetName()] = nil
                        btn:SetParent(f)
                        btn:ClearAllPoints()
                        if(y == 1) then
                                btn:SetPoint("TOPLEFT", f, "TOPLEFT",0 , -row * 34)
                        else
                                btn:SetPoint("TOPLEFT", lastbutton, "TOPRIGHT")
                        end
                        y = y + 1
                        lastbutton = btn
                        if(y > spr) then
                                y = 1
                                row = row + 1
                        end
                end
        end
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
        localButtons()
end

local function buildPrefs()
        for b = 1, #defBars do
                local bname = getBarname(defBars[b])
                local o = addon['AddConfigMenu'](addon, {
                        ['name'] = bname,
                        ['menuGet'] = getBarPref,
                        ['menuSet'] = setBarPref,
                }, addon['options']['args'][childName])
                addon['AddConfigEntry'](addon, name, 'range', 'rows', 'Rows', 'Number of rows', 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)
        end
        local o = addon['AddConfigMenu'](addon, {
                ['name'] = name.."MicroMenu",
                ['menuGet'] = getBarPref,
                ['menuSet'] = setBarPref,
        }, addon['options']['args'][childName])
        addon['AddConfigEntry'](addon, name, 'range', 'rows', 'Rows', 'Number of rows', 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)
end

local function getPref(pref)
        return db[pref[#pref]]
end

local function setPref(pref,value)
        db[pref[#pref]] = value
end
do
-- Copied from HBar
        local textures = {              -- Table with textures we wish to remove
                ReputationWatchBarTexture0,
                ReputationWatchBarTexture1,
                ReputationWatchBarTexture2,
                ReputationWatchBarTexture3,
                ReputationXPBarTexture0,
                ReputationXPBarTexture1,
                ReputationXPBarTexture2,
                ReputationXPBarTexture3,
                MainMenuXPBarTexture0,
                MainMenuXPBarTexture1,
                MainMenuXPBarTexture2,
                MainMenuXPBarTexture3,
                MainMenuMaxLevelBar0,
                MainMenuMaxLevelBar1,
                MainMenuMaxLevelBar2,
                MainMenuMaxLevelBar3,
                MainMenuBarTexture0,
                MainMenuBarTexture1,
                MainMenuBarTexture2,
                MainMenuBarTexture3,
                SlidingActionBarTexture0,       
                SlidingActionBarTexture1,
                BonusActionBarTexture0,
                BonusActionBarTexture1,
        }
        local hide = {
                MainMenuBarLeftEndCap,
                MainMenuBarRightEndCap,
                ReputationWatchBar,
                MainMenuExpBar,
                ActionBarUpButton,
                ActionBarDownButton,
                MainMenuBarPageNumber,
                BonusActionBarFrameTexture1,
                BonusActionBarFrameTexture2,
                BonusActionBarFrameTexture3,
                BonusActionBarFrameTexture4,
        }

        for _, frame in pairs(textures) do      -- Set the textures of the items in "textures" to nil
                frame:SetTexture("");
                frame.SetTexture = function() end
        end
        for _, frame in pairs(hide) do  -- Set the textures of the items in "textures" to nil
                frame:Hide()
                frame.Show = frame.Hide
        end
        MainMenuBar:SetFrameStrata("BACKGROUND")
end

local function togglePriv(show)
        for k,v in pairs(privFrame) do
                if(type(v) == 'boolean') then
                        _G[name..k.."Bar"]:SetAlpha(show and 1 or 0)
                end
        end
end

local function init()
        options = addon['InitConfig'](addon, childName, true, {
                ['type'] = "launcher",
        }, getPref, setPref)
        db = addon['db']['profile'][childName]
        db['bars'] = db['bars'] or {}
        localButtons()
        addon['AddConfigEntry'](addon, name, 'toggle', 'dragAble', 'Unlocked', 'Use alt+click to move your bars', 0)
        buildPrefs()
        addon['RegisterFunc']({"UNIT_EXITED_VEHICLE","UNIT_ENTERING_VEHICLE"}, "OnEvent", function(self, event,arg1,...)
                if(arg1 ~= 'player') then return end
                if(event == "UNIT_EXITED_VEHICLE") then
                        togglePriv(true)
                elseif(event == "UNIT_ENTERING_VEHICLE") then
                        togglePriv(false)
                end
        end)
        MoveMicroButtons = function() end
        VehicleMenuBar_MoveMicroButtons = function() end
end

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

Go to most recent revision | Compare with Previous | Blame