View Single Post
08-28-18, 08:41 PM   #18
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
This should let you just use one action bar for everything:
Code:
local BUTTON_SIZE, BUTTON_SPACING = 50, 1

------------------------------------------------------
--[[              Bar Setup                       ]]--
------------------------------------------------------
local actionBar = CreateFrame("Frame", "XActionBar", UIParent, "SecureHandlerStateTemplate")
actionBar:SetSize((BUTTON_SIZE + BUTTON_SPACING) * NUM_ACTIONBAR_BUTTONS, BUTTON_SIZE)
actionBar:SetPoint("CENTER")

local background = actionBar:CreateTexture(nil, "BACKGROUND")
background:SetColorTexture(0, 0, 0, 0.5)
background:SetAllPoints()

actionBar:Execute([[
    buttons = newtable()
]])

------------------------------------------------------
--[[                 Button Setup                 ]]--
------------------------------------------------------
local buttons = { }
for id = 1, NUM_ACTIONBAR_BUTTONS do
    local button = CreateFrame("CheckButton", "$parentButton" .. id, actionBar, "ActionBarButtonTemplate")
    button:SetID(id)

    button:SetSize(BUTTON_SIZE, BUTTON_SIZE)
    if id ~= 1 then
        button:SetPoint("LEFT", buttons[id - 1], "RIGHT", BUTTON_SPACING, 0)
    else
        button:SetPoint("LEFT")
    end

    button.NormalTexture:Hide()

    actionBar:SetFrameRef("button", button)
    actionBar:Execute(([[
        buttons[%s] = self:GetFrameRef("button")
    ]]):format(id))

    buttons[id] = button
end
actionBar.Buttons = buttons

actionBar:Execute([[
    self:SetAttribute("frameref-button", nil)
]])

------------------------------------------------------
--[[                 Paging Stuff                 ]]--
------------------------------------------------------
actionBar:SetAttribute('_onstate-page', ([[
    if not newstate then return end
    newstate = tonumber(newstate)
    self:SetAttribute("actionpage", newstate)

    local pageOffset, hasAction = (newstate - 1) * NUM_ACTIONBAR_BUTTONS
    for id = 1, NUM_ACTIONBAR_BUTTONS do
        if HasAction(id + pageOffset) then
            buttons[id]:SetAttribute('actionpage', newstate)
            hasAction = true
        else
            buttons[id]:SetAttribute('actionpage', nil)
        end
    end

    if not hasAction then
        self:SetAttribute("state-page", nil)
    end
]]):gsub('NUM_ACTIONBAR_BUTTONS', NUM_ACTIONBAR_BUTTONS))

local paging = {
    ("[vehicleui] %d"):format(GetVehicleBarIndex()),
    ("[overridebar] %s"):format(GetOverrideBarIndex()),
    ("[possessbar] [@vehicle, exists] %s"):format(GetVehicleBarIndex()),
    ("[shapeshift] %d"):format(GetTempShapeshiftBarIndex())
}
for index = 2, NUM_ACTIONBAR_PAGES do
    paging[#paging + 1] = ("[bar:%d] %d"):format(index, index)
end
for index = 1, 5 do
    paging[#paging + 1] = ("[bonusbar:%d] %d"):format(index, index + NUM_ACTIONBAR_PAGES)
end
paging[#paging + 1] = "1"
RegisterStateDriver(actionBar, "page", strjoin("; ", unpack(paging)))

------------------------------------------------------
--[[                 Leave Button                 ]]--
------------------------------------------------------
OverrideActionBarLeaveFrameLeaveButton:SetParent(actionBar)
OverrideActionBarLeaveFrameLeaveButton:SetAllPoints(buttons[12])
RegisterStateDriver(OverrideActionBarLeaveFrameLeaveButton, "visibility", "[canexitvehicle] show; hide")
Can you provide a Wowhead link to the quest you have been testing this against (I may want to try some other ideas out later)?
  Reply With Quote