186 lines
8.3 KiB
Lua
186 lines
8.3 KiB
Lua
-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
|
|
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
|
|
-- Native junk selling for the Classic merchant window (owner 2026-11-28).
|
|
-- The 70334 Vanilla MerchantFrame has no "Sell All Junk" button; retail's button calls
|
|
-- C_MerchantFrame.SellAllJunkItems, whose batch request the Turtle server does not know. This
|
|
-- adds the retail-looking button and sells item by item through the ordinary sell request
|
|
-- (C_Container.UseContainerItem at an open merchant), which the gateway already translates.
|
|
-- Junk = poor-quality items with a sell price, plus items the player marked (an item in
|
|
-- the bags with Ctrl+Shift+click, or /junk <item link>). Marks are per account (WoWHybridJunk.items).
|
|
-- No Blizzard globals are written; only hooks and our own frames.
|
|
|
|
WoWHybridJunk = WoWHybridJunk or {};
|
|
local db;
|
|
local SELL_INTERVAL = 0.05; -- seconds between sell requests (~20 items/s, like the 1.12 junk sellers)
|
|
local queue, selling = {}, false;
|
|
|
|
local function Defaults()
|
|
db = WoWHybridJunk;
|
|
if type(db.items) ~= "table" then db.items = {}; end
|
|
if db.autoSell == nil then db.autoSell = false; end
|
|
if db.includeMarked == nil then db.includeMarked = true; end
|
|
if db.includePoor == nil then db.includePoor = true; end
|
|
end
|
|
|
|
local function ItemIDFromLink(link)
|
|
if type(link) ~= "string" then return nil; end
|
|
local id = link:match("item:(%d+)");
|
|
return id and tonumber(id) or nil;
|
|
end
|
|
|
|
local function IsJunk(info)
|
|
if not info or not info.itemID or info.isLocked then return false; end
|
|
if info.hasNoValue then return false; end
|
|
if db.includeMarked and db.items[info.itemID] then return true; end
|
|
return db.includePoor and info.quality == 0;
|
|
end
|
|
|
|
-- Public helpers for other addons (e.g. a Bagshui rule): WoWHybridJunk.IsMarked(itemID).
|
|
function WoWHybridJunk.IsMarked(itemID) return db ~= nil and db.items[itemID] == true; end
|
|
|
|
local function JunkSlots()
|
|
local slots = {};
|
|
for bag = 0, NUM_BAG_SLOTS or 4 do
|
|
for slot = 1, C_Container.GetContainerNumSlots(bag) do
|
|
local info = C_Container.GetContainerItemInfo(bag, slot);
|
|
if IsJunk(info) then slots[#slots + 1] = { bag, slot, info.itemID }; end
|
|
end
|
|
end
|
|
return slots;
|
|
end
|
|
|
|
local button;
|
|
local function Refresh()
|
|
if not button then return; end
|
|
local has = #JunkSlots() > 0 and not selling;
|
|
button.Icon:SetDesaturated(not has);
|
|
button:SetEnabled(has);
|
|
end
|
|
|
|
local function SellNext()
|
|
if not MerchantFrame or not MerchantFrame:IsShown() then queue, selling = {}, false; Refresh(); return; end
|
|
local entry = table.remove(queue, 1);
|
|
if not entry then selling = false; Refresh(); return; end
|
|
local info = C_Container.GetContainerItemInfo(entry[1], entry[2]);
|
|
if info and info.itemID == entry[3] and IsJunk(info) then
|
|
C_Container.UseContainerItem(entry[1], entry[2]);
|
|
end
|
|
C_Timer.After(SELL_INTERVAL, function() SellNext(); end);
|
|
end
|
|
|
|
local function SellAll()
|
|
if selling then return; end
|
|
queue = JunkSlots();
|
|
if #queue == 0 then return; end
|
|
selling = true; Refresh();
|
|
SellNext();
|
|
end
|
|
|
|
local function CreateButton()
|
|
if button or not MerchantFrame then return; end
|
|
button = CreateFrame("Button", "WoWHybridSellJunkButton", MerchantFrame);
|
|
button:SetSize(36, 36);
|
|
local bg = button:CreateTexture(nil, "BACKGROUND");
|
|
bg:SetTexture("Interface\\Buttons\\UI-EmptySlot"); bg:SetSize(64, 64); bg:SetPoint("TOPLEFT", -13, 14);
|
|
button.Icon = button:CreateTexture(nil, "BORDER");
|
|
button.Icon:SetAtlas("SpellIcon-256x256-SellJunk"); button.Icon:SetAllPoints();
|
|
button:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress");
|
|
button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", "ADD");
|
|
button:SetScript("OnEnter", function(self)
|
|
GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
|
|
GameTooltip:SetText(SELL_ALL_JUNK_ITEMS or "Sell All Junk Items");
|
|
GameTooltip:AddLine("Ctrl+Shift+click an item in your bags to mark or unmark it as junk.", 1, 1, 1, true);
|
|
GameTooltip:Show();
|
|
end);
|
|
button:SetScript("OnLeave", GameTooltip_Hide);
|
|
button:SetScript("OnClick", function() SellAll(); end); -- no confirmation (owner 2026-11-28)
|
|
end
|
|
|
|
local function PlaceButton()
|
|
if not button then return; end
|
|
button:ClearAllPoints();
|
|
if MerchantRepairAllButton and MerchantRepairAllButton:IsShown() then
|
|
local left = MerchantRepairItemButton and MerchantRepairItemButton:IsShown() and MerchantRepairItemButton or MerchantRepairAllButton;
|
|
button:SetPoint("RIGHT", left, "LEFT", -4, 0);
|
|
else
|
|
button:SetPoint("BOTTOMLEFT", MerchantFrame, "BOTTOMLEFT", 22, 34);
|
|
end
|
|
-- Only on the merchant tab, never on the buyback tab.
|
|
button:SetShown(not MerchantFrame.selectedTab or MerchantFrame.selectedTab == 1);
|
|
end
|
|
|
|
local function Toggle(itemID, link)
|
|
if not itemID then return; end
|
|
if db.items[itemID] then db.items[itemID] = nil; else db.items[itemID] = true; end
|
|
local name = link or (C_Item.GetItemNameByID and C_Item.GetItemNameByID(itemID)) or ("item " .. itemID);
|
|
print(string.format("|cffffd200Junk:|r %s %s", name, db.items[itemID] and "marked as junk" or "no longer junk"));
|
|
Refresh();
|
|
end
|
|
|
|
-- Ctrl+Shift+left-click on a bag item (owner 2026-11-28; no default 70334 ModifiedClick uses CTRL-SHIFT).
|
|
-- Works with Blizzard bags and bag addons that route modified clicks through HandleModifiedItemClick.
|
|
hooksecurefunc("HandleModifiedItemClick", function(link)
|
|
local button = GetMouseButtonClicked and GetMouseButtonClicked();
|
|
if IsControlKeyDown() and IsShiftKeyDown() and not IsAltKeyDown() and (not button or button == "LeftButton") then
|
|
Toggle(ItemIDFromLink(link), link);
|
|
end
|
|
end);
|
|
|
|
-- Tooltip marker.
|
|
if TooltipDataProcessor and Enum.TooltipDataType then
|
|
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, function(tooltip, data)
|
|
if db and data and data.id and db.items[data.id] then
|
|
tooltip:AddLine("Marked as junk (sold by Sell Junk)", 0.62, 0.62, 0.62);
|
|
end
|
|
end);
|
|
end
|
|
|
|
SLASH_WOWHYBRIDJUNK1 = "/junk";
|
|
SlashCmdList.WOWHYBRIDJUNK = function(msg)
|
|
local id = ItemIDFromLink(msg) or tonumber(msg);
|
|
if id then Toggle(id, msg:find("|H") and msg or nil); return; end
|
|
local n = 0; for _ in pairs(db.items) do n = n + 1; end
|
|
print(string.format("|cffffd200Junk:|r %d marked item(s). Ctrl+Shift+click a bag item or /junk <item link> to toggle.", n));
|
|
end
|
|
|
|
local function RegisterOptions()
|
|
if not Settings or not Settings.RegisterVerticalLayoutCategory then return; end
|
|
local ok = pcall(function()
|
|
local category = Settings.RegisterVerticalLayoutCategory("WoW-Hybrid: Junk Selling");
|
|
local function Check(key, name, tip)
|
|
local setting = Settings.RegisterAddOnSetting(category, "WOWHYBRID_JUNK_" .. key, key, db, type(true), name, db[key]);
|
|
Settings.CreateCheckbox(category, setting, tip);
|
|
end
|
|
Check("autoSell", "Sell junk automatically at merchants", "Sells junk as soon as a merchant window opens.");
|
|
Check("includePoor", "Sell poor (grey) items", "Poor-quality items with a sell price count as junk.");
|
|
Check("includeMarked", "Sell items marked as junk", "Items you marked with Ctrl+Shift+click or /junk count as junk.");
|
|
Settings.RegisterAddOnCategory(category);
|
|
end);
|
|
if not ok then print("|cffffd200Junk:|r options panel unavailable; use /junk."); end
|
|
end
|
|
|
|
local events = CreateFrame("Frame");
|
|
events:RegisterEvent("ADDON_LOADED");
|
|
events:RegisterEvent("MERCHANT_SHOW");
|
|
events:RegisterEvent("MERCHANT_CLOSED");
|
|
events:RegisterEvent("BAG_UPDATE_DELAYED");
|
|
events:SetScript("OnEvent", function(_, event, arg)
|
|
if event == "ADDON_LOADED" then
|
|
if arg ~= "WoWHybridUI" then return; end
|
|
Defaults(); RegisterOptions(); CreateButton();
|
|
if MerchantFrame then
|
|
MerchantFrame:HookScript("OnShow", PlaceButton);
|
|
if MerchantFrame_Update then hooksecurefunc("MerchantFrame_Update", function() PlaceButton(); Refresh(); end); end
|
|
end
|
|
elseif not db then
|
|
return;
|
|
elseif event == "MERCHANT_SHOW" then
|
|
PlaceButton(); Refresh();
|
|
if db.autoSell then C_Timer.After(0.3, function() SellAll(); end); end
|
|
elseif event == "MERCHANT_CLOSED" then
|
|
queue, selling = {}, false;
|
|
else
|
|
Refresh();
|
|
end
|
|
end);
|