some hooking refactoring
This commit is contained in:
@@ -118,41 +118,32 @@ function Aux.setup_hooks()
|
||||
end
|
||||
AuctionFrame:SetScript('OnHide', blizzard_ui_on_hide)
|
||||
|
||||
Aux.orig.AuctionFrame_OnShow = AuctionFrame_OnShow
|
||||
AuctionFrame_OnShow = function()
|
||||
Aux.hook('AuctionFrame_OnShow', function(...)
|
||||
if not Aux.blizzard_ui_shown then
|
||||
Aux.control.as_soon_as(function() return AuctionFrame:GetScript('OnHide') == blizzard_ui_on_hide end, function()
|
||||
HideUIPanel(AuctionFrame)
|
||||
end)
|
||||
end
|
||||
return Aux.orig.AuctionFrame_OnShow()
|
||||
end
|
||||
return Aux.orig.AuctionFrame_OnShow(unpack(arg))
|
||||
end)
|
||||
|
||||
Aux.orig.GetOwnerAuctionItems = GetOwnerAuctionItems
|
||||
GetOwnerAuctionItems = Aux.GetOwnerAuctionItems
|
||||
|
||||
Aux.orig.PickupContainerItem = PickupContainerItem
|
||||
PickupContainerItem = Aux.PickupContainerItem
|
||||
|
||||
Aux.orig.SetItemRef = SetItemRef
|
||||
SetItemRef = Aux.SetItemRef
|
||||
|
||||
Aux.orig.UseContainerItem = UseContainerItem
|
||||
UseContainerItem = Aux.UseContainerItem
|
||||
|
||||
Aux.orig.AuctionFrameAuctions_OnEvent = AuctionFrameAuctions_OnEvent
|
||||
AuctionFrameAuctions_OnEvent = Aux.AuctionFrameAuctions_OnEvent
|
||||
Aux.hook('GetOwnerAuctionItems', Aux.GetOwnerAuctionItems)
|
||||
Aux.hook('PickupContainerItem', Aux.PickupContainerItem)
|
||||
Aux.hook('SetItemRef', Aux.SetItemRef)
|
||||
Aux.hook('UseContainerItem', Aux.UseContainerItem)
|
||||
Aux.hook('AuctionFrameAuctions_OnEvent', Aux.AuctionFrameAuctions_OnEvent)
|
||||
|
||||
end
|
||||
|
||||
function Aux.GetOwnerAuctionItems(page)
|
||||
function Aux.GetOwnerAuctionItems(...)
|
||||
local page = arg1
|
||||
Aux.last_owner_page_requested = page
|
||||
return Aux.orig.GetOwnerAuctionItems(page)
|
||||
return Aux.orig.GetOwnerAuctionItems(unpack(arg))
|
||||
end
|
||||
|
||||
function Aux.AuctionFrameAuctions_OnEvent()
|
||||
function Aux.AuctionFrameAuctions_OnEvent(...)
|
||||
if AuctionFrameAuctions:IsVisible() then
|
||||
Aux.orig.AuctionFrameAuctions_OnEvent()
|
||||
return Aux.orig.AuctionFrameAuctions_OnEvent(unpack(arg))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -225,9 +216,10 @@ end
|
||||
|
||||
do -- TODO make it work for other ways to pick up things
|
||||
local last_picked_up
|
||||
function Aux.PickupContainerItem(bag, slot)
|
||||
function Aux.PickupContainerItem(...)
|
||||
local bag, slot = unpack(arg)
|
||||
last_picked_up = { bag, slot }
|
||||
return Aux.orig.PickupContainerItem(bag, slot)
|
||||
return Aux.orig.PickupContainerItem(unpack(arg))
|
||||
end
|
||||
function Aux.cursor_item()
|
||||
if last_picked_up and CursorHasItem() then
|
||||
@@ -236,7 +228,8 @@ do -- TODO make it work for other ways to pick up things
|
||||
end
|
||||
end
|
||||
|
||||
function Aux.SetItemRef(itemstring, text, button)
|
||||
function Aux.SetItemRef(...)
|
||||
local itemstring, text, button = unpack(arg)
|
||||
if IsAltKeyDown() and AuxSearchFrame:IsVisible() then
|
||||
local item_info = Aux.static.item_info(tonumber(({strfind(itemstring, '^item:(%d+)')})[3]))
|
||||
if item_info then
|
||||
@@ -245,12 +238,13 @@ function Aux.SetItemRef(itemstring, text, button)
|
||||
return
|
||||
end
|
||||
end
|
||||
return Aux.orig.SetItemRef(itemstring, text, button)
|
||||
return Aux.orig.SetItemRef(unpack(arg))
|
||||
end
|
||||
|
||||
function Aux.UseContainerItem(bag, slot)
|
||||
function Aux.UseContainerItem(...)
|
||||
local bag, slot = unpack(arg)
|
||||
if IsShiftKeyDown() or IsControlKeyDown() or IsAltKeyDown() then
|
||||
return Aux.orig.UseContainerItem(bag, slot)
|
||||
return Aux.orig.UseContainerItem(unpack(arg))
|
||||
end
|
||||
|
||||
if AuxSearchFrame:IsVisible() then
|
||||
@@ -270,7 +264,7 @@ function Aux.UseContainerItem(bag, slot)
|
||||
return
|
||||
end
|
||||
|
||||
return Aux.orig.UseContainerItem(bag, slot)
|
||||
return Aux.orig.UseContainerItem(unpack(arg))
|
||||
end
|
||||
|
||||
function Aux.quality_color(code)
|
||||
@@ -340,4 +334,23 @@ function Aux.is_player(name)
|
||||
return UnitName('player') == name -- TODO support multiple chars
|
||||
end
|
||||
|
||||
Aux.orig = {}
|
||||
function Aux.hook(name, handler, object)
|
||||
local orig
|
||||
if object then
|
||||
Aux.orig[object] = Aux.orig[object] or {}
|
||||
orig = Aux.orig[object]
|
||||
else
|
||||
object = object or getfenv(0)
|
||||
orig = Aux.orig
|
||||
end
|
||||
|
||||
if orig[name] then
|
||||
error('Already got a hook for '..name)
|
||||
end
|
||||
|
||||
orig[name] = object[name]
|
||||
object[name] = handler
|
||||
end
|
||||
|
||||
Aux.huge = 2^100000
|
||||
+1
-1
@@ -984,7 +984,7 @@ function private.record_auction(key, aux_quantity, unit_blizzard_bid, unit_buyou
|
||||
end
|
||||
|
||||
entry.count = entry.count + 1
|
||||
entry.yours = entry.yours + (owner == UnitName('player') and 1 or 0)
|
||||
entry.yours = entry.yours + (Aux.is_player(owner) and 1 or 0)
|
||||
|
||||
return entry
|
||||
end
|
||||
|
||||
+25
-22
@@ -5,17 +5,20 @@ local game_tooltip_hooks = {}
|
||||
|
||||
function public.on_load()
|
||||
for func, hook in game_tooltip_hooks do
|
||||
local old = GameTooltip[func]
|
||||
local hook = hook
|
||||
GameTooltip[func] = function(self, ...)
|
||||
local result = old(unpack(Aux.util.cons(self, arg)))
|
||||
hook(unpack(arg))
|
||||
return result
|
||||
end
|
||||
local func, hook = func, hook
|
||||
Aux.hook(
|
||||
func,
|
||||
function(...)
|
||||
local results = {Aux.orig[GameTooltip][func](unpack(arg))}
|
||||
hook(unpack(arg))
|
||||
return unpack(results)
|
||||
end,
|
||||
GameTooltip
|
||||
)
|
||||
end
|
||||
local old = SetItemRef
|
||||
local orig = SetItemRef
|
||||
SetItemRef = function(...)
|
||||
local result = old(unpack(arg))
|
||||
local result = orig(unpack(arg))
|
||||
local name, _, quality = GetItemInfo(arg[1])
|
||||
if not IsShiftKeyDown() and not IsControlKeyDown() and name then
|
||||
local _, _, _, hex = GetItemQualityColor(quality)
|
||||
@@ -91,7 +94,7 @@ function private.extend_tooltip(tooltip, hyperlink, quantity)
|
||||
tooltip:Show()
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetHyperlink(itemstring)
|
||||
function game_tooltip_hooks:SetHyperlink(itemstring)
|
||||
local name, _, quality = GetItemInfo(itemstring)
|
||||
if name then
|
||||
local _, _, _, hex = GetItemQualityColor(quality)
|
||||
@@ -100,7 +103,7 @@ function game_tooltip_hooks.SetHyperlink(itemstring)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetAuctionItem(type, index)
|
||||
function game_tooltip_hooks:SetAuctionItem(type, index)
|
||||
local link = GetAuctionItemLink(type, index)
|
||||
if link then
|
||||
local _, _, quantity = GetAuctionItemInfo(type, index)
|
||||
@@ -108,7 +111,7 @@ function game_tooltip_hooks.SetAuctionItem(type, index)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetLootItem(slot)
|
||||
function game_tooltip_hooks:SetLootItem(slot)
|
||||
local link = GetLootSlotLink(slot)
|
||||
if link then
|
||||
local _, _, quantity = GetLootSlotInfo(slot)
|
||||
@@ -116,7 +119,7 @@ function game_tooltip_hooks.SetLootItem(slot)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetQuestItem(qtype, slot)
|
||||
function game_tooltip_hooks:SetQuestItem(qtype, slot)
|
||||
local link = GetQuestItemLink(qtype, slot)
|
||||
if link then
|
||||
local _, _, quantity = GetQuestItemInfo(qtype, slot)
|
||||
@@ -124,7 +127,7 @@ function game_tooltip_hooks.SetQuestItem(qtype, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetQuestLogItem(qtype, slot)
|
||||
function game_tooltip_hooks:SetQuestLogItem(qtype, slot)
|
||||
local link = GetQuestLogItemLink(qtype, slot)
|
||||
if link then
|
||||
local _, _, quantity = GetQuestLogRewardInfo(slot)
|
||||
@@ -132,7 +135,7 @@ function game_tooltip_hooks.SetQuestLogItem(qtype, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetBagItem(bag, slot)
|
||||
function game_tooltip_hooks:SetBagItem(bag, slot)
|
||||
local link = GetContainerItemLink(bag, slot)
|
||||
if link then
|
||||
local _, quantity = GetContainerItemInfo(bag, slot)
|
||||
@@ -140,7 +143,7 @@ function game_tooltip_hooks.SetBagItem(bag, slot)
|
||||
end
|
||||
end
|
||||
|
||||
--function game_tooltip_hooks.SetInboxItem(index)
|
||||
--function game_tooltip_hooks:SetInboxItem(index)
|
||||
-- local name, _, quantity = GetInboxItem(index)
|
||||
--
|
||||
-- for itemID = 1, 30000 do
|
||||
@@ -154,14 +157,14 @@ end
|
||||
-- end
|
||||
--end
|
||||
|
||||
function game_tooltip_hooks.SetInventoryItem(unit, slot)
|
||||
function game_tooltip_hooks:SetInventoryItem(unit, slot)
|
||||
local link = GetInventoryItemLink(unit, slot)
|
||||
if link then
|
||||
private.extend_tooltip(GameTooltip, link, 1)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetMerchantItem(slot)
|
||||
function game_tooltip_hooks:SetMerchantItem(slot)
|
||||
local link = GetMerchantItemLink(slot)
|
||||
if link then
|
||||
local _, _, _, quantity = GetMerchantItemInfo(slot)
|
||||
@@ -169,7 +172,7 @@ function game_tooltip_hooks.SetMerchantItem(slot)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetCraftItem(skill, slot)
|
||||
function game_tooltip_hooks:SetCraftItem(skill, slot)
|
||||
local link, quantity
|
||||
if slot then
|
||||
link = GetCraftReagentItemLink(skill, slot)
|
||||
@@ -183,14 +186,14 @@ function game_tooltip_hooks.SetCraftItem(skill, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetCraftSpell(slot)
|
||||
function game_tooltip_hooks:SetCraftSpell(slot)
|
||||
local link = GetCraftItemLink(slot)
|
||||
if link then
|
||||
private.extend_tooltip(GameTooltip, link, 1)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetTradeSkillItem(skill, slot)
|
||||
function game_tooltip_hooks:SetTradeSkillItem(skill, slot)
|
||||
local link, quantity
|
||||
if slot then
|
||||
link = GetTradeSkillReagentItemLink(skill, slot)
|
||||
@@ -204,7 +207,7 @@ function game_tooltip_hooks.SetTradeSkillItem(skill, slot)
|
||||
end
|
||||
end
|
||||
|
||||
function game_tooltip_hooks.SetAuctionSellItem()
|
||||
function game_tooltip_hooks:SetAuctionSellItem()
|
||||
local name, _, quantity, _, _, _ = GetAuctionSellItemInfo()
|
||||
if name then
|
||||
for bag = 0, 4 do
|
||||
|
||||
Reference in New Issue
Block a user