fpv/source/scenes/Menu.lua

128 lines
3.0 KiB
Lua
Raw Normal View History

2024-06-01 16:52:11 +03:00
Menu = {}
class("Menu").extends(BaseScene)
local scene = Menu
function scene:setValues()
2024-06-10 01:50:27 +03:00
self.background = Graphics.image.new("assets/images/menuBg")
2024-06-01 16:52:11 +03:00
self.color1 = Graphics.kColorBlack
self.color2 = Graphics.kColorWhite
self.menu = nil
self.sequence = nil
self.menuX = 15
self.menuYFrom = -50
self.menuY = 15
self.menuYTo = 240
2024-06-12 01:22:12 +03:00
scene.musicEnabled = Noble.Settings.get("music")
scene.levelAudio = playdate.sound.fileplayer.new("assets/audio/menu")
scene.levelAudio:setVolume(0.7)
2024-06-01 16:52:11 +03:00
end
function scene:init()
scene.super.init(self)
local menuSelSound = playdate.sound.fileplayer.new("assets/audio/menu_select")
menuSelSound:setVolume(0.5)
2024-06-10 01:50:27 +03:00
local menuConfirmSound = playdate.sound.fileplayer.new("assets/audio/confirm")
-- menuConfirmSound:setVolume(0.5)
2024-06-01 16:52:11 +03:00
self:setValues()
2024-06-10 01:50:27 +03:00
self.menu = Noble.Menu.new(false, Noble.Text.ALIGN_CENTER, false, self.color2, 4, 6, 0, Noble.Text.FONT_SMALL)
2024-06-01 16:52:11 +03:00
self:setupMenu(self.menu)
local crankTick = 0
self.inputHandler = {
upButtonDown = function()
self.menu:selectPrevious()
menuSelSound:play(1)
end,
downButtonDown = function()
self.menu:selectNext()
menuSelSound:play(1)
end,
cranked = function(change, acceleratedChange)
crankTick = crankTick + change
if (crankTick > 30) then
crankTick = 0
self.menu:selectNext()
menuSelSound:play(1)
elseif (crankTick < -30) then
crankTick = 0
self.menu:selectPrevious()
menuSelSound:play(1)
end
end,
AButtonDown = function()
2024-06-10 01:50:27 +03:00
menuConfirmSound:play(1)
2024-06-01 16:52:11 +03:00
self.menu:click()
end
}
end
function scene:enter()
scene.super.enter(self)
self.sequence = Sequence.new():from(self.menuYFrom):to(self.menuY, 1.5, Ease.outBounce):start()
2024-06-12 01:22:12 +03:00
if scene.musicEnabled then
scene.levelAudio:play(0)
end
2024-06-01 16:52:11 +03:00
end
function scene:start()
scene.super.start(self)
self.menu:activate()
end
function scene:drawBackground()
scene.super.drawBackground(self)
self.background:draw(0, 0)
end
local logo_image <const> = Graphics.image.new("assets/images/logo")
function scene:update()
scene.super.update(self)
Graphics.setColor(self.color1)
Graphics.setDitherPattern(0.2, Graphics.image.kDitherTypeScreen)
2024-06-10 01:50:27 +03:00
Graphics.fillRoundRect(200 - 38, 160 - 8, 75, 60, 15)
2024-06-01 16:52:11 +03:00
self.menu:draw(200, 160)
2024-06-10 01:50:27 +03:00
-- logo_image:draw(120, 55)
2024-06-01 16:52:11 +03:00
Graphics.setColor(Graphics.kColorBlack)
end
function scene:exit()
scene.super.exit(self)
2024-06-12 01:22:12 +03:00
scene.levelAudio:stop()
2024-06-01 16:52:11 +03:00
self.sequence = Sequence.new():from(self.menuY):to(self.menuYTo, 0.5, Ease.inSine)
2024-06-12 01:22:12 +03:00
self.sequence:start()
2024-06-01 16:52:11 +03:00
end
function scene:setupMenu(__menu)
2024-06-12 01:22:12 +03:00
__menu:addItem("Start", function() Noble.transition(DroneCardSelector, nil, Noble.Transition.DipToWhite) end)
2024-06-12 18:41:38 +03:00
__menu:addItem("Tutorial", function()
local debug = Noble.Settings.get("debug")
if debug then
Noble.Settings.set("debug", false)
else
Noble.Settings.set("debug", true)
end
return
end)
2024-06-10 01:50:27 +03:00
__menu:addItem("Credits", function() return end)
2024-06-01 16:52:11 +03:00
__menu:select("Start")
2024-06-10 01:50:27 +03:00
end