diff options
| author | ubq323 <ubq323@ubq323.website> | 2025-06-10 14:11:06 +0100 |
|---|---|---|
| committer | ubq323 <ubq323@ubq323.website> | 2025-06-10 14:11:06 +0100 |
| commit | 26092dbd56fab16b8036224cd0fa507bab2bd51d (patch) | |
| tree | b5e2503f3bc637efa6bf863df6428b06fe8bd2d3 /msgbox.lua | |
| parent | 21e6694c2244a8e7c102bd841e41a3e627e0e885 (diff) | |
add msgbox frm hexemu
Diffstat (limited to 'msgbox.lua')
| -rw-r--r-- | msgbox.lua | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/msgbox.lua b/msgbox.lua new file mode 100644 index 0000000..720bfab --- /dev/null +++ b/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, +} |
