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 04:59:43 +02:00
|
|
|
local Field = require("components.pager.field")
|
|
|
|
|
2022-04-03 19:51:56 +02:00
|
|
|
---@class ServiceFieldState
|
|
|
|
ServiceFieldState = {
|
|
|
|
INACTIVE = 0,
|
|
|
|
FOCUSED = 1,
|
|
|
|
ACTIVE = 2
|
|
|
|
}
|
|
|
|
|
2022-04-03 04:59:43 +02:00
|
|
|
---@class ServiceField: Field
|
|
|
|
---@field label string
|
|
|
|
---@field value any
|
|
|
|
---@field footer string|string[]
|
2022-04-03 19:51:56 +02:00
|
|
|
---@field _state ServiceFieldState
|
2022-04-03 04:59:43 +02:00
|
|
|
local ServiceField = {
|
2022-04-05 23:53:19 +02:00
|
|
|
__tostring = function () return "ServiceField" end,
|
2022-04-03 04:59:43 +02:00
|
|
|
SERVICE_DEFAULT_FONT_SIZE = 24,
|
|
|
|
SERVICE_DEFAULT_FONT_FACE = "dfmarugoth.ttf",
|
|
|
|
SERVICE_DEFAULT_FONT_COLOR = {255, 255, 255, 255}, --{r, g, b, a}
|
|
|
|
}
|
|
|
|
|
|
|
|
function ServiceField:new(o)
|
2022-04-03 19:43:50 +02:00
|
|
|
o = Inherit(self, Field, o)
|
2022-04-03 04:59:43 +02:00
|
|
|
|
|
|
|
o.label = o.label or "<UNDEFINED>"
|
|
|
|
o.value = o.value or nil
|
|
|
|
o.footer = o.footer or nil
|
|
|
|
|
2022-04-03 19:51:56 +02:00
|
|
|
o._state = ServiceFieldState.INACTIVE
|
|
|
|
|
2022-04-03 04:59:43 +02:00
|
|
|
return o
|
|
|
|
end
|
|
|
|
|
2022-04-03 19:51:56 +02:00
|
|
|
function ServiceField:activate()
|
|
|
|
self._state = ServiceFieldState.ACTIVE
|
|
|
|
end
|
|
|
|
|
|
|
|
function ServiceField:focus()
|
|
|
|
self._state = ServiceFieldState.FOCUSED
|
|
|
|
end
|
|
|
|
|
|
|
|
function ServiceField:deactivate()
|
|
|
|
self._state = ServiceFieldState.INACTIVE
|
|
|
|
end
|
|
|
|
|
2022-04-03 04:59:43 +02:00
|
|
|
function ServiceField:drawValue(deltaTime)
|
|
|
|
gfx.Save()
|
2022-04-04 01:58:10 +02:00
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.FillColor(table.unpack(self.SERVICE_DEFAULT_FONT_COLOR))
|
|
|
|
if type(self.value) == "string" then
|
2022-04-05 17:31:02 +02:00
|
|
|
gfx.Text(string.upper(self.value), Dim.design.width / 2, 0)
|
2022-04-04 01:58:10 +02:00
|
|
|
else
|
2022-04-05 17:31:02 +02:00
|
|
|
gfx.Text("N/A", Dim.design.width / 2, 0)
|
2022-04-04 01:58:10 +02:00
|
|
|
end
|
2022-04-03 04:59:43 +02:00
|
|
|
gfx.Restore()
|
|
|
|
end
|
|
|
|
|
|
|
|
function ServiceField:render(deltaTime)
|
|
|
|
gfx.Save()
|
|
|
|
|
|
|
|
gfx.Translate(self.posX, self.posY)
|
|
|
|
|
2022-04-04 01:58:10 +02:00
|
|
|
gfx.FontSize(self.SERVICE_DEFAULT_FONT_SIZE)
|
|
|
|
gfx.LoadSkinFont(self.SERVICE_DEFAULT_FONT_FACE)
|
2022-04-03 04:59:43 +02:00
|
|
|
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT | gfx.TEXT_ALIGN_TOP)
|
2022-04-03 19:51:56 +02:00
|
|
|
|
|
|
|
if self._state == ServiceFieldState.FOCUSED then
|
|
|
|
gfx.FillColor(255, 0, 0, 255)
|
|
|
|
else
|
2022-04-04 01:58:10 +02:00
|
|
|
gfx.FillColor(table.unpack(self.SERVICE_DEFAULT_FONT_COLOR))
|
2022-04-03 19:51:56 +02:00
|
|
|
end
|
|
|
|
|
2022-04-03 04:59:43 +02:00
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.Text(self.label, 0, 0)
|
2022-04-03 19:51:56 +02:00
|
|
|
|
2022-04-03 04:59:43 +02:00
|
|
|
self:drawValue(deltaTime)
|
|
|
|
|
|
|
|
gfx.Restore()
|
|
|
|
end
|
|
|
|
|
2022-04-05 23:53:19 +02:00
|
|
|
return ServiceField
|