193 lines
7.1 KiB
Lua
193 lines
7.1 KiB
Lua
local WHITE, BLACK = { 255, 255, 255, 255 }, { 0, 0, 0, 255 }
|
|
|
|
local MAX_SONGS = 8
|
|
local WAIT_SONGS_MS = 1500
|
|
local INTRO_MS = 600
|
|
local OUTRO_MS = 400
|
|
local SLOT_STAGGER_MS = 150
|
|
local SONG_MS = 3000
|
|
local SLOTS = { { 146, 648 }, { 958, 648 }, { 146, 804 }, { 958, 804 } }
|
|
local TITLE_SIZE, TITLE_MAX_W = 44, 700
|
|
local BANNER_SIZE, BANNER_MAX_W = 100, 1000
|
|
local GENRE_KEYS = { "children", "game", "anime", "namco", "pop", "vocaloid", "variety", "classic" }
|
|
|
|
-- Hiroba genre folder name -> frame of slot / genre_plate
|
|
local GENRES = {
|
|
{ "vocaloid", 5 }, { "variety", 6 }, { "classic", 7 }, { "anime", 2 }, { "namco", 3 }, { "game", 1 },
|
|
{ "child", 0 }, { "folk", 0 }, { "pop", 4 },
|
|
}
|
|
|
|
-- name, start x, y, drift px/s (x, y), spin deg/s, half size
|
|
local PARTICLES = {
|
|
{ "gem_purple_fan", 430, 80, 14, 22, 18, 96 }, { "blossom_pink_face", 880, 20, -10, 18, -12, 96 },
|
|
{ "leaf_green", 700, 0, 8, 26, 10, 96 }, { "gem_green", 1560, 120, -16, 20, 24, 96 },
|
|
{ "blossom_blue", 1700, 700, -12, -14, 9, 96 }, { "gem_teal", 60, 560, 12, -16, -20, 96 },
|
|
{ "blossom_pink_flower", 1280, 880, -9, -20, 14, 96 }, { "gem_green_large", 20, 900, 18, -12, -16, 96 },
|
|
{ "gem_purple_flower", 1000, 900, -6, -18, 12, 96 }, { "leaf_green_2", 1850, 300, -14, 16, 18, 96 },
|
|
{ "gem_teal_2", 520, 960, 10, -22, -14, 96 }, { "blossom_pink_small", 1380, 40, -8, 24, 20, 96 },
|
|
{ "gem_teal_small", 250, 330, 16, 12, 22, 96 }, { "gem_green_2", 1090, 400, -10, 14, -18, 96 },
|
|
{ "leaf_teal_blur", 800, 760, 12, -10, 8, 96 }, { "gem_teal_tiny", 1500, 580, -12, -12, 16, 96 },
|
|
}
|
|
|
|
local SPARKLES = {
|
|
{ 40, 240, 0 }, { 300, 290, 700 }, { 1620, 310, 300 }, { 1810, 250, 1100 }, { 190, 560, 500 }, { 1690, 470, 900 },
|
|
}
|
|
|
|
local function genre_frame(name)
|
|
name = (name or ""):lower()
|
|
for _, g in ipairs(GENRES) do
|
|
if name:find(g[1], 1, true) then
|
|
return g[2], true
|
|
end
|
|
end
|
|
return 5, false
|
|
end
|
|
|
|
local function texture(name)
|
|
return tex.get_texture("title/music_intro/" .. name)
|
|
end
|
|
|
|
local function wrap(v, lo, hi)
|
|
local span = hi - lo
|
|
return (v - lo) % span + lo
|
|
end
|
|
|
|
AttractScene = {}
|
|
AttractScene.__index = AttractScene
|
|
|
|
function AttractScene.new()
|
|
local self = setmetatable({}, AttractScene)
|
|
self.start_ms = tex.get_current_ms()
|
|
self.t = 0
|
|
self.songs = nil
|
|
self.finished = false
|
|
|
|
self.t_background = texture("background")
|
|
self.t_banner = texture("banner")
|
|
self.t_panel = texture("panel")
|
|
self.t_slot = texture("slot")
|
|
self.t_plate = texture("genre_plate")
|
|
self.t_slot_label = texture("slot_label")
|
|
self.t_don_red = texture("don_red")
|
|
self.t_don_blue = texture("don_blue")
|
|
self.t_sparkle = texture("sparkle")
|
|
for _, p in ipairs(PARTICLES) do
|
|
p.tex = texture(p[1])
|
|
end
|
|
self.genre_names = {}
|
|
for i, key in ipairs(GENRE_KEYS) do
|
|
self.genre_names[i - 1] = tex.skin_text("attract_genre_" .. key)
|
|
end
|
|
self.more_text = text.create_raw_text(tex.skin_text("attract_music_intro_more"), 42, WHITE, BLACK, false,
|
|
5.0 / tex.get_screen_scale())
|
|
|
|
return self
|
|
end
|
|
|
|
function AttractScene:load_songs()
|
|
local songs = network.popular_songs()
|
|
if not songs or #songs == 0 then
|
|
return
|
|
end
|
|
self.songs = {}
|
|
for i = 1, math.min(#songs, MAX_SONGS) do
|
|
local song = songs[i]
|
|
local genre, known = genre_frame(song.genre)
|
|
local name = known and self.genre_names[genre] or song.genre or ""
|
|
self.songs[i] = {
|
|
genre = genre,
|
|
title = text.create_raw_text(song.title, TITLE_SIZE, WHITE, BLACK, false, 3.0 / tex.get_screen_scale()),
|
|
banner = text.create_raw_text(song.title, BANNER_SIZE, WHITE, BLACK, false, 6.0 / tex.get_screen_scale()),
|
|
genre_text = text.create_raw_text(name, 40, WHITE, BLACK, false, 0),
|
|
label_text = text.create_raw_text(name, 18, WHITE, BLACK, false, 0),
|
|
}
|
|
end
|
|
self.songs_at = self.t
|
|
self.total_ms = math.max(#self.songs, 2) * SONG_MS
|
|
end
|
|
|
|
function AttractScene:update(current_ms)
|
|
self.t = current_ms - self.start_ms
|
|
if not self.songs then
|
|
self:load_songs()
|
|
if not self.songs and self.t >= WAIT_SONGS_MS then
|
|
self.finished = true
|
|
end
|
|
return
|
|
end
|
|
if self.t - self.songs_at >= self.total_ms then
|
|
self.finished = true
|
|
end
|
|
end
|
|
|
|
local function draw_centered_text(obj, cx, cy, max_w, fade)
|
|
local s = math.min(1, max_w / obj.width)
|
|
local w, h = obj.width * s, obj.height * s
|
|
obj:draw({ x = cx - w / 2, y = cy - h / 2, x2 = w - obj.width, y2 = h - obj.height, fade = fade })
|
|
end
|
|
|
|
function AttractScene:draw_particles(t)
|
|
for _, p in ipairs(PARTICLES) do
|
|
local x = wrap(p[2] + p[4] * t / 1000, -200, 2120)
|
|
local y = wrap(p[3] + p[5] * t / 1000, -200, 1280)
|
|
tex.draw_texture(p.tex, { x = x - p[7], y = y - 80, origin = { p[7], 80 }, rotation = p[6] * t / 1000 })
|
|
end
|
|
end
|
|
|
|
function AttractScene:draw_sparkles(t)
|
|
for _, s in ipairs(SPARKLES) do
|
|
local phase = ((t + s[3]) % 1400) / 1400
|
|
local a = math.sin(phase * math.pi)
|
|
tex.draw_texture(self.t_sparkle, {
|
|
x = s[1] - 64, y = s[2] - 64, scale = 0.4 + 0.6 * a, center = true, fade = a,
|
|
})
|
|
end
|
|
end
|
|
|
|
function AttractScene:draw()
|
|
tex.draw_texture(self.t_background)
|
|
if not self.songs then
|
|
return
|
|
end
|
|
local t = self.t - self.songs_at
|
|
local fade = math.min(1, t / INTRO_MS) * math.min(1, (self.total_ms - t) / OUTRO_MS)
|
|
|
|
self:draw_particles(t)
|
|
self:draw_sparkles(t)
|
|
|
|
tex.draw_texture(self.t_banner, { fade = fade })
|
|
|
|
local bob = math.sin(t / 260) * 10
|
|
tex.draw_texture(self.t_don_red, { y = bob, fade = fade })
|
|
tex.draw_texture(self.t_don_blue, { y = -bob, fade = fade })
|
|
|
|
tex.draw_texture(self.t_panel, { fade = fade })
|
|
local count = #self.songs
|
|
local highlight = math.floor(t / SONG_MS) % count + 1
|
|
local current = self.songs[highlight]
|
|
local swap = math.min(1, (t % SONG_MS) / 250)
|
|
draw_centered_text(current.banner, 960, 360, BANNER_MAX_W, fade * swap)
|
|
draw_centered_text(self.more_text, 960, 627, 900, fade)
|
|
|
|
for i = 1, math.min(count - 1, #SLOTS) do
|
|
local song = self.songs[(highlight + i - 1) % count + 1]
|
|
local pos = SLOTS[i]
|
|
local slot_t = t - INTRO_MS * 0.5 - (i - 1) * SLOT_STAGGER_MS
|
|
local a = math.max(0, math.min(1, slot_t / 300)) * fade
|
|
local dx, dy = pos[1] - SLOTS[1][1], pos[2] - SLOTS[1][2] + (1 - math.min(1, math.max(0, slot_t / 300))) * 40
|
|
tex.draw_texture(self.t_slot, { frame = song.genre, x = dx, y = dy, fade = a })
|
|
tex.draw_texture(self.t_slot_label, { frame = song.genre, x = dx, y = dy, fade = a })
|
|
draw_centered_text(song.title, pos[1] + 408, pos[2] + 78 + dy - (pos[2] - SLOTS[1][2]), TITLE_MAX_W, a)
|
|
draw_centered_text(song.label_text, pos[1] + 588 + 108, pos[2] + 120 + 12 + dy - (pos[2] - SLOTS[1][2]), 190, a)
|
|
end
|
|
|
|
tex.draw_texture(self.t_plate, { frame = current.genre, fade = fade })
|
|
draw_centered_text(current.genre_text, 1404 + 236, 520 + 36, 420, fade)
|
|
end
|
|
|
|
function AttractScene:is_finished()
|
|
return self.finished
|
|
end
|
|
|
|
function AttractScene:close() end
|