mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 14:03:26 +02:00
more scripting features (dynamic fields)
This commit is contained in:
@@ -66,6 +66,9 @@ void UIContainer::removeChild(UIElementPtr child)
|
||||
if(m_focusedElement == child)
|
||||
setFocusedElement(UIElementPtr());
|
||||
|
||||
// try to unlock
|
||||
unlockElement(child);
|
||||
|
||||
// remove from children list
|
||||
m_children.remove(child);
|
||||
|
||||
|
@@ -64,6 +64,17 @@ void UIElement::internalOnDestroy()
|
||||
getParent()->removeChild(me);
|
||||
}
|
||||
|
||||
// free script stuff
|
||||
clearLuaRefs();
|
||||
|
||||
g_dispatcher.addTask(boost::bind(&UIElement::internalDestroyCheck, asUIElement()));
|
||||
}
|
||||
|
||||
void UIElement::internalDestroyCheck()
|
||||
{
|
||||
//logTraceDebug(getId());
|
||||
|
||||
UIElementPtr me = asUIElement();
|
||||
// check for leaks, the number of references must be always 2 here
|
||||
if(me.use_count() != 2 && me != UIContainer::getRoot()) {
|
||||
flogWarning("destroyed element with id '%s', but it still have %d references left", getId() % (me.use_count()-2));
|
||||
|
@@ -52,6 +52,7 @@ public:
|
||||
/// Destroy this element by removing it from its parent
|
||||
void destroy();
|
||||
virtual void internalOnDestroy();
|
||||
virtual void internalDestroyCheck();
|
||||
|
||||
/// Draw element
|
||||
virtual void render();
|
||||
|
@@ -215,7 +215,7 @@ void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node)
|
||||
// load events
|
||||
if(node.FindValue("onLoad")) {
|
||||
const YAML::Node& cnode = node["onLoad"];
|
||||
int funcRef = g_lua.loadBufferAsFunction(cnode.Read<std::string>());
|
||||
int funcRef = g_lua.loadBufferAsFunction(cnode.Read<std::string>(), element->getId() + ":onLoad");
|
||||
if(funcRef != LUA_REFNIL) {
|
||||
g_lua.pushClassInstance(element);
|
||||
g_lua.pushFunction(funcRef);
|
||||
@@ -226,7 +226,7 @@ void UILoader::loadElement(const UIElementPtr& element, const YAML::Node& node)
|
||||
|
||||
if(node.FindValue("onDestroy")) {
|
||||
const YAML::Node& cnode = node["onDestroy"];
|
||||
int funcRef = g_lua.loadBufferAsFunction(cnode.Read<std::string>());
|
||||
int funcRef = g_lua.loadBufferAsFunction(cnode.Read<std::string>(), element->getId() + ":onDestroy");
|
||||
if(funcRef != LUA_REFNIL) {
|
||||
g_lua.pushClassInstance(element);
|
||||
g_lua.pushFunction(funcRef);
|
||||
@@ -314,7 +314,7 @@ void UILoader::loadButton(const UIButtonPtr& button, const YAML::Node& node)
|
||||
|
||||
// set on click event
|
||||
if(node.FindValue("onClick")) {
|
||||
int funcRef = g_lua.loadBufferAsFunction(node["onClick"].Read<std::string>());
|
||||
int funcRef = g_lua.loadBufferAsFunction(node["onClick"].Read<std::string>(), button->getId() + ":onClick");
|
||||
if(funcRef != LUA_REFNIL) {
|
||||
g_lua.pushClassInstance(button);
|
||||
g_lua.pushFunction(funcRef);
|
||||
|
Reference in New Issue
Block a user