Lua Code:
-- FrameXML\SecureTemplates.lua:351
SECURE_ACTIONS.pet =
function (self, unit, button)
local action =
SecureButton_GetModifiedAttribute(self, "action", button);
if ( action ) then
CastPetAction(action, unit);
end
end;
Damn, I didn't even know this. They could change it to this...
Lua Code:
SECURE_ACTIONS.pet =
function (self, unit, button)
local action =
SecureButton_GetModifiedAttribute(self, "action", button);
if ( action ) then
if ( button == "LeftButton" ) then
CastPetAction(action, unit);
else
TogglePetAutocast(action);
end
end
end;
...or give a separate type for it since you might want to use something other than LeftButton as input.
I've also built my own version of LAB because it didn't cover all my needs, but here are my recommendations anyway:
- I'm just using PetActionButtonTemplate for a separate pet bar. I haven't bothered trying to fit a square peg in a round hole.
- For posterity I recommend not pre-calculating the actionpage attribute using a state driver, because to me it seems these numbers may change when they make changes to certain specs; Shadowdance used to have its own page, and monks had several pages for stances that no longer exist.
Lua Code:
local function GetActionpageStateDriver()
-- Generate a macro condition with generic values to ensure any change pushes an update.
-- Add any new / extra macro conditions to the list below. (as if there aren't enough already)
local conditionFormat = '[%s] %d; '
local count, driver = 0, ''
local conditions = {
----------------------------------
'vehicleui', 'possessbar', 'overridebar', 'shapeshift',
'bar:2', 'bar:3', 'bar:4', 'bar:5', 'bar:6',
'bonusbar:1', 'bonusbar:2', 'bonusbar:3', 'bonusbar:4'
----------------------------------
}
for i, condition in ipairs(conditions) do
driver = driver .. format(conditionFormat, condition, i)
end
driver = driver .. (#conditions + 1) -- append the list for the default bar (1) when none of the conditions apply.
-- this ends up looking like this: "[vehicleui] 1; [possessbar] 2; ... [bonusbar:4] 13; 14"
----------------------------------
return driver
end
-- Register the generic state driver just so it sends updates on page swaps.
RegisterStateDriver(mainBar, 'page', GetActionpageStateDriver())
-- With this approach, newstate is expected to return an incorrect value,
-- because I didn't bother finding out which condition corresponds to which page.
-- Instead I'm using the available API in the environment to calculate the page.
-- This is pretty much an exact copy of ActionBarController_UpdateAll,
-- which you can find in FrameXML\ActionBarController.lua:107
mainBar:SetAttribute('_onstate-page', [[
if HasVehicleActionBar() then
newstate = GetVehicleBarIndex()
elseif HasOverrideActionBar() then
newstate = GetOverrideBarIndex()
elseif HasTempShapeshiftActionBar() then
newstate = GetTempShapeshiftBarIndex()
elseif GetBonusBarOffset() > 0 then
newstate = GetBonusBarOffset() + 6
else
newstate = GetActionBarPage()
end
self:SetAttribute('actionpage', newstate)
control:ChildUpdate('actionpage', newstate)
]])