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

118 lines
4.5 KiB
Lua

ComboAnnounce = {}
ComboAnnounce.__index = ComboAnnounce
local CELL = 104.0
local GROUP_CX = 204.0 -- combo_num's origin inside the scroll
local PITCH_WIDE = 64.0
local PITCH_NARROW = 54.0
local SX_NARROW = 0.85
local NARROW_X0 = -70.0 -- leftmost cell, local to GROUP_CX
local TEXTMC_WIDE = 392.0
local TEXTMC_NARROW = 398.0
local TEXT_DX = -84.0
-- the cabinet's timeline (sixty fps): closed scroll fades in, pops open, holds, closes, fades out
local FRAME_MS = 1000 / 60
local F_IN = 6 -- first frame with any alpha
local F_OPEN = 12 -- the scroll swaps to its open shape, the digits start
local F_HOLD_END = 104
local F_CLOSE = 110
local F_END = 115
-- digits slide in from GROUP_CX + 10 to GROUP_CX while they fade (the pack's -66 -> -76)
local DIGIT_IN = { [12] = 10.0, [13] = 6.65, [14] = 3.35 }
-- the label used to be announce_text.png, whose rest position in combo/texture.json is (412, -148):
-- draw() x/y are offsets from a texture's rest position, so a text object needs them added by hand
local LABEL = { size = 44, fill = { 240, 192, 0, 255 }, rim = { 0, 0, 0, 255 }, thickness = 4,
rest_x = 412, rest_y = -148, cy = 23 }
-- sx, pitch, first_cx (centre of the leftmost cell, scroll frame), textmc_x
local function layout(digits)
if digits <= 3 then
return 1.0, PITCH_WIDE, GROUP_CX - PITCH_WIDE * (digits - 1) * 0.5, TEXTMC_WIDE
end
if digits == 4 then
return SX_NARROW, PITCH_NARROW, GROUP_CX + NARROW_X0, TEXTMC_NARROW
end
local k = 4.0 / digits
local pitch = PITCH_NARROW * k
return SX_NARROW * k, pitch, GROUP_CX + 92.0 - pitch * (digits - 1), TEXTMC_NARROW
end
local function alpha_at(f)
if f < F_IN then return 0 end
if f < F_IN + 3 then return (f - F_IN + 1) * 0.25 end -- 0.25, 0.5, 0.75
if f <= F_CLOSE then return 1 end -- held open through 110
if f >= F_END then return 0 end
return (F_END - 1 - f) / (F_END - 2 - F_CLOSE) -- 111..114: 1, 2/3, 1/3, 0
end
-- the digits (and the label) only exist while the scroll is open
local function digits_alpha(f)
if f < F_OPEN + 1 or f > F_HOLD_END then return 0 end
if f < F_OPEN + 4 then return (f - F_OPEN) / 3 end -- 0.33, 0.67, 1
if f <= F_HOLD_END - 4 then return 1 end
return (F_HOLD_END + 1 - f) * 0.2 -- 0.8, 0.6, 0.4, 0.2
end
function ComboAnnounce.new(combo, player_num)
local self = setmetatable({}, ComboAnnounce)
if tex.current_screen() == "AI_GAME" then return self end -- YataiDON's AI battle: no plate, as the cabinet's
local suffix = player_num .. "p"
self.t_closed = tex.get_texture("game/combo/announce_bg_closed_" .. suffix)
self.t_open = tex.get_texture("game/combo/announce_bg_open_" .. suffix)
self.t_flat = tex.get_texture("game/combo/announce_bg_" .. suffix)
self.t_digit = tex.get_texture("game/combo/announce_digit_" .. suffix)
self.number = tostring(combo)
self.label = text.create_raw_text(tex.skin_text("combo_announce_label"), LABEL.size, LABEL.fill, LABEL.rim,
false, LABEL.thickness, 2.0)
self.t0 = tex.get_current_ms()
return self
end
local function frame_of(self)
return (tex.get_current_ms() - self.t0) / FRAME_MS
end
function ComboAnnounce:draw(y, fade_value)
if not self.t_flat then return end
local f = frame_of(self)
if f < F_IN or f >= F_END then return end
local bg = self.t_flat
if f < F_OPEN or f > F_CLOSE then
bg = self.t_closed
elseif f < F_OPEN + 3 or (f > F_HOLD_END and f <= F_CLOSE) then
bg = self.t_open
end
tex.draw_texture(bg, { y = y, fade = alpha_at(f) })
local a = digits_alpha(f)
if a <= 0 or not self.t_digit then return end
local n = #self.number
local sx, pitch, first_cx, textmc_x = layout(n)
local dw = CELL * sx
local shift = DIGIT_IN[math.floor(f)] or 0
for i = 1, n do
local cx = first_cx + pitch * (i - 1) + shift
tex.draw_texture(self.t_digit, {
frame = tonumber(self.number:sub(i, i)),
x = cx - dw * 0.5,
y = y,
x2 = dw - CELL, -- horizontal condense only; sy stays 1
fade = a,
})
end
if self.label then
self.label:draw({
x = LABEL.rest_x + textmc_x + sx * TEXT_DX + shift,
y = LABEL.rest_y + y + LABEL.cy - self.label.height / 2,
fade = a,
})
end
end
return ComboAnnounce