function KeyBind:OnBind(key)
KeyBind.hasChanges = true
if (key == "ESCAPE") then
if (KeyBind.frame.button.bindings) then
for i = 1, #KeyBind.frame.button.bindings do
SetBinding(KeyBind.frame.button.bindings[i])
end
end
KeyBind:OnBindUpdate(KeyBind.frame.button, KeyBind.frame.spellMacro)
return
end
local isFlyOut = (KeyBind.frame.button.FlyoutArrow and KeyBind.frame.button.FlyoutArrow:IsShown())
if ((key == "LSHIFT") or (key == "RSHIFT") or (key == "LCTRL") or (key == "RCTRL") or (key == "LALT") or (key == "RALT") or (key == "UNKNOWN")) then
return
end
if ((key == "LeftButton") and isFlyOut) then
SecureActionButton_OnClick(KeyBind.frame.button)
end
if (key == "MiddleButton") then
key = "BUTTON3"
end
if (key:find("Button%d")) then
key = key:upper()
end
local allowBinding = (not isFlyOut or (key ~= "LeftButton"))
if (allowBinding and KeyBind.frame.button.bindString) then
local alt = IsAltKeyDown() and "ALT-" or ""
local ctrl = IsControlKeyDown() and "CTRL-" or ""
local shift = IsShiftKeyDown() and "SHIFT-" or ""
SetBinding(alt .. ctrl .. shift .. key, KeyBind.frame.button.bindString)
end
KeyBind:OnBindUpdate(KeyBind.frame.button, KeyBind.frame.spellMacro)
end
function KeyBind:OnBindUpdate(button, spellMacro)
if ((not KeyBind.frame.active) or InCombatLockdown()) then
return
end
KeyBind.frame.button = button
KeyBind.frame.spellMacro = spellMacro
KeyBind.frame.bindString = nil
KeyBind.frame:ClearAllPoints()
KeyBind.frame:SetAllPoints(button)
KeyBind.frame:Show()
if (spellMacro == "FLYOUT") then
KeyBind.frame.button.name = KeyBind.frame.button.spellName
KeyBind.frame.button.bindString = spellMacro .. " " .. KeyBind.frame.button.name
elseif (spellMacro == "SPELL") then
KeyBind.frame.button.id = SpellBook_GetSpellBookSlot(KeyBind.frame.button)
KeyBind.frame.button.name = GetSpellBookItemName(KeyBind.frame.button.id, _G.SpellBookFrame.bookType)
KeyBind.frame.button.bindString = spellMacro .. " " .. KeyBind.frame.button.name
elseif (spellMacro == "MACRO") then
KeyBind.frame.button.id = KeyBind.frame.button:GetID()
if ((MATH:Floor(.5 + select(2, _G.MacroFrameTab1Text:GetTextColor()) * 10) / 10) == .8) then
KeyBind.frame.button.id = KeyBind.frame.button.id + MAX_ACCOUNT_MACROS
end
KeyBind.frame.button.name = GetMacroInfo(KeyBind.frame.button.id)
button.bindString = spellMacro .. " " .. KeyBind.frame.KeyBind.frame.button.name
elseif (spellMacro == "MICRO") then
KeyBind.frame.button.name = KeyBind.frame.button.tooltipText
KeyBind.frame.button.bindString = KeyBind.frame.button.commandName
elseif (spellMacro == "BAG") then
if (KeyBind.frame.button.itemID) then
KeyBind.frame.button.name = KeyBind.frame.button.name
KeyBind.frame.button.bindString = "ITEM item:" .. KeyBind.frame.button.itemID
end
else
KeyBind.frame.button.name = KeyBind.frame.button:GetName()
if (not KeyBind.frame.button.name) then
return
end
if (KeyBind.frame.button.keyBoundTarget) then
KeyBind.frame.button.bindString = KeyBind.frame.button.keyBoundTarget
elseif (KeyBind.frame.button.commandName) then -- pet and stance
KeyBind.frame.button.bindString = KeyBind.frame.button.commandName
elseif (KeyBind.frame.button.action) then
local action = MATH:ToNumber(KeyBind.frame.button.action)
local mod = (1 + ((action - 1) % 12))
if (KeyBind.frame.button.name == "ExtraActionButton1") then
KeyBind.frame.button.bindString = "EXTRAACTIONBUTTON1"
elseif ((KeyBind.frame.button.action < 25) or (KeyBind.frame.button.action > 72)) then
KeyBind.frame.button.bindString = "ACTIONBUTTON" .. mod
elseif ((KeyBind.frame.button.action < 73) and (KeyBind.frame.button.action > 60)) then
KeyBind.frame.button.bindString = "MULTIACTIONBAR1BUTTON" .. mod
elseif ((KeyBind.frame.button.action < 61) and (KeyBind.frame.button.action > 48)) then
KeyBind.frame.button.bindString = "MULTIACTIONBAR2BUTTON" .. mod
elseif ((KeyBind.frame.button.action < 49) and (KeyBind.frame.button.action > 36)) then
KeyBind.frame.button.bindString = "MULTIACTIONBAR4BUTTON" .. mod
elseif ((KeyBind.frame.button.action < 37) and (KeyBind.frame.button.action > 24)) then
KeyBind.frame.button.bindString = "MULTIACTIONBAR3BUTTON" .. mod
end
end
end
if (KeyBind.frame.button.bindString) then
KeyBind.frame.button.bindings = { GetBindingKey(KeyBind.frame.button.bindString) }
end
end