1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-07 12:54:00 +00:00
OpenMW/components/lua_ui/scriptsettings.cpp

61 lines
1.5 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
2022-01-29 22:43:08 +00:00
#include "registerscriptsettings.hpp"
2022-01-25 20:53:00 +00:00
#include "element.hpp"
#include "adapter.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";
return {
name, searchHints, 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
}
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
{
if (index < allPages.size())
{
ScriptSettingsPage page = parse(allPages[index]);
adapter->detach();
if (page.mElement.get())
adapter->attach(page.mElement);
}
2022-01-25 20:53:00 +00:00
}
}