2022-04-03 19:43:50 +02:00
|
|
|
require("common.class")
|
2022-04-05 17:31:02 +02:00
|
|
|
local Dim = require("common.dimensions")
|
2022-04-03 01:35:41 +02:00
|
|
|
local Page = require("components.pager.page")
|
2022-04-05 17:31:02 +02:00
|
|
|
local ServiceField = require("titlescreen.fields.service.servicefield")
|
2022-04-03 01:35:41 +02:00
|
|
|
|
|
|
|
---@class ServicePage: Page
|
2022-04-03 04:59:43 +02:00
|
|
|
---@field title string|string[]
|
2022-04-03 19:43:50 +02:00
|
|
|
---@field selectedIndex integer
|
2022-04-03 01:35:41 +02:00
|
|
|
---@field footer string[]
|
2022-04-03 04:59:43 +02:00
|
|
|
---@field content ServiceField[]
|
2022-04-03 01:35:41 +02:00
|
|
|
local ServicePage = {
|
2022-04-05 23:53:19 +02:00
|
|
|
__tostring = function () return "ServicePage" end,
|
2022-04-03 04:59:43 +02:00
|
|
|
SERVICE_DEFAULT_FONT_SIZE = ServiceField.SERVICE_DEFAULT_FONT_SIZE,
|
|
|
|
SERVICE_DEFAULT_FONT_FACE = ServiceField.SERVICE_DEFAULT_FONT_FACE,
|
|
|
|
SERVICE_DEFAULT_FONT_COLOR = ServiceField.SERVICE_DEFAULT_FONT_COLOR,
|
2022-04-03 01:35:41 +02:00
|
|
|
SERVICE_DEFAULT_MARGIN = {92, 128, 0, 56}, --{left, top, right, bottom}
|
|
|
|
SERVICE_DEFAULT_SPACING = 4,
|
|
|
|
SERVICE_DEFAULT_FOOTER = {
|
2022-04-03 22:08:31 +02:00
|
|
|
"A/B BUTTON = SELECT ITEM",
|
|
|
|
"START BUTTON = EXECUTE",
|
|
|
|
"BACK BUTTON = EXIT"
|
2022-04-03 01:35:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
---Create a new ServicePage instance
|
|
|
|
---
|
|
|
|
---Inherits from Page
|
|
|
|
---@return ServicePage
|
|
|
|
function ServicePage:new(o)
|
2022-04-03 19:43:50 +02:00
|
|
|
o = Inherit(self, Page, o)
|
2022-04-03 01:35:41 +02:00
|
|
|
|
|
|
|
o.title = o.title or ""
|
2022-04-03 19:43:50 +02:00
|
|
|
o.selectedIndex = o.selectedIndex or 1
|
2022-04-03 01:35:41 +02:00
|
|
|
o.footer = o.footer or self.SERVICE_DEFAULT_FOOTER
|
|
|
|
|
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
|
|
|
---Add field to page
|
|
|
|
---@param field Field
|
|
|
|
function ServicePage:addField(field)
|
2022-04-03 23:24:17 +02:00
|
|
|
field.posX = self.SERVICE_DEFAULT_MARGIN[1]
|
|
|
|
field.posY = self.SERVICE_DEFAULT_MARGIN[2] + #self.content * (self.SERVICE_DEFAULT_FONT_SIZE + self.SERVICE_DEFAULT_SPACING)
|
2022-04-03 01:35:41 +02:00
|
|
|
Page.addField(self, field)
|
|
|
|
end
|
|
|
|
|
2022-04-03 19:51:56 +02:00
|
|
|
function ServicePage:refreshFields()
|
|
|
|
for index, field in ipairs(self.content) do
|
2022-04-03 23:24:17 +02:00
|
|
|
field.posX = self.SERVICE_DEFAULT_MARGIN[1]
|
|
|
|
field.posY = self.SERVICE_DEFAULT_MARGIN[2] + (index - 1) * (self.SERVICE_DEFAULT_FONT_SIZE + self.SERVICE_DEFAULT_SPACING)
|
2022-04-03 19:51:56 +02:00
|
|
|
if index == self.selectedIndex then
|
|
|
|
field:focus()
|
|
|
|
else
|
|
|
|
field:deactivate()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Page.refreshFields(self)
|
|
|
|
end
|
|
|
|
|
2022-04-03 01:35:41 +02:00
|
|
|
function ServicePage:drawBackground(deltaTime)
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.FillColor(0, 0, 0)
|
2022-04-05 17:31:02 +02:00
|
|
|
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
|
2022-04-03 01:35:41 +02:00
|
|
|
gfx.Fill()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ServicePage:drawHeader(deltaTime)
|
2022-04-03 23:24:17 +02:00
|
|
|
local pageTopTitleMargin = self.SERVICE_DEFAULT_FONT_SIZE
|
|
|
|
local lineHeight = self.SERVICE_DEFAULT_FONT_SIZE + self.SERVICE_DEFAULT_SPACING
|
2022-04-03 01:35:41 +02:00
|
|
|
gfx.BeginPath()
|
2022-04-03 23:24:17 +02:00
|
|
|
gfx.FontSize(self.SERVICE_DEFAULT_FONT_SIZE)
|
|
|
|
gfx.LoadSkinFont(self.SERVICE_DEFAULT_FONT_FACE)
|
|
|
|
gfx.FillColor(table.unpack(self.SERVICE_DEFAULT_FONT_COLOR))
|
2022-04-03 01:35:41 +02:00
|
|
|
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_TOP)
|
2022-04-03 04:59:43 +02:00
|
|
|
if type(self.title) == "table" then
|
|
|
|
for index, line in ipairs(self.title) do
|
2022-04-05 17:31:02 +02:00
|
|
|
gfx.Text(line, Dim.design.width / 2, pageTopTitleMargin + (index-1) * lineHeight)
|
2022-04-03 04:59:43 +02:00
|
|
|
end
|
|
|
|
elseif type(self.title) == "string" then
|
2022-04-05 17:31:02 +02:00
|
|
|
gfx.Text(self.title, Dim.design.width / 2, pageTopTitleMargin)
|
2022-04-03 04:59:43 +02:00
|
|
|
end
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function ServicePage:drawFooter(deltaTime)
|
2022-04-03 19:43:50 +02:00
|
|
|
local footer = self.content[self.selectedIndex] and self.content[self.selectedIndex].footer or self.footer
|
2022-04-03 04:59:43 +02:00
|
|
|
|
2022-04-03 23:24:17 +02:00
|
|
|
local bottomPageMargin = self.SERVICE_DEFAULT_MARGIN[4]
|
|
|
|
local lineHeight = self.SERVICE_DEFAULT_FONT_SIZE + self.SERVICE_DEFAULT_SPACING
|
2022-04-03 04:59:43 +02:00
|
|
|
gfx.BeginPath()
|
2022-04-03 23:24:17 +02:00
|
|
|
gfx.FontSize(self.SERVICE_DEFAULT_FONT_SIZE)
|
|
|
|
gfx.LoadSkinFont(self.SERVICE_DEFAULT_FONT_FACE)
|
|
|
|
gfx.FillColor(table.unpack(self.SERVICE_DEFAULT_FONT_COLOR))
|
2022-04-03 04:59:43 +02:00
|
|
|
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_BOTTOM)
|
|
|
|
if type(footer) == "table" then
|
2022-04-05 17:31:02 +02:00
|
|
|
local yFooterBase = Dim.design.height - bottomPageMargin - #footer * lineHeight
|
2022-04-03 04:59:43 +02:00
|
|
|
for index, line in ipairs(footer) do
|
2022-04-05 17:31:02 +02:00
|
|
|
gfx.Text(line, Dim.design.width / 2, yFooterBase + (index-1) * lineHeight)
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
2022-04-03 04:59:43 +02:00
|
|
|
elseif type(footer) == "string" then
|
2022-04-05 17:31:02 +02:00
|
|
|
local yFooterBase = Dim.design.height - bottomPageMargin
|
|
|
|
gfx.Text(footer, Dim.design.width / 2, yFooterBase)
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
---Handle controller button input
|
|
|
|
---@param button integer
|
|
|
|
function ServicePage:handleButtonInput(button)
|
|
|
|
local stop_processing = false
|
2022-04-03 19:43:50 +02:00
|
|
|
local field = self.content[self.selectedIndex]
|
|
|
|
if field and field.handleButtonInput then
|
|
|
|
stop_processing = field:handleButtonInput(button)
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
|
|
|
|
2022-04-03 19:51:56 +02:00
|
|
|
field:deactivate()
|
|
|
|
|
2022-04-03 01:35:41 +02:00
|
|
|
-- default behaviour
|
|
|
|
if not stop_processing then
|
|
|
|
local direction = 0
|
|
|
|
|
|
|
|
if button == game.BUTTON_BCK then
|
|
|
|
if self.viewHandler then
|
|
|
|
self.viewHandler:back()
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if button == game.BUTTON_BTA then
|
|
|
|
direction = -1
|
|
|
|
elseif button == game.BUTTON_BTB then
|
|
|
|
direction = 1
|
|
|
|
end
|
|
|
|
|
2022-04-03 19:43:50 +02:00
|
|
|
self.selectedIndex = (self.selectedIndex - 1 + direction) % #self.content + 1
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
2022-04-03 19:51:56 +02:00
|
|
|
|
|
|
|
field = self.content[self.selectedIndex]
|
|
|
|
field:focus()
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
---Handle controller knob input
|
|
|
|
---@param knob integer
|
|
|
|
---@param delta number
|
|
|
|
function ServicePage:handleKnobInput(knob, delta)
|
2022-04-03 19:43:50 +02:00
|
|
|
if self.content[self.selectedIndex] and self.content[self.selectedIndex].handleKnobInput then
|
|
|
|
self.content[self.selectedIndex].handleKnobInput(knob, delta)
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-05 23:53:19 +02:00
|
|
|
return ServicePage
|