Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectTypes/COList.cpp
/* Copyright (C) 2021 Wildfire Games. | /* Copyright (C) 2023 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
void COList::HandleMessage(SGUIMessage& Message) | void COList::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
CList::HandleMessage(Message); | CList::HandleMessage(Message); | ||||
switch (Message.type) | switch (Message.type) | ||||
{ | { | ||||
case GUIM_SETTINGS_UPDATED: | |||||
{ | |||||
if (Message.value.find("heading_") == 0) | |||||
SetupText(); | |||||
break; | |||||
} | |||||
// If somebody clicks on the column heading | // If somebody clicks on the column heading | ||||
case GUIM_MOUSE_PRESS_LEFT: | case GUIM_MOUSE_PRESS_LEFT: | ||||
{ | { | ||||
if (!m_Sortable) | if (!m_Sortable) | ||||
return; | return; | ||||
const CVector2D& mouse = m_pGUI.GetMousePos(); | const CVector2D& mouse = m_pGUI.GetMousePos(); | ||||
if (!m_CachedActualSize.PointInside(mouse)) | if (!m_CachedActualSize.PointInside(mouse)) | ||||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | for (XMBAttribute attr : child.GetAttributes()) | ||||
// Check if it's a relative value, and save as decimal if so. | // Check if it's a relative value, and save as decimal if so. | ||||
if (attr_value.find("%") != std::string::npos) | if (attr_value.find("%") != std::string::npos) | ||||
width = width / 100.f; | width = width / 100.f; | ||||
column.m_Width = width; | column.m_Width = width; | ||||
} | } | ||||
} | } | ||||
else if (attr_name == "heading") | else if (attr_name == "heading") | ||||
{ | { | ||||
column.m_Heading = attr_value.FromUTF8(); | column.m_Heading.Set(attr_value.FromUTF8(), false); | ||||
} | } | ||||
} | } | ||||
for (XMBElement grandchild : child.GetChildNodes()) | for (XMBElement grandchild : child.GetChildNodes()) | ||||
{ | { | ||||
if (grandchild.GetNodeName() != elmt_translatableAttribute) | if (grandchild.GetNodeName() != elmt_translatableAttribute) | ||||
continue; | continue; | ||||
CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id)); | CStr attributeName(grandchild.GetAttributes().GetNamedItem(attr_id)); | ||||
// only the heading is translatable for list column | // only the heading is translatable for list column | ||||
if (attributeName.empty() || attributeName != "heading") | if (attributeName.empty() || attributeName != "heading") | ||||
{ | { | ||||
LOGERROR("GUI: translatable attribute in olist column that isn't a heading. (object: %s)", this->GetPresentableName().c_str()); | LOGERROR("GUI: translatable attribute in olist column that isn't a heading. (object: %s)", this->GetPresentableName().c_str()); | ||||
continue; | continue; | ||||
} | } | ||||
CStr value(grandchild.GetText()); | CStr value(grandchild.GetText()); | ||||
if (value.empty()) | if (value.empty()) | ||||
continue; | continue; | ||||
CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. | CStr context(grandchild.GetAttributes().GetNamedItem(attr_context)); // Read the context if any. | ||||
if (!context.empty()) | if (!context.empty()) | ||||
{ | { | ||||
CStr translatedValue(g_L10n.TranslateWithContext(context, value)); | CStr translatedValue(g_L10n.TranslateWithContext(context, value)); | ||||
column.m_Heading = translatedValue.FromUTF8(); | column.m_Heading.Set(translatedValue.FromUTF8(), false); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
CStr translatedValue(g_L10n.Translate(value)); | CStr translatedValue(g_L10n.Translate(value)); | ||||
column.m_Heading = translatedValue.FromUTF8(); | column.m_Heading.Set(translatedValue.FromUTF8(), false); | ||||
} | } | ||||
} | } | ||||
m_Columns.emplace_back(std::move(column)); | m_Columns.emplace_back(std::move(column)); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 165 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator