]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/timer.qc
Using a separate global to keep track of overtime phase
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / timer.qc
index ff7aab1d60b32c6728717e63eb27426d54b70408..31468b15228da37dbd01c72f6980775d25dbaa76 100644 (file)
@@ -10,6 +10,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 >= 300)
+               return '1 1 1'; //white
+       else if(timeleft >= 60)
+               return '1 1 0'; //yellow
+       else
+               return '1 0 0'; //red
+}
+
+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)
@@ -35,81 +61,84 @@ void HUD_Timer()
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
-       string timer, subtimer, subtext;
-       float timelimit, timeleft, minutesLeft, overtimes;
-       float round_timelimit, round_timeleft;
+       string timer;
+       string subtimer = 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));
 
-       // Calculate timelimit
+       // Use real or frozen time and get the time limit
+       curtime = (intermission_time ? intermission_time : time);
        if(warmup_stage)
        {
                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);
+       // Calculate time left
+       timeleft = HUD_Timer_TimeLeft(curtime, STAT(GAMESTARTTIME), timelimit);
 
        // Timer color
-       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 && !warmup_stage && timelimit > 0)
+               timer_color = HUD_Timer_Color(timeleft);
 
        // Timer text
-       if (intermission_time) {
-               timer = seconds_tostring(max(0, floor(intermission_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 (autocvar_hud_panel_timer_increment || timelimit == 0)
+               timer = seconds_tostring(HUD_Timer_TimeElapsed(curtime, STAT(GAMESTARTTIME)));
+       else
                timer = seconds_tostring(timeleft);
-       }
        
-       // Subtimer text
-       if(STAT(ROUNDSTARTTIME))
+       // Secondary timer for round-based game modes
+       if(STAT(ROUNDSTARTTIME) && autocvar_hud_panel_timer_secondary)
        {
-               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));
+               if(STAT(ROUNDSTARTTIME) == -1) {
+                       // Round can't start
+                       subtimer = "--:--";
+                       subtimer_color = '1 0 0';
                } else {
-                       round_timeleft = bound(0, round_timelimit + STAT(ROUNDSTARTTIME) - time, round_timelimit);
-                       round_timeleft = ceil(round_timeleft);
-                       
-                       subtimer = seconds_tostring(round_timeleft);
+                       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 = seconds_tostring(HUD_Timer_TimeElapsed(round_curtime, STAT(ROUNDSTARTTIME)));
+                       else
+                               subtimer = seconds_tostring(round_timeleft);
                }
        }
-       else
-               subtimer = string_null;
 
        // Subtext
-       overtimes = STAT(OVERTIMESADDED);
-       
-       if(warmup_stage)
-               subtext = "Warmup";
+       int overtimes = STAT(OVERTIMES);
+
+       if(warmup_stage || autocvar__hud_configure)
+               subtext = _("Warmup");
+       else if(STAT(TIMEOUT_STATUS))
+               subtext = _("Timeout");
+       else if (overtimes == -1)
+               subtext = _("Sudden Death");
        else if(overtimes == 1)
-               subtext = "Overtime";
-       else if (overtimes > 1)
-               subtext = sprintf("Overtime #%d", overtimes);
-       else
-               subtext = string_null;
+               subtext = _("Overtime");
+       else if (overtimes >= 2)
+               subtext = sprintf(_("Overtime #%d"), overtimes);
 
-       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);
@@ -119,13 +148,13 @@ void HUD_Timer()
        
        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 + eX * timer_size.x, (swap ? timer : subtimer), subtimer_size, (swap ? timer_color : subtimer_color), panel_fg_alpha, DRAWFLAG_NORMAL);
        }
        
-       drawstring_aspect(pos, timer, timer_size, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
+       drawstring_aspect(pos, (swap ? subtimer : timer), timer_size, (swap ? subtimer_color : 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);
+               drawstring_aspect(pos + eY * timer_size.y, subtext, subtext_size, '0 1 0', panel_fg_alpha, DRAWFLAG_NORMAL);
 
        draw_endBoldFont();
 }