add hooks for Ace3 editBoxes

update Ace3Keybinging widget
This commit is contained in:
Pinya
2018-07-21 18:38:16 +03:00
parent bf015aea4d
commit 2658c39dc6
3 changed files with 236 additions and 3 deletions
@@ -7,12 +7,27 @@ if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs
local tostring, pairs = tostring, pairs
local gsub, sub = string.gsub, string.sub
-- WoW APIs
local PlaySound = PlaySound
local GetCursorInfo, ClearCursor, GetSpellName = GetCursorInfo, ClearCursor, GetSpellName
local CreateFrame, UIParent = CreateFrame, UIParent
local _G = _G
local GetContainerItemLink = GetContainerItemLink
local GetInventoryItemLink = GetInventoryItemLink
local GetLootSlotLink = GetLootSlotLink
local GetMerchantItemLink = GetMerchantItemLink
local GetQuestItemLink = GetQuestItemLink
local GetQuestLogItemLink = GetQuestLogItemLink
local GetSpellName = GetSpellName
local IsShiftKeyDown = IsShiftKeyDown
local IsSpellPassive = IsSpellPassive
local SpellBook_GetSpellID = SpellBook_GetSpellID
local BANK_CONTAINER = BANK_CONTAINER
local KEYRING_CONTAINER = KEYRING_CONTAINER
local MAX_SPELLS = MAX_SPELLS
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
@@ -23,6 +38,104 @@ Support functions
-------------------------------------------------------------------------------]]
if not AceGUIEditBoxInsertLink then
-- upgradeable hook
local orig_BankFrameItemButtonGeneric_OnClick = BankFrameItemButtonGeneric_OnClick
function BankFrameItemButtonGeneric_OnClick(button)
if button == "LeftButton" and IsShiftKeyDown() and not this.isBag then
return _G.AceGUIEditBoxInsertLink(GetContainerItemLink(BANK_CONTAINER, this:GetID()))
end
end
local orig_ContainerFrameItemButton_OnClick = ContainerFrameItemButton_OnClick
function ContainerFrameItemButton_OnClick(button, ignoreModifiers)
if button == "LeftButton" and IsShiftKeyDown() and not ignoreModifiers then
return _G.AceGUIEditBoxInsertLink(GetContainerItemLink(this:GetParent():GetID(), this:GetID()))
end
end
local orig_KeyRingItemButton_OnClick = KeyRingItemButton_OnClick
function KeyRingItemButton_OnClick(button)
if button == "LeftButton" and IsShiftKeyDown() and not this.isBag then
return _G.AceGUIEditBoxInsertLink(GetContainerItemLink(KEYRING_CONTAINER, this:GetID()))
end
end
local orig_LootFrameItem_OnClick = LootFrameItem_OnClick
function LootFrameItem_OnClick(button)
if button == "LeftButton" and IsShiftKeyDown() then
return _G.AceGUIEditBoxInsertLink(GetLootSlotLink(this.slot))
end
end
local orig_SetItemRef = SetItemRef
function SetItemRef(link, text, button)
if IsShiftKeyDown() then
if sub(link, 1, 6) == "player" then
local name = sub(link, 8)
if name and name ~= "" then
return _G.AceGUIEditBoxInsertLink(name)
end
else
return _G.AceGUIEditBoxInsertLink(text)
end
end
end
local orig_MerchantItemButton_OnClick = MerchantItemButton_OnClick
function MerchantItemButton_OnClick(button, ignoreModifiers)
if MerchantFrame.selectedTab == 1 and button == "LeftButton" and IsShiftKeyDown() and not ignoreModifiers then
return _G.AceGUIEditBoxInsertLink(GetMerchantItemLink(this:GetID()))
end
end
local orig_PaperDollItemSlotButton_OnClick = PaperDollItemSlotButton_OnClick
function PaperDollItemSlotButton_OnClick(button, ignoreModifiers)
if button == "LeftButton" and IsShiftKeyDown() and not ignoreModifiers then
return _G.AceGUIEditBoxInsertLink(GetInventoryItemLink("player", this:GetID()))
end
end
local orig_QuestItem_OnClick = QuestItem_OnClick
function QuestItem_OnClick()
if IsShiftKeyDown() and this.rewardType ~= "spell" then
return _G.AceGUIEditBoxInsertLink(GetQuestItemLink(this.type, this:GetID()))
end
end
local orig_QuestRewardItem_OnClick = QuestRewardItem_OnClick
function QuestRewardItem_OnClick()
if IsShiftKeyDown() and this.rewardType ~= "spell" then
return _G.AceGUIEditBoxInsertLink(GetQuestItemLink(this.type, this:GetID()))
end
end
local orig_QuestLogTitleButton_OnClick = QuestLogTitleButton_OnClick
function QuestLogTitleButton_OnClick(button)
if IsShiftKeyDown() and (not this.isHeader) then
return _G.AceGUIEditBoxInsertLink(gsub(this:GetText(), " *(.*)", "%1"))
end
end
local orig_QuestLogRewardItem_OnClick = QuestLogRewardItem_OnClick
function QuestLogRewardItem_OnClick()
if IsShiftKeyDown() and this.rewardType ~= "spell" then
return _G.AceGUIEditBoxInsertLink(GetQuestLogItemLink(this.type, this:GetID()))
end
end
local orig_SpellButton_OnClick = SpellButton_OnClick
function SpellButton_OnClick(drag)
local id = SpellBook_GetSpellID(this:GetID())
if id <= MAX_SPELLS and (not drag) and IsShiftKeyDown() then
local spellName, subSpellName = GetSpellName(id, SpellBookFrame.bookType)
if spellName and not IsSpellPassive(id, SpellBookFrame.bookType) then
if subSpellName and subSpellName ~= "" then
_G.AceGUIEditBoxInsertLink(spellName.."("..subSpellName..")")
else
_G.AceGUIEditBoxInsertLink(spellName)
end
end
end
end
end
function _G.AceGUIEditBoxInsertLink(text)
@@ -29,7 +29,15 @@ local function Control_OnLeave()
this.obj:Fire("OnLeave")
end
--[[
local function Keybinding_OnHide()
local self = this.obj
this:EnableKeyboard(false)
this:EnableMouseWheel(false)
self.msgframe:Hide()
this:UnlockHighlight()
self.waitingForKey = nil
end
local function Keybinding_OnClick()
if arg1 == "LeftButton" or arg1 == "RightButton" then
local self = this.obj
@@ -49,7 +57,6 @@ local function Keybinding_OnClick()
end
AceGUI:ClearFocus()
end
]]
local ignoreKeys = {
["BUTTON1"] = true, ["BUTTON2"] = true,
@@ -224,6 +231,7 @@ local function Constructor()
button:SetScript("OnKeyDown", Keybinding_OnKeyDown)
button:SetScript("OnMouseDown", Keybinding_OnMouseDown)
button:SetScript("OnMouseWheel", Keybinding_OnMouseWheel)
button:SetScript("OnHide", Keybinding_OnHide)
button:SetPoint("BOTTOMLEFT", 0, 0)
button:SetPoint("BOTTOMRIGHT", 0, 0)
button:SetHeight(24)
@@ -4,12 +4,26 @@ if not AceGUI or (AceGUI:GetWidgetVersion(Type) or 0) >= Version then return end
-- Lua APIs
local pairs = pairs
local format = string.format
local format, gsub, sub = string.format, string.gsub, string.sub
-- WoW APIs
local GetCursorInfo, GetSpellName, ClearCursor = GetCursorInfo, GetSpellName, ClearCursor
local CreateFrame, UIParent = CreateFrame, UIParent
local _G = _G
local GetContainerItemLink = GetContainerItemLink
local GetInventoryItemLink = GetInventoryItemLink
local GetLootSlotLink = GetLootSlotLink
local GetMerchantItemLink = GetMerchantItemLink
local GetQuestItemLink = GetQuestItemLink
local GetQuestLogItemLink = GetQuestLogItemLink
local GetSpellName = GetSpellName
local IsShiftKeyDown = IsShiftKeyDown
local IsSpellPassive = IsSpellPassive
local SpellBook_GetSpellID = SpellBook_GetSpellID
local BANK_CONTAINER = BANK_CONTAINER
local KEYRING_CONTAINER = KEYRING_CONTAINER
local MAX_SPELLS = MAX_SPELLS
-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded
-- List them here for Mikk's FindGlobals script
@@ -21,6 +35,104 @@ Support functions
if not AceGUIMultiLineEditBoxInsertLink then
-- upgradeable hook
local orig_BankFrameItemButtonGeneric_OnClick = BankFrameItemButtonGeneric_OnClick
function BankFrameItemButtonGeneric_OnClick(button)
if button == "LeftButton" and IsShiftKeyDown() and not this.isBag then
return _G.AceGUIMultiLineEditBoxInsertLink(GetContainerItemLink(BANK_CONTAINER, this:GetID()))
end
end
local orig_ContainerFrameItemButton_OnClick = ContainerFrameItemButton_OnClick
function ContainerFrameItemButton_OnClick(button, ignoreModifiers)
if button == "LeftButton" and IsShiftKeyDown() and not ignoreModifiers then
return _G.AceGUIMultiLineEditBoxInsertLink(GetContainerItemLink(this:GetParent():GetID(), this:GetID()))
end
end
local orig_KeyRingItemButton_OnClick = KeyRingItemButton_OnClick
function KeyRingItemButton_OnClick(button)
if button == "LeftButton" and IsShiftKeyDown() and not this.isBag then
return _G.AceGUIMultiLineEditBoxInsertLink(GetContainerItemLink(KEYRING_CONTAINER, this:GetID()))
end
end
local orig_LootFrameItem_OnClick = LootFrameItem_OnClick
function LootFrameItem_OnClick(button)
if button == "LeftButton" and IsShiftKeyDown() then
return _G.AceGUIMultiLineEditBoxInsertLink(GetLootSlotLink(this.slot))
end
end
local orig_SetItemRef = SetItemRef
function SetItemRef(link, text, button)
if IsShiftKeyDown() then
if sub(link, 1, 6) == "player" then
local name = sub(link, 8)
if name and name ~= "" then
return _G.AceGUIMultiLineEditBoxInsertLink(name)
end
else
return _G.AceGUIMultiLineEditBoxInsertLink(text)
end
end
end
local orig_MerchantItemButton_OnClick = MerchantItemButton_OnClick
function MerchantItemButton_OnClick(button, ignoreModifiers)
if MerchantFrame.selectedTab == 1 and button == "LeftButton" and IsShiftKeyDown() and not ignoreModifiers then
return _G.AceGUIMultiLineEditBoxInsertLink(GetMerchantItemLink(this:GetID()))
end
end
local orig_PaperDollItemSlotButton_OnClick = PaperDollItemSlotButton_OnClick
function PaperDollItemSlotButton_OnClick(button, ignoreModifiers)
if button == "LeftButton" and IsShiftKeyDown() and not ignoreModifiers then
return _G.AceGUIMultiLineEditBoxInsertLink(GetInventoryItemLink("player", this:GetID()))
end
end
local orig_QuestItem_OnClick = QuestItem_OnClick
function QuestItem_OnClick()
if IsShiftKeyDown() and this.rewardType ~= "spell" then
return _G.AceGUIMultiLineEditBoxInsertLink(GetQuestItemLink(this.type, this:GetID()))
end
end
local orig_QuestRewardItem_OnClick = QuestRewardItem_OnClick
function QuestRewardItem_OnClick()
if IsShiftKeyDown() and this.rewardType ~= "spell" then
return _G.AceGUIMultiLineEditBoxInsertLink(GetQuestItemLink(this.type, this:GetID()))
end
end
local orig_QuestLogTitleButton_OnClick = QuestLogTitleButton_OnClick
function QuestLogTitleButton_OnClick(button)
if IsShiftKeyDown() and (not this.isHeader) then
return _G.AceGUIMultiLineEditBoxInsertLink(gsub(this:GetText(), " *(.*)", "%1"))
end
end
local orig_QuestLogRewardItem_OnClick = QuestLogRewardItem_OnClick
function QuestLogRewardItem_OnClick()
if IsShiftKeyDown() and this.rewardType ~= "spell" then
return _G.AceGUIMultiLineEditBoxInsertLink(GetQuestLogItemLink(this.type, this:GetID()))
end
end
local orig_SpellButton_OnClick = SpellButton_OnClick
function SpellButton_OnClick(drag)
local id = SpellBook_GetSpellID(this:GetID())
if id <= MAX_SPELLS and (not drag) and IsShiftKeyDown() then
local spellName, subSpellName = GetSpellName(id, SpellBookFrame.bookType)
if spellName and not IsSpellPassive(id, SpellBookFrame.bookType) then
if subSpellName and subSpellName ~= "" then
_G.AceGUIMultiLineEditBoxInsertLink(spellName.."("..subSpellName..")")
else
_G.AceGUIMultiLineEditBoxInsertLink(spellName)
end
end
end
end
end
function _G.AceGUIMultiLineEditBoxInsertLink(text)