summaryrefslogtreecommitdiff
path: root/mm/2s2h/CustomMessage/CustomMessage.cpp
diff options
context:
space:
mode:
authorArchez <Archez@users.noreply.github.com>2025-01-15 09:57:20 -0500
committerGitHub <noreply@github.com>2025-01-15 08:57:20 -0600
commit81eef9928ea7b12091e95880642127a79b14cf08 (patch)
tree26d687a18ca0581e903985e5d33a5f83f7b64870 /mm/2s2h/CustomMessage/CustomMessage.cpp
parent4625dc0d899ed078c0cbc282a27e8ce675b2d497 (diff)
Fix custom message formatting and gossip stone hint text (#175)
Diffstat (limited to 'mm/2s2h/CustomMessage/CustomMessage.cpp')
-rw-r--r--mm/2s2h/CustomMessage/CustomMessage.cpp19
1 files changed, 13 insertions, 6 deletions
diff --git a/mm/2s2h/CustomMessage/CustomMessage.cpp b/mm/2s2h/CustomMessage/CustomMessage.cpp
index a94d4a739..b3fcd19e8 100644
--- a/mm/2s2h/CustomMessage/CustomMessage.cpp
+++ b/mm/2s2h/CustomMessage/CustomMessage.cpp
@@ -51,10 +51,17 @@ void CustomMessage::AddLineBreaks(std::string* msg) {
for (size_t i = 0; i < msg->size(); ++i) {
char currentChar = (*msg)[i];
- if (currentChar >= 0x20 && currentChar < 0x20 + sizeof(sNESFontWidths) / sizeof(sNESFontWidths[0])) {
+ if ((uint8_t)currentChar >= 0x20 && (uint8_t)currentChar < 0x20 + ARRAY_COUNTU(sNESFontWidths)) {
currentLineWidth += sNESFontWidths[currentChar - 0x20];
}
+ // Increment for existing new liens
+ if (currentChar == 0x11) {
+ currentLineWidth = 0.0f;
+ lastSpaceIndex = std::string::npos;
+ ++currentLineCount;
+ }
+
if (currentChar == ' ') {
lastSpaceIndex = i;
}
@@ -71,8 +78,8 @@ void CustomMessage::AddLineBreaks(std::string* msg) {
++currentLineCount;
if (currentLineCount >= MAX_LINES_PER_PAGE) {
- msg->insert(i + 1, 1, 0x10);
- ++i;
+ // Replace the added new line for a box break instead
+ (*msg)[i] = 0x10;
currentLineCount = 0;
}
}
@@ -81,7 +88,7 @@ void CustomMessage::AddLineBreaks(std::string* msg) {
// Ensure that the message ends with the message end character
void CustomMessage::EnsureMessageEnd(std::string* msg) {
- if (msg->back() != 0xBF) {
+ if ((unsigned char)msg->back() != 0xBF) {
msg->push_back(0xBF);
}
}
@@ -129,10 +136,10 @@ void CustomMessage::LoadCustomMessageIntoFont(CustomMessage::Entry entry) {
buff[10] = 0xFF;
if (entry.autoFormat) {
- CustomMessage::AddLineBreaks(&entry.msg);
CustomMessage::ReplaceColorChars(&entry.msg);
- CustomMessage::EnsureMessageEnd(&entry.msg);
CustomMessage::Replace(&entry.msg, "\n", "\x11");
+ CustomMessage::AddLineBreaks(&entry.msg);
+ CustomMessage::EnsureMessageEnd(&entry.msg);
}
// If message is too long, truncate it and add the message end character