This commit is contained in:
assada 2024-06-01 22:46:36 +03:00
parent 29a5ed2f62
commit f19610e458
Signed by: assada
GPG Key ID: D4860A938E541F06
12 changed files with 543 additions and 451 deletions

View File

@ -1,265 +1,265 @@
--metrics={"baseline":0,"xHeight":0,"capHeight":0,"pairs":{"Ta":[-4,1],"Tc":[-4,1],"Te":[-4,1],"To":[-4,1],"Tm":[-4,1],"Tn":[-4,1],"Tr":[-4,1],"Tu":[-4,1],"Tv":[-4,1],"Tw":[-4,1],"fB":[2,1],"fD":[2,1],"fE":[2,1],"fF":[2,1],"fH":[2,1],"fI":[2,1],"fK":[2,1],"fL":[2,1],"fM":[2,1],"fN":[2,1],"fP":[2,1],"fR":[2,1],"fW":[2,1],"fb":[2,1],"fh":[2,1],"fk":[2,1],"fC":[2,1],"fG":[2,1],"fO":[2,1],"fQ":[2,1],"fU":[2,1],"fl":[2,1],"lB":[1,1],"lD":[1,1],"lE":[1,1],"lF":[1,1],"lH":[1,1],"lI":[1,1],"lK":[1,1],"lL":[1,1],"lM":[1,1],"lN":[1,1],"lP":[1,1],"lR":[1,1],"lW":[1,1],"lb":[1,1],"lh":[1,1],"lk":[1,1],"lC":[1,1],"lG":[1,1],"lO":[1,1],"lQ":[1,1],"lU":[0,1,1,1],"ll":[0,1,1,1],"la":[0,1,1,1],"lc":[0,1,1,1],"le":[0,1,1,1],"lo":[0,1,1,1],"lm":[1,1],"ln":[1,1],"lr":[1,1],"lu":[0,1,1,1],"lv":[0,1,1,1],"lw":[0,1,1,1],"Fa":[-2,1],"Fc":[-2,1],"Fe":[-2,1],"Fo":[-2,1],"Fm":[-2,1],"Fn":[-2,1],"Fr":[-2,1],"Fu":[-2,1],"Fv":[-2,1],"Fw":[-2,1],"aT":[-4,2],"uT":[-4,2],"gT":[-4,2],"yT":[-4,2],"mT":[-4,2],"nT":[-4,2],"vT":[-4,2],"wT":[-4,2],"Td":[-4,0],"Tf":[-2,0],"Tg":[-4,0],"Tp":[-4,0],"Tq":[-4,0],"Ts":[-4,0],"Tt":[-2,0],"Tx":[-4,0],"Ty":[-4,0],"Tz":[-4,0],"TJ":[-4,0],"T<>":[-4,0],"bT":[-4,0],"cT":[-4,0],"eT":[-4,0],"fA":[1,0,2,0],"fT":[2,0],"fi":[2,0],"fj":[2,0],"fY":[2,0],"fJ":[-2,0],"fS":[2,0],"fV":[2,0],"fX":[2,0],"fZ":[2,0],"hT":[-4,0],"kT":[-4,0],"lA":[1,0],"lT":[-1,0],"ld":[0,0,1,0],"lf":[-1,0],"lg":[0,0,1,0],"li":[1,0],"lj":[1,0],"lp":[1,0],"lq":[0,0,1,0],"ls":[1,0],"lt":[-1,0],"lx":[1,0],"ly":[0,0,1,0],"lz":[1,0],"lY":[-1,0],"lJ":[1,0],"lS":[1,0],"lV":[-1,0],"lX":[1,0],"lZ":[1,0],"l<>":[-1,0],"oT":[-4,0],"pT":[-4,0],"qT":[-4,0],"rT":[-4,0],"rX":[-2,0],"rZ":[-2,0],"sT":[-4,0],"tT":[-2,0],"xT":[-4,0],"zT":[-4,0],"C<>":[-2,0],"Ef":[-2,0],"Et":[-2,0],"E<>":[-2,0],"Fd":[-2,0],"Ff":[-2,0],"Fg":[-2,0],"Fp":[-2,0],"Fq":[-2,0],"Fs":[-2,0],"Ft":[-2,0],"Fx":[-2,0],"Fy":[-2,0],"Fz":[-2,0],"FJ":[-2,0],"F<>":[-2,0],"YJ":[-2,0],"Kf":[-2,0],"Kt":[-2,0],"K<>":[-4,0],"LT":[-4,0],"Lf":[-2,0],"Lt":[-2,0],"LY":[-4,0],"LV":[-4,0],"L<>":[-4,0],"PJ":[-2,0],"X<>":[-2,0],"Z<>":[-2,0],"<22>T":[-4,0],"<22>X":[-2,0],"<22>Z":[-2,0]},"left":["BDEFHIKLMNPRWbhk","CGOQ","Ul","aceo","mnr","uvw"],"right":["AQ","DO","HIMNWd","JU","au","gy","mn","vw"]} --metrics={"baseline":0,"xHeight":0,"capHeight":0,"pairs":{"Ta":[-4,1],"Tc":[-4,1],"Te":[-4,1],"To":[-4,1],"Tm":[-4,1],"Tn":[-4,1],"Tr":[-4,1],"Tu":[-4,1],"Tv":[-4,1],"Tw":[-4,1],"fB":[2,1],"fD":[2,1],"fE":[2,1],"fF":[2,1],"fH":[2,1],"fI":[2,1],"fK":[2,1],"fL":[2,1],"fM":[2,1],"fN":[2,1],"fP":[2,1],"fR":[2,1],"fW":[2,1],"fb":[2,1],"fh":[2,1],"fk":[2,1],"fC":[2,1],"fG":[2,1],"fO":[2,1],"fQ":[2,1],"fU":[2,1],"fl":[2,1],"lB":[1,1],"lD":[1,1],"lE":[1,1],"lF":[1,1],"lH":[1,1],"lI":[1,1],"lK":[1,1],"lL":[1,1],"lM":[1,1],"lN":[1,1],"lP":[1,1],"lR":[1,1],"lW":[1,1],"lb":[1,1],"lh":[1,1],"lk":[1,1],"lC":[1,1],"lG":[1,1],"lO":[1,1],"lQ":[1,1],"lU":[0,1,1,1],"ll":[0,1,1,1],"la":[0,1,1,1],"lc":[0,1,1,1],"le":[0,1,1,1],"lo":[0,1,1,1],"lm":[1,1],"ln":[1,1],"lr":[1,1],"lu":[0,1,1,1],"lv":[0,1,1,1],"lw":[0,1,1,1],"Fa":[-2,1],"Fc":[-2,1],"Fe":[-2,1],"Fo":[-2,1],"Fm":[-2,1],"Fn":[-2,1],"Fr":[-2,1],"Fu":[-2,1],"Fv":[-2,1],"Fw":[-2,1],"aT":[-4,2],"uT":[-4,2],"gT":[-4,2],"yT":[-4,2],"mT":[-4,2],"nT":[-4,2],"vT":[-4,2],"wT":[-4,2],"Td":[-4,0],"Tf":[-2,0],"Tg":[-4,0],"Tp":[-4,0],"Tq":[-4,0],"Ts":[-4,0],"Tt":[-2,0],"Tx":[-4,0],"Ty":[-4,0],"Tz":[-4,0],"TJ":[-4,0],"T<>":[-4,0],"bT":[-4,0],"cT":[-4,0],"eT":[-4,0],"fA":[1,0,2,0],"fT":[2,0],"fi":[2,0],"fj":[2,0],"fY":[2,0],"fJ":[-2,0],"fS":[2,0],"fV":[2,0],"fX":[2,0],"fZ":[2,0],"hT":[-4,0],"kT":[-4,0],"lA":[1,0],"lT":[-1,0],"ld":[0,0,1,0],"lf":[-1,0],"lg":[0,0,1,0],"li":[1,0],"lj":[1,0],"lp":[1,0],"lq":[0,0,1,0],"ls":[1,0],"lt":[-1,0],"lx":[1,0],"ly":[0,0,1,0],"lz":[1,0],"lY":[-1,0],"lJ":[1,0],"lS":[1,0],"lV":[-1,0],"lX":[1,0],"lZ":[1,0],"l<>":[-1,0],"oT":[-4,0],"pT":[-4,0],"qT":[-4,0],"rT":[-4,0],"rX":[-2,0],"rZ":[-2,0],"sT":[-4,0],"tT":[-2,0],"xT":[-4,0],"zT":[-4,0],"C<>":[-2,0],"Ef":[-2,0],"Et":[-2,0],"E<>":[-2,0],"Fd":[-2,0],"Ff":[-2,0],"Fg":[-2,0],"Fp":[-2,0],"Fq":[-2,0],"Fs":[-2,0],"Ft":[-2,0],"Fx":[-2,0],"Fy":[-2,0],"Fz":[-2,0],"FJ":[-2,0],"F<>":[-2,0],"YJ":[-2,0],"Kf":[-2,0],"Kt":[-2,0],"K<>":[-4,0],"LT":[-4,0],"Lf":[-2,0],"Lt":[-2,0],"LY":[-4,0],"LV":[-4,0],"L<>":[-4,0],"PJ":[-2,0],"X<>":[-2,0],"Z<>":[-2,0],"<22>T":[-4,0],"<22>X":[-2,0],"<22>Z":[-2,0]},"left":["BDEFHIKLMNPRWbhk","CGOQ","Ul","aceo","mnr","uvw"],"right":["AQ","DO","HIMNWd","JU","au","gy","mn","vw"]}
tracking=2 tracking=2
0 12 0 12
1 12 1 12
2 12 2 12
3 12 3 12
4 12 4 12
5 12 5 12
6 12 6 12
7 12 7 12
8 12 8 12
9 12 9 12
space 8 space 8
. 4 . 4
A 12 A 12
B 12 B 12
T 12 T 12
a 12 a 12
b 12 b 12
c 12 c 12
d 12 d 12
e 12 e 12
f 8 f 8
g 12 g 12
h 12 h 12
i 4 i 4
j 4 j 4
k 12 k 12
l 5 l 5
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
Ef -2 Ef -2
Et -2 Et -2
E<EFBFBD> -2 E<EFBFBD> -2
Fd -2 Fd -2
Ff -2 Ff -2
Fg -2 Fg -2
Fp -2 Fp -2
Fq -2 Fq -2
Fs -2 Fs -2
Ft -2 Ft -2
Fx -2 Fx -2
Fy -2 Fy -2
Fz -2 Fz -2
FJ -2 FJ -2
F<EFBFBD> -2 F<EFBFBD> -2
YJ -2 YJ -2
Kf -2 Kf -2
Kt -2 Kt -2
K<EFBFBD> -4 K<EFBFBD> -4
LT -4 LT -4
Lf -2 Lf -2
Lt -2 Lt -2
LY -4 LY -4
LV -4 LV -4
L<EFBFBD> -4 L<EFBFBD> -4
PJ -2 PJ -2
X<EFBFBD> -2 X<EFBFBD> -2
Z<EFBFBD> -2 Z<EFBFBD> -2
<EFBFBD>T -4 <EFBFBD>T -4
<EFBFBD>X -2 <EFBFBD>X -2
<EFBFBD>Z -2 <EFBFBD>Z -2

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -17,6 +17,7 @@ import "scripts/player"
import "scripts/groundSprite" import "scripts/groundSprite"
import "scripts/balebaSprite" import "scripts/balebaSprite"
import "scripts/dangerSprite" import "scripts/dangerSprite"
import "scripts/tankSprite"
import "scenes/BaseScene" import "scenes/BaseScene"
import 'scenes/Menu' import 'scenes/Menu'
@ -35,4 +36,4 @@ playdate.display.setRefreshRate(50)
Noble.showFPS = true Noble.showFPS = true
Noble.new(Menu) Noble.new(Game)

View File

@ -28,6 +28,8 @@ function scene:setValues()
scene.t = playdate.timer.new(10000) scene.t = playdate.timer.new(10000)
scene.t.repeats = true scene.t.repeats = true
scene.tankTimer = playdate.timer.new(1000)
scene.fp = playdate.sound.fileplayer.new( "assets/audio/war" ) scene.fp = playdate.sound.fileplayer.new( "assets/audio/war" )
scene.fp:setVolume(0.7) scene.fp:setVolume(0.7)
scene.hello = playdate.sound.fileplayer.new( "assets/audio/hello" ) scene.hello = playdate.sound.fileplayer.new( "assets/audio/hello" )
@ -68,7 +70,7 @@ function scene:enter()
end end
local k = #scene.balebas+1 local k = #scene.balebas+1
scene.balebas[k] = scene:spawnBaleba() --scene.balebas[k] = scene:spawnBaleba()
end end
for i=1, 3 do for i=1, 3 do
@ -80,6 +82,11 @@ function scene:enter()
if musicEnabled then if musicEnabled then
scene.fp:play(0) scene.fp:play(0)
end end
scene.tankTimer.timerEndedCallback = function()
scene.tank = Tank(550, 190, scene.player, scene.ground)
scene.tank:add()
end
end end
function scene:update() function scene:update()
@ -90,15 +97,13 @@ function scene:update()
return return
end end
if scene.player.isDead() then if scene.player.isDead() and not scene.telemLostSoundPlayed then
if not scene.telemLostSoundPlayed then scene.telemLostSound:play(1)
scene.telemLostSound:play(1) scene.telemLostSoundPlayed = true
scene.telemLostSoundPlayed = true screenShake(500, 5)
screenShake(500, 5)
end
local et = playdate.timer.new(6000)
scene:destroyPlayer()
local et = playdate.timer.new(2000)
et.timerEndedCallback = function() et.timerEndedCallback = function()
Noble.transition(Menu) Noble.transition(Menu)
end end
@ -126,6 +131,9 @@ function scene:exit()
scene.ground:remove() scene.ground:remove()
scene.ground = nil scene.ground = nil
scene.tank:remove()
scene.ground = nil
for i=1, #scene.balebas do for i=1, #scene.balebas do
scene.balebas[i]:destroy() scene.balebas[i]:destroy()
scene.balebas[i] = nil scene.balebas[i] = nil
@ -139,6 +147,9 @@ function scene:exit()
scene.t:remove() scene.t:remove()
scene.t = nil scene.t = nil
scene.tankTimer:remove()
scene.tankTimer = nil
Noble.showFPS = false Noble.showFPS = false
end end

View File

@ -1,7 +1,7 @@
Ground = {} Ground = {}
class("Ground").extends(Graphics.sprite) class("Ground").extends(Graphics.sprite)
local groundImage = playdate.graphics.image.new("assets/sprites/groundFin") local groundImage = Graphics.image.new("assets/sprites/groundFin")
function Ground:init(x, y, player) function Ground:init(x, y, player)
Ground.super.init(self, groundImage) Ground.super.init(self, groundImage)
@ -24,6 +24,12 @@ function Ground:setMoveSpeed(speed)
end end
function Ground:update() function Ground:update()
-- Stop ground
if Ground.moveSpeed == 0 then
return
end
-- Speedup when player is moving right -- Speedup when player is moving right
if Ground.player.isMovingRight() == false then if Ground.player.isMovingRight() == false then
Ground.moveSpeed = 0.2 Ground.moveSpeed = 0.2

View File

@ -99,6 +99,24 @@ function Player:changeToRunState(direction)
end end
end end
function Player:boom(collisionObject)
Player.dead = true
self:changeState("boom")
local particleB = ParticlePoly(self.x, self.y)
particleB:setThickness(2)
particleB:setAngular(-15, 15)
particleB:setSize(1, 2)
particleB:setSpeed(1, 3)
particleB:setMode(Particles.modes.STAY)
particleB:setBounds(0, 0, 400, 240)
particleB:setColour(Graphics.kColorXOR)
particleB:add(20)
if collisionObject then
collisionObject:remove()
end
end
function Player:handleMovementAndCollisions() function Player:handleMovementAndCollisions()
if Player.dead then if Player.dead then
return return
@ -134,23 +152,24 @@ function Player:handleMovementAndCollisions()
end end
if collisionTag == 3 then -- Ground if collisionTag == 3 then -- Ground
Player.dead = true self:boom()
self:changeState("boom")
return return
elseif collisionTag == 154 then -- Baleba elseif collisionTag == 154 then -- Baleba
Player.dead = true -- self:boom(collisionObject)
self:changeState("boom") return
elseif collisionTag == 2 then -- Tank
self:boom()
local particleB = ParticlePoly(self.x, self.y) local particleC = ParticlePoly(collisionObject.x, collisionObject.y)
particleB:setThickness(2) particleC:setThickness(5)
particleB:setAngular(-15, 15) particleC:setAngular(-15, 15)
particleB:setSize(1, 2) particleC:setSize(1, 5)
particleB:setSpeed(1, 3) particleC:setSpeed(1, 3)
particleB:setMode(Particles.modes.STAY) particleC:setMode(Particles.modes.STAY)
particleB:setBounds(0, 0, 400, 240) particleC:setBounds(0, 0, 400, 240)
particleB:setColour(Graphics.kColorXOR) particleC:setColour(Graphics.kColorXOR)
particleB:add(20) particleC:add(50)
collisionObject:remove() collisionObject:fadeout()
return return
end end
end end

View File

@ -0,0 +1,55 @@
Tank = {}
class("Tank").extends(Graphics.sprite)
function Tank:init(x, y, player, ground)
self.tankImage = Graphics.image.new("assets/sprites/tank")
self.tankImageD = Graphics.image.new("assets/sprites/tankD")
Tank.super.init(self)
local width, height = self.tankImage:getSize()
self.faded_image = Graphics.image.new(width, height, Graphics.kColorClear)
Graphics.pushContext(self.faded_image)
self.tankImageD:drawBlurred(0, 0, 2, 2, Graphics.image.kDitherTypeFloydSteinberg)
Graphics.popContext()
-- Collision properties
self:setZIndex(99)
self:setTag(2)
self:setCollideRect(4, 56, 147, 65)
-- Main properties
Tank.moveSpeed = 2
Tank.player = player
Tank.ground = ground
self:fadein()
self:moveTo(x, y)
end
function Tank:fadein()
self:setImage(self.tankImage)
end
function Tank:fadeout()
self:setImage(self.faded_image)
end
function Tank:update()
if self.x <= 330 then
Tank.ground:setMoveSpeed(0)
return
end
-- Speedup when player is moving right
if Tank.player.isMovingRight() == false then
Tank.moveSpeed = 0.2
else
Tank.moveSpeed = 1
end
self:moveTo(self.x-Tank.moveSpeed, self.y)
end

View File

@ -1,9 +1,9 @@
function enum( t ) function enum( t )
local result = {} local result = {}
for index, name in pairs(t) do for index, name in pairs(t) do
result[name] = index result[name] = index
end end
return result return result
end end

View File

@ -1,153 +1,153 @@
-- https://gist.github.com/GammaGames/17e0c64e932e6a5b10919af380276fb1 -- https://gist.github.com/GammaGames/17e0c64e932e6a5b10919af380276fb1
local pd <const> = playdate local pd <const> = playdate
local gfx <const> = Graphics local gfx <const> = Graphics
local box = playout.box.new local box = playout.box.new
local text = playout.text.new local text = playout.text.new
local window = { local window = {
padding = 8, padding = 8,
border = 2, border = 2,
borderRadius = 1, borderRadius = 1,
minWidth=160, minWidth=160,
maxWidth=210, maxWidth=210,
backgroundColor = gfx.kColorWhite, backgroundColor = gfx.kColorWhite,
font = Noble.Text.FONT_NEWSLEAK font = Noble.Text.FONT_NEWSLEAK
} }
local label = { local label = {
padding = 4 padding = 4
} }
local labelText = { local labelText = {
alignment = kTextAlignment.left alignment = kTextAlignment.left
} }
local input = { local input = {
padding = 4, padding = 4,
paddingLeft = 8, paddingLeft = 8,
borderRadius = 2, borderRadius = 2,
border = 1, border = 1,
minWidth = 140, minWidth = 140,
hAlign = playout.kAlignStart hAlign = playout.kAlignStart
} }
local inputText = { local inputText = {
alignment = kTextAlignment.left, alignment = kTextAlignment.left,
wrap = false wrap = false
} }
local button = { local button = {
padding = 4, padding = 4,
paddingLeft = 8 paddingLeft = 8
} }
local buttonHover = { local buttonHover = {
padding = 4, padding = 4,
paddingLeft = 8, paddingLeft = 8,
borderRadius = 2, borderRadius = 2,
border = 2, border = 2,
backgroundColor = gfx.kColorWhite, backgroundColor = gfx.kColorWhite,
font = Noble.Text.FONT_NEWSLEAK_BOLD, font = Noble.Text.FONT_NEWSLEAK_BOLD,
} }
function notify(_text, callback) function notify(_text, callback)
local tree = playout.tree.new( local tree = playout.tree.new(
box({ box({
direction = playout.kDirectionVertical, direction = playout.kDirectionVertical,
spacing = 4, spacing = 4,
style = window, style = window,
}, { }, {
text(_text, labelText), text(_text, labelText),
box({ style = button, tabIndex = 1 }, { text("Okay") }), box({ style = button, tabIndex = 1 }, { text("Okay") }),
}) })
) )
tree:computeTabIndex() tree:computeTabIndex()
local nodes = tree.tabIndex local nodes = tree.tabIndex
local selectedIndex = 1 local selectedIndex = 1
nodes[selectedIndex].style = buttonHover nodes[selectedIndex].style = buttonHover
pd.inputHandlers.push({ pd.inputHandlers.push({
AButtonDown = function() AButtonDown = function()
pd.inputHandlers.pop() pd.inputHandlers.pop()
callback() callback()
end, end,
BButtonDown = function() BButtonDown = function()
pd.inputHandlers.pop() pd.inputHandlers.pop()
callback() callback()
end, end,
}, true) }, true)
return tree:asSprite() return tree:asSprite()
end end
function confirm(_text, callback) function confirm(_text, callback)
local tree = playout.tree.new( local tree = playout.tree.new(
box({ box({
direction = playout.kDirectionVertical, direction = playout.kDirectionVertical,
spacing = 4, spacing = 4,
style = window style = window
}, { }, {
box({ style = label}, { text(_text, labelText) }), box({ style = label}, { text(_text, labelText) }),
box({ box({
direction = playout.kDirectionHorizontal, direction = playout.kDirectionHorizontal,
spacing = 8 spacing = 8
}, { }, {
box({ style = button, tabIndex = 1 }, { text("No") }), box({ style = button, tabIndex = 1 }, { text("No") }),
box({ style = button, tabIndex = 2 }, { text("Yes") }), box({ style = button, tabIndex = 2 }, { text("Yes") }),
}) })
}) })
) )
tree:computeTabIndex() tree:computeTabIndex()
local nodes = tree.tabIndex local nodes = tree.tabIndex
local selectedIndex = 1 local selectedIndex = 1
nodes[selectedIndex].style = buttonHover nodes[selectedIndex].style = buttonHover
pd.inputHandlers.push({ pd.inputHandlers.push({
leftButtonDown = function() leftButtonDown = function()
nodes[selectedIndex].style = button nodes[selectedIndex].style = button
selectedIndex = math.ringInt(selectedIndex - 1, 1, #nodes) selectedIndex = math.ringInt(selectedIndex - 1, 1, #nodes)
nodes[selectedIndex].style = buttonHover nodes[selectedIndex].style = buttonHover
tree:draw() tree:draw()
end, end,
rightButtonDown = function() rightButtonDown = function()
nodes[selectedIndex].style = button nodes[selectedIndex].style = button
selectedIndex = math.ringInt(selectedIndex + 1, 1, #nodes) selectedIndex = math.ringInt(selectedIndex + 1, 1, #nodes)
nodes[selectedIndex].style = buttonHover nodes[selectedIndex].style = buttonHover
tree:draw() tree:draw()
end, end,
AButtonUp = function() AButtonUp = function()
pd.inputHandlers.pop() pd.inputHandlers.pop()
callback(selectedIndex == 2) callback(selectedIndex == 2)
end, end,
BButtonUp = function() BButtonUp = function()
pd.inputHandlers.pop() pd.inputHandlers.pop()
callback(false) callback(false)
end, end,
}, true) }, true)
return tree:asSprite() return tree:asSprite()
end end
function prompt(_text, value, callback) function prompt(_text, value, callback)
local tree = playout.tree.new( local tree = playout.tree.new(
box({ box({
direction = playout.kDirectionVertical, direction = playout.kDirectionVertical,
style = window, style = window,
spacing = 4, spacing = 4,
hAlign = playout.kAlignStart hAlign = playout.kAlignStart
}, { }, {
box({ style = label }, { text(_text, labelText) }), box({ style = label }, { text(_text, labelText) }),
box({ style = input, tabIndex = 1 }, { text(value, inputText)}), box({ style = input, tabIndex = 1 }, { text(value, inputText)}),
}) })
) )
tree:computeTabIndex() tree:computeTabIndex()
local nodes = tree.tabIndex local nodes = tree.tabIndex
local input = nodes[1].children[1] local input = nodes[1].children[1]
pd.keyboard.show(value) pd.keyboard.show(value)
function pd.keyboard.textChangedCallback() function pd.keyboard.textChangedCallback()
input.text = pd.keyboard.text input.text = pd.keyboard.text
tree:layout() tree:layout()
tree:draw() tree:draw()
end end
function pd.keyboard.keyboardWillHideCallback(ok) callback(ok, pd.keyboard.text) end function pd.keyboard.keyboardWillHideCallback(ok) callback(ok, pd.keyboard.text) end
return tree:asSprite() return tree:asSprite()
end end