mirror of
https://github.com/brues-code/pfUI.git
synced 2026-10-31 16:06:57 +00:00
Each if/else that only showed one object in one branch and hid it in the other is now ClassicAPI's SetShown, which shows on any truthy value. 21 sites across 10 modules.
94 lines
3.2 KiB
Lua
94 lines
3.2 KiB
Lua
pfUI:RegisterModule("autovendor", 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()
|
|
|
|
C_Timer.After(0.3, function()
|
|
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:SetSize(36, 36)
|
|
autovendor.button.icon = autovendor.button:CreateTexture(nil, "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()
|
|
autovendor.button:SetShown(MerchantFrame.selectedTab == 1 and C["global"]["autosell"] ~= "1")
|
|
pfMerchantFrame_Update()
|
|
end
|
|
end
|
|
end)
|