]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/hud/panel/spect.qc
Showing Spectating label in spectator HUD
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / hud / panel / spect.qc
index 92eff46dbab99d7fd15a1abe7b832a8e59ccf7f9..2c153b9250fff1e87a583690b09629aa7f0e8e0c 100644 (file)
@@ -1,6 +1,5 @@
 #include "spect.qh"
 
-#include <client/autocvars.qh>
 #include <client/hud/hud.qh>
 #include <client/view.qh>
 
@@ -15,11 +14,18 @@ void HUD_SpectHUD_Export(int fh)
 
 void HUD_SpectHUD_drawCurrentName(vector pos)
 {
-       if(!current_player) return;
+       vector tmp;
        
+       tmp = pos;
        string s = entcs_GetName(current_player);
-       pos.x -= stringwidth_colors(s, hud_fontsize * 2) / 2;
-       drawcolorcodedstring(pos, s, hud_fontsize * 2, panel_fg_alpha, DRAWFLAG_NORMAL);
+       tmp.x -= stringwidth_colors(s, hud_fontsize * 2) / 2;
+       drawcolorcodedstring(tmp, s, hud_fontsize * 2, panel_fg_alpha, DRAWFLAG_NORMAL);
+       
+       tmp = pos;
+       s = "Spectating";
+       tmp.x -= stringwidth_colors(s, hud_fontsize) / 2;
+       tmp.y -= hud_fontsize.y;
+       drawcolorcodedstring(tmp, s, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
 }
        
 void HUD_SpectHUD_drawTeamPlayers(vector pos, entity tm, vector rgb, bool invert)
@@ -27,8 +33,8 @@ void HUD_SpectHUD_drawTeamPlayers(vector pos, entity tm, vector rgb, bool invert
        vector tmp_over;
        vector line_sz = vec2((vid_conwidth - 1) / 7, hud_fontsize.y * 1.5);
        vector line_sz_sub = vec2((vid_conwidth - 1) / 7, hud_fontsize.y);
-       vector total_sz = vec2(line_sz.x, line_sz.y + line_sz_sub.y);
-       string tmp_str;
+       
+       string playername;
        float a = panel_fg_alpha * 0.8;
        entity pl;
        
@@ -44,33 +50,77 @@ void HUD_SpectHUD_drawTeamPlayers(vector pos, entity tm, vector rgb, bool invert
                
                float health = 0;
                float armor = 0;
+               string icon = "";
+               vector icon_size = '0 0 0';
+               vector icon_rgb = '1 1 1';
                
+               // Position and size calculation vectors
                tmp_over = pos;
-               tmp_str = textShortenToWidth(entcs_GetName(pl.sv_entnum), line_sz.x * 0.8, hud_fontsize, stringwidth_colors);
+               vector total_sz = vec2(line_sz.x, line_sz.y + line_sz_sub.y);
+               
+               if(pl.eliminated) {
+                       // z411 TODO : Unhardcode luma
+                       icon = "gfx/hud/luma/notify_death.tga";
+                       icon_rgb = rgb;
+               } else {
+                       entity entcs = entcs_receiver(pl.sv_entnum);
+                       if(entcs.m_entcs_private) {
+                               health = (entcs.healthvalue / autocvar_hud_panel_healtharmor_maxhealth) * line_sz.x;
+                               armor = (GetResource(entcs, RES_ARMOR) / autocvar_hud_panel_healtharmor_maxarmor) * line_sz_sub.x;
+                                       
+                               Weapon wep = REGISTRY_GET(Weapons, entcs.activewepid);
+                               icon = strcat("gfx/hud/luma/", wep.model2);
+                       } else {
+                               if(tm.team == NUM_TEAM_1)
+                                       icon = "gfx/hud/luma/player_red";
+                               else if(tm.team == NUM_TEAM_2)
+                                       icon = "gfx/hud/luma/player_blue";
+                               else if(tm.team == NUM_TEAM_3)
+                                       icon = "gfx/hud/luma/player_yellow";
+                               else if(tm.team == NUM_TEAM_4)
+                                       icon = "gfx/hud/luma/player_pink";
+                               else
+                                       icon = "gfx/hud/luma/player_neutral";
+                       }
+               }
                
-               entity entcs = entcs_receiver(pl.sv_entnum);
-               if(entcs.m_entcs_private) {
-                       health = (entcs.healthvalue / autocvar_hud_panel_healtharmor_maxhealth) * line_sz.x;
-                       armor = (GetResource(entcs, RES_ARMOR) / autocvar_hud_panel_healtharmor_maxarmor) * line_sz_sub.x;
+               // Draw weapon
+               if(icon != "")  {
+                       vector tmp_sz = draw_getimagesize(icon);
+                       icon_size = vec2(total_sz.y*(tmp_sz.x/tmp_sz.y), total_sz.y);
+                       total_sz.x += icon_size.x;
+                               
+                       if(invert) {
+                               pos.x -= icon_size.x;
+                               tmp_over.x -= icon_size.x;
+                       }
+                       drawpic(pos, icon, icon_size, icon_rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       pos.x += icon_size.x;
                }
                
+               // Get player's name
+               playername = textShortenToWidth(entcs_GetName(pl.sv_entnum), line_sz.x * 0.8, hud_fontsize, stringwidth_colors);
+               
                // Draw health and name
                drawfill(pos, line_sz, rgb * 0.7, a * 0.3, DRAWFLAG_NORMAL);
                if(health)
                        drawfill(pos, vec2(health, line_sz.y), rgb * 0.7, a, DRAWFLAG_NORMAL);
-               drawcolorcodedstring(pos + eY * ((line_sz.y - hud_fontsize.y) / 2) + eX * (hud_fontsize.x * 0.5), tmp_str, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+               drawcolorcodedstring(pos + eY * ((line_sz.y - hud_fontsize.y) / 2) + eX * (hud_fontsize.x * 0.5), playername, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
                pos.y += line_sz.y;
                
                // Draw armor
                if(armor)
                        drawfill(pos, vec2(armor, line_sz_sub.y), rgb, a, DRAWFLAG_NORMAL);
-               pos.y += line_sz_sub.y * 2;
                
                // Highlight current player
-               if(pl.sv_entnum == current_player)
+               if(pl.sv_entnum == current_player && spectatee_status != -1)
                        drawfill(tmp_over, total_sz, '1 1 1', 0.3, DRAWFLAG_NORMAL);
                if(pl.eliminated)
-                       drawfill(tmp_over, total_sz, '0 0 0', 0.3, DRAWFLAG_NORMAL);
+                       drawfill(tmp_over, total_sz, '0 0 0', 0.4, DRAWFLAG_NORMAL);
+               
+               if(!invert)
+                       pos.x -= icon_size.x;
+               pos.y += line_sz_sub.y * 2;
        }
 }
 
@@ -111,6 +161,90 @@ void HUD_SpectHUD_drawTeamScore(vector pos, entity tm, vector rgb, bool invert)
        drawcolorcodedstring(tmp, tmp_str, teamname_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
 }
 
+void HUD_SpectHUD_drawDuelScore(vector pos, entity pl, bool invert)
+{
+       if(!pl) return;
+       
+       vector tmp, tmp_in;
+       string tmp_str;
+       vector health_sz = vec2((vid_conwidth - 1) / 6, teamscore_size.y * 0.4);
+       vector armor_sz = vec2(health_sz.x, health_sz.y / 4);
+       
+       float health = 0;
+       float armor = 0;
+       
+       entity entcs = entcs_receiver(pl.sv_entnum);
+       if(entcs.m_entcs_private) {
+               health = (entcs.healthvalue / autocvar_hud_panel_healtharmor_maxhealth) * health_sz.x;
+               armor = (GetResource(entcs, RES_ARMOR) / autocvar_hud_panel_healtharmor_maxarmor) * armor_sz.x;
+       }
+       
+       // Player score
+       tmp_str = ftos(pl.(scores(ps_primary)));
+       
+       if(invert)
+               pos.x -= teamscore_size.x;
+       
+       drawfill(pos, teamscore_size, '0 0 0', 0.3, DRAWFLAG_NORMAL);
+       
+       tmp = pos;
+       tmp.x += (teamscore_size.x - stringwidth(tmp_str, true, teamscore_fontsize)) / 2;
+       tmp.y += (teamscore_size.y - teamscore_fontsize.y) / 2;
+               
+       draw_beginBoldFont();
+       drawstring(tmp, tmp_str, teamscore_fontsize, '1 1 1', panel_fg_alpha, DRAWFLAG_NORMAL);
+       draw_endBoldFont();
+       
+       // Player health/armor
+       tmp_in = pos;
+       tmp_in.y += ((teamscore_size.y / 2) - health_sz.y) / 2;
+       
+       // Background
+       tmp = tmp_in;
+       if(invert)
+               tmp.x -= health_sz.x;
+       else
+               tmp.x += teamscore_size.x;
+       
+       drawfill(tmp, health_sz, '0 0 0', 0.3, DRAWFLAG_NORMAL);
+       
+       // Bars
+       if(health) {
+               tmp = tmp_in;
+               if(invert)
+                       tmp.x -= health;
+               else
+                       tmp.x += teamscore_size.x;
+       
+               drawfill(tmp, vec2(health, health_sz.y), '1 0 0', 0.7, DRAWFLAG_NORMAL);
+       }
+       
+       if(armor) {
+               tmp = tmp_in;
+               tmp.y += health_sz.y - armor_sz.y;
+               
+               if(invert)
+                       tmp.x -= armor;
+               else
+                       tmp.x += teamscore_size.x;
+               
+               drawfill(tmp, vec2(armor, armor_sz.y), '0 1 0', 0.7, DRAWFLAG_NORMAL);
+       }
+       
+       // Player name
+       tmp_str = entcs_GetName(pl.sv_entnum);
+       
+       tmp = pos;
+       if(invert)
+               tmp.x -= stringwidth_colors(tmp_str, teamname_fontsize) + teamname_fontsize.x * 0.5;
+       else
+               tmp.x += teamscore_size.x + teamname_fontsize.x * 0.5;
+       tmp.y += ((teamscore_size.y / 2) - teamname_fontsize.y) / 2;
+       tmp.y += teamscore_size.y / 2;
+       
+       drawcolorcodedstring(tmp, tmp_str, teamname_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+}
+
 void HUD_SpectHUD()
 {
        if(!spectatee_status) return;
@@ -125,35 +259,80 @@ void HUD_SpectHUD()
        hud_fontsize = HUD_GetFontsize("hud_fontsize");
        
        // Spectator name
-       ammo_y = stov(cvar_string("hud_panel_ammo_pos")).y * vid_conheight;
-       pos = panel_pos + vec2((vid_conwidth - 1) / 2, (ammo_y - (hud_fontsize.y * 2)));
-       HUD_SpectHUD_drawCurrentName(pos);
-       
-       if(!teamplay) return;
-       
-       // Set vars
-       teamscore_fontsize = hud_fontsize * 3;
-       teamname_fontsize = hud_fontsize * 2;
-       teamscore_size = vec2(teamscore_fontsize.x * 1.5, teamscore_fontsize.y * 1.25);
-       timer_width = stov(cvar_string("hud_panel_timer_size")).x * vid_conwidth;
-       
-       // Team 1
-       pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
-       tm = GetTeam(NUM_TEAM_1, false);
-       rgb = Team_ColorRGB(tm.team);
-       pos.x -= (timer_width * 1.3) / 2;
-       HUD_SpectHUD_drawTeamScore(pos, tm, rgb, true);
-       
-       pos = panel_pos + vec2(0, (vid_conheight - 1) / 4 + hud_fontsize.y);
-       HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, false);
-       
-       // Team 2
-       pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
-       tm = GetTeam(NUM_TEAM_2, false);
-       rgb = Team_ColorRGB(tm.team);
-       pos.x += (timer_width * 1.3) / 2;
-       HUD_SpectHUD_drawTeamScore(pos, tm, rgb, false);
-       
-       pos = panel_pos + vec2(vid_conwidth - 1, (vid_conheight - 1) / 4 + hud_fontsize.y);
-       HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, true);
+       if (autocvar_hud_spectatorplayernamedisplay)
+       {
+               if(spectatee_status != -1) {
+                       ammo_y = stov(cvar_string("hud_panel_ammo_pos")).y * vid_conheight;
+                       pos = panel_pos + vec2((vid_conwidth - 1) / 2, (ammo_y - (hud_fontsize.y * 2)));
+                       HUD_SpectHUD_drawCurrentName(pos);
+               }
+       }
+       
+       if (teamplay && autocvar_hud_spectatorteamdisplay)
+       {
+               // Set vars
+               teamscore_fontsize = hud_fontsize * 3;
+               teamname_fontsize = hud_fontsize * 2;
+               teamscore_size = vec2(teamscore_fontsize.x * 1.5, teamscore_fontsize.y * 1.25);
+               timer_width = stov(cvar_string("hud_panel_timer_size")).x * vid_conwidth;
+               
+               // Team 1
+               pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
+               tm = GetTeam(NUM_TEAM_1, false);
+               rgb = Team_ColorRGB(tm.team);
+               pos.x -= (timer_width * 1.3) / 2;
+               HUD_SpectHUD_drawTeamScore(pos, tm, rgb, true);
+               
+               pos = panel_pos + vec2(0, (vid_conheight - 1) / 4 + hud_fontsize.y);
+               HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, false);
+               
+               // Team 2
+               pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
+               tm = GetTeam(NUM_TEAM_2, false);
+               rgb = Team_ColorRGB(tm.team);
+               pos.x += (timer_width * 1.3) / 2;
+               HUD_SpectHUD_drawTeamScore(pos, tm, rgb, false);
+               
+               pos = panel_pos + vec2(vid_conwidth - 1, (vid_conheight - 1) / 4 + hud_fontsize.y);
+               HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, true);
+
+               // Team 3
+               pos = panel_pos + vec2((vid_conwidth - 1) / 2, 41);
+               tm = GetTeam(NUM_TEAM_3, false);
+               rgb = Team_ColorRGB(tm.team);
+               pos.x -= (timer_width * 1.3) / 2;
+               HUD_SpectHUD_drawTeamScore(pos, tm, rgb, true);
+               
+               pos = panel_pos + vec2(0, (vid_conheight + 450) / 4 + hud_fontsize.y);
+               HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, false);
+
+               // Team 4
+               pos = panel_pos + vec2((vid_conwidth - 1) / 2, 41);
+               tm = GetTeam(NUM_TEAM_4, false);
+               rgb = Team_ColorRGB(tm.team);
+               pos.x += (timer_width * 1.3) / 2;
+               HUD_SpectHUD_drawTeamScore(pos, tm, rgb, false);
+               
+               pos = panel_pos + vec2(vid_conwidth - 1, (vid_conheight + 450) / 4 + hud_fontsize.y);
+               HUD_SpectHUD_drawTeamPlayers(pos, tm, rgb, true);
+       } else if(gametype == MAPINFO_TYPE_DUEL && autocvar_hud_spectatordueldisplay) {
+               // Set vars
+               teamscore_fontsize = hud_fontsize * 3;
+               teamname_fontsize = hud_fontsize * 1.5;
+               teamscore_size = vec2(teamscore_fontsize.x * 1.5, teamscore_fontsize.y * 1.25);
+               timer_width = stov(cvar_string("hud_panel_timer_size")).x * vid_conwidth;
+               
+               entity pl_left = players.sort_next;
+               entity pl_right = pl_left.sort_next;
+       
+               // Left player
+               pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
+               pos.x -= (timer_width * 1.3) / 2;
+               HUD_SpectHUD_drawDuelScore(pos, pl_left, true);
+               
+               // Right player
+               pos = panel_pos + vec2((vid_conwidth - 1) / 2, 0);
+               pos.x += (timer_width * 1.3) / 2;
+               HUD_SpectHUD_drawDuelScore(pos, pl_right, false);
+       }
 }