Change CDBGroupComboBox to UTF-8, ryzom/ryzomcore#335

develop
kaetemi 4 years ago
parent 506f9f26bd
commit e1195fe34e

@ -60,13 +60,15 @@ namespace NLGUI
// Combo Texts
void resetTexts();
void addText(const ucstring &text);
void setText(uint i, const ucstring &text);
void insertText(uint i, const ucstring &text);
const ucstring &getText(uint i) const;
void addText(const std::string &text);
void setText(uint i, const std::string &text);
void insertText(uint i, const std::string &text);
const std::string &getText(uint i) const;
ucstring getTextAsUtf16(uint i) const;
uint getTextId(uint i) const;
uint getTextPos(uint nId) const;
const ucstring &getTexture(uint i) const;
const std::string &getTexture(uint i) const;
ucstring getTextureAsUtf16(uint i) const;
void setGrayed(uint i, bool g);
bool getGrayed(uint i) const;
void removeText(uint nPos);
@ -87,11 +89,13 @@ namespace NLGUI
std::string getSelectionText() const;
// view text
void setViewText(const ucstring & text);
ucstring getViewText() const;
void setViewText(const std::string & text);
std::string getViewText() const;
void setViewTextAsUtf16(const ucstring &text) { setViewText(text.toUtf8()); }
ucstring getViewTextAsUtf16() const;
CViewText *getViewText();
void setTexture(uint i, const ucstring &texture);
void setTexture(uint i, const std::string &texture);
sint32 evalContentWidth() const;
@ -122,7 +126,7 @@ namespace NLGUI
REFLECT_LUA_METHOD("resetTexts", luaResetTexts)
REFLECT_SINT32 ("selectionNb", getSelectionNb, setSelectionNb)
REFLECT_STRING ("selection_text", getSelectionText, setSelectionText)
REFLECT_UCSTRING ("view_text", getViewText, setViewText)
REFLECT_UCSTRING ("view_text", getViewTextAsUtf16, setViewTextAsUtf16) // FIXME: Better to have UTF-8
REFLECT_EXPORT_END
@ -137,8 +141,8 @@ namespace NLGUI
// sint32
CInterfaceProperty _Selection;
sint32 _NotLinkedToDBSelection;
std::vector<std::pair<uint, ucstring> > _Texts;
std::vector<ucstring> _Textures;
std::vector<std::pair<uint, std::string> > _Texts;
std::vector<std::string> _Textures;
std::vector<bool> _Grayed;
// Action Handler called on combo click
@ -155,7 +159,7 @@ namespace NLGUI
CCtrlBaseButton *_SelectButton;
bool _IsExternViewText;
ucstring _ExternViewText;
std::string _ExternViewText;
private:

@ -43,9 +43,9 @@ namespace NLGUI
void force_link_dbgroup_combo_box_cpp() { }
// Compare strings
static inline bool lt_text(const std::pair<int,ucstring> &s1, const std::pair<int,ucstring> &s2)
static inline bool lt_text(const std::pair<int,std::string> &s1, const std::pair<int,std::string> &s2)
{
return toLower(s1.second) < toLower(s2.second);
return toLowerAsUtf8(s1.second) < toLowerAsUtf8(s2.second);
}
std::string CDBGroupComboBox::measureMenu;
@ -183,10 +183,10 @@ namespace NLGUI
if (name)
{
const char *propPtr = name;
ucstring Text = ucstring::makeFromUtf8(propPtr);
if ((strlen(propPtr)>2) && (propPtr[0] == 'u') && (propPtr[1] == 'i'))
Text = CI18N::get (propPtr);
addText(Text);
if (NLMISC::startsWith(propPtr, "ui"))
addText(CI18N::get(propPtr).toUtf8());
else
addText(propPtr);
}
}
child = child->next;
@ -240,11 +240,11 @@ namespace NLGUI
}
else if(_IsExternViewText)
{
_ViewText->setText(_ExternViewText.toUtf8());
_ViewText->setText(_ExternViewText);
}
else
{
_ViewText->setText(_Texts[_CacheSelection].second.toUtf8());
_ViewText->setText(_Texts[_CacheSelection].second);
}
}
}
@ -274,7 +274,7 @@ namespace NLGUI
}
// ***************************************************************************
void CDBGroupComboBox::addText(const ucstring &text)
void CDBGroupComboBox::addText(const std::string &text)
{
dirt();
_Texts.push_back(make_pair((uint)_Texts.size(), text));
@ -283,7 +283,7 @@ namespace NLGUI
}
// ***************************************************************************
void CDBGroupComboBox::setText(uint i, const ucstring &text)
void CDBGroupComboBox::setText(uint i, const std::string &text)
{
dirt();
if(i<_Texts.size())
@ -291,7 +291,7 @@ namespace NLGUI
}
// ***************************************************************************
void CDBGroupComboBox::insertText(uint i, const ucstring &text)
void CDBGroupComboBox::insertText(uint i, const std::string &text)
{
dirt();
if(i<_Texts.size())
@ -313,7 +313,7 @@ namespace NLGUI
}
// ***************************************************************************
void CDBGroupComboBox::setTexture(uint i, const ucstring &texture)
void CDBGroupComboBox::setTexture(uint i, const std::string &texture)
{
dirt();
if(i<_Textures.size())
@ -351,13 +351,19 @@ namespace NLGUI
}
// ***************************************************************************
const ucstring &CDBGroupComboBox::getText(uint i) const
const std::string &CDBGroupComboBox::getText(uint i) const
{
static ucstring null;
if(i<_Texts.size())
static const std::string empty;
if (i < _Texts.size())
return _Texts[i].second;
else
return null;
return empty;
}
// ***************************************************************************
ucstring CDBGroupComboBox::getTextAsUtf16(uint i) const
{
return ucstring::makeFromUtf8(getText(i));
}
// ***************************************************************************
@ -385,15 +391,21 @@ namespace NLGUI
{
sort(_Texts.begin(), _Texts.end(), lt_text);
}
// ***************************************************************************
const ucstring &CDBGroupComboBox::getTexture(uint i) const
const std::string &CDBGroupComboBox::getTexture(uint i) const
{
static ucstring null;
if(i<_Textures.size())
static const std::string empty;
if (i < _Textures.size())
return _Textures[i];
else
return null;
return empty;
}
// ***************************************************************************
ucstring CDBGroupComboBox::getTextureAsUtf16(uint i) const
{
return ucstring::makeFromUtf8(getTexture(i));
}
// ***************************************************************************
@ -452,8 +464,7 @@ namespace NLGUI
sint32 value;
for(uint i=0; i<getNumTexts(); i++)
{
std::string sText;
getText(i).toString(sText);
std::string sText = getText(i);
if(sText == val)
{
value = i;
@ -464,15 +475,21 @@ namespace NLGUI
}
// ***************************************************************************
void CDBGroupComboBox::setViewText(const ucstring & text)
void CDBGroupComboBox::setViewText(const std::string &text)
{
_IsExternViewText = true;
_ExternViewText = text;
_ViewText->setText(_ExternViewText.toUtf8());
_ViewText->setText(_ExternViewText);
}
// ***************************************************************************
ucstring CDBGroupComboBox::getViewText() const
std::string CDBGroupComboBox::getViewText() const
{
return _ViewText->getText();
}
// ***************************************************************************
ucstring CDBGroupComboBox::getViewTextAsUtf16() const
{
return CUtfStringView(_ViewText->getText()).toUtf16();
}
@ -486,18 +503,14 @@ namespace NLGUI
// ***************************************************************************
std::string CDBGroupComboBox::getSelectionText() const
{
ucstring text;
if (_LinkedToDB)
{
text = getText(_Selection.getSInt32());
return getText(_Selection.getSInt32());
}
else
{
text = getText(_NotLinkedToDBSelection);
return getText(_NotLinkedToDBSelection);
}
std::string texteS;
text.toString(texteS);
return texteS;
}
// ***************************************************************************
@ -538,8 +551,7 @@ namespace NLGUI
sint32 value;
for(uint i=0; i<getNumTexts(); i++)
{
std::string sText;
getText(i).toString(sText);
std::string sText = getText(i);
if(sText == text)
{
value = i;
@ -566,7 +578,7 @@ namespace NLGUI
CLuaIHM::checkArgTypeUCString(ls, funcName, 1);
ucstring text;
nlverify(CLuaIHM::pop(ls, text));
addText(text);
addText(text.toUtf8()); // FIXME: Lua should just do UTF-8!
return 0;
}
@ -579,7 +591,7 @@ namespace NLGUI
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
ucstring text;
nlverify(CLuaIHM::pop(ls, text));
setText((uint) ls.toInteger(1), text);
setText((uint) ls.toInteger(1), text.toUtf8()); // FIXME: Lua should just do UTF-8!
return 0;
}
@ -592,7 +604,7 @@ namespace NLGUI
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
ucstring text;
nlverify(CLuaIHM::pop(ls, text));
insertText((uint) ls.toInteger(1), text);
insertText((uint) ls.toInteger(1), text.toUtf8()); // FIXME: Lua should just do UTF-8!
return 0;
}
@ -605,7 +617,7 @@ namespace NLGUI
CLuaIHM::checkArgTypeUCString(ls, funcName, 2);
ucstring texture;
nlverify(CLuaIHM::pop(ls, texture));
setTexture((uint) ls.toInteger(1), texture);
setTexture((uint) ls.toInteger(1), texture.toUtf8()); // FIXME: Lua should just do UTF-8!
return 0;
}
@ -625,7 +637,7 @@ namespace NLGUI
const char *funcName = "removeText";
CLuaIHM::checkArgCount(ls, funcName, 1);
CLuaIHM::checkArgType(ls, funcName, 1, LUA_TNUMBER);
removeText((uint) ls.toInteger(1));
removeText((uint)ls.toInteger(1));
return 0;
}
@ -652,12 +664,12 @@ namespace NLGUI
{
// set the id as the parameter
bool checkable = false;
if(getTexture(i).toString() != std::string())
if (getTexture(i) != std::string())
{
checkable = true;
}
groupMenu->addLine(getText(i), "combo_box_select_end", toString(i),
"", std::string(), getTexture(i).toString(), checkable);
groupMenu->addLine(ucstring::makeFromUtf8(getText(i)), "combo_box_select_end", toString(i),
"", std::string(), getTexture(i), checkable);
groupMenu->setGrayedLine(i, getGrayed(i));
}

@ -6437,7 +6437,7 @@ namespace NLGUI
if (cb)
{
uint lineIndex = cb->getNumTexts();
cb->addText(_SelectOptionStr);
cb->addText(_SelectOptionStr.toUtf8());
if (_Forms.back().Entries.back().sbOptionDisabled == lineIndex)
{
cb->setGrayed(lineIndex, true);

@ -3013,7 +3013,7 @@ void updateVRDevicesComboUI(bool enable)
{
std::stringstream displayname;
displayname << std::string("[") << VRDeviceCache[i].first << "] [" << VRDeviceCache[i].second << "]";
pCB->addText(ucstring(displayname.str()));
pCB->addText(displayname.str());
if (ClientCfg.VRDisplayDevice == VRDeviceCache[i].first)
{
if (selectedDevice == -1 || ClientCfg.VRDisplayDeviceId == VRDeviceCache[i].second)
@ -3027,7 +3027,7 @@ void updateVRDevicesComboUI(bool enable)
// configured device not found, add a dummy
std::stringstream displayname;
displayname << std::string("[") << ClientCfg.VRDisplayDevice << "] [" << ClientCfg.VRDisplayDeviceId<< "] [DEVICE NOT FOUND]";
pCB->addText(ucstring(displayname.str()));
pCB->addText(displayname.str());
selectedDevice = VRDeviceCache.size();
}
NLGUI::CDBManager::getInstance()->getDbProp(GAME_CONFIG_VR_DEVICE_DB)->setValue32(-1);
@ -3062,7 +3062,7 @@ public:
{
pCB->resetTexts();
for (sint j = 0; j < (sint)stringModeList.size(); j++)
pCB->addText(ucstring(stringModeList[j]));
pCB->addText(stringModeList[j]);
}
// frequencies
@ -3071,7 +3071,7 @@ public:
{
pCB->resetTexts();
for (sint j = 0; j < (sint)stringFreqList.size(); j++)
pCB->addText(ucstring(stringFreqList[j]));
pCB->addText(stringFreqList[j]);
}
// -1 is important to indicate we set this value in edit mode
@ -3094,10 +3094,10 @@ public:
if( pCB )
{
pCB->resetTexts();
pCB->addText(CI18N::get("uigcLowTextureMode"));
pCB->addText(CI18N::get("uigcNormalTextureMode"));
pCB->addText(CI18N::get("uigcLowTextureMode").toUtf8());
pCB->addText(CI18N::get("uigcNormalTextureMode").toUtf8());
if(ClientCfg.HDTextureInstalled)
pCB->addText(CI18N::get("uigcHighTextureMode"));
pCB->addText(CI18N::get("uigcHighTextureMode").toUtf8());
}
// Anisotropic Filtering
@ -3110,14 +3110,14 @@ public:
sint maxAnisotropic = (sint)Driver->getAnisotropicFilterMaximum();
pCB->resetTexts();
pCB->addText(CI18N::get("uigcFxAnisotropicFilterNone"));
pCB->addText(CI18N::get("uigcFxAnisotropicFilterNone").toUtf8());
sint anisotropic = 2;
uint i = 1;
while (anisotropic <= maxAnisotropic)
{
pCB->addText(ucstring(NLMISC::toString("%dx", anisotropic)));
pCB->addText(NLMISC::toString("%dx", anisotropic));
if (ClientCfg.AnisotropicFilter == anisotropic)
nAnisotropic = i;
@ -3222,7 +3222,7 @@ class CHandlerGameConfigMode : public IActionHandler
// Get W, H
sint w,h;
{
string vidModeStr = pCB->getText(nVideModeNb).toString();
string vidModeStr = pCB->getText(nVideModeNb);
string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1);
fromString(tmp, w);
tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size());
@ -3262,7 +3262,7 @@ class CHandlerGameConfigMode : public IActionHandler
{
pCB->resetTexts();
for (j = 0; j < (sint)stringFreqList.size(); j++)
pCB->addText(ucstring(stringFreqList[j]) + " Hz");
pCB->addText(stringFreqList[j] + " Hz");
}
NLGUI::CDBManager::getInstance()->getDbProp( GAME_CONFIG_VIDEO_FREQ_DB )->setValue32(nFoundFreq);
@ -3464,7 +3464,7 @@ class CHandlerGameConfigApply : public IActionHandler
CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_MODES_COMBO ));
if( pCB != NULL )
{
string vidModeStr = pCB->getText(nVideModeNb).toString();
string vidModeStr = pCB->getText(nVideModeNb);
string tmp = vidModeStr.substr(0,vidModeStr.find('x')-1);
fromString(tmp, w);
tmp = vidModeStr.substr(vidModeStr.find('x')+2,vidModeStr.size());
@ -3478,7 +3478,7 @@ class CHandlerGameConfigApply : public IActionHandler
CDBGroupComboBox *pCB = dynamic_cast<CDBGroupComboBox*>(CWidgetManager::getInstance()->getElementFromId( GAME_CONFIG_VIDEO_FREQS_COMBO ));
if( pCB != NULL )
{
string vidFreqStr = pCB->getText(nVideoFreqNb).toString();
string vidFreqStr = pCB->getText(nVideoFreqNb);
fromString(vidFreqStr, freq);
}
}

@ -2200,7 +2200,7 @@ static void setupRawMaterialStats(CSheetHelpSetup &setup)
if(pIS->canBuildItemPart(faberType))
{
pCB->addText(RM_FABER_TYPE::toLocalString(faberType));
pCB->addText(RM_FABER_TYPE::toLocalString(faberType).toUtf8());
}
}

@ -156,7 +156,7 @@ void CBotChatPageDynamicMission::update()
{
if (ClientCfg.Local)
{
_ChoiceCB[k]->setText(l, ucstring(toString("Dynamic mission %d:%d", (int) k, (int) l)));
_ChoiceCB[k]->setText(l, toString("Dynamic mission %d:%d", (int) k, (int) l));
_TextReceived[k][l] = true;
}
else
@ -167,7 +167,7 @@ void CBotChatPageDynamicMission::update()
bool received = CStringManagerClient::instance()->getDynString(textID, result);
if (received)
{
_ChoiceCB[k]->setText(l, result);
_ChoiceCB[k]->setText(l, result.toUtf8());
_TextReceived[k][l] = true;
}
}
@ -183,13 +183,13 @@ void CBotChatPageDynamicMission::update()
bool received = CStringManagerClient::instance()->getDynString(textID, result);
if (received)
{
_ChoiceCB[k]->addText(result);
_ChoiceCB[k]->addText(result.toUtf8());
_TextReceived[k][l] = true;
}
else
{
// add a text to show the player that the text is being received
_ChoiceCB[k]->addText(NLMISC::CI18N::get("uiWaitingChoiceFromServer"));
_ChoiceCB[k]->addText(NLMISC::CI18N::get("uiWaitingChoiceFromServer").toUtf8());
}
}
}

@ -492,7 +492,7 @@ void CModalContainerEditCmd::activate()
}
if (found)
{
pCB->addText( CI18N::get(rVCat[i].LocalizedName) );
pCB->addText(CI18N::get(rVCat[i].LocalizedName).toUtf8());
CurrentEditCmdCategories.push_back(rVCat[i].Name);
}
}
@ -1033,7 +1033,7 @@ void CModalContainerEditCmd::onChangeCategory()
{
if (rBA.isUsableInCurrentContext())
{
pCB->addText( CI18N::get(rBA.LocalizedName) );
pCB->addText(CI18N::get(rBA.LocalizedName).toUtf8());
}
}
}
@ -1130,11 +1130,10 @@ void CModalContainerEditCmd::onChangeAction()
if (ActionsContext.matchContext(rVal.Contexts))
{
if ((rVal.LocalizedValue.size() >= 2) &&
(rVal.LocalizedValue[0] == 'u') && (rVal.LocalizedValue[1] == 'i'))
pCB->addText(CI18N::get(rVal.LocalizedValue));
if (NLMISC::startsWith(rVal.LocalizedValue, "ui"))
pCB->addText(CI18N::get(rVal.LocalizedValue).toUtf8());
else
pCB->addText(ucstring(rVal.LocalizedValue));
pCB->addText(rVal.LocalizedValue);
}
}
}

@ -1097,7 +1097,7 @@ public:
string titleStr = CHARACTER_TITLE::toString((CHARACTER_TITLE::ECharacterTitle)i);
bool womenTitle = (UserEntity && UserEntity->getGender() == GSGENDER::female);
const ucstring s(CStringManagerClient::getTitleLocalizedName(titleStr,womenTitle));
pCB->addText(s);
pCB->addText(s.toUtf8());
pSM->_UIUnblockedTitles.push_back((CHARACTER_TITLE::ECharacterTitle)i);
}
}

Loading…
Cancel
Save