mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-06 21:45:35 +00:00
Allow to override MyGUI layout
This commit is contained in:
parent
4ddba5142e
commit
2630bc21dd
7 changed files with 18 additions and 62 deletions
|
@ -521,6 +521,7 @@ void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs)
|
||||||
{
|
{
|
||||||
mDataDirs = dataDirs;
|
mDataDirs = dataDirs;
|
||||||
mDataDirs.insert(mDataDirs.begin(), (mResDir / "vfs"));
|
mDataDirs.insert(mDataDirs.begin(), (mResDir / "vfs"));
|
||||||
|
mDataDirs.insert(mDataDirs.begin(), (mResDir / "mygui"));
|
||||||
mFileCollections = Files::Collections (mDataDirs, !mFSStrict);
|
mFileCollections = Files::Collections (mDataDirs, !mFSStrict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -825,7 +826,7 @@ void OMW::Engine::prepareEngine()
|
||||||
mWindowManager = std::make_unique<MWGui::WindowManager>(mWindow, mViewer, guiRoot, mResourceSystem.get(), mWorkQueue.get(),
|
mWindowManager = std::make_unique<MWGui::WindowManager>(mWindow, mViewer, guiRoot, mResourceSystem.get(), mWorkQueue.get(),
|
||||||
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
|
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
|
||||||
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts,
|
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts,
|
||||||
Version::getOpenmwVersionDescription(mResDir.string()), mCfgMgr.getUserConfigPath().string(), shadersSupported);
|
Version::getOpenmwVersionDescription(mResDir.string()), shadersSupported);
|
||||||
mEnvironment.setWindowManager(*mWindowManager);
|
mEnvironment.setWindowManager(*mWindowManager);
|
||||||
|
|
||||||
mInputManager = std::make_unique<MWInput::InputManager>(mWindow, mViewer, mScreenCaptureHandler,
|
mInputManager = std::make_unique<MWInput::InputManager>(mWindow, mViewer, mScreenCaptureHandler,
|
||||||
|
|
|
@ -129,7 +129,7 @@ namespace MWGui
|
||||||
WindowManager::WindowManager(
|
WindowManager::WindowManager(
|
||||||
SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
||||||
const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
|
const std::string& logpath, const std::string& resourcePath, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
|
||||||
ToUTF8::FromType encoding, bool exportFonts, const std::string& versionDescription, const std::string& userDataPath, bool useShaders)
|
ToUTF8::FromType encoding, bool exportFonts, const std::string& versionDescription, bool useShaders)
|
||||||
: mOldUpdateMask(0)
|
: mOldUpdateMask(0)
|
||||||
, mOldCullMask(0)
|
, mOldCullMask(0)
|
||||||
, mStore(nullptr)
|
, mStore(nullptr)
|
||||||
|
@ -205,7 +205,7 @@ namespace MWGui
|
||||||
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
|
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
|
||||||
|
|
||||||
// Load fonts
|
// Load fonts
|
||||||
mFontLoader = std::make_unique<Gui::FontLoader>(encoding, resourceSystem->getVFS(), userDataPath, mScalingFactor);
|
mFontLoader = std::make_unique<Gui::FontLoader>(encoding, resourceSystem->getVFS(), mScalingFactor);
|
||||||
mFontLoader->loadBitmapFonts(exportFonts);
|
mFontLoader->loadBitmapFonts(exportFonts);
|
||||||
|
|
||||||
//Register own widgets with MyGUI
|
//Register own widgets with MyGUI
|
||||||
|
|
|
@ -136,7 +136,7 @@ namespace MWGui
|
||||||
|
|
||||||
WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
WindowManager(SDL_Window* window, osgViewer::Viewer* viewer, osg::Group* guiRoot, Resource::ResourceSystem* resourceSystem, SceneUtil::WorkQueue* workQueue,
|
||||||
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
|
const std::string& logpath, const std::string& cacheDir, bool consoleOnlyScripts, Translation::Storage& translationDataStorage,
|
||||||
ToUTF8::FromType encoding, bool exportFonts, const std::string& versionDescription, const std::string& localPath, bool useShaders);
|
ToUTF8::FromType encoding, bool exportFonts, const std::string& versionDescription, bool useShaders);
|
||||||
virtual ~WindowManager();
|
virtual ~WindowManager();
|
||||||
|
|
||||||
/// Set the ESMStore to use for retrieving of GUI-related strings.
|
/// Set the ESMStore to use for retrieving of GUI-related strings.
|
||||||
|
|
|
@ -151,9 +151,8 @@ namespace
|
||||||
namespace Gui
|
namespace Gui
|
||||||
{
|
{
|
||||||
|
|
||||||
FontLoader::FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs, const std::string& userDataPath, float scalingFactor)
|
FontLoader::FontLoader(ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor)
|
||||||
: mVFS(vfs)
|
: mVFS(vfs)
|
||||||
, mUserDataPath(userDataPath)
|
|
||||||
, mFontHeight(std::clamp(Settings::Manager::getInt("font size", "GUI"), 12, 20))
|
, mFontHeight(std::clamp(Settings::Manager::getInt("font size", "GUI"), 12, 20))
|
||||||
, mScalingFactor(scalingFactor)
|
, mScalingFactor(scalingFactor)
|
||||||
{
|
{
|
||||||
|
@ -214,15 +213,11 @@ namespace Gui
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dataManager->setUseVfs(true);
|
|
||||||
|
|
||||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/"))
|
for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/"))
|
||||||
{
|
{
|
||||||
if (Misc::getFileExtension(name) == "omwfont")
|
if (Misc::getFileExtension(name) == "omwfont")
|
||||||
MyGUI::ResourceManager::getInstance().load(name);
|
MyGUI::ResourceManager::getInstance().load(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
dataManager->setUseVfs(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
|
|
|
@ -25,7 +25,7 @@ namespace Gui
|
||||||
class FontLoader
|
class FontLoader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FontLoader (ToUTF8::FromType encoding, const VFS::Manager* vfs, const std::string& userDataPath, float scalingFactor);
|
FontLoader (ToUTF8::FromType encoding, const VFS::Manager* vfs, float scalingFactor);
|
||||||
~FontLoader();
|
~FontLoader();
|
||||||
|
|
||||||
/// @param exportToFile export the converted fonts (Images and XML with glyph metrics) to files?
|
/// @param exportToFile export the converted fonts (Images and XML with glyph metrics) to files?
|
||||||
|
@ -41,7 +41,6 @@ namespace Gui
|
||||||
private:
|
private:
|
||||||
ToUTF8::FromType mEncoding;
|
ToUTF8::FromType mEncoding;
|
||||||
const VFS::Manager* mVFS;
|
const VFS::Manager* mVFS;
|
||||||
std::string mUserDataPath;
|
|
||||||
int mFontHeight;
|
int mFontHeight;
|
||||||
float mScalingFactor;
|
float mScalingFactor;
|
||||||
|
|
||||||
|
|
|
@ -18,34 +18,16 @@ void DataManager::setResourcePath(const std::string &path)
|
||||||
mResourcePath = path;
|
mResourcePath = path;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::setUseVfs(bool useVfs)
|
|
||||||
{
|
|
||||||
mUseVfs = useVfs;
|
|
||||||
}
|
|
||||||
|
|
||||||
MyGUI::IDataStream *DataManager::getData(const std::string &name) const
|
MyGUI::IDataStream *DataManager::getData(const std::string &name) const
|
||||||
{
|
{
|
||||||
if (mUseVfs)
|
// Note: MyGUI is supposed to read/free input steam itself,
|
||||||
{
|
// so copy data from VFS stream to the string stream and pass it to MyGUI.
|
||||||
// Note: MyGUI is supposed to read/free input steam itself,
|
Files::IStreamPtr streamPtr = mVfs->get(name);
|
||||||
// so copy data from VFS stream to the string stream and pass it to MyGUI.
|
std::istream* fileStream = streamPtr.get();
|
||||||
Files::IStreamPtr streamPtr = mVfs->get(name);
|
std::unique_ptr<std::stringstream> dataStream;
|
||||||
std::istream* fileStream = streamPtr.get();
|
dataStream.reset(new std::stringstream);
|
||||||
std::unique_ptr<std::stringstream> dataStream;
|
*dataStream << fileStream->rdbuf();
|
||||||
dataStream.reset(new std::stringstream);
|
return new MyGUI::DataStream(dataStream.release());
|
||||||
*dataStream << fileStream->rdbuf();
|
|
||||||
return new MyGUI::DataStream(dataStream.release());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string fullpath = getDataPath(name);
|
|
||||||
auto stream = std::make_unique<std::ifstream>();
|
|
||||||
stream->open(fullpath, std::ios::binary);
|
|
||||||
if (stream->fail())
|
|
||||||
{
|
|
||||||
Log(Debug::Error) << "DataManager::getData: Failed to open '" << name << "'";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
return new MyGUI::DataFileStream(stream.release());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::freeData(MyGUI::IDataStream *data)
|
void DataManager::freeData(MyGUI::IDataStream *data)
|
||||||
|
@ -55,10 +37,7 @@ void DataManager::freeData(MyGUI::IDataStream *data)
|
||||||
|
|
||||||
bool DataManager::isDataExist(const std::string &name) const
|
bool DataManager::isDataExist(const std::string &name) const
|
||||||
{
|
{
|
||||||
if (mUseVfs) return mVfs->exists(name);
|
return mVfs->exists(name);
|
||||||
|
|
||||||
std::string fullpath = mResourcePath + "/" + name;
|
|
||||||
return std::filesystem::exists(fullpath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataManager::setVfs(const VFS::Manager* vfs)
|
void DataManager::setVfs(const VFS::Manager* vfs)
|
||||||
|
@ -68,26 +47,12 @@ void DataManager::setVfs(const VFS::Manager* vfs)
|
||||||
|
|
||||||
const MyGUI::VectorString &DataManager::getDataListNames(const std::string &pattern) const
|
const MyGUI::VectorString &DataManager::getDataListNames(const std::string &pattern) const
|
||||||
{
|
{
|
||||||
// TODO: pattern matching (unused?)
|
throw std::runtime_error("DataManager::getDataListNames is not implemented - VFS is used");
|
||||||
static MyGUI::VectorString strings;
|
|
||||||
strings.clear();
|
|
||||||
strings.push_back(getDataPath(pattern));
|
|
||||||
return strings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string &DataManager::getDataPath(const std::string &name) const
|
const std::string &DataManager::getDataPath(const std::string &name) const
|
||||||
{
|
{
|
||||||
// FIXME: in theory, we should use the VFS here too, but it does not provide the real path to data files.
|
throw std::runtime_error("DataManager::getDataPath is not implemented - VFS is used");
|
||||||
// In some cases there is no real path at all (when the requested MyGUI file is in BSA archive, for example).
|
|
||||||
// Currently it should not matter since we use this virtual function only to setup fonts for profilers.
|
|
||||||
static std::string result;
|
|
||||||
result.clear();
|
|
||||||
if (!isDataExist(name))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
result = mResourcePath + "/" + name;
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,6 @@ public:
|
||||||
|
|
||||||
void setResourcePath(const std::string& path);
|
void setResourcePath(const std::string& path);
|
||||||
|
|
||||||
void setUseVfs(bool useVfs);
|
|
||||||
|
|
||||||
void setVfs(const VFS::Manager* vfs);
|
void setVfs(const VFS::Manager* vfs);
|
||||||
|
|
||||||
/** Get data stream from specified resource name.
|
/** Get data stream from specified resource name.
|
||||||
|
@ -52,8 +50,6 @@ private:
|
||||||
std::string mResourcePath;
|
std::string mResourcePath;
|
||||||
|
|
||||||
const VFS::Manager* mVfs;
|
const VFS::Manager* mVfs;
|
||||||
|
|
||||||
bool mUseVfs{false};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue