summaryrefslogtreecommitdiff
path: root/client/msgbox.lua
diff options
context:
space:
mode:
authorubq323 <ubq323@ubq323.website>2023-02-20 03:55:51 +0000
committerubq323 <ubq323@ubq323.website>2023-02-20 03:55:51 +0000
commita3af144dec34adf9e8ac047dd368bb102de40821 (patch)
tree23f84d753dd3158d65f58004686687977f6f5496 /client/msgbox.lua
parent12972093a8eb1853c4bbe32750e43ec390cfe8c5 (diff)
chat system, some controls changes
Diffstat (limited to 'client/msgbox.lua')
-rw-r--r--client/msgbox.lua53
1 files changed, 53 insertions, 0 deletions
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,
+}