Skip to content

Commit

Permalink
fix override ui binder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tuller committed Jan 28, 2024
1 parent 577f7b5 commit 95c05dd
Showing 1 changed file with 37 additions and 44 deletions.
81 changes: 37 additions & 44 deletions Dominos/bars/actionBar/bindings.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local _, Addon = ...
if not Addon:IsBuild("retail") then return end
if not OverrideActionBar then return end

--------------------------------------------------------------------------------
-- Sets priority bindings to the Pet Battle and Override UI when either frame
Expand All @@ -11,72 +12,64 @@ if not Addon:IsBuild("retail") then return end
-- from those
--------------------------------------------------------------------------------

local Binder = CreateFrame("Frame", nil, nil, "SecureHandlerStateTemplate")
local Binder = CreateFrame("Frame", nil, nil, "SecureHandlerAttributeTemplate")

Binder:WrapScript(OverrideActionBar, "OnShow", [[
self:SetAttribute("state-overrideui", 1)
Binder:WrapScript(OverrideActionBarButton1, "OnShow", [[
control:SetAttribute("overrideui", 1)
]])

Binder:WrapScript(OverrideActionBar, "OnHide", [[
self:SetAttribute("state-overrideui", 0)
Binder:WrapScript(OverrideActionBarButton1, "OnHide", [[
control:SetAttribute("overrideui", 0)
]])

Binder:SetAttributeNoHandler("_onstate-overrideui", [[
local bindState = self:GetAttribute("state-bind") or 0
Binder:SetAttributeNoHandler("_onattributechanged", [[
if name == "bind" then return end
if newstate == 1 or self:GetAttribute("state-petabattleui") == 1 then
if bindState == 0 then
self:SetAttribute("state-bind", 1)
end
else
if bindState == 1 then
self:SetAttribute("state-bind", 0)
end
end
]])
local bind = (
(self:GetAttribute("overrideui") == 1 and self:GetAttribute("useoverrideui") == 1)
or self:GetAttribute("petbattleui") == 1
)
Binder:SetAttributeNoHandler("_onstate-petabattleui", [[
local bindState = self:GetAttribute("state-bind") or 0
if self:GetAttribute("bind") ~= bind then
self:SetAttribute("bind", bind)
self:ClearBindings()
if newstate == 1 or self:GetAttribute("state-overrideui") == 1 then
if bindState == 0 then
self:SetAttribute("state-bind", 1)
end
else
if bindState == 1 then
self:SetAttribute("state-bind", 0)
end
end
]])

Binder:SetAttributeNoHandler("_onstate-bind", [[
self:ClearBindings()
if newstate == 1 then
for i = 1, 6 do
local command = "ACTIONBUTTON" .. i
local keyCommand = self:GetAttribute(command) or command
self:RunAttribute("SetBindings", command, GetBindingKey(keyCommand))
if bind then
for i = 1, 6 do
local command = "ACTIONBUTTON" .. i
local keyCommand = self:GetAttribute(command) or command
self:RunAttribute("SetBindings", command, GetBindingKey(keyCommand))
end
end
end
]])

Binder:SetAttributeNoHandler("SetBindings", [[
local command = ...
for i = 2, select("#", ...) do
self:SetBinding(true, select(i, ...), command)
end
]])

-- initialize state
Binder:SetScript("OnEvent", function(self, event)
self:UnregisterEvent(event)
self:SetScript("OnEvent", nil)
self:UnregisterEvent(event)

-- initialize secure state
self:SetAttribute("state-overrideui", OverrideActionBar:IsVisible() and 1 or 0)
RegisterStateDriver(self, "petabattleui", "[petbattle]1;0")
self:SetAttribute("overrideui", OverrideActionBarButton1:IsShown() and 1 or 0)
self:SetAttribute("useoverrideui", Addon:UsingOverrideUI() and 1 or 0)
RegisterAttributeDriver(self, "petabattleui", "[petbattle]1;0")
end)

Binder:RegisterEvent("PLAYER_LOGIN")

function Binder:USE_OVERRRIDE_UI_CHANGED(_, enabled)
self:SetAttribute("useoverrideui", enabled and 1 or 0)
end

function Binder:LAYOUT_LOADED()
self:SetAttribute("useoverrideui", Addon:UsingOverrideUI() and 1 or 0)
end

Addon.RegisterCallback(Binder, "USE_OVERRRIDE_UI_CHANGED")
Addon.RegisterCallback(Binder, "LAYOUT_LOADED")

0 comments on commit 95c05dd

Please sign in to comment.