Fixed: Display of emotes using the same character case as in translations and showing corresponding command to type

This commit is contained in:
kervala 2016-01-23 19:06:28 +01:00
parent f09a8e0a81
commit f128266242

View file

@ -2904,6 +2904,32 @@ struct CEmoteEntry
} }
}; };
static bool translateEmote(const std::string &id, ucstring &translatedName, std::string &commandName, std::string &commandNameAlt)
{
if (CI18N::hasTranslation(id))
{
translatedName = CI18N::get(id);
// convert command to utf8 since emote translation can have strange chars
commandName = toLower(translatedName).toUtf8();
// replace all spaces by _
while (strFindReplace(commandName, " ", "_"));
// TODO: remove accents
commandNameAlt = commandName;
if (commandNameAlt == commandName) commandNameAlt.clear();
return true;
}
translatedName = id;
commandName = id;
return false;
}
// *************************************************************************** // ***************************************************************************
void CInterfaceManager::initEmotes() void CInterfaceManager::initEmotes()
{ {
@ -2979,11 +3005,16 @@ void CInterfaceManager::initEmotes()
nbToken++; nbToken++;
CGroupMenu *pRootMenu = dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:user_chat_emote_menu")); CGroupMenu *pRootMenu = dynamic_cast<CGroupMenu*>(CWidgetManager::getInstance()->getElementFromId("ui:interface:user_chat_emote_menu"));
pRootMenu->setProperty("case_mode", "0");
nlassert(pRootMenu); nlassert(pRootMenu);
CGroupSubMenu *pMenu = pRootMenu->getRootMenu(); CGroupSubMenu *pMenu = pRootMenu->getRootMenu();
nlassert(pMenu); nlassert(pMenu);
ucstring sTranslatedName;
std::string sCommandName;
std::string sCommandNameAlt;
// Add to the game context menu // Add to the game context menu
// ---------------------------- // ----------------------------
for (i = 0; i < nbToken; ++i) for (i = 0; i < nbToken; ++i)
@ -3021,8 +3052,10 @@ void CInterfaceManager::initEmotes()
} }
else else
{ {
translateEmote(sTmp, sTranslatedName, sCommandName, sCommandNameAlt);
// Create a line // Create a line
pMenu->addLine ("/" + CI18N::get(sTmp), "emote", pMenu->addLine (sTranslatedName + " (/" + ucstring::makeFromUtf8(sCommandName) + ")", "emote",
"nb="+toString(nEmoteNb)+"|behav="+toString(nBehav), sTmp); "nb="+toString(nEmoteNb)+"|behav="+toString(nBehav), sTmp);
} }
} }
@ -3035,25 +3068,42 @@ void CInterfaceManager::initEmotes()
} }
} }
if (sTranslatedName.empty())
translateEmote(sName, sTranslatedName, sCommandName, sCommandNameAlt);
// Create new command // Create new command
// ------------------ // ------------------
if (CI18N::hasTranslation(sName)) if (!sTranslatedName.empty())
{ {
CGroupSubMenu *pMenu = pRootMenu->getRootMenu(); if(ICommand::exists(sCommandName))
// convert command to utf8 since emote translation can have strange chars
string cmdName = (toLower(CI18N::get(sName))).toUtf8();
if(ICommand::exists(cmdName))
{ {
nlwarning("Translation for emote %s already exist: '%s' exist twice", sName.c_str(), cmdName.c_str()); nlwarning("Translation for emote %s already exist: '%s' exist twice", sName.c_str(), sCommandName.c_str());
} }
else else
{ {
CEmoteCmd *pNewCmd = new CEmoteCmd(cmdName.c_str(), "", ""); CEmoteCmd *pNewCmd = new CEmoteCmd(sCommandName.c_str(), "", "");
pNewCmd->EmoteNb = nEmoteNb; pNewCmd->EmoteNb = nEmoteNb;
pNewCmd->Behaviour = nBehav; pNewCmd->Behaviour = nBehav;
_EmoteCmds.push_back(pNewCmd); _EmoteCmds.push_back(pNewCmd);
// add alternative command if defined
if (!sCommandNameAlt.empty())
{
if(ICommand::exists(sCommandNameAlt))
{
nlwarning("Translation for emote %s already exist: '%s' exist twice", sName.c_str(), sCommandName.c_str());
}
else
{
CEmoteCmd *pNewCmd = new CEmoteCmd(sCommandNameAlt.c_str(), "", "");
pNewCmd->EmoteNb = nEmoteNb;
pNewCmd->Behaviour = nBehav;
_EmoteCmds.push_back(pNewCmd);
}
}
CGroupSubMenu *pMenu = pRootMenu->getRootMenu();
// Quick-Emote too ? // Quick-Emote too ?
for (i = 0; i< pMenu->getNumLine (); i++) for (i = 0; i< pMenu->getNumLine (); i++)
{ {
@ -3061,7 +3111,7 @@ void CInterfaceManager::initEmotes()
{ {
// Yeah that's a quick emote too; set command // Yeah that's a quick emote too; set command
pMenu->addLineAtIndex (i, pMenu->addLineAtIndex (i,
"@{FFFF}/" + toLower(CI18N::get(sName)), "@{FFFF}/" + ucstring::makeFromUtf8(sCommandName),
"emote", "nb="+toString(nEmoteNb)+"|behav="+toString(nBehav), "emote", "nb="+toString(nEmoteNb)+"|behav="+toString(nBehav),
"", "", "", false, false, true); "", "", "", false, false, true);