summaryrefslogtreecommitdiff
path: root/client/msgbox.lua
diff options
context:
space:
mode:
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,
+}