feat: reverse stack sorting
This commit is contained in:
+28
-2
@@ -489,6 +489,9 @@ local function AddSortKeys(items)
|
|||||||
item.texturePattern = ""
|
item.texturePattern = ""
|
||||||
item.invertedCount = 0
|
item.invertedCount = 0
|
||||||
item.invertedItemID = 0
|
item.invertedItemID = 0
|
||||||
|
item.maxStackCount = 1
|
||||||
|
item.isStackable = false
|
||||||
|
item.stackCount = 1
|
||||||
else
|
else
|
||||||
-- Check if item is equippable (Armor or Weapon category)
|
-- Check if item is equippable (Armor or Weapon category)
|
||||||
local isEquippable = itemCategory == "Armor" or itemCategory == "Weapon"
|
local isEquippable = itemCategory == "Armor" or itemCategory == "Weapon"
|
||||||
@@ -576,6 +579,11 @@ local function AddSortKeys(items)
|
|||||||
item.invertedCount = -(tonumber(item.data.count) or 1)
|
item.invertedCount = -(tonumber(item.data.count) or 1)
|
||||||
item.invertedItemID = -tonumber(itemID)
|
item.invertedItemID = -tonumber(itemID)
|
||||||
|
|
||||||
|
-- Stack info for reverse stack sorting
|
||||||
|
item.maxStackCount = tonumber(itemStackCount) or 1
|
||||||
|
item.isStackable = item.maxStackCount > 1
|
||||||
|
item.stackCount = tonumber(item.data.count) or 1
|
||||||
|
|
||||||
-- Name for alphabetical sorting
|
-- Name for alphabetical sorting
|
||||||
item.itemName = item.name or ""
|
item.itemName = item.name or ""
|
||||||
end
|
end
|
||||||
@@ -586,6 +594,15 @@ end
|
|||||||
local function SortItems(items)
|
local function SortItems(items)
|
||||||
AddSortKeys(items)
|
AddSortKeys(items)
|
||||||
|
|
||||||
|
-- Get reverse stack sort setting from DB
|
||||||
|
local reverseStackSort = false
|
||||||
|
if addon.Modules.DB and addon.Modules.DB.GetSetting then
|
||||||
|
reverseStackSort = addon.Modules.DB:GetSetting("reverseStackSort")
|
||||||
|
if reverseStackSort == nil then
|
||||||
|
reverseStackSort = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
table.sort(items, function(a, b)
|
table.sort(items, function(a, b)
|
||||||
-- 1. Priority items first (Hearthstone, etc.)
|
-- 1. Priority items first (Hearthstone, etc.)
|
||||||
if a.priority ~= b.priority then
|
if a.priority ~= b.priority then
|
||||||
@@ -677,9 +694,18 @@ local function SortItems(items)
|
|||||||
if a.invertedItemLevel ~= b.invertedItemLevel then
|
if a.invertedItemLevel ~= b.invertedItemLevel then
|
||||||
return a.invertedItemLevel < b.invertedItemLevel
|
return a.invertedItemLevel < b.invertedItemLevel
|
||||||
end
|
end
|
||||||
-- Then by stack count (larger stacks first)
|
-- Then by stack count
|
||||||
|
-- If reverse stack sort is enabled AND both items are the same stackable item,
|
||||||
|
-- place smaller stacks before larger ones
|
||||||
if a.invertedCount ~= b.invertedCount then
|
if a.invertedCount ~= b.invertedCount then
|
||||||
return a.invertedCount < b.invertedCount
|
-- Check if both items are the same stackable item (same itemID)
|
||||||
|
if reverseStackSort and a.isStackable and b.isStackable and a.invertedItemID == b.invertedItemID then
|
||||||
|
-- Reverse: smaller stacks first (compare stackCount ascending)
|
||||||
|
return a.stackCount < b.stackCount
|
||||||
|
else
|
||||||
|
-- Normal: larger stacks first (use invertedCount)
|
||||||
|
return a.invertedCount < b.invertedCount
|
||||||
|
end
|
||||||
end
|
end
|
||||||
-- Final stable sort: preserve original collection order for identical items
|
-- Final stable sort: preserve original collection order for identical items
|
||||||
-- This prevents unnecessary reshuffling when items are already sorted
|
-- This prevents unnecessary reshuffling when items are already sorted
|
||||||
|
|||||||
@@ -973,6 +973,46 @@ function Guda_SettingsPopup_BankViewTypeButton_OnClick()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Reverse Stack Sort Checkbox OnLoad
|
||||||
|
function Guda_SettingsPopup_ReverseStackSortCheckbox_OnLoad(self)
|
||||||
|
local text = getglobal(self:GetName().."Text")
|
||||||
|
if text then
|
||||||
|
text:SetText("Reverse Stack Sort")
|
||||||
|
|
||||||
|
-- Increase font size
|
||||||
|
local font, _, flags = text:GetFont()
|
||||||
|
if font then
|
||||||
|
text:SetFont(font, 13, flags)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Tooltip
|
||||||
|
self.tooltipText = "When enabled, smaller stacks of the same item will be sorted before larger stacks (e.g., stack of 16 before stack of 20)."
|
||||||
|
|
||||||
|
local reverseStackSort = false
|
||||||
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
||||||
|
reverseStackSort = Guda.Modules.DB:GetSetting("reverseStackSort")
|
||||||
|
if reverseStackSort == nil then
|
||||||
|
reverseStackSort = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
self:SetChecked(reverseStackSort and 1 or 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Reverse Stack Sort Checkbox OnClick
|
||||||
|
function Guda_SettingsPopup_ReverseStackSortCheckbox_OnClick(self)
|
||||||
|
local isChecked = self:GetChecked() == 1
|
||||||
|
|
||||||
|
-- Save setting
|
||||||
|
if Guda and Guda.Modules and Guda.Modules.DB then
|
||||||
|
Guda.Modules.DB:SetSetting("reverseStackSort", isChecked)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Note: Sorting will use the new setting on next sort operation
|
||||||
|
-- No immediate UI update needed
|
||||||
|
end
|
||||||
|
|
||||||
-- Initialize
|
-- Initialize
|
||||||
function SettingsPopup:Initialize()
|
function SettingsPopup:Initialize()
|
||||||
Guda:Debug("Settings popup initialized")
|
Guda:Debug("Settings popup initialized")
|
||||||
|
|||||||
+26
-7
@@ -395,12 +395,31 @@
|
|||||||
</Scripts>
|
</Scripts>
|
||||||
</CheckButton>
|
</CheckButton>
|
||||||
|
|
||||||
<!-- View Types (Toggles for now since no Dropdown) -->
|
<!-- Reverse Stack Sort Checkbox -->
|
||||||
<Button name="Guda_SettingsPopup_BagViewTypeButton" inherits="UIPanelButtonTemplate">
|
<CheckButton name="Guda_SettingsPopup_ReverseStackSortCheckbox" inherits="OptionsCheckButtonTemplate">
|
||||||
<Size><AbsDimension x="130" y="25"/></Size>
|
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="TOPLEFT" relativeTo="Guda_SettingsPopup_HideFooterCheckbox" relativePoint="BOTTOMLEFT">
|
<Anchor point="TOP" relativePoint="BOTTOM" relativeTo="Guda_SettingsPopup_HoverBaglineCheckbox">
|
||||||
<Offset><AbsDimension x="-175" y="-15"/></Offset>
|
<Offset>
|
||||||
|
<AbsDimension x="0" y="-8"/>
|
||||||
|
</Offset>
|
||||||
|
</Anchor>
|
||||||
|
</Anchors>
|
||||||
|
<Scripts>
|
||||||
|
<OnLoad>
|
||||||
|
Guda_SettingsPopup_ReverseStackSortCheckbox_OnLoad(this)
|
||||||
|
</OnLoad>
|
||||||
|
<OnClick>
|
||||||
|
Guda_SettingsPopup_ReverseStackSortCheckbox_OnClick(this)
|
||||||
|
</OnClick>
|
||||||
|
</Scripts>
|
||||||
|
</CheckButton>
|
||||||
|
|
||||||
|
<!-- View Types - Same row as Reverse Stack Sort -->
|
||||||
|
<Button name="Guda_SettingsPopup_BagViewTypeButton" inherits="UIPanelButtonTemplate">
|
||||||
|
<Size><AbsDimension x="140" y="22"/></Size>
|
||||||
|
<Anchors>
|
||||||
|
<Anchor point="LEFT" relativePoint="RIGHT" relativeTo="Guda_SettingsPopup_ReverseStackSortCheckbox">
|
||||||
|
<Offset><AbsDimension x="147" y="0"/></Offset>
|
||||||
</Anchor>
|
</Anchor>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
@@ -409,10 +428,10 @@
|
|||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Button name="Guda_SettingsPopup_BankViewTypeButton" inherits="UIPanelButtonTemplate">
|
<Button name="Guda_SettingsPopup_BankViewTypeButton" inherits="UIPanelButtonTemplate">
|
||||||
<Size><AbsDimension x="130" y="25"/></Size>
|
<Size><AbsDimension x="140" y="22"/></Size>
|
||||||
<Anchors>
|
<Anchors>
|
||||||
<Anchor point="LEFT" relativeTo="Guda_SettingsPopup_BagViewTypeButton" relativePoint="RIGHT">
|
<Anchor point="LEFT" relativeTo="Guda_SettingsPopup_BagViewTypeButton" relativePoint="RIGHT">
|
||||||
<Offset><AbsDimension x="20" y="0"/></Offset>
|
<Offset><AbsDimension x="10" y="0"/></Offset>
|
||||||
</Anchor>
|
</Anchor>
|
||||||
</Anchors>
|
</Anchors>
|
||||||
<Scripts>
|
<Scripts>
|
||||||
|
|||||||
Reference in New Issue
Block a user