528 lines
25 KiB
Lua
528 lines
25 KiB
Lua
AIIntro = {}
|
|
AIIntro.__index = AIIntro
|
|
|
|
local S = tex.get_screen_scale()
|
|
local F = 1000 / 60
|
|
local LEFT, RIGHT, DECIDE = 1, 2, 3
|
|
local SKIP_WAIT, FORCED_SKIP = 30, 1200
|
|
local INPUT_WAIT = 60
|
|
local OUT_FRAMES = 30
|
|
local OX, OY = 640, 324
|
|
local FONT = "FOT-Seurat_Pro_B.otf"
|
|
local WHITE = { 255, 255, 255, 255 }
|
|
local INK = { 24, 24, 24, 255 }
|
|
local LINE_X, LINE_Y, LINE_GAP, LINE_WIDTH = 640, 553, 54, 1000
|
|
local ICON_SCALE = 2
|
|
local STYLES = {
|
|
line = { color = INK, em = { color = { 40, 170, 110, 255 } } },
|
|
caption = { color = INK, outline = WHITE, thickness = 5,
|
|
em = { color = { 255, 160, 0, 255 }, outline = { 90, 30, 0, 255 }, thickness = 5 } },
|
|
bubble = { color = INK, em = { color = { 255, 140, 0, 255 }, outline = { 90, 30, 0, 255 }, thickness = 3 } },
|
|
bubble_blue = { color = INK, em = { color = { 40, 150, 255, 255 }, outline = { 10, 30, 90, 255 }, thickness = 3 } },
|
|
}
|
|
|
|
local function clamp01(v) return math.max(0, math.min(1, v)) end
|
|
local function ramp(f, at, len) return clamp01((f - at) / len) end
|
|
local function lerp(a, b, u) return a + (b - a) * u end
|
|
|
|
-- rows: { from, to, scale_from, scale_to, y_from, y_to }
|
|
local function pick(t)
|
|
local lang = tex.language()
|
|
return t[lang] or (lang:find("^zh") and t["zh-tw"]) or t.en or t.ja or ""
|
|
end
|
|
|
|
local function make_text(str, size, style)
|
|
local color = style.color
|
|
return text.create_raw_text(str, math.floor(size * S), color, style.outline or color, false, style.thickness or 0,
|
|
0, 1, FONT)
|
|
end
|
|
|
|
-- runs of plain text, *emphasis* and {win} icons; widths in screen px
|
|
local function make_row(str, size, style)
|
|
local row = { runs = {}, width = 0 }
|
|
local icon_w = size * ICON_SCALE * S
|
|
local i, em = 1, false
|
|
while i <= #str do
|
|
local a = str:find("[*{]", i)
|
|
local plain = str:sub(i, (a or #str + 1) - 1)
|
|
if plain ~= "" then
|
|
local t = make_text(plain, size, em and style.em or style)
|
|
row.runs[#row.runs + 1] = { text = t }
|
|
row.width = row.width + t.width
|
|
end
|
|
if not a then break end
|
|
if str:sub(a, a) == "*" then
|
|
em, i = not em, a + 1
|
|
else
|
|
row.runs[#row.runs + 1] = { icon = icon_w }
|
|
row.width = row.width + icon_w
|
|
i = (str:find("}", a, true) or #str) + 1
|
|
end
|
|
end
|
|
return row
|
|
end
|
|
|
|
-- one long line splits in two at the space (or character) nearest its middle
|
|
local function wrap(str)
|
|
local chars = {}
|
|
for ch in str:gmatch("[%z\1-\127\194-\244][\128-\191]*") do chars[#chars + 1] = ch end
|
|
local n = #chars
|
|
if str:find("\n", 1, true) or n <= (str:find(" ", 1, true) and 40 or 26) then return str end
|
|
local mid, best, cut = n / 2, nil, nil
|
|
for i, ch in ipairs(chars) do
|
|
if ch == " " and (not best or math.abs(i - mid) < best) then best, cut = math.abs(i - mid), i end
|
|
end
|
|
cut = cut or math.floor(mid) + 1
|
|
local head, tail = {}, {}
|
|
for i, ch in ipairs(chars) do
|
|
if i < cut then head[#head + 1] = ch elseif i > cut or ch ~= " " then tail[#tail + 1] = ch end
|
|
end
|
|
return table.concat(head) .. "\n" .. table.concat(tail)
|
|
end
|
|
|
|
local function make_block(str, size, style, width)
|
|
local rows
|
|
repeat
|
|
rows = {}
|
|
local widest = 0
|
|
for line in (str .. "\n"):gmatch("(.-)\n") do
|
|
rows[#rows + 1] = make_row(line, size, style)
|
|
widest = math.max(widest, rows[#rows].width)
|
|
end
|
|
size = size - 1
|
|
until widest <= width * S or size < 12
|
|
return rows
|
|
end
|
|
|
|
local function track(rows, f)
|
|
if rows then
|
|
for _, r in ipairs(rows) do
|
|
if f <= r[2] then
|
|
local u = r[2] > r[1] and clamp01((f - r[1]) / (r[2] - r[1])) or 1
|
|
return lerp(r[3], r[4], u), lerp(r[5], r[6], u)
|
|
end
|
|
end
|
|
end
|
|
return 1, 0
|
|
end
|
|
|
|
local DON_HOP = {
|
|
{ 0, 3, 1, 0.988, 0, 2 }, { 4, 6, 0.992, 1, 1.3, 0 }, { 7, 16, 1, 1, -7.8, -78 }, { 17, 27, 1, 1, -70.9, 0 },
|
|
{ 28, 30, 0.996, 0.988, 0.65, 2 }, { 31, 33, 0.992, 1, 1.3, 0 },
|
|
}
|
|
local DON_JUMP = { { 0, 2, 1, 0.987, 0, 4 }, { 3, 12, 0.98, 0.998, 6, -140 }, { 13, 23, 1, 1, -156, -14 } }
|
|
local AIDON_HOP = {
|
|
{ 0, 3, 1, 0.965, 0, 7 }, { 4, 9, 0.983, 1.075, -18, -144 }, { 10, 15, 1.057, 0.965, -119, 7 },
|
|
{ 16, 19, 0.974, 1, 5, 0 },
|
|
}
|
|
local AIDON_TRIPLE = {
|
|
{ 0, 3, 1, 0.965, 0, 7 }, { 4, 9, 0.983, 1.075, -18, -144 }, { 10, 15, 1.057, 0.965, -119, 7 },
|
|
{ 16, 25, 0.974, 1.075, 5, -144 }, { 26, 31, 1.057, 0.965, -119, 7 },
|
|
{ 32, 39, 0.974, 1.075, 5, -144 }, { 40, 45, 1.057, 0.965, -119, 7 }, { 46, 49, 0.974, 1, 5, 0 },
|
|
}
|
|
local MAKINA_HOP = { { 0, 9, 1, 1, 0, -30 }, { 10, 19, 1, 1, -27, 0 } }
|
|
local MAKINA_DOUBLE = {
|
|
{ 0, 9, 1, 1, 0, -30 }, { 10, 19, 1, 1, -27, 0 }, { 20, 28, 1, 1, -3, -30 }, { 29, 38, 1, 1, -27, 0 },
|
|
}
|
|
local AIDON_BIG_JUMP = {
|
|
{ 0, 79, 1, 1, 0, 0 }, { 80, 83, 0.977, 0.906, -0.25, -1 }, { 84, 87, 0.93, 1, -0.8, 0 },
|
|
{ 88, 100, 1.005, 1.07, -10, -132 }, { 101, 114, 1.065, 1, -122.5, 0 },
|
|
{ 115, 118, 0.977, 0.906, -0.25, -1 }, { 119, 121, 0.938, 1, -0.65, 0 },
|
|
}
|
|
|
|
-- text: { ja = ..., en = ... }, rows split on \n, *name* in green
|
|
local PHRASES = {
|
|
{ bubble = "bubble_don", se = "se_absurd", don = { "don_idle", DON_HOP }, bgm = true,
|
|
text = { ja = "むにゃ・・・ここはどこカッ?", en = "Huh...? Where am I?",
|
|
["zh-tw"] = "唔嗯……這裡是哪裡咔?", ko = "음냐...여기는 어딘갓?" } },
|
|
{ bubble = "bubble_aidon", aidon = AIDON_HOP,
|
|
text = { ja = "目が覚めたようだゾ", en = "Looks like he's awake.",
|
|
["zh-tw"] = "你 醒 來 了 啊", ko = "정신이 든 듯하군" } },
|
|
{ bubble = "bubble_makina", se = "se_norm", vo = "vo_makina_hello", makina = { "open", MAKINA_HOP },
|
|
text = { ja = "は、はじめまして!わたしは「まきな」\n未来からきた、ドンだー研究者です。", en = "N-Nice to meet you! My name is Machina. I'm a Donder\nresearcher from the future.",
|
|
["zh-tw"] = "你、你好!我叫「牧菜」\n是來自未來的鼓眾研究者。", ko = "처, 처음 뵙겠습니다! 저는 '마키나'\n미래에서 온 동더 연구자입니다." } },
|
|
{ bubble = "bubble_don", se = "se_absurd",
|
|
text = { ja = "未来?ドンだー研究者?\nこれは夢カッ?二度寝だドン…", en = "A Donder researcher? From the future? This has gotta be\na dream. I'm going back to sleep.",
|
|
["zh-tw"] = "來自未來?鼓眾研究者?\n我還在作夢咔?來睡個回頭覺咚……", ko = "미래? 동더 연구자?\n이거 꿈인갓? 다시 자야겠다쿵…" } },
|
|
{ bubble = "bubble_makina", se = "se_norm", makina = { "smile", MAKINA_DOUBLE },
|
|
text = { ja = "ね、寝ないでください~!\n夢ではないのです…!", en = "P-Please don't! You're not dreaming!",
|
|
["zh-tw"] = "請、請不要睡呀~!\n你不是在作夢……!", ko = "자, 잠들지 마세요~!\n꿈이 아닙니다…!" } },
|
|
{ bubble = "bubble_makina", se = "se_norm", makina = { "blink" },
|
|
text = { ja = "わたし達は、\n2765年からタイムトラベルしてきました。", en = "We've time-traveled here from the year 2765.",
|
|
["zh-tw"] = "我們是從2765年\n穿越時空來到這裡的。", ko = "저희들은\n2765년에서 시간여행을 왔습니다." } },
|
|
{ bubble = "bubble_makina", se = "se_norm",
|
|
text = { ja = "いきなりですけど…", en = "And while this may seem a bit sudden...",
|
|
["zh-tw"] = "雖然很突然……", ko = "뜬금없지만…" } },
|
|
{ bubble = "bubble_makina", se = "se_norm",
|
|
text = { ja = "この「AIどん」と、演奏勝負をして\n最強のドンだーを目指してみませんか!", en = "Won't you face off with AI-DON here and aim to be the\nstrongest Donder?!",
|
|
["zh-tw"] = "但你要不要和這個「AI咚」比賽演奏\n目標成為最強的鼓眾呢!?", ko = "이 ''AI동'과의 연주 대결로\n최강의 동더를 목표로 삼지 않으시겠습니까?" } },
|
|
{ bubble = "bubble_don", se = "se_don_jump", don = { "don_cheer", DON_JUMP },
|
|
text = { ja = "最強・・・?ボクがなれるのカッ!?", en = "The strongest? Me?! Am I capable of doing that?!",
|
|
["zh-tw"] = "最強……?我成為得了咔!?", ko = "최강...? 내가 될 수 있는갓!?" } },
|
|
{ bubble = "bubble_makina", se = "se_norm", don = { "don_idle" }, makina = { "glad", MAKINA_HOP },
|
|
text = { ja = "なれますよ!!!", en = "You can if you try!",
|
|
["zh-tw"] = "成為得了哦!!!", ko = "될 수 있습니다!!!" } },
|
|
{ bubble = "bubble_makina", se = "se_norm",
|
|
text = { ja = "わたしが開発した「AIどん」は、\nバトルするたび学習していくので、", en = "I've programmed AI-DON to learn from each battle...",
|
|
["zh-tw"] = "我開發出來的「AI咚」\n會將每次的對戰過程學習下來", ko = "제가 개발한 'AI동'은\n배틀할수록 학습을 해나가므로," } },
|
|
{ bubble = "bubble_makina", se = "se_norm",
|
|
text = { ja = "つねに勝つか負けるかの\n熱いバトルが楽しめちゃうんです!", en = "...So that you're always competing head-to-head!",
|
|
["zh-tw"] = "所以你可以時常享受\n難分勝負的炙熱對戰!", ko = "언제든 막상막하의\n열띤 배틀을 즐길 수 있습니다!" } },
|
|
{ bubble = "bubble_don", se = "se_norm", don = { "don_cheer", DON_JUMP },
|
|
text = { ja = "勝つか負けるかの熱いバトル…\nやるしかないドーン!", en = "Head-to-head, you say? That sounds like my kind of battle!",
|
|
["zh-tw"] = "難分勝負的炙熱對戰……\n那我只好放手一試了咚!", ko = "막상막하의 열띤 배틀…\n할 수 밖에 없다쿵!" } },
|
|
{ bubble = "bubble_aidon", se = "se_norm", vo = "vo_aidon_thanks", aidon = AIDON_TRIPLE,
|
|
text = { ja = "ヨロシクたのム", en = "May the best Donder win.",
|
|
["zh-tw"] = "請 多 指 教", ko = "잘 부탁한다" } },
|
|
{ bubble = "bubble_makina", se = "se_norm", vo = "vo_makina_thanks", makina = { "glad", MAKINA_HOP },
|
|
stop_bgm = true,
|
|
text = { ja = "では早速いってみましょう~っ!\nこれからよろしくおねがいしますねっ♪", en = "Well then, let's get this battle underway!",
|
|
["zh-tw"] = "那麼事不宜遲,立即開始吧~!\n今後請你多多指教囉♪", ko = "그럼 어서 가봅시다~앗!\n앞으로 잘 부탁드리겠습니닷♪" } },
|
|
}
|
|
|
|
-- the arcade's ai_tutorial_information_1..7; {bar} pages show the section bar with its labels
|
|
local PAGES = {
|
|
{ text = { ja = "AIバトル演奏のルールを説明します!", en = "Allow me to explain the AI battle rules!",
|
|
["zh-tw"] = "由我來說明AI對戰的規則!", ko = "AI 배틀 연주의 룰을 설명하겠습니다!" } },
|
|
{ teacher = "talk", text = { ja = "「良」を出すほど、優勢になります!", en = "The more GOODs you get, the more you gain the upper hand!",
|
|
["zh-tw"] = "對戰中只要打出越多的「良」就越佔優勢!", ko = "'얼쑤'가 나올수록 유리해집니다!" } },
|
|
{ teacher = "talk", text = { ja = "でも、「不可」を出すほど、 劣勢になっちゃいます…", en = "But you'll have less of an advantage the more BADs you get!",
|
|
["zh-tw"] = "不過要是打出越多「不可」,則會陷入劣勢……", ko = "하지만 '에구'가 나올수록 불리해집니다…" } },
|
|
{ bar = true, text = { ja = "1曲を3つの区間にわけます!\n(5つのときもあります)", en = "Each song is divided into three sections! (Some are divided into five.)",
|
|
["zh-tw"] = "一首歌曲會被分成3個區間!\n(偶爾會出現5個區間)", ko = "1곡은 3개의 구간으로 나뉩니다!\n(5개일 때도 있습니다)" } },
|
|
{ bar = true, teacher = "talk", text = { ja = "区間のおわりで優勢だと、「勝利バッジ」がもらえます!", en = "If you have the upper hand at the end of a section, you'll get a \"win badge\"!",
|
|
["zh-tw"] = "在區間的最後若居優勢的話,就可獲得「勝利徽章」!", ko = "구간의 끝부분에서 우세한 상황이면 '승리 배지'를 받습니다!" } },
|
|
{ text = { ja = "「勝利バッジ」の多かったほうが、バトルの勝者です!", en = "The player with the greater number of win badges is the winner!",
|
|
["zh-tw"] = "而獲得較多「勝利徽章」的一方,就是對戰的優勝者!", ko = "'승리 배지'가 많은 쪽이 배틀의 승자입니다!" } },
|
|
{ teacher = "happy", text = { ja = "「AIどん」との、勝つか負けるかの熱いバトルを楽しみましょう!", en = "Test your skills in a heated battle against AI-DON!",
|
|
["zh-tw"] = "與「AI咚」一同享樂\n難分勝負的炙熱對戰吧!", ko = "'AI동'과 막상막하 열띤 배틀을 즐겨봐요!" } },
|
|
}
|
|
local LABELS = { { ja = "曲のはじまり", en = "Song Start",
|
|
["zh-tw"] = "歌曲開頭", ko = "곡의 시작" }, { ja = "曲のおわり", en = "Song End",
|
|
["zh-tw"] = "歌曲結尾", ko = "곡의 끝" }, { ja = "1区間目", en = "First Section",
|
|
["zh-tw"] = "第1個區間", ko = "1구간째" }, { ja = "2区間目", en = "Second Section",
|
|
["zh-tw"] = "第2個區間", ko = "2구간째" }, { ja = "3区間目", en = "Third Section",
|
|
["zh-tw"] = "第3個區間", ko = "3구간째" } }
|
|
|
|
local PAGE_FADE = 15
|
|
local LAST_PAGE = #PAGES - 1
|
|
|
|
function AIIntro.new()
|
|
local self = setmetatable({}, AIIntro)
|
|
tex.load_folder("song_select", "ai_intro")
|
|
tex.load_folder("song_select", "ai_intro_story")
|
|
tex.load_folder("song_select", "ai_intro_tutorial")
|
|
self.ids, self.sizes = {}, {}
|
|
self.draw_background = require("song_select/ai_background").new()
|
|
self.hint_page = text.create_text("ai_intro_hint_page", { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 5, 2)
|
|
self.hint_end = text.create_text("ai_intro_hint_end", { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 5, 2)
|
|
self.icon_h = tex.get_texture_info("ai_intro", "icon_win").height
|
|
local latin = tex.language() ~= "ja" and tex.language() ~= "zh"
|
|
self.lines = {}
|
|
for i, p in ipairs(PHRASES) do
|
|
self.lines[i] = make_block(pick(p.text), latin and 32 or 38, STYLES.line, LINE_WIDTH)
|
|
end
|
|
self.pages = {}
|
|
for i, p in ipairs(PAGES) do
|
|
self.pages[i] = make_block(wrap(pick(p.text)), (p.bar and 28) or (latin and 32 or 38), STYLES.line, 880)
|
|
end
|
|
self.labels = {}
|
|
for i, l in ipairs(LABELS) do
|
|
self.labels[i] = make_block(pick(l), 26, STYLES.line, 360)
|
|
end
|
|
self.now = tex.get_current_ms()
|
|
self.mode = "story"
|
|
self.tut = {}
|
|
self.story_t0 = self.now
|
|
self.don = { "don_idle" }
|
|
self:show_phrase(1)
|
|
return self
|
|
end
|
|
|
|
function AIIntro:frame_since(ms)
|
|
return (self.now - ms) / F
|
|
end
|
|
|
|
function AIIntro:play(name, preset)
|
|
name = "ai_intro_" .. name
|
|
if audio.has_sound(name) then audio.play_sound(name, preset or (name:find("_vo_") and "voice" or "sound")) end
|
|
end
|
|
|
|
function AIIntro:show_phrase(n)
|
|
local p = PHRASES[n]
|
|
self.phrase, self.phrase_t0 = n, self.now
|
|
if p.don then self.don, self.don_t0 = p.don, self.now end
|
|
if p.aidon then self.aidon, self.aidon_t0 = p.aidon, self.now end
|
|
if p.makina then self.makina, self.makina_t0 = p.makina, self.now end
|
|
if p.se then self:play(p.se) end
|
|
if p.vo then self:play(p.vo) end
|
|
if p.bgm then audio.play_sound("ai_intro_story_bgm", "music", true) end
|
|
if p.stop_bgm then audio.stop_sound("ai_intro_story_bgm") end
|
|
end
|
|
|
|
function AIIntro:start_tutorial()
|
|
self.mode = "tutorial"
|
|
self.tutorial_t0 = self.now
|
|
self:play("vo_rule")
|
|
audio.play_sound("ai_intro_tutorial_bgm", "music", true)
|
|
self:show_page(0)
|
|
end
|
|
|
|
function AIIntro:show_page(n)
|
|
self.page, self.page_t0 = n, self.now
|
|
end
|
|
|
|
function AIIntro:page_frame()
|
|
return math.min(self:frame_since(self.page_t0), PAGE_FADE)
|
|
end
|
|
|
|
function AIIntro:next_phrase()
|
|
if self.phrase < #PHRASES then
|
|
self:show_phrase(self.phrase + 1)
|
|
return
|
|
end
|
|
audio.play_sound("don", "sound")
|
|
self:start_tutorial()
|
|
end
|
|
|
|
function AIIntro:update(current_ms)
|
|
self.now = current_ms
|
|
if self.mode == "story" then
|
|
if self:frame_since(self.phrase_t0) >= FORCED_SKIP then self:next_phrase() end
|
|
end
|
|
end
|
|
|
|
function AIIntro:input_story(action)
|
|
if self:frame_since(self.phrase_t0) < SKIP_WAIT then return end
|
|
local last = self.phrase == #PHRASES
|
|
if (action == DECIDE) == last then self:next_phrase() end
|
|
end
|
|
|
|
function AIIntro:input_tutorial(action)
|
|
if self:frame_since(self.tutorial_t0) < INPUT_WAIT then return end
|
|
if action == DECIDE then
|
|
if self.page == LAST_PAGE then
|
|
audio.play_sound("don", "sound")
|
|
audio.stop_sound("ai_intro_tutorial_bgm")
|
|
self.mode, self.out_t0 = "out", self.now
|
|
end
|
|
return
|
|
end
|
|
local ended = self:page_frame() >= PAGE_FADE
|
|
if action == LEFT and self.page == 0 then return end
|
|
if action == RIGHT and self.page == LAST_PAGE and ended then return end
|
|
audio.play_sound("kat", "sound")
|
|
if not ended then
|
|
self.page_t0 = self.now - PAGE_FADE * F -- first hit finishes the page's fade
|
|
else
|
|
self:show_page(self.page + (action == LEFT and -1 or 1))
|
|
end
|
|
end
|
|
|
|
function AIIntro:input(action)
|
|
if self.mode == "story" then
|
|
self:input_story(action)
|
|
elseif self.mode == "tutorial" then
|
|
self:input_tutorial(action)
|
|
end
|
|
end
|
|
|
|
function AIIntro:is_done()
|
|
return self.mode == "out" and self:frame_since(self.out_t0) >= OUT_FRAMES
|
|
end
|
|
|
|
function AIIntro:put(key, cx, cy, o)
|
|
o = o or {}
|
|
local id = self.ids[key]
|
|
if id == nil then
|
|
id = tex.get_texture("song_select/ai_intro/" .. key)
|
|
self.ids[key] = id
|
|
self.sizes[key] = tex.get_texture_info("ai_intro", key)
|
|
end
|
|
local info = self.sizes[key]
|
|
if not info then return end
|
|
local sx, sy = o.sx or o.s or 1, o.sy or o.s or 1
|
|
local w, h = info.width * S, info.height * S
|
|
tex.draw_texture(id, {
|
|
x = cx * S, y = cy * S,
|
|
x2 = w * (sx - 1), y2 = h * (sy - 1),
|
|
origin = { w * sx * 0.5, h * sy * 0.5 },
|
|
fade = o.fade or 1,
|
|
frame = o.frame or 0,
|
|
mirror = o.mirror,
|
|
blend = o.add and "additive" or nil,
|
|
})
|
|
end
|
|
|
|
-- the Nijiiro story art is native 1920 px: sizes are not scaled, x and y stay on the 1280 grid
|
|
function AIIntro:put_native(key, cx, cy, o)
|
|
o = o or {}
|
|
local id = self.ids["story/" .. key]
|
|
if id == nil then
|
|
id = tex.get_texture("song_select/ai_intro_story/" .. key)
|
|
self.ids["story/" .. key] = id
|
|
self.sizes["story/" .. key] = tex.get_texture_info("ai_intro_story", key)
|
|
end
|
|
local info = self.sizes["story/" .. key]
|
|
if not info then return end
|
|
local sx, sy = o.sx or o.s or 1, o.sy or o.s or 1
|
|
local w, h = info.width, info.height
|
|
tex.draw_texture(id, {
|
|
x = cx * S, y = cy * S,
|
|
x2 = w * (sx - 1), y2 = h * (sy - 1),
|
|
origin = { w * sx * 0.5, h * sy * 0.5 },
|
|
fade = o.fade or 1,
|
|
})
|
|
end
|
|
|
|
function AIIntro:board(key, x, y, o)
|
|
self:put(key, OX + x, OY + y, o)
|
|
end
|
|
|
|
function AIIntro:draw_rows(rows, cx, cy, gap, o)
|
|
o = o or {}
|
|
local top = cy - (#rows - 1) * gap / 2
|
|
for i, row in ipairs(rows) do
|
|
local x = cx * S - row.width / 2
|
|
if o.align == "left" then x = cx * S elseif o.align == "right" then x = cx * S - row.width end
|
|
local y = top + (i - 1) * gap
|
|
for _, run in ipairs(row.runs) do
|
|
if run.icon then
|
|
local s = run.icon / (S * self.icon_h)
|
|
self:put("icon_win", (x + run.icon / 2) / S, y, { s = s, fade = o.fade })
|
|
x = x + run.icon
|
|
else
|
|
run.text:draw({ x = x, y = y * S - run.text.height / 2, fade = o.fade })
|
|
x = x + run.text.width
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local function draw_hint_text(hint, cx, cy, fade)
|
|
hint:draw({ x = (cx - hint.width / (2 * S)) * S, y = (cy - hint.height / (2 * S)) * S, fade = fade })
|
|
end
|
|
|
|
-- drum with blinking rims; sides = "left", "right", "both"
|
|
function AIIntro:draw_rim_hint(ox, oy, f, sides, no_left_arrow)
|
|
local fade = ramp(f, 45, 14)
|
|
if fade <= 0 then return end
|
|
local g = (f - 45) % 120
|
|
local glow = g < 30 and g / 30 or math.max(1 - (g - 30) / 30, 0)
|
|
local arrow = clamp01(1 - g / 60)
|
|
local dx = clamp01(g / 60) * 7
|
|
local cx, cy = ox - 132 + 28, oy - 29 + 28
|
|
self:put("drum_rim", cx, cy, { fade = fade })
|
|
if sides ~= "right" then
|
|
self:put("drum_rim_glow", cx - 12, cy, { fade = fade * glow })
|
|
if not no_left_arrow then self:put("drum_rim_arrow", cx - 27 - dx, cy, { fade = fade * arrow }) end
|
|
end
|
|
if sides ~= "left" then
|
|
self:put("drum_rim_glow", cx + 12, cy, { fade = fade * glow, mirror = "horizontal" })
|
|
self:put("drum_rim_arrow", cx + 27 + dx, cy, { fade = fade * arrow, mirror = "horizontal" })
|
|
end
|
|
draw_hint_text(self.hint_page, ox + 52, oy - 2, fade)
|
|
end
|
|
|
|
function AIIntro:draw_decide_hint(ox, oy, f)
|
|
local fade = ramp(f, 9, 15)
|
|
if fade <= 0 then return end
|
|
local g = (f - 9) % 60
|
|
local blink = g < 30 and 1 - g / 30 or (g - 30) / 30
|
|
local flash = (f - 9) % 120
|
|
flash = flash < 30 and flash / 30 or (flash < 60 and 1 - (flash - 30) / 30 or 0)
|
|
self:put("hint_glow", ox + 120, oy - 3, { fade = fade * blink })
|
|
self:put("hint_glow_round", ox - 43, oy - 1, { fade = fade * blink })
|
|
draw_hint_text(self.hint_end, ox + 87, oy - 1, fade) -- the baked text sits left of its glow atlas
|
|
self:put("drum_decide", ox - 43, oy - 1, { fade = fade })
|
|
self:put("drum_decide_flash", ox - 43, oy - 1, { fade = fade * flash })
|
|
end
|
|
|
|
function AIIntro:draw_story()
|
|
local OY_S = 326
|
|
local p = PHRASES[self.phrase]
|
|
local don_d, don_y = track(self.don[2], self:frame_since(self.don_t0))
|
|
self:put_native(self.don[1], 327, 302 + don_y, { sy = don_d })
|
|
if self.aidon then
|
|
local d, y = track(self.aidon, self:frame_since(self.aidon_t0))
|
|
self:put_native("aidon", 870, 312 + y, { sy = d })
|
|
end
|
|
if self.makina then
|
|
local f = self:frame_since(self.makina_t0)
|
|
local _, y = track(self.makina[2], f)
|
|
local key = "makina_open"
|
|
if self.makina[1] == "smile" then
|
|
key = "makina_smile"
|
|
elseif self.makina[1] == "glad" then
|
|
key = f < 175 and "makina_glad" or "makina_open"
|
|
elseif self.makina[1] == "blink" then
|
|
local b = f % 182
|
|
key = (b >= 173 and b < 181) and "makina_blink" or "makina_open"
|
|
end
|
|
self:put_native(key, 1074, OY_S - 36 + y)
|
|
end
|
|
self:put_native(p.bubble, 640, OY_S + 216)
|
|
self:draw_rows(self.lines[self.phrase], LINE_X, LINE_Y, LINE_GAP)
|
|
local f = self:frame_since(self.phrase_t0)
|
|
if self.phrase == #PHRASES then
|
|
self:draw_decide_hint(993, 671, f)
|
|
else
|
|
self:draw_rim_hint(993, 668, self:frame_since(self.story_t0), "both", true)
|
|
end
|
|
end
|
|
|
|
local function tutorial_tex(self, name)
|
|
local t = self.tut[name]
|
|
if t == nil then
|
|
t = tex.get_texture("song_select/ai_intro_tutorial/" .. name) or false
|
|
self.tut[name] = t
|
|
end
|
|
return t
|
|
end
|
|
|
|
function AIIntro:tut_draw(name, fade)
|
|
local id = tutorial_tex(self, name)
|
|
if id then tex.draw_texture(id, { fade = fade or 1 }) end
|
|
end
|
|
|
|
function AIIntro:draw_tutorial()
|
|
local t = self:frame_since(self.tutorial_t0)
|
|
local p = PAGES[self.page + 1]
|
|
local k = self.page + 1
|
|
local fade = clamp01(self:page_frame() / PAGE_FADE)
|
|
self:tut_draw("base")
|
|
self:tut_draw("scene_" .. k, fade)
|
|
self:tut_draw("teacher_" .. (p.teacher or "idle"))
|
|
self:tut_draw("bubble")
|
|
self:tut_draw(p.bar and "scene_5_bubble" or "scene_" .. k .. "_bubble", fade)
|
|
if p.bar then
|
|
self:draw_rows(self.pages[k], 722, 448, 40, { fade = fade })
|
|
-- song start / end under the bar's ends, the three sections between its ticks
|
|
self:draw_rows(self.labels[1], 336, 566, 0, { fade = fade })
|
|
self:draw_rows(self.labels[2], 1137, 566, 0, { fade = fade })
|
|
for i, x in ipairs({ 469, 737, 1005 }) do
|
|
self:draw_rows(self.labels[2 + i], x, 508, 0, { fade = fade })
|
|
end
|
|
else
|
|
self:draw_rows(self.pages[k], 722, 624, 54, { fade = fade })
|
|
end
|
|
if self.page == LAST_PAGE then
|
|
self:draw_decide_hint(993, 671, t)
|
|
else
|
|
self:draw_rim_hint(993, 668, t, "both", self.page == 0)
|
|
end
|
|
end
|
|
|
|
function AIIntro:draw()
|
|
self.draw_background()
|
|
if self.mode == "story" then
|
|
self:draw_story()
|
|
return
|
|
end
|
|
self:draw_tutorial()
|
|
if self.mode == "out" then
|
|
local a = clamp01(self:frame_since(self.out_t0) / OUT_FRAMES)
|
|
tex.draw_rect(0, 0, tex.get_screen_width(), tex.get_screen_height(), 0, 0, 0, math.floor(255 * a))
|
|
end
|
|
end
|