diff --git a/Core.lua b/Core.lua index d4d9afb..0b14036 100644 --- a/Core.lua +++ b/Core.lua @@ -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 @@ -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 diff --git a/Frame.lua b/Frame.lua index 181de9b..4aa8821 100644 --- a/Frame.lua +++ b/Frame.lua @@ -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 @@ -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) @@ -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)