| 753 | } |
| 754 | |
| 755 | const char* NetworkBase::FormatChat(Player* fromPlayer, const char* text) |
| 756 | { |
| 757 | static std::string formatted; |
| 758 | formatted.clear(); |
| 759 | |
| 760 | if (fromPlayer != nullptr) |
| 761 | { |
| 762 | auto& network = OpenRCT2::GetContext()->GetNetwork(); |
| 763 | auto it = network.GetGroupByID(fromPlayer->id); |
| 764 | std::string groupName = ""; |
| 765 | std::vector<std::string> colours; |
| 766 | if (it != nullptr) |
| 767 | { |
| 768 | groupName = it->getName(); |
| 769 | if (groupName[0] != '{') |
| 770 | { |
| 771 | colours.push_back("{WHITE}"); |
| 772 | } |
| 773 | } |
| 774 | |
| 775 | for (size_t i = 0; i < groupName.size(); ++i) |
| 776 | { |
| 777 | if (groupName[i] == '{') |
| 778 | { |
| 779 | std::string colour = "{"; |
| 780 | ++i; |
| 781 | while (i < groupName.size() && groupName[i] != '}' && groupName[i] != '{') |
| 782 | { |
| 783 | colour += groupName[i]; |
| 784 | ++i; |
| 785 | } |
| 786 | colour += '}'; |
| 787 | if (groupName[i] == '}' && i < groupName.size()) |
| 788 | { |
| 789 | colours.push_back(colour); |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | |
| 794 | if (colours.empty() || (colours.size() == 1 && colours[0] == "{WHITE}")) |
| 795 | { |
| 796 | formatted += "{BABYBLUE}"; |
| 797 | formatted += fromPlayer->name; |
| 798 | } |
| 799 | else |
| 800 | { |
| 801 | size_t j = 0; |
| 802 | size_t proportionalSize = fromPlayer->name.size() / colours.size(); |
| 803 | for (size_t i = 0; i < colours.size(); ++i) |
| 804 | { |
| 805 | formatted += colours[i]; |
| 806 | size_t numCharacters = proportionalSize + j; |
| 807 | for (; j < numCharacters && j < fromPlayer->name.size(); ++j) |
| 808 | { |
| 809 | formatted += fromPlayer->name[j]; |
| 810 | } |
| 811 | } |
| 812 | while (j < fromPlayer->name.size()) |
no test coverage detected