Skip to content

Commit

Permalink
Loadingscreen: Enhancements (#1538)
Browse files Browse the repository at this point in the history
Slightly tweaked the loading screen by adding some info to it. I also
added a sound that plays. I think it fits, but we need feedback on this
during beta testing I guess.


![20240530182043_1](https://github.com/TTT-2/TTT2/assets/13639408/971a9189-8430-4eba-ba7c-ea5dd49d5bb8)
  • Loading branch information
TimGoll authored May 31, 2024
1 parent 8dba67f commit e9b4faa
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
Binary file not shown.
21 changes: 2 additions & 19 deletions gamemodes/terrortown/gamemode/client/vgui/cl_sb_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ local draw = draw
local math = math
local string = string
local vgui = vgui
local floor = math.floor
local GetTranslation = LANG.GetTranslation
local GetPTranslation = LANG.GetParamTranslation
local table = table
Expand Down Expand Up @@ -117,23 +116,6 @@ surface.CreateFont("treb_small", {
weight = 700,
})

local function UntilMapChange()
local roundsLeft = gameloop.GetRoundsLeft()
local timeLeft = floor(gameloop.GetLevelTimeLeft())

local hours = floor(timeLeft / 3600)

timeLeft = timeLeft - floor(hours * 3600)

local minutes = floor(timeLeft / 60)

timeLeft = timeLeft - floor(minutes * 60)

local seconds = floor(timeLeft)

return roundsLeft, string.format("%02i:%02i:%02i", hours, minutes, seconds)
end

---
-- Comparison functions used to sort scoreboard
sboard_sort = {
Expand Down Expand Up @@ -185,7 +167,8 @@ function PANEL:Init()

self.mapchange.Think = function(sf)
if gameloop.HasLevelLimits() then
local r, t = UntilMapChange()
local r, t = gameloop.UntilMapChange()

sf:SetText(GetPTranslation("sb_mapchange", { num = r, time = t }))
else
sf:SetText(GetTranslation("sb_mapchange_disabled"))
Expand Down
4 changes: 4 additions & 0 deletions lua/terrortown/lang/en.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2301,3 +2301,7 @@ Restart a round or reset the level.
Restarting a round only restarts the current round so you can start over. Resetting the level clears everything so that the game starts new as if it is fresh after a map change.]]

L.label_button_level_reset = "reset level"

L.loadingscreen_round_restart_title = "Starting new round"
L.loadingscreen_round_restart_subtitle = "you're playing on {map}"
L.loadingscreen_round_restart_subtitle_limits = "you're playing on {map} for another {rounds} round(s) or {time}"
22 changes: 22 additions & 0 deletions lua/ttt2/libraries/gameloop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,28 @@ if CLIENT then
end
end

---
-- Returns the amount of rounds and time left until the map changes.
-- @return number The amount of rounds left
-- @return string The amount of time left as hh:mm:ss
-- @realm client
function gameloop.UntilMapChange()
local roundsLeft = gameloop.GetRoundsLeft()
local timeLeft = math.floor(gameloop.GetLevelTimeLeft())

local hours = math.floor(timeLeft / 3600)

timeLeft = timeLeft - math.floor(hours * 3600)

local minutes = math.floor(timeLeft / 60)

timeLeft = timeLeft - math.floor(minutes * 60)

local seconds = math.floor(timeLeft)

return roundsLeft, string.format("%02i:%02i:%02i", hours, minutes, seconds)
end

net.Receive("TTT_ClearClientState", function()
---
-- @realm client
Expand Down
43 changes: 42 additions & 1 deletion lua/ttt2/libraries/loadingscreen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ if CLIENT then
loadingscreen.state = LS_FADE_IN
loadingscreen.timeStateChange = SysTime()

if cvLoadingScreen:GetBool() then
surface.PlaySound("ttt/loadingscreen.wav")
end

timer.Create("TTT2LoadingscreenShow", durationStateChange, 1, function()
loadingscreen.state = LS_SHOWN
loadingscreen.timeStateChange = SysTime()
Expand Down Expand Up @@ -163,6 +167,43 @@ if CLIENT then
draw.BlurredBox(0, 0, ScrW(), ScrH(), progress * 5)
draw.Box(0, 0, ScrW(), ScrH(), colorLoadingScreen)

draw.AdvancedText(
LANG.TryTranslation("loadingscreen_round_restart_title"),
"PureSkinPopupTitle",
0.5 * ScrW(),
0.15 * ScrH(),
colorTip,
TEXT_ALIGN_CENTER,
TEXT_ALIGN_CENTER,
true,
appearance.GetGlobalScale()
)

local text = ""

if gameloop.HasLevelLimits() then
local roundsLeft, timeLeft = gameloop.UntilMapChange()

text = LANG.GetParamTranslation(
"loadingscreen_round_restart_subtitle_limits",
{ map = game.GetMap(), rounds = roundsLeft, time = timeLeft }
)
else
text = LANG.TryTranslation("loadingscreen_round_restart_subtitle")
end

draw.AdvancedText(
text,
"PureSkinPopupText",
0.5 * ScrW(),
0.2 * ScrH(),
colorTip,
TEXT_ALIGN_CENTER,
TEXT_ALIGN_CENTER,
true,
appearance.GetGlobalScale()
)

if not cvLoadingScreenTips:GetBool() then
return
end
Expand All @@ -186,7 +227,7 @@ if CLIENT then
textWrapped[i],
"PureSkinRole",
0.5 * ScrW(),
0.7 * ScrH() + i * heightLine,
0.85 * ScrH() + i * heightLine,
colorTip,
TEXT_ALIGN_CENTER,
TEXT_ALIGN_CENTER,
Expand Down

0 comments on commit e9b4faa

Please sign in to comment.