From: z411 Date: Sat, 10 Oct 2020 00:28:12 +0000 (-0300) Subject: Custom team names X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=41862e18f597b917e1890c3ff1b7821454ef720c;p=xonotic%2Fxonotic-data.pk3dir.git Custom team names --- diff --git a/qcsrc/client/hud/panel/score.qc b/qcsrc/client/hud/panel/score.qc index ece4c5e4e..b749a3b17 100644 --- a/qcsrc/client/hud/panel/score.qc +++ b/qcsrc/client/hud/panel/score.qc @@ -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; diff --git a/qcsrc/client/hud/panel/scoreboard.qc b/qcsrc/client/hud/panel/scoreboard.qc index 7d7db3096..f3bb2d3d8 100644 --- a/qcsrc/client/hud/panel/scoreboard.qc +++ b/qcsrc/client/hud/panel/scoreboard.qc @@ -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) diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index f10cf8fcf..69cec830d 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -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) diff --git a/qcsrc/common/net_linked.qh b/qcsrc/common/net_linked.qh index 6651c6cb9..125c01f96 100644 --- a/qcsrc/common/net_linked.qh +++ b/qcsrc/common/net_linked.qh @@ -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 diff --git a/qcsrc/common/teams.qh b/qcsrc/common/teams.qh index 62bb2db7c..9e3a8181f 100644 --- a/qcsrc/common/teams.qh +++ b/qcsrc/common/teams.qh @@ -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) diff --git a/qcsrc/server/autocvars.qh b/qcsrc/server/autocvars.qh index 87aae71e3..438514d29 100644 --- a/qcsrc/server/autocvars.qh +++ b/qcsrc/server/autocvars.qh @@ -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") diff --git a/qcsrc/server/client.qc b/qcsrc/server/client.qc index f04023547..b1d77fcab 100644 --- a/qcsrc/server/client.qc +++ b/qcsrc/server/client.qc @@ -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; } } diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index 7de740bdd..e6fad18c8 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -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); } diff --git a/qcsrc/server/teamplay.qc b/qcsrc/server/teamplay.qc index 1c436da96..1d42ad7bb 100644 --- a/qcsrc/server/teamplay.qc +++ b/qcsrc/server/teamplay.qc @@ -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;