Skip to content

Commit

Permalink
Change sort to ilvl then itemID
Browse files Browse the repository at this point in the history
  • Loading branch information
Kirri777 committed Oct 27, 2024
1 parent 05627c0 commit 0021c19
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,9 @@ function AddOn:ClearEntries()
self.Entries[i].looter = nil
self.Entries[i].guid = nil
self.Entries[i].itemID = nil
self.Entries[i].ilvl:SetText("0")
self.Entries[i].itemLink = nil
self.Entries[i].looter = nil
end
end
end
Expand Down Expand Up @@ -1159,7 +1162,7 @@ local function SlashCommandHandler(msg)
item:ContinueOnItemLoad(function()
local itemLink = item:GetItemLink()
local itemLevel = item:GetCurrentItemLevel()
local _, _, rarity, _, _, _, _, _, equipLoc, _, _, itemClass, itemSubClass = GetItemInfo(itemLink)
local _, _, rarity, _, _, type, _, _, equipLoc, _, _, itemClass, itemSubClass = GetItemInfo(itemLink)

-- If not Armor/Weapon
if (type ~= ARMOR and type ~= AUCTION_CATEGORY_ARMOR and type ~= WEAPON) then
Expand Down
53 changes: 42 additions & 11 deletions Frame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,43 @@ end

function AddOn:repositionFrames()
local lastentry = nil
local sortByIlvl = {}

-- sort by ilvl
tsort(AddOn.Entries, function(a, b)
return tonumber(a.ilvl:GetText()) > tonumber(b.ilvl:GetText())
-- sort by ilvl
local ailvl, bilvl = tonumber(a.ilvl:GetText()), tonumber(b.ilvl:GetText())
return ailvl > bilvl
end)

for i = 1, #AddOn.Entries do
local currententry = AddOn.Entries[i]
if currententry.itemLink then
if lastentry then
currententry:SetPoint("TOPLEFT", lastentry, "BOTTOMLEFT", 0, 1)
else
currententry:SetPoint("TOPLEFT", AddOn.lootFrame.table.content, "TOPLEFT", 0, 1)
local ilvl = tonumber(AddOn.Entries[i].ilvl:GetText())

if ilvl ~= nil and ilvl > 0 then
if sortByIlvl[ilvl] == nil then
sortByIlvl[ilvl] = {}
end

table.insert(sortByIlvl[ilvl], AddOn.Entries[i])
end
end

for _, entries in pairs(sortByIlvl) do
tsort(entries, function(a, b)
local aitemID, bitemID = tonumber(a.itemID), tonumber(b.itemID)
return aitemID > bitemID
end)

for i = 1, #entries do
local currententry = entries[i]

if currententry.itemLink then
if lastentry then
currententry:SetPoint("TOPLEFT", lastentry, "BOTTOMLEFT", 0, 1)
else
currententry:SetPoint("TOPLEFT", AddOn.lootFrame.table.content, "TOPLEFT", 0, 1)
end
lastentry = currententry
end
lastentry = currententry
end
end
end
Expand Down Expand Up @@ -326,6 +348,10 @@ function AddOn.createLootFrame()
skinBackdrop(entry, 1, 1, 1, .1)
entry:Hide()

entry.itemLink = nil
entry.itemID = nil
entry.looter = nil

---@type table|BackdropTemplate|Frame
entry.item = CreateFrame("Button", nil, entry, "BackdropTemplate")
entry.item:SetSize(20, 20)
Expand Down Expand Up @@ -402,9 +428,14 @@ function AddOn.createLootFrame()
entry.delete:SetText("x")
skinButton(entry.delete, true, "red")
entry.delete:SetScript("OnClick", function()
entry:Hide()
entry.itemLink = nil
entry.looter = nil
entry:Hide()
entry.guid = nil
entry.ilvl:SetText("0")
entry.itemID = nil
entry.looter = nil

-- Re order
AddOn:repositionFrames()
end)
Expand Down

0 comments on commit 0021c19

Please sign in to comment.