Fix duplicate in Body as well

pull/1141/head
Levin Li 2021-10-18 22:59:35 +08:00
parent cb0fe13ecd
commit 1613542c5d
3 changed files with 17 additions and 20 deletions

View File

@ -113,10 +113,9 @@ const vector<string>& Body::getNames() const
*/
string Body::getName(bool i18n) const
{
if (!i18n)
return names[0];
else
return names[localizedNameIndex];
if (i18n && hasLocalizedName())
return localizedName;
return names[0];
}
@ -125,13 +124,13 @@ string Body::getName(bool i18n) const
*/
string Body::getLocalizedName() const
{
return names[localizedNameIndex];
return hasLocalizedName() ? localizedName : names[0];
}
bool Body::hasLocalizedName() const
{
return localizedNameIndex != 0;
return primaryNameLocalized;
}
@ -148,12 +147,12 @@ void Body::setName(const string& name)
{
// No localized name; set the localized name index to zero to
// indicate this.
localizedNameIndex = 0;
primaryNameLocalized = false;
}
else
{
names.push_back(localizedName);
localizedNameIndex = names.size() - 1;
this->localizedName = localizedName;
primaryNameLocalized = true;
}
}

View File

@ -377,7 +377,7 @@ class Body : public AstroObject
private:
std::vector<std::string> names{ 1 };
unsigned int localizedNameIndex{ 0 };
std::string localizedName;
// Parent in the name hierarchy
PlanetarySystem* system;
@ -430,6 +430,7 @@ class Body : public AstroObject
bool overrideOrbitColor{ false };
VisibilityPolicy orbitVisibility : 3;
bool secondaryIlluminator{ true };
bool primaryNameLocalized { false };
};
#endif // _CELENGINE_BODY_H_

View File

@ -3364,19 +3364,16 @@ void CelestiaCore::renderOverlay()
if (sel != lastSelection)
{
lastSelection = sel;
selectionNames = "";
const vector<string>& names = sel.body()->getNames();
auto body = sel.body();
selectionNames = body->getLocalizedName(); // Primary name, might be localized
const vector<string>& names = body->getNames();
// Skip displaying the primary name if there's a localized version
// of the name.
auto firstName = names.begin();
if (sel.body()->hasLocalizedName())
++firstName;
// Start from the second one because primary name is already in the string
auto secondName = names.begin() + 1;
for (auto iter = firstName; iter != names.end(); ++iter)
for (auto iter = secondName; iter != names.end(); ++iter)
{
if (iter != firstName)
selectionNames += " / ";
selectionNames += " / ";
// Use localized version of parent name in alternative names.
string alias = *iter;