Added sorting to Overview
This commit is contained in:
+30
-7
@@ -45,7 +45,12 @@ local function ensureChainsLoaded()
|
|||||||
local itemCount = 0
|
local itemCount = 0
|
||||||
|
|
||||||
for _, item in ipairs(chain.items or {}) do
|
for _, item in ipairs(chain.items or {}) do
|
||||||
if item.stage ~= "item" then
|
if item.stage == "item" then
|
||||||
|
itemById[item.item_id] = {
|
||||||
|
id = item.item_id,
|
||||||
|
icon_nfp = item.icon_nfp_16x16,
|
||||||
|
}
|
||||||
|
else
|
||||||
itemCount = itemCount + 1
|
itemCount = itemCount + 1
|
||||||
items[itemCount] = {
|
items[itemCount] = {
|
||||||
id = item.item_id,
|
id = item.item_id,
|
||||||
@@ -359,7 +364,7 @@ local function drawPage(base_id)
|
|||||||
local backWidth, backHeight = imageSize(backIcon)
|
local backWidth, backHeight = imageSize(backIcon)
|
||||||
local backX = SCREEN_WIDTH - backWidth + 1
|
local backX = SCREEN_WIDTH - backWidth + 1
|
||||||
local pageItemIds = {}
|
local pageItemIds = {}
|
||||||
local visibleItemCount = math.min(math.max(#pageItems, 9), 9)
|
local visibleItemCount = math.min(#pageItems, 9)
|
||||||
|
|
||||||
for i = 1, visibleItemCount do
|
for i = 1, visibleItemCount do
|
||||||
pageItemIds[i] = pageItems[i].id
|
pageItemIds[i] = pageItems[i].id
|
||||||
@@ -399,15 +404,33 @@ end
|
|||||||
|
|
||||||
drawOverview = function()
|
drawOverview = function()
|
||||||
local items = getBaseItemIds()
|
local items = getBaseItemIds()
|
||||||
local visibleItemCount = math.min(math.max(#items, 9), 9)
|
local itemCounts = getMeItemCounts(items)
|
||||||
-- TODO LATER: get item counts from me-system using item, then sort items according to their counts and display the top 9. For now, just use random numbers.
|
local sortedItemIds = {}
|
||||||
|
|
||||||
|
for i = 1, #items do
|
||||||
|
sortedItemIds[i] = items[i]
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(sortedItemIds, function(a, b)
|
||||||
|
local countA = itemCounts[a] or 0
|
||||||
|
local countB = itemCounts[b] or 0
|
||||||
|
|
||||||
|
if countA ~= countB then
|
||||||
|
return countA > countB
|
||||||
|
end
|
||||||
|
|
||||||
|
return a < b
|
||||||
|
end)
|
||||||
|
|
||||||
|
local visibleItemCount = math.min(#sortedItemIds, 9)
|
||||||
|
|
||||||
frame.buffer:clear()
|
frame.buffer:clear()
|
||||||
|
|
||||||
for i = 1, visibleItemCount do
|
for i = 1, visibleItemCount do
|
||||||
local item = getItemById(items[i])
|
local itemId = sortedItemIds[i]
|
||||||
|
local item = getItemById(itemId)
|
||||||
local icon = getItemIcon(item) or getFallbackIcon()
|
local icon = getItemIcon(item) or getFallbackIcon()
|
||||||
drawItem(icon, 4+(8+4)*((i-1)%3), 2+(5+1)*math.floor((i-1)/3), math.random(0, 1000000000000))
|
drawItem(icon, 4+(8+4)*((i-1)%3), 2+(5+1)*math.floor((i-1)/3), itemCounts[itemId] or 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
assertBufferValid(frame)
|
assertBufferValid(frame)
|
||||||
@@ -424,7 +447,7 @@ drawOverview = function()
|
|||||||
local index = row * 3 + col + 1
|
local index = row * 3 + col + 1
|
||||||
|
|
||||||
if index <= visibleItemCount then
|
if index <= visibleItemCount then
|
||||||
drawPage(items[index])
|
drawPage(sortedItemIds[index])
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user