Network messages will now show usernames instead of just numbers

Gives more useful feedback as it's not obvious which node belongs to who.

Added line breaks to network messages for cases where a large amount of players are desynced.
This commit is contained in:
Boondorl 2024-04-29 07:43:14 -04:00 committed by Ricardo Luís Vaz Silva
parent 4c191f4bf5
commit 3d6e508d67
4 changed files with 51 additions and 47 deletions

View file

@ -1233,76 +1233,63 @@ void DBaseStatusBar::DrawTopStuff (EHudState state)
void DBaseStatusBar::DrawConsistancy () const void DBaseStatusBar::DrawConsistancy () const
{ {
static bool firsttime = true;
int i;
char conbuff[64], *buff_p;
if (!netgame) if (!netgame)
return; return;
buff_p = NULL; bool desync = false;
for (i = 0; i < MAXPLAYERS; i++) FString text = "Out of sync with:";
for (int i = 0; i < MAXPLAYERS; i++)
{ {
if (playeringame[i] && players[i].inconsistant) if (playeringame[i] && players[i].inconsistant)
{ {
if (buff_p == NULL) desync = true;
{ text.AppendFormat(" %s (%d)", players[i].userinfo.GetName(10u), i + 1);
strcpy (conbuff, "Out of sync with:");
buff_p = conbuff + 17;
}
*buff_p++ = ' ';
*buff_p++ = '1' + i;
*buff_p = 0;
} }
} }
if (buff_p != NULL) if (desync)
{ {
if (firsttime) auto lines = V_BreakLines(SmallFont, twod->GetWidth() / CleanXfac - 40, text.GetChars());
const int height = SmallFont->GetHeight() * CleanYfac;
double y = 0.0;
for (auto& line : lines)
{ {
firsttime = false;
if (debugfile)
{
fprintf (debugfile, "%s as of tic %d (%d)\n", conbuff,
players[1-consoleplayer].inconsistant,
players[1-consoleplayer].inconsistant/ticdup);
}
}
DrawText(twod, SmallFont, CR_GREEN, DrawText(twod, SmallFont, CR_GREEN,
(twod->GetWidth() - SmallFont->StringWidth (conbuff)*CleanXfac) / 2, (twod->GetWidth() - SmallFont->StringWidth(line.Text) * CleanXfac) * 0.5,
0, conbuff, DTA_CleanNoMove, true, TAG_DONE); y, line.Text.GetChars(), DTA_CleanNoMove, true, TAG_DONE);
y += height;
}
} }
} }
void DBaseStatusBar::DrawWaiting () const void DBaseStatusBar::DrawWaiting () const
{ {
int i;
char conbuff[64], *buff_p;
if (!netgame) if (!netgame)
return; return;
buff_p = NULL; FString text = "Waiting for:";
for (i = 0; i < MAXPLAYERS; i++) bool isWaiting = false;
for (int i = 0; i < MAXPLAYERS; i++)
{ {
if (playeringame[i] && players[i].waiting) if (playeringame[i] && players[i].waiting)
{ {
if (buff_p == NULL) isWaiting = true;
{ text.AppendFormat(" %s (%d)", players[i].userinfo.GetName(10u), i + 1);
strcpy (conbuff, "Waiting for:");
buff_p = conbuff + 12;
}
*buff_p++ = ' ';
*buff_p++ = '1' + i;
*buff_p = 0;
} }
} }
if (buff_p != NULL) if (isWaiting)
{
auto lines = V_BreakLines(SmallFont, twod->GetWidth() / CleanXfac - 40, text.GetChars());
const int height = SmallFont->GetHeight() * CleanYfac;
double y = 0.0;
for (auto& line : lines)
{ {
DrawText(twod, SmallFont, CR_ORANGE, DrawText(twod, SmallFont, CR_ORANGE,
(twod->GetWidth() - SmallFont->StringWidth (conbuff)*CleanXfac) / 2, (twod->GetWidth() - SmallFont->StringWidth(line.Text) * CleanXfac) * 0.5,
SmallFont->GetHeight()*CleanYfac, conbuff, DTA_CleanNoMove, true, TAG_DONE); y, line.Text.GetChars(), DTA_CleanNoMove, true, TAG_DONE);
y += height;
}
} }
} }

View file

@ -204,9 +204,25 @@ struct userinfo_t : TMap<FName,FBaseCVar *>
{ {
return *static_cast<FFloatCVar *>(*CheckKey(NAME_Autoaim)); return *static_cast<FFloatCVar *>(*CheckKey(NAME_Autoaim));
} }
const char *GetName() const const char *GetName(unsigned int charLimit = 0u) const
{ {
return *static_cast<FStringCVar *>(*CheckKey(NAME_Name)); const char* name = *static_cast<FStringCVar*>(*CheckKey(NAME_Name));
if (charLimit)
{
FString temp = name;
if (temp.CharacterCount() > charLimit)
{
int next = 0;
for (unsigned int i = 0u; i < charLimit; ++i)
temp.GetNextCharacter(next);
temp.Truncate(next);
temp += "...";
name = temp.GetChars();
}
}
return name;
} }
int GetTeam() const int GetTeam() const
{ {

View file

@ -727,7 +727,8 @@ DEFINE_ACTION_FUNCTION(_PlayerInfo, Resurrect)
DEFINE_ACTION_FUNCTION(_PlayerInfo, GetUserName) DEFINE_ACTION_FUNCTION(_PlayerInfo, GetUserName)
{ {
PARAM_SELF_STRUCT_PROLOGUE(player_t); PARAM_SELF_STRUCT_PROLOGUE(player_t);
ACTION_RETURN_STRING(self->userinfo.GetName()); PARAM_UINT(charLimit);
ACTION_RETURN_STRING(self->userinfo.GetName(charLimit));
} }
DEFINE_ACTION_FUNCTION(_PlayerInfo, GetNeverSwitch) DEFINE_ACTION_FUNCTION(_PlayerInfo, GetNeverSwitch)

View file

@ -2861,7 +2861,7 @@ struct PlayerInfo native play // self is what internally is known as player_t
native void SetSubtitleNumber (int text, Sound sound_id = 0); native void SetSubtitleNumber (int text, Sound sound_id = 0);
native bool Resurrect(); native bool Resurrect();
native clearscope String GetUserName() const; native clearscope String GetUserName(uint charLimit = 0u) const;
native clearscope Color GetColor() const; native clearscope Color GetColor() const;
native clearscope Color GetDisplayColor() const; native clearscope Color GetDisplayColor() const;
native clearscope int GetColorSet() const; native clearscope int GetColorSet() const;