Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loadingscreen: Cleanup #1601

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading