mirror of https://github.com/OpenRCT2/OpenRCT2.git
Close #11512: Add coloured usernames in multiplayer servers by group
Co-authored-by: mbilik <mbilik@umich.edu> Co-authored-by: Matt <matthewsings5@gmail.com>
This commit is contained in:
parent
b05dcb3dfe
commit
1f761faee0
|
@ -1,5 +1,6 @@
|
|||
0.4.11 (in development)
|
||||
------------------------------------------------------------------------
|
||||
- Feature: [#11512] Coloured usernames by group on multiplayer servers.
|
||||
- Feature: [#21734] Park admittance price can now be set via text input.
|
||||
- Improved: [#21769] Expose “animation is backwards” wall property in Tile Inspector.
|
||||
- Change: [#21715] [Plugin] Remove access to the internal `owner` property. Note: `ownership` is still accessible.
|
||||
|
|
|
@ -711,15 +711,70 @@ int32_t NetworkBase::GetNumVisiblePlayers() const noexcept
|
|||
return static_cast<int32_t>(player_list.size());
|
||||
}
|
||||
|
||||
const char* NetworkBase::FormatChat(NetworkPlayer* fromplayer, const char* text)
|
||||
const char* NetworkBase::FormatChat(NetworkPlayer* fromPlayer, const char* text)
|
||||
{
|
||||
static std::string formatted;
|
||||
formatted.clear();
|
||||
formatted += "{OUTLINE}";
|
||||
if (fromplayer != nullptr)
|
||||
|
||||
if (fromPlayer != nullptr)
|
||||
{
|
||||
formatted += "{BABYBLUE}";
|
||||
formatted += fromplayer->Name;
|
||||
auto& network = OpenRCT2::GetContext()->GetNetwork();
|
||||
auto it = network.GetGroupByID(fromPlayer->Id);
|
||||
std::string groupName = "";
|
||||
std::vector<std::string> colours;
|
||||
if (it != nullptr)
|
||||
{
|
||||
groupName = it->GetName();
|
||||
if (groupName[0] != '{')
|
||||
{
|
||||
colours.push_back("{WHITE}");
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < groupName.size(); ++i)
|
||||
{
|
||||
if (groupName[i] == '{')
|
||||
{
|
||||
std::string colour = "{";
|
||||
++i;
|
||||
while (i < groupName.size() && groupName[i] != '}' && groupName[i] != '{')
|
||||
{
|
||||
colour += groupName[i];
|
||||
++i;
|
||||
}
|
||||
colour += '}';
|
||||
if (groupName[i] == '}' && i < groupName.size())
|
||||
{
|
||||
colours.push_back(colour);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (colours.size() == 0 || (colours.size() == 1 && colours[0] == "{WHITE}"))
|
||||
{
|
||||
formatted += "{BABYBLUE}";
|
||||
formatted += fromPlayer->Name;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t j = 0;
|
||||
size_t proportionalSize = fromPlayer->Name.size() / colours.size();
|
||||
for (size_t i = 0; i < colours.size(); ++i)
|
||||
{
|
||||
formatted += colours[i];
|
||||
size_t numCharacters = proportionalSize + j;
|
||||
for (; j < numCharacters && j < fromPlayer->Name.size(); ++j)
|
||||
{
|
||||
formatted += fromPlayer->Name[j];
|
||||
}
|
||||
}
|
||||
while (j < fromPlayer->Name.size())
|
||||
{
|
||||
formatted += fromPlayer->Name[j];
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
formatted += ": ";
|
||||
}
|
||||
formatted += "{WHITE}";
|
||||
|
|
Loading…
Reference in New Issue