From a3af144dec34adf9e8ac047dd368bb102de40821 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 20 Feb 2023 03:55:51 +0000 Subject: chat system, some controls changes --- client/msgbox.lua | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 client/msgbox.lua (limited to 'client/msgbox.lua') diff --git a/client/msgbox.lua b/client/msgbox.lua new file mode 100644 index 0000000..720bfab --- /dev/null +++ b/client/msgbox.lua @@ -0,0 +1,53 @@ +local font = love.graphics.getFont() + + +local msgs = {} + +local function add(str) + table.insert(msgs, 1, {text=love.graphics.newText(font,str),time=10}) +end + +local margin_bottom = 70 + +local function draw() + if #msgs == 0 then return end + + local W,H = love.graphics.getDimensions() + local maxw = 0 + local sumh = 0 + for _,msg in ipairs(msgs) do + local text = msg.text + maxw = math.max(maxw,text:getWidth()) + sumh = sumh + text:getHeight() + end + love.graphics.setColor(0,0,0,0.8) + love.graphics.rectangle("fill",0,H-sumh-margin_bottom,maxw,sumh) + + love.graphics.setColor(1,1,1) + local cury = H + for _,msg in ipairs(msgs) do + local text = msg.text + local h = text:getHeight() + love.graphics.draw(text,0,cury-h-margin_bottom) + cury = cury - h + end +end + +local function update(dt) + for ix = #msgs,1,-1 do + local m = msgs[ix] + m.time = m.time - dt + if m.time <= 0 then + msgs[ix] = nil + end + end +end + + + + +return { + draw=draw, + update=update, + add=add, +} -- cgit v1.2.3