235 lines
9.1 KiB
Lua
235 lines
9.1 KiB
Lua
require("global/guide_panel")
|
|
|
|
CourseGuide = {}
|
|
CourseGuide.__index = CourseGuide
|
|
|
|
local ARCADE_FPS = 60
|
|
local LOOP = 420
|
|
local SELECT_X, DECIDE_X = -133, 40
|
|
local PILL_X, PILL_Y = -14, -28
|
|
|
|
local NAMES = {
|
|
"panel", "panel_decide", "pill", "drum", "rim_soft", "rim_sharp", "flash", "glow",
|
|
"stick_up_outline", "stick_up", "stick_lift_outline", "stick_lift", "stick_drop_outline", "stick_drop",
|
|
"tap_raised_outline", "tap_raised", "tap_a_outline", "tap_a", "tap_b_outline", "tap_b",
|
|
"tap_hold_outline", "tap_hold",
|
|
}
|
|
|
|
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
|
|
|
|
-- 1 on the frame of a hit, easing back to 0 over the next five
|
|
local function press(f, hits)
|
|
for i = 1, #hits do
|
|
local t = f - hits[i]
|
|
if t >= 0 and t < 5 then return 1 - t / 5 end
|
|
end
|
|
return 0
|
|
end
|
|
|
|
-- the rims breathe with a 20 frame period: down to half at phase 10, back to full at 19
|
|
local function pulse(f)
|
|
local p = f % 20
|
|
if p < 10 then return 1 - 0.05 * p end
|
|
if p < 19 then return 0.5 + 0.5 * (p - 10) / 9 end
|
|
return 1
|
|
end
|
|
|
|
-- select side: the left hand hits at 60 and 145, the right hand 210 frames later
|
|
local HANDS = {
|
|
{ shift = 0, hits = { 60, 145 }, fx = { 60, 145 }, p0 = { -26, -32 }, p1 = { -29.15, -43.2 }, p2 = { -29, -44 }, mirror = false,
|
|
rim_x = -48, rim_hit = { 1.32, 1.6 }, drum_hit = { 1.32, 1.52 }, flash_x = -21 },
|
|
{ shift = 210, hits = { 270, 354 }, fx = { 270, 355 }, p0 = { 2, -32 }, p1 = { 4.9, -43.25 }, p2 = { 5, -44 }, mirror = true,
|
|
rim_x = 0, rim_hit = { -0.36, 1.6 }, drum_hit = { 0.6, 1.52 }, flash_x = 21 },
|
|
}
|
|
local FLASH_Y = -34
|
|
|
|
local function raised(h, f)
|
|
local g = f - h.shift
|
|
local a = lerp(g, 0, 20, 0, 1) * (1 - lerp(g, 180, 190, 0, 1))
|
|
for i = 1, #h.hits do
|
|
if f >= h.hits[i] - 5 and f < h.hits[i] + 5 then a = 0 end
|
|
end
|
|
local x, y
|
|
if g < 40 then x, y = h.p0[1], h.p0[2]
|
|
elseif g < 54 then x, y = lerp(g, 40, 54, h.p0[1], h.p1[1]), lerp(g, 40, 54, h.p0[2], h.p1[2])
|
|
else x, y = lerp(g, 54, 64, h.p1[1], h.p2[1]), lerp(g, 54, 64, h.p1[2], h.p2[2]) end
|
|
return x, y, a
|
|
end
|
|
|
|
-- the stick just before (-5..0 frames) or after (0..5) a hit
|
|
local function swing(h, f, after)
|
|
for i = 1, #h.hits do
|
|
local t = f - h.hits[i]
|
|
if (after and t >= 0 and t < 5) or (not after and t >= -5 and t < 0) then return h.p2[1], h.p2[2], 1 end
|
|
end
|
|
return 0, 0, 0
|
|
end
|
|
|
|
-- decide side: both sticks fade in, tilt over the drum, tap it at frame 100, then hold
|
|
local TAPS = {
|
|
{ x = -49, mirror = false, tilt = { -43.45, -24.19, 5.526 }, rest = -46 },
|
|
{ x = 9, mirror = true, tilt = { 3.604, -20.33, -5.526 }, rest = 6 },
|
|
}
|
|
local TAP_Y, TAP_REST_Y = -15, -23
|
|
|
|
local function tap_pose(f)
|
|
if f < 85 then return "raised" end
|
|
if f < 95 then return "a" end
|
|
if f < 100 then return "b" end
|
|
return "hold"
|
|
end
|
|
|
|
local function tap_alpha(f)
|
|
if f < 85 then return lerp(f, 0, 20, 0, 1) end
|
|
if f < 100 then return 1 end
|
|
return 1 - lerp(f, 179, 190, 0, 1)
|
|
end
|
|
|
|
function CourseGuide.new()
|
|
local self = setmetatable({}, CourseGuide)
|
|
self.t0 = tex.get_current_ms()
|
|
self.id = {}
|
|
for _, n in ipairs(NAMES) do self.id[n] = tex.get_texture("global/course_guide/" .. n) end
|
|
return self
|
|
end
|
|
|
|
local K = 1
|
|
|
|
local function put(id, x, y, o)
|
|
if id and o.fade > 0.002 then
|
|
tex.draw_texture(id, { x = o.cx + x * K, y = o.cy + y * K, scale = (o.scale or 1) * K, rotation = o.rot,
|
|
origin = { 0, 0 },
|
|
mirror = o.mirror and "horizontal" or "none", fade = o.fade })
|
|
end
|
|
end
|
|
|
|
local function draw_sticks(self, cx, cy, fade, f, fill)
|
|
local suffix = fill and "" or "_outline"
|
|
for _, h in ipairs(HANDS) do
|
|
local x, y, a = raised(h, f)
|
|
put(self.id["stick_up" .. suffix], x, y, { cx = cx + SELECT_X * K, cy = cy, fade = a * fade, mirror = h.mirror })
|
|
x, y, a = swing(h, f, false)
|
|
put(self.id["stick_lift" .. suffix], x, y, { cx = cx + SELECT_X * K, cy = cy, fade = a * fade, mirror = h.mirror })
|
|
x, y, a = swing(h, f, true)
|
|
put(self.id["stick_drop" .. suffix], x, y, { cx = cx + SELECT_X * K, cy = cy, fade = a * fade, mirror = h.mirror })
|
|
end
|
|
end
|
|
|
|
function CourseGuide:draw_select(cx, cy, fade, f)
|
|
local ox = cx + SELECT_X * K
|
|
put(self.id.pill, PILL_X, PILL_Y, { cx = ox, cy = cy, fade = fade })
|
|
draw_sticks(self, cx, cy, fade, f, false)
|
|
|
|
for _, h in ipairs(HANDS) do
|
|
for i = 1, #h.fx do
|
|
local t = f - h.fx[i]
|
|
if t >= -1 and t < 10 then
|
|
local sc = (t < 5) and lerp(t, 0, 5, 0.8333, 1.25) or lerp(t, 5, 10, 1.25, 1.5)
|
|
local a = ((t < 0) and lerp(t, -1, 0, 0, 1) or 1) * (1 - lerp(t, 5, 10, 0, 1))
|
|
put(self.id.flash, h.flash_x - 20 * sc, FLASH_Y - 20 * sc, { cx = ox, cy = cy, fade = a * fade, scale = sc })
|
|
end
|
|
end
|
|
end
|
|
|
|
local function rims(art, front)
|
|
for k, h in ipairs(HANDS) do
|
|
local g = f - h.shift
|
|
local u = press(f, h.fx)
|
|
local a = pulse(f) * lerp(g, 0, 10, 0, 1) * (1 - lerp(g, 200, 209, 0, 1))
|
|
if g >= 0 and g < 210 then
|
|
put(self.id[art], h.rim_x + h.rim_hit[1] * u, -52 + h.rim_hit[2] * u,
|
|
{ cx = ox, cy = cy, fade = a * fade, scale = 1 - 0.02 * u, mirror = h.mirror })
|
|
end
|
|
end
|
|
end
|
|
rims("rim_soft")
|
|
|
|
local ul, ur = press(f, HANDS[1].fx), press(f, HANDS[2].fx)
|
|
put(self.id.drum, -48 + HANDS[1].drum_hit[1] * ul + HANDS[2].drum_hit[1] * ur,
|
|
-48 + 1.52 * (ul + ur), { cx = ox, cy = cy, fade = fade, scale = 1 - 0.02 * (ul + ur) })
|
|
rims("rim_sharp")
|
|
draw_sticks(self, cx, cy, fade, f, true)
|
|
end
|
|
|
|
function CourseGuide:draw_decide(cx, cy, fade, f)
|
|
local ox = cx + DECIDE_X * K
|
|
put(self.id.pill, PILL_X, PILL_Y, { cx = ox, cy = cy, fade = fade })
|
|
|
|
local function sticks(fill)
|
|
for _, s in ipairs(TAPS) do
|
|
local pose, a = tap_pose(f), tap_alpha(f)
|
|
local name, x, y, rot = nil, s.rest, TAP_REST_Y, 0
|
|
if pose == "raised" then
|
|
name, x, y = "tap_raised", s.x, TAP_Y
|
|
if f >= 70 then
|
|
local k = lerp(f, 70, 84, 0, 1)
|
|
x, y, rot = s.x + (s.tilt[1] - s.x) * k, TAP_Y + (s.tilt[2] - TAP_Y) * k, s.tilt[3] * k
|
|
end
|
|
elseif pose == "a" then name = "tap_a"
|
|
elseif pose == "b" then name = "tap_b"
|
|
else name = "tap_hold" end
|
|
put(self.id[name .. (fill and "" or "_outline")], x, y,
|
|
{ cx = ox, cy = cy, fade = a * fade, rot = rot, mirror = s.mirror })
|
|
end
|
|
end
|
|
sticks(false)
|
|
|
|
local k = (f >= 100 and f < 105) and lerp(f, 100, 105, 1, 0) or 0
|
|
put(self.id.drum, -48 + 1.92 * k, -48 + 3.27 * k, { cx = ox, cy = cy, fade = fade, scale = 1 - 0.04 * k })
|
|
|
|
if f < 100 then
|
|
local a = (f < 20) and lerp(f, 0, 20, 0, 1) or (1 - 0.5 * (1 - math.abs((f - 20) % 20 - 10) / 10))
|
|
put(self.id.glow, -40, -40, { cx = ox, cy = cy, fade = a * fade })
|
|
elseif f < 120 then
|
|
local early = f < 105
|
|
local sc = early and lerp(f, 100, 105, 1, 1.625) or lerp(f, 105, 120, 1.625, 1.75)
|
|
local a = early and lerp(f, 100, 105, 1, 0.75) or lerp(f, 105, 120, 0.75, 0)
|
|
local x = early and lerp(f, 100, 105, -40, -65) or lerp(f, 105, 120, -65, -70)
|
|
local y = early and lerp(f, 100, 105, -40, -58.75) or lerp(f, 105, 120, -58.75, -62.5)
|
|
put(self.id.glow, x, y, { cx = ox, cy = cy, fade = a * fade, scale = sc })
|
|
end
|
|
sticks(true)
|
|
end
|
|
|
|
-- the guide centred on (cx, cy): select hands on the left, the decide tap on the right
|
|
function CourseGuide:draw(cx, cy, fade, scale)
|
|
fade = fade or 1.0
|
|
K = scale or 1
|
|
local f = (tex.get_current_ms() - self.t0) * ARCADE_FPS / 1000 % LOOP
|
|
if self.id.panel then
|
|
tex.draw_texture(self.id.panel, { x = cx - 186 * K, y = cy - 48 * K, scale = K, fade = fade })
|
|
end
|
|
self:draw_select(cx, cy, fade, f)
|
|
self:draw_decide(cx, cy, fade, f % 210)
|
|
K = 1
|
|
end
|
|
|
|
-- the result screen's guide: one drum, pill and label on the short panel, with the decide label
|
|
function CourseGuide:draw_confirm(cx, cy, fade, scale)
|
|
fade = fade or 1.0
|
|
K = scale or 0.806
|
|
local f = (tex.get_current_ms() - self.t0) * ARCADE_FPS / 1000
|
|
if self.id.panel_decide then
|
|
tex.draw_texture(self.id.panel_decide, { x = cx - 132 * K, y = cy - 44 * K, scale = K, fade = fade })
|
|
end
|
|
self:draw_decide(cx - (33 + DECIDE_X) * K, cy, fade, f % 210)
|
|
local cfg = tex.get_skin_config("guide_decide_label")
|
|
if cfg and not self.label then
|
|
self.label = text.create_raw_text(tex.skin_text("guide_decide_label"), GuidePanel.label_size(cfg.font_size or 24),
|
|
{ 40, 40, 40, 255 }, { 0, 0, 0, 0 }, false, 2.0, 1.0, 0.0,
|
|
GuidePanel.label_font())
|
|
end
|
|
local t = self.label
|
|
if t then
|
|
t:draw({ x = math.floor(cx + 44 * K - (t.width - 2.0) / 2 + 0.5), y = math.floor(cy + 2 * K - t.height / 2 + 0.5),
|
|
fade = fade })
|
|
end
|
|
K = 1
|
|
end
|
|
|
|
return CourseGuide
|