mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-19 19:53:53 +00:00
Merge branch 'fix-lua-layers' into 'master'
Fix Lua UI Layer bindings See merge request OpenMW/openmw!3433
This commit is contained in:
commit
1a5b63412a
1 changed files with 19 additions and 12 deletions
|
@ -156,20 +156,16 @@ namespace MWLua
|
||||||
uiLayer[sol::meta_function::to_string]
|
uiLayer[sol::meta_function::to_string]
|
||||||
= [](LuaUi::Layer& self) { return Misc::StringUtils::format("UiLayer(%s)", self.name()); };
|
= [](LuaUi::Layer& self) { return Misc::StringUtils::format("UiLayer(%s)", self.name()); };
|
||||||
|
|
||||||
sol::table layers = context.mLua->newTable();
|
sol::table layersTable = context.mLua->newTable();
|
||||||
layers[sol::meta_function::length] = []() { return LuaUi::Layer::count(); };
|
layersTable["indexOf"] = [](std::string_view name) -> sol::optional<size_t> {
|
||||||
layers[sol::meta_function::index] = [](size_t index) {
|
|
||||||
index = fromLuaIndex(index);
|
|
||||||
return LuaUi::Layer(index);
|
|
||||||
};
|
|
||||||
layers["indexOf"] = [](std::string_view name) -> sol::optional<size_t> {
|
|
||||||
size_t index = LuaUi::Layer::indexOf(name);
|
size_t index = LuaUi::Layer::indexOf(name);
|
||||||
if (index == LuaUi::Layer::count())
|
if (index == LuaUi::Layer::count())
|
||||||
return sol::nullopt;
|
return sol::nullopt;
|
||||||
else
|
else
|
||||||
return toLuaIndex(index);
|
return toLuaIndex(index);
|
||||||
};
|
};
|
||||||
layers["insertAfter"] = [context](std::string_view afterName, std::string_view name, const sol::object& opt) {
|
layersTable["insertAfter"] = [context](
|
||||||
|
std::string_view afterName, std::string_view name, const sol::object& opt) {
|
||||||
LuaUi::Layer::Options options;
|
LuaUi::Layer::Options options;
|
||||||
options.mInteractive = LuaUtil::getValueOrDefault(LuaUtil::getFieldOrNil(opt, "interactive"), true);
|
options.mInteractive = LuaUtil::getValueOrDefault(LuaUtil::getFieldOrNil(opt, "interactive"), true);
|
||||||
size_t index = LuaUi::Layer::indexOf(afterName);
|
size_t index = LuaUi::Layer::indexOf(afterName);
|
||||||
|
@ -178,7 +174,8 @@ namespace MWLua
|
||||||
index++;
|
index++;
|
||||||
context.mLuaManager->addAction([=]() { LuaUi::Layer::insert(index, name, options); }, "Insert UI layer");
|
context.mLuaManager->addAction([=]() { LuaUi::Layer::insert(index, name, options); }, "Insert UI layer");
|
||||||
};
|
};
|
||||||
layers["insertBefore"] = [context](std::string_view beforename, std::string_view name, const sol::object& opt) {
|
layersTable["insertBefore"] = [context](
|
||||||
|
std::string_view beforename, std::string_view name, const sol::object& opt) {
|
||||||
LuaUi::Layer::Options options;
|
LuaUi::Layer::Options options;
|
||||||
options.mInteractive = LuaUtil::getValueOrDefault(LuaUtil::getFieldOrNil(opt, "interactive"), true);
|
options.mInteractive = LuaUtil::getValueOrDefault(LuaUtil::getFieldOrNil(opt, "interactive"), true);
|
||||||
size_t index = LuaUi::Layer::indexOf(beforename);
|
size_t index = LuaUi::Layer::indexOf(beforename);
|
||||||
|
@ -186,6 +183,16 @@ namespace MWLua
|
||||||
throw std::logic_error(std::string("Layer not found"));
|
throw std::logic_error(std::string("Layer not found"));
|
||||||
context.mLuaManager->addAction([=]() { LuaUi::Layer::insert(index, name, options); }, "Insert UI layer");
|
context.mLuaManager->addAction([=]() { LuaUi::Layer::insert(index, name, options); }, "Insert UI layer");
|
||||||
};
|
};
|
||||||
|
sol::table layers = LuaUtil::makeReadOnly(layersTable);
|
||||||
|
sol::table layersMeta = layers[sol::metatable_key];
|
||||||
|
layersMeta[sol::meta_function::length] = []() { return LuaUi::Layer::count(); };
|
||||||
|
layersMeta[sol::meta_function::index] = sol::overload(
|
||||||
|
[](const sol::object& self, size_t index) {
|
||||||
|
index = fromLuaIndex(index);
|
||||||
|
return LuaUi::Layer(index);
|
||||||
|
},
|
||||||
|
[layersTable](
|
||||||
|
const sol::object& self, std::string_view key) { return layersTable.raw_get<sol::object>(key); });
|
||||||
{
|
{
|
||||||
auto pairs = [layers](const sol::object&) {
|
auto pairs = [layers](const sol::object&) {
|
||||||
auto next = [](const sol::table& l, size_t i) -> sol::optional<std::tuple<size_t, LuaUi::Layer>> {
|
auto next = [](const sol::table& l, size_t i) -> sol::optional<std::tuple<size_t, LuaUi::Layer>> {
|
||||||
|
@ -196,10 +203,10 @@ namespace MWLua
|
||||||
};
|
};
|
||||||
return std::make_tuple(next, layers, 0);
|
return std::make_tuple(next, layers, 0);
|
||||||
};
|
};
|
||||||
layers[sol::meta_function::pairs] = pairs;
|
layersMeta[sol::meta_function::pairs] = pairs;
|
||||||
layers[sol::meta_function::ipairs] = pairs;
|
layersMeta[sol::meta_function::ipairs] = pairs;
|
||||||
}
|
}
|
||||||
api["layers"] = LuaUtil::makeReadOnly(layers);
|
api["layers"] = layers;
|
||||||
|
|
||||||
sol::table typeTable = context.mLua->newTable();
|
sol::table typeTable = context.mLua->newTable();
|
||||||
for (const auto& it : LuaUi::widgetTypeToName())
|
for (const auto& it : LuaUi::widgetTypeToName())
|
||||||
|
|
Loading…
Reference in a new issue