66 lines
2.0 KiB
Lua
66 lines
2.0 KiB
Lua
ResultCrownMessage = {}
|
|
ResultCrownMessage.__index = ResultCrownMessage
|
|
|
|
local FRAME_MS = 1000 / 60
|
|
|
|
local MSG_FRAMES = 9 -- grow in and settle: 4 frames up to 1.2, 5 back to 1
|
|
|
|
-- frame (pre is_2p offset) is the judgement: 0 miss, 1 near, 2 success, 3 perfect
|
|
-- (result_player.lua's gauge_state/gauge_length -> frame mapping).
|
|
local MSG_KEY = {
|
|
[0] = "crown_message_miss",
|
|
[1] = "crown_message_near",
|
|
[2] = "crown_message_success",
|
|
[3] = "crown_message_perfect",
|
|
}
|
|
|
|
local MSG_W, MSG_H = 520, 340
|
|
local MSG_CENTER = {
|
|
{ 410 + MSG_W / 2, 626 + MSG_H / 2 }, -- 1P
|
|
{ 989 + MSG_W / 2, 626 + MSG_H / 2 }, -- 2P
|
|
}
|
|
|
|
function ResultCrownMessage.new(frame, is_2p)
|
|
local self = setmetatable({}, ResultCrownMessage)
|
|
self.t0 = tex.get_current_ms()
|
|
self.now = self.t0
|
|
self.frame = frame + (is_2p and 4 or 0)
|
|
self.is_2p = is_2p
|
|
self.t_msg = tex.get_texture("result/crown/message")
|
|
local key = MSG_KEY[frame]
|
|
self.t_text = key and text.create_text(key, { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 4, 2) or nil
|
|
return self
|
|
end
|
|
|
|
function ResultCrownMessage:update(current_ms)
|
|
self.now = current_ms
|
|
end
|
|
|
|
function ResultCrownMessage:draw()
|
|
if not self.t_msg then return end
|
|
local f = math.min((self.now - self.t0) * 0.06, MSG_FRAMES)
|
|
local scale, fade
|
|
if f < 4 then
|
|
local u = 1 - (1 - f / 4) ^ 2
|
|
scale, fade = 0.5 + 0.7 * u, u
|
|
else
|
|
scale, fade = 1.2 - 0.2 * ((f - 4) / 5) ^ 2, 1.0
|
|
end
|
|
if fade <= 0 then return end
|
|
tex.draw_texture(self.t_msg, {
|
|
frame = self.frame, scale = scale, center = true, fade = fade,
|
|
index = self.is_2p and 1 or 0,
|
|
})
|
|
|
|
local t = self.t_text
|
|
if t and t.width and t.width > 0 then
|
|
local c = MSG_CENTER[self.is_2p and 2 or 1]
|
|
local w, h = t.width * scale, t.height * scale
|
|
t:draw({
|
|
x = c[1] - w / 2, y = c[2] - h / 2,
|
|
x2 = w - t.width, y2 = h - t.height,
|
|
fade = fade,
|
|
})
|
|
end
|
|
end
|