room/day: add animation to text

This commit is contained in:
Franzi 2023-09-30 09:47:09 +02:00
parent 17992f7283
commit 4e15583b4e

View file

@ -308,37 +308,58 @@ end
local function view_room(starts, ends, config, x1, y1, x2, y2) local function view_room(starts, ends, config, x1, y1, x2, y2)
local font_size = config.font_size or 70 local font_size = config.font_size or 70
local align = config.room_align or "left" local align = config.room_align or "left"
local r,g,b = helper.parse_rgb(config.color or "#ffffff") local default_color = {helper.parse_rgb(config.color or "#ffffff")}
local a = anims.Area(x2 - x1, y2 - y1)
local S = starts
local E = ends
local function text(...)
return a.add(anims.moving_font(S, E, font, ...))
end
local x = 0
local w = font:width(current_room, font_size)
if align == "right" then
x = a.width - w
elseif align == "center" then
x = (a.width - w) / 2
end
text(x, 0, current_room, font_size, rgba(default_color,1))
for now in api.frame_between(starts, ends) do for now in api.frame_between(starts, ends) do
local x = x1 a.draw(now, x1, y1, x2, y2)
local w = font:width(current_room, font_size)
if align == "right" then
x = x2 - w
elseif align == "center" then
x = (x1 + x2 - w) / 2
end
font:write(x, y1, current_room, font_size, r,g,b)
end end
end end
local function view_day(starts, ends, config, x1, y1, x2, y2) local function view_day(starts, ends, config, x1, y1, x2, y2)
local font_size = config.font_size or 70 local font_size = config.font_size or 70
local r,g,b = helper.parse_rgb(config.color or "#ffffff")
local align = config.day_align or "left" local align = config.day_align or "left"
local template = config.day_template or "Day %d" local template = config.day_template or "Day %d"
local default_color = {helper.parse_rgb(config.color or "#ffffff")}
local a = anims.Area(x2 - x1, y2 - y1)
local S = starts
local E = ends
local function text(...)
return a.add(anims.moving_font(S, E, font, ...))
end
local x = 0
local line = string.format(template, day)
local w = font:width(line, font_size)
if align == "right" then
x = a.width - w
elseif align == "center" then
x = (a.width - w) / 2
end
text(x, 0, line, font_size, rgba(default_color,1))
for now in api.frame_between(starts, ends) do for now in api.frame_between(starts, ends) do
local x = x1 a.draw(now, x1, y1, x2, y2)
local line = string.format(template, day)
local w = font:width(line, font_size)
if align == "right" then
x = x2 - w
elseif align == "center" then
x = (x1 + x2 - w) / 2
end
font:write(x, y1, line, font_size, r,g,b)
end end
end end