From c75071b4887035feb940adbbe9a73d6fceb3bbfc Mon Sep 17 00:00:00 2001 From: Sit Melai Date: Mon, 15 Feb 2021 02:17:50 +0100 Subject: [PATCH 1/5] Handle hiding the flag and inversing translations for each language --- .../src/interface_v3/chat_text_manager.cpp | 21 ++++++++++++------- .../interface_v3/group_in_scene_bubble.cpp | 9 +++++--- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/chat_text_manager.cpp b/code/ryzom/client/src/interface_v3/chat_text_manager.cpp index ec0aee822..c8a07f0f8 100644 --- a/code/ryzom/client/src/interface_v3/chat_text_manager.cpp +++ b/code/ryzom/client/src/interface_v3/chat_text_manager.cpp @@ -424,27 +424,30 @@ CViewBase *CChatTextManager::createMsgTextComplex(const ucstring &msg, NLMISC::C ucstring::size_type pos = 0; - // Manage Translations - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHAT:SHOW_TRANSLATION_ONLY_AS_TOOLTIP_CB", false); - bool originalFirst = node->getValueBool(); - string::size_type startTr = msg.find(ucstring("{:")); string::size_type endOfOriginal = msg.find(ucstring("}@{")); // Original/Translated case, example: {:enHello the world!}@{ Bonjour le monde ! if (startTr != string::npos && endOfOriginal != string::npos) { + string lang = toUpper(msg.substr(startTr+2, 2)).toString(); + + CCDBNodeLeaf *nodeInverse = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":INVERSE_DISPLAY", false); + bool inverse = nodeInverse->getValueBool(); + CCDBNodeLeaf *nodeHideFlag = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":HIDE_FLAG", false); + bool hideFlag = nodeHideFlag->getValueBool(); + CViewBase *vt = createMsgTextSimple(msg.substr(0, startTr), col, justified, NULL); para->addChild(vt); string texture = "flag-"+toLower(msg.substr(startTr+2, 2)).toString()+".tga"; ucstring original = msg.substr(startTr+5, endOfOriginal-startTr-5); - ucstring translation = msg.substr(endOfOriginal+3); + ucstring translation = msg.substr(endOfOriginal+4); CCtrlButton *ctrlButton = new CCtrlButton(CViewBase::TCtorParam()); ctrlButton->setTexture(texture); ctrlButton->setTextureOver(texture); ctrlButton->setTexturePushed(texture); - if (!originalFirst) + if (!inverse) { ctrlButton->setDefaultContextHelp(original); pos = endOfOriginal+3; @@ -456,7 +459,11 @@ CViewBase *CChatTextManager::createMsgTextComplex(const ucstring &msg, NLMISC::C textSize = endOfOriginal; } ctrlButton->setId("tr"); - para->addChild(ctrlButton); + if (hideFlag) { + delete ctrlButton; + } else { + para->addChild(ctrlButton); + } } // quickly check if text has links or not diff --git a/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp b/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp index 015800173..e2fca2053 100644 --- a/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp +++ b/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp @@ -875,16 +875,19 @@ void CGroupInSceneBubbleManager::chatOpen (uint32 nUID, const ucstring &ucsText, // Clean bubble from translation system - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:CHAT:SHOW_TRANSLATION_ONLY_AS_TOOLTIP_CB", false); - bool originalFirst = node->getValueBool(); ucstring::size_type pos = 0; ucstring::size_type textSize = ucsText.size(); string::size_type startTr = ucsText.find(ucstring("{:")); string::size_type endOfOriginal = ucsText.find(ucstring("}@{")); + + string lang = toUpper(ucsText.substr(startTr+2, 2)).toString(); + CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":INVERSE_DISPLAY", false); + bool inverse = node->getValueBool(); + if (endOfOriginal != string::npos) { - if (!originalFirst) + if (!inverse) { pos = endOfOriginal+4; } From 91b3ff25b48d88062dec670408da0c65c483a227 Mon Sep 17 00:00:00 2001 From: Sit Melai Date: Tue, 16 Feb 2021 00:04:04 +0100 Subject: [PATCH 2/5] Add disabling of translation per channel --- .../src/interface_v3/chat_text_manager.cpp | 2 +- .../client/src/interface_v3/chat_window.cpp | 30 ++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/chat_text_manager.cpp b/code/ryzom/client/src/interface_v3/chat_text_manager.cpp index c8a07f0f8..32558f642 100644 --- a/code/ryzom/client/src/interface_v3/chat_text_manager.cpp +++ b/code/ryzom/client/src/interface_v3/chat_text_manager.cpp @@ -450,7 +450,7 @@ CViewBase *CChatTextManager::createMsgTextComplex(const ucstring &msg, NLMISC::C if (!inverse) { ctrlButton->setDefaultContextHelp(original); - pos = endOfOriginal+3; + pos = endOfOriginal+4; } else { diff --git a/code/ryzom/client/src/interface_v3/chat_window.cpp b/code/ryzom/client/src/interface_v3/chat_window.cpp index 13f7bc66d..51e4a96a3 100644 --- a/code/ryzom/client/src/interface_v3/chat_window.cpp +++ b/code/ryzom/client/src/interface_v3/chat_window.cpp @@ -216,7 +216,23 @@ void CChatWindow::displayMessage(const ucstring &msg, NLMISC::CRGBA col, CChatGr gl = dynamic_cast(_Chat->getGroup("cb:text_list")); - CViewBase *child = ctm.createMsgText(msg, col); + + + CCDBNodeLeaf *nodeNoTranslation = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + toUpper(CChatGroup::groupTypeToString(gt)) + ":DISABLE", false); + bool noTranslation = nodeNoTranslation->getValueBool(); + + ucstring msgNoTranslate = msg; + + if (noTranslation) { + string::size_type startTr = msg.find(ucstring("{:")); + string::size_type endOfOriginal = msg.find(ucstring("}@{")); + + if (startTr != string::npos && endOfOriginal != string::npos) { + msgNoTranslate = msg.substr(0, startTr) + msg.substr(startTr+5, endOfOriginal-startTr-5); + } + } + + CViewBase *child = ctm.createMsgText(msgNoTranslate, col); if (child) { if (gl) gl->addChild(child); @@ -568,6 +584,18 @@ void CChatGroupWindow::displayMessage(const ucstring &msg, NLMISC::CRGBA col, CC ucstring newmsg = msg; ucstring prefix; + CCDBNodeLeaf *nodeNoTranslation = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + toUpper(CChatGroup::groupTypeToString(gt)) + ":DISABLE", false); + bool noTranslation = nodeNoTranslation->getValueBool(); + + if (noTranslation) { + string::size_type startTr = msg.find(ucstring("{:")); + string::size_type endOfOriginal = msg.find(ucstring("}@{")); + + if (startTr != string::npos && endOfOriginal != string::npos) { + newmsg = newmsg.substr(0, startTr) + newmsg.substr(startTr+5, endOfOriginal-startTr-5); + } + } + CViewBase *child = NULL; if (gl != NULL) { From 673ce18e72778a2b7fa26aee1ca56b682a67a03d Mon Sep 17 00:00:00 2001 From: Sit Melai Date: Tue, 4 May 2021 14:14:57 +0200 Subject: [PATCH 3/5] Fix crash if bubble message isn't translated --- .../client/src/interface_v3/group_in_scene_bubble.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp b/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp index e2fca2053..91e936dc6 100644 --- a/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp +++ b/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp @@ -881,12 +881,11 @@ void CGroupInSceneBubbleManager::chatOpen (uint32 nUID, const ucstring &ucsText, string::size_type startTr = ucsText.find(ucstring("{:")); string::size_type endOfOriginal = ucsText.find(ucstring("}@{")); - string lang = toUpper(ucsText.substr(startTr+2, 2)).toString(); - CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":INVERSE_DISPLAY", false); - bool inverse = node->getValueBool(); + if (startTr != string::npos && endOfOriginal != string::npos) { + string lang = toUpper(ucsText.substr(startTr+2, 2)).toString(); + CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":INVERSE_DISPLAY", false); + bool inverse = node->getValueBool(); - if (endOfOriginal != string::npos) - { if (!inverse) { pos = endOfOriginal+4; From 1ec4f8847192030abcb96793fea8ecbb503b2daa Mon Sep 17 00:00:00 2001 From: Nuno Date: Tue, 4 May 2021 14:27:39 +0200 Subject: [PATCH 4/5] Added check if node are null --- code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp b/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp index 91e936dc6..a4135122e 100644 --- a/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp +++ b/code/ryzom/client/src/interface_v3/group_in_scene_bubble.cpp @@ -882,9 +882,11 @@ void CGroupInSceneBubbleManager::chatOpen (uint32 nUID, const ucstring &ucsText, string::size_type endOfOriginal = ucsText.find(ucstring("}@{")); if (startTr != string::npos && endOfOriginal != string::npos) { + bool inverse = false; string lang = toUpper(ucsText.substr(startTr+2, 2)).toString(); CCDBNodeLeaf *node= NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":INVERSE_DISPLAY", false); - bool inverse = node->getValueBool(); + if (node) + inverse = node->getValueBool(); if (!inverse) { From cdf1bacee1af82ba691c342f8d72f896a7a354a6 Mon Sep 17 00:00:00 2001 From: Sit Melai Date: Tue, 4 May 2021 14:56:09 +0200 Subject: [PATCH 5/5] Added checks if the DB leafs aren't present --- .../client/src/interface_v3/chat_text_manager.cpp | 10 +++++++--- code/ryzom/client/src/interface_v3/chat_window.cpp | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/chat_text_manager.cpp b/code/ryzom/client/src/interface_v3/chat_text_manager.cpp index 32558f642..5a2955722 100644 --- a/code/ryzom/client/src/interface_v3/chat_text_manager.cpp +++ b/code/ryzom/client/src/interface_v3/chat_text_manager.cpp @@ -431,11 +431,15 @@ CViewBase *CChatTextManager::createMsgTextComplex(const ucstring &msg, NLMISC::C if (startTr != string::npos && endOfOriginal != string::npos) { string lang = toUpper(msg.substr(startTr+2, 2)).toString(); - + + bool inverse = false; + bool hideFlag = false; CCDBNodeLeaf *nodeInverse = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":INVERSE_DISPLAY", false); - bool inverse = nodeInverse->getValueBool(); + if (nodeInverse) + inverse = nodeInverse->getValueBool(); CCDBNodeLeaf *nodeHideFlag = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + lang + ":HIDE_FLAG", false); - bool hideFlag = nodeHideFlag->getValueBool(); + if (nodeHideFlag) + hideFlag = nodeHideFlag->getValueBool(); CViewBase *vt = createMsgTextSimple(msg.substr(0, startTr), col, justified, NULL); para->addChild(vt); diff --git a/code/ryzom/client/src/interface_v3/chat_window.cpp b/code/ryzom/client/src/interface_v3/chat_window.cpp index 51e4a96a3..9340377f9 100644 --- a/code/ryzom/client/src/interface_v3/chat_window.cpp +++ b/code/ryzom/client/src/interface_v3/chat_window.cpp @@ -218,8 +218,10 @@ void CChatWindow::displayMessage(const ucstring &msg, NLMISC::CRGBA col, CChatGr + bool noTranslation = false; CCDBNodeLeaf *nodeNoTranslation = NLGUI::CDBManager::getInstance()->getDbProp("UI:SAVE:TRANSLATION:" + toUpper(CChatGroup::groupTypeToString(gt)) + ":DISABLE", false); - bool noTranslation = nodeNoTranslation->getValueBool(); + if (nodeNoTranslation) + noTranslation = nodeNoTranslation->getValueBool(); ucstring msgNoTranslate = msg;