View Single Post
03-23-19, 07:44 PM   #9
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by Terenna View Post
That being said, is my solution using the secure code snippets and the registered state driver the "correct" way to go about my initial desire? Or is there a less verbose method that doesn't involve secureframes?
I would say your solution is ok. However, you are emulating a paging state driver with your visibility state driver. It could be simplified slightly(dry coded / untested):
Code:
local header = CreateFrame('Frame', nil, nil, 'SecureHandlerStateTemplate')

for id = 1, NUM_ACTIONBAR_BUTTONS do
    local name = 'ActionButton' .. id
    header:SetFrameRef(name, _G[name])
end

for id = 1, NUM_OVERRIDE_BUTTONS do
    local name = 'OverrideActionBarButton' .. id
    header:SetFrameRef(name, _G[name])
end

header:Execute(([[
    actionButton = table.new()
    for id = 1, NUM_ACTIONBAR_BUTTONS do
        actionButton[id] = self:GetFrameRef('ActionButton' .. id)
    end
 
    overrideButton = table.new()
    for id = 1, NUM_OVERRIDE_BUTTONS do
        overrideButton[id] = self:GetFrameRef('OverrideActionBarButton' .. id)
    end
]]):gsub('NUM_ACTIONBAR_BUTTONS', NUM_ACTIONBAR_BUTTONS):gsub('NUM_OVERRIDE_BUTTONS', NUM_OVERRIDE_BUTTONS))

header:SetAttribute("_onstate-override", ([[
    if newstate then
        for id = 1, NUM_OVERRIDE_BUTTONS do
            local stateHidden = overrideButton[id]:GetAttribute('statehidden')
            actionButton[id]:SetAttribute('statehidden', stateHidden)
            actionButton[id][stateHidden and 'Hide' or 'Show'](actionButton[id])
        end
        for id = NUM_OVERRIDE_BUTTONS + 1, NUM_ACTIONBAR_BUTTONS do
            actionButton[id]:SetAttribute('statehidden', true)
            actionButton[id]:Hide()
        end
    else
        for id = 1, NUM_ACTIONBAR_BUTTONS do
            actionButton[id]:SetAttribute('statehidden', false)
            actionButton[id]:Show()
        end
    end
]]):gsub('NUM_ACTIONBAR_BUTTONS', NUM_ACTIONBAR_BUTTONS):gsub('NUM_OVERRIDE_BUTTONS', NUM_OVERRIDE_BUTTONS))
RegisterStateDriver(header, "override", "[overridebar][vehicleui] true")
Since you are running an additional paging state driver at this point wouldn't it be easier to just change the parameters of the paging state driver for the addon that is misbehaving? This is what I use and haven't had any issues (I hardly play any more so that may be a factor, but I did complete Righteous Retribution without issue):
Code:
[vehicleui] 12; [overridebar] 14; [possessbar] [@vehicle, exists] 12; [shapeshift] 13; [bar:2] 2; [bar:3] 3; [bar:4] 4; [bar:5] 5; [bar:6] 6; [bonusbar:1] 7; [bonusbar:2] 8; [bonusbar:3] 9; [bonusbar:4] 10; [bonusbar:5] 11; 1
For future reference, to hook a script and run secure code you need to create a frame using one of the SecureHandler templates and then use it's WrapScript method:
Code:
local header = CreateFrame('Frame', nil, nil, 'SecureHandlerBaseTemplate')
header:WrapScript(ActionButton1, 'OnAttributeChanged', [[
    print(self:GetName(), 'OnAttributeChanged', name, value)
    -- Your secure snippet here
]])
  Reply With Quote