]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Implemented spectator HUD
authorz411 <z411@omaera.org>
Tue, 3 Nov 2020 01:25:53 +0000 (22:25 -0300)
committerz411 <z411@omaera.org>
Tue, 3 Nov 2020 01:25:53 +0000 (22:25 -0300)
qcsrc/client/hud/hud.qh
qcsrc/client/hud/panel/_mod.inc
qcsrc/client/hud/panel/_mod.qh
qcsrc/client/hud/panel/infomessages.qc
qcsrc/client/hud/panel/modicons.qc
qcsrc/client/hud/panel/score.qc
qcsrc/client/hud/panel/spect.qc [new file with mode: 0644]
qcsrc/client/hud/panel/spect.qh [new file with mode: 0644]
qcsrc/client/hud/panel/weapons.qc

index 47e39f6ba3fb0b0bc2324029f1543ee7fb34eba6..7f38072ced945d63b9bfdc760ff885d2efb4b032 100644 (file)
@@ -255,6 +255,7 @@ REGISTER_HUD_PANEL(ITEMSTIME,       HUD_ItemsTime,      PANEL_CONFIG_MAIN | PANE
 REGISTER_HUD_PANEL(QUICKMENU,       HUD_QuickMenu,      PANEL_CONFIG_MAIN                        , PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME                                          ) // QUICKMENU
 REGISTER_HUD_PANEL(SCOREBOARD,      Scoreboard_Draw,    PANEL_CONFIG_NO                          , PANEL_SHOW_MAINGAME | PANEL_SHOW_MINIGAME | PANEL_SHOW_MAPVOTE | PANEL_SHOW_WITH_SB) // SCOREBOARD
 REGISTER_HUD_PANEL(STRAFEHUD,       HUD_StrafeHUD,      PANEL_CONFIG_MAIN | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME                                                                ) // STRAFEHUD
+REGISTER_HUD_PANEL(SPECTHUD,        HUD_SpectHUD,       PANEL_CONFIG_NO | PANEL_CONFIG_CANBEOFF, PANEL_SHOW_MAINGAME) // SPECTHUD
 // always add new panels to the end of list
 
 // Because calling lots of functions in QC apparently cuts fps in half on many machines:
index 68e368ed13cb0c9dad0227073710fe0f885c7c57..33a01443b6969d3def17f899544ba5abb731bab1 100644 (file)
@@ -15,6 +15,7 @@
 #include <client/hud/panel/racetimer.qc>
 #include <client/hud/panel/radar.qc>
 #include <client/hud/panel/score.qc>
+#include <client/hud/panel/spect.qc>
 #include <client/hud/panel/scoreboard.qc>
 #include <client/hud/panel/strafehud.qc>
 #include <client/hud/panel/timer.qc>
index 1b45f0cd042a5be7fa4b42483c1e08039c04f636..657fb4ab82c3c6f26f8b50206a2f248a89e1fa38 100644 (file)
@@ -15,6 +15,7 @@
 #include <client/hud/panel/racetimer.qh>
 #include <client/hud/panel/radar.qh>
 #include <client/hud/panel/score.qh>
+#include <client/hud/panel/spect.qh>
 #include <client/hud/panel/scoreboard.qh>
 #include <client/hud/panel/strafehud.qh>
 #include <client/hud/panel/timer.qh>
index 54f128a5c8d7bbf2730ec1ea22f5e4c23aab840f..7590ce5d4b93fea4f5d7ae8e26e68fd003d277bb 100644 (file)
@@ -89,11 +89,11 @@ void HUD_InfoMessages()
        {
                if(spectatee_status)
                {
-                       if(spectatee_status == -1)
+                       /*if(spectatee_status == -1)
                                s = _("^1Observing");
                        else
                                s = sprintf(_("^1Spectating: ^7%s"), entcs_GetName(current_player));
-                       InfoMessage(s);
+                       InfoMessage(s);*/
 
                        if(autocvar_hud_panel_infomessages_group0)
                        {
index e488e31ac38540b301cc93258eee3ad89451ceaf..ff8f5bf654c96187571f1db3a6c6eb643ecfafe9 100644 (file)
@@ -31,7 +31,9 @@ void HUD_ModIcons()
                if(!autocvar_hud_panel_modicons) return;
                if(!HUD_ModIcons_GameType) return;
        }
-
+       
+       if(spectatee_status && teamplay) return; // z411
+       
        if(mod_active || autocvar__hud_configure)
                mod_alpha = min(mod_alpha + frametime * 2, 1);
        else
index 72767fcdc686f5d1083cee6523aedeef907e476f..2ce8e3c737a064913b055f4702d08c184ca220d4 100644 (file)
@@ -15,7 +15,7 @@ void HUD_Score_Export(int fh)
 }
 
 void HUD_Score_Rankings(vector pos, vector mySize, entity me)
-{
+{      
        float score;
        entity tm = NULL, pl;
        int SCOREPANEL_MAX_ENTRIES = 6;
@@ -78,9 +78,6 @@ void HUD_Score_Rankings(vector pos, vector mySize, entity me)
                return;
        }
        
-       if (!scoreboard_fade_alpha) // the scoreboard too calls Scoreboard_UpdatePlayerTeams
-               Scoreboard_UpdatePlayerTeams();
-               
        /*
        if (team_count)
        {
@@ -131,7 +128,11 @@ void HUD_Score_Rankings(vector pos, vector mySize, entity me)
                        score_color = Team_ColorRGB(tm.team) * 0.8;
                        
                        drawcolorcodedstring(pos + eX * (name_size - stringwidth(s, true, fontsize)), s, fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       
+                       draw_beginBoldFont();
                        drawstring(pos + eX * (name_size + spacing_size), ftos(tm.(teamscores(ts_primary))), fontsize, score_color, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       draw_endBoldFont();
+                       
                        pos.y += fontsize.y;
                        ++i;
                }
@@ -198,6 +199,11 @@ void HUD_Score()
                if(!autocvar_hud_panel_score) return;
                if(MUTATOR_CALLHOOK(HUD_Score_show)) return;
        }
+       
+       if (!scoreboard_fade_alpha) // the scoreboard too calls Scoreboard_UpdatePlayerTeams
+               Scoreboard_UpdatePlayerTeams();
+       
+       if(spectatee_status) return;
 
        HUD_Panel_LoadCvars();
        vector pos, mySize;
diff --git a/qcsrc/client/hud/panel/spect.qc b/qcsrc/client/hud/panel/spect.qc
new file mode 100644 (file)
index 0000000..7990706
--- /dev/null
@@ -0,0 +1,157 @@
+#include "spect.qh"
+
+#include <client/autocvars.qh>
+#include <client/hud/hud.qh>
+#include <client/view.qh>
+
+vector teamscore_size;
+vector teamscore_fontsize;
+vector teamname_fontsize;
+
+void HUD_SpectHUD_Export(int fh)
+{
+       // allow saving cvars that aesthetically change the panel into hud skin files
+}
+
+void HUD_SpectHUD_drawCurrentName(vector pos)
+{
+       if(!current_player) return;
+       
+       string s = entcs_GetName(current_player);
+       pos.x -= stringwidth(s, false, hud_fontsize * 2) / 2;
+       drawcolorcodedstring(pos, s, hud_fontsize * 2, panel_fg_alpha, DRAWFLAG_NORMAL);
+}
+       
+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;
+       float a = panel_fg_alpha * 0.8;
+       entity pl;
+       
+       if(invert)
+               pos.x -= line_sz.x + hud_fontsize.x;
+       else
+               pos.x += hud_fontsize.x;        
+       
+       for(pl = players.sort_next; pl; pl = pl.sort_next)
+       {
+               if(pl.team != tm.team)
+                       continue;
+               
+               float health = 0;
+               float armor = 0;
+               
+               tmp_over = pos;
+               tmp_str = textShortenToWidth(entcs_GetName(pl.sv_entnum), line_sz.x * 0.8, hud_fontsize, stringwidth_colors);
+               
+               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 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);
+               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)
+                       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);
+       }
+}
+
+
+void HUD_SpectHUD_drawTeamScore(vector pos, entity tm, vector rgb, bool invert)
+{
+       if(!tm) return;
+       
+       vector tmp;
+       string tmp_str;
+       
+       // Team score
+       tmp_str = ftos(tm.(teamscores(ts_primary)));
+       
+       if(invert)
+               pos.x -= teamscore_size.x;
+       
+       drawfill(pos, teamscore_size, rgb * 0.8, 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, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
+       draw_endBoldFont();
+       
+       // Team name
+       tmp_str = Team_CustomName(tm.team);
+       
+       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 - teamname_fontsize.y) / 2;
+       
+       drawcolorcodedstring(tmp, tmp_str, teamname_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+}
+
+void HUD_SpectHUD()
+{
+       if(!spectatee_status || !teamplay) return;
+       
+       vector pos, rgb;
+       float ammo_y, timer_width;
+       entity tm;
+       
+       // Set main vars
+       HUD_Panel_LoadCvars();
+       HUD_Scale_Enable();
+       
+       hud_fontsize = HUD_GetFontsize("hud_fontsize");
+       teamscore_fontsize = hud_fontsize * 3;
+       teamname_fontsize = hud_fontsize * 2;
+       
+       teamscore_size = vec2(teamscore_fontsize.x * 1.5, teamscore_fontsize.y * 1.25);
+       ammo_y = stov(cvar_string("hud_panel_ammo_pos")).y * vid_conheight;
+       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);
+       
+       // Spectator name
+       pos = panel_pos + vec2((vid_conwidth - 1) / 2, (ammo_y - (hud_fontsize.y * 2)));
+       HUD_SpectHUD_drawCurrentName(pos);
+}
diff --git a/qcsrc/client/hud/panel/spect.qh b/qcsrc/client/hud/panel/spect.qh
new file mode 100644 (file)
index 0000000..6db88c6
--- /dev/null
@@ -0,0 +1,2 @@
+#pragma once
+#include "../panel.qh"
index 57414291b238f6431d4570b834409ad3b726778d..014905ec834a67b510cde141598fd703423598ee 100644 (file)
@@ -119,6 +119,8 @@ string cl_weaponpriority_old;
 bool weapons_orderbyimpulse_old;
 void HUD_Weapons()
 {
+       if(spectatee_status && teamplay) return; // z411
+       
        // declarations
        WepSet weapons_stat = WepSet_GetFromStat();
        int i;