openmw/components/lua_ui/scriptsettings.cpp

57 lines
1.4 KiB
C++
Raw Normal View History

2022-01-25 21:53:00 +01:00
#include "scriptsettings.hpp"
#include <map>
#include "element.hpp"
namespace LuaUi
{
namespace
{
std::vector<sol::table> allPages;
ScriptSettingsPage parse(const sol::table& options)
{
auto name = options.get_or("name", std::string());
auto description = options.get_or("description", 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, description, element.get()
};
}
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
}
void clearSettings()
{
allPages.clear();
2022-01-25 21:53:00 +01:00
}
void attachToWidget(size_t index, MyGUI::Widget* widget)
2022-01-25 21:53:00 +01:00
{
if (index < allPages.size())
{
ScriptSettingsPage page = parse(allPages[index]);
if (page.mElement)
page.mElement->attachToWidget(widget);
}
2022-01-25 21:53:00 +01:00
}
}