mirror of
https://github.com/notwa/mm
synced 2024-06-30 22:07:11 -07:00
a dumb frame-based message renderer
This commit is contained in:
parent
9dabf504d4
commit
5c76e9466a
|
@ -1,6 +1,7 @@
|
||||||
require "boilerplate"
|
require "boilerplate"
|
||||||
require "addrs.init"
|
require "addrs.init"
|
||||||
require "classes"
|
require "classes"
|
||||||
|
require "messages"
|
||||||
|
|
||||||
-- check for errors in the actor linked lists
|
-- check for errors in the actor linked lists
|
||||||
local validate = false
|
local validate = false
|
||||||
|
@ -27,15 +28,6 @@ function sort_by_key(t)
|
||||||
return sorted
|
return sorted
|
||||||
end
|
end
|
||||||
|
|
||||||
function T(x, y, color, pos, fmt, ...)
|
|
||||||
gui.text(10*x + 2, 16*y + 4, fmt:format(...), nil, color or "white", pos or "bottomright")
|
|
||||||
end
|
|
||||||
|
|
||||||
function T_BR(x, y, color, ...) T(x, y, color, "bottomright", ...) end
|
|
||||||
function T_BL(x, y, color, ...) T(x, y, color, "bottomleft", ...) end
|
|
||||||
function T_TL(x, y, color, ...) T(x, y, color, "topleft", ...) end
|
|
||||||
function T_TR(x, y, color, ...) T(x, y, color, "topright", ...) end
|
|
||||||
|
|
||||||
function get_actor_count(i)
|
function get_actor_count(i)
|
||||||
return R4(addrs.actor_counts[i].addr)
|
return R4(addrs.actor_counts[i].addr)
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,18 +2,7 @@ require "boilerplate"
|
||||||
require "addrs.init"
|
require "addrs.init"
|
||||||
require "classes"
|
require "classes"
|
||||||
require "menu classes"
|
require "menu classes"
|
||||||
|
require "messages"
|
||||||
function T(x, y, color, pos, s, ...)
|
|
||||||
if #{...} > 0 then
|
|
||||||
s = s:format(...)
|
|
||||||
end
|
|
||||||
gui.text(10*x + 2, 16*y + 4, s, nil, color or "white", pos or "bottomright")
|
|
||||||
end
|
|
||||||
|
|
||||||
function T_BR(x, y, color, ...) T(x, y, color, "bottomright", ...) end
|
|
||||||
function T_BL(x, y, color, ...) T(x, y, color, "bottomleft", ...) end
|
|
||||||
function T_TL(x, y, color, ...) T(x, y, color, "topleft", ...) end
|
|
||||||
function T_TR(x, y, color, ...) T(x, y, color, "topright", ...) end
|
|
||||||
|
|
||||||
local passives = {}
|
local passives = {}
|
||||||
|
|
||||||
|
|
48
Lua/messages.lua
Normal file
48
Lua/messages.lua
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
-- gui.addmessage sucks so we're doing this our way
|
||||||
|
|
||||||
|
function T(x, y, color, pos, s, ...)
|
||||||
|
if #{...} > 0 then
|
||||||
|
s = s:format(...)
|
||||||
|
end
|
||||||
|
gui.text(10*x + 2, 16*y + 4, s, nil, color or "white", pos or "bottomright")
|
||||||
|
end
|
||||||
|
|
||||||
|
function T_BR(x, y, color, ...) T(x, y, color, "bottomright", ...) end
|
||||||
|
function T_BL(x, y, color, ...) T(x, y, color, "bottomleft", ...) end
|
||||||
|
function T_TL(x, y, color, ...) T(x, y, color, "topleft", ...) end
|
||||||
|
function T_TR(x, y, color, ...) T(x, y, color, "topright", ...) end
|
||||||
|
|
||||||
|
messages = {}
|
||||||
|
__messages_then = 0
|
||||||
|
|
||||||
|
function message(text, frames)
|
||||||
|
local now = emu.framecount()
|
||||||
|
frames = frames or 60
|
||||||
|
local when = now + frames
|
||||||
|
table.insert(messages, {text=text, when=when})
|
||||||
|
end
|
||||||
|
|
||||||
|
function draw_messages()
|
||||||
|
local now = emu.framecount()
|
||||||
|
if now == __messages_then then
|
||||||
|
-- already drawn this frame
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if now ~= __messages_then + 1 then
|
||||||
|
-- nonlinearity in time, probably a savestate
|
||||||
|
messages = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
local okay = {}
|
||||||
|
for i, t in ipairs(messages) do
|
||||||
|
if now < t.when then
|
||||||
|
table.insert(okay, t)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i, t in ipairs(okay) do
|
||||||
|
T_BL(0, i - 1, nil, t.text)
|
||||||
|
end
|
||||||
|
|
||||||
|
messages = okay
|
||||||
|
__messages_then = now
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user