|
|
@ -89,12 +89,16 @@ namespace LuaUi
|
|
|
|
root->updateCoord();
|
|
|
|
root->updateCoord();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WidgetExtension* pluckElementRoot(const sol::object& child)
|
|
|
|
WidgetExtension* pluckElementRoot(const sol::object& child, uint64_t depth)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::shared_ptr<Element> element = child.as<std::shared_ptr<Element>>();
|
|
|
|
std::shared_ptr<Element> element = child.as<std::shared_ptr<Element>>();
|
|
|
|
WidgetExtension* root = element->mRoot;
|
|
|
|
if (element->mState == Element::Destroyed || element->mState == Element::Destroy)
|
|
|
|
if (!root)
|
|
|
|
|
|
|
|
throw std::logic_error("Using a destroyed element as a layout child");
|
|
|
|
throw std::logic_error("Using a destroyed element as a layout child");
|
|
|
|
|
|
|
|
// child Element was created in the same frame and its action hasn't been processed yet
|
|
|
|
|
|
|
|
if (element->mState == Element::New)
|
|
|
|
|
|
|
|
element->create(depth + 1);
|
|
|
|
|
|
|
|
WidgetExtension* root = element->mRoot;
|
|
|
|
|
|
|
|
assert(root);
|
|
|
|
WidgetExtension* parent = root->getParent();
|
|
|
|
WidgetExtension* parent = root->getParent();
|
|
|
|
if (parent)
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -107,7 +111,7 @@ namespace LuaUi
|
|
|
|
return root;
|
|
|
|
return root;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WidgetExtension* createWidget(const sol::table& layout, uint64_t depth);
|
|
|
|
WidgetExtension* createWidget(const sol::table& layout, bool isRoot, uint64_t depth);
|
|
|
|
void updateWidget(WidgetExtension* ext, const sol::table& layout, uint64_t depth);
|
|
|
|
void updateWidget(WidgetExtension* ext, const sol::table& layout, uint64_t depth);
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<WidgetExtension*> updateContent(
|
|
|
|
std::vector<WidgetExtension*> updateContent(
|
|
|
@ -130,7 +134,7 @@ namespace LuaUi
|
|
|
|
sol::object child = content.at(i);
|
|
|
|
sol::object child = content.at(i);
|
|
|
|
if (child.is<Element>())
|
|
|
|
if (child.is<Element>())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
WidgetExtension* root = pluckElementRoot(child);
|
|
|
|
WidgetExtension* root = pluckElementRoot(child, depth);
|
|
|
|
if (ext != root)
|
|
|
|
if (ext != root)
|
|
|
|
destroyChild(ext);
|
|
|
|
destroyChild(ext);
|
|
|
|
result[i] = root;
|
|
|
|
result[i] = root;
|
|
|
@ -145,7 +149,7 @@ namespace LuaUi
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
destroyChild(ext);
|
|
|
|
destroyChild(ext);
|
|
|
|
ext = createWidget(newLayout, depth);
|
|
|
|
ext = createWidget(newLayout, false, depth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result[i] = ext;
|
|
|
|
result[i] = ext;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -156,9 +160,9 @@ namespace LuaUi
|
|
|
|
{
|
|
|
|
{
|
|
|
|
sol::object child = content.at(i);
|
|
|
|
sol::object child = content.at(i);
|
|
|
|
if (child.is<Element>())
|
|
|
|
if (child.is<Element>())
|
|
|
|
result[i] = pluckElementRoot(child);
|
|
|
|
result[i] = pluckElementRoot(child, depth);
|
|
|
|
else
|
|
|
|
else
|
|
|
|
result[i] = createWidget(child.as<sol::table>(), depth);
|
|
|
|
result[i] = createWidget(child.as<sol::table>(), false, depth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -191,7 +195,7 @@ namespace LuaUi
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WidgetExtension* createWidget(const sol::table& layout, uint64_t depth)
|
|
|
|
WidgetExtension* createWidget(const sol::table& layout, bool isRoot, uint64_t depth)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
static auto widgetTypeMap = widgetTypeToName();
|
|
|
|
static auto widgetTypeMap = widgetTypeToName();
|
|
|
|
std::string type = widgetType(layout);
|
|
|
|
std::string type = widgetType(layout);
|
|
|
@ -205,7 +209,7 @@ namespace LuaUi
|
|
|
|
WidgetExtension* ext = dynamic_cast<WidgetExtension*>(widget);
|
|
|
|
WidgetExtension* ext = dynamic_cast<WidgetExtension*>(widget);
|
|
|
|
if (!ext)
|
|
|
|
if (!ext)
|
|
|
|
throw std::runtime_error("Invalid widget!");
|
|
|
|
throw std::runtime_error("Invalid widget!");
|
|
|
|
ext->initialize(layout.lua_state(), widget, depth == 0);
|
|
|
|
ext->initialize(layout.lua_state(), widget, isRoot);
|
|
|
|
|
|
|
|
|
|
|
|
updateWidget(ext, layout, depth);
|
|
|
|
updateWidget(ext, layout, depth);
|
|
|
|
return ext;
|
|
|
|
return ext;
|
|
|
@ -247,8 +251,7 @@ namespace LuaUi
|
|
|
|
: mRoot(nullptr)
|
|
|
|
: mRoot(nullptr)
|
|
|
|
, mLayout(std::move(layout))
|
|
|
|
, mLayout(std::move(layout))
|
|
|
|
, mLayer()
|
|
|
|
, mLayer()
|
|
|
|
, mUpdate(false)
|
|
|
|
, mState(Element::New)
|
|
|
|
, mDestroy(false)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -267,12 +270,12 @@ namespace LuaUi
|
|
|
|
sGameElements.erase(element);
|
|
|
|
sGameElements.erase(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Element::create()
|
|
|
|
void Element::create(uint64_t depth)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
assert(!mRoot);
|
|
|
|
assert(!mRoot);
|
|
|
|
if (!mRoot)
|
|
|
|
if (mState == New)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mRoot = createWidget(layout(), 0);
|
|
|
|
mRoot = createWidget(layout(), true, depth);
|
|
|
|
mLayer = setLayer(mRoot, layout());
|
|
|
|
mLayer = setLayer(mRoot, layout());
|
|
|
|
updateRootCoord(mRoot);
|
|
|
|
updateRootCoord(mRoot);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -280,15 +283,16 @@ namespace LuaUi
|
|
|
|
|
|
|
|
|
|
|
|
void Element::update()
|
|
|
|
void Element::update()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mRoot && mUpdate)
|
|
|
|
if (mState == Update)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
assert(mRoot);
|
|
|
|
if (mRoot->widget()->getTypeName() != widgetType(layout()))
|
|
|
|
if (mRoot->widget()->getTypeName() != widgetType(layout()))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
destroyRoot(mRoot);
|
|
|
|
destroyRoot(mRoot);
|
|
|
|
WidgetExtension* parent = mRoot->getParent();
|
|
|
|
WidgetExtension* parent = mRoot->getParent();
|
|
|
|
auto children = parent->children();
|
|
|
|
auto children = parent->children();
|
|
|
|
auto it = std::find(children.begin(), children.end(), mRoot);
|
|
|
|
auto it = std::find(children.begin(), children.end(), mRoot);
|
|
|
|
mRoot = createWidget(layout(), 0);
|
|
|
|
mRoot = createWidget(layout(), true, 0);
|
|
|
|
assert(it != children.end());
|
|
|
|
assert(it != children.end());
|
|
|
|
*it = mRoot;
|
|
|
|
*it = mRoot;
|
|
|
|
parent->setChildren(children);
|
|
|
|
parent->setChildren(children);
|
|
|
@ -301,16 +305,18 @@ namespace LuaUi
|
|
|
|
mLayer = setLayer(mRoot, layout());
|
|
|
|
mLayer = setLayer(mRoot, layout());
|
|
|
|
updateRootCoord(mRoot);
|
|
|
|
updateRootCoord(mRoot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mUpdate = false;
|
|
|
|
mState = Created;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Element::destroy()
|
|
|
|
void Element::destroy()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mRoot)
|
|
|
|
if (mState != Destroyed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
destroyRoot(mRoot);
|
|
|
|
destroyRoot(mRoot);
|
|
|
|
mRoot = nullptr;
|
|
|
|
mRoot = nullptr;
|
|
|
|
|
|
|
|
if (mState != New)
|
|
|
|
mLayout = sol::make_object(mLayout.lua_state(), sol::nil);
|
|
|
|
mLayout = sol::make_object(mLayout.lua_state(), sol::nil);
|
|
|
|
|
|
|
|
mState = Destroyed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|