forked from Yonokid/PyTaikoGreen
110 lines
4.7 KiB
Lua
110 lines
4.7 KiB
Lua
Nameplate = {}
|
|
Nameplate.__index = Nameplate
|
|
|
|
local PLAYER_NUM_AI = 5
|
|
local PLAYER_NUM_ALL = 0
|
|
|
|
function Nameplate.new(name, title, player_num, dan, is_gold, is_rainbow, title_bg)
|
|
local self = setmetatable({}, Nameplate)
|
|
|
|
self.player_num = player_num
|
|
self.dan = dan
|
|
self.is_gold = is_gold
|
|
self.is_rainbow = is_rainbow
|
|
self.title_bg = title_bg
|
|
|
|
self.shadow = tex.load_texture("global/nameplate/shadow")
|
|
self.ai = tex.load_texture("global/nameplate/ai")
|
|
self.outline = tex.load_texture("global/nameplate/outline")
|
|
self.frame_top = tex.load_texture("global/nameplate/frame_top")
|
|
self.frame_top_rainbow = tex.load_texture("global/nameplate/frame_top_rainbow")
|
|
self.dan_emblem_bg = tex.load_texture("global/nameplate/dan_emblem_bg")
|
|
self.dan_emblem = tex.load_texture("global/nameplate/dan_emblem")
|
|
self.dan_emblem_gold = tex.load_texture("global/nameplate/dan_emblem_gold")
|
|
|
|
self.rainbow_anim = tex.get_animation(12, "global")
|
|
|
|
local name_cfg = tex.get_skin_config("nameplate_text_name")
|
|
local title_cfg = tex.get_skin_config("nameplate_text_title")
|
|
self.name_text = text.create_raw_text(name, name_cfg.font_size, { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 2)
|
|
self.title_text = text.create_raw_text(title, title_cfg.font_size, { 0, 0, 0, 255 }, { 0, 0, 0, 0 }, false, 0)
|
|
|
|
self.padding = tex.get_skin_config("nameplate_text_padding").x
|
|
self.name_offset = tex.get_skin_config("nameplate_name_offset").y
|
|
self.title_offset = tex.get_skin_config("nameplate_title_offset").y
|
|
|
|
self.outline_info = tex.get_texture_info("nameplate", "outline")
|
|
self.frame_top_info = tex.get_texture_info("nameplate", "frame_top")
|
|
self.emblem_info = tex.get_texture_info("nameplate", "dan_emblem")
|
|
|
|
if player_num ~= PLAYER_NUM_ALL and player_num ~= PLAYER_NUM_AI then
|
|
local pnum_key = tostring(player_num) .. "p"
|
|
self.pnum_tex = tex.get_id("nameplate", pnum_key)
|
|
self.pnum_info = tex.get_texture_info("nameplate", pnum_key)
|
|
end
|
|
|
|
return self
|
|
end
|
|
|
|
function Nameplate:update(current_ms)
|
|
self.rainbow_anim:update(current_ms)
|
|
end
|
|
|
|
function Nameplate:draw(x, y, fade)
|
|
fade = fade or 1.0
|
|
|
|
tex.draw_texture(self.shadow, { x = x, y = y, fade = math.min(0.5, fade) })
|
|
|
|
if self.player_num == PLAYER_NUM_AI then
|
|
tex.draw_texture(self.ai, { x = x, y = y })
|
|
return
|
|
end
|
|
|
|
local frame = (self.player_num == PLAYER_NUM_ALL) and 2 or self.title_bg
|
|
if self.is_rainbow then
|
|
local ra = self.rainbow_anim.attribute
|
|
if ra > 0 and ra < 6 then
|
|
tex.draw_texture(self.frame_top_rainbow, { frame = math.floor(ra) - 1, x = x, y = y, fade = fade })
|
|
end
|
|
tex.draw_texture(self.frame_top_rainbow, { frame = math.floor(ra), x = x, y = y, fade = fade })
|
|
else
|
|
tex.draw_texture(self.frame_top, { frame = frame, x = x, y = y, fade = fade })
|
|
end
|
|
|
|
tex.draw_texture(self.outline, { x = x, y = y, fade = fade })
|
|
|
|
local dan_offset = 0
|
|
if self.dan ~= -1 then
|
|
tex.draw_texture(self.dan_emblem_bg, { x = x, y = y, fade = fade })
|
|
if self.is_gold then
|
|
tex.draw_texture(self.dan_emblem_gold, { frame = self.dan, x = x, y = y, fade = fade })
|
|
else
|
|
tex.draw_texture(self.dan_emblem, { frame = self.dan, x = x, y = y, fade = fade })
|
|
end
|
|
dan_offset = self.emblem_info.width
|
|
end
|
|
|
|
local offset = 0
|
|
if self.player_num ~= PLAYER_NUM_ALL then
|
|
tex.draw_texture(self.pnum_tex, { x = x, y = y, fade = fade })
|
|
offset = self.pnum_info.width / 2.0
|
|
end
|
|
|
|
local outline_w = self.outline_info.width
|
|
local frame_top_w = self.frame_top_info.width
|
|
local frame_top_h = self.frame_top_info.height
|
|
local outline_h = self.outline_info.height
|
|
|
|
local name_max = frame_top_w - self.padding - offset - dan_offset
|
|
local name_width = math.min(self.name_text.width, name_max)
|
|
local name_x = x + offset + dan_offset + (outline_w - offset - dan_offset) / 2.0 - name_width / 2
|
|
local name_y = y + outline_h / 2.0 + self.name_offset
|
|
self.name_text:draw({ x = name_x, y = name_y, x2 = name_width - self.name_text.width, fade = fade })
|
|
|
|
local title_max = frame_top_w - self.padding - offset
|
|
local title_width = math.min(self.title_text.width, title_max)
|
|
local title_x = x + offset + (frame_top_w - offset) / 2.0 - title_width / 2
|
|
local title_y = y + frame_top_h / 2.0 - self.title_text.height / 2 + self.title_offset
|
|
self.title_text:draw({ x = title_x, y = title_y, x2 = title_width - self.title_text.width, fade = fade })
|
|
end
|