mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-05 15:55:45 +00:00
MR feedack
This commit is contained in:
parent
a7bb87d8a1
commit
67879bac55
@ -26,7 +26,10 @@
|
||||
namespace MWLua
|
||||
{
|
||||
|
||||
LuaManager::LuaManager(const VFS::Manager* vfs, const std::string& libsDir) : mLua(vfs, &mConfiguration), mI18n(vfs, &mLua)
|
||||
LuaManager::LuaManager(const VFS::Manager* vfs, const std::string& libsDir)
|
||||
: mLua(vfs, &mConfiguration)
|
||||
, mUiResourceManager(vfs)
|
||||
, mI18n(vfs, &mLua)
|
||||
{
|
||||
Log(Debug::Info) << "Lua version: " << LuaUtil::getLuaVersion();
|
||||
mLua.addInternalLibSearchPath(libsDir);
|
||||
@ -37,8 +40,6 @@ namespace MWLua
|
||||
mLocalLoader = createUserdataSerializer(true, mWorldView.getObjectRegistry(), &mContentFileMapping);
|
||||
|
||||
mGlobalScripts.setSerializer(mGlobalSerializer.get());
|
||||
|
||||
mUiResourceManager = std::make_unique<LuaUi::ResourceManager>(vfs);
|
||||
}
|
||||
|
||||
void LuaManager::initConfiguration()
|
||||
@ -250,6 +251,7 @@ namespace MWLua
|
||||
void LuaManager::clear()
|
||||
{
|
||||
LuaUi::clearUserInterface();
|
||||
mUiResourceManager.clear();
|
||||
mActiveLocalScripts.clear();
|
||||
mLocalEvents.clear();
|
||||
mGlobalEvents.clear();
|
||||
@ -472,7 +474,8 @@ namespace MWLua
|
||||
{
|
||||
Log(Debug::Info) << "Reload Lua";
|
||||
|
||||
LuaUi::clearUserInterface();
|
||||
LuaUi::clearUserInterface();
|
||||
mUiResourceManager.clear();
|
||||
mLua.dropScriptCache();
|
||||
initConfiguration();
|
||||
|
||||
|
@ -91,18 +91,17 @@ namespace MWLua
|
||||
return [this, c](Arg arg) { this->queueCallback(c, sol::make_object(c.mFunc.lua_state(), arg)); };
|
||||
}
|
||||
|
||||
LuaUi::ResourceManager* uiResourceManager() { return mUiResourceManager.get(); }
|
||||
LuaUi::ResourceManager* uiResourceManager() { return &mUiResourceManager; }
|
||||
|
||||
private:
|
||||
void initConfiguration();
|
||||
LocalScripts* createLocalScripts(const MWWorld::Ptr& ptr, ESM::LuaScriptCfg::Flags);
|
||||
|
||||
std::unique_ptr<LuaUi::ResourceManager> mUiResourceManager;
|
||||
|
||||
bool mInitialized = false;
|
||||
bool mGlobalScriptsStarted = false;
|
||||
LuaUtil::ScriptsConfiguration mConfiguration;
|
||||
LuaUtil::LuaState mLua;
|
||||
LuaUi::ResourceManager mUiResourceManager;
|
||||
LuaUtil::I18nManager mI18n;
|
||||
sol::table mNearbyPackage;
|
||||
sol::table mUserInterfacePackage;
|
||||
|
@ -78,10 +78,10 @@ namespace MWLua
|
||||
std::shared_ptr<LuaUi::Element> mElement;
|
||||
};
|
||||
|
||||
class LayerAction final : public Action
|
||||
class InsertLayerAction final : public Action
|
||||
{
|
||||
public:
|
||||
LayerAction(std::string_view name, std::string_view afterName,
|
||||
InsertLayerAction(std::string_view name, std::string_view afterName,
|
||||
LuaUi::Layers::Options options, LuaUtil::LuaState* state)
|
||||
: Action(state)
|
||||
, mName(name)
|
||||
@ -247,7 +247,7 @@ namespace MWLua
|
||||
{
|
||||
LuaUi::Layers::Options options;
|
||||
options.mInteractive = LuaUtil::getValueOrDefault(LuaUtil::getFieldOrNil(opt, "interactive"), true);
|
||||
context.mLuaManager->addAction(std::make_unique<LayerAction>(name, afterName, options, context.mLua));
|
||||
context.mLuaManager->addAction(std::make_unique<InsertLayerAction>(name, afterName, options, context.mLua));
|
||||
};
|
||||
{
|
||||
auto pairs = [layers](const sol::object&)
|
||||
@ -283,10 +283,10 @@ namespace MWLua
|
||||
{
|
||||
LuaUi::TextureData data;
|
||||
sol::object path = LuaUtil::getFieldOrNil(options, "path");
|
||||
if (path.is<std::string>() && !path.as<std::string>().empty())
|
||||
if (path.is<std::string>())
|
||||
data.mPath = path.as<std::string>();
|
||||
else
|
||||
throw sol::error("Invalid texture path");
|
||||
if (data.mPath.empty())
|
||||
throw std::logic_error("Invalid texture path");
|
||||
sol::object offset = LuaUtil::getFieldOrNil(options, "offset");
|
||||
if (offset.is<osg::Vec2f>())
|
||||
data.mOffset = offset.as<osg::Vec2f>();
|
||||
|
@ -39,13 +39,12 @@ namespace LuaUi
|
||||
MyGUI::IntCoord atlasCoord;
|
||||
if (resource)
|
||||
{
|
||||
auto& data = resource->data();
|
||||
atlasCoord = MyGUI::IntCoord(
|
||||
static_cast<int>(data.mOffset.x()),
|
||||
static_cast<int>(data.mOffset.y()),
|
||||
static_cast<int>(data.mSize.x()),
|
||||
static_cast<int>(data.mSize.y()));
|
||||
setImageTexture(data.mPath);
|
||||
static_cast<int>(resource->mOffset.x()),
|
||||
static_cast<int>(resource->mOffset.y()),
|
||||
static_cast<int>(resource->mSize.x()),
|
||||
static_cast<int>(resource->mSize.y()));
|
||||
setImageTexture(resource->mPath);
|
||||
}
|
||||
|
||||
bool tileH = propertyValue("tileH", false);
|
||||
|
@ -7,8 +7,8 @@ namespace LuaUi
|
||||
{
|
||||
std::shared_ptr<TextureResource> ResourceManager::registerTexture(TextureData data)
|
||||
{
|
||||
std::string normalizedPath = vfs()->normalizeFilename(data.mPath);
|
||||
if (!vfs()->exists(normalizedPath))
|
||||
std::string normalizedPath = mVfs->normalizeFilename(data.mPath);
|
||||
if (!mVfs->exists(normalizedPath))
|
||||
{
|
||||
auto error = Misc::StringUtils::format("Texture with path \"%s\" doesn't exist", data.mPath);
|
||||
throw std::logic_error(error);
|
||||
@ -19,4 +19,9 @@ namespace LuaUi
|
||||
list.push_back(std::make_shared<TextureResource>(data));
|
||||
return list.back();
|
||||
}
|
||||
|
||||
void ResourceManager::clear()
|
||||
{
|
||||
mTextures.clear();
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,8 @@ namespace LuaUi
|
||||
osg::Vec2f mSize;
|
||||
};
|
||||
|
||||
class TextureResource
|
||||
{
|
||||
public:
|
||||
TextureResource(TextureData data)
|
||||
: mData(data)
|
||||
{}
|
||||
|
||||
const TextureData& data() { return mData; }
|
||||
|
||||
private:
|
||||
TextureData mData;
|
||||
};
|
||||
// will have more/different data when automated atlasing is supported
|
||||
using TextureResource = TextureData;
|
||||
|
||||
class ResourceManager
|
||||
{
|
||||
@ -43,10 +33,9 @@ namespace LuaUi
|
||||
{}
|
||||
|
||||
std::shared_ptr<TextureResource> registerTexture(TextureData data);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
const VFS::Manager* vfs() const { return mVfs; }
|
||||
|
||||
const VFS::Manager* mVfs;
|
||||
using TextureResources = std::vector<std::shared_ptr<TextureResource>>;
|
||||
std::unordered_map<std::string, TextureResources> mTextures;
|
||||
|
Loading…
Reference in New Issue
Block a user