1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-29 08:15:35 +00:00

Use page terminology for script settings

This commit is contained in:
uramer 2022-01-29 13:22:08 +01:00
parent e78b8402fa
commit a005f25c4b
4 changed files with 24 additions and 24 deletions

View file

@ -741,12 +741,12 @@ namespace MWGui
auto flags = std::regex_constants::icase; auto flags = std::regex_constants::icase;
std::regex filterRegex(filter, flags); std::regex filterRegex(filter, flags);
auto scriptSettings = LuaUi::scriptSettings(); auto scriptSettings = LuaUi::scriptSettingsPages();
for (size_t i = 0; i < scriptSettings.size(); ++i) for (size_t i = 0; i < scriptSettings.size(); ++i)
{ {
LuaUi::ScriptSettings script = scriptSettings[i]; LuaUi::ScriptSettingsPage page = scriptSettings[i];
if (std::regex_match(script.mName, filterRegex) || std::regex_match(script.mSearchHints, filterRegex)) if (std::regex_match(page.mName, filterRegex) || std::regex_match(page.mSearchHints, filterRegex))
mScriptList->addItem(script.mName, i); mScriptList->addItem(page.mName, i);
} }
// Hide script settings tab when the game world isn't loaded and scripts couldn't add their settings // Hide script settings tab when the game world isn't loaded and scripts couldn't add their settings

View file

@ -239,18 +239,18 @@ namespace MWLua
typeTable.set(it.second, it.first); typeTable.set(it.second, it.first);
api["TYPE"] = LuaUtil::makeReadOnly(typeTable); api["TYPE"] = LuaUtil::makeReadOnly(typeTable);
api["registerSettings"] = [](sol::table options) api["registerSettingsPage"] = [](sol::table options)
{ {
LuaUi::ScriptSettings script; LuaUi::ScriptSettingsPage page;
script.mName = options.get_or("name", std::string()); page.mName = options.get_or("name", std::string());
if (script.mName.empty()) if (page.mName.empty())
throw std::logic_error("No name provided for script settings"); throw std::logic_error("No name provided for the settings page");
script.mSearchHints = options.get_or("searchHints", std::string()); page.mSearchHints = options.get_or("searchHints", std::string());
auto element = options.get_or<std::shared_ptr<LuaUi::Element>>("element", nullptr); auto element = options.get_or<std::shared_ptr<LuaUi::Element>>("element", nullptr);
if (!element) if (!element)
throw std::logic_error("No UI element provided for script settings"); throw std::logic_error("No UI element provided for the settings page");
script.mElement = element.get(); page.mElement = element.get();
LuaUi::registerSettings(script); LuaUi::registerSettingsPage(page);
}; };
return LuaUtil::makeReadOnly(api); return LuaUtil::makeReadOnly(api);

View file

@ -8,27 +8,27 @@ namespace LuaUi
{ {
namespace namespace
{ {
std::vector<ScriptSettings> allSettings; std::vector<ScriptSettingsPage> allPages;
} }
const std::vector<ScriptSettings>& scriptSettings() const std::vector<ScriptSettingsPage>& scriptSettingsPages()
{ {
return allSettings; return allPages;
} }
void registerSettings(const ScriptSettings& script) void registerSettingsPage(const ScriptSettingsPage& page)
{ {
allSettings.push_back(script); allPages.push_back(page);
} }
void clearSettings() void clearSettings()
{ {
allSettings.clear(); allPages.clear();
} }
void attachToWidget(size_t index, MyGUI::Widget* widget) void attachToWidget(size_t index, MyGUI::Widget* widget)
{ {
if (index < allSettings.size()) if (index < allPages.size())
allSettings[index].mElement->attachToWidget(widget); allPages[index].mElement->attachToWidget(widget);
} }
} }

View file

@ -10,14 +10,14 @@
namespace LuaUi namespace LuaUi
{ {
struct Element; struct Element;
struct ScriptSettings struct ScriptSettingsPage
{ {
std::string mName; std::string mName;
std::string mSearchHints; std::string mSearchHints;
Element* mElement; // TODO: figure out if this can lead to use after free Element* mElement; // TODO: figure out if this can lead to use after free
}; };
const std::vector<ScriptSettings>& scriptSettings(); const std::vector<ScriptSettingsPage>& scriptSettingsPages();
void registerSettings(const ScriptSettings& script); void registerSettingsPage(const ScriptSettingsPage& page);
void clearSettings(); void clearSettings();
void attachToWidget(size_t index, MyGUI::Widget* widget = nullptr); void attachToWidget(size_t index, MyGUI::Widget* widget = nullptr);
} }