Files
YataiDON14/Scripts/game/song_info.lua
T
2026-11-22 19:25:31 -05:00

69 lines
2.8 KiB
Lua

SongInfo = {}
SongInfo.__index = SongInfo
-- Taiko 14 title band (enso_kyokumei_ac): every 4 s the song title cross-fades (0.5 s) to the course and
-- "N曲目" for 1.5 s and back. Course and number art: Graphics/game/song_info; the band: background.lua.
local WHITE, BLACK = { 255, 255, 255, 255 }, { 0, 0, 0, 255 }
local LOOP, FADE, HOLD = 4000, 500, 1500 -- ms: title HOLD, FADE, label HOLD, FADE
local COURSE = { [0] = "easy", "normal", "hard", "oni", "oni" }
local DIGIT_W = 24 * tex.get_screen_width() / 640
local function outline_of(cfg)
return cfg.outline >= 0 and cfg.outline or 5.0
end
function SongInfo.new(title, subtitle, number)
local self = setmetatable({}, SongInfo)
self.title_cfg = tex.get_skin_config("game_song_info")
self.title = text.create_raw_text(title, self.title_cfg.font_size, WHITE, BLACK, false, outline_of(self.title_cfg))
local max_width_cfg = tex.get_skin_config("game_song_info_max_width")
self.max_width = max_width_cfg and max_width_cfg.width
local c = type(NK_COURSE_BY_PLAYER) == "table" and NK_COURSE_BY_PLAYER[1]
self.t_course = tex.get_texture("song_info/course_" .. (COURSE[c or 3] or "oni"))
self.t_word = tex.get_texture("song_info/stage_word")
self.t_num = tex.get_texture("song_info/stage_num")
self.number = math.max(0, math.floor(tonumber(number) or 0))
self.ms = 0
return self
end
function SongInfo:update(current_ms)
self.start = self.start or current_ms
self.ms = current_ms - self.start
end
-- label weight: 0 = title, 1 = course / number
function SongInfo:label_weight()
local t = self.ms % LOOP
if t < HOLD then return 0 end
t = t - HOLD
if t < FADE then return t / FADE end
t = t - FADE
if t < HOLD then return 1 end
return 1 - (t - HOLD) / FADE
end
function SongInfo:draw(dx, dy)
local w = self:label_weight()
if w < 1 then
local title_w, title_x2 = self.title.width, 0
if self.max_width and self.max_width > 0 and title_w > self.max_width then
title_x2 = self.max_width - title_w
title_w = self.max_width
end
self.title:draw({ x = self.title_cfg.x + dx - title_w, y = self.title_cfg.y + dy - self.title.height / 2,
x2 = title_x2, fade = 1 - w })
end
if w > 0 then
local fade = w < 1 and w or nil
if self.t_course then tex.draw_texture(self.t_course, { x = dx, y = dy, fade = fade }) end
if self.t_word then tex.draw_texture(self.t_word, { x = dx, y = dy, fade = fade }) end
if self.t_num and self.number > 0 then
local s = tostring(self.number)
for i = 1, #s do
tex.draw_texture(self.t_num, { frame = s:byte(i) - 48, x = dx - DIGIT_W * (#s - i), y = dy, fade = fade })
end
end
end
end