mirror of
https://github.com/brues-code/pfUI.git
synced 2026-09-24 00:26:55 +00:00
2619b0bd77
Two-part collapse: Button-click sell path: was a 0.1s-per-item manual iteration via UseContainerItem (with processed[] tracking + a merchant-state flag + OnShow/OnUpdate/OnHide handler trio). Now calls SellJunkAndReport which fires C_MerchantFrame.SellAllJunkItems and a 0.3s deferred GetMoney delta reporter. Engine handles per-frame sell pacing. Button enable/disable check: HasGreyItems() iterated bags 0..4 with C_Item.GetItemQuality manually. Replaced with C_MerchantFrame.GetNumJunkItems() > 0 (the engine's canonical answer to the same question). The button's Update only runs from MERCHANT_SHOW / MERCHANT_UPDATE handlers so the "merchant must be open" gate on GetNumJunkItems is always satisfied. Side effect: the MERCHANT_SHOW auto-sell path NOW reports income to chat. Previously only the manual button reported it. Deleted: HasGreyItems, processed/count/gold state, GetNextGreyItem, autovendor.merchant flag, OnShow/OnUpdate/OnHide handlers, the MERCHANT_CLOSED branch. 170 → 104 lines.
104 lines
3.5 KiB
Lua
104 lines
3.5 KiB
Lua
pfUI:RegisterModule("autovendor", "vanilla:tbc", function ()
|
|
local rawborder, border = GetBorderSize()
|
|
local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel()
|
|
|
|
local function RepairItems()
|
|
local cost, possible = GetRepairAllCost()
|
|
if cost > 0 and possible then
|
|
DEFAULT_CHAT_FRAME:AddMessage(T["Your items have been repaired for"] .. " " .. CreateGoldString(cost))
|
|
RepairAllItems()
|
|
end
|
|
end
|
|
|
|
-- Trigger the engine's sell-all-junk path and report the gold income to
|
|
-- chat. C_MerchantFrame.SellAllJunkItems handles its own one-per-frame
|
|
-- pacing to avoid CMSG_SELL_ITEM flooding, so we just wait a beat before
|
|
-- sampling the final gold delta.
|
|
local function SellJunkAndReport()
|
|
if C_MerchantFrame.GetNumJunkItems() <= 0 then return end
|
|
local startGold = GetMoney()
|
|
C_MerchantFrame.SellAllJunkItems()
|
|
|
|
local reporter = CreateFrame("Frame")
|
|
reporter.deadline = GetTime() + 0.3
|
|
reporter:SetScript("OnUpdate", function()
|
|
if GetTime() < this.deadline then return end
|
|
this:SetScript("OnUpdate", nil)
|
|
this:Hide()
|
|
local income = GetMoney() - startGold
|
|
if income > 0 then
|
|
DEFAULT_CHAT_FRAME:AddMessage(T["Your vendor trash has been sold and you earned"] .. " " .. CreateGoldString(income))
|
|
end
|
|
end)
|
|
end
|
|
|
|
local autovendor = CreateFrame("Frame", "pfMoneyUpdate", nil)
|
|
autovendor:RegisterEvent("MERCHANT_SHOW")
|
|
autovendor:RegisterEvent("MERCHANT_UPDATE")
|
|
autovendor:SetScript("OnEvent", function()
|
|
autovendor.button:Update()
|
|
|
|
if event == "MERCHANT_SHOW" then
|
|
if C["global"]["autorepair"] == "1" then RepairItems() end
|
|
|
|
if C["global"]["autosell"] == "1" then
|
|
SellJunkAndReport()
|
|
autovendor.button:Hide()
|
|
else
|
|
autovendor.button:Show()
|
|
end
|
|
|
|
MerchantRepairText:SetText("")
|
|
if MerchantRepairItemButton:IsShown() then
|
|
autovendor.button:ClearAllPoints()
|
|
autovendor.button:SetPoint("RIGHT", MerchantRepairItemButton, "LEFT", -4*bpad, 0)
|
|
else
|
|
autovendor.button:ClearAllPoints()
|
|
autovendor.button:SetPoint("RIGHT", MerchantBuyBackItemItemButton, "LEFT", -14, 0)
|
|
end
|
|
end
|
|
end)
|
|
|
|
-- Setup Autosell button
|
|
autovendor.button = CreateFrame("Button", "pfMerchantAutoVendorButton", MerchantFrame)
|
|
autovendor.button:SetWidth(36)
|
|
autovendor.button:SetHeight(36)
|
|
autovendor.button.icon = autovendor.button:CreateTexture("ARTWORK")
|
|
autovendor.button.icon:SetTexture("Interface\\Icons\\Spell_Shadow_SacrificialShield")
|
|
autovendor.button:SetScript("OnEnter", function()
|
|
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
|
|
GameTooltip:SetText(T["Sell Grey Items"])
|
|
GameTooltip:Show()
|
|
end)
|
|
|
|
autovendor.button:SetScript("OnLeave", function()
|
|
GameTooltip:Hide()
|
|
end)
|
|
SkinButton(autovendor.button, nil, nil, nil, autovendor.button.icon)
|
|
|
|
autovendor.button:SetScript("OnClick", SellJunkAndReport)
|
|
|
|
autovendor.button.Update = function()
|
|
if C_MerchantFrame.GetNumJunkItems() > 0 then
|
|
autovendor.button:Enable()
|
|
autovendor.button.icon:SetDesaturated(false)
|
|
else
|
|
autovendor.button:Disable()
|
|
autovendor.button.icon:SetDesaturated(true)
|
|
end
|
|
end
|
|
|
|
-- Hook MerchantFrame_Update
|
|
if not pfMerchantFrame_Update then
|
|
local pfMerchantFrame_Update = MerchantFrame_Update
|
|
function _G.MerchantFrame_Update()
|
|
if MerchantFrame.selectedTab == 1 and C["global"]["autosell"] ~= "1" then
|
|
autovendor.button:Show()
|
|
else
|
|
autovendor.button:Hide()
|
|
end
|
|
pfMerchantFrame_Update()
|
|
end
|
|
end
|
|
end)
|