diff --git a/lua/ttt2/libraries/gameloop.lua b/lua/ttt2/libraries/gameloop.lua index da0babde44..5ec3333b7e 100644 --- a/lua/ttt2/libraries/gameloop.lua +++ b/lua/ttt2/libraries/gameloop.lua @@ -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 diff --git a/lua/ttt2/libraries/loadingscreen.lua b/lua/ttt2/libraries/loadingscreen.lua index 1e8f72605e..5223fa0a63 100644 --- a/lua/ttt2/libraries/loadingscreen.lua +++ b/lua/ttt2/libraries/loadingscreen.lua @@ -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() @@ -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 @@ -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 @@ -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(