]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'terencehill/minigame_spectator_list' into 'master'
authorterencehill <piuntn@gmail.com>
Sat, 23 Mar 2024 16:25:37 +0000 (16:25 +0000)
committerterencehill <piuntn@gmail.com>
Sat, 23 Mar 2024 16:25:37 +0000 (16:25 +0000)
Refactor minigame spectator list code

See merge request xonotic/xonotic-data.pk3dir!1239

1  2 
qcsrc/common/minigames/cl_minigames.qc
qcsrc/common/minigames/minigame/bd.qc
qcsrc/common/minigames/minigame/c4.qc
qcsrc/common/minigames/minigame/nmm.qc
qcsrc/common/minigames/minigame/pong.qc
qcsrc/common/minigames/minigame/pp.qc
qcsrc/common/minigames/minigame/ps.qc

index df6f77a4fa1be1d798c6960028814b22cd3640bf,68fa2ac372daafc8e94f9c58eecbc5d730ee8afa..a4241ba97b14d4349170db7229cd5700fcf29d21
@@@ -246,6 -246,51 +246,51 @@@ NET_HANDLE(ENT_CLIENT_MINIGAME, bool is
  #undef FIELD
  #undef MSLE
  
+ void minigame_show_allspecs(vector boardpos, vector boardsize)
+ {
+       string allspecs = "";
+       float allspecs_width = 0;
+       float max_allspecs_width = boardsize.x;
+       float max_current_spec_width = hud_fontsize.x * 5;
+       int allspecs_lines = 2;
+       entity e;
+       FOREACH_MINIGAME_ENTITY(e)
+       {
+               if (allspecs_width >= 0 && e.classname == "minigame_player" && e.team == C4_SPECTATOR_TEAM)
+               {
+                       string current_spec = ColorTranslateRGB(entcs_GetName(e.minigame_playerslot - 1));
+                       current_spec = textShortenToWidth(current_spec, max_current_spec_width, hud_fontsize, stringwidth_colors);
+                       if (allspecs != "")
+                               current_spec = strcat(", ", current_spec);
+                       else
+                               current_spec = current_spec;
+                       allspecs_width = stringwidth(allspecs, true, hud_fontsize);
+                       float max_width = max_allspecs_width * allspecs_lines - max_current_spec_width;
+                       if (allspecs_width + stringwidth(current_spec, true, hud_fontsize) < max_width)
+                               allspecs = strcat(allspecs, current_spec);
+                       else
+                       {
+                               // current_spec doesn't fit in the list
+                               allspecs = strcat(allspecs, ", ...");
+                               allspecs_width = -1; // skip remaining spectators
+                       }
+               }
+       }
+       if (allspecs != "")
+       {
+               vector pos = boardpos;
+               pos.y -= panel_bg_border + hud_fontsize.y * (1.25 + allspecs_lines + 0.5);
+               minigame_drawstring_wrapped(max_allspecs_width, pos, _("Spectators:"), hud_fontsize * 1.25, '0.85 0.47 0.42', panel_fg_alpha, DRAWFLAG_NORMAL, 0);
+               pos.y += hud_fontsize.y * 1.25;
+               minigame_drawcolorcodedstring_wrapped(max_allspecs_width, pos, allspecs, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL, 0);
+       }
+ }
  string minigame_getWrappedLine(float w, vector theFontSize, textLengthUpToWidth_widthFunction_t tw)
  {
        string s = getWrappedLine_remaining;
                take_until = strlen(s);
  
        int skip = 0;
 -      for ( int i = 0; i < take_until; i++ )
 +      for ( int i = 0; i < take_until; ++i )
                if ( substring(s,i,1) == "\n" )
                {
                        take_until = i;
@@@ -364,7 -409,7 +409,7 @@@ void minigame_cmd_workaround(float dumm
        string cmd;
        cmd = "cmd minigame ";
        float i;
 -      for ( i = 0; i < cmdargc; i++ )
 +      for ( i = 0; i < cmdargc; ++i )
                cmd = strcat(cmd,...(i,string));
        localcmd(strcat(cmd,"\n"));
  }
index 9c56247af4ee8c2368e7feddf9ab3e7d34f50568,c918ac9da5efd11b0661e613b4e54051ed9b9099..2150af5e896ee9b95fbca6f2f08e416d0146d804
@@@ -1114,11 -1114,13 +1114,13 @@@ void bd_hud_board(vector pos, vector my
                win_sz = minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
                        victory_text, winfs, 0, DRAWFLAG_NORMAL, 0.5);
  
 -              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'0.3 0.3 1',0.8,DRAWFLAG_ADDITIVE);
 +              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'0.3 0.3 1',0.8*panel_fg_alpha,DRAWFLAG_ADDITIVE);
  
                minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
                        victory_text, winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+       minigame_show_allspecs(bd_boardpos, bd_boardsize);
  }
  
  
@@@ -1142,9 -1144,9 +1144,9 @@@ void bd_hud_status(vector pos, vector m
        if(minigame_self.team != BD_SPECTATOR_TEAM)
        {
                mypos = pos;
 -              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
                mypos_y += player_fontsize_y;
 -              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25*panel_fg_alpha,DRAWFLAG_ADDITIVE);
        }
  
        entity e;
index 7e6407bf3d12a4b5c32f2b9cdb2b47bbdca248e8,ccf94c8d8f45d8f3ac97661bfa05c2880515aa52..bcf0d01dadbe6607d81f024f5782a98201866712
@@@ -316,12 -316,14 +316,14 @@@ void c4_hud_board(vector pos, vector my
                        sprintf(_("%s^7 won the game!"), pname),
                        winfs, 0, DRAWFLAG_NORMAL, 0.5);
  
 -              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
  
                minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
                        sprintf(_("%s^7 won the game!"), pname),
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+       minigame_show_allspecs(c4_boardpos, c4_boardsize);
  }
  
  
@@@ -347,13 -349,12 +349,12 @@@ void c4_hud_status(vector pos, vector m
                mypos = pos;
                if ( (active_minigame.minigame_flags&C4_TURN_TEAM) == 2 )
                        mypos_y  += player_fontsize_y + ts_y;
 -              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
                mypos_y += player_fontsize_y;
 -              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25*panel_fg_alpha,DRAWFLAG_ADDITIVE);
        }
  
        entity e;
-       string allspecs = "";
        FOREACH_MINIGAME_ENTITY(e)
        {
                if ( e.classname == "minigame_player" && e.team != C4_SPECTATOR_TEAM )
  
                        mypos_x += tile_size_x;
                }
-               if (e.classname == "minigame_player" && e.team == C4_SPECTATOR_TEAM)
-               {
-                       string current_spec = "";
-                       string cmpctString = entcs_GetName(e.minigame_playerslot - 1);
-                       if (strlennocol(cmpctString) > 8)
-                       {
-                               int new_length = textLengthUpToLength(cmpctString, 8, strlennocol);
-                               cmpctString = strcat(substring(cmpctString, 0, new_length), "..");
-                       }
-                       if (strlen(allspecs) > 0)
-                               current_spec = strcat(",", cmpctString);
-                       else
-                               current_spec = cmpctString;
-                       if (strlen(allspecs) < 90)
-                               allspecs = strcat(allspecs, current_spec);
-               }
-       }
-       if (strlen(allspecs) > 0)
-       {
-               pos_y = pos_y * 0.3;
-               pos_x = pos_x * 0.41;
-               ts = minigame_drawstring_wrapped(mySize_x * 1.7, pos, "Spectators: ", '14 14 0', '0.85 0.47 0.42', panel_fg_alpha, DRAWFLAG_NORMAL, 0);
-               pos_y += 14;
-               ts = minigame_drawcolorcodedstring_wrapped(mySize_x * 1.7, pos, allspecs, hud_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL, 0);
        }
  }
  
index a54df3b74db3382d467ac5cf5cfbbf78aa40126e,fbc6df231c6e3311ca8e3139401846b5c4d3627d..2d561a635224b35ee3a336cd24599e89e740e447
@@@ -101,10 -101,10 +101,10 @@@ void nmm_spawn_tile_square( entity mini
  {
        int letter = offset;
        int number = offset;
 -      for ( int i = 0; i < 3; i++ )
 +      for ( int i = 0; i < 3; ++i )
        {
                number = offset;
 -              for ( int j = 0; j < 3; j++ )
 +              for ( int j = 0; j < 3; ++j )
                {
                        if ( i != 1 || j != 1 )
                                nmm_spawn_tile(strzone(minigame_tile_buildname(letter,number)),minig, skip+1);
@@@ -175,7 -175,7 +175,7 @@@ bool nmm_tile_canmove(entity tile
  bool nmm_in_mill_string(entity tile, string s)
  {
        int argc = tokenize(s);
 -      for ( int i = 0; i < argc; i++ )
 +      for ( int i = 0; i < argc; ++i )
        {
                entity e = nmm_find_tile(tile.owner,argv(i));
                if ( !e || !e.nmm_tile_piece || e.nmm_tile_piece.team != tile.nmm_tile_piece.team )
@@@ -223,7 -223,7 +223,7 @@@ int nmm_server_event(entity minigame, s
                minigame.minigame_flags = NMM_TURN_PLACE|NMM_TURN_TEAM1;
                nmm_init_tiles(minigame);
                entity e;
 -              for ( int i = 0; i < 7; i++ )
 +              for ( int i = 0; i < 7; ++i )
                {
                        e = msle_spawn(minigame,new(minigame_board_piece));
                        e.team = 1;
@@@ -489,12 -489,14 +489,14 @@@ void nmm_hud_board(vector pos, vector m
                        sprintf(_("%s^7 won the game!"), pname),
                        winfs, 0, DRAWFLAG_NORMAL, 0.5);
  
 -              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
  
                minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
                        sprintf(_("%s^7 won the game!"), pname),
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+       minigame_show_allspecs(nmm_boardpos, nmm_boardsize);
  }
  
  // Required function, draw the game status panel
@@@ -524,9 -526,9 +526,9 @@@ void nmm_hud_status(vector pos, vector 
                mypos = pos;
                if ( (active_minigame.minigame_flags&NMM_TURN_TEAM) == 2 )
                        mypos_y  += player_fontsize_y + ts_y;
 -              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
                mypos_y += player_fontsize_y;
 -              drawfill(mypos,eX*mySize_x+eY*piece_sz_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*piece_sz_y,'1 1 1',0.25*panel_fg_alpha,DRAWFLAG_ADDITIVE);
        }
  
        FOREACH_MINIGAME_ENTITY(e)
index 17c92d8d6ad9672dc75043be01c061dbb77bd4ab,baf7cf2859575b267e515c861e896998e7458ef0..b6c0988c7d5682c9871dc60dd25c47ead69fd9e6
@@@ -162,7 -162,7 +162,7 @@@ void pong_ball_think(entity this
        this.SendFlags |= MINIG_SF_UPDATE;
  
        int i;
 -      for ( i = 1; i <= PONG_MAX_PLAYERS; i++ )
 +      for ( i = 1; i <= PONG_MAX_PLAYERS; ++i )
                if ( pong_paddle_hit(this, i) )
                {
                        pong_paddle_bounce(this,i);
@@@ -357,7 -357,7 +357,7 @@@ int pong_server_event(entity minigame, 
  
                        entity player = ...(0,entity);
                        int i;
 -                      for ( i = 0; i < PONG_MAX_PLAYERS; i++ )
 +                      for ( i = 0; i < PONG_MAX_PLAYERS; ++i )
                        {
                                if ( minigame.pong_paddles[i] == NULL )
                                {
                        entity paddle;
                        entity ai;
                        int i;
 -                      for ( i = 0; i < PONG_MAX_PLAYERS; i++ )
 +                      for ( i = 0; i < PONG_MAX_PLAYERS; ++i )
                        {
                                paddle = minigame.pong_paddles[i];
                                if ( paddle != NULL && paddle.realowner == player )
                                                minigame.SendFlags |= MINIG_SF_UPDATE;
  
                                                entity ball;
 -                                              for ( int j = 0; j < autocvar_sv_minigames_pong_ball_number; j++ )
 +                                              for ( int j = 0; j < autocvar_sv_minigames_pong_ball_number; ++j )
                                                {
                                                        ball = msle_spawn(minigame,new(pong_ball));
                                                        ball.pong_length = autocvar_sv_minigames_pong_ball_radius;
                                        // potentially compiler bug
                                        int j;
                                        if ( minigame.minigame_flags & PONG_STATUS_WAIT )
 -                                              for ( j = 0; j < PONG_MAX_PLAYERS; j++ )
 -                                              //for ( int j = 0; j < PONG_MAX_PLAYERS; j++ )
 +                                              for ( j = 0; j < PONG_MAX_PLAYERS; ++j )
 +                                              //for ( int j = 0; j < PONG_MAX_PLAYERS; ++j )
                                                {
                                                        if ( minigame.pong_paddles[j] == NULL )
                                                        {
                                        if ( minigame.minigame_flags & PONG_STATUS_WAIT )
                                        {
                                                entity paddle;
 -                                              for ( int j = PONG_MAX_PLAYERS-1; j >= 0; j-- )
 +                                              for ( int j = PONG_MAX_PLAYERS-1; j >= 0; --j )
                                                {
                                                        paddle = minigame.pong_paddles[j];
                                                        if ( paddle != NULL &&
@@@ -575,6 -575,8 +575,8 @@@ void pong_hud_board(vector pos, vector 
  
                }
        }
+       minigame_show_allspecs(pos, mySize);
  }
  
  // Required function, draw the game status panel
@@@ -601,7 -603,7 +603,7 @@@ void pong_hud_status(vector pos, vecto
                        mypos = pos;
                        mypos_y  += (e.team-1) * (player_fontsize_y + ts_y);
  
 -                      drawfill(mypos, ts, pong_team_to_color(e.team), 0.25, DRAWFLAG_ADDITIVE);
 +                      drawfill(mypos, ts, pong_team_to_color(e.team), 0.25 * panel_fg_alpha, DRAWFLAG_ADDITIVE);
  
                        minigame_drawcolorcodedstring_trunc(mySize_x,mypos,
                                (e.minigame_playerslot ? entcs_GetName(e.minigame_playerslot-1) : _("AI")),
index 4a9425f84f3446f0133276ea4d26480b49f7bf9e,6cdca1add34756f35750d0f146cf5f545496c9de..0811ba28e04bcf97bbb946d10db135dff15e9131
@@@ -368,12 -368,14 +368,14 @@@ void pp_hud_board(vector pos, vector my
                        sprintf(_("%s^7 won the game!"), pname),
                        winfs, 0, DRAWFLAG_NORMAL, 0.5);
  
 -              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
  
                minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
                        sprintf(_("%s^7 won the game!"), pname),
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+       minigame_show_allspecs(pp_boardpos, pp_boardsize);
  }
  
  
@@@ -399,9 -401,9 +401,9 @@@ void pp_hud_status(vector pos, vector m
                mypos = pos;
                if ( (active_minigame.minigame_flags&PP_TURN_TEAM) == 2 )
                        mypos_y  += player_fontsize_y + ts_y;
 -              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
                mypos_y += player_fontsize_y;
 -              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25*panel_fg_alpha,DRAWFLAG_ADDITIVE);
        }
  
        entity e;
index ff8da7e09cae8d30c65a9d1d4028c3d730af116f,b86628beb01bb56c00a231e662e82492ecdff3c4..058b935ec6c32ce4cf8e0fbf5c4fd5d4499ca21b
@@@ -425,12 -425,14 +425,14 @@@ void ps_hud_board(vector pos, vector my
                        strcat(_("Game over!"), " ", remaining_text),
                        winfs, 0, DRAWFLAG_NORMAL, 0.5);
  
 -              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(win_pos-eY*hud_fontsize_y,win_sz+2*eY*hud_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
  
                minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
                        strcat(_("Game over!"), " ", remaining_text),
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+       minigame_show_allspecs(ps_boardpos, ps_boardsize);
  }
  
  
@@@ -454,9 -456,9 +456,9 @@@ void ps_hud_status(vector pos, vector m
        if(minigame_self.team != PS_SPECTATOR_TEAM)
        {
                mypos = pos;
 -              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*player_fontsize_y,'1 1 1',0.5*panel_fg_alpha,DRAWFLAG_ADDITIVE);
                mypos_y += player_fontsize_y;
 -              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25,DRAWFLAG_ADDITIVE);
 +              drawfill(mypos,eX*mySize_x+eY*tile_size_y,'1 1 1',0.25*panel_fg_alpha,DRAWFLAG_ADDITIVE);
        }
  
        int remaining = 0;