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 string Body::getName(bool i18n) const
{ {
if (!i18n) if (i18n && hasLocalizedName())
return names[0]; return localizedName;
else return names[0];
return names[localizedNameIndex];
} }
@ -125,13 +124,13 @@ string Body::getName(bool i18n) const
*/ */
string Body::getLocalizedName() const string Body::getLocalizedName() const
{ {
return names[localizedNameIndex]; return hasLocalizedName() ? localizedName : names[0];
} }
bool Body::hasLocalizedName() const 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 // No localized name; set the localized name index to zero to
// indicate this. // indicate this.
localizedNameIndex = 0; primaryNameLocalized = false;
} }
else else
{ {
names.push_back(localizedName); this->localizedName = localizedName;
localizedNameIndex = names.size() - 1; primaryNameLocalized = true;
} }
} }

View File

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

View File

@ -3364,19 +3364,16 @@ void CelestiaCore::renderOverlay()
if (sel != lastSelection) if (sel != lastSelection)
{ {
lastSelection = sel; lastSelection = sel;
selectionNames = ""; auto body = sel.body();
const vector<string>& names = sel.body()->getNames(); 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 // Start from the second one because primary name is already in the string
// of the name. auto secondName = names.begin() + 1;
auto firstName = names.begin();
if (sel.body()->hasLocalizedName())
++firstName;
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. // Use localized version of parent name in alternative names.
string alias = *iter; string alias = *iter;