2022-04-04 01:58:10 +02:00
|
|
|
require("common.class")
|
2022-06-29 00:35:52 +02:00
|
|
|
local ServiceField = require("api.page.servicefield")
|
2022-04-04 01:58:10 +02:00
|
|
|
|
|
|
|
---@class UpdateField: ServiceField
|
|
|
|
---@field _timer number
|
|
|
|
local UpdateField = {
|
2022-05-06 01:02:30 +02:00
|
|
|
__name = "UpdateField",
|
2022-04-04 01:58:10 +02:00
|
|
|
UPDATE_FLICKER_TIME = 0.5,
|
|
|
|
UPDATE_FLICKER_COLORS = {
|
|
|
|
{255, 0, 0, 255},
|
|
|
|
{255, 255, 0, 255}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---Create a new UpdateField instance
|
2022-05-06 01:02:30 +02:00
|
|
|
---@param params? UpdateField # initial parameters
|
2022-04-12 23:45:28 +02:00
|
|
|
---@return UpdateField
|
2022-05-06 01:02:30 +02:00
|
|
|
function UpdateField.new(params)
|
|
|
|
params = params or {}
|
2022-04-04 01:58:10 +02:00
|
|
|
|
2022-05-06 01:02:30 +02:00
|
|
|
local self = CreateInstance(UpdateField, params, ServiceField)
|
2022-04-04 01:58:10 +02:00
|
|
|
|
2022-05-06 01:02:30 +02:00
|
|
|
self._timer = 0
|
|
|
|
|
|
|
|
return self
|
2022-04-04 01:58:10 +02:00
|
|
|
end
|
|
|
|
|
2022-04-15 04:54:30 +02:00
|
|
|
---@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
|
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---@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
|
2022-04-04 01:58:10 +02:00
|
|
|
function UpdateField:handleButtonInput(button)
|
|
|
|
local url, _ = game.UpdateAvailable()
|
|
|
|
|
|
|
|
if button == game.BUTTON_STA and url then
|
|
|
|
Menu.Update()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---@param deltaTime number # frametime in seconds
|
2022-04-04 01:58:10 +02:00
|
|
|
function UpdateField:drawValue(deltaTime)
|
|
|
|
self._timer = self._timer + deltaTime
|
|
|
|
local url, version = game.UpdateAvailable()
|
|
|
|
|
2022-04-15 04:54:30 +02:00
|
|
|
gfx.Translate(self.VALUE_OFFSETX, 0)
|
|
|
|
|
2022-04-11 18:47:26 +02:00
|
|
|
gfx.FontSize(self.FONT_SIZE)
|
|
|
|
gfx.LoadSkinFont(self.FONT_FACE)
|
2022-04-04 01:58:10 +02:00
|
|
|
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
|
2022-04-15 04:54:30 +02:00
|
|
|
gfx.Text("*UPDATE AVAILABLE (" .. version .. ")*", 0, 0)
|
2022-04-04 01:58:10 +02:00
|
|
|
else
|
2022-04-11 18:47:26 +02:00
|
|
|
gfx.FillColor(table.unpack(self.FONT_COLOR))
|
2022-04-15 04:54:30 +02:00
|
|
|
gfx.Text(self.value or "<VERSION STRING NOT AVAILABLE>", 0, 0)
|
2022-04-04 01:58:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-04-05 23:53:19 +02:00
|
|
|
return UpdateField
|