From 6e10fc43de8a770d58c08c66412bc3e033772337 Mon Sep 17 00:00:00 2001 From: terencehill Date: Tue, 26 Apr 2022 19:55:22 +0200 Subject: [PATCH] Show compact times (1.34 instead of 0:01.34) in some places (messages, scoreboard and rankings panel) --- qcsrc/client/hud/panel/racetimer.qc | 8 +++--- qcsrc/client/hud/panel/score.qc | 2 +- qcsrc/client/hud/panel/scoreboard.qc | 2 +- qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc | 2 +- .../common/gamemodes/gamemode/race/cl_race.qc | 4 +-- .../common/gamemodes/gamemode/race/sv_race.qc | 2 +- qcsrc/common/notifications/all.qh | 12 ++++----- qcsrc/common/util.qc | 2 +- qcsrc/common/util.qh | 2 +- qcsrc/lib/string.qh | 26 +++++++++++++++---- qcsrc/server/command/getreplies.qc | 2 +- qcsrc/server/race.qc | 2 +- 12 files changed, 41 insertions(+), 25 deletions(-) diff --git a/qcsrc/client/hud/panel/racetimer.qc b/qcsrc/client/hud/panel/racetimer.qc index 7ecdf1a82..9b812b81a 100644 --- a/qcsrc/client/hud/panel/racetimer.qc +++ b/qcsrc/client/hud/panel/racetimer.qc @@ -67,12 +67,12 @@ string MakeRaceString(int cp, float mytime, float theirtime, float othertime, fl if(mytime >= theirtime) timestr = strcat("+", ftos_decimals(mytime - theirtime, TIME_DECIMALS)); else - timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime)); + timestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(theirtime), false); col = "^3"; if(mytime >= othertime) othertimestr = strcat("+", ftos_decimals(mytime - othertime, TIME_DECIMALS)); else - othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime)); + othertimestr = TIME_ENCODED_TOSTRING(TIME_ENCODE(othertime), false); othercol = "^7"; } @@ -172,7 +172,7 @@ void HUD_RaceTimer () else s = MakeRaceString(race_checkpoint, 0, -1, 0, 0, race_previousbestname); if(race_time) - forcetime = TIME_ENCODED_TOSTRING(race_time); + forcetime = TIME_ENCODED_TOSTRING(race_time, false); } } else @@ -220,7 +220,7 @@ void HUD_RaceTimer () if(race_laptime && race_checkpoint != 255) { - s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime)); + s = TIME_ENCODED_TOSTRING(TIME_ENCODE(time + TIME_DECODE(race_penaltyaccumulator) - race_laptime), false); str_pos = pos + eX * 0.5 * (mySize.x - stringwidth(s, false, '0.6 0.6 0' * mySize.y)); drawstring(str_pos, s, '0.6 0.6 0' * mySize.y, '1 1 1', panel_fg_alpha * a, DRAWFLAG_NORMAL); } diff --git a/qcsrc/client/hud/panel/score.qc b/qcsrc/client/hud/panel/score.qc index 164f60534..c33fce08b 100644 --- a/qcsrc/client/hud/panel/score.qc +++ b/qcsrc/client/hud/panel/score.qc @@ -179,7 +179,7 @@ void HUD_Score() pl = NULL; score = me.(scores(ps_primary)); - timer = TIME_ENCODED_TOSTRING(score); + timer = TIME_ENCODED_TOSTRING(score, false); draw_beginBoldFont(); if (pl && ((!(scores_flags(ps_primary) & SFL_ZERO_IS_WORST)) || score)) { diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index ed8715e02..624a9e8b5 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -1655,7 +1655,7 @@ vector Scoreboard_Rankings_Draw(vector pos, string ranktitle, entity pl, vector str = count_ordinal(i+1); drawstring(pos + text_ofs, str, hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL); - drawstring(pos + text_ofs + eX * ranksize, TIME_ENCODED_TOSTRING(t), hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL); + drawstring(pos + text_ofs + eX * ranksize, TIME_ENCODED_TOSTRING(t, true), hud_fontsize, '1 1 1', sbt_fg_alpha, DRAWFLAG_NORMAL); str = ColorTranslateRGB(grecordholder[i]); if(cut) str = textShortenToWidth(str, namesize, hud_fontsize, stringwidth_colors); diff --git a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc index 45457d1a4..3e7c4159c 100644 --- a/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc +++ b/qcsrc/common/gamemodes/gamemode/cts/sv_cts.qc @@ -325,7 +325,7 @@ MUTATOR_HOOKFUNCTION(cts, GetRecords) continue; string h = race_readName(MapInfo_Map_bspname, 1); - ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); + ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r, false)), " ", h, "\n"); } } diff --git a/qcsrc/common/gamemodes/gamemode/race/cl_race.qc b/qcsrc/common/gamemodes/gamemode/race/cl_race.qc index 4311ce777..a551b1546 100644 --- a/qcsrc/common/gamemodes/gamemode/race/cl_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/cl_race.qc @@ -31,10 +31,10 @@ int race_CheckName(string net_name) void race_showTime(string text, vector pos, vector timeText_ofs, float theTime, vector textSize, float f) { drawstring_aspect(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); - drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); + drawstring_aspect(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime, false), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL); if (f < 1) { drawstring_aspect_expanding(pos, text, textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f); - drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f); + drawstring_aspect_expanding(pos + timeText_ofs, TIME_ENCODED_TOSTRING(theTime, false), textSize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL, f); } } diff --git a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc index 0ffda17a9..f06df370d 100644 --- a/qcsrc/common/gamemodes/gamemode/race/sv_race.qc +++ b/qcsrc/common/gamemodes/gamemode/race/sv_race.qc @@ -350,7 +350,7 @@ MUTATOR_HOOKFUNCTION(rc, GetRecords) continue; string h = race_readName(MapInfo_Map_bspname, 1); - ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); + ret_string = strcat(ret_string, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r, false)), " ", h, "\n"); } } diff --git a/qcsrc/common/notifications/all.qh b/qcsrc/common/notifications/all.qh index 45259741b..fb06d264a 100644 --- a/qcsrc/common/notifications/all.qh +++ b/qcsrc/common/notifications/all.qh @@ -358,8 +358,8 @@ float autocvar_notification_show_sprees_center_specialonly = true; f1points: point or points depending on f1 f1ord: count_ordinal of f1 f1time: process_time of f1 - f1race_time: mmssth of f1 - f2race_time: mmssth of f2 + f1race_time: TIME_ENCODED_TOSTRING of f1 + f2race_time: TIME_ENCODED_TOSTRING of f2 race_col: color of race time/position (i.e. good or bad) race_diff: show time difference between f2 and f3 missing_teams: show which teams still need players @@ -418,11 +418,11 @@ string BUFF_NAME(int i); ARG_CASE(ARG_CS, "f1points", (f1 == 1 ? _("point") : _("points"))) \ ARG_CASE(ARG_CS_SV, "f1ord", count_ordinal(f1)) \ ARG_CASE(ARG_CS_SV, "f1time", process_time(2, f1)) \ - ARG_CASE(ARG_CS_SV_HA, "f1race_time", mmssth(f1)) \ - ARG_CASE(ARG_CS_SV_HA, "f2race_time", mmssth(f2)) \ - ARG_CASE(ARG_CS_SV_HA, "f3race_time", mmssth(f3)) \ + ARG_CASE(ARG_CS_SV_HA, "f1race_time", TIME_ENCODED_TOSTRING(f1, true)) \ + ARG_CASE(ARG_CS_SV_HA, "f2race_time", TIME_ENCODED_TOSTRING(f2, true)) \ + ARG_CASE(ARG_CS_SV_HA, "f3race_time", TIME_ENCODED_TOSTRING(f3, true)) \ ARG_CASE(ARG_CS_SV, "race_col", CCR(((f1 == 1) ? "^F1" : "^F2"))) \ - ARG_CASE(ARG_CS_SV, "race_diff", ((f2 > f3) ? sprintf(CCR("^1[+%s]"), mmssth(f2 - f3)) : sprintf(CCR("^2[-%s]"), mmssth(f3 - f2)))) \ + ARG_CASE(ARG_CS_SV, "race_diff", ((f2 > f3) ? sprintf(CCR("^1[+%s]"), TIME_ENCODED_TOSTRING(f2 - f3, true)) : sprintf(CCR("^2[-%s]"), TIME_ENCODED_TOSTRING(f3 - f2, true)))) \ ARG_CASE(ARG_CS, "missing_teams", notif_arg_missing_teams(f1)) \ ARG_CASE(ARG_CS, "pass_key", getcommandkey(_("drop flag"), "+use")) \ ARG_CASE(ARG_CS, "nade_key", getcommandkey(_("throw nade"), "dropweapon")) \ diff --git a/qcsrc/common/util.qc b/qcsrc/common/util.qc index 0b1b96880..8ef6b2019 100644 --- a/qcsrc/common/util.qc +++ b/qcsrc/common/util.qc @@ -384,7 +384,7 @@ string ScoreString(int pFlags, float pValue) else if(pFlags & SFL_RANK) valstr = (pValue < 256 ? count_ordinal(pValue) : _("N/A")); else if(pFlags & SFL_TIME) - valstr = TIME_ENCODED_TOSTRING(pValue); + valstr = TIME_ENCODED_TOSTRING(pValue, true); else valstr = ftos(pValue); diff --git a/qcsrc/common/util.qh b/qcsrc/common/util.qh index 3ca09994a..3c12463d3 100644 --- a/qcsrc/common/util.qh +++ b/qcsrc/common/util.qh @@ -88,7 +88,7 @@ void depthfirst(entity start, .entity up, .entity downleft, .entity right, void( const int TIME_DECIMALS = 2; const float TIME_FACTOR = 100; -#define TIME_ENCODED_TOSTRING(n) mmssth(n) +#define TIME_ENCODED_TOSTRING(n, compact) mmssth(n, compact) #define RACE_RECORD "/race100record/" #define CTS_RECORD "/cts100record/" #define CTF_RECORD "/ctf100record/" diff --git a/qcsrc/lib/string.qh b/qcsrc/lib/string.qh index 6a37d5edd..c2e77aacc 100644 --- a/qcsrc/lib/string.qh +++ b/qcsrc/lib/string.qh @@ -139,23 +139,39 @@ string seconds_tostring(float seconds) /// \param[in] tm integer clocked time in tenths or hundredths, CANNOT be negative /// \param[in] hundredths if true append hundredths too, otherwise only tenths +/// \param[in] compact if true leading 0s are omitted (except the seconds unit digit) /// \return clocked time as "m:ss.t" or "m:ss.th" string (rounded) ERASEABLE -string clockedtime_tostring(int tm, bool hundredths) +string clockedtime_tostring(int tm, bool hundredths, bool compact) { if (tm < 0) - return strcat("0:00:0", hundredths ? "0" : ""); + { + if (compact) + return strcat("0.0", hundredths ? "0" : ""); + else + return strcat("0:00.0", hundredths ? "0" : ""); + } int acc = hundredths ? 6000 : 600; tm = floor(tm + 0.5); int minutes = floor(tm / acc); int tm_without_minutes = tm - minutes * acc; // NOTE: the start digit of s is a placeholder and won't be displayed string s = ftos(acc * 10 + tm_without_minutes); - return strcat(ftos(minutes), ":", substring(s, 1, 2), ".", substring(s, 3, hundredths ? 2 : 1)); + if (!compact || minutes > 0) + return strcat(ftos(minutes), ":", substring(s, 1, 2), ".", substring(s, 3, hundredths ? 2 : 1)); + + int ofs = 2, digits = 1; + if (tm_without_minutes >= 10 * (hundredths ? 100 : 10)) + { + ofs = 1; + digits = 2; + } + return strcat(substring(s, ofs, digits), ".", substring(s, 3, hundredths ? 2 : 1)); + } -#define mmsst(tm) clockedtime_tostring(tm, false) -#define mmssth(tm) clockedtime_tostring(tm, true) +#define mmsst(tm, compact) clockedtime_tostring(tm, false, compact) +#define mmssth(tm, compact) clockedtime_tostring(tm, true, compact) ERASEABLE string format_time(float seconds) diff --git a/qcsrc/server/command/getreplies.qc b/qcsrc/server/command/getreplies.qc index 3f82484ab..b6bde0c68 100644 --- a/qcsrc/server/command/getreplies.qc +++ b/qcsrc/server/command/getreplies.qc @@ -59,7 +59,7 @@ string getrankings() n = race_readName(map, i); p = count_ordinal(i); - s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n"); + s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t, false)), " ", n, "\n"); } MapInfo_ClearTemps(); diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index 4ecda0a9a..71ab29060 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -61,7 +61,7 @@ void write_recordmarker(entity pl, float tstart, float dt) // also write a marker into demo files for demotc-race-record-extractor to find stuffcmd(pl, strcat( - strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt))), + strcat("//", strconv(2, 0, 0, GetGametype()), " RECORD SET ", TIME_ENCODED_TOSTRING(TIME_ENCODE(dt), false)), " ", ftos(tstart), " ", ftos(dt), "\n")); } -- 2.39.2