From 76b44e3d9b2b9f146866ad66154fecdf3cb8dfd4 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 5 Aug 2018 19:46:14 -0400 Subject: Buttons can be parrented to elements --- src/client/lua_api/gui/iguibutton.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/client') diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp index 2d04fd1..0e16ef6 100644 --- a/src/client/lua_api/gui/iguibutton.cpp +++ b/src/client/lua_api/gui/iguibutton.cpp @@ -30,31 +30,33 @@ static int newiguibutton(lua_State* L){ int nargs = lua_gettop(L); IGUIElement* parent = NULL; - if(nargs == 4){ + if(nargs == 3){ + lua_getfield(L,-1,"guielement"); parent = (IGUIElement*)lua_touserdata(L,-1); - lua_pop(L,1); + lua_pop(L,2);//{{sx,sy},{ex,ey}},"text" } - - const char* label_c = lua_tostring(L,-1); - const wchar_t* label_w = irr::core::stringw(label_c).c_str(); - lua_pop(L,1); - + const char* label_c = lua_tostring(L,-1);//{{sx,sy},{ex,ey}},"text" + const wchar_t* label_w = irr::core::stringw(label_c).c_str();//{{sx,sy},{ex,ey}},"text" + lua_pop(L,1);//{{sx,sy},{ex,ey}} + printf("Created title\n"); long sx,sy,ex,ey; - poprecti(L,&sx,&sy,&ex,&ey); + poprecti(L,&sx,&sy,&ex,&ey);// + printf("Got coords\n"); rect dim = rect(sx,sy,ex,ey); IGUIEnvironment* env = device->getGUIEnvironment(); - IGUIButton* but = env->addButton(dim,parent,-2,label_w,L""); + IGUIButton* but = env->addButton(dim,parent,-1,label_w,L""); + printf("Added button\n"); lua_newtable(L);//{} lua_pushlightuserdata(L,but);//{},ud_iguibutton lua_setfield(L,-2,"guielement");//{guielement} luaL_getmetatable(L,"gui.iguibutton");//{guielement},{m_iguibutton} lua_setmetatable(L,-2);//{guielement} + printf("Created lua representation\n"); setelementcallback(L,EGET_BUTTON_CLICKED,"onClicked");// - printf("Finished registering callback\n"); return 1; -- cgit v1.2.3-70-g09d2