From 7ee7e7e7bdee33f98144a82f54be683d64faa21d Mon Sep 17 00:00:00 2001 From: RealityWinner <31143064+RealityWinner@users.noreply.github.com> Date: Mon, 3 Jul 2023 22:09:07 -0400 Subject: [PATCH] Fix bank sort button and make weapons first (#7) This fixes bank sorting in bagnon (the button would sort your inventory bags) and makes weapons first in sorting to fit next to Armor. --- Bagnon/components/sortBtn.lua | 46 +++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/Bagnon/components/sortBtn.lua b/Bagnon/components/sortBtn.lua index fc6247b..3b5cf94 100644 --- a/Bagnon/components/sortBtn.lua +++ b/Bagnon/components/sortBtn.lua @@ -1,4 +1,4 @@ ---[[ +--[[ sortBtn.lua imagine a button that sorts your inventory in Bagnon, crazy am I right?!1 --]] @@ -78,6 +78,9 @@ local function CompareItems(lItem, rItem) elseif (lItem.id == nil) then return false; elseif (lItem.class ~= rItem.class) then + if lItem.class == "Weapon" or rItem.class == "Weapon" then + return lItem.class == "Weapon" + end return (lItem.class < rItem.class); elseif (lItem.subclass ~= rItem.subclass) then return (lItem.subclass < rItem.subclass); @@ -207,7 +210,28 @@ end --[[ Frame Events ]] -- function SortBtn:OnClick() local bags = {}; - for i = 0, NUM_BAG_FRAMES, 1 do + + if self.frameID == "inventory" then + for i = 0, NUM_BAG_FRAMES, 1 do + local bag = CreateBagFromID(i); + local type = select(2, GetContainerNumFreeSlots(i)); + if type == nil then + type = "ALL" + else + type = tostring(type); + end + if bags[type] == nil then + bags[type] = bag; + else + for j = 1, #bag, 1 do + table.insert(bags[type], bag[j]); + end + end + end + end + + if self.frameID == "bank" then + local i = -1 local bag = CreateBagFromID(i); local type = select(2, GetContainerNumFreeSlots(i)); if type == nil then @@ -222,8 +246,26 @@ function SortBtn:OnClick() table.insert(bags[type], bag[j]); end end + + for i = NUM_BAG_FRAMES+1, NUM_BAG_FRAMES + NUM_BANKBAGSLOTS, 1 do + local bag = CreateBagFromID(i); + local type = select(2, GetContainerNumFreeSlots(i)); + if type == nil then + type = "ALL" + else + type = tostring(type); + end + if bags[type] == nil then + bags[type] = bag; + else + for j = 1, #bag, 1 do + table.insert(bags[type], bag[j]); + end + end + end end + BeginSort(); for k, v in pairs(bags) do if v ~= nil then