Skip to content

Commit

Permalink
Fix duplicate in Body as well
Browse files Browse the repository at this point in the history
  • Loading branch information
levinli303 committed Oct 19, 2021
1 parent b558b53 commit f5e1a68
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
17 changes: 8 additions & 9 deletions src/celengine/body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}


Expand All @@ -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;
}


Expand All @@ -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;
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/celengine/body.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -430,6 +430,7 @@ class Body : public AstroObject
bool overrideOrbitColor{ false };
VisibilityPolicy orbitVisibility : 3;
bool secondaryIlluminator{ true };
bool primaryNameLocalized { false };
};

#endif // _CELENGINE_BODY_H_
17 changes: 7 additions & 10 deletions src/celestia/celestiacore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f5e1a68

Please sign in to comment.