ExperimentalGear/scripts/titlescreen/boot/checkupdatepage.lua

95 lines
2.7 KiB
Lua
Raw Normal View History

2022-04-24 01:39:48 +02:00
require("common.class")
2024-02-02 02:50:48 +01:00
local Display = require("scripts.graphics.display")
2022-04-27 12:29:54 +02:00
local Page = require("api.page.page")
local CheckUpdateField = require("titlescreen.boot.checkupdatefield")
local DialogField = require("titlescreen.boot.dialogfield")
2022-04-24 01:39:48 +02:00
---@class CheckUpdatePage: Page
---@field _focusedField CheckUpdateField
2022-04-24 01:39:48 +02:00
local CheckUpdatePage = {
__name = "CheckUpdatePage",
2022-04-24 01:39:48 +02:00
}
---Create a new CheckUpdatePage instance
---@param params? CheckUpdatePage # initial parameters
2022-04-24 01:39:48 +02:00
---@return CheckUpdatePage
function CheckUpdatePage.new(params)
local self = CreateInstance(CheckUpdatePage, params, Page)
2022-04-24 01:39:48 +02:00
local width = DialogField.DEFAULT_WIDTH
local height = DialogField.DEFAULT_HEIGHT
2024-02-02 02:50:48 +01:00
local posX = (Display.design.width - width) / 2
local posY = (Display.design.height - height) / 2
self._updateDialogField = DialogField.new{
posX = posX,
posY = posY,
aabbW = width,
aabbH = height,
HEADER = {
title = "Updates found",
code = "0-1000-0000"
},
TEXT = {
"An update is available to Unnamed SDVX Clone,",
"please update to receive the latest features."
},
LEGEND = {
{
label = "BACK BUTTON",
text = "ABORT UPDATE/START GAME"
},
{
label = "START BUTTON",
text = "GO TO SERVICE PAGE"
}
}
}
self._updateDialogField.handleButtonInput = function (_, button)
if not self.viewHandler then
return false
end
if button == game.BUTTON_BCK then
self:onInvalidation() -- Cancel update, close screen
return true
elseif button == game.BUTTON_STA then
self:onInvalidation(true)
return true
end
return false
end
self._checkUpdateField = CheckUpdateField.new{posX = 32, posY = 64, label = "update check"}
self._checkUpdateField.onUpdateAvailable = function(url, version)
self:addField(self._updateDialogField)
self._focusedField = self._updateDialogField
2022-04-24 01:39:48 +02:00
end
self:addField(self._checkUpdateField)
2022-04-24 01:39:48 +02:00
self._focusedField = self._checkUpdateField
return self
2022-04-24 01:39:48 +02:00
end
function CheckUpdatePage:handleButtonInput(button)
if self._focusedField and self._focusedField:handleButtonInput(button) then
return -- stop processing input
end
if button == game.BUTTON_BCK then
self:onInvalidation()
end
end
2022-04-24 01:39:48 +02:00
---@param deltaTime number # frametime in seconds
function CheckUpdatePage:drawBackground(deltaTime)
gfx.BeginPath()
gfx.FillColor(0, 0, 0)
2024-02-02 02:50:48 +01:00
gfx.Rect(0, 0, Display.design.width, Display.design.height)
2022-04-24 01:39:48 +02:00
gfx.Fill()
end
return CheckUpdatePage