From: z411 Date: Mon, 7 Feb 2022 22:36:41 +0000 (-0300) Subject: Implement secondary timer and subtext X-Git-Tag: xonotic-v0.8.5~177^2~24 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=146e7c375e5ea326da320faf1a8a362223770726;p=xonotic%2Fxonotic-data.pk3dir.git Implement secondary timer and subtext --- diff --git a/qcsrc/client/hud/panel/timer.qc b/qcsrc/client/hud/panel/timer.qc index 035d21b60..ff7aab1d6 100644 --- a/qcsrc/client/hud/panel/timer.qc +++ b/qcsrc/client/hud/panel/timer.qc @@ -29,34 +29,37 @@ void HUD_Timer() HUD_Scale_Enable(); else HUD_Scale_Disable(); - HUD_Panel_DrawBg(); if(panel_bg_padding) { pos += '1 1 0' * panel_bg_padding; mySize -= '2 2 0' * panel_bg_padding; } - string timer; - float timelimit, timeleft, minutesLeft; - - timelimit = STAT(TIMELIMIT); - - timeleft = bound(0, timelimit * 60 + STAT(GAMESTARTTIME) - time, timelimit * 60); - timeleft = ceil(timeleft); - - minutesLeft = floor(timeleft / 60); + string timer, subtimer, subtext; + float timelimit, timeleft, minutesLeft, overtimes; + float round_timelimit, round_timeleft; - float warmup_timeleft = 0; + // Calculate timelimit if(warmup_stage) { - float warmup_timelimit = STAT(WARMUP_TIMELIMIT); - if(warmup_timelimit > 0) - warmup_timeleft = max(0, warmup_timelimit - time + STAT(GAMESTARTTIME)); - else if(warmup_timelimit == 0) - warmup_timeleft = timeleft; - warmup_timeleft = ceil(warmup_timeleft); + timelimit = STAT(WARMUP_TIMELIMIT); + if(timelimit == 0) + timelimit = STAT(TIMELIMIT) * 60; + else if(timelimit == -1) + timelimit = 0; } + else + { + timelimit = STAT(TIMELIMIT) * 60; + } + + // Calculate time left + timeleft = bound(0, timelimit + STAT(GAMESTARTTIME) - time, timelimit); + timeleft = ceil(timeleft); + minutesLeft = floor(timeleft / 60); + + // Timer color vector timer_color; if(intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0) timer_color = '1 1 1'; //white @@ -65,23 +68,64 @@ void HUD_Timer() else timer_color = '1 0 0'; //red + // Timer text if (intermission_time) { timer = seconds_tostring(max(0, floor(intermission_time - STAT(GAMESTARTTIME)))); - } else if (warmup_stage && warmup_timeleft >= 60) { - timer = _("WARMUP"); - } else if (autocvar_hud_panel_timer_increment || (!warmup_stage && timelimit == 0) || (warmup_stage && warmup_timeleft <= 0)) { - if (time < STAT(GAMESTARTTIME)) - timer = seconds_tostring(0); //while restart is still active, show 00:00 - else - timer = seconds_tostring(floor(time - STAT(GAMESTARTTIME))); + } else if (autocvar_hud_panel_timer_increment || timelimit == 0) { + float time_elapsed = floor(time - STAT(GAMESTARTTIME)); + timer = seconds_tostring(max(0, time_elapsed)); } else { - if(warmup_stage) - timer = seconds_tostring(warmup_timeleft); - else - timer = seconds_tostring(timeleft); + timer = seconds_tostring(timeleft); } + + // Subtimer text + if(STAT(ROUNDSTARTTIME)) + { + round_timelimit = STAT(ROUND_TIMELIMIT); + + if (autocvar_hud_panel_timer_increment || round_timelimit <= 0) { + float round_time_elapsed = floor(time - STAT(ROUNDSTARTTIME)); + subtimer = seconds_tostring(max(0, round_time_elapsed)); + } else { + round_timeleft = bound(0, round_timelimit + STAT(ROUNDSTARTTIME) - time, round_timelimit); + round_timeleft = ceil(round_timeleft); + + subtimer = seconds_tostring(round_timeleft); + } + } + else + subtimer = string_null; - drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL); + // Subtext + overtimes = STAT(OVERTIMESADDED); + + if(warmup_stage) + subtext = "Warmup"; + else if(overtimes == 1) + subtext = "Overtime"; + else if (overtimes > 1) + subtext = sprintf("Overtime #%d", overtimes); + else + subtext = string_null; + + vector timer_size, subtext_size, subtimer_size; + + subtext_size = vec2(mySize.x, mySize.y / 3); + timer_size = vec2(mySize.x, mySize.y - subtext_size.y); + subtimer_size = vec2(mySize.x / 3, mySize.y - subtext_size.y); + + panel_size.y -= subtext_size.y; + HUD_Panel_DrawBg(); + + if(subtimer) { + timer_size.x -= subtimer_size.x; + drawstring_aspect(pos + eX * timer_size.x, subtimer, subtimer_size, '1 1 0', panel_fg_alpha, DRAWFLAG_NORMAL); + } + + drawstring_aspect(pos, timer, timer_size, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL); + + if(subtext) + drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '1 0 0', panel_fg_alpha, DRAWFLAG_NORMAL); draw_endBoldFont(); } diff --git a/qcsrc/common/stats.qh b/qcsrc/common/stats.qh index 091f7e689..b5f684db0 100644 --- a/qcsrc/common/stats.qh +++ b/qcsrc/common/stats.qh @@ -79,6 +79,8 @@ float game_stopped; float game_starttime; //point in time when the countdown to game start is over float round_starttime; //point in time when the countdown to round start is over int autocvar_leadlimit; +float checkrules_overtimesadded; + // TODO: world.qh can't be included here due to circular includes! #define autocvar_fraglimit cvar("fraglimit") #define autocvar_fraglimit_override cvar("fraglimit_override") @@ -115,6 +117,7 @@ REGISTER_STAT(SECRETS_TOTAL, int, secrets_total) REGISTER_STAT(SECRETS_FOUND, int, secrets_found) REGISTER_STAT(RESPAWN_TIME, float) REGISTER_STAT(ROUNDSTARTTIME, float, round_starttime) +REGISTER_STAT(OVERTIMESADDED, float, checkrules_overtimesadded) REGISTER_STAT(MONSTERS_TOTAL, int) REGISTER_STAT(MONSTERS_KILLED, int) REGISTER_STAT(NADE_BONUS, float) @@ -360,6 +363,7 @@ REGISTER_STAT(Q3COMPAT, int, q3compat) #ifdef SVQC #include "physics/movetypes/movetypes.qh" float warmup_limit; +float round_limit; #endif #ifdef SVQC @@ -399,6 +403,7 @@ REGISTER_STAT(MOVEVARS_AIRCONTROL, float) REGISTER_STAT(FRAGLIMIT, float, autocvar_fraglimit) REGISTER_STAT(TIMELIMIT, float, autocvar_timelimit) REGISTER_STAT(WARMUP_TIMELIMIT, float, warmup_limit) +REGISTER_STAT(ROUND_TIMELIMIT, float, round_limit) #ifdef SVQC float autocvar_sv_wallfriction; #define autocvar_sv_gravity cvar("sv_gravity") diff --git a/qcsrc/server/round_handler.qc b/qcsrc/server/round_handler.qc index 5307eca78..fa68211f9 100644 --- a/qcsrc/server/round_handler.qc +++ b/qcsrc/server/round_handler.qc @@ -75,6 +75,7 @@ void round_handler_Init(float the_delay, float the_count, float the_round_timeli this.count = fabs(floor(the_count)); this.cnt = this.count + 1; this.round_timelimit = (the_round_timelimit > 0) ? the_round_timelimit : 0; + round_limit = the_round_timelimit; } // NOTE: this is only needed because if round_handler spawns at time 1 diff --git a/qcsrc/server/world.qh b/qcsrc/server/world.qh index 299c88535..9cd9799f6 100644 --- a/qcsrc/server/world.qh +++ b/qcsrc/server/world.qh @@ -30,7 +30,7 @@ float autocvar_timelimit_suddendeath; float checkrules_equality; float checkrules_suddendeathwarning; float checkrules_suddendeathend; -float checkrules_overtimesadded; //how many overtimes have been already added +//float checkrules_overtimesadded; //how many overtimes have been already added // flag set on worldspawn so that the code knows if it is dedicated or not bool server_is_dedicated;