]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
center align possibility for physics panel
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index c796f4cc751734404b05c01c40846a94dead334e..1d91217da7b3f7bbbdf8ada0437100338ce9d0b2 100644 (file)
@@ -575,12 +575,12 @@ if(highlightedPanel_prev == hud_configure_active_panel && autocvar__hud_configur
 } ENDS_WITH_CURLY_BRACE
 
 //basically the same code of draw_ButtonPicture and draw_VertButtonPicture for the menu
-void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float lenght_ratio, float vertical, float right_align, vector theColor, float theAlpha, float drawflag)
+void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, float length_ratio, float vertical, float baralign, vector theColor, float theAlpha, float drawflag)
 {
-       if(lenght_ratio <= 0 || !theAlpha)
+       if(length_ratio <= 0 || !theAlpha)
                return;
-       if(lenght_ratio > 1)
-               lenght_ratio = 1;
+       if(length_ratio > 1)
+               length_ratio = 1;
 
        vector square;
        vector width, height;
@@ -590,9 +590,11 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo
                        pic = "gfx/hud/default/statusbar_vertical";
                }
 
-               if (right_align)
-                       theOrigin_y += (1 - lenght_ratio) * theSize_y;
-               theSize_y *= lenght_ratio;
+        if (baralign == 1) // bottom align
+                       theOrigin_y += (1 - length_ratio) * theSize_y;
+        else if (baralign == 2) // center align
+            theOrigin_y += 0.5 * (1 - length_ratio) * theSize_y;
+               theSize_y *= length_ratio;
 
                vector bH;
                width = eX * theSize_x;
@@ -619,9 +621,11 @@ void HUD_Panel_DrawProgressBar(vector theOrigin, vector theSize, string pic, flo
                        pic = "gfx/hud/default/statusbar";
                }
 
-               if (right_align)
-                       theOrigin_x += (1 - lenght_ratio) * theSize_x;
-               theSize_x *= lenght_ratio;
+               if (baralign == 1) // right align
+                       theOrigin_x += (1 - length_ratio) * theSize_x;
+        else if (baralign == 2) // center align
+            theOrigin_x += 0.5 * (1 - length_ratio) * theSize_x;
+               theSize_x *= length_ratio;
 
                vector bW;
                width = eX * theSize_x;
@@ -1688,8 +1692,8 @@ void HUD_Weapons(void)
                if(!autocvar_hud_panel_weapons) return;
                if(spectatee_status == -1) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_WEAPONS;
+
+    hud_configure_active_panel = HUD_PANEL_WEAPONS;
 
        float timeout = autocvar_hud_panel_weapons_timeout;
        float timeout_effect_length, timein_effect_length;
@@ -2098,8 +2102,8 @@ void HUD_Ammo(void)
                if(!autocvar_hud_panel_ammo) return;
                if(spectatee_status == -1) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_AMMO;
+
+    hud_configure_active_panel = HUD_PANEL_AMMO;
 
        HUD_Panel_UpdateCvars(ammo);
        vector pos, mySize;
@@ -2282,12 +2286,12 @@ void HUD_Powerups(void)
        }
        else
        {
-               hud_configure_active_panel = HUD_PANEL_POWERUPS;
-
                strength_time = 15;
                shield_time = 27;
        }
 
+    hud_configure_active_panel = HUD_PANEL_POWERUPS;
+
        HUD_Panel_UpdateCvars(powerups);
        vector pos, mySize;
        pos = panel_pos;
@@ -2429,13 +2433,13 @@ void HUD_HealthArmor(void)
        }
        else
        {
-               hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
-
                health = 150;
                armor = 75;
                fuel = 20;
        }
 
+    hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
+
        HUD_Panel_UpdateCvars(healtharmor);
        vector pos, mySize;
        pos = panel_pos;
@@ -3118,8 +3122,8 @@ void HUD_Notify (void)
        {
                if(!autocvar_hud_panel_notify) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_NOTIFY;
+
+    hud_configure_active_panel = HUD_PANEL_NOTIFY;
 
        HUD_Panel_UpdateCvars(notify);
        vector pos, mySize;
@@ -3434,8 +3438,8 @@ void HUD_Timer(void)
        {
                if(!autocvar_hud_panel_timer) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_TIMER;
+
+    hud_configure_active_panel = HUD_PANEL_TIMER;
 
        HUD_Panel_UpdateCvars(timer);
        vector pos, mySize;
@@ -3493,8 +3497,8 @@ void HUD_Radar(void)
                if (autocvar_hud_panel_radar == 0) return;
                if (autocvar_hud_panel_radar != 2 && !teamplay) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_RADAR;
+
+    hud_configure_active_panel = HUD_PANEL_RADAR;
 
        HUD_Panel_UpdateCvars(radar);
        vector pos, mySize;
@@ -3621,8 +3625,8 @@ void HUD_Score(void)
        {
                if(!autocvar_hud_panel_score) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_SCORE;
+
+    hud_configure_active_panel = HUD_PANEL_SCORE;
 
        HUD_Panel_UpdateCvars(score);
        vector pos, mySize;
@@ -3888,8 +3892,8 @@ void HUD_RaceTimer (void)
                if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
                if(spectatee_status == -1) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_RACETIMER;
+
+    hud_configure_active_panel = HUD_PANEL_RACETIMER;
 
        HUD_Panel_UpdateCvars(racetimer);
        vector pos, mySize;
@@ -4067,13 +4071,13 @@ void HUD_VoteWindow(void)
        }
        else
        {
-               hud_configure_active_panel = HUD_PANEL_VOTE;
-
                vote_yescount = 3;
                vote_nocount = 2;
                vote_needed = 4;
        }
 
+    hud_configure_active_panel = HUD_PANEL_VOTE;
+
        string s;
        float a;
        if(vote_active != vote_prev) {
@@ -4732,32 +4736,32 @@ void HUD_Mod_Race(vector pos, vector mySize)
 
 void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
 {
-       float dom_pps, dom_pps_ratio;
+       float stat, pps_ratio;
        string pic;
        vector color;
        switch(i)
        {
                case 0:
-                       dom_pps = dom_pps_red;
+                       stat = getstatf(STAT_DOM_PPS_RED);
                        pic = "dom_icon_red";
                        color = '1 0 0';
                        break;
                case 1:
-                       dom_pps = dom_pps_blue;
+                       stat = getstatf(STAT_DOM_PPS_BLUE);
                        pic = "dom_icon_blue";
                        color = '0 0 1';
                        break;
                case 2:
-                       dom_pps = dom_pps_yellow;
+                       stat = getstatf(STAT_DOM_PPS_YELLOW);
                        pic = "dom_icon_yellow";
                        color = '1 1 0';
                        break;
                case 3:
-                       dom_pps = dom_pps_pink;
+                       stat = getstatf(STAT_DOM_PPS_PINK);
                        pic = "dom_icon_pink";
                        color = '1 0 1';
        }
-       dom_pps_ratio = dom_pps / dom_total_pps;
+       pps_ratio = stat / getstatf(STAT_DOM_TOTAL_PPS);
 
        if(mySize_x/mySize_y > aspect_ratio)
        {
@@ -4775,18 +4779,18 @@ void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout,
        if (layout) // show text too
        {
                //draw the text
-               color *= 0.5 + dom_pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
+               color *= 0.5 + pps_ratio * (1 - 0.5); // half saturated color at min, full saturated at max
                if (layout == 2) // average pps
-                       drawstring_aspect(myPos + eX * mySize_y, ftos_decimals(dom_pps, 2), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawstring_aspect(myPos + eX * mySize_y, ftos_decimals(stat, 2), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
                else // percentage of average pps
-                       drawstring_aspect(myPos + eX * mySize_y, strcat( ftos(floor(dom_pps_ratio*100 + 0.5)), "%" ), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       drawstring_aspect(myPos + eX * mySize_y, strcat( ftos(floor(pps_ratio*100 + 0.5)), "%" ), eX * (2/3) * mySize_x + eY * mySize_y, color, panel_fg_alpha, DRAWFLAG_NORMAL);
        }
 
        //draw the icon
        drawpic_aspect_skin(myPos, pic, '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-       if (dom_pps > 0)
+       if (stat > 0)
        {
-               drawsetcliparea(myPos_x, myPos_y + mySize_y * (1 - dom_pps_ratio), mySize_y, mySize_y * dom_pps_ratio);
+               drawsetcliparea(myPos_x, myPos_y + mySize_y * (1 - pps_ratio), mySize_y, mySize_y * pps_ratio);
                drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
                drawresetcliparea();
        }
@@ -4801,7 +4805,7 @@ void HUD_Mod_Dom(vector myPos, vector mySize)
                if(tm.team != COLOR_SPECTATOR)
                        ++teams_count;
 
-       float layout = cvar("hud_panel_modicons_dom_layout");
+       float layout = autocvar_hud_panel_modicons_dom_layout;
        float rows, columns, aspect_ratio;
        rows = mySize_y/mySize_x;
        aspect_ratio = (layout) ? 3 : 1;
@@ -4840,8 +4844,8 @@ void HUD_ModIcons(void)
                if(!autocvar_hud_panel_modicons) return;
                if (gametype != GAME_CTF && gametype != GAME_KEYHUNT && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && gametype != GAME_CA && gametype != GAME_FREEZETAG && gametype != GAME_KEEPAWAY && gametype != GAME_DOMINATION) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_MODICONS;
+
+    hud_configure_active_panel = HUD_PANEL_MODICONS;
 
        HUD_Panel_UpdateCvars(modicons);
        vector pos, mySize;
@@ -4893,9 +4897,8 @@ void HUD_DrawPressedKeys(void)
                if(!autocvar_hud_panel_pressedkeys) return;
                if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
 
+    hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
 
        HUD_Panel_UpdateCvars(pressedkeys);
        vector pos, mySize;
@@ -4958,8 +4961,8 @@ void HUD_Chat(void)
                        return;
                }
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_CHAT;
+
+    hud_configure_active_panel = HUD_PANEL_CHAT;
 
        HUD_Panel_UpdateCvars(chat);
 
@@ -5033,8 +5036,8 @@ void HUD_EngineInfo(void)
        {
                if(!autocvar_hud_panel_engineinfo) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
+
+    hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
 
        HUD_Panel_UpdateCvars(engineinfo);
        vector pos, mySize;
@@ -5097,8 +5100,8 @@ void HUD_InfoMessages(void)
        {
                if(!autocvar_hud_panel_infomessages) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
+
+    hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
 
        HUD_Panel_UpdateCvars(infomessages);
        vector pos, mySize;
@@ -5284,8 +5287,8 @@ void HUD_Physics(void)
        {
                if(!autocvar__hud_configure) return;
        }
-       else
-               hud_configure_active_panel = HUD_PANEL_PHYSICS;
+
+    hud_configure_active_panel = HUD_PANEL_PHYSICS;
 
        HUD_Panel_UpdateCvars(physics);
 
@@ -5375,6 +5378,8 @@ void HUD_Physics(void)
        float speed_baralign, acceleration_baralign;
        if (autocvar_hud_panel_physics_baralign == 1)
                acceleration_baralign = speed_baralign = 1;
+    else if(autocvar_hud_panel_physics_baralign == 4)
+               acceleration_baralign = speed_baralign = 2;
        else if (autocvar_hud_panel_physics_flip)
        {
                acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
@@ -5430,30 +5435,40 @@ void HUD_Physics(void)
                                top_speed = speed;
                                top_speed_time = time;
                        }
-                       if (top_speed == 0) //hide top speed 0, it would be stupid
-                               f = 0;
-                       else
+                       if (top_speed != 0)
                        {
                                f = max(1, autocvar_hud_panel_physics_topspeed_time);
                                // divide by f to make it start from 1
                                f = cos( ((time - top_speed_time) / f) * PI/2 );
                        }
+            else //hide top speed 0, it would be stupid
+                               f = 0;
                }
                if (f > 0)
                {
-                       //top speed progressbar peek
+                       //top speed progressbar peak
                        if(autocvar_hud_panel_physics_progressbar && speed < top_speed)
                        {
-                               float peek_offset_x, peek_size_x;
-                               if (speed_baralign)
-                                       peek_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
-                               else
-                                       peek_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
+                               float peak_offset_x;
+                vector peak_size
+                               if (speed_baralign == 0)
+                                       peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x;
+                else if (speed_baralign == 1)
+                                       peak_offset_x = (1 - min(top_speed, max_speed)/max_speed) * panel_size_x;
+                else if (speed_baralign == 2)
+                    peak_offset_x = min(top_speed, max_speed)/max_speed * panel_size_x * 0.5;
                                //if speed is not 0 the speed progressbar already fetched the color
                                if (speed == 0)
                                        HUD_Panel_GetProgressBarColor(speed);
-                               peek_size_x = panel_size_x * 0.01;
-                               drawfill(panel_pos + speed_offset + eX * (peek_offset_x - peek_size_x), eX * peek_size_x + eY * panel_size_y, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                               peak_size_x = floor(panel_size_x * 0.01 + 1.5);
+                peak_size_y = panel_size_y;
+                if (speed_baralign == 2) // draw two peaks, on both sides
+                {
+                    drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x + peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                    drawfill(panel_pos + speed_offset + eX * (0.5 * panel_size_x - peak_offset_x + peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                }
+                else
+                    drawfill(panel_pos + speed_offset + eX * (peak_offset_x - peak_size_x), peak_size, progressbar_color, f * autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
 
                        //top speed
@@ -5465,6 +5480,7 @@ void HUD_Physics(void)
                else
                        top_speed = 0;
        }
+    print(ftos(f), "\n");
 
        //draw acceleration
        if(acceleration && autocvar_hud_panel_physics_progressbar)