]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Access directly these autocvars
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 0314ab954c2fd77e784118c1497979dca6590dea..8f690bb18adfcd3132832dae5f854393eac4a6ba 100644 (file)
@@ -297,7 +297,6 @@ void HUD_DrawCenterPrint (void)
        {
                ts = centerprint_messages[i];
                drawfontscale = sz * '1 1 0';
-               drawfont = hud_bigfont;
                pos_x = (vid_conwidth - stringwidth(ts, TRUE, centerprint_fontsize)) * 0.5;
                if (ts != "")
                {
@@ -308,7 +307,6 @@ void HUD_DrawCenterPrint (void)
                        // half height for empty lines looks better
                        pos_y = pos_y + sz * centerprint_fontsize_y * 0.5;
                drawfontscale = '1 1 0';
-               drawfont = hud_font;
        }
 }
 
@@ -417,167 +415,22 @@ HUD panels
 ==================
 */
 
-#define HUD_Write(s) fputs(fh, s)
-// q: quoted, n: not quoted
-#define HUD_Write_Cvar_n(cvar) HUD_Write(strcat("seta ", cvar, " ", cvar_string(cvar), "\n"))
-#define HUD_Write_Cvar_q(cvar) HUD_Write(strcat("seta ", cvar, " \"", cvar_string(cvar), "\"\n"))
-#define HUD_Write_PanelCvar_n(cvar_suf) HUD_Write_Cvar_n(strcat("hud_panel_", panel_name, cvar_suf))
-#define HUD_Write_PanelCvar_q(cvar_suf) HUD_Write_Cvar_q(strcat("hud_panel_", panel_name, cvar_suf))
-// Save the config
-void HUD_Panel_ExportCfg(string cfgname)
-{
-       float fh;
-       string filename = strcat("hud_", autocvar_hud_skin, "_", cfgname, ".cfg");
-       fh = fopen(filename, FILE_WRITE);
-       if(fh >= 0)
-       {
-               HUD_Write_Cvar_q("hud_skin");
-               HUD_Write_Cvar_q("hud_panel_bg");
-               HUD_Write_Cvar_q("hud_panel_bg_color");
-               HUD_Write_Cvar_q("hud_panel_bg_color_team");
-               HUD_Write_Cvar_q("hud_panel_bg_alpha");
-               HUD_Write_Cvar_q("hud_panel_bg_border");
-               HUD_Write_Cvar_q("hud_panel_bg_padding");
-               HUD_Write_Cvar_q("hud_panel_fg_alpha");
-               HUD_Write("\n");
-
-               HUD_Write_Cvar_q("hud_dock");
-               HUD_Write_Cvar_q("hud_dock_color");
-               HUD_Write_Cvar_q("hud_dock_color_team");
-               HUD_Write_Cvar_q("hud_dock_alpha");
-               HUD_Write("\n");
-
-               HUD_Write_Cvar_q("hud_progressbar_alpha");
-               HUD_Write_Cvar_q("hud_progressbar_strength_color");
-               HUD_Write_Cvar_q("hud_progressbar_shield_color");
-               HUD_Write_Cvar_q("hud_progressbar_health_color");
-               HUD_Write_Cvar_q("hud_progressbar_armor_color");
-               HUD_Write_Cvar_q("hud_progressbar_fuel_color");
-               HUD_Write_Cvar_q("hud_progressbar_nexball_color");
-               HUD_Write("\n");
-
-               HUD_Write_Cvar_q("_hud_panelorder");
-               HUD_Write("\n");
-
-               HUD_Write_Cvar_q("hud_configure_grid");
-               HUD_Write_Cvar_q("hud_configure_grid_xsize");
-               HUD_Write_Cvar_q("hud_configure_grid_ysize");
-               HUD_Write("\n");
-
-               HUD_Write_Cvar_q("scr_centerpos");
-               HUD_Write("\n");
-
-               // common cvars for all panels
-               float i;
-               for (i = 0; i < HUD_PANEL_NUM; ++i)
-               {
-                       HUD_Panel_GetName(i);
-
-                       HUD_Write_PanelCvar_n("");
-                       HUD_Write_PanelCvar_q("_pos");
-                       HUD_Write_PanelCvar_q("_size");
-                       HUD_Write_PanelCvar_q("_bg");
-                       HUD_Write_PanelCvar_q("_bg_color");
-                       HUD_Write_PanelCvar_q("_bg_color_team");
-                       HUD_Write_PanelCvar_q("_bg_alpha");
-                       HUD_Write_PanelCvar_q("_bg_border");
-                       HUD_Write_PanelCvar_q("_bg_padding");
-                       switch(i) {
-                               case HUD_PANEL_WEAPONS:
-                                       HUD_Write_PanelCvar_q("_complainbubble");
-                                       HUD_Write_PanelCvar_q("_complainbubble_padding");
-                                       HUD_Write_PanelCvar_q("_complainbubble_color_outofammo");
-                                       HUD_Write_PanelCvar_q("_complainbubble_color_donthave");
-                                       HUD_Write_PanelCvar_q("_complainbubble_color_unavailable");
-                                       HUD_Write_PanelCvar_q("_ammo_color");
-                                       HUD_Write_PanelCvar_q("_ammo_alpha");
-                                       HUD_Write_PanelCvar_q("_aspect");
-                                       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("_text");
-                                       break;
-                               case HUD_PANEL_POWERUPS:
-                                       HUD_Write_PanelCvar_q("_flip");
-                                       HUD_Write_PanelCvar_q("_iconalign");
-                                       HUD_Write_PanelCvar_q("_baralign");
-                                       HUD_Write_PanelCvar_q("_progressbar");
-                                       HUD_Write_PanelCvar_q("_progressbar_strength");
-                                       HUD_Write_PanelCvar_q("_progressbar_shield");
-                                       break;
-                               case HUD_PANEL_HEALTHARMOR:
-                                       HUD_Write_PanelCvar_q("_flip");
-                                       HUD_Write_PanelCvar_q("_iconalign");
-                                       HUD_Write_PanelCvar_q("_baralign");
-                                       HUD_Write_PanelCvar_q("_progressbar");
-                                       HUD_Write_PanelCvar_q("_progressbar_health");
-                                       HUD_Write_PanelCvar_q("_progressbar_armor");
-                                       HUD_Write_PanelCvar_q("_text");
-                                       break;
-                               case HUD_PANEL_NOTIFY:
-                                       HUD_Write_PanelCvar_q("_flip");
-                                       HUD_Write_PanelCvar_q("_print");
-                                       break;
-                               case HUD_PANEL_RADAR:
-                                       HUD_Write_PanelCvar_q("_foreground_alpha");
-                                       break;
-                               case HUD_PANEL_VOTE:
-                                       HUD_Write_PanelCvar_q("_alreadyvoted_alpha");
-                                       break;
-                               case HUD_PANEL_PRESSEDKEYS:
-                                       HUD_Write_PanelCvar_q("_aspect");
-                                       break;
-                               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");
-               }
-               HUD_Write("menu_sync\n"); // force the menu to reread the cvars, so that the dialogs are updated
-
-               print("^2Successfully exported to ", filename, "! (Note: It's saved in data/data/)\n");
-               fclose(fh);
-       }
-       else
-               print("^1Couldn't write to ", filename, "\n");
-}
-
-const float hlBorderSize = 4;
-const string hlBorder = "gfx/hud/default/border_highlighted";
-const string hlBorder2 = "gfx/hud/default/border_highlighted2";
-void HUD_Panel_HlBorder(float myBorder, vector color, float alpha)
-{
-       drawfill(panel_pos - '1 1 0' * myBorder, panel_size + '2 2 0' * myBorder, '0 0.5 1', .5 * alpha, DRAWFLAG_NORMAL);
-       drawpic_tiled(panel_pos - '1 1 0' * myBorder, hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
-       drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * (panel_size_y + 2 * myBorder - hlBorderSize), hlBorder, '8 1 0' * hlBorderSize, eX * (panel_size_x + 2 * myBorder) + eY * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
-       drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize, hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
-       drawpic_tiled(panel_pos - '1 1 0' * myBorder + eY * hlBorderSize + eX * (panel_size_x + 2 * myBorder - hlBorderSize), hlBorder2, '1 8 0' * hlBorderSize, eY * (panel_size_y + 2 * myBorder - 2 * hlBorderSize) + eX * hlBorderSize, color, alpha, DRAWFLAG_NORMAL);
-}
-
 // draw the background/borders
 #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 == 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
 
 //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;
@@ -587,9 +440,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;
@@ -616,9 +471,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;
@@ -659,962 +516,8 @@ void HUD_Panel_DrawHighlight(vector pos, vector mySize, vector color, float alph
        drawsubpic(pos + eX * mySize_x - eX * min(mySize_x * 0.5, mySize_y), eX * min(mySize_x * 0.5, mySize_y) + eY * mySize_y, pic, '0.75 0 0', '0.25 1 0', color, alpha, drawflag);
 }
 
-// check if move will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
-vector HUD_Panel_CheckMove(vector myPos, vector mySize)
-{
-       float i;
-
-       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;
-
-               HUD_Panel_UpdatePosSizeForId(i);
-
-               panel_pos -= '1 1 0' * panel_bg_border;
-               panel_size += '2 2 0' * panel_bg_border;
-
-               if(myPos_y + mySize_y < panel_pos_y)
-                       continue;
-               if(myPos_y > panel_pos_y + panel_size_y)
-                       continue;
-
-               if(myPos_x + mySize_x < panel_pos_x)
-                       continue;
-               if(myPos_x > panel_pos_x + panel_size_x)
-                       continue;
-
-               // OK, there IS a collision.
-
-               myCenter_x = myPos_x + 0.5 * mySize_x;
-               myCenter_y = myPos_y + 0.5 * mySize_y;
-
-               targCenter_x = panel_pos_x + 0.5 * panel_size_x;
-               targCenter_y = panel_pos_y + 0.5 * panel_size_y;
-
-               if(myCenter_x < targCenter_x && myCenter_y < targCenter_y) // top left (of the target panel)
-               {
-                       if(myPos_x + mySize_x - panel_pos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
-                               myTarget_x = panel_pos_x - mySize_x;
-                       else // push it upwards
-                               myTarget_y = panel_pos_y - mySize_y;
-               }
-               else if(myCenter_x > targCenter_x && myCenter_y < targCenter_y) // top right
-               {
-                       if(panel_pos_x + panel_size_x - myPos_x < myPos_y + mySize_y - panel_pos_y) // push it to the side
-                               myTarget_x = panel_pos_x + panel_size_x;
-                       else // push it upwards
-                               myTarget_y = panel_pos_y - mySize_y;
-               }
-               else if(myCenter_x < targCenter_x && myCenter_y > targCenter_y) // bottom left
-               {
-                       if(myPos_x + mySize_x - panel_pos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
-                               myTarget_x = panel_pos_x - mySize_x;
-                       else // push it downwards
-                               myTarget_y = panel_pos_y + panel_size_y;
-               }
-               else if(myCenter_x > targCenter_x && myCenter_y > targCenter_y) // bottom right
-               {
-                       if(panel_pos_x + panel_size_x - myPos_x < panel_pos_y + panel_size_y - myPos_y) // push it to the side
-                               myTarget_x = panel_pos_x + panel_size_x;
-                       else // push it downwards
-                               myTarget_y = panel_pos_y + panel_size_y;
-               }
-               //if(cvar("hud_configure_checkcollisions_debug"))
-                       //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
-       }
-
-       return myTarget;
-}
-
-void HUD_Panel_SetPos(vector pos)
-{
-       HUD_Panel_UpdatePosSizeForId(highlightedPanel);
-       vector mySize;
-       mySize = panel_size;
-
-       //if(cvar("hud_configure_checkcollisions_debug"))
-               //drawfill(pos, mySize, '1 1 1', .2, DRAWFLAG_NORMAL);
-
-       if(cvar("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;
-       }
-
-       if(hud_configure_checkcollisions)
-               pos = HUD_Panel_CheckMove(pos, mySize);
-
-       pos_x = bound(0, pos_x, vid_conwidth - mySize_x);
-       pos_y = bound(0, pos_y, vid_conheight - mySize_y);
-
-       string s;
-       s = strcat(ftos(pos_x/vid_conwidth), " ", ftos(pos_y/vid_conheight));
-
-       HUD_Panel_GetName(highlightedPanel);
-       cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
-}
-
-// check if resize will result in panel being moved into another panel. If so, return snapped vector, otherwise return the given vector
-vector HUD_Panel_CheckResize(vector mySize, vector resizeorigin) {
-       float i;
-
-       vector targEndPos;
-
-       float dist_x, dist_y;
-       float ratio;
-       ratio = mySize_x/mySize_y;
-
-       for (i = 0; i < HUD_PANEL_NUM; ++i) {
-               if(i == highlightedPanel || !panel_enabled)
-                       continue;
-
-               HUD_Panel_UpdatePosSizeForId(i);
-
-               panel_pos -= '1 1 0' * panel_bg_border;
-               panel_size += '2 2 0' * panel_bg_border;
-
-               targEndPos = panel_pos + panel_size;
-
-               // resizeorigin is WITHIN target panel, just abort any collision testing against that particular panel to produce expected behaviour!
-               if(resizeorigin_x > panel_pos_x && resizeorigin_x < targEndPos_x && resizeorigin_y > panel_pos_y && resizeorigin_y < targEndPos_y)
-                       continue;
-
-               if (resizeCorner == 1)
-               {
-                       // check if this panel is on our way
-                       if (resizeorigin_x <= panel_pos_x)
-                               continue;
-                       if (resizeorigin_y <= panel_pos_y)
-                               continue;
-                       if (targEndPos_x <= resizeorigin_x - mySize_x)
-                               continue;
-                       if (targEndPos_y <= resizeorigin_y - mySize_y)
-                               continue;
-
-                       // there is a collision:
-                       // detect which side of the panel we are facing is actually limiting the resizing
-                       // (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
-                       dist_x = resizeorigin_x - targEndPos_x;
-                       dist_y = resizeorigin_y - targEndPos_y;
-                       if (dist_y <= 0 || dist_x / dist_y > ratio)
-                               mySize_x = min(mySize_x, dist_x);
-                       else
-                               mySize_y = min(mySize_y, dist_y);
-               }
-               else if (resizeCorner == 2)
-               {
-                       if (resizeorigin_x >= targEndPos_x)
-                               continue;
-                       if (resizeorigin_y <= panel_pos_y)
-                               continue;
-                       if (panel_pos_x >= resizeorigin_x + mySize_x)
-                               continue;
-                       if (targEndPos_y <= resizeorigin_y - mySize_y)
-                               continue;
-
-                       dist_x = panel_pos_x - resizeorigin_x;
-                       dist_y = resizeorigin_y - targEndPos_y;
-                       if (dist_y <= 0 || dist_x / dist_y > ratio)
-                               mySize_x = min(mySize_x, dist_x);
-                       else
-                               mySize_y = min(mySize_y, dist_y);
-               }
-               else if (resizeCorner == 3)
-               {
-                       if (resizeorigin_x <= panel_pos_x)
-                               continue;
-                       if (resizeorigin_y >= targEndPos_y)
-                               continue;
-                       if (targEndPos_x <= resizeorigin_x - mySize_x)
-                               continue;
-                       if (panel_pos_y >= resizeorigin_y + mySize_y)
-                               continue;
-
-                       dist_x = resizeorigin_x - targEndPos_x;
-                       dist_y = panel_pos_y - resizeorigin_y;
-                       if (dist_y <= 0 || dist_x / dist_y > ratio)
-                               mySize_x = min(mySize_x, dist_x);
-                       else
-                               mySize_y = min(mySize_y, dist_y);
-               }
-               else if (resizeCorner == 4)
-               {
-                       if (resizeorigin_x >= targEndPos_x)
-                               continue;
-                       if (resizeorigin_y >= targEndPos_y)
-                               continue;
-                       if (panel_pos_x >= resizeorigin_x + mySize_x)
-                               continue;
-                       if (panel_pos_y >= resizeorigin_y + mySize_y)
-                               continue;
-
-                       dist_x = panel_pos_x - resizeorigin_x;
-                       dist_y = panel_pos_y - resizeorigin_y;
-                       if (dist_y <= 0 || dist_x / dist_y > ratio)
-                               mySize_x = min(mySize_x, dist_x);
-                       else
-                               mySize_y = min(mySize_y, dist_y);
-               }
-               //if(cvar("hud_configure_checkcollisions_debug"))
-                       //drawfill(panel_pos, panel_size, '1 1 0', .3, DRAWFLAG_NORMAL);
-       }
-
-       return mySize;
-}
-
-void HUD_Panel_SetPosSize(vector mySize)
-{
-       HUD_Panel_UpdatePosSizeForId(highlightedPanel);
-       vector resizeorigin;
-       resizeorigin = panel_click_resizeorigin;
-       vector myPos;
-
-       // minimum panel size cap
-       mySize_x = max(0.025 * vid_conwidth, mySize_x);
-       mySize_y = max(0.025 * vid_conheight, mySize_y);
-
-       if(highlightedPanel == HUD_PANEL_CHAT) // some panels have their own restrictions, like the chat panel (which actually only moves the engine chat print around). Looks bad if it's too small.
-       {
-               mySize_x = max(17 * autocvar_con_chatsize, mySize_x);
-               mySize_y = max(2 * autocvar_con_chatsize + 2 * panel_bg_padding, mySize_y);
-       }
-
-       // collision testing|
-       // -----------------+
-
-       // we need to know pos at this stage, but it might still change later if we hit a screen edge/other panel (?)
-       if(resizeCorner == 1) {
-               myPos_x = resizeorigin_x - mySize_x;
-               myPos_y = resizeorigin_y - mySize_y;
-       } else if(resizeCorner == 2) {
-               myPos_x = resizeorigin_x;
-               myPos_y = resizeorigin_y - mySize_y;
-       } else if(resizeCorner == 3) {
-               myPos_x = resizeorigin_x - mySize_x;
-               myPos_y = resizeorigin_y;
-       } else { // resizeCorner == 4
-               myPos_x = resizeorigin_x;
-               myPos_y = resizeorigin_y;
-       }
-
-       // left/top screen edges
-       if(myPos_x < 0)
-               mySize_x = mySize_x + myPos_x;
-       if(myPos_y < 0)
-               mySize_y = mySize_y + myPos_y;
-
-       // bottom/right screen edges
-       if(myPos_x + mySize_x > vid_conwidth)
-               mySize_x = vid_conwidth - myPos_x;
-       if(myPos_y + mySize_y > vid_conheight)
-               mySize_y = vid_conheight - myPos_y;
-
-       //if(cvar("hud_configure_checkcollisions_debug"))
-               //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"))
-       {
-               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;
-       }
-
-       if(hud_configure_checkcollisions)
-               mySize = HUD_Panel_CheckResize(mySize, resizeorigin);
-
-       // minimum panel size cap, do this once more so we NEVER EVER EVER have a panel smaller than this, JUST IN CASE above code still makes the panel eg negative (impossible to resize back without changing cvars manually then)
-       mySize_x = max(0.025 * vid_conwidth, mySize_x);
-       mySize_y = max(0.025 * vid_conheight, mySize_y);
-
-       // do another pos check, as size might have changed by now
-       if(resizeCorner == 1) {
-               myPos_x = resizeorigin_x - mySize_x;
-               myPos_y = resizeorigin_y - mySize_y;
-       } else if(resizeCorner == 2) {
-               myPos_x = resizeorigin_x;
-               myPos_y = resizeorigin_y - mySize_y;
-       } else if(resizeCorner == 3) {
-               myPos_x = resizeorigin_x - mySize_x;
-               myPos_y = resizeorigin_y;
-       } else { // resizeCorner == 4
-               myPos_x = resizeorigin_x;
-               myPos_y = resizeorigin_y;
-       }
-
-       //if(cvar("hud_configure_checkcollisions_debug"))
-               //drawfill(myPos, mySize, '0 1 0', .3, DRAWFLAG_NORMAL);
-
-       HUD_Panel_GetName(highlightedPanel);
-       string s;
-       s = strcat(ftos(mySize_x/vid_conwidth), " ", ftos(mySize_y/vid_conheight));
-       cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
-
-       s = strcat(ftos(myPos_x/vid_conwidth), " ", ftos(myPos_y/vid_conheight));
-       cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
-}
-
-float mouseClicked;
-float prevMouseClicked; // previous state
-float prevMouseClickedTime; // time during previous mouse click, to check for doubleclicks
-vector prevMouseClickedPos; // pos during previous mouse click, to check for doubleclicks
-
-float pressed_key_time;
-void HUD_Panel_Arrow_Action(float nPrimary)
-{
-       if (highlightedPanel_prev == -1 || mouseClicked)
-               return;
-
-       hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
-
-       float step;
-       if(cvar("hud_configure_grid"))
-       {
-               if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
-               {
-                       if (hudShiftState & S_SHIFT)
-                               step = hud_configure_realGridSize_y;
-                       else
-                               step = 2 * hud_configure_realGridSize_y;
-               }
-               else
-               {
-                       if (hudShiftState & S_SHIFT)
-                               step = hud_configure_realGridSize_x;
-                       else
-                               step = 2 * hud_configure_realGridSize_x;
-               }
-       }
-       else
-       {
-               if (nPrimary == K_UPARROW || nPrimary == K_DOWNARROW)
-                       step = vid_conheight;
-               else
-                       step = vid_conwidth;
-               if (hudShiftState & S_SHIFT)
-                       step = (step / 256); // more precision
-               else
-                       step = (step / 64) * (1 + 2 * (time - pressed_key_time));
-       }
-
-       highlightedPanel = highlightedPanel_prev;
-
-       HUD_Panel_UpdatePosSizeForId(highlightedPanel);
-
-       vector prev_pos, prev_size;
-       prev_pos = panel_pos;
-       prev_size = panel_size;
-
-       if (hudShiftState & S_ALT) // resize
-       {
-               highlightedAction = 1;
-               if(nPrimary == K_UPARROW)
-                       resizeCorner = 1;
-               else if(nPrimary == K_RIGHTARROW)
-                       resizeCorner = 2;
-               else if(nPrimary == K_LEFTARROW)
-                       resizeCorner = 3;
-               else // if(nPrimary == K_DOWNARROW)
-                       resizeCorner = 4;
-
-               // ctrl+arrow reduces the size, instead of increasing it
-               // Note that ctrl disables collisions check too, but it's fine
-               // since we don't collide with anything reducing the size
-               if (hudShiftState & S_CTRL) {
-                       step = -step;
-                       resizeCorner = 5 - resizeCorner;
-               }
-
-               vector mySize;
-               mySize = panel_size;
-               panel_click_resizeorigin = panel_pos;
-               if(resizeCorner == 1) {
-                       panel_click_resizeorigin += mySize;
-                       mySize_y += step;
-               } else if(resizeCorner == 2) {
-                       panel_click_resizeorigin_y += mySize_y;
-                       mySize_x += step;
-               } else if(resizeCorner == 3) {
-                       panel_click_resizeorigin_x += mySize_x;
-                       mySize_x += step;
-               } else { // resizeCorner == 4
-                       mySize_y += step;
-               }
-               HUD_Panel_SetPosSize(mySize);
-       }
-       else // move
-       {
-               highlightedAction = 2;
-               vector pos;
-               pos = panel_pos;
-               if(nPrimary == K_UPARROW)
-                       pos_y -= step;
-               else if(nPrimary == K_DOWNARROW)
-                       pos_y += step;
-               else if(nPrimary == K_LEFTARROW)
-                       pos_x -= step;
-               else // if(nPrimary == K_RIGHTARROW)
-                       pos_x += step;
-
-               HUD_Panel_SetPos(pos);
-       }
-
-       HUD_Panel_UpdatePosSizeForId(highlightedPanel);
-
-       if (prev_pos != panel_pos || prev_size != panel_size)
-       {
-               // backup!
-               panel_pos_backup = prev_pos;
-               panel_size_backup = prev_size;
-               highlightedPanel_backup = highlightedPanel;
-       }
-}
-
-void HUD_Panel_EnableMenu();
-float tab_panels[HUD_PANEL_NUM];
-float tab_panel, tab_backward;
-vector tab_panel_pos;
-void HUD_Panel_FirstInDrawQ(float id);
-void reset_tab_panels()
-{
-       int i;
-       for(i = 0; i < HUD_PANEL_NUM; ++i)
-               tab_panels[i] = -1;
-}
-float HUD_Panel_InputEvent(float bInputType, float nPrimary, float nSecondary)
-{
-       string s;
-
-       if(!autocvar__hud_configure)
-               return false;
-
-       // allow console bind to work
-       string con_keys;
-       float keys;
-       con_keys = findkeysforcommand("toggleconsole");
-       keys = tokenize(con_keys);
-
-       float hit_con_bind, i;
-       for (i = 0; i < keys; ++i)
-       {
-               if(nPrimary == stof(argv(i)))
-                       hit_con_bind = 1;
-       }
-
-       if(bInputType == 0) {
-               if(nPrimary == K_ALT) hudShiftState |= S_ALT;
-               if(nPrimary == K_CTRL) hudShiftState |= S_CTRL;
-               if(nPrimary == K_SHIFT) hudShiftState |= S_SHIFT;
-       }
-       else if(bInputType == 1) {
-               if(nPrimary == K_ALT) hudShiftState -= (hudShiftState & S_ALT);
-               if(nPrimary == K_CTRL) hudShiftState -= (hudShiftState & S_CTRL);
-               if(nPrimary == K_SHIFT) hudShiftState -= (hudShiftState & S_SHIFT);
-       }
-
-       if(nPrimary == K_CTRL)
-       {
-               if (bInputType == 1)
-               {
-                       if (tab_panel != -1)
-                       {
-                               //switch to selected panel when ctrl has been released
-                               highlightedPanel_prev = tab_panel;
-                               HUD_Panel_FirstInDrawQ(highlightedPanel_prev);
-                       }
-               }
-               //reset on press AND on release
-               tab_panel = -1;
-               reset_tab_panels();
-       }
-
-       if(nPrimary == K_MOUSE1)
-       {
-               if(bInputType == 0) { // key pressed
-                       mouseClicked = 1;
-                       return true;
-               }
-               else if(bInputType == 1) {// key released
-                       mouseClicked = 0;
-                       return true;
-               }
-       }
-       else if(nPrimary == K_TAB && hudShiftState & S_CTRL) //TODO: move this case down
-       {
-               if (bInputType == 1)
-                       return true;
-
-               //FIXME: if a panel is highlighted, has the same pos_x and lays in the same level
-               //of other panels then next consecutive ctrl-tab will select the highlighted panel too
-               //(it should only after every other panel of the hud)
-               //It's a minor bug anyway, we can live with it
-
-               float starting_panel;
-               float old_tab_panel = tab_panel;
-               if (tab_panel == -1) //first press of TAB
-               {
-                       if (highlightedPanel_prev != -1)
-                               HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev)
-                       else
-                               panel_pos = '0 0 0';
-                       starting_panel = highlightedPanel_prev; //can be -1, it means no starting panel
-                       tab_panel_pos = panel_pos; //to compute level
-               }
-               else
-               {
-                       if ( ((!tab_backward) && (hudShiftState & S_SHIFT)) || (tab_backward && !(hudShiftState & S_SHIFT)) ) //tab direction changed?
-                               reset_tab_panels();
-                       starting_panel = tab_panel;
-               }
-               tab_backward = (hudShiftState & S_SHIFT);
-
-               float k, level, start_pos_x;
-               vector candidate_pos;
-               const float LEVELS_NUM = 4;
-               const float level_height = vid_conheight / LEVELS_NUM;
-:find_tab_panel
-               level = floor(tab_panel_pos_y / level_height) * level_height; //starting level
-               candidate_pos_x = (!tab_backward) ? vid_conwidth : 0;
-               start_pos_x = tab_panel_pos_x;
-               tab_panel = -1;
-               k=0;
-               while(++k)
-               {
-                       for(i = 0; i < HUD_PANEL_NUM; ++i)
-                       {
-                               if (i == tab_panels[i] || i == starting_panel)
-                                       continue;
-                               HUD_Panel_UpdatePosSizeForId(i)
-                               if (panel_pos_y >= level && (panel_pos_y - level) < level_height)
-                               if (  ( !tab_backward && panel_pos_x >= start_pos_x && (panel_pos_x < candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y <= candidate_pos_y)) )
-                                       || ( tab_backward && panel_pos_x <= start_pos_x && (panel_pos_x > candidate_pos_x || (panel_pos_x == candidate_pos_x && panel_pos_y >= candidate_pos_y)) )  )
-                               {
-                                       tab_panel = i;
-                                       tab_panel_pos = candidate_pos = panel_pos;
-                               }
-                       }
-                       if (tab_panel != -1)
-                               break;
-                       if (k == LEVELS_NUM) //tab_panel not found
-                       {
-                               reset_tab_panels();
-                               if (old_tab_panel == -2) //this prevents an infinite loop (should not happen normally)
-                               {
-                                       tab_panel = -1;
-                                       return true;
-                               }
-                               starting_panel = old_tab_panel;
-                               old_tab_panel = -2;
-                               goto find_tab_panel; //u must find tab_panel!
-                       }
-                       if (!tab_backward)
-                       {
-                               level = mod(level + level_height, vid_conheight);
-                               start_pos_x = 0;
-                               candidate_pos_x = vid_conwidth;
-                       }
-                       else
-                       {
-                               level = mod(level - level_height, vid_conheight);
-                               start_pos_x = vid_conwidth;
-                               candidate_pos_x = 0;
-                       }
-               }
-
-               tab_panels[tab_panel] = tab_panel;
-       }
-       else if(nPrimary == K_ESCAPE)
-       {
-               if (bInputType == 1)
-                       return true;
-               menu_enabled = 1;
-               menu_enabled_time = time;
-               localcmd("menu_showhudexit\n");
-       }
-       else if(nPrimary == K_SPACE && hudShiftState & S_CTRL) // enable/disable highlighted panel or dock
-       {
-               if (bInputType == 1 || mouseClicked)
-                       return true;
-
-               if (highlightedPanel_prev != -1)
-                       cvar_set(strcat("hud_panel_", panel_name), ftos(!(panel_enabled)));
-               else
-                       cvar_set(strcat("hud_dock"), (autocvar_hud_dock == "") ? "dock" : "");
-       }
-       else if(nPrimary == 'c' && hudShiftState & S_CTRL) // copy highlighted panel size
-       {
-               if (bInputType == 1 || mouseClicked)
-                       return true;
-
-               if (highlightedPanel_prev != -1)
-               {
-                       panel_size_copied = panel_size;
-                       highlightedPanel_copied = highlightedPanel_prev;
-               }
-       }
-       else if(nPrimary == 'v' && hudShiftState & S_CTRL) // past copied size on the highlighted panel
-       {
-               if (bInputType == 1 || mouseClicked)
-                       return true;
-
-               if (highlightedPanel_copied == -1 || highlightedPanel_prev == -1)
-                       return true;
-
-               HUD_Panel_UpdatePosSizeForId(highlightedPanel_prev);
-
-               // reduce size if it'd go beyond screen boundaries
-               vector tmp_size = panel_size_copied;
-               if (panel_pos_x + panel_size_copied_x > vid_conwidth)
-                       tmp_size_x = vid_conwidth - panel_pos_x;
-               if (panel_pos_y + panel_size_copied_y > vid_conheight)
-                       tmp_size_y = vid_conheight - panel_pos_y;
-
-               if (panel_size == tmp_size)
-                       return true;
-
-               // backup first!
-               panel_pos_backup = panel_pos;
-               panel_size_backup = panel_size;
-               highlightedPanel_backup = highlightedPanel_prev;
-
-               s = strcat(ftos(tmp_size_x/vid_conwidth), " ", ftos(tmp_size_y/vid_conheight));
-               cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
-       }
-       else if(nPrimary == 'z' && hudShiftState & S_CTRL) // undo last action
-       {
-               if (bInputType == 1 || mouseClicked)
-                       return true;
-               //restore previous values
-               if (highlightedPanel_backup != -1)
-               {
-                       HUD_Panel_GetName(highlightedPanel_backup);
-                       s = strcat(ftos(panel_pos_backup_x/vid_conwidth), " ", ftos(panel_pos_backup_y/vid_conheight));
-                       cvar_set(strcat("hud_panel_", panel_name, "_pos"), s);
-                       s = strcat(ftos(panel_size_backup_x/vid_conwidth), " ", ftos(panel_size_backup_y/vid_conheight));
-                       cvar_set(strcat("hud_panel_", panel_name, "_size"), s);
-                       highlightedPanel_backup = -1;
-               }
-       }
-       else if(nPrimary == K_UPARROW || nPrimary == K_DOWNARROW || nPrimary == K_LEFTARROW || nPrimary == K_RIGHTARROW)
-       {
-               if (bInputType == 1)
-               {
-                       pressed_key_time = 0;
-                       return true;
-               }
-               else if (pressed_key_time == 0)
-                       pressed_key_time = time;
-
-               HUD_Panel_Arrow_Action(nPrimary); //move or resize panel
-       }
-       else if(nPrimary == K_ENTER || nPrimary == K_SPACE || nPrimary == K_KP_ENTER)
-       {
-               if (bInputType == 1)
-                       return true;
-               if (highlightedPanel_prev != -1)
-               {
-                       highlightedPanel = highlightedPanel_prev;
-                       HUD_Panel_EnableMenu();
-               }
-       }
-       else if(hit_con_bind)
-               return false;
-
-       return true;
-}
-
-float HUD_Panel_HighlightCheck()
-{
-       float i, j, border;
-
-       while(j < HUD_PANEL_NUM)
-       {
-               i = panel_order[j];
-               j += 1;
-
-               HUD_Panel_UpdatePosSizeForId(i);
-
-               border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
-
-               // move
-               if(mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
-               {
-                       return 1;
-               }
-               // resize from topleft border
-               else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
-               {
-                       return 2;
-               }
-               // resize from topright border
-               else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
-               {
-                       return 3;
-               }
-               // resize from bottomleft border
-               else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
-               {
-                       return 3;
-               }
-               // resize from bottomright border
-               else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
-               {
-                       return 2;
-               }
-       }
-       return 0;
-}
-
-// move a panel to the beginning of the panel order array (which means it gets drawn last, on top of everything else)
-void HUD_Panel_FirstInDrawQ(float id)
-{
-       float i;
-       var float place = -1;
-       // find out where in the array our current id is, save into place
-       for(i = 0; i < HUD_PANEL_NUM; ++i)
-       {
-               if(panel_order[i] == id)
-               {
-                       place = i;
-                       break;
-               }
-       }
-       // place last if we didn't find a place for it yet (probably new panel, or screwed up cvar)
-       if(place == -1)
-               place = HUD_PANEL_NUM - 1;
-
-       // move all ids up by one step in the array until "place"
-       for(i = place; i > 0; --i)
-       {
-               panel_order[i] = panel_order[i-1];
-       }
-       // now save the new top id
-       panel_order[0] = id;
-       
-       // let's save them into the cvar by some strcat trickery
-       string s;
-       for(i = 0; i < HUD_PANEL_NUM; ++i)
-       {
-               s = strcat(s, ftos(panel_order[i]), " ");
-       }
-       cvar_set("_hud_panelorder", s);
-       if(hud_panelorder_prev)
-               strunzone(hud_panelorder_prev);
-       hud_panelorder_prev = strzone(autocvar__hud_panelorder); // prevent HUD_Main from doing useless update, we already updated here
-}
-
-void HUD_Panel_Highlight()
-{
-       float i, j, border;
-
-       while(j < HUD_PANEL_NUM)
-       {
-               i = panel_order[j];
-               j += 1;
-
-               HUD_Panel_UpdatePosSizeForId(i);
-
-               border = max(8, panel_bg_border); // FORCED border so a small border size doesn't mean you can't resize
-
-               // move
-               if(mousepos_x >= panel_pos_x && mousepos_y >= panel_pos_y && mousepos_x <= panel_pos_x + panel_size_x && mousepos_y <= panel_pos_y + panel_size_y)
-               {
-                       highlightedPanel = i;
-                       HUD_Panel_FirstInDrawQ(i);
-                       highlightedAction = 1;
-                       panel_click_distance = mousepos - panel_pos;
-                       return;
-               }
-               // resize from topleft border
-               else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
-               {
-                       highlightedPanel = i;
-                       HUD_Panel_FirstInDrawQ(i);
-                       highlightedAction = 2;
-                       resizeCorner = 1;
-                       panel_click_distance = mousepos - panel_pos;
-                       panel_click_resizeorigin = panel_pos + panel_size;
-                       return;
-               }
-               // resize from topright border
-               else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y - border && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + 0.5 * panel_size_y)
-               {
-                       highlightedPanel = i;
-                       HUD_Panel_FirstInDrawQ(i);
-                       highlightedAction = 2;
-                       resizeCorner = 2;
-                       panel_click_distance_x = panel_size_x - mousepos_x + panel_pos_x;
-                       panel_click_distance_y = mousepos_y - panel_pos_y;
-                       panel_click_resizeorigin = panel_pos + eY * panel_size_y;
-                       return;
-               }
-               // resize from bottomleft border
-               else if(mousepos_x >= panel_pos_x - border && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + 0.5 * panel_size_x && mousepos_y <= panel_pos_y + panel_size_y + border)
-               {
-                       highlightedPanel = i;
-                       HUD_Panel_FirstInDrawQ(i);
-                       highlightedAction = 2;
-                       resizeCorner = 3;
-                       panel_click_distance_x = mousepos_x - panel_pos_x;
-                       panel_click_distance_y = panel_size_y - mousepos_y + panel_pos_y;
-                       panel_click_resizeorigin = panel_pos + eX * panel_size_x;
-                       return;
-               }
-               // resize from bottomright border
-               else if(mousepos_x >= panel_pos_x + 0.5 * panel_size_x && mousepos_y >= panel_pos_y + 0.5 * panel_size_y && mousepos_x <= panel_pos_x + panel_size_x + border && mousepos_y <= panel_pos_y + panel_size_y + border)
-               {
-                       highlightedPanel = i;
-                       HUD_Panel_FirstInDrawQ(i);
-                       highlightedAction = 2;
-                       resizeCorner = 4;
-                       panel_click_distance = panel_size - mousepos + panel_pos;
-                       panel_click_resizeorigin = panel_pos;
-                       return;
-               }
-               else
-               {
-                       highlightedPanel_prev = -1;
-               }
-       }
-}
-
-void HUD_Panel_EnableMenu()
-{
-       menu_enabled = 2;
-       menu_enabled_time = time;
-       HUD_Panel_GetName(highlightedPanel);
-       localcmd("menu_showhudoptions ", panel_name, "\n");
-}
-float highlightcheck;
-vector prev_pos, prev_size;
-void HUD_Panel_Mouse()
-{
-       // TODO: needs better check... is there any float that contains the current state of the menu? _menu_alpha isn't apparently updated the frame the menu gets enabled
-       if (autocvar__menu_alpha == 0 && time - menu_enabled_time > 0.5)
-               menu_enabled = 0;
-
-       /*
-       print("menu_enabled: ", ftos(menu_enabled), "\n");
-       print("Highlighted: ", ftos(highlightedPanel), "\n");
-       print("Menu alpha: ", ftos(autocvar__menu_alpha), "\n");
-       */
-
-       // instantly hide the editor cursor if we open the HUDExit dialog
-       // as hud_fade_alpha doesn't decrease to 0 in this case
-       // TODO: find a way to fade the cursor out even in this case
-       if(menu_enabled == 1 || (menu_enabled == 2 && !hud_fade_alpha))
-               return;
-
-       if(mouseClicked == 0 && menu_enabled != 2 && highlightedPanel >= 0) { // don't reset these variables in menu_enabled mode 2!
-               highlightedPanel = -1;
-               highlightedAction = 0;
-       }
-       if(highlightedPanel != -1)
-               highlightedPanel_prev = highlightedPanel;
-
-       mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
-
-       mousepos_x = bound(0, mousepos_x, vid_conwidth);
-       mousepos_y = bound(0, mousepos_y, vid_conheight);
-
-       if(mouseClicked)
-       {
-               if(prevMouseClicked == 0)
-               {
-                       HUD_Panel_Highlight(); // sets highlightedPanel, highlightedAction, panel_click_distance, panel_click_resizeorigin
-                                                                       // and calls HUD_Panel_UpdatePosSizeForId() for the highlighted panel
-                       prev_pos = panel_pos;
-                       prev_size = panel_size;
-               }
-               else
-                       HUD_Panel_UpdatePosSizeForId(highlightedPanel);
-
-               if (prev_pos != panel_pos || prev_size != panel_size)
-               {
-                       hud_configure_checkcollisions = (!(hudShiftState & S_CTRL) && autocvar_hud_configure_checkcollisions);
-                       // backup!
-                       panel_pos_backup = prev_pos;
-                       panel_size_backup = prev_size;
-                       highlightedPanel_backup = highlightedPanel;
-               }
-               else
-                       // in case the clicked panel is inside another panel and we aren't
-                       // moving it, avoid the immediate "fix" of its position/size
-                       // (often unwanted and hateful) by disabling collisions check
-                       hud_configure_checkcollisions = false;
-
-               if(highlightedAction == 1)
-                       HUD_Panel_SetPos(mousepos - panel_click_distance);
-               else if(highlightedAction == 2)
-               {
-                       vector mySize;
-                       if(resizeCorner == 1) {
-                               mySize_x = panel_click_resizeorigin_x - (mousepos_x - panel_click_distance_x);
-                               mySize_y = panel_click_resizeorigin_y - (mousepos_y - panel_click_distance_y);
-                       } else if(resizeCorner == 2) {
-                               mySize_x = mousepos_x + panel_click_distance_x - panel_click_resizeorigin_x;
-                               mySize_y = panel_click_distance_y + panel_click_resizeorigin_y - mousepos_y;
-                       } else if(resizeCorner == 3) {
-                               mySize_x = panel_click_resizeorigin_x + panel_click_distance_x - mousepos_x;
-                               mySize_y = mousepos_y + panel_click_distance_y - panel_click_resizeorigin_y;
-                       } else { // resizeCorner == 4
-                               mySize_x = mousepos_x - (panel_click_resizeorigin_x - panel_click_distance_x);
-                               mySize_y = mousepos_y - (panel_click_resizeorigin_y - panel_click_distance_y);
-                       }
-                       HUD_Panel_SetPosSize(mySize);
-               }
-
-               // doubleclick check
-               if(time - prevMouseClickedTime < 0.4 && prevMouseClicked == 0 && prevMouseClickedPos == mousepos && highlightedPanel >= 0)
-               {
-                       mouseClicked = 0; // to prevent spam, I guess.
-                       HUD_Panel_EnableMenu();
-                       return;
-               }
-               if(prevMouseClicked == 0)
-               {
-                       prevMouseClickedTime = time;
-                       prevMouseClickedPos = mousepos;
-               }
-       }
-       else
-       {
-               highlightcheck = HUD_Panel_HighlightCheck();
-       }
-       // draw cursor after performing move/resize to have the panel pos/size updated before highlightcheck
-       vector cursorsize;
-       cursorsize = '32 32 0';
-
-       if(highlightcheck == 0)
-               drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
-       else if(highlightcheck == 1)
-               drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
-       else if(highlightcheck == 2)
-               drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
-       else
-               drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', hud_fade_alpha, DRAWFLAG_NORMAL);
-
-       prevMouseClicked = mouseClicked;
-}
-
 // Weapon icons (#0)
 //
-float weaponspace[10];
-#define HUD_Weapons_Clear()\
-       float idx;\
-       for(idx = 0; idx < 10; ++idx)\
-               weaponspace[idx] = 0
-
 entity weaponorder[WEP_MAXCOUNT];
 void weaponorder_swap(float i, float j, entity pass)
 {
@@ -1679,6 +582,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;
@@ -1699,18 +604,17 @@ void HUD_Weapons(void)
                return;
        }
 
-       active_panel = HUD_PANEL_WEAPONS;
        HUD_Panel_UpdateCvars(weapons);
 
        if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
        {
                f = (time - (weapontime + timeout)) / timeout_effect_length;
-               if (autocvar_hud_panel_weapons_timeout_effect)
+               if (autocvar_hud_panel_weapons_timeout_effect == 1 || autocvar_hud_panel_weapons_timeout_effect == 3)
                {
                        panel_bg_alpha *= (1 - f);
                        panel_fg_alpha *= (1 - f);
                }
-               if (autocvar_hud_panel_weapons_timeout_effect == 1)
+               if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
                {
                        f *= f; // for a cooler movement
                        center_x = panel_pos_x + panel_size_x/2;
@@ -1736,12 +640,12 @@ void HUD_Weapons(void)
        else if (timeout && time < weaponprevtime + timein_effect_length && !autocvar__hud_configure)
        {
                f = (time - weaponprevtime) / timein_effect_length;
-               if (autocvar_hud_panel_weapons_timeout_effect)
+               if (autocvar_hud_panel_weapons_timeout_effect == 1 || autocvar_hud_panel_weapons_timeout_effect == 3)
                {
                        panel_bg_alpha *= (f);
                        panel_fg_alpha *= (f);
                }
-               if (autocvar_hud_panel_weapons_timeout_effect == 1)
+               if (autocvar_hud_panel_weapons_timeout_effect == 2 || autocvar_hud_panel_weapons_timeout_effect == 3)
                {
                        f *= f; // for a cooler movement
                        f = 1 - f;
@@ -1816,8 +720,6 @@ void HUD_Weapons(void)
        else
                wpnalpha = panel_fg_alpha;
 
-       HUD_Weapons_Clear();
-
        float rows, columns;
        float aspect = autocvar_hud_panel_weapons_aspect;
        rows = panel_size_y/panel_size_x;
@@ -1871,7 +773,6 @@ void HUD_Weapons(void)
        }
 
        float weapons_st = getstati(STAT_WEAPONS);
-       float label = autocvar_hud_panel_weapons_label;
 
        for(i = 0; i < weapon_cnt; ++i)
        {
@@ -1911,16 +812,16 @@ void HUD_Weapons(void)
                {
                        drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', wpnalpha, DRAWFLAG_NORMAL);
 
-                       if(label == 1) // weapon number
+                       if(autocvar_hud_panel_weapons_label == 1) // weapon number
                                drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-                       else if(label == 2) // bind
+                       else if(autocvar_hud_panel_weapons_label == 2) // bind
                                drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * wpnsize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
 
                        // draw ammo status bar
-                       if(autocvar_hud_panel_weapons_ammo && weapid != WEP_TUBA && weapid != WEP_LASER && weapid != WEP_PORTO)
+                       if(autocvar_hud_panel_weapons_ammo && self.weapon != WEP_TUBA && self.weapon != WEP_LASER && self.weapon != WEP_PORTO)
                        {
                                a = 0;
-                               type = GetAmmoTypeForWep(weapid);
+                               type = GetAmmoTypeForWep(self.weapon);
                                if(type != -1)
                                        a = getstati(GetAmmoStat(type)); // how much ammo do we have?
 
@@ -2088,8 +989,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;
@@ -2134,7 +1036,6 @@ void HUD_Ammo(void)
                ammo_size_y = newSize;
        }
 
-       drawfont = hud_bigfont;
        float i, stat_items, currently_selected;
        if (autocvar_hud_panel_ammo_onlycurrent)
        {
@@ -2166,7 +1067,6 @@ void HUD_Ammo(void)
                        column = column + 1;
                }
        }
-       drawfont = hud_font;
 }
 
 void DrawNumIcon(vector myPos, vector mySize, float x, string icon, float vertical, float icon_right_align, vector color, float alpha)
@@ -2256,33 +1156,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)
        {
@@ -2290,128 +1189,138 @@ void HUD_Powerups(void) {
                mySize -= '2 2 0' * panel_bg_padding;
        }
 
-       vector barsize;
-       vector picpos;
-       vector numpos;
-
-       string leftname, rightname;
-    string leftprogressname, rightprogressname;
-       float leftcnt, rightcnt;
-       float leftexact, rightexact;
-       if (autocvar_hud_panel_powerups_flip) {
-               leftname = "strength";
-        leftprogressname = autocvar_hud_panel_powerups_progressbar_strength;
-               leftcnt = ceil(strength_time);
-               leftexact = strength_time;
-
-               rightname = "shield";
-        rightprogressname = autocvar_hud_panel_powerups_progressbar_shield;
-               rightcnt = ceil(shield_time);
-               rightexact = shield_time;
-       } else {
-               leftname = "shield";
-        leftprogressname = autocvar_hud_panel_powerups_progressbar_shield;
-               leftcnt = ceil(shield_time);
-               leftexact = shield_time;
-
-               rightname = "strength";
-        rightprogressname = autocvar_hud_panel_powerups_progressbar_strength;
-               rightcnt = ceil(strength_time);
-               rightexact = strength_time;
-       }
-
-       drawfont = hud_bigfont;
-       float baralign = autocvar_hud_panel_powerups_baralign;
-       float iconalign = autocvar_hud_panel_powerups_iconalign;
-
        float panel_ar = mySize_x/mySize_y;
        float is_vertical = (panel_ar < 1);
+       vector shield_offset, strength_offset;
        if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
        {
-        barsize = eX * 0.5 * mySize_x + eY * mySize_y;
-               if(leftcnt)
+               mySize_x *= 0.5;
+               if (autocvar_hud_panel_powerups_flip)
+                       shield_offset_x = mySize_x;
+               else
+                       strength_offset_x = mySize_x;
+       }
+       else
+       {
+               mySize_y *= 0.5;
+               if (autocvar_hud_panel_powerups_flip)
+                       shield_offset_y = mySize_y;
+               else
+                       strength_offset_y = mySize_y;
+       }
+
+       float shield_baralign, strength_baralign;
+       float shield_iconalign, strength_iconalign;
+       if (autocvar_hud_panel_powerups_flip)
+       {
+               strength_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
+               shield_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
+               strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
+               shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
+       }
+       else
+       {
+               shield_baralign = (autocvar_hud_panel_powerups_baralign == 2 || autocvar_hud_panel_powerups_baralign == 1);
+               strength_baralign = (autocvar_hud_panel_powerups_baralign == 3 || autocvar_hud_panel_powerups_baralign == 1);
+               shield_iconalign = (autocvar_hud_panel_powerups_iconalign == 2 || autocvar_hud_panel_powerups_iconalign == 1);
+               strength_iconalign = (autocvar_hud_panel_powerups_iconalign == 3 || autocvar_hud_panel_powerups_iconalign == 1);
+       }
+
+       if(shield_time)
+       {
+               const float maxshield = 30;
+               float shield = ceil(shield_time);
+               if(autocvar_hud_panel_powerups_progressbar)
                {
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(leftname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/30, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(leftcnt > 1)
-                                       DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
-                               if(leftcnt <= 5)
-                                       DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
-                       }
+                       HUD_Panel_GetProgressBarColor(shield);
+                       HUD_Panel_DrawProgressBar(pos + shield_offset, mySize, autocvar_hud_panel_powerups_progressbar_shield, shield/maxshield, is_vertical, shield_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                }
-
-               if(rightcnt)
+               if(autocvar_hud_panel_powerups_text)
                {
-                       pos_x += barsize_x;
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(rightname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, rightprogressname, rightcnt/30, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(rightcnt > 1)
-                                       DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
-                               if(rightcnt <= 5)
-                                       DrawNumIcon_expanding(pos, eX * 0.5 * mySize_x + eY * mySize_y, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
-                       }
+                       if(shield > 1)
+                               DrawNumIcon(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', 1);
+                       if(shield <= 5)
+                               DrawNumIcon_expanding(pos + shield_offset, mySize, shield, "shield", is_vertical, shield_iconalign, '1 1 1', bound(0, (shield - shield_time) / 0.5, 1));
                }
        }
-       else
+
+       if(strength_time)
        {
-        barsize = eX * mySize_x + eY * 0.5 * mySize_y;
-               if(leftcnt)
+               const float maxstrength = 30;
+               float strength = ceil(strength_time);
+               if(autocvar_hud_panel_powerups_progressbar)
                {
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(leftname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/30, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(leftcnt > 1)
-                                       DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', 1);
-                               if(leftcnt <= 5)
-                                       DrawNumIcon_expanding(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), '1 1 1', bound(0, (leftcnt - leftexact) / 0.5, 1));
-                       }
+                       HUD_Panel_GetProgressBarColor(strength);
+                       HUD_Panel_DrawProgressBar(pos + strength_offset, mySize, autocvar_hud_panel_powerups_progressbar_strength, strength/maxstrength, is_vertical, strength_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                }
-
-               if(rightcnt)
+               if(autocvar_hud_panel_powerups_text)
                {
-                       pos_y += barsize_y;
-                       if(autocvar_hud_panel_powerups_progressbar)
-                       {
-                               HUD_Panel_GetProgressBarColorForString(rightname);
-                               HUD_Panel_DrawProgressBar(pos, barsize, rightprogressname, rightcnt/30, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * bound(0, max(strength_time, shield_time), 1), DRAWFLAG_NORMAL);
-                       }
-            if(autocvar_hud_panel_powerups_text)
-            {
-                               if(rightcnt > 1)
-                                       DrawNumIcon(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', 1);
-                               if(rightcnt <= 5)
-                                       DrawNumIcon_expanding(pos, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), '1 1 1', bound(0, (rightcnt - rightexact) / 0.5, 1));
-                       }
+                       if(strength > 1)
+                               DrawNumIcon(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', 1);
+                       if(strength <= 5)
+                               DrawNumIcon_expanding(pos + strength_offset, mySize, strength, "strength", is_vertical, strength_iconalign, '1 1 1', bound(0, (strength - strength_time) / 0.5, 1));
                }
        }
-       drawfont = hud_font;
 }
 
 // Health/armor (#3)
 //
+float health_time, prev_health;
+float armor_time, prev_armor;
+var float saved_health = -2;
+var float saved_armor = -2;
 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)
+               {
+                       health_time = -1;
+                       return;
+               }
+               if (autocvar_hud_panel_healtharmor_progressbar_gfx)
+               {
+                       if ( (prev_spectatee_status == -1 && spectatee_status > 0) //before observing, now spectating
+                         || (prev_spectatee_status > 0 && spectatee_status > 0 && prev_spectatee_status != spectatee_status) //changed spectated player
+                       )
+                       {
+                               //no effect
+                               saved_health = 0;
+                               saved_armor = 0;
+                               health_time = 0;
+                               armor_time = 0;
+                       }
+                       else if(prev_spectatee_status == -1 || (prev_spectatee_status > 0 && !spectatee_status)) //before spectating/observing, now playing
+                               health_time = -1;
+
+                       if (health_time == -1)
+                       {
+                               //start the load effect
+                               saved_health = -2;
+                               saved_armor = -2;
+                               health_time = time;
+                               armor_time = time;
+                               prev_health = 0;
+                               prev_armor = 0;
+                       }
+               }
+               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;
@@ -2424,25 +1333,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;
-
-       drawfont = hud_bigfont;
        float baralign = autocvar_hud_panel_healtharmor_baralign;
        float iconalign = autocvar_hud_panel_healtharmor_iconalign;
 
@@ -2493,118 +1383,143 @@ void HUD_HealthArmor(void)
        }
        else
        {
-               string leftname, rightname;
-        string leftprogressname, rightprogressname;
-               float leftcnt, rightcnt;
-               float leftmax, rightmax;
-               float leftactive, rightactive;
-               float leftalpha, rightalpha;
-               if (autocvar_hud_panel_healtharmor_flip) { // old style layout with armor left/top of health
-                       leftname = "armor";
-            leftprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
-                       leftcnt = armor;
-                       if(leftcnt)
-                               leftactive = 1;
-                       leftalpha = min((armor+10)/55, 1);
-            leftmax = maxarmor;
-
-                       rightname = "health";
-            rightprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
-                       rightcnt = health;
-                       rightactive = 1;
-                       rightalpha = 1;
-            rightmax = maxhealth;
-               } else {
-                       leftname = "health";
-            leftprogressname = autocvar_hud_panel_healtharmor_progressbar_health;
-                       leftcnt = health;
-                       leftactive = 1;
-                       leftalpha = 1;
-            leftmax = maxhealth;
-
-                       rightname = "armor";
-            rightprogressname = autocvar_hud_panel_healtharmor_progressbar_armor;
-                       rightcnt = armor;
-                       if(rightcnt)
-                               rightactive = 1;
-                       rightalpha = min((armor+10)/55, 1);
-            rightmax = maxarmor;
-               }
-
                float panel_ar = mySize_x/mySize_y;
                float is_vertical = (panel_ar < 1);
+               vector health_offset, armor_offset;
                if (panel_ar >= 4 || (panel_ar >= 1/4 && panel_ar < 1))
                {
-            barsize = eX * 0.5 * mySize_x + eY * mySize_y;
-                       if(leftactive)
-                       {
-                               if(autocvar_hud_panel_healtharmor_progressbar)
-                               {
-                                       HUD_Panel_GetProgressBarColorForString(leftname);
-                                       HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/leftmax, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-                               }
-                               if(autocvar_hud_panel_healtharmor_text)
-                                       DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
-                       }
-
-                       if(rightactive)
-                       {
-                               if(autocvar_hud_panel_healtharmor_progressbar)
-                               {
-                                       HUD_Panel_GetProgressBarColorForString(rightname);
-                                       HUD_Panel_DrawProgressBar(pos + eX * 0.5 * mySize_x, barsize, rightprogressname, rightcnt/rightmax, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
-                               }
-                               if(autocvar_hud_panel_healtharmor_text)
-                                       DrawNumIcon(pos + eX * 0.5 * mySize_x, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
-                       }
+                       mySize_x *= 0.5;
+                       if (autocvar_hud_panel_healtharmor_flip)
+                               health_offset_x = mySize_x;
+                       else
+                               armor_offset_x = mySize_x;
+               }
+               else
+               {
+                       mySize_y *= 0.5;
+                       if (autocvar_hud_panel_healtharmor_flip)
+                               health_offset_y = mySize_y;
+                       else
+                               armor_offset_y = mySize_y;
+               }
 
-                       if(fuel)
-                       {
-                               HUD_Panel_GetProgressBarColor(fuel);
-                               if (is_vertical) //if vertical always halve x to not cover too much numbers with 3 digits
-                                       mySize_x *= 0.2 * 0.5 / 2;
-                               else
-                                       mySize_y *= 0.2;
-                               HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
-                       }
+               float health_baralign, armor_baralign, fuel_baralign;
+               float health_iconalign, armor_iconalign;
+               if (autocvar_hud_panel_healtharmor_flip)
+               {
+                       armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
+                       health_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
+                       fuel_baralign = health_baralign;
+                       armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
+                       health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
                }
                else
                {
-            barsize = eX * mySize_x + eY * 0.5 * mySize_y;
-                       if(leftactive)
+                       health_baralign = (autocvar_hud_panel_healtharmor_baralign == 2 || autocvar_hud_panel_healtharmor_baralign == 1);
+                       armor_baralign = (autocvar_hud_panel_healtharmor_baralign == 3 || autocvar_hud_panel_healtharmor_baralign == 1);
+                       fuel_baralign = armor_baralign;
+                       health_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 2 || autocvar_hud_panel_healtharmor_iconalign == 1);
+                       armor_iconalign = (autocvar_hud_panel_healtharmor_iconalign == 3 || autocvar_hud_panel_healtharmor_iconalign == 1);
+               }
+
+               //if(health)
+               {
+                       if(autocvar_hud_panel_healtharmor_progressbar)
                        {
-                               if(autocvar_hud_panel_healtharmor_progressbar)
+                               HUD_Panel_GetProgressBarColor(health);
+                               float p_health;
+                               p_health = health;
+                               if (autocvar_hud_panel_healtharmor_progressbar_gfx)
                                {
-                                       HUD_Panel_GetProgressBarColorForString(leftname);
-                                       HUD_Panel_DrawProgressBar(pos, barsize, leftprogressname, leftcnt/leftmax, is_vertical, (baralign == 1 || baralign == 2), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                                       if (saved_health == -1)
+                                       {
+                                               if (prev_health == 0 || prev_health - health >= 3)
+                                               {
+                                                       health_time = time;
+                                                       saved_health = prev_health;
+                                               }
+                                       }
+                                       if (saved_health != -1)
+                                       {
+                                               float d = time - health_time;
+                                               if (d < 1)
+                                               {
+                                                       if (saved_health == -2)
+                                                               p_health *= sqrt(d);
+                                                       else
+                                                       {
+                                                               HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, saved_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
+                                                               if (prev_health - health >= 1) //refresh the effect if repeatedly damaged
+                                                                       health_time = time;
+                                                       }
+                                               }
+                                               else
+                                                       saved_health = -1; //damage effect ended
+                                       }
+                                       prev_health = health;
                                }
-                               if(autocvar_hud_panel_healtharmor_text)
-                                       DrawNumIcon(pos, barsize, leftcnt, leftname, is_vertical, (iconalign == 1 || iconalign == 2), HUD_Get_Num_Color(leftcnt, leftmax), 1);
+                               HUD_Panel_DrawProgressBar(pos + health_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_health, p_health/maxhealth, is_vertical, health_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
+                       if(autocvar_hud_panel_healtharmor_text)
+                               DrawNumIcon(pos + health_offset, mySize, health, "health", is_vertical, health_iconalign, HUD_Get_Num_Color(health, maxhealth), 1);
+               }
 
-                       if(rightactive)
+               if(armor)
+               {
+                       if(autocvar_hud_panel_healtharmor_progressbar)
                        {
-                               if(autocvar_hud_panel_healtharmor_progressbar)
+                               HUD_Panel_GetProgressBarColor(armor);
+                               float p_armor;
+                               p_armor = armor;
+                               if (autocvar_hud_panel_healtharmor_progressbar_gfx)
                                {
-                                       HUD_Panel_GetProgressBarColorForString(rightname);
-                                       HUD_Panel_DrawProgressBar(pos + eY * 0.5 * mySize_y, barsize, rightprogressname, rightcnt/rightmax, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+                                       if (saved_armor == -1)
+                                       {
+                                               if (prev_armor == 0 || prev_armor - armor >= 3)
+                                               {
+                                                       armor_time = time;
+                                                       saved_armor = prev_armor;
+                                               }
+                                       }
+                                       if (saved_armor != -1)
+                                       {
+                                               float d = time - armor_time;
+                                               if (d < 1)
+                                               {
+                                                       if (saved_armor == -2)
+                                                               p_armor *= sqrt(d);
+                                                       else
+                                                       {
+                                                               HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, saved_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha * (1 - d * d), DRAWFLAG_NORMAL);
+                                                               if (prev_armor - armor >= 1) //refresh the effect if repeatedly damaged
+                                                                       armor_time = time;
+                                                       }
+                                               }
+                                               else
+                                                       saved_armor = -1; //damage effect ended
+                                       }
+                                       prev_armor = armor;
                                }
-                               if(autocvar_hud_panel_healtharmor_text)
-                                       DrawNumIcon(pos + eY * 0.5 * mySize_y, barsize, rightcnt, rightname, is_vertical, (iconalign == 1 || iconalign == 3), HUD_Get_Num_Color(rightcnt, rightmax), 1);
+                               HUD_Panel_DrawProgressBar(pos + armor_offset, mySize, autocvar_hud_panel_healtharmor_progressbar_armor, p_armor/maxarmor, is_vertical, armor_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
+                       if(autocvar_hud_panel_healtharmor_text)
+                               DrawNumIcon(pos + armor_offset, mySize, armor, "armor", is_vertical, armor_iconalign, HUD_Get_Num_Color(armor, maxarmor), 1);
+               }
 
-                       if(fuel)
-                       {
-                               HUD_Panel_GetProgressBarColor(fuel);
-                               if (is_vertical) //if vertical always halve x to not cover numbers with 3 digits
-                                       mySize_x *= 0.2 / 2;
-                               else
-                                       mySize_y *= 0.2 * 0.5;
-                               HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, (baralign == 1 || baralign == 3), progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
-                       }
+               if(fuel)
+               {
+                       if (is_vertical)
+                               mySize_x *= 0.2 / 2; //if vertical always halve x to not cover too much numbers with 3 digits
+                       else
+                               mySize_y *= 0.2;
+                       if (panel_ar >= 4)
+                               mySize_x *= 2; //restore full panel size
+                       else if (panel_ar < 1/4)
+                               mySize_y *= 2; //restore full panel size
+                       HUD_Panel_GetProgressBarColor(fuel);
+                       HUD_Panel_DrawProgressBar(pos, mySize, "progressbar", fuel/100, is_vertical, fuel_baralign, progressbar_color, panel_fg_alpha * 0.8, DRAWFLAG_NORMAL);
                }
        }
-       drawfont = hud_font;
 }
 
 // Notification area (#4)
@@ -3105,10 +2020,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;
@@ -3418,10 +2336,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;
@@ -3464,19 +2385,21 @@ void HUD_Timer(void)
                timer = seconds_tostring(timeleft);
        }
 
-       drawfont = hud_bigfont;
        drawstring_aspect(pos, timer, mySize, timer_color, panel_fg_alpha, DRAWFLAG_NORMAL);
-       drawfont = hud_font;
 }
 
 // Radar (#6)
 //
 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;
@@ -3538,7 +2461,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
        {
@@ -3566,7 +2489,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(
@@ -3598,10 +2521,14 @@ 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;
+               if(spectatee_status == -1 && (gametype == GAME_RACE || gametype == GAME_CTS)) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_SCORE;
 
-       active_panel = HUD_PANEL_SCORE;
        HUD_Panel_UpdateCvars(score);
        vector pos, mySize;
        pos = panel_pos;
@@ -3652,23 +2579,22 @@ void HUD_Score(void)
                // race record display
                if (distribution <= 0)
                        HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawfont = hud_bigfont;
                drawstring_aspect(pos, timer, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawfont = hud_font;
        } else if (!teamplay) { // non-teamgames
                if ((spectatee_status == -1 && !autocvar__hud_configure) || autocvar_hud_panel_score_rankings)
                {
 #define SCOREPANEL_MAX_ENTRIES 6
 #define SCOREPANEL_ASPECTRATIO 2
-                       float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
-                       float height = mySize_y/entries;
-                       vector fontsize = '0.9 0.9 0' * height;
+                       const float entries = bound(1, floor(SCOREPANEL_MAX_ENTRIES * mySize_y/mySize_x * SCOREPANEL_ASPECTRATIO), SCOREPANEL_MAX_ENTRIES);
+                       const float height = mySize_y/entries;
+                       const vector fontsize = '0.9 0.9 0' * height;
                        pos_y += height * (1 - 0.9) / 2;
 
                        vector rgb;
                        rgb = '1 1 1';
 
-                       float name_size = mySize_x*0.75;
+                       const float name_size = mySize_x*0.75;
+                       const float highlight_alpha = 0.2;
                        float i, me_printed;
                        string s;
                        if (autocvar__hud_configure)
@@ -3682,7 +2608,7 @@ void HUD_Score(void)
                                        if (i == entries-1 && autocvar_hud_panel_score_rankings == 1)
                                        {
                                                rgb = '1 1 0';
-                                               drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
+                                               drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                                                s = GetPlayerName(pl.sv_entnum);
                                                score = 7;
                                        }
@@ -3727,7 +2653,7 @@ void HUD_Score(void)
                                        if (i == 0)
                                                rgb = '0 1 0'; //first: green
                                        me_printed = 1;
-                                       drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, 0.3 * panel_fg_alpha, DRAWFLAG_NORMAL);
+                                       drawfill(pos - eY * (height * (1 - 0.9) / 2), eX * mySize_x + eY * height, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                                }
                                s = textShortenToWidth(GetPlayerName(pl.sv_entnum), name_size, fontsize, stringwidth_colors);
                                drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, TRUE, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
@@ -3769,9 +2695,7 @@ void HUD_Score(void)
                                distribution_str = strcat("+", distribution_str);
                        HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
                }
-               drawfont = hud_bigfont;
                drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
-               drawfont = hud_font;
                drawstring_aspect(pos + eX * 0.75 * mySize_x, distribution_str, eX * 0.25 * mySize_x + eY * (1/3) * mySize_y, distribution_color, panel_fg_alpha, DRAWFLAG_NORMAL);
        } else { // teamgames
                float max_fragcount;
@@ -3830,9 +2754,7 @@ void HUD_Score(void)
                                score_pos = pos + eX * column * (score_size_x + offset_x) + eY * row * (score_size_y + offset_y);
                                if (max_fragcount == score)
                                        HUD_Panel_DrawHighlight(score_pos, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-                               drawfont = hud_bigfont;
                                drawstring_aspect(score_pos, ftos(score), score_size, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
-                               drawfont = hud_font;
                                ++row;
                                if(row >= rows)
                                {
@@ -3843,9 +2765,7 @@ void HUD_Score(void)
                        else if(tm.team == myteam) {
                                if (max_fragcount == score)
                                        HUD_Panel_DrawHighlight(pos, eX * 0.75 * mySize_x + eY * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
-                               drawfont = hud_bigfont;
                                drawstring_aspect(pos, ftos(score), eX * 0.75 * mySize_x + eY * mySize_y, GetTeamRGB(tm.team) * 0.8, panel_fg_alpha, DRAWFLAG_NORMAL);
-                               drawfont = hud_font;
                        } else {
                                if (max_fragcount == score)
                                        HUD_Panel_DrawHighlight(pos + eX * 0.75 * mySize_x + eY * (1/3) * rows * mySize_y, score_size, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
@@ -3858,15 +2778,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;
@@ -3897,7 +2819,6 @@ void HUD_RaceTimer (void) {
        }
        mySize = newSize;
 
-       drawfont = hud_bigfont;
        float a, t;
        string s, forcetime;
 
@@ -3997,8 +2918,6 @@ void HUD_RaceTimer (void) {
                        }
                }
        }
-
-       drawfont = hud_font;
 }
 
 // Vote window (#9)
@@ -4015,19 +2934,24 @@ float vote_change; // "time" when vote_active changed
 
 void HUD_VoteWindow(void) 
 {
-    uid2name_dialog = 0;
        if(autocvar_cl_allow_uid2name == -1 && (gametype == GAME_CTS || gametype == GAME_RACE))
        {
                vote_active = 1;
-               vote_called_vote = strzone(strcat("^2Name ^7instead of \"^1Unregistered player\"", " ^7in stats"));
-        uid2name_dialog = 1;
+               if (autocvar__hud_configure)
+               {
+                       vote_yescount = 0;
+                       vote_nocount = 0;
+                       print("^1You have to answer before entering hud configure mode\n");
+                       cvar_set("_hud_configure", "0");
+               }
+               vote_called_vote = strzone("^2Name ^7instead of \"^1Unregistered player^7\" in stats");
+               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;
 
@@ -4036,6 +2960,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;
@@ -4049,17 +2981,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)
@@ -4162,7 +3086,6 @@ void HUD_Mod_CA(vector pos, vector mySize)
        redalive = getstati(STAT_REDALIVE);
        bluealive = getstati(STAT_BLUEALIVE);
 
-       drawfont = hud_bigfont;
        vector redpos, bluepos;
        if(mySize_x > mySize_y)
        {
@@ -4182,7 +3105,6 @@ void HUD_Mod_CA(vector pos, vector mySize)
                drawpic_aspect_skin(bluepos, "player_blue.tga", eX * mySize_x + eY * 0.3 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
                drawstring_aspect(bluepos + eY * 0.3 * mySize_y, ftos(bluealive), eX * mySize_x + eY * 0.2 * mySize_y, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
        }
-       drawfont = hud_font;
 }
 
 // CTF HUD modicon section
@@ -4574,8 +3496,6 @@ void HUD_Mod_Race(vector pos, vector mySize)
        if not((scores_flags[ps_primary] & SFL_TIME) && !teamplay) // race/cts record display on HUD
                return; // no records in the actual race
 
-       drawfont = hud_bigfont;
-
        // clientside personal record
        string rr;
        if(gametype == GAME_CTS)
@@ -4698,7 +3618,103 @@ void HUD_Mod_Race(vector pos, vector mySize)
                        strunzone(race_status_name_prev);
                race_status_name_prev = string_null;
        }
-       drawfont = hud_font;
+}
+
+void DrawDomItem(vector myPos, vector mySize, float aspect_ratio, float layout, float i)
+{
+       float stat, pps_ratio;
+       string pic;
+       vector color;
+       switch(i)
+       {
+               case 0:
+                       stat = getstatf(STAT_DOM_PPS_RED);
+                       pic = "dom_icon_red";
+                       color = '1 0 0';
+                       break;
+               case 1:
+                       stat = getstatf(STAT_DOM_PPS_BLUE);
+                       pic = "dom_icon_blue";
+                       color = '0 0 1';
+                       break;
+               case 2:
+                       stat = getstatf(STAT_DOM_PPS_YELLOW);
+                       pic = "dom_icon_yellow";
+                       color = '1 1 0';
+                       break;
+               case 3:
+                       stat = getstatf(STAT_DOM_PPS_PINK);
+                       pic = "dom_icon_pink";
+                       color = '1 0 1';
+       }
+       pps_ratio = stat / getstatf(STAT_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 + 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(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(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 (stat > 0)
+       {
+               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();
+       }
+}
+
+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 = autocvar_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);
+
+       int i;
+       float row, column;
+       for(i=0; i<teams_count; ++i)
+       {
+               vector pos, itemSize;
+               pos = myPos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
+               itemSize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
+
+               DrawDomItem(pos, itemSize, aspect_ratio, layout, i);
+
+               ++row;
+               if(row >= rows)
+               {
+                       row = 0;
+                       ++column;
+               }
+       }
 }
 
 float mod_prev; // previous state of mod_active to check for a change
@@ -4707,13 +3723,14 @@ 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;
@@ -4749,6 +3766,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);
 }
@@ -4757,13 +3776,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;
@@ -4816,13 +3837,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
@@ -4853,7 +3879,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));
@@ -4863,8 +3890,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)
@@ -4873,7 +3900,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;
                }
        }
 }
@@ -4889,10 +3917,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;
@@ -4936,9 +3967,7 @@ void HUD_EngineInfo(void)
 
        vector color;
        color = HUD_Get_Num_Color (prevfps, 100);
-       drawfont = hud_bigfont;
        drawstring_aspect(pos, strcat("FPS: ", ftos_decimals(prevfps, autocvar_hud_panel_engineinfo_framecounter_decimals)), mySize, color, panel_fg_alpha, DRAWFLAG_NORMAL);
-       drawfont = hud_font;
 }
 
 // Info messages panel (#14)
@@ -4950,10 +3979,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;
@@ -5134,10 +4166,14 @@ float acc_prevtime, acc_avg, top_speed, top_speed_time;
 
 void HUD_Physics(void)
 {
-       if(!autocvar_hud_panel_physics && !autocvar__hud_configure)
-               return;
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_physics) return;
+               if(spectatee_status == -1 && autocvar_hud_panel_physics < 2) return;
+       }
+       else
+               hud_configure_active_panel = HUD_PANEL_PHYSICS;
 
-       active_panel = HUD_PANEL_PHYSICS;
        HUD_Panel_UpdateCvars(physics);
 
        HUD_Panel_DrawBg(1);
@@ -5151,7 +4187,7 @@ void HUD_Physics(void)
        float speed, conversion_factor;
        string unit;
 
-       switch(autocvar_cl_showspeed_unit)
+       switch(autocvar_hud_panel_physics_speed_unit)
        {
                default:
                case 1:
@@ -5186,9 +4222,8 @@ void HUD_Physics(void)
 
        //compute acceleration
        float acceleration, f;
-       float max_acceleration = autocvar_hud_panel_physics_acceleration_max;
        if (autocvar__hud_configure)
-               acceleration = max_acceleration * 0.3;
+               acceleration = autocvar_hud_panel_physics_acceleration_max * 0.3;
        else
        {
                f = time - acc_prevtime;
@@ -5205,9 +4240,6 @@ void HUD_Physics(void)
        }
 
        //compute layout
-       drawfont = hud_bigfont;
-       float baralign = autocvar_hud_panel_physics_baralign;
-       float progressbar = autocvar_hud_panel_physics_progressbar;
        float panel_ar = panel_size_x/panel_size_y;
        vector speed_offset, acceleration_offset;
        if (panel_ar >= 5)
@@ -5227,19 +4259,23 @@ void HUD_Physics(void)
                        acceleration_offset_y = panel_size_y;
        }
        float speed_baralign, acceleration_baralign;
-       if (autocvar_hud_panel_physics_flip)
+       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 = (baralign == 1 || baralign == 2);
-               speed_baralign = (baralign == 1 || baralign == 3);
+               acceleration_baralign = (autocvar_hud_panel_physics_baralign == 2);
+               speed_baralign = (autocvar_hud_panel_physics_baralign == 3);
        }
        else
        {
-               speed_baralign = (baralign == 1 || baralign == 2);
-               acceleration_baralign = (baralign == 1 || baralign == 3);
+               speed_baralign = (autocvar_hud_panel_physics_baralign == 2);
+               acceleration_baralign = (autocvar_hud_panel_physics_baralign == 3);
        }
 
        //draw speed
-       if(speed && progressbar)
+       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);
@@ -5281,31 +4317,42 @@ void HUD_Physics(void)
                        {
                                top_speed = speed;
                                top_speed_time = time;
+                f = 1;
                        }
-                       if (top_speed == 0) //hide top speed 0, it would be stupid
-                               f = 0;
-                       else
+            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
-                       if(progressbar && speed < top_speed)
+                       //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
@@ -5319,16 +4366,15 @@ void HUD_Physics(void)
        }
 
        //draw acceleration
-       if(acceleration && progressbar)
+       if(acceleration && autocvar_hud_panel_physics_progressbar)
        {
                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)/max_acceleration, 0, acceleration_baralign, progressbar_color, autocvar_hud_progressbar_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
+               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;
 }
 
 /*
@@ -5411,8 +4457,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);
@@ -5420,12 +4465,14 @@ 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);
        }
 
+    current_player = (spectatee_status > 0) ? spectatee_status : player_localentnum;
+
        // draw the dock
        if(autocvar_hud_dock != "" && autocvar_hud_dock != "0")
        {
@@ -5433,7 +4480,7 @@ void HUD_Main (void)
                vector color;
                float hud_dock_color_team = autocvar_hud_dock_color_team;
                if((teamplay) && hud_dock_color_team) {
-                       f = stof(getplayerkey(player_localentnum - 1, "colors"));
+                       f = stof(getplayerkey(current_player - 1, "colors"));
                        color = colormapPaletteColor(mod(f, 16), 1) * hud_dock_color_team;
                }
                else if(autocvar_hud_configure_teamcolorforced && autocvar__hud_configure && hud_dock_color_team) {
@@ -5443,11 +4490,11 @@ void HUD_Main (void)
                {
                        string hud_dock_color = autocvar_hud_dock_color;
                        if(hud_dock_color == "shirt") {
-                               f = stof(getplayerkey(player_localentnum - 1, "colors"));
+                               f = stof(getplayerkey(current_player - 1, "colors"));
                                color = colormapPaletteColor(floor(f / 16), 0);
                        }
                        else if(hud_dock_color == "pants") {
-                               f = stof(getplayerkey(player_localentnum - 1, "colors"));
+                               f = stof(getplayerkey(current_player - 1, "colors"));
                                color = colormapPaletteColor(mod(f, 16), 1);
                        }
                        else
@@ -5505,6 +4552,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!