diff --git a/apps/openmw/mwgui/itemwidget.cpp b/apps/openmw/mwgui/itemwidget.cpp index 7c79f8027..fd4a74830 100644 --- a/apps/openmw/mwgui/itemwidget.cpp +++ b/apps/openmw/mwgui/itemwidget.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include "../mwworld/class.hpp" namespace MWGui @@ -63,15 +65,7 @@ namespace MWGui void ItemWidget::setIcon(const MWWorld::Ptr &ptr) { - // image - std::string path = std::string("icons\\"); - path += ptr.getClass().getInventoryIcon(ptr); - - std::string::size_type pos = path.rfind("."); - if(pos != std::string::npos) - path.erase(pos); - path.append(".dds"); - setIcon(path); + setIcon(NifOgre::NIFMaterialLoader::findIconName(ptr.getClass().getInventoryIcon(ptr))); } diff --git a/components/nifogre/material.cpp b/components/nifogre/material.cpp index 44831c13b..e216fe984 100644 --- a/components/nifogre/material.cpp +++ b/components/nifogre/material.cpp @@ -55,14 +55,14 @@ static const char *getTestMode(int mode) } -std::string NIFMaterialLoader::findTextureName(const std::string &filename) +std::string NIFMaterialLoader::findMaterialName(const std::string &topLevelDirectory, const std::string &filename) { /* Bethesda at some point converted all their BSA * textures from tga to dds for increased load speed, but all * texture file name references were kept as .tga. */ - static const char path[] = "textures\\"; - static const char path2[] = "textures/"; + std::string path = topLevelDirectory + '\\'; + std::string path2 = topLevelDirectory + '/'; std::string texname = filename; Misc::StringUtils::toLower(texname); @@ -71,8 +71,8 @@ std::string NIFMaterialLoader::findTextureName(const std::string &filename) while (texname.size() && (texname[0] == '/' || texname[0] == '\\')) texname.erase(0, 1); - if(texname.compare(0, sizeof(path)-1, path) != 0 && - texname.compare(0, sizeof(path2)-1, path2) != 0) + if(texname.compare(0, path.size()-1, path.data()) != 0 && + texname.compare(0, path2.size()-1, path2.data()) != 0) texname = path + texname; Ogre::String::size_type pos = texname.rfind('.'); @@ -88,8 +88,8 @@ std::string NIFMaterialLoader::findTextureName(const std::string &filename) { texname = filename; Misc::StringUtils::toLower(texname); - if(texname.compare(0, sizeof(path)-1, path) != 0 && - texname.compare(0, sizeof(path2)-1, path2) != 0) + if(texname.compare(0, path.size()-1, path.data()) != 0 && + texname.compare(0, path2.size()-1, path2.data()) != 0) texname = path + texname; } } @@ -97,6 +97,18 @@ std::string NIFMaterialLoader::findTextureName(const std::string &filename) return texname; } +std::string NIFMaterialLoader::findTextureName(const std::string &filename) +{ + static const std::string dir = "textures"; + return findMaterialName(dir, filename); +} + +std::string NIFMaterialLoader::findIconName(const std::string &filename) +{ + static const std::string dir = "icons"; + return findMaterialName(dir, filename); +} + Ogre::String NIFMaterialLoader::getMaterial(const Nif::ShapeData *shapedata, const Ogre::String &name, const Ogre::String &group, const Nif::NiTexturingProperty *texprop, diff --git a/components/nifogre/material.hpp b/components/nifogre/material.hpp index abe1982eb..df37ce164 100644 --- a/components/nifogre/material.hpp +++ b/components/nifogre/material.hpp @@ -38,7 +38,9 @@ class NIFMaterialLoader { static std::map sMaterialMap; public: + static std::string findMaterialName(const std::string &topLevelDirectory, const std::string &filename); static std::string findTextureName(const std::string &filename); + static std::string findIconName(const std::string &filename); static Ogre::String getMaterial(const Nif::ShapeData *shapedata, const Ogre::String &name, const Ogre::String &group,