]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Merge remote branch 'origin/terencehill/newpanelhud-dom_points' into terencehill...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 1d6af47934dc24f7637780306bcca8abec8f6d2f..a8d82dd76a9d0e6b23d85a0e171268bd65c298d8 100644 (file)
@@ -492,12 +492,15 @@ void HUD_Panel_ExportCfg(string cfgname)
                                        HUD_Write_PanelCvar_q("_ammo_color");
                                        HUD_Write_PanelCvar_q("_ammo_alpha");
                                        HUD_Write_PanelCvar_q("_aspect");
+                                       HUD_Write_PanelCvar_q("_timeout");
+                                       HUD_Write_PanelCvar_q("_timeout_effect");
                                        break;
                                case HUD_PANEL_AMMO:
                                        HUD_Write_PanelCvar_q("_onlycurrent");
                                        HUD_Write_PanelCvar_q("_iconalign");
                                        HUD_Write_PanelCvar_q("_progressbar");
                                        HUD_Write_PanelCvar_q("_progressbar_name");
+                                       HUD_Write_PanelCvar_q("_progressbar_xoffset");
                                        HUD_Write_PanelCvar_q("_text");
                                        break;
                                case HUD_PANEL_POWERUPS:
@@ -533,6 +536,11 @@ void HUD_Panel_ExportCfg(string cfgname)
                                case HUD_PANEL_INFOMESSAGES:
                                        HUD_Write_PanelCvar_q("_flip");
                                        break;
+                               case HUD_PANEL_PHYSICS:
+                                       HUD_Write_PanelCvar_q("_flip");
+                                       HUD_Write_PanelCvar_q("_baralign");
+                                       HUD_Write_PanelCvar_q("_progressbar");
+                                       break;
                        }
                        HUD_Write("\n");
                }
@@ -561,7 +569,7 @@ void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
 #define HUD_Panel_DrawBg(alpha)\
 if(panel_bg != "0")\
        draw_BorderPicture(panel_pos - '1 1 0' * panel_bg_border, panel_bg, panel_size + '1 1 0' * 2 * panel_bg_border, panel_bg_color, panel_bg_alpha * alpha, '1 1 0' * (panel_bg_border/BORDER_MULTIPLIER));\
-if(highlightedPanel_prev == active_panel && autocvar__hud_configure)\
+if(highlightedPanel_prev == hud_configure_active_panel && autocvar__hud_configure)\
 {\
        HUD_Panel_HlBorder(panel_bg_border + 1.5 * hlBorderSize, '0 0.5 1', 0.25 * (1 - autocvar__menu_alpha) * alpha);\
 } ENDS_WITH_CURLY_BRACE
@@ -658,15 +666,10 @@ void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alph
 vector HUD_Panel_CheckMove(vector myPos, vector mySize)
 {
        float i;
-
+       float myCenter_x, myCenter_y, targCenter_x, targCenter_y;
        vector myTarget;
        myTarget = myPos;
 
-       vector myCenter;
-       vector targCenter;
-       myCenter = '0 0 0'; // shut up fteqcc, there IS a reference
-       targCenter = '0 0 0'; // shut up fteqcc, there IS a reference
-
        for (i = 0; i < HUD_PANEL_NUM; ++i) {
                if(i == highlightedPanel || !panel_enabled)
                        continue;
@@ -738,7 +741,7 @@ void HUD_Panel_SetPos(vector pos)
        //if(cvar("hud_configure_checkcollisions_debug"))
                //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
 
-       if(cvar("hud_configure_grid"))
+       if(autocvar_hud_configure_grid)
        {
                pos_x = floor((pos_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
                pos_y = floor((pos_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
@@ -799,7 +802,7 @@ vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
                        // (which side the resize direction finds for first) and reduce the size up to there
                        //
                        // dist is the distance between resizeorigin and the "analogous" point of the panel
-                       // in this case resizeorigin (bottom-right point) and the bottom-right point of the panel
+                       // in this case between resizeorigin (bottom-right point) and the bottom-right point of the panel
                        dist_x = resizeorigin_x - targEndPos_x;
                        dist_y = resizeorigin_y - targEndPos_y;
                        if (dist_y <= 0 || dist_x / dist_y > ratio)
@@ -919,7 +922,7 @@ void HUD_Panel_SetPosSize(vector mySize)
                //drawfill(myPos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
 
        // before checkresize, otherwise panel can be snapped partially inside another panel or panel aspect ratio can be broken
-       if(cvar("hud_configure_grid"))
+       if(autocvar_hud_configure_grid)
        {
                mySize_x = floor((mySize_x/vid_conwidth)/hud_configure_gridSize_x + 0.5) * hud_configure_realGridSize_x;
                mySize_y = floor((mySize_y/vid_conheight)/hud_configure_gridSize_y + 0.5) * hud_configure_realGridSize_y;
@@ -973,7 +976,7 @@ void HUD_Panel_Arrow_Action(float nPrimary)
        hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
 
        float step;
-       if(cvar("hud_configure_grid"))
+       if(autocvar_hud_configure_grid)
        {
                if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
                {
@@ -1685,6 +1688,8 @@ void HUD_Weapons(void)
                if(!autocvar_hud_panel_weapons) return;
                if(spectatee_status == -1) return;
        }
+       else
+               hud_configure_active_panel = HUD_PANEL_WEAPONS;
 
        float timeout = autocvar_hud_panel_weapons_timeout;
        float timeout_effect_length, timein_effect_length;
@@ -1705,7 +1710,6 @@ void HUD_Weapons(void)
                return;
        }
 
-       active_panel = HUD_PANEL_WEAPONS;
        HUD_Panel_UpdateCvars(weapons);
 
        if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
@@ -2094,8 +2098,9 @@ void HUD_Ammo(void)
                if(!autocvar_hud_panel_ammo) return;
                if(spectatee_status == -1) return;
        }
+       else
+               hud_configure_active_panel = HUD_PANEL_AMMO;
 
-       active_panel = HUD_PANEL_AMMO;
        HUD_Panel_UpdateCvars(ammo);
        vector pos, mySize;
        pos = panel_pos;
@@ -2262,33 +2267,32 @@ void DrawNumIcon_expanding(vector myPos, vector mySize, float x, string icon, fl
 
 // Powerups (#2)
 //
-void HUD_Powerups(void) {
+void HUD_Powerups(void)
+{
+       float strength_time, shield_time;
        if(!autocvar__hud_configure)
        {
                if(!autocvar_hud_panel_powerups) return;
                if(spectatee_status == -1) return;
                if not(getstati(STAT_ITEMS) & (IT_STRENGTH | IT_INVINCIBLE)) return;
                if (getstati(STAT_HEALTH) <= 0) return;
+
+               strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
+               shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
+       }
+       else
+       {
+               hud_configure_active_panel = HUD_PANEL_POWERUPS;
+
+               strength_time = 15;
+               shield_time = 27;
        }
 
-       active_panel = HUD_PANEL_POWERUPS;
        HUD_Panel_UpdateCvars(powerups);
        vector pos, mySize;
        pos = panel_pos;
        mySize = panel_size;
 
-       float strength_time, shield_time;
-       if(autocvar__hud_configure)
-       {
-               strength_time = 15;
-               shield_time = 27;
-       }
-       else
-       {
-               strength_time = bound(0, getstatf(STAT_STRENGTH_FINISHED) - time, 99);
-               shield_time = bound(0, getstatf(STAT_INVINCIBLE_FINISHED) - time, 99);
-       }
-
        HUD_Panel_DrawBg(bound(0, max(strength_time, shield_time), 1));
        if(panel_bg_padding)
        {
@@ -2411,13 +2415,27 @@ void HUD_Powerups(void) {
 //
 void HUD_HealthArmor(void)
 {
+       float armor, health, fuel;
        if(!autocvar__hud_configure)
        {
                if(!autocvar_hud_panel_healtharmor) return;
                if(spectatee_status == -1) return;
+
+               health = getstati(STAT_HEALTH);
+               if(health <= 0)
+                       return;
+               armor = getstati(STAT_ARMOR);
+               fuel = getstati(STAT_FUEL);
+       }
+       else
+       {
+               hud_configure_active_panel = HUD_PANEL_HEALTHARMOR;
+
+               health = 150;
+               armor = 75;
+               fuel = 20;
        }
 
-       active_panel = HUD_PANEL_HEALTHARMOR;
        HUD_Panel_UpdateCvars(healtharmor);
        vector pos, mySize;
        pos = panel_pos;
@@ -2430,21 +2448,6 @@ void HUD_HealthArmor(void)
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
-       float armor, health, fuel;
-       armor = getstati(STAT_ARMOR);
-       health = getstati(STAT_HEALTH);
-       fuel = getstati(STAT_FUEL);
-
-       if(autocvar__hud_configure)
-       {
-               armor = 75;
-               health = 150;
-               fuel = 20;
-       }
-
-       if(health <= 0)
-               return;
-
        vector barsize;
        vector picpos, numpos;
 
@@ -3111,10 +3114,13 @@ void HUD_Centerprint(string s1, string s2, float type, float msg)
 
 void HUD_Notify (void)
 {
-       if(!autocvar_hud_panel_notify && !autocvar__hud_configure)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_notify) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_NOTIFY;
 
-       active_panel = HUD_PANEL_NOTIFY;
        HUD_Panel_UpdateCvars(notify);
        vector pos, mySize;
        pos = panel_pos;
@@ -3424,10 +3430,13 @@ string seconds_tostring(float sec)
 
 void HUD_Timer(void)
 {
-       if(!autocvar_hud_panel_timer && !autocvar__hud_configure)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_timer) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_TIMER;
 
-       active_panel = HUD_PANEL_TIMER;
        HUD_Panel_UpdateCvars(timer);
        vector pos, mySize;
        pos = panel_pos;
@@ -3479,10 +3488,14 @@ void HUD_Timer(void)
 //
 void HUD_Radar(void)
 {
-       if ((autocvar_hud_panel_radar == 0 || (autocvar_hud_panel_radar != 2 && !teamplay)) && !autocvar__hud_configure)
-               return;
+       if (!autocvar__hud_configure)
+       {
+               if (autocvar_hud_panel_radar == 0) return;
+               if (autocvar_hud_panel_radar != 2 && !teamplay) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_RADAR;
 
-       active_panel = HUD_PANEL_RADAR;
        HUD_Panel_UpdateCvars(radar);
        vector pos, mySize;
        pos = panel_pos;
@@ -3544,7 +3557,7 @@ void HUD_Radar(void)
        if(hud_panel_radar_rotation == 0)
        {
                // max-min distance must fit the radar in any rotation
-               bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_max - mi_min));
+               bigsize = vlen_minnorm2d(teamradar_size2d) * scale2d / (1.05 * vlen2d(mi_scale));
        }
        else
        {
@@ -3572,7 +3585,7 @@ void HUD_Radar(void)
                  f * bigsize
                + (1 - f) * normalsize;
        teamradar_origin3d_in_texcoord = teamradar_3dcoord_to_texcoord(
-                 f * (mi_min + mi_max) * 0.5
+                 f * mi_center
                + (1 - f) * view_origin);
 
        drawsetcliparea(
@@ -3604,10 +3617,13 @@ void HUD_Radar(void)
 void HUD_UpdatePlayerTeams();
 void HUD_Score(void)
 {
-       if(!autocvar__hud_configure && !autocvar_hud_panel_score)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_score) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_SCORE;
 
-       active_panel = HUD_PANEL_SCORE;
        HUD_Panel_UpdateCvars(score);
        vector pos, mySize;
        pos = panel_pos;
@@ -3864,15 +3880,17 @@ void HUD_Score(void)
 
 // Race timer (#8)
 //
-void HUD_RaceTimer (void) {
+void HUD_RaceTimer (void)
+{
        if(!autocvar__hud_configure)
        {
                if(!autocvar_hud_panel_racetimer) return;
                if(!(gametype == GAME_RACE || gametype == GAME_CTS)) return;
                if(spectatee_status == -1) return;
        }
+       else
+               hud_configure_active_panel = HUD_PANEL_RACETIMER;
 
-       active_panel = HUD_PANEL_RACETIMER;
        HUD_Panel_UpdateCvars(racetimer);
        vector pos, mySize;
        pos = panel_pos;
@@ -4035,11 +4053,10 @@ void HUD_VoteWindow(void)
                uid2name_dialog = 1;
        }
 
-       if(!autocvar_hud_panel_vote && !autocvar__hud_configure)
-               return;
-
        if(!autocvar__hud_configure)
        {
+               if(!autocvar_hud_panel_vote) return;
+
                panel_fg_alpha = autocvar_hud_panel_fg_alpha;
                panel_bg_alpha_str = autocvar_hud_panel_vote_bg_alpha;
 
@@ -4048,6 +4065,14 @@ void HUD_VoteWindow(void)
                }
                panel_bg_alpha = stof(panel_bg_alpha_str);
        }
+       else
+       {
+               hud_configure_active_panel = HUD_PANEL_VOTE;
+
+               vote_yescount = 3;
+               vote_nocount = 2;
+               vote_needed = 4;
+       }
 
        string s;
        float a;
@@ -4061,17 +4086,9 @@ void HUD_VoteWindow(void)
        else
                vote_alpha = bound(0, 1 - (time - vote_change) * 2, 1);
 
-       if(autocvar__hud_configure)
-       {
-               vote_yescount = 3;
-               vote_nocount = 2;
-               vote_needed = 4;
-       }
-
        if(!vote_alpha)
                return;
 
-       active_panel = HUD_PANEL_VOTE;
        HUD_Panel_UpdateCvars(vote);
 
        if(uid2name_dialog)
@@ -4713,19 +4730,119 @@ void HUD_Mod_Race(vector pos, vector mySize)
        drawfont = hud_font;
 }
 
+void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
+{
+       float dom_pps, dom_pps_ratio;
+       string pic;
+       vector color;
+       switch(i)
+       {
+               case 0:
+                       dom_pps = dom_pps_red;
+                       pic = "dom_icon_red";
+                       color = '1 0 0';
+                       break;
+               case 1:
+                       dom_pps = dom_pps_blue;
+                       pic = "dom_icon_blue";
+                       color = '0 0 1';
+                       break;
+               case 2:
+                       dom_pps = dom_pps_yellow;
+                       pic = "dom_icon_yellow";
+                       color = '1 1 0';
+                       break;
+               case 3:
+                       dom_pps = dom_pps_pink;
+                       pic = "dom_icon_pink";
+                       color = '1 0 1';
+       }
+       dom_pps_ratio = dom_pps / dom_total_pps;
+
+       if(mySize_x/mySize_y > aspect_ratio)
+       {
+               i = aspect_ratio * mySize_y;
+               myPos_x = myPos_x + (mySize_x - i) / 2;
+               mySize_x = i;
+       }
+       else
+       {
+               i = 1/aspect_ratio * mySize_x;
+               myPos_y = myPos_y + (mySize_y - i) / 2;
+               mySize_y = i;
+       }
+
+       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
+               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);
+               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);
+       }
+
+       //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)
+       {
+               drawsetcliparea(myPos_x, myPos_y + mySize_y * (1 - dom_pps_ratio), mySize_y, mySize_y * dom_pps_ratio);
+               drawpic_aspect_skin(myPos, strcat(pic, "-highlighted"), '1 1 0' * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawresetcliparea();
+       }
+}
+
+void HUD_Mod_Dom(vector myPos, vector mySize)
+{
+       mod_active = 1; // required in each mod function that always shows something
+       entity tm;
+       float teams_count;
+       for(tm = teams.sort_next; tm; tm = tm.sort_next)
+               if(tm.team != COLOR_SPECTATOR)
+                       ++teams_count;
+
+       float layout = cvar("hud_panel_modicons_dom_layout");
+       float rows, columns, aspect_ratio;
+       rows = mySize_y/mySize_x;
+       aspect_ratio = (layout) ? 3 : 1;
+       rows = bound(1, floor((sqrt((4 * aspect_ratio * teams_count + rows) * rows) + rows + 0.5) / 2), teams_count);
+       columns = ceil(teams_count/rows);
+
+       drawfont = hud_bigfont;
+       int i;
+       float row, column;
+       for(i=0; i<teams_count; ++i)
+       {
+               vector pos, size;
+               pos = myPos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
+               size = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
+
+               DrawDomItem(pos, size, aspect_ratio, layout, i);
+
+               ++row;
+               if(row >= rows)
+               {
+                       row = 0;
+                       ++column;
+               }
+       }
+       drawfont = hud_font;
+}
+
 float mod_prev; // previous state of mod_active to check for a change
 float mod_alpha;
 float mod_change; // "time" when mod_active changed
 
 void HUD_ModIcons(void)
 {
-       if(!autocvar_hud_panel_modicons && !autocvar__hud_configure)
-               return;
-
-       if (gametype != GAME_KEYHUNT && gametype != GAME_CTF && gametype != GAME_NEXBALL && gametype != GAME_CTS && gametype != GAME_RACE && gametype != GAME_CA && gametype != GAME_FREEZETAG && gametype != GAME_KEEPAWAY && !autocvar__hud_configure)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               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;
 
-       active_panel = HUD_PANEL_MODICONS;
        HUD_Panel_UpdateCvars(modicons);
        vector pos, mySize;
        pos = panel_pos;
@@ -4761,6 +4878,8 @@ void HUD_ModIcons(void)
                HUD_Mod_Race(pos, mySize);
        else if(gametype == GAME_CA || gametype == GAME_FREEZETAG)
                HUD_Mod_CA(pos, mySize);
+       else if(gametype == GAME_DOMINATION)
+               HUD_Mod_Dom(pos, mySize);
        else if(gametype == GAME_KEEPAWAY)
                HUD_Mod_Keepaway(pos, mySize);
 }
@@ -4769,13 +4888,15 @@ void HUD_ModIcons(void)
 //
 void HUD_DrawPressedKeys(void)
 {
-       if(!autocvar_hud_panel_pressedkeys && !autocvar__hud_configure)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_pressedkeys) return;
+               if(spectatee_status <= 0 && autocvar_hud_panel_pressedkeys < 2) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_PRESSEDKEYS;
 
-       if(!(spectatee_status > 0 || autocvar_hud_panel_pressedkeys >= 2 || autocvar__hud_configure))
-               return;
 
-       active_panel = HUD_PANEL_PRESSEDKEYS;
        HUD_Panel_UpdateCvars(pressedkeys);
        vector pos, mySize;
        pos = panel_pos;
@@ -4828,13 +4949,18 @@ void HUD_DrawPressedKeys(void)
 //
 void HUD_Chat(void)
 {
-       if(!autocvar_hud_panel_chat && !autocvar__hud_configure)
+       if(!autocvar__hud_configure)
        {
-               cvar_set("con_chatrect", "0");
-               return;
+               if (!autocvar_hud_panel_chat)
+               {
+                       if (!autocvar_con_chatrect)
+                               cvar_set("con_chatrect", "0");
+                       return;
+               }
        }
+       else
+               hud_configure_active_panel = HUD_PANEL_CHAT;
 
-       active_panel = HUD_PANEL_CHAT;
        HUD_Panel_UpdateCvars(chat);
 
        if(autocvar__con_chat_maximized && !autocvar__hud_configure) // draw at full screen height if maximized
@@ -4865,7 +4991,8 @@ void HUD_Chat(void)
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
-       cvar_set("con_chatrect", "1");
+       if (!autocvar_con_chatrect)
+               cvar_set("con_chatrect", "1");
 
        cvar_set("con_chatrect_x", ftos(pos_x/vid_conwidth));
        cvar_set("con_chatrect_y", ftos(pos_y/vid_conheight));
@@ -4875,8 +5002,8 @@ void HUD_Chat(void)
 
        if(autocvar__hud_configure)
        {
-               float chatsize;
-               chatsize = autocvar_con_chatsize;
+               vector chatsize;
+               chatsize = '1 1 0' * autocvar_con_chatsize;
                cvar_set("con_chatrect_x", "9001"); // over 9000, we'll fake it instead for more control over alpha and such
                float i, a;
                for(i = 0; i < autocvar_con_chat; ++i)
@@ -4885,7 +5012,8 @@ void HUD_Chat(void)
                                a = panel_fg_alpha;
                        else
                                a = panel_fg_alpha * floor(((i + 1) * 7 + autocvar_con_chattime)/45);
-                       drawcolorcodedstring(pos + eY * i * chatsize, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, '1 1 0' * chatsize, stringwidth_colors), '1 1 0' * chatsize, a, DRAWFLAG_NORMAL);
+                       drawcolorcodedstring(pos, textShortenToWidth("^3Player^7: This is the chat area.", mySize_x, chatsize, stringwidth_colors), chatsize, a, DRAWFLAG_NORMAL);
+                       pos_y += chatsize_y;
                }
        }
 }
@@ -4901,10 +5029,13 @@ float frametimeavg1; // 1 frame ago
 float frametimeavg2; // 2 frames ago
 void HUD_EngineInfo(void)
 {
-       if(!autocvar_hud_panel_engineinfo && !autocvar__hud_configure)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_engineinfo) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_ENGINEINFO;
 
-       active_panel = HUD_PANEL_ENGINEINFO;
        HUD_Panel_UpdateCvars(engineinfo);
        vector pos, mySize;
        pos = panel_pos;
@@ -4962,10 +5093,13 @@ void HUD_EngineInfo(void)
        o_y += fontsize_y;
 void HUD_InfoMessages(void)
 {
-       if(!autocvar_hud_panel_infomessages && !autocvar__hud_configure)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_infomessages) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_INFOMESSAGES;
 
-       active_panel = HUD_PANEL_INFOMESSAGES;
        HUD_Panel_UpdateCvars(infomessages);
        vector pos, mySize;
        pos = panel_pos;
@@ -5139,113 +5273,218 @@ void HUD_InfoMessages(void)
        }
 }
 
-/*
-==================
-Main HUD system
-==================
-*/
+// Physics panel (#15)
+//
+vector acc_prevspeed;
+float acc_prevtime, acc_avg, top_speed, top_speed_time;
 
-void HUD_ShowSpeed(void)
+void HUD_Physics(void)
 {
-       vector numsize;
-       float pos, conversion_factor;
-       string speed, zspeed, unit;
+       if(!autocvar_hud_panel_physics)
+       {
+               if(!autocvar__hud_configure) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_PHYSICS;
+
+       HUD_Panel_UpdateCvars(physics);
+
+       HUD_Panel_DrawBg(1);
+       if(panel_bg_padding)
+       {
+               panel_pos += '1 1 0' * panel_bg_padding;
+               panel_size -= '2 2 0' * panel_bg_padding;
+       }
+
+       //compute speed
+       float speed, conversion_factor;
+       string unit;
 
        switch(autocvar_cl_showspeed_unit)
        {
                default:
-               case 0:
-                       unit = "";
-                       conversion_factor = 1.0;
-                       break;
                case 1:
-                       unit = " qu/s";
+                       unit = "qu/s";
                        conversion_factor = 1.0;
                        break;
                case 2:
-                       unit = " m/s";
+                       unit = "m/s";
                        conversion_factor = 0.0254;
                        break;
                case 3:
-                       unit = " km/h";
+                       unit = "km/h";
                        conversion_factor = 0.0254 * 3.6;
                        break;
                case 4:
-                       unit = " mph";
+                       unit = "mph";
                        conversion_factor = 0.0254 * 3.6 * 0.6213711922;
                        break;
                case 5:
-                       unit = " knots";
+                       unit = "knots";
                        conversion_factor = 0.0254 * 1.943844492; // 1 m/s = 1.943844492 knots, because 1 knot = 1.852 km/h
                        break;
        }
 
-       speed = strcat(ftos(floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 )), unit);
-
-       numsize_x = numsize_y = autocvar_cl_showspeed_size;
-       pos = (vid_conheight - numsize_y) * autocvar_cl_showspeed_position;
+       float max_speed = floor( autocvar_hud_panel_physics_speed_max * conversion_factor + 0.5 );
+       if (autocvar__hud_configure)
+               speed = floor( max_speed * 0.65 + 0.5 );
+       else if(autocvar_hud_panel_physics_speed_z)
+               speed = floor( vlen(pmove_vel) * conversion_factor + 0.5 );
+       else
+               speed = floor( vlen(pmove_vel - pmove_vel_z * '0 0 1') * conversion_factor + 0.5 );
 
-       drawfont = hud_bigfont;
-       drawstringcenter(eX + pos * eY, speed, numsize, '1 1 1', autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
+       //compute acceleration
+       float acceleration, f;
+       if (autocvar__hud_configure)
+               acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
+       else
+       {
+               f = time - acc_prevtime;
+               if(autocvar_hud_panel_physics_acceleration_z)
+                       acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
+               else
+                       acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
+               acc_prevspeed = pmove_vel;
+               acc_prevtime = time;
 
-       if (autocvar_cl_showspeed_z == 1) {
-               zspeed = strcat(ftos(fabs(floor( pmove_vel_z * conversion_factor + 0.5 ))), unit);
-               drawstringcenter(eX + pos * eY + numsize_y * eY, zspeed, numsize * 0.5, '1 1 1', autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
+               f = bound(0, f * 10, 1);
+               acc_avg = acc_avg * (1 - f) + acceleration * f;
+               acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
        }
 
-       drawfont = hud_font;
-}
+       //compute layout
+       drawfont = hud_bigfont;
+       float panel_ar = panel_size_x/panel_size_y;
+       vector speed_offset, acceleration_offset;
+       if (panel_ar >= 5)
+       {
+               panel_size_x *= 0.5;
+               if (autocvar_hud_panel_physics_flip)
+                       speed_offset_x = panel_size_x;
+               else
+                       acceleration_offset_x = panel_size_x;
+       }
+       else
+       {
+               panel_size_y *= 0.5;
+               if (autocvar_hud_panel_physics_flip)
+                       speed_offset_y = panel_size_y;
+               else
+                       acceleration_offset_y = panel_size_y;
+       }
+       float speed_baralign, acceleration_baralign;
+       if (autocvar_hud_panel_physics_baralign == 1)
+               acceleration_baralign = speed_baralign = 1;
+       else if (autocvar_hud_panel_physics_flip)
+       {
+               acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
+               speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
+       }
+       else
+       {
+               speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
+               acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
+       }
 
-vector acc_prevspeed;
-float acc_prevtime;
-float acc_avg;
+       //draw speed
+       if(speed && autocvar_hud_panel_physics_progressbar)
+       {
+               HUD_Panel_GetProgressBarColor(speed);
+               HUD_Panel_DrawProgressBar(panel_pos + speed_offset, panel_size, "progressbar", speed/max_speed, 0, speed_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+       }
 
-void HUD_ShowAcceleration(void)
-{
-       float acceleration, sz, scale, alpha, f;
-       vector pos, mySize, rgb;
+       vector tmp_offset, tmp_size;
+       tmp_size_x = panel_size_x * 0.75;
+       tmp_size_y = panel_size_y;
+       if (speed_baralign)
+               tmp_offset_x = panel_size_x - tmp_size_x;
+       //else
+               //tmp_offset_x = 0;
+       drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(speed), tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 
-       f = time - acc_prevtime;
-       if(autocvar_cl_showacceleration_z)
-               acceleration = (vlen(pmove_vel) - vlen(acc_prevspeed)) * (1 / f);
+       //draw speed unit
+       if (speed_baralign)
+               tmp_offset_x = 0;
        else
-               acceleration = (vlen(pmove_vel - '0 0 1' * pmove_vel_z) - vlen(acc_prevspeed - '0 0 1' * acc_prevspeed_z)) * (1 / f);
-       acc_prevspeed = pmove_vel;
-       acc_prevtime = time;
-
-       f = bound(0, f * 10, 1);
-       acc_avg = acc_avg * (1 - f) + acceleration * f;
-       acceleration = acc_avg / getstatf(STAT_MOVEVARS_MAXSPEED);
-       if (acceleration == 0)
-               return;
-
-       sz = autocvar_cl_showacceleration_size;
-       scale = autocvar_cl_showacceleration_scale;
-       alpha = autocvar_cl_showacceleration_alpha;
-       if (autocvar_cl_showacceleration_color_custom)
-               rgb = stov(autocvar_cl_showacceleration_color);
-       else {
-               if (acceleration < 0)
-                       rgb = '1 .5 .5' - '0 .5 .5' * bound(0, -acceleration * 0.2, 1);
-               else
-                       rgb = '.5 1 .5' - '.5 0 .5' * bound(0, +acceleration * 0.2, 1);
+               tmp_offset_x = tmp_size_x;
+       if (autocvar_hud_panel_physics_speed_unit_show)
+       {
+               //tmp_offset_y = 0;
+               tmp_size_x = panel_size_x * (1 - 0.75);
+               tmp_size_y = panel_size_y * 0.4;
+               drawstring_aspect(panel_pos + speed_offset + tmp_offset, unit, tmp_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
        }
 
-       mySize_x = vid_conwidth/2;
-       mySize_y = sz;
-       pos_y = autocvar_cl_showacceleration_position * vid_conheight - sz/2;
-       if (acceleration > 0)
+       //compute and draw top speed
+       if (autocvar_hud_panel_physics_topspeed)
        {
-               pos_x = mySize_x;
-               HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", acceleration * scale, 0, 0, rgb, alpha * autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
+               if (autocvar__hud_configure)
+               {
+                       top_speed = floor( max_speed * 0.75 + 0.5 );
+                       f = 1;
+               }
+               else
+               {
+                       if (speed >= top_speed)
+                       {
+                               top_speed = speed;
+                               top_speed_time = time;
+                       }
+                       if (top_speed == 0) //hide top speed 0, it would be stupid
+                               f = 0;
+                       else
+                       {
+                               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 );
+                       }
+               }
+               if (f > 0)
+               {
+                       //top speed progressbar peek
+                       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;
+                               //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);
+                       }
+
+                       //top speed
+                       tmp_offset_y = panel_size_y * 0.4;
+                       tmp_size_x = panel_size_x * (1 - 0.75);
+                       tmp_size_y = panel_size_y - tmp_offset_y;
+                       drawstring_aspect(panel_pos + speed_offset + tmp_offset, ftos(top_speed), tmp_size, '1 0 0', f * panel_fg_alpha, DRAWFLAG_NORMAL);
+               }
+               else
+                       top_speed = 0;
        }
-       else
+
+       //draw acceleration
+       if(acceleration && autocvar_hud_panel_physics_progressbar)
        {
-               //pos_x = 0;
-               HUD_Panel_DrawProgressBar(pos, mySize, "statusbar", -acceleration * scale, 0, 1, rgb, alpha * autocvar_hud_panel_fg_alpha * hud_fade_alpha, DRAWFLAG_NORMAL);
+               if (acceleration < 0)
+                       HUD_Panel_GetProgressBarColor(acceleration_neg);
+               else
+                       HUD_Panel_GetProgressBarColor(acceleration);
+               HUD_Panel_DrawProgressBar(panel_pos + acceleration_offset, panel_size, "progressbar", fabs(acceleration)/autocvar_hud_panel_physics_acceleration_max, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
        }
+       drawstring_aspect(panel_pos + acceleration_offset, ftos_decimals(acceleration, 3), panel_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+       drawfont = hud_font;
 }
 
+/*
+==================
+Main HUD system
+==================
+*/
+
 void HUD_Reset (void)
 {
        // reset gametype specific icons
@@ -5287,6 +5526,8 @@ switch (id) {\
                HUD_EngineInfo(); break;\
        case (HUD_PANEL_INFOMESSAGES):\
                 HUD_InfoMessages(); break;\
+       case (HUD_PANEL_PHYSICS):\
+                HUD_Physics(); break;\
 } ENDS_WITH_CURLY_BRACE
 
 void HUD_Main (void)
@@ -5318,8 +5559,7 @@ void HUD_Main (void)
        }
 
        // HUD configure visible grid
-       float hud_configure_grid_alpha;
-       if(autocvar__hud_configure && cvar("hud_configure_grid") && (hud_configure_grid_alpha = cvar("hud_configure_grid_alpha")))
+       if(autocvar__hud_configure && autocvar_hud_configure_grid && autocvar_hud_configure_grid_alpha)
        {
                hud_configure_gridSize_x = bound(0.005, cvar("hud_configure_grid_xsize"), 0.2);
                hud_configure_gridSize_y = bound(0.005, cvar("hud_configure_grid_ysize"), 0.2);
@@ -5327,10 +5567,10 @@ void HUD_Main (void)
                hud_configure_realGridSize_y = hud_configure_gridSize_y * vid_conheight;
                // x-axis
                for(i = 0; i < 1/hud_configure_gridSize_x; ++i)
-                       drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
+                       drawfill(eX * i * hud_configure_realGridSize_x, eX + eY * vid_conheight, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
                // y-axis
                for(i = 0; i < 1/hud_configure_gridSize_y; ++i)
-                       drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', hud_configure_grid_alpha, DRAWFLAG_NORMAL);
+                       drawfill(eY * i * hud_configure_realGridSize_y, eY + eX * vid_conwidth, '0.5 0.5 0.5', autocvar_hud_configure_grid_alpha, DRAWFLAG_NORMAL);
        }
 
        // draw the dock
@@ -5412,6 +5652,7 @@ void HUD_Main (void)
                        panel_order[i] = stof(argv(i));
                }
        }
+
        // draw panels in order specified by panel_order array
        for(i = HUD_PANEL_NUM - 1; i >= 0; --i) {
                if(i != HUD_PANEL_CHAT || !autocvar__con_chat_maximized) // don't draw maximized chat panel twice!
@@ -5422,12 +5663,6 @@ void HUD_Main (void)
        if(autocvar__con_chat_maximized)
                HUD_Chat(); // HUD_DrawPanel(HUD_PANEL_CHAT);
 
-       // TODO hud_'ify these
-       if (autocvar_cl_showspeed)
-               HUD_ShowSpeed();
-       if (autocvar_cl_showacceleration)
-               HUD_ShowAcceleration();
-
        if (autocvar__hud_configure && spectatee_status && hud_configure_prev == -1) // try to join if we are in hud_configure mode, but still spectating, and in the first frame (in order to get rid of motd when launching a server via the menu "HUD Setup" button)
                localcmd("cmd selectteam auto; cmd join\n");