Generalize function for texture path correction (Fixes #1779)

deque
MiroslavR 11 years ago
parent 42dceb641e
commit 4873c4bd31

@ -3,6 +3,8 @@
#include <MyGUI_FactoryManager.h>
#include <MyGUI_ImageBox.h>
#include <components/nifogre/material.hpp>
#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)));
}

@ -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,

@ -38,7 +38,9 @@ class NIFMaterialLoader {
static std::map<size_t,std::string> 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,

Loading…
Cancel
Save