From 9e2872d15ec7f93040a62ba473d24785a532659c Mon Sep 17 00:00:00 2001 From: Ulukyn Date: Fri, 12 Jun 2020 14:09:29 +0200 Subject: [PATCH] Added: Add a language icon when client receive a translated message --- .../src/interface_v3/chat_text_manager.cpp | 26 +++++++++++++++++-- .../interface_v3/group_in_scene_bubble.cpp | 10 ++++++- 2 files changed, 33 insertions(+), 3 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 3b11d17a5..b3a673ffe 100644 --- a/code/ryzom/client/src/interface_v3/chat_text_manager.cpp +++ b/code/ryzom/client/src/interface_v3/chat_text_manager.cpp @@ -422,6 +422,29 @@ CViewBase *CChatTextManager::createMsgTextComplex(const ucstring &msg, NLMISC::C return para; } + ucstring::size_type pos = 0; + + // Manage Translations + 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) + { + 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); + pos = endOfOriginal+3; + CCtrlButton *ctrlButton = new CCtrlButton(CViewBase::TCtorParam()); + ctrlButton->setTexture(texture); + ctrlButton->setTextureOver(texture); + ctrlButton->setTexturePushed(texture); + ctrlButton->setDefaultContextHelp(original); + ctrlButton->setId("tr"); + para->addChild(ctrlButton); + } // quickly check if text has links or not bool hasUrl; @@ -430,8 +453,7 @@ CViewBase *CChatTextManager::createMsgTextComplex(const ucstring &msg, NLMISC::C hasUrl = (s.find(ucstring("http://")) || s.find(ucstring("https://"))); } - ucstring::size_type pos = 0; - for (ucstring::size_type i = 0; i< textSize;) + for (ucstring::size_type i = pos; i< textSize;) { if (hasUrl && isUrlTag(msg, i, textSize)) { 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 d79861b58..460a095fc 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 @@ -843,6 +843,14 @@ void CGroupInSceneBubbleManager::chatOpen (uint32 nUID, const ucstring &ucsText, if (pChar == NULL || nUID==CLFECOMMON::INVALID_CLIENT_DATASET_INDEX) return; if (bubbleTimer == 0) bubbleTimer = CWidgetManager::getInstance()->getSystemOption(CWidgetManager::OptionTimeoutBubbles).getValSInt32(); + + + // Clean bubble from translation system + ucstring::size_type pos = 0; + string::size_type endOfOriginal = ucsText.find(ucstring("}@{")); + if (endOfOriginal != string::npos) + pos = endOfOriginal+4; + // Output the message in a bubble bool show = false; @@ -862,7 +870,7 @@ void CGroupInSceneBubbleManager::chatOpen (uint32 nUID, const ucstring &ucsText, return; // Get a bubble - CGroupInSceneBubble *bubble = newBubble (ucsText); + CGroupInSceneBubble *bubble = newBubble (ucsText.substr(pos)); if (bubble) { // Link the bubble