ExperimentalGear/scripts/titlescreen/service/screencheckpage.lua

105 lines
3.6 KiB
Lua
Raw Normal View History

2022-04-03 22:08:31 +02:00
require("common.class")
2024-02-02 02:50:48 +01:00
local Display = require("scripts.graphics.display")
local ServicePage = require("api.page.servicepage")
2022-04-03 22:08:31 +02:00
---@class ScreenCheckPage: ServicePage
local ScreenCheckPage = {
__name = "ScreenCheckPage",
2022-04-05 23:53:19 +02:00
2022-04-03 22:08:31 +02:00
BG_COLOR = {255, 255, 255, 255},
STROKE_COLOR = {255, 0, 0, 255},
SQUARE_BG_COLOR = {128, 128, 128, 255},
SQUARE_STROKE_COLOR = {0, 0, 0, 255},
STROKE_WIDTH = 6,
SQUARE_COUNT = {18, 32}
}
---Create a new ScreenCheckPage instance
---@param params? ScreenCheckPage # initial parameters
2022-04-03 22:08:31 +02:00
---@return ScreenCheckPage
function ScreenCheckPage.new(params)
params = params or {}
2022-04-03 22:08:31 +02:00
params.title = params.title or "SCREEN CHECK"
params.footer = params.footer or {
2022-04-03 22:08:31 +02:00
"START BUTTON = EXIT",
"BACK BUTTON = EXIT"
}
return CreateInstance(ScreenCheckPage, params, ServicePage)
2022-04-03 22:08:31 +02:00
end
---@param button integer # options are under the `game` table prefixed with `BUTTON`
2022-04-03 22:08:31 +02:00
function ScreenCheckPage:handleButtonInput(button)
if button == game.BUTTON_BCK or button == game.BUTTON_STA then
if self.viewHandler then
self.viewHandler:back()
end
end
end
---@param deltaTime number # frametime in seconds
2022-04-03 22:08:31 +02:00
function ScreenCheckPage:drawBackground(deltaTime)
--background fill
gfx.BeginPath()
2024-02-02 02:50:48 +01:00
gfx.Rect(0, 0, Display.design.width, Display.design.height)
2022-04-03 22:08:31 +02:00
gfx.FillColor(table.unpack(self.BG_COLOR))
gfx.Fill()
--draw square array
gfx.BeginPath()
2024-02-02 02:50:48 +01:00
local squareSize = Display.design.width / self.SQUARE_COUNT[1] - 2 * self.STROKE_WIDTH
2022-04-03 22:08:31 +02:00
local squareSpacing = 2 * self.STROKE_WIDTH
for j = 0, self.SQUARE_COUNT[2] - 1 do
local posY = self.STROKE_WIDTH + j * (squareSize + squareSpacing)
for i = 0, self.SQUARE_COUNT[1] - 1 do
local posX = self.STROKE_WIDTH + i * (squareSize + squareSpacing)
gfx.Rect(posX, posY, squareSize, squareSize)
end
end
gfx.FillColor(table.unpack(self.SQUARE_BG_COLOR))
gfx.StrokeColor(table.unpack(self.SQUARE_STROKE_COLOR))
gfx.StrokeWidth(self.STROKE_WIDTH)
gfx.Fill()
gfx.Stroke()
--draw crosshairs
gfx.BeginPath()
--frame
gfx.Rect(self.STROKE_WIDTH / 2, self.STROKE_WIDTH / 2,
2024-02-02 02:50:48 +01:00
Display.design.width - self.STROKE_WIDTH, Display.design.height - self.STROKE_WIDTH)
2022-04-03 22:08:31 +02:00
--center lines
2024-02-02 02:50:48 +01:00
gfx.MoveTo(Display.design.width / 2, 0)
gfx.LineTo(Display.design.width / 2, Display.design.height)
gfx.MoveTo(0, Display.design.height / 2)
gfx.LineTo(Display.design.width, Display.design.height / 2)
2022-04-03 22:08:31 +02:00
--corners
2024-02-02 02:50:48 +01:00
local cornerW = Display.design.width * 4 / 18
local cornerH = Display.design.height * 4 / 32
2022-04-03 22:08:31 +02:00
gfx.MoveTo(0, cornerH)
gfx.LineTo(cornerW, cornerH)
gfx.LineTo(cornerW, 0)
2024-02-02 02:50:48 +01:00
gfx.MoveTo(Display.design.width - cornerW, 0)
gfx.LineTo(Display.design.width - cornerW, cornerH)
gfx.LineTo(Display.design.width, cornerH)
gfx.MoveTo(0, Display.design.height - cornerH)
gfx.LineTo(cornerW, Display.design.height - cornerH)
gfx.LineTo(cornerW, Display.design.height)
gfx.MoveTo(Display.design.width - cornerW, Display.design.height)
gfx.LineTo(Display.design.width - cornerW, Display.design.height - cornerH)
gfx.LineTo(Display.design.width, Display.design.height - cornerH)
2022-04-03 22:08:31 +02:00
--center square
2024-02-02 02:50:48 +01:00
local centerX = Display.design.width * 4 / 18
local centerY = Display.design.height * 11 / 32
local centerW = Display.design.width * 10 / 18
local centerH = Display.design.height * 10 / 32
2022-04-03 22:08:31 +02:00
gfx.Rect(centerX, centerY, centerW, centerH)
gfx.StrokeColor(table.unpack(self.STROKE_COLOR))
gfx.StrokeWidth(self.STROKE_WIDTH)
gfx.Stroke()
end
2022-04-05 23:53:19 +02:00
return ScreenCheckPage