]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Make weapons panel automatically disappear
authorterencehill <piuntn@gmail.com>
Sun, 1 Aug 2010 20:24:09 +0000 (22:24 +0200)
committerterencehill <piuntn@gmail.com>
Sun, 1 Aug 2010 20:24:09 +0000 (22:24 +0200)
hud_panel_weapons_timeout "10" "panel disappears if you don't switch weapon for this amount of seconds"
hud_panel_weapons_timeout_effect "1" "disappearance effect: 0) no effect; 1) panel moves out of screen; 2) panel fades out"

Note: I had to use panel_pos and panel_size instead of pos and mySize to make properly work HUD_Panel_DrawBg(1);. Actually, it's even a good thing as pos and mySize aren't really needed... (like in every other panel, btw).

defaultXonotic.cfg
qcsrc/client/hud.qc

index 2e5b56cd14fccfd30703d33850cd912f2858c744..2f7dc51dd0fb72293fd2b611feaef387e445daeb 100644 (file)
@@ -1353,6 +1353,8 @@ seta hud_panel_weapons_ammo_full_nails 200 "show 100% of the status bar at this
 seta hud_panel_weapons_ammo_full_cells 80 "show 100% of the status bar at this ammo count"
 seta hud_panel_weapons_ammo_full_rockets 80 "show 100% of the status bar at this ammo count"
 seta hud_panel_weapons_ammo_full_fuel 100 "show 100% of the status bar at this ammo count"
+seta hud_panel_weapons_timeout "10" "panel disappears if you don't switch weapon for this amount of seconds"
+seta hud_panel_weapons_timeout_effect "1" "disappearance effect: 0) no effect; 1) panel moves out of screen; 2) panel fades out"
 
 seta hud_panel_notify_time 10 "time that a new entry stays until it fades out"
 seta hud_panel_notify_fadetime 3 "fade out time"
index be7169dba40659f8d7b4d23b824a3cc1333a5bcd..fd49022c36c2524e00bfbc67c911b637e325d8ee 100644 (file)
@@ -1484,14 +1484,52 @@ void HUD_Weapons(void)
        if(!autocvar_hud_panel_weapons && !autocvar__hud_configure)
                return;
 
+       float timeout = cvar("hud_panel_weapons_timeout");
+       float timeout_effect_lenght;
+       if (cvar("hud_panel_weapons_timeout_effect") == 0)
+               timeout_effect_lenght = 0;
+       else
+               timeout_effect_lenght = 0.75;
+
+       if (timeout && time >= weapontime + timeout + timeout_effect_lenght && !autocvar__hud_configure)
+               return;
+
        active_panel = HUD_PANEL_WEAPONS;
        HUD_Panel_UpdateCvars(weapons);
-       vector pos, mySize;
-       float i, weapid, fade, weapon_stats, weapon_number, weapon_cnt;
 
-       pos = panel_pos;
-       mySize = panel_size;
+       if (timeout && time >= weapontime + timeout && !autocvar__hud_configure)
+       {
+               float f = (time - (weapontime + timeout)) / timeout_effect_lenght;
+               if (cvar("hud_panel_weapons_timeout_effect") == 2)
+               {
+                       panel_bg_alpha *= (1 - f);
+                       panel_fg_alpha *= (1 - f);
+               }
+               else
+               {
+                       f *= f; // for a cooler movement
+                       vector center;
+                       center_x = panel_pos_x + panel_size_x/2;
+                       center_y = panel_pos_y + panel_size_y/2;
+                       float screen_ar = vid_conwidth/vid_conheight;
+                       if (center_x/center_y < screen_ar) //bottom left
+                       {
+                               if ((vid_conwidth - center_x)/center_y < screen_ar) //bottom
+                                       panel_pos_y += f * (vid_conheight - panel_pos_y);
+                               else //left
+                                       panel_pos_x -= f * (panel_pos_x + panel_size_x);
+                       }
+                       else //top right
+                       {
+                               if ((vid_conwidth - center_x)/center_y < screen_ar) //right
+                                       panel_pos_x += f * (vid_conwidth - panel_pos_x);
+                               else //top
+                                       panel_pos_y -= f * (panel_pos_y + panel_size_y);
+                       }
+               }
+       }
 
+       float i, weapid, fade, weapon_stats, weapon_number, weapon_cnt;
        weapon_cnt = 0;
        for(i = WEP_FIRST; i <= WEP_LAST; ++i)
        {
@@ -1524,8 +1562,8 @@ void HUD_Weapons(void)
        HUD_Panel_DrawBg(1);
        if(panel_bg_padding)
        {
-               pos += '1 1 0' * panel_bg_padding;
-               mySize -= '2 2 0' * panel_bg_padding;
+               panel_pos += '1 1 0' * panel_bg_padding;
+               panel_size -= '2 2 0' * panel_bg_padding;
        }
 
        // hits
@@ -1548,7 +1586,7 @@ void HUD_Weapons(void)
        HUD_Weapons_Clear();
 
        float rows, columns;
-       rows = mySize_y/mySize_x;
+       rows = panel_size_y/panel_size_x;
        rows = bound(1, floor((sqrt(4 * autocvar_hud_panel_weapons_aspect * rows * WEP_COUNT + rows * rows) + rows + 0.5) / 2), WEP_COUNT);
 
        columns = ceil(WEP_COUNT/rows);
@@ -1566,8 +1604,8 @@ void HUD_Weapons(void)
 
        for(i = 0; i < weapon_cnt; ++i)
        {
-               wpnpos = pos + eX * column * mySize_x*(1/columns) + eY * row * mySize_y*(1/rows);
-               wpnsize = eX * mySize_x*(1/columns) + eY * mySize_y*(1/rows);
+               wpnpos = panel_pos + eX * column * panel_size_x*(1/columns) + eY * row * panel_size_y*(1/rows);
+               wpnsize = eX * panel_size_x*(1/columns) + eY * panel_size_y*(1/rows);
 
                self = weaponorder[i];
                weapid = self.impulse;
@@ -1609,9 +1647,9 @@ void HUD_Weapons(void)
                        drawpic_aspect_skin(wpnpos, strcat("weapon", self.netname), wpnsize, '1 1 1', fade * panel_fg_alpha, DRAWFLAG_NORMAL);
 
                        if(autocvar_hud_panel_weapons_label == 1) // weapon number
-                               drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+                               drawstring(wpnpos, ftos(weapid), '1 1 0' * 0.5 * panel_size_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
                        else if(autocvar_hud_panel_weapons_label == 2) // bind
-                               drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * mySize_y*(1/rows), '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+                               drawstring(wpnpos, getcommandkey(ftos(weapid), strcat("impulse ", ftos(weapid))), '1 1 0' * 0.5 * panel_size_y*(1/rows), '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)