forked from 0ad/0ad
Partially support Unicode strings in GUI XML files
This was SVN commit r7594.
This commit is contained in:
parent
5b9d29729a
commit
4ff8d8742c
@ -1237,7 +1237,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
ManuallySetZ = true;
|
||||
|
||||
// Try setting the value
|
||||
if (object->SetSetting(pFile->GetAttributeString(attr.Name), CStr(attr.Value), true) != PSRETURN_OK)
|
||||
if (object->SetSetting(pFile->GetAttributeString(attr.Name), CStrW(attr.Value), true) != PSRETURN_OK)
|
||||
{
|
||||
LOGERROR(L"GUI: (object: %hs) Can't set \"%hs\" to \"%ls\"", object->GetPresentableName().c_str(), pFile->GetAttributeString(attr.Name).c_str(), CStrW(attr.Value).c_str());
|
||||
|
||||
|
@ -193,7 +193,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI* gui)
|
||||
}
|
||||
|
||||
// Clear the caption
|
||||
usedobj->SetSetting("caption", "");
|
||||
usedobj->SetSetting("caption", L"");
|
||||
usedobj->HandleMessage(SGUIMessage(GUIM_SETTINGS_UPDATED, "caption"));
|
||||
|
||||
|
||||
|
@ -161,7 +161,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
|
||||
{
|
||||
CSize displacement;
|
||||
// Parse the value
|
||||
if (!GUI<CSize>::ParseString(itTextChunk->m_Tags[0].m_TagAdditionalValue, displacement))
|
||||
if (!GUI<CSize>::ParseString(CStrW(itTextChunk->m_Tags[0].m_TagAdditionalValue), displacement))
|
||||
LOG(CLogger::Error, LOG_CATEGORY, L"Error parsing 'displace' value for tag [ICON]");
|
||||
else
|
||||
SpriteCall.m_Area += displacement;
|
||||
@ -207,7 +207,7 @@ void CGUIString::GenerateTextCall(SFeedback &Feedback,
|
||||
TextCall.m_UseCustomColor = true;
|
||||
|
||||
// Try parsing the color std::string
|
||||
if (!GUI<CColor>::ParseString(it2->m_TagValue, TextCall.m_Color))
|
||||
if (!GUI<CColor>::ParseString(CStrW(it2->m_TagValue), TextCall.m_Color))
|
||||
{
|
||||
if (pObject)
|
||||
LOG(CLogger::Error, LOG_CATEGORY, L"Error parsing the value of a [color]-tag in GUI text when reading object \"%hs\".", pObject->GetPresentableName().c_str());
|
||||
|
@ -32,12 +32,12 @@ extern int g_yres;
|
||||
|
||||
|
||||
template <>
|
||||
bool __ParseString<bool>(const CStr& Value, bool &Output)
|
||||
bool __ParseString<bool>(const CStrW& Value, bool &Output)
|
||||
{
|
||||
if (Value == "true")
|
||||
if (Value == L"true")
|
||||
Output = true;
|
||||
else
|
||||
if (Value == "false")
|
||||
if (Value == L"false")
|
||||
Output = false;
|
||||
else
|
||||
return false;
|
||||
@ -46,26 +46,26 @@ bool __ParseString<bool>(const CStr& Value, bool &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<int>(const CStr& Value, int &Output)
|
||||
bool __ParseString<int>(const CStrW& Value, int &Output)
|
||||
{
|
||||
Output = Value.ToInt();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<float>(const CStr& Value, float &Output)
|
||||
bool __ParseString<float>(const CStrW& Value, float &Output)
|
||||
{
|
||||
Output = Value.ToFloat();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CRect>(const CStr& Value, CRect &Output)
|
||||
bool __ParseString<CRect>(const CStrW& Value, CRect &Output)
|
||||
{
|
||||
// Use the parser to parse the values
|
||||
CParser& parser (CParserCache::Get("_$value_$value_$value_$value_"));
|
||||
|
||||
std::string str = Value;
|
||||
std::string str = CStr(Value);
|
||||
|
||||
CParserLine line;
|
||||
line.ParseString(parser, str);
|
||||
@ -90,13 +90,13 @@ bool __ParseString<CRect>(const CStr& Value, CRect &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CClientArea>(const CStr& Value, CClientArea &Output)
|
||||
bool __ParseString<CClientArea>(const CStrW& Value, CClientArea &Output)
|
||||
{
|
||||
return Output.SetClientArea(Value);
|
||||
}
|
||||
|
||||
template <>
|
||||
bool GUI<int>::ParseColor(const CStr& Value, CColor &Output, float DefaultAlpha)
|
||||
bool GUI<int>::ParseColor(const CStrW& Value, CColor &Output, float DefaultAlpha)
|
||||
{
|
||||
// First, check our database in g_GUI for pre-defined colors
|
||||
// If we find anything, we'll ignore DefaultAlpha
|
||||
@ -109,7 +109,7 @@ bool GUI<int>::ParseColor(const CStr& Value, CColor &Output, float DefaultAlpha)
|
||||
|
||||
|
||||
template <>
|
||||
bool __ParseString<CColor>(const CStr& Value, CColor &Output)
|
||||
bool __ParseString<CColor>(const CStrW& Value, CColor &Output)
|
||||
{
|
||||
// First, check our database in g_GUI for pre-defined colors
|
||||
// If it fails, it won't do anything with Output
|
||||
@ -120,12 +120,12 @@ bool __ParseString<CColor>(const CStr& Value, CColor &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CSize>(const CStr& Value, CSize &Output)
|
||||
bool __ParseString<CSize>(const CStrW& Value, CSize &Output)
|
||||
{
|
||||
// Use the parser to parse the values
|
||||
CParser& parser (CParserCache::Get("_$value_$value_"));
|
||||
|
||||
std::string str = Value;
|
||||
std::string str = CStr(Value);
|
||||
|
||||
CParserLine line;
|
||||
line.ParseString(parser, str);
|
||||
@ -158,12 +158,12 @@ bool __ParseString<CSize>(const CStr& Value, CSize &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CPos>(const CStr& Value, CPos &Output)
|
||||
bool __ParseString<CPos>(const CStrW& Value, CPos &Output)
|
||||
{
|
||||
CParser& parser (CParserCache::Get("_[-$arg(_minus)]$value_[-$arg(_minus)]$value_"));
|
||||
|
||||
CParserLine line;
|
||||
line.ParseString(parser, Value);
|
||||
line.ParseString(parser, CStr(Value));
|
||||
if (!line.m_ParseOK)
|
||||
return false;
|
||||
|
||||
@ -180,15 +180,15 @@ bool __ParseString<CPos>(const CStr& Value, CPos &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<EAlign>(const CStr& Value, EAlign &Output)
|
||||
bool __ParseString<EAlign>(const CStrW& Value, EAlign &Output)
|
||||
{
|
||||
if (Value == "left")
|
||||
if (Value == L"left")
|
||||
Output = EAlign_Left;
|
||||
else
|
||||
if (Value == "center")
|
||||
if (Value == L"center")
|
||||
Output = EAlign_Center;
|
||||
else
|
||||
if (Value == "right")
|
||||
if (Value == L"right")
|
||||
Output = EAlign_Right;
|
||||
else
|
||||
return false;
|
||||
@ -197,15 +197,15 @@ bool __ParseString<EAlign>(const CStr& Value, EAlign &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<EVAlign>(const CStr& Value, EVAlign &Output)
|
||||
bool __ParseString<EVAlign>(const CStrW& Value, EVAlign &Output)
|
||||
{
|
||||
if (Value == "top")
|
||||
if (Value == L"top")
|
||||
Output = EVAlign_Top;
|
||||
else
|
||||
if (Value == "center")
|
||||
if (Value == L"center")
|
||||
Output = EVAlign_Center;
|
||||
else
|
||||
if (Value == "bottom")
|
||||
if (Value == L"bottom")
|
||||
Output = EVAlign_Bottom;
|
||||
else
|
||||
return false;
|
||||
@ -214,17 +214,16 @@ bool __ParseString<EVAlign>(const CStr& Value, EVAlign &Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CGUIString>(const CStr& Value, CGUIString &Output)
|
||||
bool __ParseString<CGUIString>(const CStrW& Value, CGUIString &Output)
|
||||
{
|
||||
// Translate the Value and retrieve the localised string in
|
||||
// Unicode.
|
||||
// TODO: i18n: Might want to translate the Value perhaps
|
||||
|
||||
Output.SetValue(I18n::translate((CStrW)Value));
|
||||
Output.SetValue(Value);
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CStr>(const CStr& Value, CStr&Output)
|
||||
bool __ParseString<CStr>(const CStrW& Value, CStr& Output)
|
||||
{
|
||||
// Do very little.
|
||||
Output = Value;
|
||||
@ -232,24 +231,23 @@ bool __ParseString<CStr>(const CStr& Value, CStr&Output)
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CStrW>(const CStr& Value, CStrW& Output)
|
||||
bool __ParseString<CStrW>(const CStrW& Value, CStrW& Output)
|
||||
{
|
||||
// Translate the Value and retrieve the localised string in
|
||||
// Unicode.
|
||||
// TODO: i18n: Might want to translate the Value perhaps
|
||||
|
||||
Output = I18n::translate((CStrW)Value);
|
||||
Output = Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CGUISpriteInstance>(const CStr& Value, CGUISpriteInstance &Output)
|
||||
bool __ParseString<CGUISpriteInstance>(const CStrW& Value, CGUISpriteInstance &Output)
|
||||
{
|
||||
Output = Value;
|
||||
return true;
|
||||
}
|
||||
|
||||
template <>
|
||||
bool __ParseString<CGUIList>(const CStr& UNUSED(Value), CGUIList& UNUSED(Output))
|
||||
bool __ParseString<CGUIList>(const CStrW& UNUSED(Value), CGUIList& UNUSED(Output))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -52,7 +52,7 @@ class CClientArea;
|
||||
class CGUIString;
|
||||
|
||||
template <typename T>
|
||||
bool __ParseString(const CStr& Value, T &tOutput);
|
||||
bool __ParseString(const CStrW& Value, T &tOutput);
|
||||
|
||||
// Load Identity matrix and
|
||||
// adapt (origio) to being in top left corner and down
|
||||
@ -231,12 +231,12 @@ public:
|
||||
*
|
||||
* @see __ParseString()
|
||||
*/
|
||||
static bool ParseString(const CStr& Value, T &tOutput)
|
||||
static bool ParseString(const CStrW& Value, T &tOutput)
|
||||
{
|
||||
return __ParseString<T>(Value, tOutput);
|
||||
}
|
||||
|
||||
static bool ParseColor(const CStr& Value, CColor &tOutput, float DefaultAlpha);
|
||||
static bool ParseColor(const CStrW& Value, CColor &tOutput, float DefaultAlpha);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -254,7 +254,7 @@ bool IGUIObject::SettingExists(const CStr& Setting) const
|
||||
GUI<type>::SetSetting(this, Setting, _Value, SkipMessage); \
|
||||
}
|
||||
|
||||
PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage)
|
||||
PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage)
|
||||
{
|
||||
if (!SettingExists(Setting))
|
||||
{
|
||||
|
@ -272,7 +272,7 @@ public:
|
||||
*
|
||||
* @return PSERROR (PSRETURN_OK if successful)
|
||||
*/
|
||||
PSRETURN SetSetting(const CStr& Setting, const CStr& Value, const bool& SkipMessage=false);
|
||||
PSRETURN SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage=false);
|
||||
|
||||
/**
|
||||
* Retrieves the type of a named setting.
|
||||
|
@ -427,7 +427,10 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
|
||||
{
|
||||
if (JSVAL_IS_STRING(*vp))
|
||||
{
|
||||
if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PSRETURN_OK)
|
||||
std::wstring value;
|
||||
StringConvert::jsstring_to_wstring(JS_ValueToString(cx, *vp), value);
|
||||
|
||||
if (e->SetSetting(propName, value) != PSRETURN_OK)
|
||||
{
|
||||
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
|
||||
return JS_FALSE;
|
||||
@ -464,7 +467,10 @@ JSBool JSI_IGUIObject::setProperty(JSContext* cx, JSObject* obj, jsval id, jsval
|
||||
{
|
||||
if (JSVAL_IS_STRING(*vp))
|
||||
{
|
||||
if (e->SetSetting(propName, JS_GetStringBytes(JS_ValueToString(cx, *vp))) != PSRETURN_OK)
|
||||
std::wstring value;
|
||||
StringConvert::jsstring_to_wstring(JS_ValueToString(cx, *vp), value);
|
||||
|
||||
if (e->SetSetting(propName, value) != PSRETURN_OK)
|
||||
{
|
||||
JS_ReportError(cx, "Invalid value for setting '%s'", propName.c_str());
|
||||
return JS_FALSE;
|
||||
|
Loading…
Reference in New Issue
Block a user