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") local TitleScreen = require('titlescreen.title') local ModeSelectScreen = require('titlescreen.modeselect') local ServiceScreen = require('titlescreen.service') game.Log("HELLO FROM TITLESCREEN", game.LOGGER_DEBUG) local screens = { [BootPage.__name] = BootPage.new(), [SplashPage.__name] = SplashPage.new(), --title = titleScreen, --[tostring(ModeSelectPage)] = ModeSelectPage.new(), --[tostring(ServiceMenuPage)] = ServiceMenuPage.new() } 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 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 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