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

736 lines
33 KiB
Lua

local STATE_BROWSING = 0
local STATE_SONG_SELECTED = 1
local DIFF_BACK = -3
local DIFF_MODIFIER = -2 -- engine Difficulty::MODIFIER (演奏オプション)
local DIFF_NEIRO = -1 -- engine Difficulty::NEIRO (音色; skin option option_neiro_row = false)
local URA_FLIP_MS = 350 -- oni <-> ura switch: column flash + icon pop length
local T14_CHROME = true
local T14_BOX_GAP_TOP, T14_BOX_GAP_BOTTOM = 16, 10 -- closed boxes: gap under the strip, a bit shorter
-- Folder open, as PyTaikoGreen: Navigator::begin_inline_load moves every box right of the opened
-- folder to screen_width + 150 over 600 ms (cubic ease-in) -- but only for skins without draw_box, so it is
-- redone here from the OPEN_BEGIN wheel event. The rest (list swap, set_positions moves, box fades,
-- close) is the engine's own animation, which this script already follows through box_x / fade.
local WEV_OPEN_BEGIN, WEV_OPEN_SWAP = 3, 4
local FOLDER_OUT_MS, FOLDER_OUT_X = 600, 960 + 150
SongSelect = {}
SongSelect.__index = SongSelect
-- columns.gd / song_select.tscn
local COL_Y = 112 -- MarginContainer anchor_top .089*720 - .08 = 64, + margin_top 48
local BOX_W = 108 -- the 14 bar (72 swg px)
local BOX_H = 472 -- bsize.y
local PAD = 27 -- 90 swg px apart
local OPEN_SONG = 480 -- box_open_size (song)
local OPEN_FOLDER = 256 -- box_open_size (box.def folder)
local OPEN_DIFF = 768 -- box_diff_select_size
local CX = 480 -- viewport width / 2
-- Box colours. juu-yon tints bar / index tab / background with the box.def #BACKCOLOR
-- (TJAMeta.box_back_color, default WHITE). The engine does not hand back_color to Lua, so the
-- genre's colour comes from the engine's own default table (color_utils.cpp DEFAULT_COLORS, the
-- same values the library's box.def files carry); genres without one stay WHITE like juu-yon.
local GENRE_BACK = {
[1] = { 32, 160, 186 }, -- JPOP
[2] = { 255, 152, 0 }, -- ANIME
[4] = { 255, 82, 134 }, -- CHILDREN
[5] = { 142, 212, 30 }, -- VARIETY
[6] = { 209, 162, 19 }, -- CLASSICAL
[7] = { 156, 117, 189 }, -- GAME
[8] = { 255, 90, 19 }, -- NAMCO
[13] = { 35, 102, 170 }, -- DAN
[14] = { 255, 85, 95 }, -- DIFFICULTY
}
local WHITE = { 255, 255, 255 }
local CHOCOLATE = { 210, 105, 30 } -- columns.gd: back.box_back_color = Color.CHOCOLATE
local BLACK = { 0, 0, 0 }
local DIFF_COL_COLOR = { 255, 162, 25 } -- the 14 course column orange
local YELLOW = { 255, 220, 45 } -- the 14 cursor bar
local URA_TINT = { 190, 130, 255 }
-- engine genre index -> t14_select frame (J-POP, anime, variety, classic, namco, children, game); 7 = tinted
local GENRE_SLOT = { [1] = 0, [2] = 1, [5] = 2, [6] = 3, [8] = 4, [4] = 5, [7] = 6 }
-- the bar art is 192x528 with its body at (46.5, 39)-(154.5, 497); ★×N digit at (106.5, 459)
local BAR_LEFT, BAR_TOP, BAR_BODY_H, BAR_ART_H = 46.5, 39, 458, 528
-- a course tower (song_select_song, 72x372) and its star stack, the bottom star on the last dot
local UNIT, UNIT_DIFF, COL_W, COL_H, STAR_X, STAR_Y = 56, 62, 72, 372, 18, 156
-- TaikoText outline sizes are Godot outline widths (radius = size / 2); OutlinedText multiplies
-- the thickness it is given by screen_scale, so it is handed radius / screen_scale.
local SS = tex.get_screen_scale()
-- juu-yon's outline widths look too heavy at this skin's 960 px (user, 2026-09-27): every text
-- outline is drawn at OUTLINE_K of the juu-yon value.
local OUTLINE_K = 0.6
local function rad(outline_size) return (outline_size / 2) / SS end
local function box_back_color(box)
local kind = box:lua_kind()
if kind == "back" then return CHOCOLATE end
return GENRE_BACK[box:genre_index()] or WHITE
end
--------------------------------------------------------------------------------
-- drawing helpers
--------------------------------------------------------------------------------
local ids = {}
local function id(name) return ids[name] end
local rgba_cache = setmetatable({}, { __mode = "k" })
local function rgba(c)
local t = rgba_cache[c]
if t == nil then
t = { c[1], c[2], c[3], 255 }
rgba_cache[c] = t
elseif t[1] ~= c[1] or t[2] ~= c[2] or t[3] ~= c[3] then
t[1], t[2], t[3] = c[1], c[2], c[3]
end
return t
end
local function rect(x, y, w, h, color, fade)
if w <= 0 or h <= 0 then return end
tex.draw_texture(id("white"), { x = x, y = y, x2 = w - 1, y2 = h - 1, color = rgba(color), fade = fade })
end
local t14, t14_size = {}, {}
local function T(name, x, y, o)
local t = t14[name]
if t == nil then
t = tex.get_texture("song_select/t14_select/" .. name) or false
t14[name] = t
local info = tex.get_texture_info("t14_select", name)
t14_size[name] = info and { info.width, info.height } or { 0, 0 }
end
if not t then return end
o = o or {}
local sz = t14_size[name]
tex.draw_texture(t, { frame = o.frame or 0, x = x, y = y, x2 = o.w and (o.w - sz[1]) or 0,
y2 = o.h and (o.h - sz[2]) or 0, color = o.color and rgba(o.color) or nil, fade = o.fade, mirror = o.mirror })
end
local function val(box, k)
local v = box[k]
if type(v) == "function" then v = v(box) end
return v
end
-- StyleBoxFlat with corner radius r (all corners, or the top two only)
local function rrect(r, x, y, w, h, color, fade, top_only)
local d = id("disc" .. r)
local function q(sx, sy, dx, dy)
tex.draw_texture(d, { src = { x = sx, y = sy, width = r, height = r }, x = dx, y = dy,
x2 = -r, y2 = -r, color = rgba(color), fade = fade })
end
q(0, 0, x, y); q(r, 0, x + w - r, y)
rect(x + r, y, w - 2 * r, r, color, fade)
if top_only then
rect(x, y + r, w, h - r, color, fade)
else
rect(x, y + r, w, h - 2 * r, color, fade)
q(0, r, x, y + h - r); q(r, r, x + w - r, y + h - r)
rect(x + r, y + h - r, w - 2 * r, r, color, fade)
end
end
-- text cache (OutlinedText objects are rasterised once per string/style)
-- keyed str -> colours -> size / outline radius / vertical (no string building per lookup)
local text_cache, text_count = {}, 0
local function raw_text(str, size, fill, outline, radius_px, vertical)
if not str or str == "" then return nil end
local k2 = ((fill[1] * 256 + fill[2]) * 256 + fill[3]) * 16777216
+ (outline[1] * 256 + outline[2]) * 256 + outline[3]
local k3 = (size * 4096 + radius_px * 16) * 2 + (vertical and 1 or 0)
local by_str = text_cache[str]
local by_col = by_str and by_str[k2]
local t = by_col and by_col[k3]
if t == nil then
if text_count > 256 then text_cache, text_count, by_str, by_col = {}, 0, nil, nil end
t = text.create_raw_text(str, size, rgba(fill), rgba(outline), vertical, radius_px * OUTLINE_K / SS, 2.0) or false
if not by_str then by_str = {}; text_cache[str] = by_str end
if not by_col then by_col = {}; by_str[k2] = by_col end
by_col[k3] = t
text_count = text_count + 1
end
return t or nil
end
--------------------------------------------------------------------------------
function SongSelect.new()
local self = setmetatable({}, SongSelect)
tex.load_folder("song_select", "global")
tex.load_folder("song_select", "jy_select")
tex.load_folder("song_select", "t14_select")
for _, n in ipairs({ "white", "disc24", "disc8" }) do
ids[n] = tex.get_texture("song_select/jy_select/" .. n)
end
self.sel_w = BOX_W -- width of the selected box (last frame)
self.next_w = BOX_W
self.diff_t = 0.0 -- diff-select progress of the selected box (last frame)
self.next_diff = 0.0
self.target_bg = WHITE
self.header_col = { 143, 143, 143 }
self.genre_name = nil
self.sel_box = nil -- geometry of the selected song box for draw_selector
self.icons = {} -- rank / new badges of this frame's boxes
return self
end
function SongSelect:update(current_ms) end
function SongSelect:restart_text_fade() end
--------------------------------------------------------------------------------
-- background: the 14 genre wallpaper of the box under the cursor
--------------------------------------------------------------------------------
function SongSelect:draw_background(nav)
local now = tex.get_current_ms()
-- per-frame hand-over of the selected box geometry (draw_box of the previous frame)
self.sel_w, self.next_w = self.next_w, BOX_W
self.diff_t, self.next_diff = self.next_diff, 0.0
local folder = nav:current_folder()
if T14_CHROME then
self:learn_ring(folder)
local ok, seq = pcall(function() return nav.wheel_event_seq end)
if ok and seq and seq ~= self.wev_seq then
local ok2, ev = pcall(function() return nav.wheel_event end)
if self.wev_seq ~= nil and ok2 then self.wev, self.wev_ms = ev, now end
self.wev_seq = seq
end
end
self.folder_color = folder and box_back_color(folder) or nil
self.folder_path = folder and folder:path() or nil
self.folder_fore = folder and folder:fore_color() or nil
self.folder_genre = folder and folder:genre_index() or nil
self.folder_name = folder and folder.text_name or nil
-- the 14 genre wallpaper, cross-faded over 250 ms (bg_change)
local slot = GENRE_SLOT[self.target_genre or -1]
local c = self.target_bg or WHITE
local key = slot or (c[1] * 65536 + c[2] * 256 + c[3])
if key ~= self.bg_key then
self.bg_prev, self.bg_key, self.bg_ms = self.bg_cur, key, now
local pale = { 255 - math.floor((255 - c[1]) / 2), 255 - math.floor((255 - c[2]) / 2),
255 - math.floor((255 - c[3]) / 2) }
self.bg_cur = { frame = slot or 7, color = not slot and pale or nil }
end
local p = math.min(1, (now - self.bg_ms) / 250)
if self.bg_prev and p < 1 then T("bg", 0, 0, self.bg_prev) end
local cur = self.bg_cur
T("bg", 0, 0, { frame = cur.frame, color = cur.color, fade = p })
end
--------------------------------------------------------------------------------
-- list geometry
--------------------------------------------------------------------------------
-- engine position -> list offset (Navigator::set_positions, non-vertical branch)
local function u_of(pos)
local left1 = (594 - 150 - 100) * SS -- offset -1
local centre = 594 * SS -- offset 0
local right1 = (594 - 150 + 100 + 300) * SS -- offset +1
if pos <= left1 then return (pos - (594 - 150) * SS) / (100 * SS) - 0.0 end
if pos >= right1 then return (pos - (594 - 150 + 300) * SS) / (100 * SS) end
if pos <= centre then return (pos - centre) / (centre - left1) end
return (pos - centre) / (right1 - centre)
end
-- list offset -> left edge in juu-yon's layout, for a selected box of width sw
local function x_of(u, sw)
local sel_x = CX - sw / 2
if u <= -1 then return sel_x - (BOX_W + PAD) + (BOX_W + PAD) * (u + 1) end
if u >= 1 then return sel_x + sw + PAD + (BOX_W + PAD) * (u - 1) end
if u <= 0 then return sel_x + (BOX_W + PAD) * u end
return sel_x + (sw + PAD) * u
end
--------------------------------------------------------------------------------
-- one column (columns.gd _draw loop body)
--------------------------------------------------------------------------------
function SongSelect:title_text(box, outline)
local name = box.text_name
if box:lua_kind() == "back" then
local s = tex.skin_text("jy_back")
if s ~= "" then name = s end
end
-- VerticalText2D font_size 32, outline_size 20
return raw_text(name, 32, WHITE, outline, 10, true)
end
function SongSelect:subtitle_text(box, outline)
local s = box.text_subtitle
if not s or s == "" then return nil end
s = s:gsub("^%-%-", ""):gsub("^%+%+", "")
if s == "" then return nil end
return raw_text(s, 24, WHITE, outline, 8, true) -- font_size 24, outline_size 16
end
local SCALED_P = {}
local function draw_scaled_v(t, cx, y, max_h, fade)
if not t then return 0 end
local h, tw = t.height, t.width
local s = math.min(1.0, max_h / h) -- tja_meta.gd update_text_scale
local p = SCALED_P
p.x, p.y, p.y2, p.fade = math.floor(cx - tw / 2 + 0.5), math.floor(y + 0.5), math.floor(h * s + 0.5) - h, fade
t:draw(p)
return tw
end
-- the box's animations: fields before the engine's 2026-09 bindings, methods (box:fade()) after
local function box_anim(box, name)
local a = box[name]
if type(a) == "function" then a = a(box) end
return a
end
function SongSelect:draw_box(box)
local kind = box:lua_kind()
local state = box:draw_state()
local fade = box_anim(box, "fade").attribute
local u = u_of(box:box_x())
local color = box_back_color(box)
-- only the root list feeds learn_ring (it ignores frames inside a folder)
if T14_CHROME and kind ~= "back" and self.frame_boxes and not self.frame_folder then
self.frame_boxes[#self.frame_boxes + 1] = { u = u, path = box:path(), color = color }
end
-- selected-box width: song 480, box.def folder / back 256, diff select 768 (columns.gd)
local is_sel = state ~= "closed"
local w, h, top = BOX_W, BOX_H, COL_Y
local trans, dtrans = 0.0, 0.0
local target = (kind == "song") and OPEN_SONG or OPEN_FOLDER
if is_sel then
trans = box_anim(box, "open_fade").attribute
if state == "diff_select" and kind == "song" then
dtrans = box.diff_fade_in.attribute
w = OPEN_SONG + (OPEN_DIFF - OPEN_SONG) * dtrans
h = BOX_H + 32 * dtrans -- bsize.y 472 -> 504, grows upward
top = COL_Y - 32 * dtrans
trans = 1.0
else
w = BOX_W + (target - BOX_W) * trans
end
self.next_w = w
self.next_diff = dtrans
-- columns.gd: a Back box (or a song) inside a box shows the box's colours
local shown = (kind == "back" and self.folder_color) or color
self.target_bg = shown
self.target_genre = (kind == "back" and self.folder_genre) or box:genre_index()
self.header_col = shown
if kind == "folder" then self.genre_name = box.text_name; self.genre_idx = box:genre_index(); self.genre_fore = box:fore_color()
elseif kind == "back" and not self.folder_name then self.genre_name = nil; self.genre_idx = nil; self.genre_fore = nil end
elseif math.abs(u) < 0.5 then
-- the cursor's box before it opens (moving / 0.5 s timer)
local shown = (kind == "back" and self.folder_color) or color
self.target_bg = shown
self.target_genre = (kind == "back" and self.folder_genre) or box:genre_index()
self.header_col = shown
if kind == "folder" then self.genre_name = box.text_name; self.genre_idx = box:genre_index(); self.genre_fore = box:fore_color() end
end
if T14_CHROME then
local g = 1.0 -- every box, selected / open too (user: wider when selected, never taller)
top = top + T14_BOX_GAP_TOP * g
h = h - (T14_BOX_GAP_TOP + T14_BOX_GAP_BOTTOM) * g
end
local sw = self.sel_w
local x
if is_sel then x = CX - w / 2 else x = x_of(u, sw) end
if T14_CHROME and not is_sel and u >= 0.5 then
local p = self:folder_slide()
if p > 0 then x = x + (FOLDER_OUT_X - x) * p end
end
if x > 960 + 40 or x + w < -40 then return end
self:draw_bar(box, kind, x, top, w, h, color, is_sel or math.abs(u) < 0.5, fade, trans)
-- title: x centre = x + 48 + (bsize.x - 96) (- 16 in diff select, - 28 for an open box.def box)
local outline = BLACK
if not is_sel then
local fc = box:fore_color()
if fc then outline = { fc.r, fc.g, fc.b } end
end
local x_ofs = 50 + (w - BOX_W) - 16 * dtrans
if kind ~= "song" and is_sel then x_ofs = x_ofs - 28 * trans end
local ty = (dtrans > 0) and (COL_Y + 24 * (1 - dtrans)) or (COL_Y + 24)
if T14_CHROME then ty = ty + T14_BOX_GAP_TOP end -- follows the lowered box top
local title = self:title_text(box, outline)
local shrink = T14_CHROME and (T14_BOX_GAP_TOP + T14_BOX_GAP_BOTTOM) or 0
local tw = draw_scaled_v(title, x + x_ofs, ty, 416 - shrink, fade)
if kind == "song" and is_sel then
-- subtitle: x_ofs -= title width + 16, y += 48
local sub = self:subtitle_text(box, outline)
if sub then
draw_scaled_v(sub, x + x_ofs - tw - 16, ty + 48, 376 - shrink, fade * math.min(1.0, trans))
end
self:draw_courses(box, x, top, w, trans, dtrans, fade)
end
end
-- closed: the genre bar (yellow under the cursor) with its ★×N footer; open: the yellow board, with the
-- genre's blurb for a folder
function SongSelect:draw_bar(box, kind, x, top, w, h, color, cursor, fade, trans)
local slot = kind ~= "back" and GENRE_SLOT[box:genre_index()] or nil
local icons = self.icons
local song = kind == "song"
local s = h / BAR_BODY_H
local bx, by = x - BAR_LEFT, top - BAR_TOP * s
if w <= BOX_W + 1 then
local frame, tint = slot, nil
if cursor then frame = 8 elseif not slot then frame, tint = 7, color end
T(song and "bar" or "bar_box", bx, by, { frame = frame, color = tint, h = BAR_ART_H * s, fade = fade })
if song then
local lvl = self:bar_level(box)
if lvl >= 1 then T("bar_digit", bx + 106.5, by + 459 * s, { frame = math.min(10, lvl) - 1, fade = fade }) end
if self:branches(box) then icons[#icons + 1] = { "branch_tag", bx + 117, by + 29 * s, slot or 0, fade } end
end
else
T("board_shadow", x - 15, top - 10, { w = w * 224 / 204, h = h * 320 / 304, fade = fade })
T("board_left", x, top, { h = h, fade = fade })
T("board_fill", x + 24, top, { w = w - 48, h = h, fade = fade })
T("board_right", x + w - 24, top, { h = h, fade = fade })
if kind == "folder" and slot then
T("genre_desc", x + 36, top + 24, { frame = slot, fade = fade * math.min(1, trans) })
end
end
-- badges and arrows go over the neighbours and the genre strip (draw_overlays)
if w > BOX_W + 1 and self.ov_state ~= STATE_SONG_SELECTED then
local bob = 6 * math.abs(math.sin(tex.get_current_ms() / 160))
local a = fade * math.min(1, trans)
icons[#icons + 1] = { "arrow_left", x - 66 - bob, top + h / 2 - 30, 0, a }
icons[#icons + 1] = { "arrow_right", x + w + 6 + bob, top + h / 2 - 30, 0, a }
end
if not song then return end
local rank = val(box, "popular_rank")
if rank and rank >= 1 and rank <= 10 then
if w > BOX_W + 1 then
icons[#icons + 1] = { "popular", x + w / 2 - 84, top - 64, rank - 1, fade }
else
icons[#icons + 1] = { "rank", bx + 42, by + 10.5 * s, rank - 1, fade }
end
end
if val(box, "is_new") then icons[#icons + 1] = { "new_icon", x + w - 54, top - 30, 0, fade } end
end
-- the footer's ★×N: the last chosen course's level (the 14 picks the course first), else the highest course
function SongSelect:bar_level(box)
local want = NK_SELECTED_DIFF
if want and want >= 0 and want <= 3 then
local ci = box:course_info(want)
if ci.has_course then return ci.level end
end
for d = 3, 0, -1 do
local ci = box:course_info(d)
if ci.has_course then return ci.level end
end
return 0
end
function SongSelect:branches(box)
for d = 0, 4 do
if box:course_info(d).is_branching then return true end
end
return false
end
-- difficulty columns (columns.gd "# Difficulties")
-- Green's folder-open move of the boxes right of the folder (0 = in place, 1 = off screen), held
-- until the engine swaps the list in
function SongSelect:folder_slide()
if self.wev ~= WEV_OPEN_BEGIN or not self.wev_ms then return 0 end
local p = math.min(1, math.max(0, (tex.get_current_ms() - self.wev_ms) / FOLDER_OUT_MS))
return p * p * p -- MoveAnimation ease_in Cubic
end
-- oni / ura weights: YataiDONNijiiro's 3 s song-board loop (oni ~1 s, change, ura ~1 s, change),
-- here as one simultaneous smoothstep cross-fade of 0.5 s each way (user: the staggered linear
-- 0.25 s ramps looked jerky)
local function ura_crossfade(ms)
local t = (ms % 3000) / 1000
local function ss(t0)
local u = math.max(0, math.min(1, (t - t0) / 0.5))
return u * u * (3 - 2 * u)
end
local ura = ss(1.0) - ss(2.5)
return 1 - ura, ura
end
function SongSelect:draw_courses(box, x, top, w, trans, dtrans, fade)
local list = {}
for d = 0, 3 do
local ci = box:course_info(d)
if ci.has_course then list[#list + 1] = { d = d, level = ci.level } end
end
if box.is_ura and #list > 0 and list[#list].d == 3 then
local ci = box:course_info(4)
if ci.has_course then list[#list] = { d = 4, level = ci.level } end
end
local n = #list
if n == 0 then return end
-- oni <-> ura switch (the engine's UraSwitchAnimation panel is hidden in
-- Graphics/song_select/diff_select): the last column flashes white and its icon pops.
-- Only a flip seen while the difficulty select is fully open counts (entering a song resets it).
local now = tex.get_current_ms()
local ura = box.is_ura and true or false
if self.ura_seen ~= nil and ura ~= self.ura_seen and dtrans >= 0.999 then self.ura_flip_ms = now end
self.ura_seen = ura
local flip_t = self.ura_flip_ms and (now - self.ura_flip_ms) / URA_FLIP_MS or 1
if flip_t >= 1 then flip_t = nil end
-- four course slots, left of the title; songs with fewer courses fill them from the right
local unit = UNIT + (UNIT_DIFF - UNIT) * dtrans
-- diff select: Back / Options / Hit sound and the four towers in one row at the tower pitch, centred left
-- of the title
local row = x + 24 + (w - 114 - 7 * unit) / 2 + 3 * unit
local slot0 = x + 36 + (row - x - 36) * dtrans
if dtrans <= 0 then slot0 = CX - OPEN_SONG / 2 + 36 end -- in place while the board widens
local ux = slot0 + math.max(0, 4 - n) * unit
local a = (dtrans > 0) and 1.0 or math.max(0.0, math.min(1.0, trans - 0.5))
if T14_CHROME then a = (dtrans > 0) and 1.0 or math.max(0.0, math.min(1.0, trans * 2)) end
a = a * fade
-- column origin: offset_x(diff_x) -> (diff_x, right.y); right.y = 472 - bsize.y in diff select
local oy = top
local col_y = oy + 24
local geo = { x = x, top = top, cols = {}, a = a, slot0 = slot0, col_y = col_y, col_h = COL_H }
for k, c in ipairs(list) do
local flipping = flip_t and k == n and c.d >= 3
local function content(cc, ca)
T("course", ux, col_y, { frame = math.min(cc.d, 3), color = cc.d == 4 and URA_TINT or nil, fade = ca })
local stars = math.min(10, cc.level)
if stars >= 1 then T("stars", ux + STAR_X, col_y + STAR_Y, { frame = stars - 1, fade = ca }) end
end
local ura_level = nil
if T14_CHROME and dtrans <= 0 and k == n and c.d == 3 and box:has_ura() then
local ui = box:course_info(4)
if ui.has_course then ura_level = ui.level end
end
if ura_level then
local oa, ua = ura_crossfade(tex.get_current_ms())
if oa > 0 then content(c, a * oa) end
if ua > 0 then content({ d = 4, level = ura_level }, a * ua) end
else
content(c, a)
end
if flipping then rrect(24, ux + 12, col_y + 4, 48, COL_H - 8, WHITE, a * 0.85 * (1 - flip_t)) end
-- x: the 48-wide hit / cursor box centred on the tower
geo.cols[k] = { x = ux + 12, d = c.d }
ux = ux + unit
end
-- Back, then the engine's extra cursor stops Options (Difficulty::MODIFIER) and Hit sound
-- (Difficulty::NEIRO), in cursor order before the towers and at their pitch
if dtrans > 0 then
local a2 = dtrans * fade
local function mini_bar(left, key)
rrect(24, left, top + 28, 48, 240, DIFF_COL_COLOR, a2)
local t = raw_text(tex.skin_text(key), 24, BLACK, BLACK, 0.5, true)
-- caption 22 px below the bar top (juu-yon 16 sat too close to the edge)
if t then t:draw({ x = math.floor(left + 24 - t.width / 2 + 0.5), y = top + 50, fade = a2 }) end
end
geo.back_x = geo.slot0 - 3 * unit + 12 - 24
geo.mod_x = geo.slot0 - 2 * unit + 12
geo.neiro_x = geo.slot0 - unit + 12
mini_bar(geo.back_x + 24, "jy_back")
mini_bar(geo.mod_x, "jy_options")
mini_bar(geo.neiro_x, "jy_neiro")
end
geo.dtrans = dtrans
self.sel_box = geo
end
function SongSelect:draw_box_bg(box) end
-- p1_cursor.png over the chosen column (columns.gd: Vector2(24, 20 + ofs) - size/2 on a column,
-- Vector2(48 - w/2, 24 + ofs) on the Back bar)
-- touch: the course column or mini bar (Back / Options / Hit sound) under a canvas point, as last laid out
local TOUCH_PAD = 12
function SongSelect:difficulty_at(_player, px, py)
local g = self.sel_box
if not g or not g.dtrans or g.dtrans <= 0 then return nil end
local function hit(left, top, h)
return px >= left - TOUCH_PAD and px < left + 48 + TOUCH_PAD and py >= top and py < top + h
end
for _, c in ipairs(g.cols) do
if hit(c.x, g.col_y, g.col_h) then return c.d end
end
if g.back_x and hit(g.back_x + 24, g.top + 28, 240) then return DIFF_BACK end
if g.mod_x and hit(g.mod_x, g.top + 28, 240) then return DIFF_MODIFIER end
if g.neiro_x and hit(g.neiro_x, g.top + 28, 240) then return DIFF_NEIRO end
return nil
end
function SongSelect:draw_selector(player, is_half, fade_in, pass)
-- [YataiDON14 build patch] publish the course for Nantoka's transition iris
-- (Scripts/global/transition.lua reads NK_SELECTED_DIFF)
do local nd = player:selected_difficulty()
if nd >= 0 and nd <= 4 then NK_SELECTED_DIFF = nd end end
if pass ~= 1 then return end
local g = self.sel_box
if not g or not g.dtrans or g.dtrans <= 0 then return end
local d = player:selected_difficulty()
-- the play HUD (YataiDON14 t14_hud.lua) reads the chosen course for its gauge art
if d >= 0 and d <= 4 then
-- NK_SELECTED_DIFF (one number) is the Nantoka transition's; this one is per player
NK_SELECTED_DIFF = d
if type(NK_COURSE_BY_PLAYER) ~= "table" then NK_COURSE_BY_PLAYER = {} end
NK_COURSE_BY_PLAYER[(player.player_num and player:player_num() == 2) and 2 or 1] = d
end
local a = math.min(1.0, g.dtrans)
-- the 14 arrows either side of the chosen column; 2P's pair sits lower
local dy = (player.player_num and player:player_num() == 2) and 60 or 0
local bob = 5 * math.abs(math.sin(tex.get_current_ms() / 140))
local function mark(l, r, cy)
T("arrow_left", l - 28 - bob, cy - 17 + dy, { w = 34, h = 34, fade = a })
T("arrow_right", r - 6 + bob, cy - 17 + dy, { w = 34, h = 34, fade = a })
end
local mini_y = g.top + 28 + 120
if d == DIFF_BACK then
if g.back_x then mark(g.back_x + 24, g.back_x + 72, mini_y) end
return
end
if d == DIFF_MODIFIER or d == DIFF_NEIRO then
local bx = (d == DIFF_MODIFIER) and g.mod_x or g.neiro_x
if bx then mark(bx, bx + 48, mini_y) end
return
end
for _, c in ipairs(g.cols) do
if c.d == d or (d == 4 and c.d == 3) or (d == 3 and c.d == 4) then
mark(c.x - 2, c.x + 50, g.col_y + COL_H / 2)
return
end
end
end
local T14_FACE_MS = 100
function SongSelect:draw_t14_footer()
local now = tex.get_current_ms()
if audio.play_count then
local n = audio.play_count("kat")
if self.kat_count and n > self.kat_count then self.face_ms = now end
self.kat_count = n
else
local kat = audio.is_sound_playing("kat")
if kat and not self.kat_prev then self.face_ms = now end
self.kat_prev = kat
end
local alt = self.face_ms ~= nil and now - self.face_ms < T14_FACE_MS
local two = tex.current_screen and tex.current_screen() == "SONG_SELECT_2P"
local solo2 = not two and tex.player_num and tex.player_num() == 2
self.chara = { alt = alt, don = not solo2, katsu = two or solo2 }
if self.ov_state == STATE_SONG_SELECTED then return end
-- ふちで選んで 面で決定: the rim disc blinks blue, its two little arrows nudge outward
local t = tex.get_current_ms() / 1000
local pulse = 0.5 + 0.5 * math.sin(t * math.pi * 2)
local nudge = 4 * math.abs(math.sin(t * math.pi * 2))
T("guide", 185.5, 609)
T("guide_rim", 272, 615)
T("guide_rim_lit", 272, 615, { fade = 0.55 + 0.45 * pulse })
T("guide_face", 531, 615)
T("guide_arrow", 256 - nudge, 627, { mirror = "horizontal" })
T("guide_arrow", 330 + nudge, 627)
end
function SongSelect:draw_footer()
return self:draw_t14_footer()
end
local T14_BAND_TOP, T14_BAND_BOTTOM = 57, 670
function SongSelect:draw_overlays(state)
self.ov_state = state -- the footer (drawn before the overlays) reads it next frame
rect(0, 0, 960, T14_BAND_TOP, BLACK)
rect(0, T14_BAND_BOTTOM, 960, 720 - T14_BAND_BOTTOM, BLACK)
-- the 14 Don (left) / Katsu (right) over the bottom band, waving for a moment on every rim hit
local ch = self.chara
if ch then
local tail = math.floor(tex.get_current_ms() / (4000 / 60)) % 7
if ch.don then
T("don", -60, 414, { frame = ch.alt and 1 or 0 })
T("cloud_don", -117, 363, { frame = tail })
end
if ch.katsu then
T("katsu", 720, 414, { frame = ch.alt and 1 or 0 })
T("cloud_katsu", 784, 363, { frame = tail })
end
end
local gname = self.folder_name or self.genre_name
local slot = GENRE_SLOT[(self.folder_name and self.folder_genre) or self.genre_idx or -1]
T("title", -11, 2)
-- ✿ N 曲目: the last chosen course's flower and this credit's song number
local n = math.max(1, math.min(9, (tex.songs_played and tex.songs_played() or 0) + 1))
local course = math.min(3, math.max(0, NK_SELECTED_DIFF or 0))
T("counter_course", 607, 29, { frame = course, w = 75.6, h = 64.8 })
T("counter_digit", 678, 34, { frame = n - 1, w = 43.2, h = 54 })
T("counter_label", 719, 34, { w = 97.2, h = 54 })
-- the open song box (difficulty select) reaches over the header: no genre name / strip then
local icons = self.icons
self.icons = {}
if state == STATE_SONG_SELECTED then return end
self:draw_genre_strip()
for _, ic in ipairs(icons) do T(ic[1], ic[2], ic[3], { frame = ic[4], fade = ic[5] }) end
if slot then
T("genre_name", 332, 61, { frame = slot })
elseif gname then
local fc = (self.folder_name and self.folder_fore) or (not self.folder_name and self.genre_fore) or nil
local oc = fc and { fc.r, fc.g, fc.b } or (self.header_col or WHITE)
if not fc and oc[1] + oc[2] + oc[3] > 600 then oc = { 80, 80, 80 } end -- light, no fore colour
local lab = raw_text(gname, 32, WHITE, oc, 9, false)
if lab then lab:draw({ x = math.floor(476 - lab.width / 2 + 0.5), y = math.floor(91 - lab.height / 2 + 0.5) }) end
end
end
local STRIP_SEG, STRIP_CUR, STRIP_X, STRIP_Y, STRIP_H, STRIP_M = 100, 300, 468, 113, 12, 24
RING_NEXT, RING_PREV, RING_COL = RING_NEXT or {}, RING_PREV or {}, RING_COL or {}
function SongSelect:learn_ring(folder)
local fb = self.frame_boxes
if fb and not self.frame_folder and #fb > 0 then
table.sort(fb, function(a, b) return a.u < b.u end)
local best = nil
for k, b in ipairs(fb) do
RING_COL[b.path] = b.color
if k > 1 and b.u - fb[k - 1].u < 1.5 then
RING_NEXT[fb[k - 1].path] = b.path
RING_PREV[b.path] = fb[k - 1].path
end
if not best or math.abs(b.u) < math.abs(best.u) then best = b end
end
self.root_cur = best and best.path or nil
end
self.frame_boxes = {}
self.frame_folder = folder and folder:path() or nil
end
function SongSelect:draw_genre_strip()
local cur = self.folder_path or self.root_cur
if not cur then return end
local l, r = STRIP_X - STRIP_CUR / 2, STRIP_X + STRIP_CUR / 2
local function seg(x, w, c)
local a, b = math.max(x, STRIP_M), math.min(x + w, 960 - STRIP_M)
if b > a then rect(a, STRIP_Y, b - a, STRIP_H, c) end
end
seg(l, STRIP_CUR, RING_COL[cur] or self.folder_color or WHITE)
local p, guard = cur, 0
while l > STRIP_M and guard < 20 do -- left: previous boxes of the root list
p = RING_PREV[p]; guard = guard + 1
if not p or p == cur then break end
l = l - STRIP_SEG
seg(l, STRIP_SEG, RING_COL[p] or WHITE)
end
p, guard = cur, 0
while r < 960 - STRIP_M and guard < 20 do -- right: next boxes
p = RING_NEXT[p]; guard = guard + 1
if not p or p == cur then break end
seg(r, STRIP_SEG, RING_COL[p] or WHITE)
r = r + STRIP_SEG
end
end
do
local T14_HC = require("global.t14_herecome")
local draw_top = SongSelect.draw_top
function SongSelect:draw_top(dan_progress)
if draw_top then draw_top(self, dan_progress) end
T14_HC.song_select(self)
end
end