From b11da90cbb868c952e956e6fb9e78b9d8e6b2b7c Mon Sep 17 00:00:00 2001 From: niansa Date: Thu, 12 Mar 2026 01:54:50 +0100 Subject: [PATCH] Added string conversion for Iggy everywhere where needed --- .../Common/UI/UIComponent_Tooltips.cpp | 6 +- .../Platform/Common/UI/UIControl_Base.cpp | 23 ++++--- .../Common/UI/UIControl_BitmapIcon.cpp | 6 +- .../Platform/Common/UI/UIControl_Button.cpp | 6 +- .../Common/UI/UIControl_ButtonList.cpp | 12 ++-- .../Platform/Common/UI/UIControl_CheckBox.cpp | 6 +- .../Platform/Common/UI/UIControl_DLCList.cpp | 6 +- .../Common/UI/UIControl_DynamicLabel.cpp | 8 ++- .../Platform/Common/UI/UIControl_Label.cpp | 7 ++- .../Common/UI/UIControl_LeaderboardList.cpp | 62 ++++++++++++------- .../Common/UI/UIControl_PlayerList.cpp | 6 +- .../Platform/Common/UI/UIControl_Progress.cpp | 8 ++- .../Platform/Common/UI/UIControl_SaveList.cpp | 24 ++++--- .../Platform/Common/UI/UIControl_Slider.cpp | 6 +- .../Common/UI/UIControl_SpaceIndicatorBar.cpp | 8 ++- .../Common/UI/UIControl_TextInput.cpp | 6 +- .../Common/UI/UIControl_TexturePackList.cpp | 12 ++-- .../Platform/Common/UI/UIScene.cpp | 4 +- .../Platform/Common/UI/UIScene_AnvilMenu.cpp | 6 +- .../Platform/Common/UI/UIScene_Credits.cpp | 6 +- .../Platform/Common/UI/UIScene_EndPoem.cpp | 8 ++- .../Platform/Common/UI/UIScene_HUD.cpp | 15 +++-- .../Platform/Common/UI/UIScene_HowToPlay.cpp | 9 ++- .../Common/UI/UIScene_InventoryMenu.cpp | 5 +- .../Platform/Common/UI/UIScene_Keyboard.cpp | 7 ++- .../Common/UI/UIScene_SkinSelectMenu.cpp | 22 ++++--- .../Common/UI/UIScene_TradingMenu.cpp | 6 +- Minecraft.World/Util/StringHelpers.cpp | 34 +++++++++- Minecraft.World/Util/StringHelpers.h | 1 + 29 files changed, 231 insertions(+), 104 deletions(-) diff --git a/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp b/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp index a7ee45f31..56e7ee85a 100644 --- a/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp @@ -319,11 +319,13 @@ void UIComponent_Tooltips::_SetTooltip(unsigned int iToolTipId, const std::wstri value[0].type = IGGY_DATATYPE_number; value[0].number = iToolTipId; + const std::u16string convLabel = convWstringToU16string(label); + value[1].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[1].string16 = stringVal; value[2].type = IGGY_DATATYPE_boolean; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp index c2fe3b924..4948c4a60 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp @@ -32,13 +32,15 @@ void UIControl_Base::tick() //app.DebugPrintf("Calling SetLabel - '%ls'\n", m_label.c_str()); m_bLabelChanged = false; + const std::u16string convLabel = convWstringToU16string(m_label); + IggyDataValue result; IggyDataValue value[1]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)m_label.c_str(); - stringVal.length = m_label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_setLabelFunc , 1 , value ); @@ -54,13 +56,15 @@ void UIControl_Base::setLabel(const std::wstring &label, bool instant, bool forc { m_bLabelChanged = false; + const std::u16string convLabel = convWstringToU16string(m_label); + IggyDataValue result; IggyDataValue value[1]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)m_label.c_str(); - stringVal.length = m_label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_setLabelFunc , 1 , value ); @@ -92,10 +96,13 @@ void UIControl_Base::setAllPossibleLabels(int labelCount, wchar_t labels[][256]) IggyDataValue *value = new IggyDataValue[labelCount]; IggyStringUTF16 * stringVal = new IggyStringUTF16[labelCount]; - for(unsigned int i = 0; i < labelCount; ++i) - { - stringVal[i].string = (IggyUTF16 *)labels[i]; - stringVal[i].length = wcslen(labels[i]); + std::vector conv; + conv.reserve(labelCount); + + for (int i = 0; i < labelCount; ++i) { + conv.push_back(convWstringToU16string(labels[i])); + stringVal[i].string = (IggyUTF16*)conv[i].c_str(); + stringVal[i].length = (S32)conv[i].length(); value[i].type = IGGY_DATATYPE_string_UTF16; value[i].string16 = stringVal[i]; } diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_BitmapIcon.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_BitmapIcon.cpp index 64486b095..d3c784383 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_BitmapIcon.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_BitmapIcon.cpp @@ -18,9 +18,11 @@ void UIControl_BitmapIcon::setTextureName(const std::wstring &iconName) IggyDataValue result; IggyDataValue value[1]; + const std::u16string convName = convWstringToU16string(iconName); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)iconName.c_str(); - stringVal.length = iconName.length(); + stringVal.string = (IggyUTF16*)convName.c_str(); + stringVal.length = convName.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_funcSetTextureName , 1 , value ); diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp index 141cea72a..bad06125c 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp @@ -22,13 +22,15 @@ void UIControl_Button::init(const std::wstring &label, int id) m_label = label; m_id = id; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[2]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; value[1].type = IGGY_DATATYPE_number; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_ButtonList.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_ButtonList.cpp index d8f60b097..95a8b9fa1 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_ButtonList.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_ButtonList.cpp @@ -98,9 +98,11 @@ void UIControl_ButtonList::addItem(const std::wstring &label, int data) IggyDataValue result; IggyDataValue value[2]; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; @@ -151,9 +153,11 @@ void UIControl_ButtonList::setButtonLabel(int iButtonId, const std::wstring &lab value[0].type = IGGY_DATATYPE_number; value[0].number = iButtonId; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[1].type = IGGY_DATATYPE_string_UTF16; value[1].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcSetButtonLabel, 2 , value ); diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp index 0aaa4eb27..4c7d02c24 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp @@ -27,13 +27,15 @@ void UIControl_CheckBox::init(const std::wstring &label, int id, bool checked) m_id = id; m_bChecked = checked; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[3]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; value[1].type = IGGY_DATATYPE_number; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_DLCList.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_DLCList.cpp index 1550d895a..0c133f341 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_DLCList.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_DLCList.cpp @@ -39,9 +39,11 @@ void UIControl_DLCList::addItem(const std::wstring &label, bool showTick, int iI IggyDataValue result; IggyDataValue value[3]; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16 *)label.c_str(); - stringVal.length = (S32)label.length(); + stringVal.string = (IggyUTF16 *)convLabel.c_str(); + stringVal.length = (S32)convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_DynamicLabel.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_DynamicLabel.cpp index a8e433279..28f273988 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_DynamicLabel.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_DynamicLabel.cpp @@ -22,12 +22,14 @@ bool UIControl_DynamicLabel::setupControl(UIScene *scene, IggyValuePath *parent, void UIControl_DynamicLabel::addText(const std::wstring &text, bool bLastEntry) { + const std::u16string convText = convWstringToU16string(text); + IggyDataValue result; IggyDataValue value[2]; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)text.c_str(); - stringVal.length = text.length(); + stringVal.string = (IggyUTF16*)convText.c_str(); + stringVal.length = convText.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; @@ -95,4 +97,4 @@ S32 UIControl_DynamicLabel::GetRealHeight() iRealHeight = (S32)result.number; } return iRealHeight; -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Label.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Label.cpp index cf42a2778..1f43dfe39 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Label.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Label.cpp @@ -21,13 +21,15 @@ void UIControl_Label::init(const std::wstring &label) { m_label = label; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[1]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_initFunc , 1 , value ); } @@ -35,6 +37,7 @@ void UIControl_Label::init(const std::wstring &label) void UIControl_Label::init(const std::string &label) { m_label = convStringToWstring(label); + IggyDataValue result; IggyDataValue value[1]; value[0].type = IGGY_DATATYPE_string_UTF8; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_LeaderboardList.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_LeaderboardList.cpp index dabbe9beb..64c4c55bb 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_LeaderboardList.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_LeaderboardList.cpp @@ -53,15 +53,19 @@ void UIControl_LeaderboardList::setupTitles(const std::wstring &rank, const std: IggyDataValue result; IggyDataValue value[2]; + const std::u16string convRank = convWstringToU16string(rank); + IggyStringUTF16 stringVal0; - stringVal0.string = (IggyUTF16*)rank.c_str(); - stringVal0.length = rank.length(); + stringVal0.string = (IggyUTF16*)convRank.c_str(); + stringVal0.length = convRank.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal0; + const std::u16string convGamertag = convWstringToU16string(gamertag); + IggyStringUTF16 stringVal1; - stringVal1.string = (IggyUTF16*)gamertag.c_str(); - stringVal1.length = gamertag.length(); + stringVal1.string = (IggyUTF16*)convGamertag.c_str(); + stringVal1.length = convGamertag.length(); value[1].type = IGGY_DATATYPE_string_UTF16; value[1].string16 = stringVal1; @@ -125,18 +129,22 @@ void UIControl_LeaderboardList::addDataSet(bool bLast, int iId, int iRank, const value[2].type = IGGY_DATATYPE_number; value[2].number = iRank; + const std::u16string convGamertag = convWstringToU16string(gamertag); + IggyStringUTF16 stringVal0; - stringVal0.string = (IggyUTF16*)gamertag.c_str(); - stringVal0.length = gamertag.length(); + stringVal0.string = (IggyUTF16*)convGamertag.c_str(); + stringVal0.length = convGamertag.length(); value[3].type = IGGY_DATATYPE_string_UTF16; value[3].string16 = stringVal0; value[4].type = IGGY_DATATYPE_boolean; value[4].boolval = bDisplayMessage; + const std::u16string convCol0 = convWstringToU16string(col0); + IggyStringUTF16 stringVal1; - stringVal1.string = (IggyUTF16*)col0.c_str(); - stringVal1.length = col0.length(); + stringVal1.string = (IggyUTF16*)convCol0.c_str(); + stringVal1.length = convCol0.length(); value[5].type = IGGY_DATATYPE_string_UTF16; value[5].string16 = stringVal1; @@ -146,9 +154,11 @@ void UIControl_LeaderboardList::addDataSet(bool bLast, int iId, int iRank, const } else { + const std::u16string convCol1 = convWstringToU16string(col1); + IggyStringUTF16 stringVal2; - stringVal2.string = (IggyUTF16*)col1.c_str(); - stringVal2.length = col1.length(); + stringVal2.string = (IggyUTF16*)convCol1.c_str(); + stringVal2.length = convCol1.length(); value[6].type = IGGY_DATATYPE_string_UTF16; value[6].string16 = stringVal2; } @@ -159,9 +169,11 @@ void UIControl_LeaderboardList::addDataSet(bool bLast, int iId, int iRank, const } else { + const std::u16string convCol2 = convWstringToU16string(col2); + IggyStringUTF16 stringVal3; - stringVal3.string = (IggyUTF16*)col2.c_str(); - stringVal3.length = col2.length(); + stringVal3.string = (IggyUTF16*)convCol2.c_str(); + stringVal3.length = convCol2.length(); value[7].type = IGGY_DATATYPE_string_UTF16; value[7].string16 = stringVal3; } @@ -172,9 +184,11 @@ void UIControl_LeaderboardList::addDataSet(bool bLast, int iId, int iRank, const } else { + const std::u16string convCol3 = convWstringToU16string(col3); + IggyStringUTF16 stringVal4; - stringVal4.string = (IggyUTF16*)col3.c_str(); - stringVal4.length = col3.length(); + stringVal4.string = (IggyUTF16*)convCol3.c_str(); + stringVal4.length = convCol3.length(); value[8].type = IGGY_DATATYPE_string_UTF16; value[8].string16 = stringVal4; } @@ -185,9 +199,11 @@ void UIControl_LeaderboardList::addDataSet(bool bLast, int iId, int iRank, const } else { + const std::u16string convCol4 = convWstringToU16string(col4); + IggyStringUTF16 stringVal5; - stringVal5.string = (IggyUTF16*)col4.c_str(); - stringVal5.length = col4.length(); + stringVal5.string = (IggyUTF16*)convCol4.c_str(); + stringVal5.length = convCol4.length(); value[9].type = IGGY_DATATYPE_string_UTF16; value[9].string16 = stringVal5; } @@ -198,9 +214,11 @@ void UIControl_LeaderboardList::addDataSet(bool bLast, int iId, int iRank, const } else { + const std::u16string convCol5 = convWstringToU16string(col5); + IggyStringUTF16 stringVal6; - stringVal6.string = (IggyUTF16*)col5.c_str(); - stringVal6.length = col5.length(); + stringVal6.string = (IggyUTF16*)convCol5.c_str(); + stringVal6.length = convCol5.length(); value[10].type = IGGY_DATATYPE_string_UTF16; value[10].string16 = stringVal6; } @@ -211,9 +229,11 @@ void UIControl_LeaderboardList::addDataSet(bool bLast, int iId, int iRank, const } else { + const std::u16string convCol6 = convWstringToU16string(col6); + IggyStringUTF16 stringVal7; - stringVal7.string = (IggyUTF16*)col6.c_str(); - stringVal7.length = col6.length(); + stringVal7.string = (IggyUTF16*)convCol6.c_str(); + stringVal7.length = convCol6.length(); value[11].type = IGGY_DATATYPE_string_UTF16; value[11].string16 = stringVal7; } @@ -235,4 +255,4 @@ void UIControl_LeaderboardList::SetTouchFocus(S32 iX, S32 iY, bool bRepeat) IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie(), &result, getIggyValuePath(), m_funcSetTouchFocus, 3 , value ); } -#endif \ No newline at end of file +#endif diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_PlayerList.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_PlayerList.cpp index 1609f4862..4dec188ed 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_PlayerList.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_PlayerList.cpp @@ -19,9 +19,11 @@ void UIControl_PlayerList::addItem(const std::wstring &label, int iPlayerIcon, i IggyDataValue result; IggyDataValue value[4]; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = (S32)label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = (S32)convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp index ec0efc1dd..8f0da8be5 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp @@ -31,13 +31,15 @@ void UIControl_Progress::init(const std::wstring &label, int id, int min, int ma m_max = max; m_current = current; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[1]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_initFunc , 1 , value ); @@ -81,4 +83,4 @@ void UIControl_Progress::showBar(bool show) value[0].boolval = show; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_showBarFunc , 1 , value ); } -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_SaveList.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_SaveList.cpp index 1ce95228c..ff9353300 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_SaveList.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_SaveList.cpp @@ -59,9 +59,11 @@ void UIControl_SaveList::addItem(const std::string &label, const std::wstring &i value[1].type = IGGY_DATATYPE_number; value[1].number = m_itemCount; + const std::u16string convName = convWstringToU16string(iconName); + IggyStringUTF16 stringVal2; - stringVal2.string = (IggyUTF16*)iconName.c_str(); - stringVal2.length = iconName.length(); + stringVal2.string = (IggyUTF16*)convName.c_str(); + stringVal2.length = convName.length(); value[2].type = IGGY_DATATYPE_string_UTF16; value[2].string16 = stringVal2; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_addNewItemFunc , 3 , value ); @@ -72,18 +74,22 @@ void UIControl_SaveList::addItem(const std::wstring &label, const std::wstring & IggyDataValue result; IggyDataValue value[3]; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = (S32)label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = (S32)convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; value[1].type = IGGY_DATATYPE_number; value[1].number = m_itemCount; + const std::u16string convName = convWstringToU16string(iconName); + IggyStringUTF16 stringVal2; - stringVal2.string = (IggyUTF16*)iconName.c_str(); - stringVal2.length = iconName.length(); + stringVal2.string = (IggyUTF16*)convName.c_str(); + stringVal2.length = convName.length(); value[2].type = IGGY_DATATYPE_string_UTF16; value[2].string16 = stringVal2; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_addNewItemFunc , 3 , value ); @@ -97,9 +103,11 @@ void UIControl_SaveList::setTextureName(int iId, const std::wstring &iconName) value[0].type = IGGY_DATATYPE_number; value[0].number = iId; + const std::u16string convName = convWstringToU16string(iconName); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)iconName.c_str(); - stringVal.length = iconName.length(); + stringVal.string = (IggyUTF16*)convName.c_str(); + stringVal.length = convName.length(); value[1].type = IGGY_DATATYPE_string_UTF16; value[1].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_funcSetTextureName , 2 , value ); diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp index cf9581489..6e5bb0596 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp @@ -30,13 +30,15 @@ void UIControl_Slider::init(const std::wstring &label, int id, int min, int max, m_max = max; m_current = current; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[5]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; value[1].type = IGGY_DATATYPE_number; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_SpaceIndicatorBar.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_SpaceIndicatorBar.cpp index d69b77a94..016bc8eb5 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_SpaceIndicatorBar.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_SpaceIndicatorBar.cpp @@ -31,13 +31,15 @@ void UIControl_SpaceIndicatorBar::init(const std::wstring &label, int id, __int6 m_min = min; m_max = max; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[1]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_initFunc , 1 , value ); @@ -119,4 +121,4 @@ void UIControl_SpaceIndicatorBar::setSaveGameOffset(float offset) value[0].type = IGGY_DATATYPE_number; value[0].number = m_currentOffset; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath() , m_setSaveGameOffsetFunc , 1 , value ); -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp index 32ee3ce4a..89074f69c 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp @@ -25,13 +25,15 @@ void UIControl_TextInput::init(const std::wstring &label, int id) m_label = label; m_id = id; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[2]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; value[1].type = IGGY_DATATYPE_number; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_TexturePackList.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_TexturePackList.cpp index b800fc182..502274c54 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_TexturePackList.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_TexturePackList.cpp @@ -28,13 +28,15 @@ void UIControl_TexturePackList::init(const std::wstring &label, int id) m_label = label; m_id = id; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[2]; value[0].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].string16 = stringVal; value[1].type = IGGY_DATATYPE_number; @@ -57,6 +59,8 @@ void UIControl_TexturePackList::init(const std::wstring &label, int id) void UIControl_TexturePackList::addPack(int id, const std::wstring &textureName) { + const std::u16string convName = convWstringToU16string(textureName); + IggyDataValue result; IggyDataValue value[2]; value[0].type = IGGY_DATATYPE_number; @@ -65,8 +69,8 @@ void UIControl_TexturePackList::addPack(int id, const std::wstring &textureName) value[1].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)textureName.c_str(); - stringVal.length = textureName.length(); + stringVal.string = (IggyUTF16*)convName.c_str(); + stringVal.length = convName.length(); value[1].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( m_parentScene->getMovie() , &result, getIggyValuePath(), m_addPackFunc ,2 , value ); } diff --git a/Minecraft.Client/Platform/Common/UI/UIScene.cpp b/Minecraft.Client/Platform/Common/UI/UIScene.cpp index b983fd8e1..30e2a012f 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene.cpp @@ -507,7 +507,9 @@ IggyName UIScene::registerFastName(const std::wstring &name) } else { - var = IggyPlayerCreateFastName ( getMovie() , (IggyUTF16 *)name.c_str() , -1 ); + const std::u16string convName = convWstringToU16string(name); + var = IggyPlayerCreateFastName ( getMovie() , (IggyUTF16 *)convName.c_str() , -1 ); + m_fastNames[name] = var; } return var; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_AnvilMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_AnvilMenu.cpp index 1df13f057..97f5a25b4 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_AnvilMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_AnvilMenu.cpp @@ -360,9 +360,11 @@ void UIScene_AnvilMenu::setCostLabel(const std::wstring &label, bool canAfford) IggyDataValue result; IggyDataValue value[2]; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_Credits.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_Credits.cpp index 6c5f0aff2..74fbde892 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_Credits.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_Credits.cpp @@ -642,9 +642,11 @@ void UIScene_Credits::setNextLabel(const std::wstring &label, ECreditTextTypes s IggyDataValue result; IggyDataValue value[3]; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_EndPoem.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_EndPoem.cpp index 5f626b912..419eb2164 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_EndPoem.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_EndPoem.cpp @@ -126,9 +126,11 @@ void UIScene_EndPoem::tick() IggyDataValue result; IggyDataValue value[3]; + const std::u16string convLabel = convWstringToU16string(label); + IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; @@ -268,4 +270,4 @@ void UIScene_EndPoem::updateNoise() found=(int)noiseString.find(tag,found+1); } -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_HUD.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_HUD.cpp index e73b6bebd..58761023e 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_HUD.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_HUD.cpp @@ -534,9 +534,10 @@ void UIScene_HUD::SetDragonLabel(const std::wstring &label) { IggyDataValue result; IggyDataValue value[1]; + const std::u16string convLabel = convWstringToU16string(label); IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetDragonLabel , 1 , value ); @@ -564,9 +565,10 @@ void UIScene_HUD::SetSelectedLabel(const std::wstring &label) IggyDataValue result; IggyDataValue value[1]; + const std::u16string convLabel = convWstringToU16string(label); IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetSelectedLabel , 1 , value ); @@ -739,8 +741,9 @@ void UIScene_HUD::SetDisplayName(const std::wstring &displayName) IggyDataValue result; IggyDataValue value[1]; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)displayName.c_str(); - stringVal.length = displayName.length(); + const std::u16string convName = convWstringToU16string(displayName); + stringVal.string = (IggyUTF16*)convName.c_str(); + stringVal.length = convName.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; IggyResult out = IggyPlayerCallMethodRS ( getMovie() , &result, IggyPlayerRootPath( getMovie() ), m_funcSetDisplayName , 1 , value ); diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_HowToPlay.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_HowToPlay.cpp index eb8aa15f6..027b669de 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_HowToPlay.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_HowToPlay.cpp @@ -305,10 +305,15 @@ void UIScene_HowToPlay::StartPage( EHowToPlayPage ePage ) value[0].type = IGGY_DATATYPE_number; value[0].number = gs_pageToFlashMapping[(int)ePage]; + std::vector conv; + conv.reserve(paragraphs.size()); + for(unsigned int i = 0; i < paragraphs.size(); ++i) { - stringVal[i].string = (IggyUTF16 *)paragraphs[i].c_str(); - stringVal[i].length = paragraphs[i].length(); + conv.push_back(convWstringToU16string(paragraphs[i])); + + stringVal[i].string = (IggyUTF16 *)conv[i].c_str(); + stringVal[i].length = conv[i].length(); value[i+1].type = IGGY_DATATYPE_string_UTF16; value[i+1].string16 = stringVal[i]; } diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_InventoryMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_InventoryMenu.cpp index e400222eb..60b327fb1 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_InventoryMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_InventoryMenu.cpp @@ -302,9 +302,10 @@ void UIScene_InventoryMenu::updateEffectsDisplay() value[0].type = IGGY_DATATYPE_number; value[0].number = icon; + const std::u16string convString = convWstringToU16string(effectString); IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)effectString.c_str(); - stringVal.length = effectString.length(); + stringVal.string = (IggyUTF16*)convString.c_str(); + stringVal.length = convString.length(); value[1].type = IGGY_DATATYPE_string_UTF16; value[1].string16 = stringVal; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_Keyboard.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_Keyboard.cpp index a54e7daf8..832db8031 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_Keyboard.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_Keyboard.cpp @@ -26,8 +26,9 @@ UIScene_Keyboard::UIScene_Keyboard(int iPad, void *initData, UILayer *parentLaye // Initialise function keyboard Buttons and set alternative symbol button string std::wstring label = L"Abc"; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + const std::u16string convLabel = convWstringToU16string(label); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); IggyDataValue result; IggyDataValue value[1]; @@ -178,4 +179,4 @@ void UIScene_Keyboard::KeyboardDonePressed() // ToDo: Keyboard can now pass on its final string value and close itself down navigateBack(); -} \ No newline at end of file +} diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp index f1a9f929c..f1551f9b6 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_SkinSelectMenu.cpp @@ -1362,14 +1362,16 @@ void UIScene_SkinSelectMenu::setLeftLabel(const std::wstring &label) { if(label.compare(m_leftLabel) != 0) { - m_leftLabel = label; + m_leftLabel = label; + + const std::u16string convLabel = convWstringToU16string(label); IggyDataValue result; IggyDataValue value[1]; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; @@ -1381,14 +1383,16 @@ void UIScene_SkinSelectMenu::setCentreLabel(const std::wstring &label) { if(label.compare(m_centreLabel) != 0) { - m_centreLabel = label; + m_centreLabel = label; + + const std::u16string convLabel = convWstringToU16string(label); IggyDataValue result; IggyDataValue value[1]; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; @@ -1402,12 +1406,14 @@ void UIScene_SkinSelectMenu::setRightLabel(const std::wstring &label) { m_rightLabel = label; + const std::u16string convLabel = convWstringToU16string(label); + IggyDataValue result; IggyDataValue value[1]; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)label.c_str(); - stringVal.length = label.length(); + stringVal.string = (IggyUTF16*)convLabel.c_str(); + stringVal.length = convLabel.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_TradingMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_TradingMenu.cpp index 66d2ef7aa..d446b2368 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_TradingMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_TradingMenu.cpp @@ -255,12 +255,14 @@ void UIScene_TradingMenu::setTradeRedBox(int index, bool show) void UIScene_TradingMenu::setOfferDescription(const std::wstring &name, std::vector &unformattedStrings) { + const std::u16string convName = convWstringToU16string(name); + IggyDataValue result; IggyDataValue value[1]; IggyStringUTF16 stringVal; - stringVal.string = (IggyUTF16*)name.c_str(); - stringVal.length = name.length(); + stringVal.string = (IggyUTF16*)convName.c_str(); + stringVal.length = convName.length(); value[0].type = IGGY_DATATYPE_string_UTF16; value[0].string16 = stringVal; diff --git a/Minecraft.World/Util/StringHelpers.cpp b/Minecraft.World/Util/StringHelpers.cpp index 12bfbfeda..34bd2b551 100644 --- a/Minecraft.World/Util/StringHelpers.cpp +++ b/Minecraft.World/Util/StringHelpers.cpp @@ -46,6 +46,38 @@ std::wstring convStringToWstring(const std::string& converting) return converted; } +std::u16string convWstringToU16string(const std::wstring& converting) { + std::u16string out; + out.reserve(converting.size()); + + if constexpr (sizeof(wchar_t) == sizeof(char16_t)) { + // wchar_t is UTF-16: direct copy + out.assign(converting.begin(), converting.end()); + } else { + // wchar_t is UTF-32: encode to UTF-16 + for (wchar_t wc : converting) { + uint32_t cp = static_cast(wc); + + if (cp <= 0xFFFF) { + // Avoid producing UTF-16 surrogate code points directly + if (cp >= 0xD800 && cp <= 0xDFFF) { + out.push_back(u'\uFFFD'); // replacement char + } else { + out.push_back(static_cast(cp)); + } + } else if (cp <= 0x10FFFF) { + cp -= 0x10000; + out.push_back(static_cast(0xD800 + (cp >> 10))); + out.push_back(static_cast(0xDC00 + (cp & 0x3FF))); + } else { + out.push_back(u'\uFFFD'); // invalid code point + } + } + } + + return out; +} + // Convert for filename std::wstrings to a straight character pointer for Xbox APIs. The returned string is only valid until // this function is called again, and it isn't thread-safe etc. as I'm just storing the returned name in a local static // to save having to clear it up everywhere this is used. @@ -130,4 +162,4 @@ std::wstring parseXMLSpecials(const std::wstring &in) out = replaceAll(out, L"<", L"<"); out = replaceAll(out, L">", L">"); return out; -} \ No newline at end of file +} diff --git a/Minecraft.World/Util/StringHelpers.h b/Minecraft.World/Util/StringHelpers.h index 73092ef69..1afe233bc 100644 --- a/Minecraft.World/Util/StringHelpers.h +++ b/Minecraft.World/Util/StringHelpers.h @@ -29,6 +29,7 @@ template T _fromHEXString(const std::wstring& s) } std::wstring convStringToWstring(const std::string& converting); +std::u16string convWstringToU16string(const std::wstring& converting); const char *wstringtofilename(const std::wstring& name); std::wstring filenametowstring(const char *name);