Resort overview every 30seconds

This commit is contained in:
Max
2026-06-01 04:23:27 +02:00
parent acfc5e7324
commit 4f623656bb
+33 -23
View File
@@ -404,42 +404,52 @@ end
drawOverview = function()
local items = getBaseItemIds()
local itemCounts = getMeItemCounts(items)
local sortedItemIds = {}
local visibleItemCount = 0
for i = 1, #items do
sortedItemIds[i] = items[i]
end
local function renderOverview()
local itemCounts = getMeItemCounts(items)
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
for i = 1, #items do
sortedItemIds[i] = items[i]
end
return a < b
end)
table.sort(sortedItemIds, function(a, b)
local countA = itemCounts[a] or 0
local countB = itemCounts[b] or 0
local visibleItemCount = math.min(#sortedItemIds, 9)
if countA ~= countB then
return countA > countB
end
frame.buffer:clear()
return a < b
end)
for i = 1, visibleItemCount do
local itemId = sortedItemIds[i]
local item = getItemById(itemId)
local icon = getItemIcon(item) or getFallbackIcon()
drawItem(icon, 4+(8+4)*((i-1)%3), 2+(5+1)*math.floor((i-1)/3), itemCounts[itemId] or 0)
visibleItemCount = math.min(#sortedItemIds, 9)
frame.buffer:clear()
for i = 1, visibleItemCount do
local itemId = sortedItemIds[i]
local item = getItemById(itemId)
local icon = getItemIcon(item) or getFallbackIcon()
drawItem(icon, 4+(8+4)*((i-1)%3), 2+(5+1)*math.floor((i-1)/3), itemCounts[itemId] or 0)
end
assertBufferValid(frame)
frame:drawBuffer()
end
assertBufferValid(frame)
frame:drawBuffer()
renderOverview()
local refreshTimer = os.startTimer(30)
while true do
local _, side, x, y = os.pullEvent("monitor_touch")
local event, p1, x, y = os.pullEvent()
if side == monName then
if event == "timer" and p1 == refreshTimer then
renderOverview()
refreshTimer = os.startTimer(30)
elseif event == "monitor_touch" and p1 == monName then
local col = math.floor((x - 4) / 12)
local row = math.floor((y - 2) / 6)