]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/timer.qc
Item Pickup panel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / timer.qc
index 446c6229bdc8f587da981d45d0f228a2c4b0a129..aa0c73b5bf90c4d08ea4e37d0d49cdb7f1ab460e 100644 (file)
@@ -1,6 +1,6 @@
 #include "timer.qh"
+#include "scoreboard.qh"
 
-#include <client/autocvars.qh>
 #include <client/draw.qh>
 #include <client/view.qh>
 
@@ -11,6 +11,32 @@ void HUD_Timer_Export(int fh)
        // allow saving cvars that aesthetically change the panel into hud skin files
 }
 
+vector HUD_Timer_Color(float timeleft)
+{
+       if(timeleft <= 60)
+               return '1 0 0'; // red
+       else if(timeleft <= 300)
+               return '1 1 0'; // yellow
+       else
+               return '1 1 1'; // white
+}
+
+float HUD_Timer_TimeElapsed(float curtime, float starttime)
+{
+       float time_elapsed = curtime - starttime;
+       if (!autocvar_hud_panel_timer_unbound)
+               time_elapsed = max(0, time_elapsed);
+       return floor(time_elapsed);
+}
+
+float HUD_Timer_TimeLeft(float curtime, float starttime, float timelimit)
+{
+       float timeleft = timelimit + starttime - curtime;
+       if (!autocvar_hud_panel_timer_unbound)
+               timeleft = bound(0, timeleft, timelimit);
+       return ceil(timeleft);
+}
+
 void HUD_Timer()
 {
        if(!autocvar__hud_configure)
@@ -30,59 +56,104 @@ 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);
+       string timer_str = string_null;
+       string subtimer_str = string_null;
+       string subtext = string_null;
+       float curtime, timelimit, timeleft;
+       vector timer_size, subtext_size, subtimer_size;
+       vector timer_color = '1 1 1';
+       vector subtimer_color = '1 1 1';
+       bool swap = (autocvar_hud_panel_timer_secondary == 2 && STAT(ROUNDSTARTTIME));
+
+       // Use real or frozen time and get the time limit
+       curtime = (intermission_time ? intermission_time : time);
+       timelimit = (warmup_stage ? STAT(WARMUP_TIMELIMIT) : STAT(TIMELIMIT) * 60);
+
+       // Calculate time left
+       timeleft = HUD_Timer_TimeLeft(curtime, STAT(GAMESTARTTIME), timelimit);
+
+       // Timer color
+       if(!intermission_time && !warmup_stage && timelimit > 0)
+               timer_color = HUD_Timer_Color(timeleft);
+
+       // Timer text
+       if (autocvar_hud_panel_timer_increment || timelimit <= 0)
+               timer = HUD_Timer_TimeElapsed(curtime, STAT(GAMESTARTTIME));
+       else
+               timer = timeleft;
 
-       timeleft = max(0, timelimit * 60 + STAT(GAMESTARTTIME) - time);
-       timeleft = ceil(timeleft);
+       // Secondary timer for round-based game modes
+       if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
+       {
+               if(STAT(ROUNDSTARTTIME) == -1) {
+                       // Round can't start
+                       subtimer_str = "--:--";
+                       subtimer_color = '1 0 0';
+               } else {
+                       float round_curtime, round_timelimit, round_timeleft;
+
+                       // Use real or frozen time and get the time limit
+                       round_curtime = (game_stopped_time ? game_stopped_time : time);
+                       round_timelimit = STAT(ROUND_TIMELIMIT);
+
+                       // Calculate time left
+                       round_timeleft = HUD_Timer_TimeLeft(round_curtime, STAT(ROUNDSTARTTIME), round_timelimit);
+
+                       // Subtimer color
+                       if(!intermission_time && round_timelimit > 0)
+                               subtimer_color = HUD_Timer_Color(round_timeleft);
+
+                       // Subtimer text
+                       if (autocvar_hud_panel_timer_increment || round_timelimit <= 0)
+                               subtimer_str = seconds_tostring(HUD_Timer_TimeElapsed(round_curtime, STAT(ROUNDSTARTTIME)));
+                       else
+                               subtimer_str = seconds_tostring(round_timeleft);
+               }
+       }
 
-       minutesLeft = floor(timeleft / 60);
+       // Subtext
+       int overtimes = STAT(OVERTIMES);
 
-       float warmup_timeleft = 0;
-       if(warmup_stage)
+       if(warmup_stage || autocvar__hud_configure)
        {
-               float warmup_timelimit = STAT(WARMUP_TIMELIMIT);
-               if(warmup_timelimit > 0)
-                       warmup_timeleft = max(0, warmup_timelimit - time);
-               else if(warmup_timelimit == 0)
-                       warmup_timeleft = timeleft;
-               warmup_timeleft = ceil(warmup_timeleft);
+               if (STAT(WARMUP_TIMELIMIT) > 0)
+                       subtext = _("Warmup");
+               else
+                       subtext = srv_minplayers ? _("Warmup: too few players") : _("Warmup: no time limit");
        }
+       else if(STAT(TIMEOUT_STATUS) == 2)
+               subtext = _("Timeout");
+       else if (overtimes == -1)
+               subtext = _("Sudden Death");
+       else if(overtimes == 1)
+               subtext = _("Overtime");
+       else if (overtimes >= 2)
+               subtext = sprintf(_("Overtime #%d"), overtimes);
+
+       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);
+       timer_str     = seconds_tostring(timer);
+
+       panel_size.y -= subtext_size.y;
+       HUD_Panel_DrawBg();
 
-       vector timer_color;
-       if(intermission_time || minutesLeft >= 5 || warmup_stage || timelimit == 0)
-               timer_color = '1 1 1'; //white
-       else if(minutesLeft >= 1)
-               timer_color = '1 1 0'; //yellow
-       else
-               timer_color = '1 0 0'; //red
-
-       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(warmup_stage)
-                       timer = seconds_tostring(warmup_timeleft);
-               else
-                       timer = seconds_tostring(timeleft);
+       if(subtimer_str) {
+               float subtimer_padding = subtimer_size.y / 5;
+               timer_size.x -= subtimer_size.x;
+               drawstring_aspect(pos + eX * timer_size.x + eY * subtimer_padding, (swap ? timer_str : subtimer_str), subtimer_size - eY * subtimer_padding * 2, (swap ? timer_color : subtimer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
        }
 
-       drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
+       drawstring_aspect(pos, (swap ? subtimer_str : timer_str), timer_size, (swap ? subtimer_color : timer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
+
+       if(subtext)
+               drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
 
        draw_endBoldFont();
 }