2022-04-03 19:43:50 +02:00
|
|
|
require("common.class")
|
|
|
|
|
2022-04-03 01:35:41 +02:00
|
|
|
---@class Field
|
2022-04-11 18:47:26 +02:00
|
|
|
---@field parent Page|ContainerField
|
2022-04-03 01:35:41 +02:00
|
|
|
---@field posX number
|
|
|
|
---@field posY number
|
2022-04-11 18:47:26 +02:00
|
|
|
---@field aabbW number
|
|
|
|
---@field aabbH number
|
2022-04-03 01:35:41 +02:00
|
|
|
local Field = {
|
2022-04-11 18:47:26 +02:00
|
|
|
__tostring = function() return "Field" end,
|
2022-04-03 01:35:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
---Create a new Field instance
|
2022-04-12 23:45:28 +02:00
|
|
|
---@param o? table # initial parameters
|
2022-04-03 01:35:41 +02:00
|
|
|
---@return Field
|
2022-04-27 02:40:22 +02:00
|
|
|
function Field.new(o)
|
2022-04-11 18:47:26 +02:00
|
|
|
o = o or {}
|
2022-04-03 01:35:41 +02:00
|
|
|
|
|
|
|
--set instance members
|
|
|
|
|
|
|
|
o.parent = o.parent or nil
|
|
|
|
o.posX = o.posX or 0
|
|
|
|
o.posY = o.posY or 0
|
2022-04-11 18:47:26 +02:00
|
|
|
o.aabbW = o.aabbW or 0
|
|
|
|
o.aabbH = o.aabbH or 0
|
2022-04-03 01:35:41 +02:00
|
|
|
|
2022-04-27 02:40:22 +02:00
|
|
|
return CreateInstance(Field, o)
|
2022-04-11 18:47:26 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
---Get the containing top-level parent page
|
2022-04-12 23:45:28 +02:00
|
|
|
---@return Field|Page
|
2022-04-11 18:47:26 +02:00
|
|
|
function Field:getParentPage()
|
|
|
|
if self.parent and self.parent.getParentPage then
|
|
|
|
return self.parent:getParentPage()
|
|
|
|
else
|
|
|
|
return self.parent
|
|
|
|
end
|
2022-04-03 01:35:41 +02:00
|
|
|
end
|
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---@param obj? any # message object for the field
|
|
|
|
function Field:activate(obj) end
|
2022-04-03 19:51:56 +02:00
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---@param obj? any # message object for the field
|
|
|
|
function Field:focus(obj) end
|
2022-04-03 19:51:56 +02:00
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---@param obj? any # message object for the field
|
|
|
|
function Field:deactivate(obj) end
|
2022-04-03 19:51:56 +02:00
|
|
|
|
2022-04-15 04:54:30 +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
|
|
|
|
function Field:handleButtonInput(button)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
---@param knob integer # `0` = Left, `1` = Right
|
|
|
|
---@param delta number # in radians, `-2*pi` to `0` (turning CCW) and `0` to `2*pi` (turning CW)
|
|
|
|
---@return boolean # true if further button input processing should be stopped, otherwise false
|
|
|
|
function Field:handleKnobInput(knob, delta)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---@param deltaTime number # frametime in seconds
|
2022-04-11 18:47:26 +02:00
|
|
|
function Field:drawContent(deltaTime)
|
2022-04-15 04:54:30 +02:00
|
|
|
-- dummy field content
|
|
|
|
|
2022-04-11 18:47:26 +02:00
|
|
|
gfx.ResetScissor()
|
2022-04-03 01:35:41 +02:00
|
|
|
|
2022-04-11 18:47:26 +02:00
|
|
|
local offX = -50
|
|
|
|
local offY = -50
|
|
|
|
local aabbW = 100
|
|
|
|
local aabbH = 100
|
2022-04-03 01:35:41 +02:00
|
|
|
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.FillColor(255, 0, 128, 192)
|
|
|
|
gfx.StrokeColor(0, 0, 0)
|
|
|
|
gfx.StrokeWidth(2)
|
2022-04-11 18:47:26 +02:00
|
|
|
gfx.Rect(offX, offY, aabbW, aabbH)
|
2022-04-03 01:35:41 +02:00
|
|
|
gfx.Fill()
|
|
|
|
gfx.Stroke()
|
|
|
|
|
|
|
|
gfx.BeginPath()
|
2022-04-11 18:47:26 +02:00
|
|
|
gfx.MoveTo(offX, 0)
|
|
|
|
gfx.LineTo(offX + aabbW, 0)
|
|
|
|
gfx.MoveTo(0, offY)
|
|
|
|
gfx.LineTo(0, offY + aabbH)
|
2022-04-03 01:35:41 +02:00
|
|
|
gfx.StrokeColor(0, 0, 0, 64)
|
|
|
|
gfx.StrokeWidth(2)
|
|
|
|
gfx.Stroke()
|
|
|
|
|
|
|
|
local fontSize = 18
|
|
|
|
local fontMargin = 4
|
|
|
|
gfx.BeginPath()
|
|
|
|
gfx.FontSize(fontSize)
|
|
|
|
gfx.LoadSkinFont("dfmarugoth.ttf")
|
|
|
|
gfx.FillColor(0, 0, 0)
|
|
|
|
gfx.TextAlign(gfx.TEXT_ALIGN_CENTER | gfx.TEXT_ALIGN_MIDDLE)
|
|
|
|
gfx.Text("TEXTURE", 0, -fontSize / 2 - fontMargin)
|
|
|
|
gfx.Text("MISSING", 0, fontSize / 2 + fontMargin)
|
2022-04-11 18:47:26 +02:00
|
|
|
end
|
|
|
|
|
2022-04-12 23:45:28 +02:00
|
|
|
---@param deltaTime number # frametime in seconds
|
2022-04-11 18:47:26 +02:00
|
|
|
function Field:render(deltaTime)
|
|
|
|
gfx.Save()
|
|
|
|
|
|
|
|
gfx.Translate(self.posX, self.posY)
|
2022-04-15 04:54:30 +02:00
|
|
|
gfx.Scissor(0, 0, self.aabbW, self.aabbH)
|
|
|
|
|
2022-04-11 18:47:26 +02:00
|
|
|
self:drawContent(deltaTime)
|
2022-04-03 01:35:41 +02:00
|
|
|
|
|
|
|
gfx.Restore()
|
|
|
|
end
|
|
|
|
|
2022-04-05 23:53:19 +02:00
|
|
|
return Field
|