ExperimentalGear/scripts/titlescreen/splash.lua

184 lines
4.8 KiB
Lua
Raw Normal View History

local Common = require("common.util")
2022-03-03 03:55:46 +01:00
local Dim = require("common.dimensions")
local Wallpaper = require("components.wallpaper")
2022-03-03 03:55:46 +01:00
local Easing = require("common.easing")
2021-12-19 23:16:19 +01:00
2022-03-03 03:55:46 +01:00
local splash1BgColor = {182, 0, 20}
local splash1Logo = gfx.CreateSkinImage("titlescreen/splash/ksm.png", 0)
local splash1LogoWidth, splash1LogoHeight = gfx.ImageSize(splash1Logo)
2021-12-19 23:16:19 +01:00
2022-03-03 03:55:46 +01:00
local splash2BgColor = {255, 255, 255}
local splash2Logo = gfx.CreateSkinImage("titlescreen/splash/usc2.png", 0)
local splash2LogoWidth, splash2LogoHeight = gfx.ImageSize(splash2Logo)
2021-12-20 15:38:54 +01:00
2022-03-03 03:55:46 +01:00
local splashState = "init"
local splashTimer = 0
local fadeDuration = 0.5
local fadeAlpha = 0
local splashInitDuration = 1
local splash1Duration = 4
local splash2Duration = 4
2021-12-19 23:16:19 +01:00
2022-03-03 03:55:46 +01:00
game.LoadSkinSample("titlescreen/splash/splash1.wav")
local splash1SfxPlayed = false
2022-03-12 15:18:24 +01:00
local triggerSkip = false
2022-03-03 03:55:46 +01:00
local function calcFade(splashDuration)
local t = splashDuration - splashTimer
if t < fadeDuration then
fadeAlpha = Easing.linear(t, 0, 255, fadeDuration) -- fade in
elseif splashTimer < fadeDuration then
fadeAlpha = Easing.linear(splashTimer, 0, 255, fadeDuration) -- fade out
else
--fadeAlpha = 255
end
fadeAlpha = Common.round(Common.clamp(fadeAlpha, 0, 255))
end
local function initSplash(deltaTime)
if (splashTimer < 0) then
splashState = "splash1"
splashTimer = 0
return
end
if splashTimer == 0 then
splashTimer = splashInitDuration
end
2021-12-19 23:16:19 +01:00
splashTimer = splashTimer - deltaTime
2022-03-03 03:55:46 +01:00
end
local function splash1(deltaTime)
local splash1LogoXOffset = (Dim.design.width - splash1LogoWidth) / 2
local splash1LogoYOffset = (Dim.design.height - splash1LogoHeight) / 2
calcFade(splash1Duration)
gfx.BeginPath()
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
gfx.FillColor(splash1BgColor[1], splash1BgColor[2], splash1BgColor[3], fadeAlpha)
gfx.Fill()
gfx.BeginPath()
gfx.ImageRect(splash1LogoXOffset, splash1LogoYOffset, splash1LogoWidth, splash1LogoHeight, splash1Logo, fadeAlpha / 255, 0)
2022-03-12 15:18:24 +01:00
gfx.BeginPath()
gfx.LoadSkinFont("segoeui.ttf")
gfx.FillColor(255, 255, 255, fadeAlpha)
2022-04-03 01:45:54 +02:00
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_BOTTOM)
2022-03-12 15:18:24 +01:00
gfx.FontSize(28)
2022-04-03 01:45:54 +02:00
gfx.Text("Press START to skip...", 10, Dim.design.height - 10)
2022-03-12 15:18:24 +01:00
2022-03-03 03:55:46 +01:00
if (splashTimer < 0) then
splashState = "splash2"
splash1SfxPlayed = false
splashTimer = 0
return
end
if splashTimer == 0 then
splashTimer = splash1Duration
end
2021-12-19 23:16:19 +01:00
2022-03-03 03:55:46 +01:00
if not splash1SfxPlayed then
game.PlaySample("titlescreen/splash/splash1.wav")
splash1SfxPlayed = true
2021-12-20 15:38:54 +01:00
end
2022-03-03 03:55:46 +01:00
splashTimer = splashTimer - deltaTime
end
local function splash2(deltaTime)
local splash2LogoXOffset = (Dim.design.width - splash2LogoWidth) / 2
local splash2LogoYOffset = (Dim.design.height - splash2LogoHeight) / 2
calcFade(splash2Duration)
gfx.BeginPath()
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
gfx.FillColor(splash2BgColor[1], splash2BgColor[2], splash2BgColor[3], fadeAlpha)
gfx.Fill()
gfx.BeginPath()
gfx.ImageRect(splash2LogoXOffset, splash2LogoYOffset, splash2LogoWidth, splash2LogoHeight, splash2Logo, fadeAlpha / 255, 0)
2022-03-12 15:18:24 +01:00
gfx.BeginPath()
gfx.LoadSkinFont("segoeui.ttf")
gfx.FillColor(0, 0, 0, fadeAlpha)
2022-04-03 01:45:54 +02:00
gfx.TextAlign(gfx.TEXT_ALIGN_LEFT + gfx.TEXT_ALIGN_BOTTOM)
2022-03-12 15:18:24 +01:00
gfx.FontSize(28)
2022-04-03 01:45:54 +02:00
gfx.Text("Press START to skip...", 10, Dim.design.height - 10)
2022-03-12 15:18:24 +01:00
2021-12-19 23:16:19 +01:00
if (splashTimer < 0) then
2022-03-03 03:55:46 +01:00
splashState = "done"
splashTimer = 0
return
end
if splashTimer == 0 then
splashTimer = splash2Duration
end
splashTimer = splashTimer - deltaTime
end
local function reset()
triggerSkip = false
splashState = "init"
splashTimer = 0
splash1SfxPlayed = false
end
2022-03-03 03:55:46 +01:00
function render(deltaTime)
2022-03-12 15:18:24 +01:00
if triggerSkip then
reset()
2022-03-12 15:18:24 +01:00
game.StopSample("titlescreen/splash/splash1.wav")
return {
eventType = "switch",
toScreen = "title"
}
end
2022-03-03 03:55:46 +01:00
Dim.updateResolution()
Wallpaper.render()
2022-03-03 03:55:46 +01:00
Dim.transformToScreenSpace()
2022-03-12 15:18:24 +01:00
gfx.BeginPath()
2022-03-03 03:55:46 +01:00
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
2022-03-29 04:27:37 +02:00
gfx.FillColor(255, 255, 255)
2022-03-03 03:55:46 +01:00
gfx.Fill()
if splashState == "init" then
initSplash(deltaTime)
elseif splashState == "splash1" then
splash1(deltaTime)
elseif splashState == "splash2" then
splash2(deltaTime)
elseif splashState == "done" then
reset()
2021-12-19 23:16:19 +01:00
return {
2022-03-03 03:55:46 +01:00
eventType = "switch",
toScreen = "title"
2021-12-19 23:16:19 +01:00
}
2022-03-03 03:55:46 +01:00
else
game.Log("Splash screen state error, splashState: " .. splashState, game.LOGGER_ERROR)
splashState = "done"
2021-12-19 23:16:19 +01:00
end
end
2022-03-12 15:18:24 +01:00
local function onButtonPressed(button)
if button == game.BUTTON_STA then
triggerSkip = true
end
end
2021-12-19 23:16:19 +01:00
return {
2022-03-12 15:18:24 +01:00
render = render,
onButtonPressed = onButtonPressed
2021-12-19 23:16:19 +01:00
}