fix crappy string cutoff

This commit is contained in:
DrPerkyLegit 2026-04-16 01:18:43 -04:00
parent 2586001d1d
commit abb96b44cf

View file

@ -1437,6 +1437,37 @@ void Gui::clearMessages(int iPad)
} }
} }
int getVisibleMessageLength(const wstring& _string) {
int visibleMessageLength = 0;
bool inHtmlTag = false;
for (wchar_t _char : _string) {
if (_char == L'<') inHtmlTag = true;
if (_char == L'>') inHtmlTag = false;
if (!inHtmlTag) visibleMessageLength++;
}
return visibleMessageLength;
}
int getVisibleIndexToRaw(const wstring& _string, size_t target) {
int visibleMessageLength = 0;
bool inHtmlTag = false;
for (size_t i = 0; i < _string.size(); i++) {
if (_string[i] == L'<') inHtmlTag = true;
if (_string[i] == L'>') inHtmlTag = false;
if (!inHtmlTag) {
if (visibleMessageLength == target) return i;
visibleMessageLength++;
}
}
return _string.size();
}
void Gui::addMessage(const wstring& _string,int iPad,bool bIsDeathMessage) void Gui::addMessage(const wstring& _string,int iPad,bool bIsDeathMessage)
{ {
@ -1517,15 +1548,11 @@ void Gui::addMessage(const wstring& _string,int iPad,bool bIsDeathMessage)
break; break;
} }
while (getVisibleMessageLength(string) > maximumChars)
while (string.length() > maximumChars)
{ {
unsigned int i = 1; size_t cutOffset = getVisibleIndexToRaw(string, maximumChars);
while (i < string.length() && (i + 1) <= maximumChars)
{ size_t iLast=string.find_last_of(L" ", cutOffset);
i++;
}
size_t iLast=string.find_last_of(L" ",i);
switch(XGetLanguage()) switch(XGetLanguage())
{ {
case XC_LANGUAGE_JAPANESE: case XC_LANGUAGE_JAPANESE:
@ -1534,7 +1561,7 @@ void Gui::addMessage(const wstring& _string,int iPad,bool bIsDeathMessage)
iLast = maximumChars; iLast = maximumChars;
break; break;
default: default:
iLast=string.find_last_of(L" ",i); iLast=string.find_last_of(L" ", cutOffset);
break; break;
} }