From a61a6001f1ff872dd6d2ae7f0fe60e216f6c8961 Mon Sep 17 00:00:00 2001 From: flowtron Date: Fri, 13 Aug 2021 13:21:04 +0200 Subject: [PATCH] spectator improved (also issue #259) --- source/src/clientgame.cpp | 7 +++---- source/src/renderhud.cpp | 25 +++++++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index 819cc1a4..b468a79f 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -1745,11 +1745,10 @@ void setfollowplayer(int cn) } COMMANDF(setfollowplayer, "i", (int *cn) { setfollowplayer(*cn); }); -// the spectate mode SM_OVERVIEW is like a radar hack and therefore is only allowed under certain conditions +// SM_OVERVIEW shows all players and their activity - could be used unfairly, possible TODO: allow restricting access by server config and votes bool smoverviewflyforbidden() { - bool notmatchnotprivate = servstate.mastermode != MM_MATCH && servstate.mastermode != MM_PRIVATE; - return ((player1->team != TEAM_SPECT || notmatchnotprivate) && !watchingdemo); + return (player1->team != TEAM_SPECT && !watchingdemo); } // set new spect mode @@ -1804,7 +1803,7 @@ void togglespect() // cycle through all spectating modes { int mode; if(player1->spectatemode==SM_NONE) mode = SM_FOLLOW1ST; // start with 1st person spect - else mode = SM_FOLLOW1ST + ((player1->spectatemode - SM_FOLLOW1ST + 1) % ((smoverviewflyforbidden() ? SM_FLY : SM_OVERVIEW)-SM_FOLLOW1ST)); // replace SM_OVERVIEW by SM_NUM to enable overview mode + else mode = SM_FOLLOW1ST + ((player1->spectatemode - SM_FOLLOW1ST + 1) % ((smoverviewflyforbidden() ? SM_FLY : SM_NUM/*SM_OVERVIEW*/)-SM_FOLLOW1ST)); // replace SM_OVERVIEW by SM_NUM to enable overview mode spectatemode(mode); } } diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index cad09ed5..5a4f59e0 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -740,6 +740,11 @@ VAR(blankouthud, 0, 0, 10000); //for "clean" screenshot string gtime; int dimeditinfopanel = 255; +const char *ghoststrings[] = +{ + "none", "deathcam", "chase 1st", "chase 3rd [O]", "chase 3rd [A]", "fly", "overview", "" +}; + void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater, int elapsed) { if(blankouthud > 0) { blankouthud -= elapsed; return; } @@ -811,7 +816,7 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(p->state==CS_ALIVE && !hidehudequipment) drawequipicons(p); - if(!hideradar || showmap) drawradar(p, w, h); + if((!hideradar || showmap) && !(player1->spectatemode>=SM_FLY)) drawradar(p, w, h); if(!editmode) { glMatrixMode(GL_MODELVIEW); @@ -1016,16 +1021,28 @@ void gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwat if(!hidespecthud && spectating && player1->spectatemode!=SM_DEATHCAM) { glLoadIdentity(); - glOrtho(0, VIRTW, VIRTH, 0, -1, 1); + glOrtho(0, VIRTW*2, VIRTH*2, 0, -1, 1); + int virtposx = (VIRTW*2)/40; + int virtposy = (VIRTH*2)/10; const char *specttext = "GHOST"; if(player1->team == TEAM_SPECT) specttext = "GHOST"; else if(player1->team == TEAM_CLA_SPECT) specttext = "[CLA]"; else if(player1->team == TEAM_RVSF_SPECT) specttext = "[RVSF]"; - draw_text(specttext, VIRTW/40, VIRTH/10*7); + draw_text(specttext, virtposx, virtposy*7); + + extern bool smoverviewflyforbidden(); + int lastvalid = smoverviewflyforbidden() ? SM_FLY : SM_OVERVIEW; + int smprev = player1->spectatemode > SM_FOLLOW1ST ? (player1->spectatemode - 1) : lastvalid; + int smnext = player1->spectatemode < lastvalid ? (player1->spectatemode + 1) : SM_FOLLOW1ST; + int gtoffx = 250; // static offset /hoping/ to be longer than the longest(!font?) specttext + draw_textf("\fZ%s", virtposx + gtoffx, virtposy*7 - FONTH, ghoststrings[smprev]); + draw_textf("\fY%s", virtposx + gtoffx, virtposy*7, ghoststrings[player1->spectatemode]); + draw_textf("\fZ%s", virtposx + gtoffx, virtposy*7 + FONTH, ghoststrings[smnext]); + if(is_spect) { defformatstring(name)("Player %s", colorname(players[player1->followplayercn])); - draw_text(name, VIRTW/40, VIRTH/10*8); + draw_text(name, virtposx, virtposy*8); } }