Files
PyTaikoGreen/Scripts/song_select/ai_support_menu.lua
T
2026-11-05 14:42:40 -05:00

108 lines
3.4 KiB
Lua

AISupportMenu = {}
AISupportMenu.__index = AISupportMenu
local FRAME_MS = 1000 / 60
local DIR = "song_select/ai_battle/"
local P2_OFFSET = 836
local BOARD_OFFSETS = { [1] = { 0 }, [4] = { -117, -39, 38, 116 } }
local COURSES = {
[0] = { board = "subdiff_easy", count = 1 },
[1] = { board = "subdiff_normal", count = 4 },
[2] = { board = "subdiff_hard", count = 4 },
[3] = { board = "subdiff_oni", count = 4 },
}
local SLIDE_IN = { { 0, 0, 0.2 }, { 5, -124, 1 }, { 15, -373, 1 }, { 21, -356, 1 } }
local SLIDE_OUT = { { 0, -356, 1 }, { 15, -89, 1 }, { 20, 0, 0 } }
local GRAY_FRAMES, GRAY_FADE = 30, 0.4
local GLOW_PERIOD, GLOW_LOW = 120, 0.7
local BRANCH_PERIOD = 120
local function slide_at(keys, frame)
for i = 2, #keys do
local a, b = keys[i - 1], keys[i]
if frame <= b[1] then
local t = math.max(0, (frame - a[1]) / (b[1] - a[1]))
return a[2] + (b[2] - a[2]) * t, a[3] + (b[3] - a[3]) * t
end
end
return keys[#keys][2], keys[#keys][3]
end
local function wave(frame, period, from, to)
local t = 1 - math.abs(2 * (frame % period) / period - 1)
return from + (to - from) * t
end
function AISupportMenu.new()
local self = setmetatable({}, AISupportMenu)
self.ids = {}
self.shown = false
self.slide_ms = -math.huge
self.course = 0
self.choose_ms = nil
return self
end
function AISupportMenu:id(key)
self.ids[key] = self.ids[key] or tex.get_texture(DIR .. key)
return self.ids[key]
end
function AISupportMenu:draw(ms, course, cursor, choosing, branching, player)
local keys = self.shown and SLIDE_IN or SLIDE_OUT
local frame = (ms - self.slide_ms) / FRAME_MS
if (course >= 0) ~= self.shown and frame >= keys[#keys][1] then
self.shown = course >= 0
self.slide_ms = ms
keys = self.shown and SLIDE_IN or SLIDE_OUT
frame = 0
end
if not self.shown and frame >= keys[#keys][1] then
return
end
if self.shown then
self.course = course
end
local y, fade = slide_at(keys, frame)
local x = player == 2 and P2_OFFSET or 0
local function draw(key, params)
params = params or {}
params.x, params.y = (params.x or 0) + x, (params.y or 0) + y
params.fade = (params.fade or 1) * fade
tex.draw_texture(self:id(key), params)
end
if choosing and not self.choose_ms then
self.choose_ms = ms
end
if choosing then
local gray = math.min(1, (ms - self.choose_ms) / FRAME_MS / GRAY_FRAMES)
tex.draw_texture(self:id("gray_filter"), { x2 = 1264, y2 = 704, fade = GRAY_FADE * gray })
draw("box_bg", { fade = wave(ms / FRAME_MS, GLOW_PERIOD, 1, GLOW_LOW) })
draw("box_bg_blur")
draw("box_2")
draw("subdiff_select_text")
draw(player == 2 and "2p" or "1p")
else
draw("box_1")
end
local info = COURSES[self.course]
local offsets = BOARD_OFFSETS[info.count]
local row = info.count == 1 and 1 or 0
for i = 0, info.count - 1 do
local board_x = offsets[i + 1]
if choosing and i == cursor then
draw("subdiff_selector", { x = board_x, y = row })
end
draw(info.board, { frame = i, x = board_x, y = row })
if branching then
draw("branch_indicator", { x = board_x, y = row, fade = wave(ms / FRAME_MS, BRANCH_PERIOD, 0, 1) })
end
end
draw("bottom_text")
end