mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-26 22:40:25 +00:00
Generalize function for texture path correction (Fixes #1779)
This commit is contained in:
parent
42dceb641e
commit
4873c4bd31
3 changed files with 24 additions and 16 deletions
|
@ -3,6 +3,8 @@
|
||||||
#include <MyGUI_FactoryManager.h>
|
#include <MyGUI_FactoryManager.h>
|
||||||
#include <MyGUI_ImageBox.h>
|
#include <MyGUI_ImageBox.h>
|
||||||
|
|
||||||
|
#include <components/nifogre/material.hpp>
|
||||||
|
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
|
||||||
namespace MWGui
|
namespace MWGui
|
||||||
|
@ -63,15 +65,7 @@ namespace MWGui
|
||||||
|
|
||||||
void ItemWidget::setIcon(const MWWorld::Ptr &ptr)
|
void ItemWidget::setIcon(const MWWorld::Ptr &ptr)
|
||||||
{
|
{
|
||||||
// image
|
setIcon(NifOgre::NIFMaterialLoader::findIconName(ptr.getClass().getInventoryIcon(ptr)));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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
|
/* Bethesda at some point converted all their BSA
|
||||||
* textures from tga to dds for increased load speed, but all
|
* textures from tga to dds for increased load speed, but all
|
||||||
* texture file name references were kept as .tga.
|
* texture file name references were kept as .tga.
|
||||||
*/
|
*/
|
||||||
static const char path[] = "textures\\";
|
std::string path = topLevelDirectory + '\\';
|
||||||
static const char path2[] = "textures/";
|
std::string path2 = topLevelDirectory + '/';
|
||||||
|
|
||||||
std::string texname = filename;
|
std::string texname = filename;
|
||||||
Misc::StringUtils::toLower(texname);
|
Misc::StringUtils::toLower(texname);
|
||||||
|
@ -71,8 +71,8 @@ std::string NIFMaterialLoader::findTextureName(const std::string &filename)
|
||||||
while (texname.size() && (texname[0] == '/' || texname[0] == '\\'))
|
while (texname.size() && (texname[0] == '/' || texname[0] == '\\'))
|
||||||
texname.erase(0, 1);
|
texname.erase(0, 1);
|
||||||
|
|
||||||
if(texname.compare(0, sizeof(path)-1, path) != 0 &&
|
if(texname.compare(0, path.size()-1, path.data()) != 0 &&
|
||||||
texname.compare(0, sizeof(path2)-1, path2) != 0)
|
texname.compare(0, path2.size()-1, path2.data()) != 0)
|
||||||
texname = path + texname;
|
texname = path + texname;
|
||||||
|
|
||||||
Ogre::String::size_type pos = texname.rfind('.');
|
Ogre::String::size_type pos = texname.rfind('.');
|
||||||
|
@ -88,8 +88,8 @@ std::string NIFMaterialLoader::findTextureName(const std::string &filename)
|
||||||
{
|
{
|
||||||
texname = filename;
|
texname = filename;
|
||||||
Misc::StringUtils::toLower(texname);
|
Misc::StringUtils::toLower(texname);
|
||||||
if(texname.compare(0, sizeof(path)-1, path) != 0 &&
|
if(texname.compare(0, path.size()-1, path.data()) != 0 &&
|
||||||
texname.compare(0, sizeof(path2)-1, path2) != 0)
|
texname.compare(0, path2.size()-1, path2.data()) != 0)
|
||||||
texname = path + texname;
|
texname = path + texname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,18 @@ std::string NIFMaterialLoader::findTextureName(const std::string &filename)
|
||||||
return texname;
|
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,
|
Ogre::String NIFMaterialLoader::getMaterial(const Nif::ShapeData *shapedata,
|
||||||
const Ogre::String &name, const Ogre::String &group,
|
const Ogre::String &name, const Ogre::String &group,
|
||||||
const Nif::NiTexturingProperty *texprop,
|
const Nif::NiTexturingProperty *texprop,
|
||||||
|
|
|
@ -38,7 +38,9 @@ class NIFMaterialLoader {
|
||||||
static std::map<size_t,std::string> sMaterialMap;
|
static std::map<size_t,std::string> sMaterialMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
static std::string findMaterialName(const std::string &topLevelDirectory, const std::string &filename);
|
||||||
static std::string findTextureName(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,
|
static Ogre::String getMaterial(const Nif::ShapeData *shapedata,
|
||||||
const Ogre::String &name, const Ogre::String &group,
|
const Ogre::String &name, const Ogre::String &group,
|
||||||
|
|
Loading…
Reference in a new issue