fix: auto sell junk items

This commit is contained in:
Vati
2026-02-28 04:13:23 +04:00
parent 4fdd2ea052
commit 88ce45b045
6 changed files with 190 additions and 3 deletions
+9
View File
@@ -1346,6 +1346,15 @@ function CategoryManager:SyncEquipmentSetCategories()
insertPos = table.getn(cats.order) + 1
end
end
if not insertPos then
-- Insert before Junk category if it exists, otherwise at end of Main group
for i, orderId in ipairs(cats.order) do
if orderId == "Junk" then
insertPos = i
break
end
end
end
if not insertPos then
for i = table.getn(cats.order), 1, -1 do
local existDef = cats.definitions[cats.order[i]]
+6
View File
@@ -130,6 +130,12 @@ function DB:Initialize()
if Guda_CharDB.settings.markEquipmentSets == nil then
Guda_CharDB.settings.markEquipmentSets = true
end
if Guda_CharDB.settings.autoVendorJunk == nil then
Guda_CharDB.settings.autoVendorJunk = true
end
if Guda_CharDB.settings.whiteItemsJunk == nil then
Guda_CharDB.settings.whiteItemsJunk = false
end
-- Initialize CategoryManager for custom categories
if addon.Modules.CategoryManager then
+6 -2
View File
@@ -241,8 +241,12 @@ local function DetectJunk(lines, itemData)
end
end
-- White equippable items might be junk
if quality == 1 and (itemClass == "Weapon" or itemClass == "Armor") then
-- White equippable items might be junk (only if whiteItemsJunk setting is enabled)
local whiteItemsJunk = false
if addon and addon.Modules and addon.Modules.DB then
whiteItemsJunk = addon.Modules.DB:GetSetting("whiteItemsJunk")
end
if quality == 1 and whiteItemsJunk and (itemClass == "Weapon" or itemClass == "Armor") then
-- Exclusions: trinkets, rings, necklaces, tabards, shirts
local subLower = string.lower(itemSubclass)
if string.find(subLower, "trinket") or
+44
View File
@@ -3269,6 +3269,50 @@ function BagFrame:Initialize()
if frameRef and not frameRef:IsShown() then
frameRef:Show()
end
-- Auto-sell junk items (spread across frames to avoid item locking)
local autoVendor = addon.Modules.DB:GetSetting("autoVendorJunk")
if autoVendor == nil then autoVendor = true end
if autoVendor then
local junkItems = {}
for bag = 0, 4 do
local numSlots = GetContainerNumSlots(bag)
for slot = 1, numSlots do
local link = GetContainerItemLink(bag, slot)
if link and string.find(link, "|cff9d9d9d") then
table.insert(junkItems, { bag = bag, slot = slot })
end
end
end
if table.getn(junkItems) > 0 then
local idx = 0
local soldCount = 0
local sellFrame = CreateFrame("Frame")
sellFrame:SetScript("OnUpdate", function()
if not isMerchantOpen then
this:SetScript("OnUpdate", nil)
if soldCount > 0 then
addon:Print("Sold " .. soldCount .. " junk item(s).")
end
return
end
idx = idx + 1
local item = junkItems[idx]
if item then
local link = GetContainerItemLink(item.bag, item.slot)
if link and string.find(link, "|cff9d9d9d") then
UseContainerItem(item.bag, item.slot)
soldCount = soldCount + 1
end
else
this:SetScript("OnUpdate", nil)
if soldCount > 0 then
addon:Print("Sold " .. soldCount .. " junk item(s).")
end
end
end)
end
end
end, "BagFrame")
addon.Modules.Events:Register("MERCHANT_CLOSED", function()
+97
View File
@@ -62,6 +62,7 @@ function Guda_SettingsPopup_OnLoad(self)
if generalTab then
CreateSectionHeader(generalTab, "Appearance", -12)
CreateSectionHeader(generalTab, "Options", -120)
CreateSectionHeader(generalTab, "Automation", -230)
end
local layoutTab = getglobal("Guda_SettingsPopup_LayoutTab")
@@ -282,6 +283,22 @@ function Guda_SettingsPopup_OnShow(self)
markEquipmentSetsCheckbox:SetChecked(markEquipmentSets and 1 or 0)
end
-- Automation checkboxes
local autoVendorJunkCheckbox = getglobal("Guda_SettingsPopup_AutoVendorJunkCheckbox")
local autoVendorJunk = Guda.Modules.DB:GetSetting("autoVendorJunk")
if autoVendorJunk == nil then autoVendorJunk = true end
if autoVendorJunkCheckbox then
autoVendorJunkCheckbox:SetChecked(autoVendorJunk and 1 or 0)
end
-- White Items as Junk checkbox
local whiteItemsJunkCheckbox = getglobal("Guda_SettingsPopup_WhiteItemsJunkCheckbox")
local whiteItemsJunk = Guda.Modules.DB:GetSetting("whiteItemsJunk")
if whiteItemsJunk == nil then whiteItemsJunk = false end
if whiteItemsJunkCheckbox then
whiteItemsJunkCheckbox:SetChecked(whiteItemsJunk and 1 or 0)
end
if bagViewButton then
if bagViewType == "single" then
bagViewButton:SetText("Bag View: Single")
@@ -1293,6 +1310,86 @@ function Guda_SettingsPopup_MarkEquipmentSetsCheckbox_OnClick(self)
end
end
-- Auto Vendor Junk Checkbox OnLoad
function Guda_SettingsPopup_AutoVendorJunkCheckbox_OnLoad(self)
local text = getglobal(self:GetName().."Text")
if text then
text:SetText("Auto Sell Junk")
local font, _, flags = text:GetFont()
if font then
text:SetFont(font, 13, flags)
end
end
self.tooltipText = "Automatically sell gray (junk) items when you visit a vendor."
local enabled = true
if Guda and Guda.Modules and Guda.Modules.DB then
enabled = Guda.Modules.DB:GetSetting("autoVendorJunk")
if enabled == nil then enabled = true end
end
self:SetChecked(enabled and 1 or 0)
end
-- Auto Vendor Junk Checkbox OnClick
function Guda_SettingsPopup_AutoVendorJunkCheckbox_OnClick(self)
local isChecked = self:GetChecked() == 1
if Guda and Guda.Modules and Guda.Modules.DB then
Guda.Modules.DB:SetSetting("autoVendorJunk", isChecked)
end
end
-- White Items as Junk Checkbox OnLoad
function Guda_SettingsPopup_WhiteItemsJunkCheckbox_OnLoad(self)
local text = getglobal(self:GetName().."Text")
if text then
text:SetText("White Items as Junk")
local font, _, flags = text:GetFont()
if font then
text:SetFont(font, 13, flags)
end
end
self.tooltipText = "Treat white (common) equippable items as junk. They will be dimmed and auto-sold if auto-sell is enabled."
local enabled = false
if Guda and Guda.Modules and Guda.Modules.DB then
enabled = Guda.Modules.DB:GetSetting("whiteItemsJunk")
if enabled == nil then enabled = false end
end
self:SetChecked(enabled and 1 or 0)
end
-- White Items as Junk Checkbox OnClick
function Guda_SettingsPopup_WhiteItemsJunkCheckbox_OnClick(self)
local isChecked = self:GetChecked() == 1
if Guda and Guda.Modules and Guda.Modules.DB then
Guda.Modules.DB:SetSetting("whiteItemsJunk", isChecked)
end
-- Clear item detection cache so junk status is re-evaluated
if Guda.Modules.ItemDetection and Guda.Modules.ItemDetection.ClearCache then
Guda.Modules.ItemDetection:ClearCache()
end
-- Update bag and bank frames
local bagFrame = getglobal("Guda_BagFrame")
if bagFrame and bagFrame:IsShown() then
Guda.Modules.BagFrame:Update()
end
local bankFrame = getglobal("Guda_BankFrame")
if bankFrame and bankFrame:IsShown() then
Guda.Modules.BankFrame:Update()
end
end
-- Theme Dropdown OnClick
function Guda_SettingsPopup_ThemeDropdown_OnClick(button)
local themes = {
+28 -1
View File
@@ -317,6 +317,20 @@
<OnClick>Guda_SettingsPopup_ReverseStackSortCheckbox_OnClick(this)</OnClick>
</Scripts>
</CheckButton>
<!-- Automation section -->
<!-- Auto Sell Junk Checkbox -->
<CheckButton name="Guda_SettingsPopup_AutoVendorJunkCheckbox" inherits="OptionsCheckButtonTemplate">
<Anchors>
<Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" relativeTo="Guda_SettingsPopup_ShowTooltipCountsCheckbox">
<Offset><AbsDimension x="0" y="-35"/></Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>Guda_SettingsPopup_AutoVendorJunkCheckbox_OnLoad(this)</OnLoad>
<OnClick>Guda_SettingsPopup_AutoVendorJunkCheckbox_OnClick(this)</OnClick>
</Scripts>
</CheckButton>
</Frames>
</Frame>
@@ -555,11 +569,24 @@
</Scripts>
</CheckButton>
<!-- White Items as Junk Checkbox -->
<CheckButton name="Guda_SettingsPopup_WhiteItemsJunkCheckbox" inherits="OptionsCheckButtonTemplate">
<Anchors>
<Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" relativeTo="Guda_SettingsPopup_MarkUnusableCheckbox">
<Offset><AbsDimension x="0" y="-8"/></Offset>
</Anchor>
</Anchors>
<Scripts>
<OnLoad>Guda_SettingsPopup_WhiteItemsJunkCheckbox_OnLoad(this)</OnLoad>
<OnClick>Guda_SettingsPopup_WhiteItemsJunkCheckbox_OnClick(this)</OnClick>
</Scripts>
</CheckButton>
<!-- Junk Item Opacity Slider -->
<Slider name="Guda_SettingsPopup_JunkOpacitySlider" inherits="OptionsSliderTemplate">
<Size><AbsDimension x="450" y="17"/></Size>
<Anchors>
<Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" relativeTo="Guda_SettingsPopup_MarkUnusableCheckbox">
<Anchor point="TOPLEFT" relativePoint="BOTTOMLEFT" relativeTo="Guda_SettingsPopup_WhiteItemsJunkCheckbox">
<Offset><AbsDimension x="0" y="-25"/></Offset>
</Anchor>
</Anchors>