ExperimentalGear/scripts/titlescreen/fields/service/updatefield.lua

56 lines
1.5 KiB
Lua

require("common.class")
local Dim = require("common.dimensions")
local ServiceField = require("titlescreen.fields.service.servicefield")
---@class UpdateField: ServiceField
---@field _timer number
local UpdateField = {
UPDATE_FLICKER_TIME = 0.5,
UPDATE_FLICKER_COLORS = {
{255, 0, 0, 255},
{255, 255, 0, 255}
}
}
function UpdateField:new(o)
o = Inherit(self, ServiceField, o)
o._timer = 0
return o
end
function UpdateField:handleButtonInput(button)
local url, _ = game.UpdateAvailable()
if button == game.BUTTON_STA and url then
Menu.Update()
return true
end
return false
end
function UpdateField:drawValue(deltaTime)
self._timer = self._timer + deltaTime
local url, version = game.UpdateAvailable()
gfx.BeginPath()
gfx.FontSize(self.SERVICE_DEFAULT_FONT_SIZE)
gfx.LoadSkinFont(self.SERVICE_DEFAULT_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 .. ")*", Dim.design.width / 2, 0)
else
gfx.FillColor(table.unpack(self.SERVICE_DEFAULT_FONT_COLOR))
gfx.Text(self.value or "<VERSION STRING NOT AVAILABLE>", Dim.design.width / 2, 0)
end
end
return UpdateField