Files
YataiDONNijiiro/Scripts/global/coin_overlay.lua
T
2026-11-24 13:32:44 -05:00

125 lines
5.7 KiB
Lua

CoinOverlay = {}
CoinOverlay.__index = CoinOverlay
require("global/guide_panel")
local credit_side_len = 180 -- frames = 3 s
local credit_side_pop_f = 8
-- the QR chip's caption is skin text, not baked into the chip art (the same as the IC Card chip)
local QR = { x = 1570, y = 38, cx = 53, cy = 82 }
local QR_SIZE = 30
local NG_COLOR, OK_COLOR = { 255, 255, 255, 255 }, { 60, 60, 60, 255 }
local function plain(str, size, color)
return text.create_raw_text(str, GuidePanel.label_size(size), color, color, false, 0, 1.0, 0.0,
GuidePanel.label_font())
end
local function draw_centered(t, cx, cy, x, y)
if t then t:draw({ x = x + cx - t.width / 2, y = y + cy - t.height / 2 }) end
end
local function lerp(f, f0, f1, v0, v1)
if f <= f0 then return v0 end
if f >= f1 then return v1 end
return v0 + (v1 - v0) * (f - f0) / (f1 - f0)
end
-- the bubble dips to nothing at frame 30 and is back at full by frame 59, then holds
local function blink(f)
if f < 30 then return 1 - f / 30 end
return lerp(f, 30, 59, 0, 1)
end
function CoinOverlay.new()
local self = setmetatable({}, CoinOverlay)
self.text = text.create_text("free_play", { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 3, 5)
self.config = tex.get_skin_config("free_play")
self.qr = tex.get_texture("global/overlay/banapass_osaifu_keitai") -- QR chip (0 NG / 1 OK)
self.qr_ng = plain("NG", QR_SIZE, NG_COLOR)
self.qr_ok = plain("OK", QR_SIZE, OK_COLOR)
self.bubble = tex.get_texture("global/overlay/camera") -- 2P cloud bubble
self.bubble_player = text.create_text("credit_side_player", { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 4, 2)
self.bubble_msg = text.create_text("credit_side_msg", { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 4, 2)
self.bubble_cfg_p = tex.get_skin_config("credit_side_player")
self.bubble_cfg_m = tex.get_skin_config("credit_side_msg")
self.blink_t0 = tex.get_current_ms()
return self
end
function CoinOverlay:update(current_ms) end
local FREE_PLAY_CY = 1046
local BUBBLE_PLAYER_CY = 749
local BUBBLE_MSG_CY = 802
local BUBBLE_BOX_W = 416 -- cloud art width
-- Centred, whole-pixel-snapped OutlinedText draw clamped to `box_w`.
local function draw_bubble_line(t, cfg, cx, cy, fade)
if not t or t.width == nil then return end
local w = math.floor(math.min(t.width, BUBBLE_BOX_W) + 0.5)
t:draw({ x = math.floor(cx - w / 2 - cfg.x + 0.5),
y = math.floor(cy - t.height / 2 - cfg.y + 0.5),
x2 = w - t.width,
fade = fade })
end
local CREDIT_SCREENS = {
ENTRY = true,
PRACTICE_SELECT = true, RECORD_SELECT = true,
TITLE = true, RESULT = true,
-- DAN_SELECT, SONG_SELECT and AI_SELECT intentionally absent (no credit line there).
}
function CoinOverlay:draw(x, y)
local screen = tex.current_screen and tex.current_screen() or ""
-- unknown/blank screen keeps the always-on behaviour
local show_credit = (screen == "") or (CREDIT_SCREENS[screen] == true)
if show_credit then
local text_x = math.floor(tex.get_screen_width() / 2 - self.text.width / 2 - self.config.x + 0.5)
local text_y = math.floor(FREE_PLAY_CY - self.text.height / 2 - self.config.y + 0.5)
self.text:draw({ x = text_x, y = text_y })
end
if tex.in_transition and tex.in_transition() then return end
-- per-frame hook for a screen to draw above the credit text
if YD_DRAW_ABOVE_CREDIT then
local fn = YD_DRAW_ABOVE_CREDIT
YD_DRAW_ABOVE_CREDIT = nil
fn()
end
local chip_screens = (screen == "ENTRY" or screen == "SONG_SELECT" or screen == "SONG_SELECT_2P"
or screen == "PRACTICE_SELECT" or screen == "AI_SELECT" or screen == "RECORD_SELECT"
or screen == "DAN_SELECT")
if chip_screens and not (tex.in_transition and tex.in_transition()) then
local qr_ok = false -- no engine flag for "QR read" yet; frame 1 and its OK caption are ready for it
tex.draw_texture(self.qr, { frame = qr_ok and 1 or 0 })
draw_centered(qr_ok and self.qr_ok or self.qr_ng, QR.cx, QR.cy, QR.x, QR.y)
end
local scr = (screen ~= "") and screen or "ENTRY"
-- the 2P invite (AI_SELECT has none: the AI already holds the 2P side)
local on_entry_or_select = (scr == "ENTRY" or scr == "SONG_SELECT" or scr == "SONG_SELECT_2P"
or scr == "PRACTICE_SELECT")
local pn = tex.player_num()
local both_joined = (pn == 3) or (scr == "SONG_SELECT_2P")
or (scr == "ENTRY" and YD_ENTRY_BOTH_JOINED == true)
local credit_up = (scr == "ENTRY") and YD_ENTRY_CREDIT_MS ~= nil
and (tex.get_current_ms() - YD_ENTRY_CREDIT_MS) < 100
local join_window = (scr == "ENTRY") or not tex.songs_played or (tex.songs_played() < 2)
if on_entry_or_select and join_window and not credit_up and not both_joined and (pn == 1 or pn == 2) then
local side = (pn == 1) and 0 or 1
local cx_p = (pn == 1) and self.bubble_cfg_p.x or (tex.get_screen_width() - self.bubble_cfg_p.x)
local cx_m = (pn == 1) and self.bubble_cfg_m.x or (tex.get_screen_width() - self.bubble_cfg_m.x)
local elapsed = tex.get_current_ms() - self.blink_t0
local f = (elapsed * 0.06) % credit_side_len -- arcade frame 0..179
local pop = math.min(1, elapsed * 0.06 / credit_side_pop_f) -- pop-in on first show
local fade_t = blink(f) * pop
local fade = 0.6992 * fade_t
tex.draw_texture(self.bubble, { index = side, fade = fade })
draw_bubble_line(self.bubble_player, self.bubble_cfg_p, cx_p, BUBBLE_PLAYER_CY, fade_t)
draw_bubble_line(self.bubble_msg, self.bubble_cfg_m, cx_m, BUBBLE_MSG_CY, fade_t)
end
end