From 592ec2aaf1feb9b0a1afb6d35b4a201ffc97df03 Mon Sep 17 00:00:00 2001 From: kaetemi Date: Fri, 30 Oct 2020 03:42:43 +0800 Subject: [PATCH] Cleanup group container title localization behaviour, ryzom/ryzomcore#335 --- nel/include/nel/gui/group_container.h | 18 ++---- nel/include/nel/gui/group_html.h | 2 +- nel/include/nel/gui/string_case.h | 1 - nel/include/nel/gui/view_text.h | 4 +- nel/src/gui/group_container.cpp | 86 ++++++++++++--------------- nel/src/gui/group_html.cpp | 6 +- 6 files changed, 51 insertions(+), 66 deletions(-) diff --git a/nel/include/nel/gui/group_container.h b/nel/include/nel/gui/group_container.h index 361ae70b9..30d91dad6 100644 --- a/nel/include/nel/gui/group_container.h +++ b/nel/include/nel/gui/group_container.h @@ -248,13 +248,6 @@ namespace NLGUI // Get the header color draw. NB: depends if grayed, and if active. NLMISC::CRGBA getDrawnHeaderColor () const; - std::string getTitleRaw () const; - void setTitleRaw (const std::string &title); - std::string getTitleOpenedRaw () const; - void setTitleOpenedRaw (const std::string &title); - std::string getTitleClosedRaw () const; - void setTitleClosedRaw (const std::string &title); - ucstring getUCTitleOpened () const; void setUCTitleOpened (const ucstring &title); ucstring getUCTitleClosed () const; @@ -295,10 +288,6 @@ namespace NLGUI REFLECT_STRING("title_opened", getTitleOpened, setTitleOpened); REFLECT_STRING("title_closed", getTitleClosed, setTitleClosed); - REFLECT_STRING("title_raw", getTitleRaw, setTitleRaw); - REFLECT_STRING("title_opened_raw", getTitleOpenedRaw, setTitleOpenedRaw); - REFLECT_STRING("title_closed_raw", getTitleClosedRaw, setTitleClosedRaw); - REFLECT_UCSTRING("uc_title_opened", getUCTitleOpened, setUCTitleOpened); // FIXME: Lua UTF-8 REFLECT_UCSTRING("uc_title_closed", getUCTitleClosed, setUCTitleClosed); // FIXME: Lua UTF-8 REFLECT_UCSTRING("uc_title", getUCTitle, setUCTitle); // FIXME: Lua UTF-8 @@ -315,6 +304,8 @@ namespace NLGUI REFLECT_BOOL("lockable", isLockable, setLockable); REFLECT_BOOL("locked", isLocked, setLocked); + REFLECT_BOOL("localize", isLocalize, setLocalize); + REFLECT_BOOL("header_active", getHeaderActive, setHeaderActive); REFLECT_BOOL("right_button_enabled", getRightButtonEnabled, setRightButtonEnabled); REFLECT_EXPORT_END @@ -377,7 +368,7 @@ namespace NLGUI bool isActiveSavable() const { return _ActiveSavable; } bool isLocalize() const { return _Localize; } - void setLocalize(bool localize) { _Localize = localize; } + void setLocalize(bool localize); void setPopupX(sint32 x) { _PopupX = x; } void setPopupY(sint32 y) { _PopupY = y; } @@ -649,6 +640,9 @@ namespace NLGUI TTileClass convertTitleClass(const char *ptr); + void setTitledOpenedViewText(); + void setTitledClosedViewText(); + static COptionsContainerMove *getMoveOptions(); COptionsLayer *getContainerOptions(sint32 ls=-1); // Depends if overload by OptionsName or default used diff --git a/nel/include/nel/gui/group_html.h b/nel/include/nel/gui/group_html.h index 56605c0cc..a5e1dc4e1 100644 --- a/nel/include/nel/gui/group_html.h +++ b/nel/include/nel/gui/group_html.h @@ -352,7 +352,7 @@ namespace NLGUI // Set the title void setTitle (const std::string &title); std::string getTitle() const; - void setTitleRaw (const std::string &title); + void setContainerTitle (const std::string &title); // Lookup a url in local file system bool lookupLocalFile (std::string &result, const char *url, bool isUrl); diff --git a/nel/include/nel/gui/string_case.h b/nel/include/nel/gui/string_case.h index bd56c7998..446998e1a 100644 --- a/nel/include/nel/gui/string_case.h +++ b/nel/include/nel/gui/string_case.h @@ -21,7 +21,6 @@ #define STRING_CASE_H #include "nel/misc/types_nl.h" -#include "nel/misc/ucstring.h" namespace NLGUI { diff --git a/nel/include/nel/gui/view_text.h b/nel/include/nel/gui/view_text.h index 7c0324f58..1974e6933 100644 --- a/nel/include/nel/gui/view_text.h +++ b/nel/include/nel/gui/view_text.h @@ -84,7 +84,7 @@ namespace NLGUI /// Set - void setText(const std::string &text); + void setText(const std::string &text); //< Not localized. Use setHardText to localize strings starting with "ui". TODO: Add a Localize flag, like title in group container. HardText then simply sets localize to true. void setTextAsUtf16 (const ucstring &text); void setFontName (const std::string &name); void setFontSize (sint nFontSize, bool coef = true); @@ -178,7 +178,7 @@ namespace NLGUI void getLineEndIndex(uint line, sint &index, bool &endOfPreviousLine) const; std::string getHardText() const { return _HardText.empty() ? _Text : _HardText; } - void setHardText (const std::string &ht); + void setHardText (const std::string &ht); //< Localizes strings starting with "ui" void setHardTextAsUtf16(const ucstring &ht); std::string getColorAsString() const; diff --git a/nel/src/gui/group_container.cpp b/nel/src/gui/group_container.cpp index 141c7ba9b..e201f2eb4 100644 --- a/nel/src/gui/group_container.cpp +++ b/nel/src/gui/group_container.cpp @@ -3744,7 +3744,7 @@ namespace NLGUI _TitleOpened->setY (pLayer->getValSInt32 ("title_offset_y")); } _TitleOpened->setFontSize (pLayer->getValSInt32 ("title_font_size")); - if (_TitleClass==TitleText) _TitleOpened->setText (_TitleTextOpened); + if (_TitleClass == TitleText) setTitledOpenedViewText(); _TitleOpened->setActive (_Opened); // Title when the container is closed @@ -3796,7 +3796,7 @@ namespace NLGUI _TitleClosed->setY (pLayer->getValSInt32 ("title_offset_y")); } _TitleClosed->setFontSize (pLayer->getValSInt32 ("title_font_size")); - if (_TitleClass==TitleText) _TitleClosed->setText (_TitleTextClosed); + if (_TitleClass == TitleText) setTitledClosedViewText(); _TitleClosed->setActive(!_Opened); @@ -3946,6 +3946,15 @@ namespace NLGUI } } + // *************************************************************************** + void CGroupContainer::setLocalize(bool localize) + { + _Localize = localize; + setTitledOpenedViewText(); + setTitledClosedViewText(); + invalidateCoords(); + } + // *************************************************************************** std::string CGroupContainer::getTitle () const { @@ -3955,8 +3964,8 @@ namespace NLGUI // *************************************************************************** void CGroupContainer::setTitle (const std::string &title) { - if (_Localize) setTitleRaw (CI18N::get(title)); - else setTitleRaw (title); + setTitleOpened(title); + setTitleClosed(title); } // *************************************************************************** @@ -3968,8 +3977,9 @@ namespace NLGUI // *************************************************************************** void CGroupContainer::setTitleOpened (const std::string &title) { - if (_Localize) setTitleOpenedRaw (CI18N::get(title)); - else setTitleOpenedRaw (title); + _TitleTextOpened = title; + setTitledOpenedViewText(); + invalidateCoords(); } // *************************************************************************** @@ -3980,88 +3990,70 @@ namespace NLGUI // *************************************************************************** void CGroupContainer::setTitleClosed (const std::string &title) - { - if (_Localize) setTitleClosedRaw (CI18N::get(title)); - else setTitleClosedRaw (title); - } - - // *************************************************************************** - void CGroupContainer::setTitleOpenedRaw(const std::string &title) - { - _TitleTextOpened = title; - if (_TitleOpened != NULL) - _TitleOpened->setText (title); - invalidateCoords(); - } - - // *************************************************************************** - void CGroupContainer::setTitleClosedRaw(const std::string &title) { _TitleTextClosed = title; - if (_TitleClosed != NULL) - _TitleClosed->setText (_TitleTextClosed); + setTitledClosedViewText(); invalidateCoords(); } // *************************************************************************** - void CGroupContainer::setTitleRaw(const std::string &title) + void CGroupContainer::setTitledOpenedViewText() { - setTitleOpenedRaw(title); - setTitleClosedRaw(title); - } - - // *************************************************************************** - std::string CGroupContainer::getTitleRaw () const - { - return getTitleOpened(); - } - - // *************************************************************************** - std::string CGroupContainer::getTitleOpenedRaw () const - { - return _TitleTextOpened; + if (_TitleOpened != NULL) + { + if (_Localize && NLMISC::startsWith(_TitleTextOpened, "ui")) + _TitleOpened->setHardText(_TitleTextOpened); + else + _TitleOpened->setText(_TitleTextOpened); + } } // *************************************************************************** - std::string CGroupContainer::getTitleClosedRaw () const + void CGroupContainer::setTitledClosedViewText() { - return _TitleTextClosed; + if (_TitleClosed != NULL) + { + if (_Localize && NLMISC::startsWith(_TitleTextClosed, "ui")) + _TitleClosed->setHardText(_TitleTextClosed); + else + _TitleClosed->setText(_TitleTextClosed); + } } // *************************************************************************** void CGroupContainer::setUCTitleOpened(const ucstring &title) { - setTitleOpenedRaw(title.toUtf8()); + setTitleOpened(title.toUtf8()); } // *************************************************************************** void CGroupContainer::setUCTitleClosed(const ucstring &title) { - setTitleClosedRaw(title.toUtf8()); + setTitleClosed(title.toUtf8()); } // *************************************************************************** void CGroupContainer::setUCTitle(const ucstring &title) { - setTitleRaw(title.toUtf8()); + setTitle(title.toUtf8()); } // *************************************************************************** ucstring CGroupContainer::getUCTitle () const { - return ucstring::makeFromUtf8(getTitleRaw()); + return ucstring::makeFromUtf8(getTitle()); } // *************************************************************************** ucstring CGroupContainer::getUCTitleOpened () const { - return ucstring::makeFromUtf8(getTitleOpenedRaw()); + return ucstring::makeFromUtf8(getTitleOpened()); } // *************************************************************************** ucstring CGroupContainer::getUCTitleClosed () const { - return ucstring::makeFromUtf8(getTitleClosedRaw()); + return ucstring::makeFromUtf8(getTitleClosed()); } // *************************************************************************** diff --git a/nel/src/gui/group_html.cpp b/nel/src/gui/group_html.cpp index f7a62cc90..b85cb5bfc 100644 --- a/nel/src/gui/group_html.cpp +++ b/nel/src/gui/group_html.cpp @@ -3401,7 +3401,7 @@ namespace NLGUI // *************************************************************************** - void CGroupHTML::setTitleRaw (const std::string &title) + void CGroupHTML::setContainerTitle (const std::string &title) { CInterfaceElement *parent = getParent(); if (parent) @@ -3411,7 +3411,7 @@ namespace NLGUI CGroupContainer *container = dynamic_cast(parent); if (container) { - container->setTitleRaw (title); + container->setTitle(title); } } } @@ -3426,7 +3426,7 @@ namespace NLGUI } _TitleString += title; - setTitleRaw(_TitleString); + setContainerTitle(_TitleString); } std::string CGroupHTML::getTitle() const {