From 39f403e0639637b691778e49c2a1929c09864fc3 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 4 Aug 2022 02:37:04 +0100 Subject: chat --- chat.lua | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/chat.lua b/chat.lua index 14d1334..3e82ade 100644 --- a/chat.lua +++ b/chat.lua @@ -5,7 +5,8 @@ assert(M,"no monitor") M.setTextScale(0.5) local Mw,Mh = M.getSize() -local lbw = 4+16+10 +local scorewidth=10 +local lbw = 4+16+scorewidth local wLog = window.create(M,1,1,Mw-lbw,Mh) -- wLog.setBackgroundColor(colors.blue) -- wLog.clear() @@ -31,18 +32,43 @@ end -- lb local function draw_lb(W,scores) + local w,h = W.getSize() W.setBackgroundColor(colors.gray) W.clear() - -- numbers + -- line numbers W.setTextColor(colors.yellow) for line=1,10 do - W.setCursorPos(1,line) + W.setCursorPos(1,line+1) W.write(pad_r(line,2)..".") end + + -- actual scores + local thescores = {} + for name,score in pairs(scores) do + table.insert(thescores,{name=name,score=score}) + end + table.sort(thescores,function(a,b) return a.score < b.score end) + for i=1,10 do + local name,score = thescores[i].name, thescores[i].score + -- name + W.setTextColor(colors.white) + W.setCursorPos(5,i+1) + W.write(name) + -- score + W.setTextColor(colors.blue) + W.setCursorPos(w-scorewidth,i+1) + W.write(pad_r(score,scorewidth)) + end end -draw_lb(wLb,nil) +draw_lb(wLb,{ + aaa=10 + bbb=100 + ccc=12345 + ddd=234287 + thethethethe=69420 + harold=111222}) local function score(msg) -- cgit v1.2.3