#include "ui_extensions.lua" SplashScreen = {} SplashScreen.tuxedoLogoDuration = 3.5 SplashScreen.saberLogoDuration= 2.5 SplashScreen.totalLogoShowTime = SplashScreen.tuxedoLogoDuration + SplashScreen.saberLogoDuration t = nil showText = nil done = nil splashTime = nil requiredTime = nil animImage = nil animPreloaded = nil animTime = nil function init() t = 0 showText = 0 done = false splashTime = 20 requiredTime = SplashScreen.totalLogoShowTime + 1 -- one additional second for warning screen animImage = "splash/logo-animation.png" animPreloaded = false animTime = 0.0 end function tick() if animPreloaded then t = t + GetTimeStep() if InputPressed("any") then if t > 2.0 and t < SplashScreen.tuxedoLogoDuration then t = SplashScreen.tuxedoLogoDuration elseif t > SplashScreen.tuxedoLogoDuration + 1 and t < SplashScreen.saberLogoDuration + SplashScreen.tuxedoLogoDuration then t = SplashScreen.saberLogoDuration + SplashScreen.tuxedoLogoDuration end end if t > splashTime or (t > requiredTime and InputPressed("any")) then if not done then Menu() done = true end end end end function drawTileAnimation(img, tt, tileWidth, tileHeight, maxFrame) local timePerFrame = 0.016667 local frame = math.min(math.floor(tt / timePerFrame), maxFrame) local w, _ = UiGetImageSize(img) local tilesX = math.floor(w/tileWidth) local x = (frame % tilesX) * tileWidth local y = math.floor(frame / tilesX) * tileHeight UiImage(img, x, y, x+tileWidth, y+tileHeight) end SplashScreen.drawStartTime = 0.0 SplashScreen.drawSaberLogo = function(self, time) local fadeOutTime = 1.0 local fadeInTime = 0.0 local showTime = 1.5 UiPush() UiAlign("middle center") UiTranslateToScreenCenter() UiTranslateToScreenMiddle() UiColorFilter(1, 1, 1, 1) local deltaTime = time - self.drawStartTime if deltaTime < fadeOutTime then local fade = deltaTime / fadeOutTime UiColor(1, 1, 1, fade) elseif deltaTime > fadeOutTime + showTime then local fade = 1 - (deltaTime - (fadeOutTime + showTime)) / fadeInTime UiColor(1, 1, 1, fade) else UiColor(1, 1, 1, 1) end UiImageBox("splash/saber_logo.png", 264, 231, 0, 0) UiPop() end SplashScreen.drawTuxedoLogo = function(self, time, dt) local t_from_start = time - self.drawStartTime -- show tuxedo logo local showTime = 4.0 if t_from_start > showTime then return end UiPush() UiColor(0,0,0) UiRect(UiWidth(), UiHeight()) UiAlign("center middle") UiTranslate(UiCenter(), UiMiddle()-70) local fade = 1.0 if t_from_start < 3.0 then fade = 1.0 else fade = 0.0 end UiColor(1, 1, 1, fade) if t_from_start > 0.2 then if animTime == 0 then UiSound("splash/logo.ogg") end drawTileAnimation(animImage, animTime, 256, 256, 89) if animTime < 0.4 then animTime = animTime + dt * 0.5 else animTime = animTime + dt end end if t_from_start > 1.8 and t_from_start < showTime and showText == 0 then SetValue("showText", 1, "bounce", 0.5) end if t_from_start > showTime and showText == 1 then showText = 0 end if showText > 0 then UiTranslate(0, 160) UiColor(1, 1, 1, showText * fade) UiScale(1, showText) UiImage("splash/logo-text.png") end UiPop() end SplashScreen.drawWarning = function(self, time) local deltaTime = time - self.drawStartTime local fade = deltaTime > 1.0 and 1.0 or deltaTime UiPush() UiColor(0,0,0) UiRect(UiWidth(), UiHeight()) UiTranslate(UiCenter(), UiMiddle() - 90) local showLargeUI = GetBool("game.largeui") local scale = 1 if showLargeUI then scale = 1.3 end UiColorFilter(1, 1, 1, fade) UiScale(scale) UiAlign("center") UiPush() UiFont("bold.ttf", 48) UiColor(1, 0.2, 0.2) UiText("loc@UI_TEXT_WARNING") UiPop() UiTranslate(0, 61/scale) UiPush() UiTextAlignment("center") UiWordWrap(500) UiFont("bold.ttf", 24) UiColor(1, 1, 1) UiText("loc@UI_TEXT_THIS_GAME", true) UiTranslate(0, 30) UiText("loc@UI_TEXT_TEARDOWN_IS", true) UiPop() UiTranslate(0, 396/scale) UiPush() UiFont("bold.ttf", 30) UiColor(1, 1, 1) UiText("loc@UI_TEXT_PRESS_ANY", true) UiPop() UiTranslate(0, 105/scale) UiPush() UiFont("bold.ttf", 24) UiColor(0.2, 0.2, 0.2) UiText("loc@UI_TEXT_COPYRIGHT", true) UiPop() UiPop() end function draw(dt) if not animPreloaded then UiGetImageSize(animImage) animPreloaded = true return end if t < SplashScreen.tuxedoLogoDuration then SplashScreen:drawTuxedoLogo(t, dt) elseif t > SplashScreen.tuxedoLogoDuration and t < SplashScreen.saberLogoDuration + SplashScreen.tuxedoLogoDuration then SplashScreen.drawStartTime = SplashScreen.tuxedoLogoDuration SplashScreen:drawSaberLogo(t, dt) else SplashScreen.drawStartTime = SplashScreen.tuxedoLogoDuration + SplashScreen.saberLogoDuration SplashScreen:drawWarning(t) end end