more scripting features (dynamic fields)

This commit is contained in:
Eduardo Bart
2011-05-02 01:13:57 -03:00
parent f7bb044f48
commit 9e90ae0ee4
19 changed files with 378 additions and 146 deletions

View File

@@ -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);

View File

@@ -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));

View File

@@ -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();

View File

@@ -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);