CHANGED: #1471 CViewTextFormated no longer depends on Ryzom game related code.

--HG--
branch : gui-refactoring
This commit is contained in:
dfighter1985 2012-06-21 10:20:43 +02:00
parent d257a3e896
commit 4013d3173e
3 changed files with 140 additions and 120 deletions

View file

@ -39,6 +39,7 @@
#include "register_interface_elements.h" #include "register_interface_elements.h"
// Action / Observers // Action / Observers
#include "nel/gui/action_handler.h" #include "nel/gui/action_handler.h"
#include "action_handler_misc.h"
#include "interface_observer.h" #include "interface_observer.h"
#include "interface_anim.h" #include "interface_anim.h"
#include "interface_ddx.h" #include "interface_ddx.h"
@ -51,6 +52,7 @@
#include "view_bitmap_combo.h" #include "view_bitmap_combo.h"
#include "nel/gui/view_text.h" #include "nel/gui/view_text.h"
#include "nel/gui/view_text_id.h" #include "nel/gui/view_text_id.h"
#include "view_text_formated.h"
// Ctrl // Ctrl
#include "nel/gui/ctrl_scroll.h" #include "nel/gui/ctrl_scroll.h"
#include "nel/gui/ctrl_button.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 &paramString )
{
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<CCharacterCL*>(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 namespace
{ {
CStringManagerTextProvider SMTextProvider; CStringManagerTextProvider SMTextProvider;
CRyzomTextFormatter RyzomTextFormatter;
} }
// ------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------
@ -282,7 +402,7 @@ CInterfaceManager::CInterfaceManager( NL3D::UDriver *driver, NL3D::UTextContext
CViewRenderer::hwCursors = &ClientCfg.HardwareCursors; CViewRenderer::hwCursors = &ClientCfg.HardwareCursors;
CViewRenderer::getInstance(); CViewRenderer::getInstance();
CViewTextID::setTextProvider( &SMTextProvider ); CViewTextID::setTextProvider( &SMTextProvider );
CViewTextFormated::setFormatter( &RyzomTextFormatter );
_Instance = this; _Instance = this;
NLGUI::CDBManager::getInstance()->resizeBanks( NB_CDB_BANKS ); NLGUI::CDBManager::getInstance()->resizeBanks( NB_CDB_BANKS );
@ -363,6 +483,7 @@ CInterfaceManager::CInterfaceManager( NL3D::UDriver *driver, NL3D::UTextContext
CInterfaceManager::~CInterfaceManager() CInterfaceManager::~CInterfaceManager()
{ {
CViewTextID::setTextProvider( NULL ); CViewTextID::setTextProvider( NULL );
CViewTextFormated::setFormatter( NULL );
reset(); // to flush IDStringWaiters reset(); // to flush IDStringWaiters
_ParentPositionsMap.clear(); _ParentPositionsMap.clear();

View file

@ -14,26 +14,14 @@
// You should have received a copy of the GNU Affero General Public License // You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "stdpch.h"
#include "view_text_formated.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/xml_auto_ptr.h"
//
#include "nel/misc/i18n.h" #include "nel/misc/i18n.h"
////////////
// EXTERN //
////////////
using namespace STRING_MANAGER;
NLMISC_REGISTER_OBJECT(CViewBase, CViewTextFormated, std::string, "text_formated"); NLMISC_REGISTER_OBJECT(CViewBase, CViewTextFormated, std::string, "text_formated");
CViewTextFormated::IViewTextFormatter *CViewTextFormated::textFormatter = NULL;
// **************************************************************************** // ****************************************************************************
bool CViewTextFormated::parse(xmlNodePtr cur,CInterfaceGroup * parentGroup) 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 &paramString) ucstring CViewTextFormated::formatString(const ucstring &inputString, const ucstring &paramString)
{ {
ucstring formatedResult; 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': if( textFormatter == NULL )
case 'p': // add player name formatedResult = inputString;
if (ClientCfg.Local)
{
formatedResult += ucstring("player");
}
else else
{ formatedResult = CViewTextFormated::textFormatter->formatString( inputString, paramString );
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<CCharacterCL*>(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; return formatedResult;
} }

View file

@ -32,6 +32,14 @@
class CViewTextFormated : public CViewText class CViewTextFormated : public CViewText
{ {
public: public:
class IViewTextFormatter
{
public:
virtual ~IViewTextFormatter(){}
virtual ucstring formatString( const ucstring &inputString, const ucstring &paramString ) = 0;
};
CViewTextFormated (const TCtorParam &param) : CViewText(param) CViewTextFormated (const TCtorParam &param) : CViewText(param)
{} {}
virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup); virtual bool parse(xmlNodePtr cur, CInterfaceGroup * parentGroup);
@ -40,8 +48,12 @@ public:
void setFormatString(const ucstring &format); void setFormatString(const ucstring &format);
static ucstring formatString(const ucstring &inputString, const ucstring &paramString); static ucstring formatString(const ucstring &inputString, const ucstring &paramString);
static void setFormatter( IViewTextFormatter *formatter ){ textFormatter = formatter; }
private: private:
ucstring _FormatString; ucstring _FormatString;
static IViewTextFormatter *textFormatter;
}; };