Something went wrong. Try again.
OpenMW is an open implementation of the Morrowind engine
Something went wrong. Try again.
3.3 kB · 100 lines
C++
at master
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101#include "util.hpp"
#include <ranges>#include <unordered_set>
#include <MyGUI_FactoryManager.h>
#include "adapter.hpp"#include "container.hpp"#include "flex.hpp"#include "image.hpp"#include "text.hpp"#include "textedit.hpp"#include "widget.hpp"#include "window.hpp"
#include "element.hpp"
namespace LuaUi{
void registerAllWidgets() { MyGUI::FactoryManager::getInstance().registerFactory<LuaAdapter>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<LuaWidget>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<LuaText>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<LuaTextEdit>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<LuaWindow>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<LuaImage>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<LuaTileRect>("BasisSkin"); MyGUI::FactoryManager::getInstance().registerFactory<LuaContainer>("Widget"); MyGUI::FactoryManager::getInstance().registerFactory<LuaFlex>("Widget"); }
const std::unordered_map<std::string, std::string>& widgetTypeToName() { static std::unordered_map<std::string, std::string> types{ { "LuaWidget", "Widget" }, { "LuaText", "Text" }, { "LuaTextEdit", "TextEdit" }, { "LuaWindow", "Window" }, { "LuaImage", "Image" }, { "LuaFlex", "Flex" }, { "LuaContainer", "Container" }, }; return types; }
void clearGameInterface() { while (!Element::sGameElements.empty()) Element::erase(Element::sGameElements.begin()->second.get()); }
void clearMenuInterface() { while (!Element::sMenuElements.empty()) Element::erase(Element::sMenuElements.begin()->second.get()); }
void updateAllElementCoords() { std::unordered_set<WidgetExtension*> roots; auto collectRoot = [&roots](Element* element) { if (!element->mRoot) return; WidgetExtension* root = element->mRoot; while (root->getParent()) root = root->getParent(); roots.insert(root); }; Element::forEach(false, collectRoot); Element::forEach(true, collectRoot); for (WidgetExtension* root : roots) root->updateCoord(); }
bool warnUnused(std::vector<std::string>& warnings, sol::object object, const std::string& tableName, const std::vector<std::string_view>& usedKeys, bool generateWarningStrings) { auto beginningSize = warnings.size(); if (!object.is<sol::table>()) return false; sol::table table = object.as<sol::table>(); for (const auto& [key, value] : table) { if (!key.is<std::string>()) continue; auto keyStr = key.as<std::string>();
if (std::ranges::find(usedKeys, keyStr) == usedKeys.end()) { if (!generateWarningStrings) return true; warnings.push_back("unused key '" + keyStr + "' in " + tableName); } } return beginningSize != warnings.size(); }}