View Single Post
01-23-18, 03:19 AM   #6
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
Lua Code:
  1. -- FrameXML\SecureTemplates.lua:351
  2. SECURE_ACTIONS.pet =
  3.     function (self, unit, button)
  4.         local action =
  5.             SecureButton_GetModifiedAttribute(self, "action", button);
  6.         if ( action ) then
  7.             CastPetAction(action, unit);
  8.         end
  9.     end;

Damn, I didn't even know this. They could change it to this...
Lua Code:
  1. SECURE_ACTIONS.pet =
  2.     function (self, unit, button)
  3.         local action =
  4.             SecureButton_GetModifiedAttribute(self, "action", button);
  5.         if ( action ) then
  6.             if ( button == "LeftButton" ) then
  7.                 CastPetAction(action, unit);
  8.             else
  9.                 TogglePetAutocast(action);
  10.             end
  11.         end
  12.     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:
    1. local function GetActionpageStateDriver()
    2.     -- Generate a macro condition with generic values to ensure any change pushes an update.
    3.     -- Add any new / extra macro conditions to the list below. (as if there aren't enough already)
    4.     local conditionFormat = '[%s] %d; '
    5.     local count, driver = 0, ''
    6.     local conditions = {
    7.         ----------------------------------
    8.         'vehicleui', 'possessbar', 'overridebar', 'shapeshift',
    9.         'bar:2', 'bar:3', 'bar:4', 'bar:5', 'bar:6',
    10.         'bonusbar:1', 'bonusbar:2', 'bonusbar:3', 'bonusbar:4'
    11.         ----------------------------------
    12.     }
    13.     for i, condition in ipairs(conditions) do
    14.         driver = driver .. format(conditionFormat, condition, i)
    15.     end
    16.     driver = driver .. (#conditions + 1) -- append the list for the default bar (1) when none of the conditions apply.
    17.     -- this ends up looking like this: "[vehicleui] 1; [possessbar] 2; ... [bonusbar:4] 13; 14"
    18.     ----------------------------------
    19.     return driver
    20. end
    21.  
    22. -- Register the generic state driver just so it sends updates on page swaps.
    23. RegisterStateDriver(mainBar, 'page', GetActionpageStateDriver())
    24.  
    25. -- With this approach, newstate is expected to return an incorrect value,
    26. -- because I didn't bother finding out which condition corresponds to which page.
    27. -- Instead I'm using the available API in the environment to calculate the page.
    28. -- This is pretty much an exact copy of ActionBarController_UpdateAll,
    29. -- which you can find in FrameXML\ActionBarController.lua:107
    30. mainBar:SetAttribute('_onstate-page', [[
    31.     if HasVehicleActionBar() then
    32.         newstate = GetVehicleBarIndex()
    33.     elseif HasOverrideActionBar() then
    34.         newstate = GetOverrideBarIndex()
    35.     elseif HasTempShapeshiftActionBar() then
    36.         newstate = GetTempShapeshiftBarIndex()
    37.     elseif GetBonusBarOffset() > 0 then
    38.         newstate = GetBonusBarOffset() + 6
    39.     else
    40.         newstate = GetActionBarPage()
    41.     end
    42.     self:SetAttribute('actionpage', newstate)
    43.     control:ChildUpdate('actionpage', newstate)
    44. ]])
__________________

Last edited by MunkDev : 01-23-18 at 03:35 AM.
  Reply With Quote