1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-09 03:39:14 +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 20:53:00 +00:00
#include "scriptsettings.hpp"
#include <map>
#include <sol/sol.hpp>
2022-01-25 20:53:00 +00:00
#include "adapter.hpp"
2022-01-25 20:53:00 +00:00
#include "element.hpp"
2022-01-29 22:43:08 +00:00
#include "registerscriptsettings.hpp"
2022-01-25 20:53:00 +00: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";
2024-01-19 12:01:48 +00:00
return { std::move(name), std::move(searchHints), std::move(element) };
}
2022-01-25 20:53:00 +00:00
}
size_t scriptSettingsPageCount()
2022-01-25 20:53:00 +00:00
{
return allPages.size();
2022-01-25 20:53:00 +00:00
}
ScriptSettingsPage scriptSettingsPageAt(size_t index)
2022-01-25 20:53:00 +00:00
{
return parse(allPages[index]);
}
void registerSettingsPage(const sol::table& options)
{
allPages.push_back(options);
2022-01-25 20:53:00 +00:00
}
2024-01-10 20:10:10 +00:00
void removeSettingsPage(const sol::table& options)
{
std::erase_if(allPages, [options](const sol::table& it) { return it == options; });
}
2022-01-25 20:53:00 +00:00
void clearSettings()
{
allPages.clear();
2022-01-25 20:53:00 +00:00
}
void attachPageAt(size_t index, LuaAdapter* adapter)
2022-01-25 20:53:00 +00:00
{
2024-01-10 20:10:10 +00:00
adapter->detach();
if (index < allPages.size())
{
ScriptSettingsPage page = parse(allPages[index]);
if (page.mElement.get())
adapter->attach(page.mElement);
}
2022-01-25 20:53:00 +00:00
}
}