From 1613542c5d5f28a64538b349e46123348bddd94e Mon Sep 17 00:00:00 2001 From: Levin Li Date: Mon, 18 Oct 2021 22:59:35 +0800 Subject: [PATCH] Fix duplicate in Body as well --- src/celengine/body.cpp | 17 ++++++++--------- src/celengine/body.h | 3 ++- src/celestia/celestiacore.cpp | 17 +++++++---------- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/celengine/body.cpp b/src/celengine/body.cpp index af42d38b9..255771bc5 100644 --- a/src/celengine/body.cpp +++ b/src/celengine/body.cpp @@ -113,10 +113,9 @@ const vector& 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; } } diff --git a/src/celengine/body.h b/src/celengine/body.h index 8021bf902..37333f252 100644 --- a/src/celengine/body.h +++ b/src/celengine/body.h @@ -377,7 +377,7 @@ class Body : public AstroObject private: std::vector 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_ diff --git a/src/celestia/celestiacore.cpp b/src/celestia/celestiacore.cpp index 7b32f51a9..f0649bbf4 100644 --- a/src/celestia/celestiacore.cpp +++ b/src/celestia/celestiacore.cpp @@ -3364,19 +3364,16 @@ void CelestiaCore::renderOverlay() if (sel != lastSelection) { lastSelection = sel; - selectionNames = ""; - const vector& names = sel.body()->getNames(); + auto body = sel.body(); + selectionNames = body->getLocalizedName(); // Primary name, might be localized + const vector& 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;