]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Custom team names
authorz411 <z411@omaera.org>
Sat, 10 Oct 2020 00:28:12 +0000 (21:28 -0300)
committerz411 <z411@omaera.org>
Sat, 10 Oct 2020 00:28:12 +0000 (21:28 -0300)
qcsrc/client/hud/panel/score.qc
qcsrc/client/hud/panel/scoreboard.qc
qcsrc/client/main.qc
qcsrc/common/net_linked.qh
qcsrc/common/teams.qh
qcsrc/server/autocvars.qh
qcsrc/server/client.qc
qcsrc/server/command/sv_cmd.qc
qcsrc/server/teamplay.qc

index ece4c5e4e4a8d90479b03d540c80c1e45e1bd1be..b749a3b17e894b5134681ff0c28d3f95d886c94a 100644 (file)
@@ -127,7 +127,7 @@ void HUD_Score_Rankings(vector pos, vector mySize, entity me)
                                drawfill(pos, eX * mySize.x + eY * fontsize.y, rgb, highlight_alpha * panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
                        
-                       s = strcat(Team_ColorCode(tm.team), strtoupper(Team_ColorName(tm.team)), "^7 team");
+                       s = Team_CustomName(tm.team);
                        //s = textShortenToWidth(Team_ColorName(tm.team), name_size, fontsize, stringwidth_colors);
                        score_color = Team_ColorRGB(tm.team) * 0.8;
                        
index 7d7db3096402892acafe87f6e16b4a7bb0bb85a7..f3bb2d3d859cac6f729687383449a934ab5eb968 100644 (file)
@@ -49,6 +49,9 @@ float max_namesize;
 vector duel_score_fontsize;
 vector duel_name_fontsize;
 vector duel_score_size;
+vector team_score_fontsize;
+vector team_name_fontsize;
+vector team_score_size;
 int total_medals;
 
 float sbt_bg_alpha;
@@ -439,6 +442,10 @@ void Cmd_Scoreboard_SetFields(int argc)
        duel_score_fontsize = hud_fontsize * 3;
        duel_name_fontsize = hud_fontsize * 1.5;
        duel_score_size = vec2(duel_score_fontsize.x * 1.5, duel_score_fontsize.y * 1.25);
+       
+       team_score_fontsize = hud_fontsize * 2;
+       team_name_fontsize = hud_fontsize * 1.5;
+       team_score_size = vec2(team_score_fontsize.x * 1.5, team_score_fontsize.y * 1.25);
 
        for(i = 1; i < argc - 1; ++i)
        {
@@ -2066,8 +2073,8 @@ void Scoreboard_Draw()
                        if(!tm.team)
                                continue;
 
-                       draw_beginBoldFont();
                        vector rgb = Team_ColorRGB(tm.team);
+                       /*draw_beginBoldFont();
                        str = ftos(tm.(teamscores(ts_primary)));
                        if (autocvar_hud_panel_scoreboard_team_size_position != 1) // team size not on left
                        {
@@ -2122,6 +2129,31 @@ void Scoreboard_Draw()
                                drawstring(str_pos, str, hud_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
                        }
                        draw_endBoldFont();
+                       */
+                       
+                       // z411 My team header
+                       // Score: highlight
+                       drawfill(pos, team_score_size, rgb * 0.5, sbt_highlight_alpha, DRAWFLAG_NORMAL);
+                       
+                       // Score: text
+                       str = ftos(tm.(teamscores(ts_primary)));
+                       str_pos = pos;
+                       str_pos.x += (team_score_size.x / 2) - (stringwidth(str, true, team_score_fontsize) / 2);
+                       str_pos.y += (team_score_size.y / 2) - (team_score_fontsize.y / 2);
+                       
+                       draw_beginBoldFont();
+                       drawstring(str_pos, str, team_score_fontsize, rgb, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       draw_endBoldFont();
+                       
+                       // Team name
+                       str = Team_CustomName(tm.team);
+                       str_pos = pos;
+                       str_pos.x += team_score_size.x + team_name_fontsize.x * 0.5;
+                       str_pos.y += (team_score_size.y / 2) - (team_name_fontsize.y / 2);
+                       drawcolorcodedstring(str_pos, str, team_name_fontsize, panel_fg_alpha, DRAWFLAG_NORMAL);
+                       
+                       pos.y += team_score_size.y + (hud_fontsize.y * 0.5);
+                       
                        if(autocvar_hud_panel_scoreboard_bg_teams_color_team > 0)
                                panel_bg_color = rgb * autocvar_hud_panel_scoreboard_bg_teams_color_team;
                        else if(panel_bg_color_team > 0)
index f10cf8fcf82f9b0f0e2e950250a1742a5225bcf6..69cec830d8018730eea2c6c5adaa969aae56688d 100644 (file)
@@ -26,6 +26,7 @@
 #include <common/net_linked.qh>
 #include <common/net_notice.qh>
 #include <common/scores.qh>
+#include <common/teams.qh>
 #include <common/mapobjects/_mod.qh>
 #include <common/vehicles/all.qh>
 #include <lib/csqcmodel/cl_model.qh>
@@ -945,6 +946,16 @@ NET_HANDLE(ENT_CLIENT_INIT, bool isnew)
        if (!postinit) PostInit();
 }
 
+NET_HANDLE(TE_CSQC_TEAMNAMES, bool isNew)
+{
+       teamname_red = strzone(ReadString());
+       teamname_blue = strzone(ReadString());
+       teamname_yellow = strzone(ReadString());
+       teamname_pink = strzone(ReadString());
+
+       return = true;
+}
+
 float GetSpeedUnitFactor(int speed_unit)
 {
        switch(speed_unit)
index 6651c6cb9b75fae79d13d8a38681883c557873a1..125c01f96169bbe7d48f621e8356cbafb2b05e75 100644 (file)
@@ -7,6 +7,8 @@ REGISTER_NET_TEMP(TE_CSQC_PINGPLREPORT)
 REGISTER_NET_TEMP(TE_CSQC_WEAPONCOMPLAIN)
 REGISTER_NET_TEMP(TE_CSQC_VEHICLESETUP)
 
+REGISTER_NET_TEMP(TE_CSQC_TEAMNAMES)
+
 const int RACE_NET_CHECKPOINT_HIT_QUALIFYING = 0; // byte checkpoint, short time, short recordtime, string recordholder
 const int RACE_NET_CHECKPOINT_CLEAR = 1;
 const int RACE_NET_CHECKPOINT_NEXT_QUALIFYING = 2; // byte nextcheckpoint, short recordtime, string recordholder
index 62bb2db7cdda28a8e6e63da5cf6024e59f570a3e..9e3a8181faf6f80841c343312bcefe19cc1bffeb 100644 (file)
@@ -58,6 +58,12 @@ const string STATIC_NAME_TEAM_4 = "Pink";
 #ifdef CSQC
 bool teamplay;
 int myteam;
+
+// z411 used for custom names
+string teamname_red;
+string teamname_blue;
+string teamname_yellow;
+string teamname_pink;
 #endif
 
 string Team_ColorCode(int teamid)
@@ -86,6 +92,21 @@ vector Team_ColorRGB(int teamid)
     return '0 0 0';
 }
 
+#ifdef CSQC
+string Team_CustomName(int teamid)
+{
+       switch(teamid)
+       {
+               case NUM_TEAM_1: return ((teamname_red != "") ? teamname_red : "^1RED^7 team");
+               case NUM_TEAM_2: return ((teamname_blue != "")? teamname_blue : "^4BLUE^7 team");
+               case NUM_TEAM_3: return ((teamname_yellow != "") ? teamname_yellow : "^3YELLOW^7 team");
+               case NUM_TEAM_4: return ((teamname_pink != "") ? teamname_pink : "^6PINK^7 team");
+       }
+
+    return NAME_NEUTRAL;
+}
+#endif
+
 string Team_ColorName(int teamid)
 {
        switch(teamid)
index 87aae71e316ee81d0e4fc7795b8d470d8449e48e..438514d299c6d413fac715b278729ca90641f9a8 100644 (file)
@@ -131,6 +131,10 @@ float autocvar_sv_chat_sounds_flood; // z411
 bool autocvar_sv_jingle_end; // z411
 string autocvar_sv_jingle_end_list; // z411
 float autocvar_sv_jingle_end_volume; // z411
+string autocvar_g_teamnames_red;
+string autocvar_g_teamnames_blue;
+string autocvar_g_teamnames_yellow;
+string autocvar_g_teamnames_pink;
 
 #define autocvar_g_friendlyfire cvar("g_friendlyfire")
 #define autocvar_g_friendlyfire_virtual cvar("g_friendlyfire_virtual")
index f04023547a6c9fc2993545e7cc125b2d3135d36b..b1d77fcabe247c38d960dfb69e5aae3c0f061e72 100644 (file)
@@ -103,6 +103,17 @@ void send_CSQC_teamnagger() {
        WriteHeader(MSG_BROADCAST, TE_CSQC_TEAMNAGGER);
 }
 
+void send_TeamNames(int channel, entity to) {
+       msg_entity = to;
+       
+       LOG_INFOF("Sending team names");
+       WriteHeader(channel, TE_CSQC_TEAMNAMES);
+       WriteString(channel, autocvar_g_teamnames_red);
+       WriteString(channel, autocvar_g_teamnames_blue);
+       WriteString(channel, autocvar_g_teamnames_yellow);
+       WriteString(channel, autocvar_g_teamnames_pink);
+}
+
 int CountSpectators(entity player, entity to)
 {
        if(!player) { return 0; } // not sure how, but best to be safe
@@ -842,6 +853,10 @@ void PutClientInServer(entity this)
        } else if (IS_PLAYER(this)) {
                PutPlayerInServer(this);
        }
+       
+       // send team names
+       if(teamplay && IS_REAL_CLIENT(this))
+               send_TeamNames(MSG_ONE, this);
 }
 
 // TODO do we need all these fields, or should we stop autodetecting runtime
@@ -858,6 +873,7 @@ bool ClientInit_SendEntity(entity this, entity to, int sf)
        ClientInit_misc(this);
        MUTATOR_CALLHOOK(Ent_Init);
 }
+
 void ClientInit_misc(entity this)
 {
        int channel = MSG_ONE;
@@ -3180,7 +3196,7 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc
                                event_log_msg = sprintf(":chat_spec:%d:%s", source.playerid, strreplace("\n", " ", msgin));
                }
                else
-               {
+               {       
                        if (source) {
                                sprint(source, sourcemsgstr);
                                dedicated_print(msgstr); // send to server console too
@@ -3204,7 +3220,9 @@ int Say(entity source, int teamsay, entity privatesay, string msgin, bool floodc
 
 bool play_chatsound(entity source, string msgin)
 {
-       if(autocvar_sv_chat_sounds && CS(source).cvar_cl_chat_sounds) {
+       //bprintf("Source (%s) has cl_chat_sounds = %d\n", source.netname, CS(source).cvar_cl_chat_sounds);
+       //if(autocvar_sv_chat_sounds && CS(source).cvar_cl_chat_sounds) {
+       if(autocvar_sv_chat_sounds) {
                var .float flood_sound = floodcontrol_chatsound;
                
                if (source.(flood_sound) < time - autocvar_sv_chat_sounds_flood) {
@@ -3214,9 +3232,20 @@ bool play_chatsound(entity source, string msgin)
                        if (findinlist_abbrev(rawmsg, autocvar_sv_chat_sounds_list)) {
                                string sndname = strcat("sound/chat/", rawmsg, ".ogg");
                                
-                               FOREACH_CLIENT(IS_REAL_CLIENT(it) && CS(it).cvar_cl_chat_sounds, play2(it, sndname));
-                               source.(flood_sound) = time;
+                               /*FOREACH_CLIENT(true, {
+                                       if(IS_REAL_CLIENT(it)) {
+                                               bprintf("Destination (%s) has cl_chat_sounds = %d\n", it.netname, CS(it).cvar_cl_chat_sounds);
+                                               if(CS(it).cvar_cl_chat_sounds) {
+                                                       precache_sound(sndname);
+                                                       play2(it, sndname);
+                                               }
+                                       } else {
+                                               bprintf("Destination (%s) has cl_chat_sounds = %d but it's not a real client\n", it.netname, CS(it).cvar_cl_chat_sounds);
+                                       }
+                               });*/
+                               play2all(sndname);
                                
+                               source.(flood_sound) = time;
                                return true;
                        }
                }
index 7de740bdde1049fc7b1f8c7c8e4d797ef91df4ae..e6fad18c87e156a2dcebb45025944f2d865f4d3d 100644 (file)
@@ -160,6 +160,25 @@ void GameCommand_adminmsg(int request, int argc)
        }
 }
 
+void GameCommand_sendteams(int request)
+{
+       switch (request)
+       {
+               case CMD_REQUEST_COMMAND:
+               {
+                       send_TeamNames(MSG_BROADCAST, NULL);
+                       return;
+               }
+
+               default:
+               case CMD_REQUEST_USAGE:
+               {
+                       LOG_HELP("Usage:^3 sv_cmd sendteams");
+                       LOG_HELP("  No arguments required.");
+                       return;
+               }
+       }
+}
 void GameCommand_allready(int request)
 {
        switch (request)
@@ -922,7 +941,7 @@ void GameCommand_lockteams(int request)
                        if (teamplay)
                        {
                                lockteams = 1;
-                               bprint("^1The teams are now locked.\n");
+                               bprint("\{1}^1The teams are now locked.\n");
                        }
                        else
                        {
@@ -1538,7 +1557,7 @@ void GameCommand_unlockteams(int request)
                        if (teamplay)
                        {
                                lockteams = 0;
-                               bprint("^1The teams are now unlocked.\n");
+                               bprint("\{1}^1The teams are now unlocked.\n");
                        }
                        else
                        {
@@ -1625,6 +1644,7 @@ void GameCommand_(int request)
 
 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
 SERVER_COMMAND(adminmsg, "Send an admin message to a client directly") { GameCommand_adminmsg(request, arguments); }
+SERVER_COMMAND(sendteams, "Send team names") { GameCommand_sendteams(request); }
 SERVER_COMMAND(allready, "Restart the server and reset the players") { GameCommand_allready(request); }
 SERVER_COMMAND(allspec, "Force all players to spectate") { GameCommand_allspec(request, arguments); }
 SERVER_COMMAND(anticheat, "Create an anticheat report for a client") { GameCommand_anticheat(request, arguments); }
index 1c436da9691b0d555225ef9453286dfab73b9212..1d42ad7bbb246540dca2b1b1a99cca7b70308cf1 100644 (file)
@@ -35,6 +35,7 @@ const int TEAM_NOT_ALLOWED = -1;
 .int m_team_balance_state; ///< Holds the state of the team balance entity.
 .entity m_team_balance_team[NUM_TEAMS]; ///< ???
 
+.string m_team_name; // z411 team name
 .float m_team_score; ///< The score of the team.
 .int m_num_players; ///< Number of players (both humans and bots) in a team.
 .int m_num_bots; ///< Number of bots in a team.
@@ -74,6 +75,16 @@ entity Team_GetTeam(int team_num)
        return g_team_entities[Team_TeamToIndex(team_num) - 1];
 }
 
+string Team_GetTeamName(entity team_ent)
+{
+       return team_ent.m_team_name;
+}
+
+void Team_SetTeamName(entity team_ent, string name)
+{
+       team_ent.m_team_name = name;
+}
+
 float Team_GetTeamScore(entity team_ent)
 {
        return team_ent.m_team_score;