diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index fe8b5cc13a..b800311eca 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -183,8 +183,6 @@ namespace MWBase /// generate a name. virtual std::string_view getCellName(const MWWorld::Cell& cell) const = 0; - virtual std::string_view getCellName(const ESM::Cell* cell) const = 0; - virtual void removeRefScript(const MWWorld::CellRef* ref) = 0; //< Remove the script attached to ref from mLocalScripts diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 0468b36a2f..ed61cf5bde 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -662,25 +663,29 @@ namespace MWWorld if (!cell.isExterior() || !cell.getDisplayName().empty()) return cell.getDisplayName(); - return ESM::visit(ESM::VisitOverload{ - [&](const ESM::Cell& cellIn) -> std::string_view { return getCellName(&cellIn); }, - [&](const ESM4::Cell& cellIn) -> std::string_view { - return mStore.get().find("sDefaultCellname")->mValue.getString(); - }, - }, - cell); - } - - std::string_view World::getCellName(const ESM::Cell* cell) const - { - if (cell) + if (!cell.getRegion().empty()) { - if (!cell->isExterior() || !cell->mName.empty()) - return cell->mName; - - if (const ESM::Region* region = mStore.get().search(cell->mRegion)) - return region->mName; + std::string_view regionName + = ESM::visit(ESM::VisitOverload{ + [&](const ESM::Cell& cellIn) -> std::string_view { + if (const ESM::Region* region = mStore.get().search(cell.getRegion())) + return !region->mName.empty() ? region->mName : region->mId.getRefIdString(); + return {}; + }, + [&](const ESM4::Cell& cellIn) -> std::string_view { return {}; }, + }, + cell); + if (!regionName.empty()) + return regionName; } + + if (!cell.getWorldSpace().empty() && ESM::isEsm4Ext(cell.getWorldSpace())) + { + if (const ESM4::World* worldspace = mStore.get().search(cell.getWorldSpace())) + if (!worldspace->mFullName.empty()) + return worldspace->mFullName; + } + return mStore.get().find("sDefaultCellname")->mValue.getString(); } diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 4e36419e7f..b7db68214d 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -273,7 +273,6 @@ namespace MWWorld /// \note If cell==0, the cell the player is currently in will be used instead to /// generate a name. std::string_view getCellName(const MWWorld::Cell& cell) const override; - std::string_view getCellName(const ESM::Cell* cell) const override; void removeRefScript(const MWWorld::CellRef* ref) override; //< Remove the script attached to ref from mLocalScripts