ExperimentalGear/scripts/titlescreen/service/common.lua

52 lines
1.6 KiB
Lua
Raw Normal View History

local dim = require("common.dimensions")
PAGE_DEFAULT_FONT_SIZE = 24
PAGE_DEFAULT_FONT_FACE = "dfmarugoth.ttf"
PAGE_DEFAULT_FONT_COLOR = {255, 255, 255, 255}
PAGE_DEFAULT_MARGIN = {72, 24, 0, 56} --{left, top, right, bottom}
PAGE_DEFAULT_SPACING = 4
PAGE_DEFAULT_FOOTER = {
"BT-A/BT-B = UP/DOWN",
"START = SELECT",
"BACK = RETURN TO LAST PAGE"
}
function DrawPageFooter(footer)
local bottomPageMargin = PAGE_DEFAULT_MARGIN[4]
local lineHeight = PAGE_DEFAULT_FONT_SIZE + PAGE_DEFAULT_SPACING
gfx.BeginPath()
gfx.FontSize(PAGE_DEFAULT_FONT_SIZE)
gfx.LoadSkinFont(PAGE_DEFAULT_FONT_FACE)
gfx.FillColor(table.unpack(PAGE_DEFAULT_FONT_COLOR))
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_BOTTOM)
if type(footer) == "table" then
for index, line in ipairs(footer) do
local yFooterBase = dim.design.height - bottomPageMargin - #footer * lineHeight
gfx.Text(line, 1080 / 2, yFooterBase + (index-1) * lineHeight)
end
elseif type(footer) == "string" then
local yFooterBase = dim.design.height - bottomPageMargin
gfx.Text(footer, 1080 / 2, yFooterBase)
end
end
---Default button input handler
---@param page Page
---@param button integer
function HandlePageButtonInput(page, button)
local direction = 0
if button == game.BUTTON_BCK then
page.viewHandler:back()
return
end
if button == game.BUTTON_BTA then
direction = -1
elseif button == game.BUTTON_BTB then
direction = 1
end
page.selectedIdx = (page.selectedIdx - 1 + direction) % #page.fields + 1
end