diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index 0219aa87c..5f7676853 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -39,6 +39,7 @@ #include "register_interface_elements.h" // Action / Observers #include "nel/gui/action_handler.h" +#include "action_handler_misc.h" #include "interface_observer.h" #include "interface_anim.h" #include "interface_ddx.h" @@ -51,6 +52,7 @@ #include "view_bitmap_combo.h" #include "nel/gui/view_text.h" #include "nel/gui/view_text_id.h" +#include "view_text_formated.h" // Ctrl #include "nel/gui/ctrl_scroll.h" #include "nel/gui/ctrl_button.h" @@ -265,9 +267,127 @@ class CStringManagerTextProvider : public CViewTextID::IViewTextProvider } }; +class CRyzomTextFormatter : public CViewTextFormated::IViewTextFormatter +{ +public: + ucstring formatString( const ucstring &inputString, const ucstring ¶mString ) + { + ucstring formatedResult; + + // Apply the format + for(ucstring::const_iterator it = inputString.begin(); it != inputString.end();) + { + if (*it == '$') + { + ++it; + if (it == inputString.end()) + break; + + switch(*it) + { + case 't': // add text ID + formatedResult += paramString; + break; + + case 'P': + case 'p': // add player name + if (ClientCfg.Local) + { + formatedResult += ucstring("player"); + } + else + { + if(UserEntity) + { + ucstring name = UserEntity->getEntityName(); + if (*it == 'P') setCase(name, CaseUpper); + formatedResult += name; + } + } + break; + // + case 's': + case 'b': // add bot name + { + ucstring botName; + bool womanTitle = false; + if (ClientCfg.Local) + { + botName = ucstring("NPC"); + } + else + { + CLFECOMMON::TCLEntityId trader = CLFECOMMON::INVALID_SLOT; + if(UserEntity) + trader = UserEntity->trader(); + if (trader != CLFECOMMON::INVALID_SLOT) + { + CEntityCL *entity = EntitiesMngr.entity(trader); + if (entity != NULL) + { + uint32 nDBid = entity->getNameId(); + if (nDBid != 0) + { + STRING_MANAGER::CStringManagerClient *pSMC = STRING_MANAGER::CStringManagerClient::instance(); + pSMC->getString(nDBid, botName); + } + else + { + botName = entity->getDisplayName(); + } + CCharacterCL *pChar = dynamic_cast(entity); + if (pChar != NULL) + womanTitle = pChar->getGender() == GSGENDER::female; + } + } + } + // get the title translated + ucstring sTitleTranslated = botName; + CStringPostProcessRemoveName spprn; + spprn.Woman = womanTitle; + spprn.cbIDStringReceived(sTitleTranslated); + + botName = CEntityCL::removeTitleAndShardFromName(botName); + + // short name (with no title such as 'guard', 'merchant' ...) + if (*it == 's') + { + // But if there is no name, display only the title + if (botName.empty()) + botName = sTitleTranslated; + } + else + { + // Else we want the title ! + if (!botName.empty()) + botName += " "; + botName += sTitleTranslated; + } + + formatedResult += botName; + } + break; + default: + formatedResult += (ucchar) '$'; + break; + } + ++it; + } + else + { + formatedResult += (ucchar) *it; + ++it; + } + } + + return formatedResult; + } +}; + namespace { CStringManagerTextProvider SMTextProvider; + CRyzomTextFormatter RyzomTextFormatter; } // ------------------------------------------------------------------------------------------------ @@ -282,7 +402,7 @@ CInterfaceManager::CInterfaceManager( NL3D::UDriver *driver, NL3D::UTextContext CViewRenderer::hwCursors = &ClientCfg.HardwareCursors; CViewRenderer::getInstance(); CViewTextID::setTextProvider( &SMTextProvider ); - + CViewTextFormated::setFormatter( &RyzomTextFormatter ); _Instance = this; NLGUI::CDBManager::getInstance()->resizeBanks( NB_CDB_BANKS ); @@ -363,6 +483,7 @@ CInterfaceManager::CInterfaceManager( NL3D::UDriver *driver, NL3D::UTextContext CInterfaceManager::~CInterfaceManager() { CViewTextID::setTextProvider( NULL ); + CViewTextFormated::setFormatter( NULL ); reset(); // to flush IDStringWaiters _ParentPositionsMap.clear(); diff --git a/code/ryzom/client/src/interface_v3/view_text_formated.cpp b/code/ryzom/client/src/interface_v3/view_text_formated.cpp index 6d3513fce..cf8e8264b 100644 --- a/code/ryzom/client/src/interface_v3/view_text_formated.cpp +++ b/code/ryzom/client/src/interface_v3/view_text_formated.cpp @@ -14,26 +14,14 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . - - -#include "stdpch.h" #include "view_text_formated.h" -#include "../user_entity.h" -#include "../entities.h" -#include "../string_manager_client.h" -#include "action_handler_misc.h" -// #include "nel/misc/xml_auto_ptr.h" -// #include "nel/misc/i18n.h" -//////////// -// EXTERN // -//////////// -using namespace STRING_MANAGER; - NLMISC_REGISTER_OBJECT(CViewBase, CViewTextFormated, std::string, "text_formated"); +CViewTextFormated::IViewTextFormatter *CViewTextFormated::textFormatter = NULL; + // **************************************************************************** bool CViewTextFormated::parse(xmlNodePtr cur,CInterfaceGroup * parentGroup) { @@ -70,112 +58,11 @@ void CViewTextFormated::setFormatString(const ucstring &format) ucstring CViewTextFormated::formatString(const ucstring &inputString, const ucstring ¶mString) { ucstring formatedResult; - // Apply the format - for(ucstring::const_iterator it = inputString.begin(); it != inputString.end();) - { - if (*it == '$') - { - ++it; - if (it == inputString.end()) break; - switch(*it) - { - case 't': // add text ID - formatedResult += paramString; - break; - case 'P': - case 'p': // add player name - if (ClientCfg.Local) - { - formatedResult += ucstring("player"); - } - else - { - if(UserEntity) - { - ucstring name = UserEntity->getEntityName(); - if (*it == 'P') setCase(name, CaseUpper); - formatedResult += name; - } - } - break; - // - case 's': - case 'b': // add bot name - { - ucstring botName; - bool womanTitle = false; - if (ClientCfg.Local) - { - botName = ucstring("NPC"); - } - else - { - CLFECOMMON::TCLEntityId trader = CLFECOMMON::INVALID_SLOT; - if(UserEntity) - trader = UserEntity->trader(); - if (trader != CLFECOMMON::INVALID_SLOT) - { - CEntityCL *entity = EntitiesMngr.entity(trader); - if (entity != NULL) - { - uint32 nDBid = entity->getNameId(); - - if (nDBid != 0) - { - CStringManagerClient *pSMC = CStringManagerClient::instance(); - pSMC->getString(nDBid, botName); - } - else - { - botName = entity->getDisplayName(); - } - - CCharacterCL *pChar = dynamic_cast(entity); - if (pChar != NULL) - womanTitle = pChar->getGender() == GSGENDER::female; - } - } - } - - // get the title translated - ucstring sTitleTranslated = botName; - CStringPostProcessRemoveName spprn; - spprn.Woman = womanTitle; - spprn.cbIDStringReceived(sTitleTranslated); - - botName = CEntityCL::removeTitleAndShardFromName(botName); - - // short name (with no title such as 'guard', 'merchant' ...) - if (*it == 's') - { - // But if there is no name, display only the title - if (botName.empty()) - botName = sTitleTranslated; - } - else - { - // Else we want the title ! - if (!botName.empty()) - botName += " "; - botName += sTitleTranslated; - } - - formatedResult += botName; - } - break; - default: - formatedResult += (ucchar) '$'; - break; - } - ++it; - } - else - { - formatedResult += (ucchar) *it; - ++it; - } - } + if( textFormatter == NULL ) + formatedResult = inputString; + else + formatedResult = CViewTextFormated::textFormatter->formatString( inputString, paramString ); return formatedResult; } diff --git a/code/ryzom/client/src/interface_v3/view_text_formated.h b/code/ryzom/client/src/interface_v3/view_text_formated.h index 0f8c2d4c0..604d16dbc 100644 --- a/code/ryzom/client/src/interface_v3/view_text_formated.h +++ b/code/ryzom/client/src/interface_v3/view_text_formated.h @@ -32,6 +32,14 @@ class CViewTextFormated : public CViewText { public: + + class IViewTextFormatter + { + public: + virtual ~IViewTextFormatter(){} + virtual ucstring formatString( const ucstring &inputString, const ucstring ¶mString ) = 0; + }; + CViewTextFormated (const TCtorParam ¶m) : CViewText(param) {} virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); @@ -40,8 +48,12 @@ public: void setFormatString(const ucstring &format); static ucstring formatString(const ucstring &inputString, const ucstring ¶mString); + + static void setFormatter( IViewTextFormatter *formatter ){ textFormatter = formatter; } + private: ucstring _FormatString; + static IViewTextFormatter *textFormatter; };