local Util = require("common.util") local Dim = require("common.dimensions") require "common.globals" require "common.class" local PageManager = require "api.page.pagemanager" local Page = require "api.page.page" local KShootManiaPage = require "titlescreen.splash.kshootmaniapage" local USCPage = require "titlescreen.splash.uscpage" local TeamExceedPage = require "titlescreen.splash.teamexceedpage" local CreditsPage = require "titlescreen.splash.creditspage" ---@class SplashPage : Page ---@field pages Page[] ---@field currentPage integer ---@field _isTransitioning boolean # actively fading between pages ---@field _isFadeOut boolean # fading out between pages local SplashPage = { __name = "SplashScreen", BACKGROUND_COLOR = {255, 255, 255}, FADE_DURATION = 0.25 } ---Create a new SplashScreen instance ---@param params? SplashPage ---@return SplashPage function SplashPage.new(params) local self = CreateInstance(SplashPage, params, Page) local pageManager = PageManager.get() self.currentPage = 0 -- start on nil page self.content = { pageManager:getPage(KShootManiaPage), pageManager:getPage(USCPage), pageManager:getPage(TeamExceedPage), pageManager:getPage(CreditsPage), } self._isTransitioning = true -- immediately transition to first page self._isFadeOut = false -- set callbacks for index, page in ipairs(self.content) do if index < #self.content then page.onInvalidation = function (page_inst) self._isTransitioning = true end else -- last index page.onInvalidation = function (page_inst) self:onInvalidation() end end end return self end function SplashPage:init() self.currentPage = 0 self._isTransitioning = true for _, page in ipairs(self.content) do page:init() end Page.init(self) end function SplashPage:handleButtonInput(button) if button == game.BUTTON_STA then game.StopSample(KShootManiaPage.SAMPLE_PATH) -- hack to stop splash screen sample from playing when skipping self:onInvalidation() end end ---Fade between pages function SplashPage:fadeTransition(deltaTime) local fadeDuration = self.FADE_DURATION local fadeColor = self.BACKGROUND_COLOR -- reset variables on first call if not self["__fadeStarted"] then self.__fadeTimer = 0.0 self.__fadeStarted = true end local fadeAlpha = 0.0 local halfDuration = fadeDuration / 2 if self.__fadeTimer < halfDuration then fadeAlpha = math.ceil(Util.lerp(self.__fadeTimer, 0, 0, halfDuration, 255)) -- fade out self._isFadeOut = true elseif self.__fadeTimer < fadeDuration then fadeAlpha = math.ceil(Util.lerp(self.__fadeTimer, halfDuration, 255, fadeDuration, 0)) -- fade in if self._isFadeOut then -- just switched to fading in, swap to new page self.currentPage = self.currentPage + 1 end self._isFadeOut = false else self.__fadeStarted = false -- fade done, reset variable self._isTransitioning = false self._isFadeOut = false end local fillColor = {table.unpack(fadeColor, 1, 3)} -- copy color table table.insert(fillColor, fadeAlpha) -- add alpha gfx.BeginPath() gfx.FillColor(table.unpack(fillColor)) gfx.Rect(0, 0, Dim.design.width, Dim.design.height) gfx.Fill() self.__fadeTimer = self.__fadeTimer + deltaTime end function SplashPage:drawBackground(deltaTime) gfx.BeginPath() gfx.FillColor(table.unpack(self.BACKGROUND_COLOR)) gfx.Rect(0, 0, Dim.design.width, Dim.design.height) gfx.Fill() end function SplashPage:drawContent(deltaTime) if self.content[self.currentPage] then self.content[self.currentPage]:render(deltaTime) end end function SplashPage:drawForeground(deltaTime) local textFillColor = {0, 0, 0} if self.currentPage <= 1 then textFillColor = {255, 255, 255} end if self._isTransitioning then self:fadeTransition(deltaTime) end gfx.LoadSkinFont("segoeui.ttf") gfx.FillColor(table.unpack(textFillColor)) gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_BOTTOM) gfx.FontSize(28) gfx.Text("Press START to skip...", 10, Dim.design.height - 10) end return SplashPage