]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud.qc
Merge branch 'master' into Mario/buffs
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud.qc
index 503075e52ad908521fd1cd244bdf29340965ef9c..e1c95025892e272c556f33edbc86275df630a21a 100644 (file)
@@ -1604,6 +1604,7 @@ void HUD_Notify_Push(string icon, string attacker, string victim)
        if (icon == "")
                return;
 
+       ++notify_count;
        --notify_index;
 
        if (notify_index == -1)
@@ -1612,8 +1613,10 @@ void HUD_Notify_Push(string icon, string attacker, string victim)
        // Free old strings
        if (notify_attackers[notify_index])
                strunzone(notify_attackers[notify_index]);
+
        if (notify_victims[notify_index])
                strunzone(notify_victims[notify_index]);
+
        if (notify_icons[notify_index])
                strunzone(notify_icons[notify_index]);
 
@@ -1645,6 +1648,10 @@ void HUD_Notify(void)
        HUD_Panel_UpdateCvars();
        HUD_Panel_DrawBg(1);
 
+       if (!autocvar__hud_configure)
+               if (notify_count == 0)
+                       return;
+
        vector pos, size;
        pos  = panel_pos;
        size = panel_size;
@@ -1655,25 +1662,26 @@ void HUD_Notify(void)
                size -= '2 2 0' * panel_bg_padding;
        }
 
-       float entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size_y / size_x), NOTIFY_MAX_ENTRIES);
-       float entry_height = size_y / entry_count;
-
        float fade_start = max(0, autocvar_hud_panel_notify_time);
        float fade_time = max(0, autocvar_hud_panel_notify_fadetime);
+       float icon_aspect = max(1, autocvar_hud_panel_notify_icon_aspect);
+
+       float entry_count = bound(1, floor(NOTIFY_MAX_ENTRIES * size_y / size_x), NOTIFY_MAX_ENTRIES);
+       float entry_height = size_y / entry_count;
 
        float panel_width_half = size_x * 0.5;
-       float icon_width_half = entry_height * NOTIFY_ICON_ASPECT / 2;
+       float icon_width_half = entry_height * icon_aspect / 2;
        float name_maxwidth = panel_width_half - icon_width_half - size_x * NOTIFY_ICON_MARGIN;
 
        vector font_size = '0.5 0.5 0' * entry_height * autocvar_hud_panel_notify_fontsize;
-       vector icon_size = (eX * NOTIFY_ICON_ASPECT + eY) * entry_height;
+       vector icon_size = (eX * icon_aspect + eY) * entry_height;
        vector icon_left = eX * (panel_width_half - icon_width_half);
        vector attacker_right = eX * name_maxwidth;
        vector victim_left = eX * (size_x - name_maxwidth);
 
        vector attacker_pos, victim_pos, icon_pos;
        string attacker, victim, icon;
-       float i, j, step, limit, alpha;
+       float i, j, count, step, limit, alpha;
 
        if (autocvar_hud_panel_notify_flip)
        {
@@ -1690,19 +1698,14 @@ void HUD_Notify(void)
                limit = -1;
        }
 
-       for (j = notify_index; i != limit; i += step, ++j)
+       for (j = notify_index, count = 0; i != limit; i += step, ++j, ++count)
        {
                if(autocvar__hud_configure)
                {
-                       if (step == +1)
-                               alpha = i;
-                       else // inverse order
-                               alpha = entry_count - 1 - i;
-
-                       attacker = textShortenToWidth(sprintf(_("Player %d"), alpha+1), 0.48 * size_x - entry_height, font_size, stringwidth_colors);
-                       victim = textShortenToWidth(sprintf(_("Player %d"), alpha+2), 0.48 * size_x - entry_height, font_size, stringwidth_colors);
-                       icon = strcat("weapon", get_weaponinfo(WEP_FIRST + mod(floor(alpha*2.4), WEP_LAST)).netname);
-                       alpha = bound(0, (fade_start - alpha) / 4, 1);
+                       attacker = sprintf(_("Player %d"), count + 1);
+                       victim = sprintf(_("Player %d"), count + 2);
+                       icon = strcat("weapon", get_weaponinfo(min(WEP_FIRST + count * 2, WEP_LAST)).netname);
+                       alpha = bound(0, 1.2 - count / entry_count, 1);
                }
                else
                {
@@ -1744,6 +1747,8 @@ void HUD_Notify(void)
                        }
                }
        }
+
+       notify_count = count;
 }
 
 // Timer (#5)
@@ -4367,6 +4372,66 @@ void HUD_CenterPrint (void)
        }
 }
 
+// Buffs (#18)
+//
+void HUD_Buffs(void)
+{
+       float buffs = getstati(STAT_BUFFS, 0, 24);
+       if(!autocvar__hud_configure)
+       {
+               if(!autocvar_hud_panel_buffs) return;
+               if(spectatee_status == -1) return;
+               if(getstati(STAT_HEALTH) <= 0) return;
+               if(!buffs) return;
+       }
+       else
+       {
+               buffs = Buff_Type_first.items; // force first buff
+       }
+       
+       float b = 0; // counter to tell other functions that we have buffs
+       entity e;
+       string s = "";
+       for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
+       {
+               ++b;
+               string o = strcat(rgb_to_hexcolor(Buff_Color(e.items)), Buff_PrettyName(e.items));
+               if(s == "")
+                       s = o;
+               else
+                       s = strcat(s, " ", o);
+       }
+
+       HUD_Panel_UpdateCvars();
+
+       draw_beginBoldFont();
+
+       vector pos, mySize;
+       pos = panel_pos;
+       mySize = panel_size;
+
+       HUD_Panel_DrawBg(bound(0, b, 1));
+       if(panel_bg_padding)
+       {
+               pos += '1 1 0' * panel_bg_padding;
+               mySize -= '2 2 0' * panel_bg_padding;
+       }
+
+       //float panel_ar = mySize_x/mySize_y;
+       //float is_vertical = (panel_ar < 1);
+       //float buff_iconalign = autocvar_hud_panel_buffs_iconalign;
+       vector buff_offset = '0 0 0';
+       
+       for(e = Buff_Type_first; e; e = e.enemy) if(buffs & e.items)
+       {
+               //DrawNumIcon(pos + buff_offset, mySize, shield, "shield", is_vertical, buff_iconalign, '1 1 1', 1);
+               drawcolorcodedstring_aspect(pos + buff_offset, s, mySize, panel_fg_alpha * 0.5, DRAWFLAG_NORMAL);
+       }
+
+       draw_endBoldFont();
+}
+
+
 /*
 ==================
 Main HUD system