Files
PyTaikoGreen/Scripts/song_select/file_navigator/genre_bg.lua
T
2026-11-16 22:55:30 -05:00

90 lines
2.9 KiB
Lua

local S = tex.get_screen_scale()
local TITLE = { y = 44 * S, width = 300 * S }
local FOLDER_TITLE = { x = 642 * S, y = 54 * S }
local EDGE_OVERLAP = 5 * S
local function T(name)
return tex.get_texture("song_select/box/" .. name)
end
local function G(gb, name)
return (gb:has_gradient() and gb:gradient_texture(name)) or T(name)
end
local infos = {}
local function info(name)
local i = infos[name]
if i == nil then
local raw = tex.get_texture_info("box", name)
i = { x = 0, y = 0, width = 0, height = 0 }
if raw then
i = { x = raw.x[1] or 0, y = raw.y[1] or 0, width = raw.width, height = raw.height }
end
infos[name] = i
end
return i
end
local function centre_y()
local body = info("folder_background")
return body.y + body.height / 2
end
local function piece(gb, name, x, w, mirrored, fade)
local i = info(name)
local cx, cy = gb.center, centre_y()
local params = {
frame = gb:texture_frame(),
x = cx + (x - cx) * gb.scale_x - i.x,
y = cy + (i.y - cy) * gb.scale_y - i.y,
x2 = w * gb.scale_x - i.width,
y2 = i.height * (gb.scale_y - 1),
fade = fade,
}
if mirrored then params.mirror = "horizontal" end
tex.draw_texture(G(gb, name), params)
end
local function span(gb, left, right, fade)
local edge = info("folder_background_edge").width
local fill_left = left + edge - EDGE_OVERLAP
local fill_right = right - edge + EDGE_OVERLAP
piece(gb, "folder_background_edge", left - EDGE_OVERLAP, edge, true, fade)
if fill_left < fill_right then
piece(gb, "folder_background", fill_left, fill_right - fill_left, false, fade)
end
piece(gb, "folder_background_edge", fill_right, edge, false, fade)
end
local function tab(gb, width, fade)
local edge = info("folder_background_folder_edge").width
local left = gb.center - width / 2
piece(gb, "folder_background_folder_edge", left - edge, edge, true, fade)
piece(gb, "folder_background_folder", left, width, false, fade)
piece(gb, "folder_background_folder_edge", left + width, edge, false, fade)
end
function SongSelect:draw_genre_bg(gb)
local fade = gb.fade
local name = gb:name()
local width = math.min(TITLE.width, name.width)
local recolor = gb:has_recolor()
if recolor then gb:begin_recolor() end
span(gb, gb.left, gb.right, fade)
if gb.wrap_left then
span(gb, gb.wrap_left, gb.wrap_right, fade)
end
if gb.show_tab then
tab(gb, width, fade)
end
if recolor then gb:end_recolor() end
if not gb.show_tab then return end
local kx = (gb.scale_x - 0.96) / 0.04
local ky = (gb.scale_y - 0.92) / 0.08
local x = FOLDER_TITLE.x + (gb.center - FOLDER_TITLE.x) * kx
local y = FOLDER_TITLE.y + (TITLE.y - FOLDER_TITLE.y) * ky
name:draw({ x = x - width / 2, y = y, x2 = width - name.width, fade = gb.title_fade })
end