1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-25 06:35:30 +00:00
OpenMW/components/lua_ui/scriptsettings.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.7 KiB
C++
Raw Normal View History

2022-01-25 21:53:00 +01:00
#include "scriptsettings.hpp"
#include <map>
#include <sol/sol.hpp>
2022-01-25 21:53:00 +01:00
#include "adapter.hpp"
2022-01-25 21:53:00 +01:00
#include "element.hpp"
2022-01-29 23:43:08 +01:00
#include "registerscriptsettings.hpp"
2022-01-25 21:53:00 +01:00
namespace LuaUi
{
namespace
{
std::vector<sol::table> allPages;
ScriptSettingsPage parse(const sol::table& options)
{
auto name = options.get_or("name", std::string());
auto searchHints = options.get_or("searchHints", std::string());
auto element = options.get_or<std::shared_ptr<LuaUi::Element>>("element", nullptr);
if (name.empty())
Log(Debug::Warning) << "A script settings page has an empty name";
if (!element.get())
Log(Debug::Warning) << "A script settings page has no UI element assigned";
return { std::move(name), std::move(searchHints), element };
}
2022-01-25 21:53:00 +01:00
}
size_t scriptSettingsPageCount()
2022-01-25 21:53:00 +01:00
{
return allPages.size();
2022-01-25 21:53:00 +01:00
}
ScriptSettingsPage scriptSettingsPageAt(size_t index)
2022-01-25 21:53:00 +01:00
{
return parse(allPages[index]);
}
void registerSettingsPage(const sol::table& options)
{
allPages.push_back(options);
2022-01-25 21:53:00 +01:00
}
2024-01-10 21:10:10 +01:00
void removeSettingsPage(const sol::table& options)
{
std::erase_if(allPages, [options](const sol::table& it) { return it == options; });
}
2022-01-25 21:53:00 +01:00
void clearSettings()
{
allPages.clear();
2022-01-25 21:53:00 +01:00
}
void attachPageAt(size_t index, LuaAdapter* adapter)
2022-01-25 21:53:00 +01:00
{
2024-01-10 21:10:10 +01:00
adapter->detach();
if (index < allPages.size())
{
ScriptSettingsPage page = parse(allPages[index]);
if (page.mElement.get())
adapter->attach(page.mElement);
}
2022-01-25 21:53:00 +01:00
}
}