2022-06-29 00:35:52 +02:00
|
|
|
local Util = require("common.util")
|
2022-03-03 03:55:46 +01:00
|
|
|
local Dim = require("common.dimensions")
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
require "common.globals"
|
|
|
|
require "common.class"
|
2022-06-29 00:35:52 +02:00
|
|
|
|
|
|
|
local PageManager = require "api.page.pagemanager"
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
local Page = require "api.page.page"
|
2022-07-12 01:43:14 +02:00
|
|
|
local KShootManiaPage = require "titlescreen.splash.kshootmaniapage"
|
|
|
|
local USCPage = require "titlescreen.splash.uscpage"
|
|
|
|
local TeamExceedPage = require "titlescreen.splash.teamexceedpage"
|
|
|
|
local CreditsPage = require "titlescreen.splash.creditspage"
|
2022-06-22 02:58:47 +02:00
|
|
|
|
|
|
|
---@class SplashPage : Page
|
|
|
|
---@field pages Page[]
|
|
|
|
---@field currentPage integer
|
|
|
|
---@field _isTransitioning boolean # actively fading between pages
|
2022-06-29 00:35:52 +02:00
|
|
|
---@field _isFadeOut boolean # fading out between pages
|
2022-06-22 02:58:47 +02:00
|
|
|
local SplashPage = {
|
|
|
|
__name = "SplashScreen",
|
|
|
|
BACKGROUND_COLOR = {255, 255, 255},
|
2022-06-29 00:35:52 +02:00
|
|
|
FADE_DURATION = 0.25
|
2022-06-22 02:58:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
---Create a new SplashScreen instance
|
|
|
|
---@param params? SplashPage
|
|
|
|
---@return SplashPage
|
|
|
|
function SplashPage.new(params)
|
|
|
|
local self = CreateInstance(SplashPage, params, Page)
|
|
|
|
|
2022-06-29 00:35:52 +02:00
|
|
|
local pageManager = PageManager.get()
|
|
|
|
|
|
|
|
self.currentPage = 0 -- start on nil page
|
2022-06-22 02:58:47 +02:00
|
|
|
self.content = {
|
2022-06-29 00:35:52 +02:00
|
|
|
pageManager:getPage(KShootManiaPage),
|
|
|
|
pageManager:getPage(USCPage),
|
|
|
|
pageManager:getPage(TeamExceedPage),
|
|
|
|
pageManager:getPage(CreditsPage),
|
2022-06-22 02:58:47 +02:00
|
|
|
}
|
|
|
|
|
2022-06-29 00:35:52 +02:00
|
|
|
self._isTransitioning = true -- immediately transition to first page
|
|
|
|
self._isFadeOut = false
|
2022-06-22 02:58:47 +02:00
|
|
|
|
|
|
|
-- 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
|
2022-03-03 03:55:46 +01:00
|
|
|
end
|
2022-06-22 02:58:47 +02:00
|
|
|
return self
|
2022-03-03 03:55:46 +01:00
|
|
|
end
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
function SplashPage:init()
|
2022-06-29 00:35:52 +02:00
|
|
|
self.currentPage = 0
|
|
|
|
self._isTransitioning = true
|
|
|
|
for _, page in ipairs(self.content) do
|
|
|
|
page:init()
|
|
|
|
end
|
2022-06-22 02:58:47 +02:00
|
|
|
Page.init(self)
|
|
|
|
end
|
2021-12-19 23:16:19 +01:00
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
function SplashPage:handleButtonInput(button)
|
|
|
|
if button == game.BUTTON_STA then
|
2022-06-29 00:35:52 +02:00
|
|
|
game.StopSample(KShootManiaPage.SAMPLE_PATH) -- hack to stop splash screen sample from playing when skipping
|
2022-06-22 02:58:47 +02:00
|
|
|
self:onInvalidation()
|
2021-12-20 15:38:54 +01:00
|
|
|
end
|
2022-03-03 03:55:46 +01:00
|
|
|
end
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
---Fade between pages
|
2022-06-29 00:35:52 +02:00
|
|
|
function SplashPage:fadeTransition(deltaTime)
|
|
|
|
local fadeDuration = self.FADE_DURATION
|
|
|
|
local fadeColor = self.BACKGROUND_COLOR
|
2022-03-12 15:18:24 +01:00
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
-- reset variables on first call
|
|
|
|
if not self["__fadeStarted"] then
|
|
|
|
self.__fadeTimer = 0.0
|
|
|
|
self.__fadeStarted = true
|
2022-03-03 03:55:46 +01:00
|
|
|
end
|
|
|
|
|
2022-06-29 00:35:52 +02:00
|
|
|
local fadeAlpha = 0.0
|
2022-06-22 02:58:47 +02:00
|
|
|
local halfDuration = fadeDuration / 2
|
|
|
|
if self.__fadeTimer < halfDuration then
|
2022-06-29 00:35:52 +02:00
|
|
|
fadeAlpha = math.ceil(Util.lerp(self.__fadeTimer, 0, 0, halfDuration, 255)) -- fade out
|
|
|
|
|
|
|
|
self._isFadeOut = true
|
|
|
|
|
2022-06-22 03:03:48 +02:00
|
|
|
elseif self.__fadeTimer < fadeDuration then
|
2022-06-29 00:35:52 +02:00
|
|
|
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
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
else
|
|
|
|
self.__fadeStarted = false -- fade done, reset variable
|
|
|
|
self._isTransitioning = false
|
2022-06-29 00:35:52 +02:00
|
|
|
self._isFadeOut = false
|
|
|
|
|
2022-03-03 03:55:46 +01:00
|
|
|
end
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
local fillColor = {table.unpack(fadeColor, 1, 3)} -- copy color table
|
|
|
|
table.insert(fillColor, fadeAlpha) -- add alpha
|
2022-04-03 03:02:16 +02:00
|
|
|
|
|
|
|
gfx.BeginPath()
|
2022-06-22 02:58:47 +02:00
|
|
|
gfx.FillColor(table.unpack(fillColor))
|
2022-04-03 03:02:16 +02:00
|
|
|
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
|
|
|
|
gfx.Fill()
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
self.__fadeTimer = self.__fadeTimer + deltaTime
|
2022-04-03 03:02:16 +02:00
|
|
|
end
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
function SplashPage:drawBackground(deltaTime)
|
2022-03-12 15:18:24 +01:00
|
|
|
gfx.BeginPath()
|
2022-06-22 02:58:47 +02:00
|
|
|
gfx.FillColor(table.unpack(self.BACKGROUND_COLOR))
|
2022-03-03 03:55:46 +01:00
|
|
|
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
|
|
|
|
gfx.Fill()
|
2022-06-22 02:58:47 +02:00
|
|
|
end
|
2022-03-03 03:55:46 +01:00
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
function SplashPage:drawContent(deltaTime)
|
2022-06-29 00:35:52 +02:00
|
|
|
if self.content[self.currentPage] then
|
|
|
|
self.content[self.currentPage]:render(deltaTime)
|
|
|
|
end
|
2021-12-19 23:16:19 +01:00
|
|
|
end
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
function SplashPage:drawForeground(deltaTime)
|
2022-06-29 00:35:52 +02:00
|
|
|
local textFillColor = {0, 0, 0}
|
|
|
|
if self.currentPage <= 1 then
|
|
|
|
textFillColor = {255, 255, 255}
|
|
|
|
end
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
if self._isTransitioning then
|
2022-06-29 00:35:52 +02:00
|
|
|
self:fadeTransition(deltaTime)
|
2022-03-12 15:18:24 +01:00
|
|
|
end
|
2022-06-29 00:35:52 +02:00
|
|
|
|
|
|
|
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)
|
2022-03-12 15:18:24 +01:00
|
|
|
end
|
|
|
|
|
2022-06-22 02:58:47 +02:00
|
|
|
return SplashPage
|