mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-06 00:55:50 +00:00
Allow to override MyGUI layout
This commit is contained in:
parent
4ddba5142e
commit
2630bc21dd
@ -521,6 +521,7 @@ void OMW::Engine::setDataDirs (const Files::PathContainer& dataDirs)
|
||||
{
|
||||
mDataDirs = dataDirs;
|
||||
mDataDirs.insert(mDataDirs.begin(), (mResDir / "vfs"));
|
||||
mDataDirs.insert(mDataDirs.begin(), (mResDir / "mygui"));
|
||||
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(),
|
||||
mCfgMgr.getLogPath().string() + std::string("/"), myguiResources,
|
||||
mScriptConsoleMode, mTranslationDataStorage, mEncoding, mExportFonts,
|
||||
Version::getOpenmwVersionDescription(mResDir.string()), mCfgMgr.getUserConfigPath().string(), shadersSupported);
|
||||
Version::getOpenmwVersionDescription(mResDir.string()), shadersSupported);
|
||||
mEnvironment.setWindowManager(*mWindowManager);
|
||||
|
||||
mInputManager = std::make_unique<MWInput::InputManager>(mWindow, mViewer, mScreenCaptureHandler,
|
||||
|
@ -129,7 +129,7 @@ namespace MWGui
|
||||
WindowManager::WindowManager(
|
||||
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,
|
||||
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)
|
||||
, mOldCullMask(0)
|
||||
, mStore(nullptr)
|
||||
@ -205,7 +205,7 @@ namespace MWGui
|
||||
MyGUI::LanguageManager::getInstance().eventRequestTag = MyGUI::newDelegate(this, &WindowManager::onRetrieveTag);
|
||||
|
||||
// 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);
|
||||
|
||||
//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,
|
||||
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();
|
||||
|
||||
/// Set the ESMStore to use for retrieving of GUI-related strings.
|
||||
|
@ -151,9 +151,8 @@ namespace
|
||||
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)
|
||||
, mUserDataPath(userDataPath)
|
||||
, mFontHeight(std::clamp(Settings::Manager::getInt("font size", "GUI"), 12, 20))
|
||||
, mScalingFactor(scalingFactor)
|
||||
{
|
||||
@ -214,15 +213,11 @@ namespace Gui
|
||||
return;
|
||||
}
|
||||
|
||||
dataManager->setUseVfs(true);
|
||||
|
||||
for (const auto& name : mVFS->getRecursiveDirectoryIterator("Fonts/"))
|
||||
{
|
||||
if (Misc::getFileExtension(name) == "omwfont")
|
||||
MyGUI::ResourceManager::getInstance().load(name);
|
||||
}
|
||||
|
||||
dataManager->setUseVfs(false);
|
||||
}
|
||||
|
||||
typedef struct
|
||||
|
@ -25,7 +25,7 @@ namespace Gui
|
||||
class FontLoader
|
||||
{
|
||||
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();
|
||||
|
||||
/// @param exportToFile export the converted fonts (Images and XML with glyph metrics) to files?
|
||||
@ -41,7 +41,6 @@ namespace Gui
|
||||
private:
|
||||
ToUTF8::FromType mEncoding;
|
||||
const VFS::Manager* mVFS;
|
||||
std::string mUserDataPath;
|
||||
int mFontHeight;
|
||||
float mScalingFactor;
|
||||
|
||||
|
@ -18,34 +18,16 @@ void DataManager::setResourcePath(const std::string &path)
|
||||
mResourcePath = path;
|
||||
}
|
||||
|
||||
void DataManager::setUseVfs(bool useVfs)
|
||||
{
|
||||
mUseVfs = useVfs;
|
||||
}
|
||||
|
||||
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.
|
||||
Files::IStreamPtr streamPtr = mVfs->get(name);
|
||||
std::istream* fileStream = streamPtr.get();
|
||||
std::unique_ptr<std::stringstream> dataStream;
|
||||
dataStream.reset(new std::stringstream);
|
||||
*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());
|
||||
// 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.
|
||||
Files::IStreamPtr streamPtr = mVfs->get(name);
|
||||
std::istream* fileStream = streamPtr.get();
|
||||
std::unique_ptr<std::stringstream> dataStream;
|
||||
dataStream.reset(new std::stringstream);
|
||||
*dataStream << fileStream->rdbuf();
|
||||
return new MyGUI::DataStream(dataStream.release());
|
||||
}
|
||||
|
||||
void DataManager::freeData(MyGUI::IDataStream *data)
|
||||
@ -55,10 +37,7 @@ void DataManager::freeData(MyGUI::IDataStream *data)
|
||||
|
||||
bool DataManager::isDataExist(const std::string &name) const
|
||||
{
|
||||
if (mUseVfs) return mVfs->exists(name);
|
||||
|
||||
std::string fullpath = mResourcePath + "/" + name;
|
||||
return std::filesystem::exists(fullpath);
|
||||
return mVfs->exists(name);
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
// TODO: pattern matching (unused?)
|
||||
static MyGUI::VectorString strings;
|
||||
strings.clear();
|
||||
strings.push_back(getDataPath(pattern));
|
||||
return strings;
|
||||
throw std::runtime_error("DataManager::getDataListNames is not implemented - VFS is used");
|
||||
}
|
||||
|
||||
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.
|
||||
// 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;
|
||||
throw std::runtime_error("DataManager::getDataPath is not implemented - VFS is used");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ public:
|
||||
|
||||
void setResourcePath(const std::string& path);
|
||||
|
||||
void setUseVfs(bool useVfs);
|
||||
|
||||
void setVfs(const VFS::Manager* vfs);
|
||||
|
||||
/** Get data stream from specified resource name.
|
||||
@ -52,8 +50,6 @@ private:
|
||||
std::string mResourcePath;
|
||||
|
||||
const VFS::Manager* mVfs;
|
||||
|
||||
bool mUseVfs{false};
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user