mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-21 20:00:48 +00:00
autovendor: all paths through C_MerchantFrame
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.
This commit is contained in:
+25
-92
@@ -1,7 +1,6 @@
|
|||||||
pfUI:RegisterModule("autovendor", "vanilla:tbc", function ()
|
pfUI:RegisterModule("autovendor", "vanilla:tbc", function ()
|
||||||
local rawborder, border = GetBorderSize()
|
local rawborder, border = GetBorderSize()
|
||||||
local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel()
|
local bpad = rawborder > 1 and border - GetPerfectPixel() or GetPerfectPixel()
|
||||||
local processed = {}
|
|
||||||
|
|
||||||
local function RepairItems()
|
local function RepairItems()
|
||||||
local cost, possible = GetRepairAllCost()
|
local cost, possible = GetRepairAllCost()
|
||||||
@@ -11,98 +10,39 @@ pfUI:RegisterModule("autovendor", "vanilla:tbc", function ()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function HasGreyItems()
|
-- Trigger the engine's sell-all-junk path and report the gold income to
|
||||||
for bag = 0, 4 do
|
-- chat. C_MerchantFrame.SellAllJunkItems handles its own one-per-frame
|
||||||
for slot = 1, GetContainerNumSlots(bag) do
|
-- pacing to avoid CMSG_SELL_ITEM flooding, so we just wait a beat before
|
||||||
local quality = C_Item.GetItemQuality(ItemLocation:CreateFromBagAndSlot(bag,slot))
|
-- sampling the final gold delta.
|
||||||
if quality and quality == LE_ITEM_QUALITY_POOR then return true end
|
local function SellJunkAndReport()
|
||||||
end
|
if C_MerchantFrame.GetNumJunkItems() <= 0 then return end
|
||||||
end
|
local startGold = GetMoney()
|
||||||
end
|
C_MerchantFrame.SellAllJunkItems()
|
||||||
|
|
||||||
local function GetNextGreyItem()
|
local reporter = CreateFrame("Frame")
|
||||||
for bag = 0, 4 do
|
reporter.deadline = GetTime() + 0.3
|
||||||
for slot = 1, GetContainerNumSlots(bag) do
|
reporter:SetScript("OnUpdate", function()
|
||||||
local quality = C_Item.GetItemQuality(ItemLocation:CreateFromBagAndSlot(bag,slot))
|
if GetTime() < this.deadline then return end
|
||||||
if quality and quality == LE_ITEM_QUALITY_POOR and not processed[bag.."x"..slot] then
|
this:SetScript("OnUpdate", nil)
|
||||||
processed[bag.."x"..slot] = true
|
this:Hide()
|
||||||
return bag, slot
|
local income = GetMoney() - startGold
|
||||||
end
|
if income > 0 then
|
||||||
|
DEFAULT_CHAT_FRAME:AddMessage(T["Your vendor trash has been sold and you earned"] .. " " .. CreateGoldString(income))
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
local autovendor = CreateFrame("Frame", "pfMoneyUpdate", nil)
|
local autovendor = CreateFrame("Frame", "pfMoneyUpdate", nil)
|
||||||
autovendor:Hide()
|
|
||||||
|
|
||||||
autovendor:SetScript("OnShow", function()
|
|
||||||
processed = {}
|
|
||||||
this.count = 0
|
|
||||||
this.gold = GetMoney()
|
|
||||||
end)
|
|
||||||
|
|
||||||
autovendor:SetScript("OnUpdate", function()
|
|
||||||
-- throttle to to one item per .1 second
|
|
||||||
if ( this.tick or 1) > GetTime() then return else this.tick = GetTime() + .1 end
|
|
||||||
|
|
||||||
-- scan for the next grey item
|
|
||||||
local bag, slot = GetNextGreyItem()
|
|
||||||
if not bag or not slot then
|
|
||||||
this:Hide()
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- double check to only sell grey
|
|
||||||
local quality = C_Item.GetItemQuality(ItemLocation:CreateFromBagAndSlot(bag,slot))
|
|
||||||
if quality ~= LE_ITEM_QUALITY_POOR then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- only proceed for items the engine reports as vendor-sellable
|
|
||||||
local id = C_Container.GetContainerItemID(bag, slot)
|
|
||||||
if (id and C_Item.GetItemSellPriceByID(id) or 0) > 0 then
|
|
||||||
this.count = this.count + 1
|
|
||||||
end
|
|
||||||
|
|
||||||
-- abort if the merchant window disappeared
|
|
||||||
if not this.merchant then return end
|
|
||||||
|
|
||||||
-- clear cursor and sell the item
|
|
||||||
ClearCursor()
|
|
||||||
UseContainerItem(bag, slot)
|
|
||||||
end)
|
|
||||||
|
|
||||||
autovendor:SetScript("OnHide", function()
|
|
||||||
if this.count > 0 then
|
|
||||||
local gold = this.gold
|
|
||||||
QueueFunction(function()
|
|
||||||
local income = GetMoney() - gold
|
|
||||||
DEFAULT_CHAT_FRAME:AddMessage(T["Your vendor trash has been sold and you earned"] .. " " .. CreateGoldString(income))
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
autovendor:RegisterEvent("MERCHANT_SHOW")
|
autovendor:RegisterEvent("MERCHANT_SHOW")
|
||||||
autovendor:RegisterEvent("MERCHANT_CLOSED")
|
|
||||||
autovendor:RegisterEvent("MERCHANT_UPDATE")
|
autovendor:RegisterEvent("MERCHANT_UPDATE")
|
||||||
autovendor:SetScript("OnEvent", function()
|
autovendor:SetScript("OnEvent", function()
|
||||||
autovendor.button:Update()
|
autovendor.button:Update()
|
||||||
|
|
||||||
if event == "MERCHANT_CLOSED" then
|
if event == "MERCHANT_SHOW" then
|
||||||
autovendor.merchant = nil
|
if C["global"]["autorepair"] == "1" then RepairItems() end
|
||||||
autovendor:Hide()
|
|
||||||
elseif event == "MERCHANT_SHOW" then
|
|
||||||
autovendor.merchant = true
|
|
||||||
if C["global"]["autorepair"] == "1" then
|
|
||||||
RepairItems()
|
|
||||||
end
|
|
||||||
|
|
||||||
if C["global"]["autosell"] == "1" then
|
if C["global"]["autosell"] == "1" then
|
||||||
if C_MerchantFrame.GetNumJunkItems() > 0 then
|
SellJunkAndReport()
|
||||||
C_MerchantFrame.SellAllJunkItems()
|
|
||||||
else
|
|
||||||
autovendor:Show()
|
|
||||||
end
|
|
||||||
autovendor.button:Hide()
|
autovendor.button:Hide()
|
||||||
else
|
else
|
||||||
autovendor.button:Show()
|
autovendor.button:Show()
|
||||||
@@ -136,19 +76,12 @@ pfUI:RegisterModule("autovendor", "vanilla:tbc", function ()
|
|||||||
end)
|
end)
|
||||||
SkinButton(autovendor.button, nil, nil, nil, autovendor.button.icon)
|
SkinButton(autovendor.button, nil, nil, nil, autovendor.button.icon)
|
||||||
|
|
||||||
autovendor.button:SetScript("OnClick", function()
|
autovendor.button:SetScript("OnClick", SellJunkAndReport)
|
||||||
autovendor:Show()
|
|
||||||
end)
|
|
||||||
|
|
||||||
autovendor.button.Update = function()
|
autovendor.button.Update = function()
|
||||||
if not autovendor:IsVisible() then
|
if C_MerchantFrame.GetNumJunkItems() > 0 then
|
||||||
if HasGreyItems() then
|
autovendor.button:Enable()
|
||||||
autovendor.button:Enable()
|
autovendor.button.icon:SetDesaturated(false)
|
||||||
autovendor.button.icon:SetDesaturated(false)
|
|
||||||
else
|
|
||||||
autovendor.button:Disable()
|
|
||||||
autovendor.button.icon:SetDesaturated(true)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
autovendor.button:Disable()
|
autovendor.button:Disable()
|
||||||
autovendor.button.icon:SetDesaturated(true)
|
autovendor.button.icon:SetDesaturated(true)
|
||||||
|
|||||||
Reference in New Issue
Block a user