71 lines
3.0 KiB
Lua
71 lines
3.0 KiB
Lua
SongInfo = {}
|
|
SongInfo.__index = SongInfo
|
|
|
|
local WHITE, BLACK, RED, BLANK = { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, { 255, 0, 0, 255 }, { 0, 0, 0, 0 }
|
|
local GENRE_PLATE_COLOR = { 60, 103, 0 } -- the plate texture's colour, replaced by the genre's
|
|
|
|
local function outline_of(cfg)
|
|
return cfg.outline >= 0 and cfg.outline or 5.0
|
|
end
|
|
|
|
function SongInfo.new(title, subtitle, number, genre_label, genre_color)
|
|
local self = setmetatable({}, SongInfo)
|
|
self.fade = tex.get_animation(3)
|
|
self.genre_color = genre_color
|
|
|
|
self.title_cfg = tex.get_skin_config("game_song_info")
|
|
self.title = text.create_raw_text(title, self.title_cfg.font_size, WHITE, BLACK, false, outline_of(self.title_cfg))
|
|
local max_width_cfg = tex.get_skin_config("game_song_info_max_width")
|
|
self.max_width = max_width_cfg and max_width_cfg.width
|
|
if subtitle ~= "" then
|
|
self.sub_cfg = tex.get_skin_config("game_song_info_subtitle")
|
|
self.subtitle = text.create_raw_text(subtitle, self.sub_cfg.font_size, WHITE, BLACK, false, 5)
|
|
end
|
|
|
|
local num_cfg = tex.get_skin_config("song_num") or { font_size = 0, outline = -1 }
|
|
local fmt = tex.skin_text("song_num")
|
|
if fmt == "" then fmt = "{0}" end
|
|
local limit = tex.song_limit()
|
|
self.number = text.create_raw_text((fmt:gsub("{0}", tostring(number))), num_cfg.font_size, WHITE,
|
|
(limit > 0 and limit == number) and RED or BLACK, false, outline_of(num_cfg))
|
|
|
|
self.genre = tex.get_texture("song_info/genre")
|
|
self.genre_info = tex.get_texture_info("song_info", "genre")
|
|
self.genre_text = text.create_raw_text(genre_label, 18 * tex.get_screen_scale(), WHITE, BLANK, false, 3, 1)
|
|
return self
|
|
end
|
|
|
|
function SongInfo:update(current_ms)
|
|
self.fade:update(current_ms)
|
|
end
|
|
|
|
function SongInfo:draw(dx, dy)
|
|
local fade = self.fade.attribute
|
|
local text_x = self.title_cfg.x + dx
|
|
local text_y = self.title_cfg.y + dy - self.title.height / 2
|
|
|
|
self.number:draw({ x = text_x - self.number.width, y = text_y, fade = fade })
|
|
|
|
local title_w, title_x2 = self.title.width, 0
|
|
local max_width = self.max_width
|
|
if max_width and max_width > 0 and title_w > max_width then
|
|
title_x2 = max_width - title_w
|
|
title_w = max_width
|
|
end
|
|
self.title:draw({ x = text_x - title_w, y = text_y, x2 = title_x2, fade = 1 - fade })
|
|
|
|
if self.subtitle then
|
|
self.subtitle:draw({ x = text_x - self.subtitle.width, y = self.sub_cfg.y + dy - self.subtitle.height / 2,
|
|
fade = 1 - fade })
|
|
end
|
|
|
|
local info = self.genre_info
|
|
local genre_dy = (self.subtitle and self.subtitle.height or 0) + dy
|
|
tex.begin_recolor(GENRE_PLATE_COLOR, self.genre_color)
|
|
tex.draw_texture(self.genre, { x = dx, y = genre_dy, fade = 1 - fade })
|
|
tex.end_recolor()
|
|
self.genre_text:draw({ x = info.x[1] + dx + info.width / 2 - self.genre_text.width / 2,
|
|
y = info.y[1] + genre_dy + info.height / 2 - self.genre_text.height / 2,
|
|
fade = 1 - fade })
|
|
end
|