ExperimentalGear/scripts/titlescreen.lua

120 lines
3.4 KiB
Lua
Raw Normal View History

require("common.globals")
local Common = require("common.util")
local Dim = require("common.dimensions")
local Wallpaper = require("components.wallpaper")
local PageView = require("api.page.pageview")
local BootPage = require("titlescreen.boot")
local SplashPage = require('titlescreen.splash')
local ModeSelectPage = require("titlescreen.pages.modeselect.modeselectpage")
local ServiceMenuPage = require("titlescreen.pages.service.mainmenupage")
game.Log("HELLO FROM TITLESCREEN", game.LOGGER_DEBUG)
2021-12-19 23:16:19 +01:00
local screens = {
[BootPage.__name] = BootPage.new(),
[SplashPage.__name] = SplashPage.new(),
--title = titleScreen,
--[tostring(ModeSelectPage)] = ModeSelectPage.new(),
--[tostring(ServiceMenuPage)] = ServiceMenuPage.new()
2021-12-19 23:16:19 +01:00
}
2021-07-25 20:10:06 +02:00
local pageView = PageView.new()
pageView.onNavigated = function(self, back)
game.Log(tostring(self) .. " navigated " .. (back and "back " or "") .. "to: " .. tostring(pageView:get()),
game.LOGGER_INFO
)
end
pageView.onEmptied = function(self)
game.Log(tostring(self) .. " empty!", game.LOGGER_WARNING)
end
local function switchScreens(newScreen)
pageView:replace(newScreen)
pageView:get():init()
end
screens[BootPage.__name].onInvalidation = function(self)
switchScreens(screens[SplashPage.__name])
end
screens[SplashPage.__name].onInvalidation = function(self)
--TODO: TitlePage
--switchScreens(screens[TitlePage.__name])
end
--[[ TODO: remaining Pages
screens[TitlePage.__name].onInvalidation = function(self)
switchScreens(screens[ModeSelectPage.__name])
end
2021-07-25 20:10:06 +02:00
screens[ServiceMenuPage.__name].onInvalidation = function(self)
switchScreens(screens[SplashPage.__name])
end
]]
--local currentScreen = game.GetSkinSetting("animations_skipIntro") and screens.title or screens.boot -- show boot screen if skipIntro is not set
switchScreens(screens[BootPage.__name])
local function deltaKnob(delta)
-- can someone tell me what the hell does this do? - Hersi
if math.abs(delta) > 1.5 * math.pi then
return delta + 2 * math.pi * Common.sign(delta) * -1
end
return delta
2021-07-25 20:10:06 +02:00
end
local lastKnobs = nil
local knobThreshold = (2 * math.pi) / 360
local function handleKnobs()
if lastKnobs == nil then
lastKnobs = {game.GetKnob(game.KNOB_LEFT), game.GetKnob(game.KNOB_RIGHT)}
else
local newKnobs = {game.GetKnob(game.KNOB_LEFT), game.GetKnob(game.KNOB_RIGHT)}
local knobProgress = {deltaKnob(lastKnobs[1] - newKnobs[1]), deltaKnob(lastKnobs[2] - newKnobs[2])}
lastKnobs = newKnobs
if math.abs(knobProgress[1]) > knobThreshold then
if pageView:get() then
pageView:get():handleKnobInput(game.KNOB_LEFT, knobProgress[1])
end
end
if math.abs(knobProgress[2]) > knobThreshold then
if pageView:get() then
pageView:get():handleKnobInput(game.KNOB_RIGHT, knobProgress[2])
end
end
end
end
function render(deltaTime)
handleKnobs()
Dim.updateResolution()
Wallpaper.render()
Dim.transformToScreenSpace()
pageView:render(deltaTime)
end
function mouse_pressed(button)
local mouseX, mouseY = game.GetMousePos()
if pageView:get() then
pageView:get():handleMouseInput(mouseX, mouseY, button)
end
return 0 --THIS '0' IS VERY IMPORTANT, IT WILL CRASH VERY HARD WITHOUT THIS
end
function button_pressed(button)
if pageView:get() then
pageView:get():handleButtonInput(button)
end
end