Skip to content

Commit

Permalink
Loadingscreen: Cleanup (TTT-2#1601)
Browse files Browse the repository at this point in the history
As requested on Discord I added a minimum render time, by default it is
4 seconds. For now you can't change it via convar, you have to call
`loadingscreen.SetDuration` to edit that.

Moreover I cleaned up the rendering of the loadingscreen, mostly by
improving the blurry-ness
  • Loading branch information
TimGoll authored Aug 27, 2024
1 parent fb43db1 commit a46ce36
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 10 deletions.
4 changes: 4 additions & 0 deletions lua/ttt2/libraries/gameloop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ if SERVER then
gameloop.SetLevelStartTime(CurTime())
end

-- make sure that the duration of the loading screen is added to the
-- duration of the prep time
timePrepPhase = timePrepPhase + loadingscreen.GetDuration()

gameloop.mapWinType = WIN_NONE

-- reset the role of all players on the server and client
Expand Down
57 changes: 47 additions & 10 deletions lua/ttt2/libraries/loadingscreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function loadingscreen.Begin()
-- add manual syncing so that the loading screen starts as soon as the
-- cleanup map is started
if SERVER then
loadingscreen.timeBegin = SysTime()

timer.Remove("TTT2LoadingscreenEndTime")

net.Start("TTT2LoadingScreenActive")
net.WriteBool(true)
net.Broadcast()
Expand All @@ -47,16 +51,26 @@ end
-- @internal
-- @realm shared
function loadingscreen.End()
loadingscreen.isShown = false
if CLIENT then
loadingscreen.isShown = false
end

if SERVER then
net.Start("TTT2LoadingScreenActive")
net.WriteBool(false)
net.Broadcast()
local duration = loadingscreen.timeBegin - SysTime() + loadingscreen.GetDuration()

-- this timer makes sure the loading screen is displayed for at least the
-- time that is set as the minimum time
timer.Create("TTT2LoadingscreenEndTime", duration, 1, function()
loadingscreen.isShown = false

-- disables sounds a while longer so it stays muted
timer.Simple(1.5, function()
loadingscreen.disableSounds = false
net.Start("TTT2LoadingScreenActive")
net.WriteBool(false)
net.Broadcast()

-- disables sounds a while longer so it stays muted
timer.Simple(1.5, function()
loadingscreen.disableSounds = false
end)
end)
end
end
Expand All @@ -69,6 +83,22 @@ if SERVER then
return false
end
end)

---
-- Reads the minimum time that a loadingscreen should have.
-- @return number The minimum time
-- @realm server
function loadingscreen.GetDuration()
return loadingscreen.duration or 4
end

---
-- Sets the minimum time that a loadingscreen should have.
-- @param number duration The minimum time in seconds
-- @realm server
function loadingscreen.SetDuration(duration)
loadingscreen.duration = duration
end
end

if CLIENT then
Expand Down Expand Up @@ -158,13 +188,20 @@ if CLIENT then
- math.min((SysTime() - loadingscreen.timeStateChange) / durationStateChange, 1.0)
end

local c = vskin.GetBackgroundColor()
-- stop rendering the loadingscreen if the progress is close to 0, this removes
-- an ugly step when transitioning from blurry to sharp
if progress < 0.01 then
return
end

local c = util.ColorDarken(vskin.GetDarkAccentColor(), 90)

local colorLoadingScreen = Color(c.r, c.g, c.b, 220 * progress)
local colorLoadingScreen = Color(c.r, c.g, c.b, 235 * progress)
local colorTip = table.Copy(util.GetDefaultColor(colorLoadingScreen))
colorTip.a = 255 * progress

draw.BlurredBox(0, 0, ScrW(), ScrH(), progress * 5)
draw.BlurredBox(0, 0, ScrW(), ScrH(), progress * 10)
draw.BlurredBox(0, 0, ScrW(), ScrH(), progress * 3)
draw.Box(0, 0, ScrW(), ScrH(), colorLoadingScreen)

draw.AdvancedText(
Expand Down

0 comments on commit a46ce36

Please sign in to comment.