From 69a77b83e94dc180db5d91e3d3e57aecb90a58ba Mon Sep 17 00:00:00 2001 From: shagu Date: Tue, 20 May 2025 11:20:01 +0200 Subject: [PATCH] bag-item-click: allow to send items to trade in one click --- README.md | 3 ++ ShaguTweaks-extras.toc | 1 + mods/bag-item-click.lua | 73 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 mods/bag-item-click.lua diff --git a/README.md b/README.md index e465d7b..ee50776 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,9 @@ For a detailed view of what's new and improved, check out the feature list below ### General +- **Bag Item Click** + *Send items to trade window or auction house search via right click.* + - **Bag Search Bar** *Adds a search field to the bag which allows you to search bag, keyring and bank slots.* diff --git a/ShaguTweaks-extras.toc b/ShaguTweaks-extras.toc index deb9c9f..d957186 100644 --- a/ShaguTweaks-extras.toc +++ b/ShaguTweaks-extras.toc @@ -27,6 +27,7 @@ mods\actionbar-right-center.lua mods\actionbar-reagents.lua mods\actionbar-float.lua mods\unitframe-energytick.lua +mods\bag-item-click.lua mods\bag-search.lua mods\worldmap-reveal.lua diff --git a/mods/bag-item-click.lua b/mods/bag-item-click.lua new file mode 100644 index 0000000..ed3bf90 --- /dev/null +++ b/mods/bag-item-click.lua @@ -0,0 +1,73 @@ +local _G = ShaguTweaks.GetGlobalEnv() +local T = ShaguTweaks.T + +local module = ShaguTweaks:register({ + title = T["Bag Item Click"], + description = T["Send items to trade window or auction house search via right click."], + expansions = { ["vanilla"] = true, ["tbc"] = nil }, + maintainer = "@shagu (GitHub)", + enabled = true, +}) + +module.enable = function(self) + -- helper functions + local IsTrading = function() + return TradeFrame:IsShown() + end + + local IsAuctionBrowsing = function() + return AuctionFrame and AuctionFrame:IsShown() and AuctionFrameBrowse and AuctionFrameBrowse:IsShown() + end + + local IsAuctionSelling = function() + return AuctionFrame and AuctionFrame:IsShown() and AuctionFrameAuctions and AuctionFrameAuctions:IsShown() + end + + -- overwrite use/trade logic unless shift is pressed + local pfHookUseContainerItem = _G.UseContainerItem + function _G.UseContainerItem(bag, slot) + if IsTrading() and not IsShiftKeyDown() then + -- move item to trade window + PickupContainerItem(bag, slot) + local slot = TradeFrame_GetAvailableSlot() + if slot then ClickTradeButton(slot) end + if CursorHasItem() then + ClearCursor() + end + elseif IsAuctionBrowsing() and not IsShiftKeyDown() then + -- search item in auction house + local link = GetContainerItemLink(bag, slot) + local name = link and string.sub(link, string.find(link, "%[")+1, string.find(link, "%]")-1) or "" + BrowseName:SetText(name) + AuctionFrameBrowse_Search() + elseif IsAuctionSelling() and not IsShiftKeyDown() then + -- sell item to auction house + PickupContainerItem(bag, slot) + AuctionsItemButton:Click() + if CursorHasItem() then + ClearCursor() + end + else + -- default action + pfHookUseContainerItem(bag, slot) + end + end + + -- detect bag button tooltips + local showHelperNextTooltip = false + local pfHookSetBagItem = GameTooltip.SetBagItem + function GameTooltip.SetBagItem(self, container, slot) + showHelperNextTooltip = IsTrading() or IsAuctionBrowsing() or IsAuctionSelling() + return pfHookSetBagItem(self, container, slot) + end + + -- add helper text to tooltips + local tooltip = CreateFrame("Frame", "pfItemClickHelpMessage", GameTooltip) + tooltip:SetScript("OnShow", function() + if showHelperNextTooltip then + GameTooltip:AddLine(T["Hold [Shift] to use item."], 0.50, 0.75, 1.00) + GameTooltip:Show() + showHelperNextTooltip = false + end + end) +end