add __tostring fields to classes
This commit is contained in:
parent
83c3504e7d
commit
df66b1592b
|
@ -5,6 +5,7 @@ require("common.class")
|
||||||
---@field posX number
|
---@field posX number
|
||||||
---@field posY number
|
---@field posY number
|
||||||
local Field = {
|
local Field = {
|
||||||
|
__tostring = function () return "Field" end,
|
||||||
---@type nil|fun(button: integer): boolean
|
---@type nil|fun(button: integer): boolean
|
||||||
---returns true if further button input processing should be stopped, otherwise false
|
---returns true if further button input processing should be stopped, otherwise false
|
||||||
handleButtonInput = nil,
|
handleButtonInput = nil,
|
||||||
|
@ -69,4 +70,4 @@ function Field:render(deltaTime)
|
||||||
gfx.Restore()
|
gfx.Restore()
|
||||||
end
|
end
|
||||||
|
|
||||||
return Field
|
return Field
|
||||||
|
|
|
@ -3,7 +3,9 @@ local Field = require("components.pager.field")
|
||||||
|
|
||||||
---@class LinkField: Field
|
---@class LinkField: Field
|
||||||
---@field link Page
|
---@field link Page
|
||||||
local LinkField = {}
|
local LinkField = {
|
||||||
|
__tostring = function () return "LinkField" end
|
||||||
|
}
|
||||||
|
|
||||||
---Create a new Field instance
|
---Create a new Field instance
|
||||||
---@param o table
|
---@param o table
|
||||||
|
@ -19,13 +21,16 @@ end
|
||||||
function LinkField:handleButtonInput(button)
|
function LinkField:handleButtonInput(button)
|
||||||
if button == game.BUTTON_STA then
|
if button == game.BUTTON_STA then
|
||||||
if self.parent and self.parent.viewHandler then
|
if self.parent and self.parent.viewHandler then
|
||||||
|
game.Log(self .. " navigate(" .. self.link .. ") called", game.LOGGER_INFO)
|
||||||
self.parent.viewHandler:navigate(self.link)
|
self.parent.viewHandler:navigate(self.link)
|
||||||
else
|
else
|
||||||
game.Log("LinkField can't access PageView instance to navigate", game.LOGGER_ERROR)
|
game.Log(self .. " can't access " ..
|
||||||
|
(self.parent and self.parent.viewHandler or "PageView") ..
|
||||||
|
" instance to navigate", game.LOGGER_ERROR)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return LinkField
|
return LinkField
|
|
@ -4,6 +4,7 @@ require("common.class")
|
||||||
---@field content Field[]
|
---@field content Field[]
|
||||||
---@field viewHandler nil|PageView
|
---@field viewHandler nil|PageView
|
||||||
local Page = {
|
local Page = {
|
||||||
|
__tostring = function () return "Page" end,
|
||||||
drawBackground = nil, ---@type nil|fun(deltaTime: number)
|
drawBackground = nil, ---@type nil|fun(deltaTime: number)
|
||||||
drawHeader = nil, ---@type nil|fun(deltaTime: number)
|
drawHeader = nil, ---@type nil|fun(deltaTime: number)
|
||||||
drawFooter = nil, ---@type nil|fun(deltaTime: number)
|
drawFooter = nil, ---@type nil|fun(deltaTime: number)
|
||||||
|
@ -80,4 +81,4 @@ function Page:render(deltaTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return Page
|
return Page
|
||||||
|
|
|
@ -2,7 +2,9 @@ require("common.class")
|
||||||
|
|
||||||
---@class PageView
|
---@class PageView
|
||||||
---@field pageStack Page[]
|
---@field pageStack Page[]
|
||||||
local PageView = {}
|
local PageView = {
|
||||||
|
__tostring = function () return "PageView" end
|
||||||
|
}
|
||||||
|
|
||||||
local function pushStack(t, o)
|
local function pushStack(t, o)
|
||||||
table.insert(t, 1, o)
|
table.insert(t, 1, o)
|
||||||
|
@ -68,4 +70,4 @@ function PageView:render(deltaTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return PageView
|
return PageView
|
||||||
|
|
|
@ -5,6 +5,7 @@ local ServiceField = require("titlescreen.fields.service.servicefield")
|
||||||
---@class ColorGradientField: ServiceField
|
---@class ColorGradientField: ServiceField
|
||||||
---@field height number
|
---@field height number
|
||||||
local ColorGradientField = {
|
local ColorGradientField = {
|
||||||
|
__tostring = function () return "ColorGradientField" end,
|
||||||
GRADIENT_X_OFFSET = 128,
|
GRADIENT_X_OFFSET = 128,
|
||||||
GRADIENT_WIDTH = 512,
|
GRADIENT_WIDTH = 512,
|
||||||
GRADIENT_STEPS = 32
|
GRADIENT_STEPS = 32
|
||||||
|
@ -37,4 +38,4 @@ function ColorGradientField:drawValue(deltaTime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return ColorGradientField
|
return ColorGradientField
|
||||||
|
|
|
@ -4,7 +4,9 @@ local ServiceField = require("titlescreen.fields.service.servicefield")
|
||||||
|
|
||||||
---@class InputButtonField: ServiceField
|
---@class InputButtonField: ServiceField
|
||||||
---@field button integer
|
---@field button integer
|
||||||
local InputButtonField = {}
|
local InputButtonField = {
|
||||||
|
__tostring = function () return "InputButtonField" end,
|
||||||
|
}
|
||||||
|
|
||||||
function InputButtonField:new(o)
|
function InputButtonField:new(o)
|
||||||
o = Inherit(self, ServiceField, o)
|
o = Inherit(self, ServiceField, o)
|
||||||
|
@ -30,4 +32,4 @@ function InputButtonField:drawValue(deltaTime)
|
||||||
gfx.Text(self.value, posX, 0)
|
gfx.Text(self.value, posX, 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
return InputButtonField
|
return InputButtonField
|
||||||
|
|
|
@ -4,7 +4,9 @@ local ServiceField = require("titlescreen.fields.service.servicefield")
|
||||||
|
|
||||||
---@class InputKnobField: ServiceField
|
---@class InputKnobField: ServiceField
|
||||||
---@field knob integer
|
---@field knob integer
|
||||||
local InputKnobField = {}
|
local InputKnobField = {
|
||||||
|
__tostring = function () return "InputKnobField" end,
|
||||||
|
}
|
||||||
|
|
||||||
function InputKnobField:new(o)
|
function InputKnobField:new(o)
|
||||||
o = Inherit(self, ServiceField, o)
|
o = Inherit(self, ServiceField, o)
|
||||||
|
@ -58,4 +60,4 @@ function InputKnobField:drawValue(deltaTime)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return InputKnobField
|
return InputKnobField
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
require("common.class")
|
require("common.class")
|
||||||
local ServiceField = require("titlescreen.fields.service.servicefield")
|
local ServiceField = require("titlescreen.fields.service.servicefield")
|
||||||
|
|
||||||
---@class LinkServiceField: ServiceField
|
---@class LinkField: ServiceField
|
||||||
local LinkServiceField = {}
|
local LinkField = {
|
||||||
|
__tostring = function () return "LinkField" end,
|
||||||
|
}
|
||||||
|
|
||||||
---Create a new Field instance
|
---Create a new Field instance
|
||||||
---@param o ServiceField
|
---@param o ServiceField
|
||||||
---@return LinkServiceField
|
---@return LinkServiceField
|
||||||
function LinkServiceField:new(o)
|
function LinkField:new(o)
|
||||||
o = Inherit(self, ServiceField, o)
|
o = Inherit(self, ServiceField, o)
|
||||||
|
|
||||||
o.value = o.value or nil
|
o.value = o.value or nil
|
||||||
|
@ -15,23 +17,26 @@ function LinkServiceField:new(o)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
function LinkServiceField:drawValue(deltaTime) end
|
function LinkField:drawValue(deltaTime) end
|
||||||
|
|
||||||
function LinkServiceField:handleButtonInput(button)
|
function LinkField:handleButtonInput(button)
|
||||||
if not self.value then
|
if not self.value then
|
||||||
game.Log("LinkServiceField (" .. self.label .. ") does not have a valid link", game.LOGGER_ERROR)
|
game.Log(self .. " (" .. self.label .. ") does not have a valid link", game.LOGGER_ERROR)
|
||||||
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if button == game.BUTTON_STA then
|
if button == game.BUTTON_STA then
|
||||||
if self.parent and self.parent.viewHandler then
|
if self.parent and self.parent.viewHandler then
|
||||||
game.Log("LinkServiceField (" .. self.label .. ") navigate() called", game.LOGGER_INFO)
|
game.Log(self .. " (" .. self.label .. ") navigate(" .. self.value .. ") called", game.LOGGER_INFO)
|
||||||
self.parent.viewHandler:navigate(self.value)
|
self.parent.viewHandler:navigate(self.value)
|
||||||
else
|
else
|
||||||
game.Log("LinkServiceField (" .. self.label .. ") can't access PageView instance to navigate", game.LOGGER_ERROR)
|
game.Log(self .. "can't access " ..
|
||||||
|
(self.parent and self.parent.viewHandler or "PageView") ..
|
||||||
|
" instance to navigate", game.LOGGER_ERROR)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return LinkServiceField
|
return LinkField
|
||||||
|
|
|
@ -15,6 +15,7 @@ ServiceFieldState = {
|
||||||
---@field footer string|string[]
|
---@field footer string|string[]
|
||||||
---@field _state ServiceFieldState
|
---@field _state ServiceFieldState
|
||||||
local ServiceField = {
|
local ServiceField = {
|
||||||
|
__tostring = function () return "ServiceField" end,
|
||||||
SERVICE_DEFAULT_FONT_SIZE = 24,
|
SERVICE_DEFAULT_FONT_SIZE = 24,
|
||||||
SERVICE_DEFAULT_FONT_FACE = "dfmarugoth.ttf",
|
SERVICE_DEFAULT_FONT_FACE = "dfmarugoth.ttf",
|
||||||
SERVICE_DEFAULT_FONT_COLOR = {255, 255, 255, 255}, --{r, g, b, a}
|
SERVICE_DEFAULT_FONT_COLOR = {255, 255, 255, 255}, --{r, g, b, a}
|
||||||
|
@ -79,4 +80,4 @@ function ServiceField:render(deltaTime)
|
||||||
gfx.Restore()
|
gfx.Restore()
|
||||||
end
|
end
|
||||||
|
|
||||||
return ServiceField
|
return ServiceField
|
||||||
|
|
|
@ -5,6 +5,7 @@ local ServiceField = require("titlescreen.fields.service.servicefield")
|
||||||
---@class UpdateField: ServiceField
|
---@class UpdateField: ServiceField
|
||||||
---@field _timer number
|
---@field _timer number
|
||||||
local UpdateField = {
|
local UpdateField = {
|
||||||
|
__tostring = function () return "UpdateField" end,
|
||||||
UPDATE_FLICKER_TIME = 0.5,
|
UPDATE_FLICKER_TIME = 0.5,
|
||||||
UPDATE_FLICKER_COLORS = {
|
UPDATE_FLICKER_COLORS = {
|
||||||
{255, 0, 0, 255},
|
{255, 0, 0, 255},
|
||||||
|
@ -53,4 +54,4 @@ function UpdateField:drawValue(deltaTime)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return UpdateField
|
return UpdateField
|
||||||
|
|
|
@ -4,6 +4,8 @@ local ColorGradientField = require("titlescreen.fields.service.colorgradientfiel
|
||||||
|
|
||||||
---@class ColorCheckPage: ServicePage
|
---@class ColorCheckPage: ServicePage
|
||||||
local ColorCheckPage = {
|
local ColorCheckPage = {
|
||||||
|
__tostring = function () return "ColorCheckPage" end,
|
||||||
|
|
||||||
SERVICE_DEFAULT_SPACING = 8,
|
SERVICE_DEFAULT_SPACING = 8,
|
||||||
LINE_COLOR = {255, 255, 255, 255},
|
LINE_COLOR = {255, 255, 255, 255},
|
||||||
LINE_WIDTH = 4,
|
LINE_WIDTH = 4,
|
||||||
|
@ -85,4 +87,4 @@ function ColorCheckPage:drawBackground(deltaTime)
|
||||||
gfx.Restore()
|
gfx.Restore()
|
||||||
end
|
end
|
||||||
|
|
||||||
return ColorCheckPage
|
return ColorCheckPage
|
||||||
|
|
|
@ -4,7 +4,9 @@ local InputButtonField = require("titlescreen.fields.service.inputbuttonfield")
|
||||||
local InputKnobField = require("titlescreen.fields.service.inputknobfield")
|
local InputKnobField = require("titlescreen.fields.service.inputknobfield")
|
||||||
|
|
||||||
---@class InputCheckPage: ServicePage
|
---@class InputCheckPage: ServicePage
|
||||||
local InputCheckPage = {}
|
local InputCheckPage = {
|
||||||
|
__tostring = function () return "InputCheckPage" end,
|
||||||
|
}
|
||||||
|
|
||||||
---Create a new InputCheckPage instance
|
---Create a new InputCheckPage instance
|
||||||
---
|
---
|
||||||
|
@ -47,4 +49,4 @@ function InputCheckPage:handleButtonInput(button)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return InputCheckPage
|
return InputCheckPage
|
||||||
|
|
|
@ -4,11 +4,13 @@ local InputCheckPage = require("titlescreen.pages.service.inputcheckpage")
|
||||||
local ScreenCheckPage = require("titlescreen.pages.service.screencheckpage")
|
local ScreenCheckPage = require("titlescreen.pages.service.screencheckpage")
|
||||||
local ColorCheckPage = require("titlescreen.pages.service.colorcheckpage")
|
local ColorCheckPage = require("titlescreen.pages.service.colorcheckpage")
|
||||||
local VersionInfoPage = require("titlescreen.pages.service.versioninfopage")
|
local VersionInfoPage = require("titlescreen.pages.service.versioninfopage")
|
||||||
local LinkField = require("titlescreen.fields.service.linkfield")
|
local ServiceLinkField = require("titlescreen.fields.service.linkfield")
|
||||||
|
|
||||||
|
|
||||||
---@class MainMenuPage: ServicePage
|
---@class MainMenuPage: ServicePage
|
||||||
local MainMenuPage = {}
|
local MainMenuPage = {
|
||||||
|
__tostring = function () return "MainMenuPage" end,
|
||||||
|
}
|
||||||
|
|
||||||
---Create a new MainMenuPage instance
|
---Create a new MainMenuPage instance
|
||||||
---
|
---
|
||||||
|
@ -20,14 +22,14 @@ function MainMenuPage:new(o)
|
||||||
|
|
||||||
o.title = o.title or "MAIN MENU"
|
o.title = o.title or "MAIN MENU"
|
||||||
|
|
||||||
o:addField(LinkField:new{
|
o:addField(ServiceLinkField:new{
|
||||||
label = "INPUT CHECK",
|
label = "INPUT CHECK",
|
||||||
value = InputCheckPage:new{
|
value = InputCheckPage:new{
|
||||||
title = "INPUT CHECK",
|
title = "INPUT CHECK",
|
||||||
footer = "BACK BUTTON = EXIT"
|
footer = "BACK BUTTON = EXIT"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
o:addField(LinkField:new{
|
o:addField(ServiceLinkField:new{
|
||||||
label = "SCREEN CHECK",
|
label = "SCREEN CHECK",
|
||||||
value = ScreenCheckPage:new{
|
value = ScreenCheckPage:new{
|
||||||
title = "SCREEN CHECK",
|
title = "SCREEN CHECK",
|
||||||
|
@ -37,7 +39,7 @@ function MainMenuPage:new(o)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
o:addField(LinkField:new{
|
o:addField(ServiceLinkField:new{
|
||||||
label = "COLOR CHECK",
|
label = "COLOR CHECK",
|
||||||
value = ColorCheckPage:new{
|
value = ColorCheckPage:new{
|
||||||
title = "COLOR CHECK",
|
title = "COLOR CHECK",
|
||||||
|
@ -47,7 +49,7 @@ function MainMenuPage:new(o)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
o:addField(LinkField:new{
|
o:addField(ServiceLinkField:new{
|
||||||
label = "VERSION INFORMATION",
|
label = "VERSION INFORMATION",
|
||||||
value = VersionInfoPage:new{
|
value = VersionInfoPage:new{
|
||||||
title = "VERSION INFORMATION",
|
title = "VERSION INFORMATION",
|
||||||
|
@ -63,4 +65,4 @@ function MainMenuPage:new(o)
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
return MainMenuPage
|
return MainMenuPage
|
||||||
|
|
|
@ -4,6 +4,8 @@ local ServicePage = require("titlescreen.pages.service.servicepage")
|
||||||
|
|
||||||
---@class ScreenCheckPage: ServicePage
|
---@class ScreenCheckPage: ServicePage
|
||||||
local ScreenCheckPage = {
|
local ScreenCheckPage = {
|
||||||
|
__tostring = function () return "ScreenCheckPage" end,
|
||||||
|
|
||||||
BG_COLOR = {255, 255, 255, 255},
|
BG_COLOR = {255, 255, 255, 255},
|
||||||
STROKE_COLOR = {255, 0, 0, 255},
|
STROKE_COLOR = {255, 0, 0, 255},
|
||||||
SQUARE_BG_COLOR = {128, 128, 128, 255},
|
SQUARE_BG_COLOR = {128, 128, 128, 255},
|
||||||
|
@ -99,4 +101,4 @@ function ScreenCheckPage:drawBackground(deltaTime)
|
||||||
gfx.Stroke()
|
gfx.Stroke()
|
||||||
end
|
end
|
||||||
|
|
||||||
return ScreenCheckPage
|
return ScreenCheckPage
|
||||||
|
|
|
@ -9,6 +9,7 @@ local ServiceField = require("titlescreen.fields.service.servicefield")
|
||||||
---@field footer string[]
|
---@field footer string[]
|
||||||
---@field content ServiceField[]
|
---@field content ServiceField[]
|
||||||
local ServicePage = {
|
local ServicePage = {
|
||||||
|
__tostring = function () return "ServicePage" end,
|
||||||
SERVICE_DEFAULT_FONT_SIZE = ServiceField.SERVICE_DEFAULT_FONT_SIZE,
|
SERVICE_DEFAULT_FONT_SIZE = ServiceField.SERVICE_DEFAULT_FONT_SIZE,
|
||||||
SERVICE_DEFAULT_FONT_FACE = ServiceField.SERVICE_DEFAULT_FONT_FACE,
|
SERVICE_DEFAULT_FONT_FACE = ServiceField.SERVICE_DEFAULT_FONT_FACE,
|
||||||
SERVICE_DEFAULT_FONT_COLOR = ServiceField.SERVICE_DEFAULT_FONT_COLOR,
|
SERVICE_DEFAULT_FONT_COLOR = ServiceField.SERVICE_DEFAULT_FONT_COLOR,
|
||||||
|
@ -145,4 +146,4 @@ function ServicePage:handleKnobInput(knob, delta)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return ServicePage
|
return ServicePage
|
||||||
|
|
|
@ -12,7 +12,9 @@ local function getGameLogValue(prefix, str)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class VersionInfoPage: ServicePage
|
---@class VersionInfoPage: ServicePage
|
||||||
local VersionInfoPage = {}
|
local VersionInfoPage = {
|
||||||
|
__tostring = function () return "VersionInfoPage" end,
|
||||||
|
}
|
||||||
|
|
||||||
---Create a new VersionInfoPage instance
|
---Create a new VersionInfoPage instance
|
||||||
---
|
---
|
||||||
|
@ -62,4 +64,4 @@ function VersionInfoPage:handleButtonInput(button)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return VersionInfoPage
|
return VersionInfoPage
|
||||||
|
|
Loading…
Reference in New Issue