require "common.globals" local Common = require "common.util" local Display = require "scripts.graphics.display" local Wallpaper = require "components.wallpaper" local PageView = require "api.page.pageview" local PageRegistry = require "api.page.pageregistry" local BootPage = require "titlescreen.boot" local SplashPage = require "titlescreen.splash" local TitlePage = require "titlescreen.title" local MainMenuPage = require "titlescreen.mainmenu" local ServiceMenuPage = require "titlescreen.service" local VersionInfoPage = require "titlescreen.service.versioninfopage" 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 PageRegistry:getOrCreatePage(BootPage).onInvalidation = function(self, toVersionPage) if toVersionPage then pageView:replace(PageRegistry:getOrCreatePage(ServiceMenuPage)) pageView:get():init() pageView:navigate(PageRegistry:getOrCreatePage(VersionInfoPage)) pageView:get():init() else pageView:replace(PageRegistry:getOrCreatePage(SplashPage)) pageView:get():init() end end PageRegistry:getOrCreatePage(SplashPage).onInvalidation = function(self) pageView:replace(PageRegistry:getOrCreatePage(TitlePage)) pageView:get():init() end PageRegistry:getOrCreatePage(TitlePage).onInvalidation = function(self, toServiceMenu) if toServiceMenu then pageView:replace(PageRegistry:getOrCreatePage(ServiceMenuPage)) pageView:get():init() else pageView:replace(PageRegistry:getOrCreatePage(MainMenuPage)) pageView:get():init() end end PageRegistry:getOrCreatePage(ServiceMenuPage).onInvalidation = function(self) pageView:replace(PageRegistry:getOrCreatePage(SplashPage)) pageView:get():init() end --local currentScreen = game.GetSkinSetting("animations_skipIntro") and screens.title or screens.boot -- show boot screen if skipIntro is not set pageView:replace(PageRegistry:getOrCreatePage(BootPage)) pageView:get():init() 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() Display.updateResolution() Wallpaper.render() Display.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