Files
YataiDONNijiiro/Scripts/song_select/score_history.lua
T

127 lines
5.0 KiB
Lua

local SKIN = {
score_info_counter_margin = { x = 28, width = 21 },
}
ScoreHistory = {}
ScoreHistory.__index = ScoreHistory
local DIFF_URA = 4
function ScoreHistory.new(available, is_shinuchi, current_ms)
local self = setmetatable({}, ScoreHistory)
self.available = available
self.is_shinuchi = is_shinuchi
self.last_ms = current_ms
self.curr_index = #available > 0 and ((1 % #available) + 1) or 0
local s = tex.get_screen_scale()
local margin = SKIN.score_info_counter_margin
self.offset_y = 50 * s
self.margin_w = margin and margin.width or 0
self.margin_x = margin and margin.x or 0
local title_cfg = { x = 76 * s, y = 275 * s, width = 134 * s, height = 27 * s }
self.title_pos = title_cfg
self.title = nil
local label = tex.skin_text("leaderboard_title")
if label ~= "" then
local font_size = title_cfg.height
while font_size > 8 do
local t = text.create_raw_text(label, font_size, { 0, 0, 0, 255 }, { 0, 0, 0, 0 }, false, 0, 2.0)
if t.width <= title_cfg.width then
self.title = t
break
end
font_size = font_size - 1
end
if not self.title then
self.title = text.create_raw_text(label, 8, { 0, 0, 0, 255 }, { 0, 0, 0, 0 }, false, 0, 2.0)
end
end
self.t_background_2 = tex.get_texture("song_select/leaderboard/background_2")
self.t_shinuchi = tex.get_texture("song_select/leaderboard/shinuchi")
self.t_shinuchi_ura = tex.get_texture("song_select/leaderboard/shinuchi_ura")
self.t_pts = tex.get_texture("song_select/leaderboard/pts")
self.t_normal = tex.get_texture("song_select/leaderboard/normal")
self.t_difficulty = tex.get_texture("song_select/leaderboard/difficulty")
self.t_judge_good = tex.get_texture("song_select/leaderboard/judge_good")
self.t_judge_ok = tex.get_texture("song_select/leaderboard/judge_ok")
self.t_judge_bad = tex.get_texture("song_select/leaderboard/judge_bad")
self.t_judge_drumroll = tex.get_texture("song_select/leaderboard/judge_drumroll")
self.t_counter = tex.get_texture("song_select/leaderboard/counter")
self.t_judge_num = tex.get_texture("song_select/leaderboard/judge_num")
return self
end
function ScoreHistory:update(current_ms)
if #self.available == 0 then return end
if current_ms >= self.last_ms + 1000.0 then
self.last_ms = current_ms
self.curr_index = (self.curr_index % #self.available) + 1
end
end
function ScoreHistory:draw()
if #self.available == 0 then return end
local entry = self.available[self.curr_index]
local diff = entry.diff
if self.t_background_2 then tex.draw_texture(self.t_background_2) end
if self.title then self.title:draw({ x = self.title_pos.x, y = self.title_pos.y }) end
if self.is_shinuchi then
if diff == DIFF_URA then
if self.t_shinuchi_ura then tex.draw_texture(self.t_shinuchi_ura, { index = 1 }) end
else
if self.t_shinuchi then tex.draw_texture(self.t_shinuchi, { index = 1 }) end
end
if self.t_pts then tex.draw_texture(self.t_pts, { color = { 255, 255, 255, 255 }, index = 1 }) end
else
if self.t_normal then tex.draw_texture(self.t_normal, { index = 1 }) end
if self.t_pts then tex.draw_texture(self.t_pts, { color = { 0, 0, 0, 255 }, index = 1 }) end
end
if self.t_difficulty then tex.draw_texture(self.t_difficulty, { frame = diff, index = 1 }) end
for i = 0, 3 do
if self.t_normal then
tex.draw_texture(self.t_normal, { y = self.offset_y + i * self.offset_y, index = 1 })
end
end
if self.t_judge_good then tex.draw_texture(self.t_judge_good) end
if self.t_judge_ok then tex.draw_texture(self.t_judge_ok) end
if self.t_judge_bad then tex.draw_texture(self.t_judge_bad) end
if self.t_judge_drumroll then tex.draw_texture(self.t_judge_drumroll) end
local values = { entry.score, entry.good, entry.ok, entry.bad, entry.drumroll }
local score_color = self.is_shinuchi and { 255, 255, 255, 255 } or { 0, 0, 0, 255 }
for j = 1, 5 do
local counter = tostring(values[j])
local len = #counter
if j == 1 then
for i = 1, len do
local digit = tonumber(string.sub(counter, i, i)) or 0
local x = -((len * self.margin_w) / 2.0) + ((i - 1) * self.margin_w)
if self.t_counter then
tex.draw_texture(self.t_counter, { color = score_color, frame = digit, x = x, index = 1 })
end
end
else
for i = 1, len do
local digit = tonumber(string.sub(counter, i, i)) or 0
local x = -(len - i + 1) * self.margin_x
local y = (j - 1) * self.offset_y
if self.t_judge_num then
tex.draw_texture(self.t_judge_num, { frame = digit, x = x, y = y })
end
end
end
end
end