forked from Yonokid/PyTaikoGreen
126 lines
5.6 KiB
Lua
126 lines
5.6 KiB
Lua
CostumeMenu = {}
|
|
CostumeMenu.__index = CostumeMenu
|
|
|
|
local ITEM_W = 80.0
|
|
|
|
local ITEM_KEYS = {
|
|
"costume", "default", "head_body",
|
|
"preset_1", "preset_2", "preset_3", "random_item",
|
|
}
|
|
|
|
function CostumeMenu.new(is_2p, text_str, title_x, title_y)
|
|
local self = setmetatable({}, CostumeMenu)
|
|
self.is_2p = is_2p
|
|
|
|
local suffix = is_2p and "2p" or "1p"
|
|
|
|
-- Box frame
|
|
self.box_top_left = tex.load_texture("entry/costume_select/box_top_left_" .. suffix)
|
|
self.box_top_right = tex.load_texture("entry/costume_select/box_top_right_" .. suffix)
|
|
self.box_bot_left = tex.load_texture("entry/costume_select/box_bottom_left_" .. suffix)
|
|
self.box_bot_right = tex.load_texture("entry/costume_select/box_bottom_right_" .. suffix)
|
|
self.box_top = tex.load_texture("entry/costume_select/box_top_" .. suffix)
|
|
self.box_bottom = tex.load_texture("entry/costume_select/box_bottom_" .. suffix)
|
|
self.box_left = tex.load_texture("entry/costume_select/box_left_" .. suffix)
|
|
self.box_right = tex.load_texture("entry/costume_select/box_right_" .. suffix)
|
|
self.box_center = tex.load_texture("entry/costume_select/box_center_" .. suffix)
|
|
self.item_box = tex.load_texture("entry/costume_select/item_box_" .. suffix)
|
|
self.item_box_hl = tex.load_texture("entry/costume_select/item_box_highlighted")
|
|
self.blue_arrow = tex.load_texture("entry/costume_select/blue_arrow")
|
|
self.text_hl = tex.load_texture("entry/costume_select/text_highlight_" .. suffix)
|
|
|
|
-- Menu items
|
|
self.items = {}
|
|
for _, key in ipairs(ITEM_KEYS) do
|
|
local id = tex.load_texture("entry/costume_select/" .. key)
|
|
local info = tex.get_texture_info("costume_select", key)
|
|
self.items[#self.items + 1] = {
|
|
id = id,
|
|
width = info and info.width or ITEM_W,
|
|
height = info and info.height or ITEM_W,
|
|
}
|
|
end
|
|
|
|
-- Positioning info
|
|
self.ib_info = tex.get_texture_info("costume_select", "item_box_1p")
|
|
self.hl_info = tex.get_texture_info("costume_select", "item_box_highlighted")
|
|
self.arr_info = tex.get_texture_info("costume_select", "blue_arrow")
|
|
self.bc_info = tex.get_texture_info("costume_select", "box_center_" .. suffix)
|
|
self.th_info = tex.get_texture_info("costume_select", "text_highlight_" .. suffix)
|
|
|
|
-- Animations
|
|
self.blue_arrow_fade = tex.get_animation(13, "entry")
|
|
self.blue_arrow_move = tex.get_animation(14, "entry")
|
|
self.blue_arrow_fade:start()
|
|
self.blue_arrow_move:start()
|
|
|
|
-- Title text
|
|
local font_size = tex.get_skin_config("entry_costume_text").font_size
|
|
self.title_text = text.create_raw_text(text_str, font_size, { 255, 255, 255, 255 }, { 0, 0, 0, 255 }, false, 5, 2.0)
|
|
self.title_x_offset = title_x
|
|
self.title_y_offset = title_y
|
|
|
|
return self
|
|
end
|
|
|
|
function CostumeMenu:update(current_ms)
|
|
self.blue_arrow_fade:update(current_ms)
|
|
self.blue_arrow_move:update(current_ms)
|
|
end
|
|
|
|
function CostumeMenu:draw_bg(x, y, selected_index, costume_select_mode)
|
|
tex.draw_texture(self.box_top_left, { x = x, y = y })
|
|
tex.draw_texture(self.box_top_right, { x = x, y = y })
|
|
tex.draw_texture(self.box_bot_left, { x = x, y = y })
|
|
tex.draw_texture(self.box_bot_right, { x = x, y = y })
|
|
tex.draw_texture(self.box_top, { x = x, y = y })
|
|
tex.draw_texture(self.box_bottom, { x = x, y = y })
|
|
tex.draw_texture(self.box_left, { x = x, y = y })
|
|
tex.draw_texture(self.box_right, { x = x, y = y })
|
|
tex.draw_texture(self.box_center, { x = x, y = y })
|
|
|
|
tex.draw_texture(self.item_box, { x = x + ITEM_W * 0, y = y })
|
|
tex.draw_texture(self.item_box, { x = x + ITEM_W * 1, y = y })
|
|
tex.draw_texture(self.item_box_hl, { x = x + ITEM_W * 2, y = y })
|
|
tex.draw_texture(self.item_box, { x = x + ITEM_W * 3, y = y })
|
|
tex.draw_texture(self.item_box, { x = x + ITEM_W * 4, y = y })
|
|
|
|
if not costume_select_mode then
|
|
local base_x = self.ib_info.x[1] + x
|
|
local base_y = self.ib_info.y[1] + y
|
|
local n = #self.items
|
|
for i = 0, 4 do
|
|
local idx = ((selected_index - 2 + i) % n) + 1
|
|
local item = self.items[idx]
|
|
if item and item.id then
|
|
local ix = base_x + i * ITEM_W + (ITEM_W - item.width) / 2
|
|
local iy = base_y + (ITEM_W - item.height) / 2
|
|
tex.draw_texture(item.id, { x = ix, y = iy })
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function CostumeMenu:draw_fg(x, y)
|
|
local hl = self.hl_info
|
|
local arr = self.arr_info
|
|
local hl_left = hl.x[1] + x + ITEM_W * 2
|
|
local hl_right = hl_left + hl.width
|
|
local arr_y = hl.y[1] + y + (hl.height - arr.height) / 2
|
|
local move_val = self.blue_arrow_move.attribute
|
|
local fade_val = self.blue_arrow_fade.attribute
|
|
|
|
tex.draw_texture(self.blue_arrow, { mirror = "horizontal", x = hl_right + move_val, y = arr_y, fade = fade_val })
|
|
tex.draw_texture(self.blue_arrow, { x = hl_left - arr.width - move_val, y = arr_y, fade = fade_val })
|
|
|
|
if self.text_hl and self.th_info then
|
|
local th = self.th_info
|
|
tex.draw_texture(self.text_hl, { x = x - th.width / 2, y = y - th.height / 2 })
|
|
end
|
|
|
|
local bc = self.bc_info
|
|
local bc_width = (bc.x2 and bc.x2[1]) or bc.width
|
|
local cx = bc.x[1] + x + bc_width / 2 - self.title_text.width / 2
|
|
self.title_text:draw({ x = cx + self.title_x_offset, y = y + self.title_y_offset })
|
|
end
|