2022-01-25 20:53:00 +00:00
|
|
|
#include "scriptsettings.hpp"
|
|
|
|
|
|
|
|
#include <map>
|
2022-01-29 22:06:43 +00:00
|
|
|
#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"
|
2022-01-29 22:06:43 +00:00
|
|
|
#include "adapter.hpp"
|
2022-01-25 20:53:00 +00:00
|
|
|
|
|
|
|
namespace LuaUi
|
|
|
|
{
|
|
|
|
namespace
|
|
|
|
{
|
2022-01-29 17:33:14 +00:00
|
|
|
std::vector<sol::table> allPages;
|
|
|
|
ScriptSettingsPage parse(const sol::table& options)
|
|
|
|
{
|
|
|
|
auto name = options.get_or("name", std::string());
|
2022-02-01 18:20:47 +00:00
|
|
|
auto searchHints = options.get_or("searchHints", std::string());
|
2022-01-29 17:33:14 +00:00
|
|
|
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 {
|
2022-02-01 18:20:47 +00:00
|
|
|
name, searchHints, element
|
2022-01-29 17:33:14 +00:00
|
|
|
};
|
|
|
|
}
|
2022-01-25 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 17:33:14 +00:00
|
|
|
size_t scriptSettingsPageCount()
|
2022-01-25 20:53:00 +00:00
|
|
|
{
|
2022-01-29 17:33:14 +00:00
|
|
|
return allPages.size();
|
2022-01-25 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 17:33:14 +00:00
|
|
|
ScriptSettingsPage scriptSettingsPageAt(size_t index)
|
2022-01-25 20:53:00 +00:00
|
|
|
{
|
2022-01-29 17:33:14 +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()
|
|
|
|
{
|
2022-01-29 12:22:08 +00:00
|
|
|
allPages.clear();
|
2022-01-25 20:53:00 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 22:06:43 +00:00
|
|
|
void attachPageAt(size_t index, LuaAdapter* adapter)
|
2022-01-25 20:53:00 +00:00
|
|
|
{
|
2022-01-29 12:22:08 +00:00
|
|
|
if (index < allPages.size())
|
2022-01-29 17:33:14 +00:00
|
|
|
{
|
|
|
|
ScriptSettingsPage page = parse(allPages[index]);
|
2022-01-29 22:06:43 +00:00
|
|
|
adapter->detach();
|
|
|
|
if (page.mElement.get())
|
|
|
|
adapter->attach(page.mElement);
|
2022-01-29 17:33:14 +00:00
|
|
|
}
|
2022-01-25 20:53:00 +00:00
|
|
|
}
|
|
|
|
}
|