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

222 lines
8.7 KiB
Lua

AnnounceScene = {}
AnnounceScene.__index = AnnounceScene
-- Taiko 14 announce_new_song.swg (新曲紹介) with Hiroba's two newest songs: the night stage lights up, Don and
-- Katsu announce, the two songs come in on lantern boards, then a firework bursts into the titles.
-- Positions are the swg's 640x480 px (K scales them), times are 60 fps frames.
local PATH = "title/announce14/"
local FRAME_MS = 1000 / 60
local WHITE, BLACK = { 255, 255, 255, 255 }, { 0, 0, 0, 255 }
local LIGHT_AT, GLOW_AT, CLOSEUP_AT = 178, 242, 249
local CHARS_AT, ANNOUNCE_AT = 270, 249
local BOARD_AT, BOARD2_AT, RISE_AT = 300, 363, 423
local BURSTS = { 530, 596 }
local END_AT, FADE_LEN = 720, 20
local WAIT_FOR_DATA = 120
local BOARD_X, BOARD_Y = 132, 62
local SOUNDS = { { 178, "an_iyo" }, { 249, "an_done" }, { 249, "an_roll" }, { 298, "an_new_song", "voice" },
{ 300, "an_fly" }, { 300, "an_lets", "voice" }, { 363, "an_fly" }, { 423, "an_fire_up" },
{ 530, "an_fire_exp" }, { 560, "an_mada", "voice" }, { 596, "an_fire_exp" } }
local function clamp(v, lo, hi) return math.max(lo, math.min(hi, v)) end
local function lerp(a, b, p) return a + (b - a) * p end
local function ease_in(p) return p * p end
local function ease_out(p) return 1 - (1 - p) * (1 - p) end
local function seg(t, from, len) return clamp((t - from) / len, 0, 1) end
local function snd(name, kind)
if audio.has_sound(name) then audio.play_sound(name, kind or "sound") end
end
function AnnounceScene.new()
local self = setmetatable({}, AnnounceScene)
self.K = tex.get_screen_width() / 640
self.tex, self.info = {}, {}
for _, name in ipairs({ "stage_dark", "stage_lit", "stage_lit_light", "stage_glow", "stage_glow_light", "closeup",
"closeup_light", "sky", "header_bar", "header",
"burst_star", "burst_text", "board_frame", "board", "don", "katsu", "trail", "spark",
"firework" }) do
self.tex[name] = tex.get_texture(PATH .. name)
local info = tex.get_texture_info("announce14", name)
self.info[name] = info and { info.x[1] or 0, info.y[1] or 0, info.x2[1] or 0, info.y2[1] or 0 }
or { 0, 0, 0, 0 }
end
self.t0 = nil
self.f = 0
self.songs = nil
self.waited = 0
self.next_sound = 1
self.finished = false
self:fetch()
return self
end
function AnnounceScene:fetch()
local list = network.new_songs()
if not list or #list == 0 then return end
self.songs = {}
for i = 1, math.min(2, #list) do
self.songs[i] = text.create_raw_text(list[i].title, math.floor(34 * self.K), WHITE, BLACK, false, 6)
end
end
function AnnounceScene:tl(name, x, y, o)
o = o or {}
local t = self.tex[name]
if not t then return end
local i = self.info[name]
local s = o.s or 1
tex.draw_texture(t, { frame = o.frame or 0, x = x * self.K - i[1], y = y * self.K - i[2], x2 = i[3] * (s - 1),
y2 = i[4] * (s - 1), fade = o.fade, blend = o.blend })
end
-- a stage state: its base, then its glow art added on top
function AnnounceScene:stage(name, y, fade)
self:tl(name, 0, y, { fade = fade })
if self.tex[name .. "_light"] then self:tl(name .. "_light", 0, y, { fade = fade, blend = "additive" }) end
end
function AnnounceScene:ctr(name, cx, cy, o)
o = o or {}
local i = self.info[name]
local s = o.s or 1
self:tl(name, cx - i[3] / self.K * s / 2, cy - i[4] / self.K * s / 2, o)
end
function AnnounceScene:title(n, cx, cy, width, s, fade)
local t = self.songs[n]
if not t or fade <= 0 then return end
s = s * math.min(1, width * self.K / math.max(1, t.width))
t:draw({ x = cx * self.K - t.width * s / 2, y = cy * self.K - t.height * s / 2, scale = s, fade = fade })
end
function AnnounceScene:update(current_ms)
if not self.songs then
self:fetch()
if not self.songs then
self.waited = self.waited + 1
if self.waited > WAIT_FOR_DATA then self.finished = true end
return
end
end
if not self.t0 then self.t0 = current_ms end
self.f = (current_ms - self.t0) / FRAME_MS
while SOUNDS[self.next_sound] and self.f >= SOUNDS[self.next_sound][1] do
local s = SOUNDS[self.next_sound]
snd(s[2], s[3])
self.next_sound = self.next_sound + 1
end
if self.f >= RISE_AT and audio.is_sound_playing("an_roll") then audio.stop_sound("an_roll") end
if self.f >= END_AT + FADE_LEN then self.finished = true end
end
function AnnounceScene:is_finished() return self.finished end
function AnnounceScene:close()
if audio.is_sound_playing("an_roll") then audio.stop_sound("an_roll") end
end
-- the night stage: lanterns come on from the outside in, a flash, then the close-up; the sky for the firework
function AnnounceScene:draw_stage()
local f = self.f
if f >= RISE_AT then
local p = seg(f, RISE_AT, 50)
self:stage("sky", 0)
self:stage("closeup", 480 * ease_in(p), 1 - p)
return
end
if f >= CLOSEUP_AT then
self:stage("closeup", 0)
return
end
self:stage("stage_dark", 0, seg(f, 0, 30))
local lit = seg(f, LIGHT_AT, GLOW_AT - LIGHT_AT)
if lit > 0 then self:stage("stage_lit", 0, math.floor(lit * 10) / 10) end
if f >= GLOW_AT then self:stage("stage_glow", 0, seg(f, GLOW_AT, 4)) end
end
-- Don and Katsu hop up in front of the stage and bounce while the boards are up
function AnnounceScene:draw_chars()
local f = self.f
if f < CHARS_AT or f >= RISE_AT + 30 then return end
local e = f - CHARS_AT
local y = lerp(260, 0, ease_out(seg(e, 0, 14))) + 260 * ease_in(seg(f, RISE_AT, 30))
local hop = -10 * math.abs(math.sin(math.pi * e / 30))
self:tl("don", 68, 250 + y + hop)
self:tl("katsu", 330, 250 + y - 10 * math.abs(math.sin(math.pi * (e + 15) / 30)))
end
-- 新曲発表だドーン!: pops at the drum hit, flies off when the first board drops in
function AnnounceScene:draw_announce()
local e = self.f - ANNOUNCE_AT
if e < 0 or self.f >= BOARD_AT + 20 then return end
local s = e < 12 and lerp(0.17, 1.1, ease_out(e / 12)) or lerp(1.1, 1, seg(e, 12, 8))
local up = -400 * ease_in(seg(self.f, BOARD_AT, 20))
self:ctr("burst_star", 320, 182.1 + up, { s = s })
self:ctr("burst_text", 320, 182.1 + up, { s = s })
end
-- one lantern board with a title, dropping in from the top; the second pushes the first off to the left
function AnnounceScene:draw_boards()
local f = self.f
if f < BOARD_AT or f >= RISE_AT + 20 then return end
local away = -400 * ease_in(seg(f, RISE_AT, 20))
for n, at in ipairs({ BOARD_AT, BOARD2_AT }) do
local e = f - at
if e >= 0 and self.songs[n] then
local y = lerp(-180, BOARD_Y, ease_out(seg(e, 0, 16)))
local x = BOARD_X
if n == 1 then x = x - 700 * ease_in(seg(f, BOARD2_AT, 20)) end
self:tl("board", x, y + away)
self:tl("board_frame", x, y + away, { blend = "additive" })
self:title(n, x + 188, y + 84 + away, 330, 1, 1)
end
end
end
function AnnounceScene:draw_firework()
local f = self.f
local e = f - RISE_AT
if e >= 20 and f < BURSTS[1] then
local p = seg(e, 20, BURSTS[1] - RISE_AT - 20)
local y = lerp(480, 150, ease_out(p))
self:ctr("trail", 320, y + 40, { fade = 1 - p * 0.5 })
self:ctr("spark", 320, y, { s = 0.6 })
end
for k, at in ipairs(BURSTS) do
local b = f - at
if b >= 0 and b < 110 then
for i, spot in ipairs({ { 320, 160, 0 }, { 160, 220, 12 }, { 480, 230, 24 } }) do
local c = b - spot[3]
if c >= 0 and c < 86 then
local s = lerp(0.2, 1.4, ease_out(seg(c, 0, 30)))
self:ctr("firework", spot[1], spot[2], { frame = (i + k) % 3, s = s, fade = 1 - seg(c, 56, 30) })
end
end
end
end
-- the titles burst out of the first firework and hang in the sky
local b = f - BURSTS[1]
if b >= 0 then
local p = ease_out(seg(b, 0, 40))
local fade = 1 - seg(f, END_AT - 40, 40)
self:title(1, lerp(320, 260, p), lerp(160, 150, p), 520, lerp(0.3, 1.15, p), fade)
if self.songs[2] then self:title(2, lerp(320, 380, p), lerp(160, 290, p), 520, lerp(0.3, 1.15, p), fade) end
end
end
function AnnounceScene:draw()
if not self.songs then return end
self:draw_stage()
self:draw_chars()
self:draw_boards()
self:draw_announce()
self:draw_firework()
self:tl("header_bar", 0, 0)
self:tl("header", 10, 6)
local fade = seg(self.f, END_AT, FADE_LEN)
if fade > 0 then
tex.draw_rect(0, 0, tex.get_screen_width(), tex.get_screen_height(), 0, 0, 0, math.floor(fade * 255))
end
end