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