]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Show spectator list on all minigames
authorterencehill <piuntn@gmail.com>
Sat, 26 Aug 2023 22:21:39 +0000 (00:21 +0200)
committerterencehill <piuntn@gmail.com>
Sat, 26 Aug 2023 22:21:39 +0000 (00:21 +0200)
qcsrc/common/minigames/cl_minigames.qc
qcsrc/common/minigames/cl_minigames.qh
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
qcsrc/common/minigames/minigame/ttt.qc

index eaf8e0d65b7ae01c523ca23acd587fda0b311280..68fa2ac372daafc8e94f9c58eecbc5d730ee8afa 100644 (file)
@@ -246,6 +246,51 @@ NET_HANDLE(ENT_CLIENT_MINIGAME, bool isnew)
 #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;
index 5b4b8a3bd3300f37b976bce5a4102d9dfab485bb..66c3793d82fc1197573b4ccb00f55db04147df4e 100644 (file)
@@ -44,6 +44,9 @@ vector minigame_hud_denormalize_size(vector v, vector pos, vector mySize);
 // Check if the mouse is inside the given area
 bool minigame_hud_mouse_in(vector pos, vector sz);
 
+// show spectator list above the board
+void minigame_show_allspecs(vector boardpos, vector boardsize);
+
 // Like drawstring, but wrapping words to fit maxwidth
 // returns the size of the drawn area
 // align selects the string alignment (0 = left, 0.5 = center, 1 = right)
index 635d1b8d5328e7dfcdb34582f4ac887d4fa67e8b..c918ac9da5efd11b0661e613b4e54051ed9b9099 100644 (file)
@@ -1119,6 +1119,8 @@ void bd_hud_board(vector pos, vector mySize)
                minigame_drawcolorcodedstring_wrapped(mySize_x,win_pos,
                        victory_text, winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+
+       minigame_show_allspecs(bd_boardpos, bd_boardsize);
 }
 
 
index 3f9454f04c4bb429b36fa734dd0c6cca2bd73e3a..ccf94c8d8f45d8f3ac97661bfa05c2880515aa52 100644 (file)
@@ -256,12 +256,6 @@ void c4_hud_board(vector pos, vector mySize)
        c4_boardpos = pos;
        c4_boardsize = mySize;
 
-       string allspecs = "";
-       float allspecs_width = 0;
-       float max_allspecs_width = c4_boardsize.x;
-       float max_current_spec_width = hud_fontsize.x * 5;
-       float allspecs_lines = 2;
-
        minigame_hud_simpleboard(pos,mySize,minigame_texture("c4/board_under"));
 
        drawpic(pos, minigame_texture("c4/board_over"), mySize, '1 1 1', 1, 0);
@@ -305,28 +299,6 @@ void c4_hud_board(vector pos, vector mySize)
                                        minigame_texture(strcat("c4/piece",ftos(e.team))),
                                        tile_size, '1 1 1'*icon_color, panel_fg_alpha, DRAWFLAG_NORMAL );
                }
-
-               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 ( active_minigame.minigame_flags & C4_TURN_WIN )
@@ -351,15 +323,7 @@ void c4_hud_board(vector pos, vector mySize)
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
 
-       if (allspecs != "")
-       {
-               pos = c4_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);
-       }
+       minigame_show_allspecs(c4_boardpos, c4_boardsize);
 }
 
 
index ea7f3b42c76e97626100b7207f65b579a5b645c4..fbc6df231c6e3311ca8e3139401846b5c4d3627d 100644 (file)
@@ -495,6 +495,8 @@ void nmm_hud_board(vector pos, vector mySize)
                        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
index 698ccfb555a05ce2629d6a1bc4cb5b4faee357a6..baf7cf2859575b267e515c861e896998e7458ef0 100644 (file)
@@ -575,6 +575,8 @@ void pong_hud_board(vector pos, vector mySize)
 
                }
        }
+
+       minigame_show_allspecs(pos, mySize);
 }
 
 // Required function, draw the game status panel
index 9a7e54234d7bab0aa48aa57c811123fd872b400e..6cdca1add34756f35750d0f146cf5f545496c9de 100644 (file)
@@ -374,6 +374,8 @@ void pp_hud_board(vector pos, vector mySize)
                        sprintf(_("%s^7 won the game!"), pname),
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+
+       minigame_show_allspecs(pp_boardpos, pp_boardsize);
 }
 
 
index 97bdfa6124b686c4dd466a9bc3faee686d1db98e..b86628beb01bb56c00a231e662e82492ecdff3c4 100644 (file)
@@ -431,6 +431,8 @@ void ps_hud_board(vector pos, vector mySize)
                        strcat(_("Game over!"), " ", remaining_text),
                        winfs, panel_fg_alpha, DRAWFLAG_NORMAL, 0.5);
        }
+
+       minigame_show_allspecs(ps_boardpos, ps_boardsize);
 }
 
 
index a78a6468a8329cacac89ecfaf5a655cfb88f0dac..d67aa15ea772f16e3dc35522280488ab2a3f243f 100644 (file)
@@ -277,6 +277,8 @@ void ttt_hud_board(vector pos, vector mySize)
                                        tile_size, '1 1 1'*icon_color, panel_fg_alpha, DRAWFLAG_NORMAL );
                }
        }
+
+       minigame_show_allspecs(ttt_boardpos, ttt_boardsize);
 }
 
 
@@ -298,7 +300,6 @@ void ttt_hud_status(vector pos, vector mySize)
        vector tile_size = '48 48 0';
 
        entity e;
-       string allspecs = "";
        FOREACH_MINIGAME_ENTITY(e)
        {
                if ( e.classname == "minigame_player" && e.team != TTT_SPECTATOR_TEAM )
@@ -320,33 +321,6 @@ void ttt_hud_status(vector pos, vector mySize)
                        drawstring(mypos,ftos(e.minigame_flags),tile_size,
                                        '0.7 0.84 1', panel_fg_alpha, DRAWFLAG_NORMAL);
                }
-
-               if (e.classname == "minigame_player" && e.team == TTT_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);
        }
 }