Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CGUI.cpp
Show First 20 Lines • Show All 659 Lines • ▼ Show 20 Lines | for (XMBAttribute attr : attributes) | ||||
} | } | ||||
if (attr.Name == attr_hotkey) | if (attr.Name == attr_hotkey) | ||||
hotkeyTag = attr.Value; | hotkeyTag = attr.Value; | ||||
if (attr.Name == attr_z) | if (attr.Name == attr_z) | ||||
ManuallySetZ = true; | ManuallySetZ = true; | ||||
if (object->SetSetting(pFile->GetAttributeString(attr.Name), attr.Value.FromUTF8(), true) != PSRETURN_OK) | const CStr settingName = pFile->GetAttributeString(attr.Name); | ||||
LOGERROR("GUI: (object: %s) Can't set \"%s\" to \"%s\"", object->GetPresentableName(), pFile->GetAttributeString(attr.Name), attr.Value); | if (object->SettingExists(settingName)) | ||||
object->SetSettingFromString(settingName, attr.Value.FromUTF8(), false); | |||||
else | |||||
LOGERROR("GUI: (object: %s) Can't set \"%s\" to \"%s\"", object->GetPresentableName(), settingName, attr.Value); | |||||
} | } | ||||
// Check if name isn't set, generate an internal name in that case. | // Check if name isn't set, generate an internal name in that case. | ||||
if (!NameSet) | if (!NameSet) | ||||
{ | { | ||||
object->SetName("__internal(" + CStr::FromInt(m_InternalNameNumber) + ")"); | object->SetName("__internal(" + CStr::FromInt(m_InternalNameNumber) + ")"); | ||||
++m_InternalNameNumber; | ++m_InternalNameNumber; | ||||
} | } | ||||
if (!hotkeyTag.empty()) | if (!hotkeyTag.empty()) | ||||
m_HotkeyObjects[hotkeyTag].push_back(object); | m_HotkeyObjects[hotkeyTag].push_back(object); | ||||
CStrW caption(Element.GetText().FromUTF8()); | CStrW caption(Element.GetText().FromUTF8()); | ||||
if (!caption.empty()) | if (!caption.empty()) | ||||
object->SetSetting("caption", caption, true); | object->SetSettingFromString("caption", caption, false); | ||||
for (XMBElement child : Element.GetChildNodes()) | for (XMBElement child : Element.GetChildNodes()) | ||||
{ | { | ||||
// Check what name the elements got | // Check what name the elements got | ||||
int element_name = child.GetNodeName(); | int element_name = child.GetNodeName(); | ||||
if (element_name == elmt_object) | if (element_name == elmt_object) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | else if (element_name == elmt_translatableAttribute) | ||||
continue; | continue; | ||||
} | } | ||||
CStr value(child.GetText()); | CStr value(child.GetText()); | ||||
if (value.empty()) | if (value.empty()) | ||||
continue; | continue; | ||||
CStr context(child.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. | CStr context(child.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. | ||||
if (!context.empty()) | |||||
{ | CStr translatedValue = context.empty() ? | ||||
CStr translatedValue(g_L10n.TranslateWithContext(context, value)); | g_L10n.Translate(value) : | ||||
object->SetSetting(attributeName, translatedValue.FromUTF8(), true); | g_L10n.TranslateWithContext(context, value); | ||||
} | |||||
else | object->SetSettingFromString(attributeName, translatedValue.FromUTF8(), false); | ||||
{ | |||||
CStr translatedValue(g_L10n.Translate(value)); | |||||
object->SetSetting(attributeName, translatedValue.FromUTF8(), true); | |||||
} | |||||
} | } | ||||
else if (element_name == elmt_attribute) | else if (element_name == elmt_attribute) | ||||
{ | { | ||||
// This is an element in the form “<attribute id="attributeName"><keep>Don’t translate this part | // This is an element in the form “<attribute id="attributeName"><keep>Don’t translate this part | ||||
// </keep><translate>but translate this one.</translate></attribute>”. | // </keep><translate>but translate this one.</translate></attribute>”. | ||||
CStr attributeName(child.GetAttributes().GetNamedItem(attr_id)); // Read the attribute name. | CStr attributeName(child.GetAttributes().GetNamedItem(attr_id)); // Read the attribute name. | ||||
if (attributeName.empty()) | if (attributeName.empty()) | ||||
{ | { | ||||
LOGERROR("GUI: ‘attribute’ XML element with empty ‘id’ XML attribute found. (object: %s)", object->GetPresentableName().c_str()); | LOGERROR("GUI: ‘attribute’ XML element with empty ‘id’ XML attribute found. (object: %s)", object->GetPresentableName().c_str()); | ||||
continue; | continue; | ||||
} | } | ||||
CStr translatedValue; | CStr translatedValue; | ||||
for (XMBElement grandchild : child.GetChildNodes()) | for (XMBElement grandchild : child.GetChildNodes()) | ||||
{ | { | ||||
if (grandchild.GetNodeName() == elmt_translate) | if (grandchild.GetNodeName() == elmt_translate) | ||||
translatedValue += g_L10n.Translate(grandchild.GetText()); | translatedValue += g_L10n.Translate(grandchild.GetText()); | ||||
else if (grandchild.GetNodeName() == elmt_keep) | else if (grandchild.GetNodeName() == elmt_keep) | ||||
translatedValue += grandchild.GetText(); | translatedValue += grandchild.GetText(); | ||||
} | } | ||||
object->SetSetting(attributeName, translatedValue.FromUTF8(), true); | object->SetSettingFromString(attributeName, translatedValue.FromUTF8(), false); | ||||
} | } | ||||
else if (element_name == elmt_include) | else if (element_name == elmt_include) | ||||
{ | { | ||||
CStrW filename(child.GetAttributes().GetNamedItem(attr_file).FromUTF8()); | CStrW filename(child.GetAttributes().GetNamedItem(attr_file).FromUTF8()); | ||||
CStrW directory(child.GetAttributes().GetNamedItem(attr_directory).FromUTF8()); | CStrW directory(child.GetAttributes().GetNamedItem(attr_directory).FromUTF8()); | ||||
if (!filename.empty()) | if (!filename.empty()) | ||||
{ | { | ||||
if (!directory.empty()) | if (!directory.empty()) | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth) | ||||
} | } | ||||
if (!ManuallySetZ) | if (!ManuallySetZ) | ||||
{ | { | ||||
// Set it automatically to 10 plus its parents | // Set it automatically to 10 plus its parents | ||||
if (object->GetSetting<bool>("absolute")) | if (object->GetSetting<bool>("absolute")) | ||||
// If the object is absolute, we'll have to get the parent's Z buffered, | // If the object is absolute, we'll have to get the parent's Z buffered, | ||||
// and add to that! | // and add to that! | ||||
GUI<float>::SetSetting(object, "z", pParent->GetBufferedZ() + 10.f, true); | object->SetSetting<float>("z", pParent->GetBufferedZ() + 10.f, false); | ||||
else | else | ||||
// If the object is relative, then we'll just store Z as "10" | // If the object is relative, then we'll just store Z as "10" | ||||
GUI<float>::SetSetting(object, "z", 10.f, true); | object->SetSetting<float>("z", 10.f, false); | ||||
} | } | ||||
try | try | ||||
{ | { | ||||
if (pParent == m_BaseObject) | if (pParent == m_BaseObject) | ||||
AddObject(object); | AddObject(object); | ||||
else | else | ||||
pParent->AddChild(object); | pParent->AddChild(object); | ||||
▲ Show 20 Lines • Show All 427 Lines • ▼ Show 20 Lines | void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile) | ||||
for (XMBAttribute attr : Element.GetAttributes()) | for (XMBAttribute attr : Element.GetAttributes()) | ||||
{ | { | ||||
CStr attr_name(pFile->GetAttributeString(attr.Name)); | CStr attr_name(pFile->GetAttributeString(attr.Name)); | ||||
CStr attr_value(attr.Value); | CStr attr_value(attr.Value); | ||||
if (attr_name == "name") | if (attr_name == "name") | ||||
object->SetName("__tooltip_" + attr_value); | object->SetName("__tooltip_" + attr_value); | ||||
else | else | ||||
object->SetSetting(attr_name, attr_value.FromUTF8()); | object->SetSettingFromString(attr_name, attr_value.FromUTF8(), true); | ||||
} | } | ||||
AddObject(object); | AddObject(object); | ||||
} | } | ||||
void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile) | void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile) | ||||
{ | { | ||||
XMBAttributeList attributes = Element.GetAttributes(); | XMBAttributeList attributes = Element.GetAttributes(); | ||||
Show All 19 Lines |
Wildfire Games · Phabricator