ExperimentalGear/scripts/titlescreen/service/updatefield.lua

74 lines
2.1 KiB
Lua
Raw Normal View History

require("common.class")
local ServiceField = require("api.page.servicefield")
---@class UpdateField: ServiceField
---@field _timer number
local UpdateField = {
__name = "UpdateField",
UPDATE_FLICKER_TIME = 0.5,
UPDATE_FLICKER_COLORS = {
{255, 0, 0, 255},
{255, 255, 0, 255}
}
}
---Create a new UpdateField instance
---@param params? UpdateField # initial parameters
---@return UpdateField
function UpdateField.new(params)
params = params or {}
local self = CreateInstance(UpdateField, params, ServiceField)
self._timer = 0
return self
end
---@param obj? any # message object for the field
function UpdateField:activate(obj) end
---@param obj? any # message object for the field
function UpdateField:focus(obj) end
---@param obj? any # message object for the field
function UpdateField:deactivate(obj) end
---@param button integer # options are under the `game` table prefixed with `BUTTON`
---@return boolean # true if further button input processing should be stopped, otherwise false
function UpdateField:handleButtonInput(button)
local url, _ = game.UpdateAvailable()
if button == game.BUTTON_STA and url then
Menu.Update()
return true
end
return false
end
---@param deltaTime number # frametime in seconds
function UpdateField:drawValue(deltaTime)
self._timer = self._timer + deltaTime
local url, version = game.UpdateAvailable()
gfx.Translate(self.VALUE_OFFSETX, 0)
gfx.FontSize(self.FONT_SIZE)
gfx.LoadSkinFont(self.FONT_FACE)
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT | gfx.TEXT_ALIGN_TOP)
if url then
if (self._timer % self.UPDATE_FLICKER_TIME) < self.UPDATE_FLICKER_TIME / 2 then
gfx.FillColor(table.unpack(self.UPDATE_FLICKER_COLORS[1]))
else
gfx.FillColor(table.unpack(self.UPDATE_FLICKER_COLORS[2]))
end
gfx.Text("*UPDATE AVAILABLE (" .. version .. ")*", 0, 0)
else
gfx.FillColor(table.unpack(self.FONT_COLOR))
gfx.Text(self.value or "<VERSION STRING NOT AVAILABLE>", 0, 0)
end
end
2022-04-05 23:53:19 +02:00
return UpdateField