From 631924f3e0e9a34e99ac7aa94231adb0b86efdf6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 19 Aug 2020 21:35:31 -0700 Subject: [PATCH 1/3] UI: Split chat lines using Unicode. --- UI/ChatScreen.cpp | 71 +++++++++++++++++++++++++---------------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index aa5478befe..9f498d8c8f 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -1,18 +1,16 @@ +#include #include "ppsspp_config.h" +#include "i18n/i18n.h" #include "ui/root.h" #include "ui/ui_context.h" #include "ui/view.h" #include "ui/viewgroup.h" #include "ui/ui.h" -#include "ChatScreen.h" -#include "Core/Config.h" -#include "Core/Host.h" -#include "Core/System.h" -#include "Common/LogManager.h" -#include "Core/HLE/proAdhoc.h" -#include "i18n/i18n.h" -#include #include "util/text/utf8.h" +#include "Core/Config.h" +#include "Core/System.h" +#include "Core/HLE/proAdhoc.h" +#include "UI/ChatScreen.h" void ChatMenu::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; @@ -167,29 +165,43 @@ UI::EventReturn ChatMenu::OnQuickChat5(UI::EventParams &e) { */ std::vector Split(const std::string& str) { - std::vector ret; - int counter = 0; - int firstSentenceEnd = 0; - int secondSentenceEnd = 0; - int spliton = 45; + static const int spliton = 45; - for (int i = 0; i<(int)str.length(); i++) { - if (isspace(str[i])) { - if (i < spliton) { - if(str[i-1]!=':') - firstSentenceEnd = i+1; + int firstSentenceEnd = 0; + int splitCharStart = 0; + + uint32_t lastc = -1; + int i = 0; + if ((int)str.length() > spliton) { + for (UTF8 utf(str.c_str()); utf.byteIndex() < (int)str.length(); ++i) { + uint32_t c = utf.next(); + if (isspace(c)) { + if (i < spliton) { + if (lastc != ':') + firstSentenceEnd = utf.byteIndex(); + } else if (i > spliton) { + firstSentenceEnd = splitCharStart; + } } - else if (i > spliton) { - firstSentenceEnd = spliton; + if (i == spliton) { + splitCharStart = utf.byteIndex(); } + lastc = c; } } if (firstSentenceEnd == 0) { - firstSentenceEnd = spliton; + if (i <= spliton) { + firstSentenceEnd = (int)str.length(); + } else { + firstSentenceEnd = splitCharStart; + } } + + std::vector ret; ret.push_back(str.substr(0, firstSentenceEnd)); - ret.push_back(str.substr(firstSentenceEnd)); + if (firstSentenceEnd < (int)str.length()) + ret.push_back(str.substr(firstSentenceEnd)); return ret; } @@ -219,17 +231,10 @@ void ChatMenu::UpdateChat() { LinearLayout *line = chatVert_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT))); TextView *nameView = line->Add(new TextView(displayname, FLAG_DYNAMIC_ASCII, true)); nameView->SetTextColor(0xFF000000 | namecolor); - if (chattext.length() > 45) { - std::vector splitted = Split(chattext); - std::string one = splitted[0]; - std::string two = splitted[1]; - TextView *oneview = line->Add(new TextView(one, FLAG_DYNAMIC_ASCII, true)); - oneview->SetTextColor(0xFF000000 | textcolor); - TextView *twoview = chatVert_->Add(new TextView(two, FLAG_DYNAMIC_ASCII, true)); - twoview->SetTextColor(0xFF000000 | textcolor); - } - else { - TextView *chatView = line->Add(new TextView(chattext, FLAG_DYNAMIC_ASCII, true)); + + std::vector splitMessage = Split(chattext); + for (const std::string &msg : splitMessage) { + TextView *chatView = line->Add(new TextView(msg, FLAG_DYNAMIC_ASCII, true)); chatView->SetTextColor(0xFF000000 | textcolor); } } From aa14fef19d5ac484045178721f26a8141294eb92 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 19 Aug 2020 21:38:11 -0700 Subject: [PATCH 2/3] UI: Allow text to use native fonts. Yes, it changes, but we want to show characters outside our atlas. It's not just ASCII. --- UI/ChatScreen.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 9f498d8c8f..215d69dae1 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -225,16 +225,16 @@ void ChatMenu::UpdateChat() { } if (i.length() <= displayname.length() || i[displayname.length()] != ':') { - TextView *v = chatVert_->Add(new TextView(i, FLAG_DYNAMIC_ASCII, true)); + TextView *v = chatVert_->Add(new TextView(i, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); v->SetTextColor(0xFF000000 | infocolor); } else { LinearLayout *line = chatVert_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT))); - TextView *nameView = line->Add(new TextView(displayname, FLAG_DYNAMIC_ASCII, true)); + TextView *nameView = line->Add(new TextView(displayname, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); nameView->SetTextColor(0xFF000000 | namecolor); std::vector splitMessage = Split(chattext); for (const std::string &msg : splitMessage) { - TextView *chatView = line->Add(new TextView(msg, FLAG_DYNAMIC_ASCII, true)); + TextView *chatView = line->Add(new TextView(msg, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); chatView->SetTextColor(0xFF000000 | textcolor); } } From 3c5d82d30e863ccca5dff553850fb6be8f12128e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Wed, 19 Aug 2020 21:58:11 -0700 Subject: [PATCH 3/3] UI: Use standard text wrapping for chat messages. This way they will actually wrap in a width-aware way, regardless of screen size. They should also better take into account non-Unicode. --- UI/ChatScreen.cpp | 59 ++++------------------------------------------- 1 file changed, 4 insertions(+), 55 deletions(-) diff --git a/UI/ChatScreen.cpp b/UI/ChatScreen.cpp index 215d69dae1..5430945518 100644 --- a/UI/ChatScreen.cpp +++ b/UI/ChatScreen.cpp @@ -157,61 +157,12 @@ UI::EventReturn ChatMenu::OnQuickChat5(UI::EventParams &e) { return UI::EVENT_DONE; } -/* - maximum chat length in one message from server is only 64 character - need to split the chat to fit the static chat screen size - if the chat screen size become dynamic from device resolution - we need to change split function logic also. -*/ -std::vector Split(const std::string& str) -{ - static const int spliton = 45; - - int firstSentenceEnd = 0; - int splitCharStart = 0; - - uint32_t lastc = -1; - int i = 0; - if ((int)str.length() > spliton) { - for (UTF8 utf(str.c_str()); utf.byteIndex() < (int)str.length(); ++i) { - uint32_t c = utf.next(); - if (isspace(c)) { - if (i < spliton) { - if (lastc != ':') - firstSentenceEnd = utf.byteIndex(); - } else if (i > spliton) { - firstSentenceEnd = splitCharStart; - } - } - if (i == spliton) { - splitCharStart = utf.byteIndex(); - } - lastc = c; - } - } - - if (firstSentenceEnd == 0) { - if (i <= spliton) { - firstSentenceEnd = (int)str.length(); - } else { - firstSentenceEnd = splitCharStart; - } - } - - std::vector ret; - ret.push_back(str.substr(0, firstSentenceEnd)); - if (firstSentenceEnd < (int)str.length()) - ret.push_back(str.substr(firstSentenceEnd)); - return ret; -} - void ChatMenu::UpdateChat() { using namespace UI; if (chatVert_ != nullptr) { chatVert_->Clear(); //read Access violation is proadhoc.cpp use NULL_->Clear() pointer? std::vector chatLog = getChatLog(); for (auto i : chatLog) { - //split long text uint32_t namecolor = 0x29B6F6; uint32_t textcolor = 0xFFFFFF; uint32_t infocolor = 0xFDD835; @@ -229,14 +180,12 @@ void ChatMenu::UpdateChat() { v->SetTextColor(0xFF000000 | infocolor); } else { LinearLayout *line = chatVert_->Add(new LinearLayout(ORIENT_HORIZONTAL, new LayoutParams(FILL_PARENT, FILL_PARENT))); - TextView *nameView = line->Add(new TextView(displayname, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); + line->SetSpacing(0.0f); + TextView *nameView = line->Add(new TextView(displayname, ALIGN_LEFT, true, new LinearLayoutParams(WRAP_CONTENT, WRAP_CONTENT, 0.0f))); nameView->SetTextColor(0xFF000000 | namecolor); - std::vector splitMessage = Split(chattext); - for (const std::string &msg : splitMessage) { - TextView *chatView = line->Add(new TextView(msg, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LayoutParams(FILL_PARENT, WRAP_CONTENT))); - chatView->SetTextColor(0xFF000000 | textcolor); - } + TextView *chatView = line->Add(new TextView(chattext, ALIGN_LEFT | FLAG_WRAP_TEXT, true, new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT, 1.0f))); + chatView->SetTextColor(0xFF000000 | textcolor); } } toBottom_ = true;