From d2b36e6c65ec8126c0ebc96adb7e011e78a5eacc Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Tue, 1 Nov 2016 00:28:16 -0400 Subject: Initial commit --- src/client/lua_api/gameparts.hpp | 15 +++ src/client/lua_api/gui/iguibutton.cpp | 163 +++++++++++++++++++++++++++++++++ src/client/lua_api/gui/iguibutton.hpp | 11 +++ src/client/lua_api/gui/iguielement.cpp | 93 +++++++++++++++++++ src/client/lua_api/gui/iguielement.hpp | 15 +++ src/client/lua_api/gui/iguilabel.cpp | 128 ++++++++++++++++++++++++++ src/client/lua_api/gui/iguilabel.hpp | 11 +++ src/client/lua_api/guiparts.hpp | 29 ++++++ src/client/lua_api/load_core.cpp | 32 +++++++ src/client/lua_api/load_core.hpp | 14 +++ src/client/lua_api/load_game.cpp | 24 +++++ src/client/lua_api/load_game.hpp | 14 +++ src/client/lua_api/load_gui.cpp | 69 ++++++++++++++ src/client/lua_api/load_gui.hpp | 14 +++ src/client/lua_api/scene/icamera.cpp | 124 +++++++++++++++++++++++++ src/client/lua_api/scene/icamera.hpp | 11 +++ 16 files changed, 767 insertions(+) create mode 100644 src/client/lua_api/gameparts.hpp create mode 100644 src/client/lua_api/gui/iguibutton.cpp create mode 100644 src/client/lua_api/gui/iguibutton.hpp create mode 100644 src/client/lua_api/gui/iguielement.cpp create mode 100644 src/client/lua_api/gui/iguielement.hpp create mode 100644 src/client/lua_api/gui/iguilabel.cpp create mode 100644 src/client/lua_api/gui/iguilabel.hpp create mode 100644 src/client/lua_api/guiparts.hpp create mode 100644 src/client/lua_api/load_core.cpp create mode 100644 src/client/lua_api/load_core.hpp create mode 100644 src/client/lua_api/load_game.cpp create mode 100644 src/client/lua_api/load_game.hpp create mode 100644 src/client/lua_api/load_gui.cpp create mode 100644 src/client/lua_api/load_gui.hpp create mode 100644 src/client/lua_api/scene/icamera.cpp create mode 100644 src/client/lua_api/scene/icamera.hpp (limited to 'src/client/lua_api') diff --git a/src/client/lua_api/gameparts.hpp b/src/client/lua_api/gameparts.hpp new file mode 100644 index 0000000..e6f02a1 --- /dev/null +++ b/src/client/lua_api/gameparts.hpp @@ -0,0 +1,15 @@ +extern "C" { + #include + #include + #include +} + +typedef struct LISceneNode { + irr::scene::ISceneNode* n; + map_t funcmap; + const char* type; +} LIGUIElement; + +extern lua_State* tL; +extern irr::IrrlichtDevice* gamedevice; +extern long nodenum; diff --git a/src/client/lua_api/gui/iguibutton.cpp b/src/client/lua_api/gui/iguibutton.cpp new file mode 100644 index 0000000..6c2fc5a --- /dev/null +++ b/src/client/lua_api/gui/iguibutton.cpp @@ -0,0 +1,163 @@ +#include +#include +#include +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include "../guiparts.hpp" +#include "iguielement.hpp" +#include "../../callbackhandeler.hpp" +#include "../../util/hashmap.h" + +using namespace irr; +using namespace gui; + +IrrlichtDevice* device; +char lhashkey[20]; + +static LIGUIElement* checkiguibutton(lua_State* L, int index){ + void* ud = luaL_checkudata(L,index,"gui.iguibutton"); + luaL_argcheck(L,ud != NULL, index, "'gui.iguibutton' expected"); + return (LIGUIElement*) ud; +} + +static LIGUIElement* checkiguibutton(lua_State* L){ + return checkiguibutton(L,1); +} + +//The callback even for all gui buttons +static void iguibuttonevent(irr::SEvent e){ + IGUIElement* caller = (IGUIElement*)e.GUIEvent.Caller; + printf("Some gui something somewhere was pressed\n"); + if(iguielements.find(caller) != iguielements.end()){ + printf("I know what reference is linked to that button: %d!\n",iguielements[caller]); + int ref = iguielements[caller]; + EGUI_EVENT_TYPE etype = e.GUIEvent.EventType; + if(etype == EGET_BUTTON_CLICKED){ + lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); + printf("getting raw, the thing on the top of stack is a %s\n",luaL_typename(tL,-1)); + LIGUIElement* tbut = checkiguibutton(tL,-1); + int hashmapresponse; + char* hashkey = (char*)"onpress"; + int terror = hashmap_get(tbut->funcmap,hashkey,(void**)&hashmapresponse); + if(terror == MAP_OK){ + lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); + lua_call(tL,0,0); + }else{ + printf("Tried to call onpress on something that dosen't have onpress\n"); + } + }else if(etype == EGET_ELEMENT_HOVERED){ + printf("Trying to call onhovered!\n"); + lua_rawgeti(tL,LUA_REGISTRYINDEX,ref); + LIGUIElement* tbut = (LIGUIElement*)lua_touserdata(tL,-1); + int hashmapresponse; + int terror = hashmap_get(tbut->funcmap,(char*)"onhovered",(void**)&hashmapresponse); + if(terror == MAP_OK){ + lua_rawgeti(tL,LUA_REGISTRYINDEX,hashmapresponse); + lua_call(tL,0,0); + } + } + } +} + +static int newiguibutton(lua_State* L){ + printf("Createing gui button!\n"); + //The position of the button + int startx = luaL_optint(L,1,0); + int starty = luaL_optint(L,2,0); + int endx = luaL_optint(L,3,startx+100); + int endy = luaL_optint(L,4,starty+100); + + //Label and tooltip + wchar_t* button_label; + wchar_t* button_tooltip; + const char* labelopt = luaL_optstring(L,5,"Button"); + const char* tooltipopt = luaL_optstring(L,6,"Tooltip"); + int bls = strlen(labelopt); + int bts = strlen(tooltipopt); + button_label = (wchar_t*)malloc(sizeof(wchar_t)*(bls)); + button_tooltip = (wchar_t*)malloc(sizeof(wchar_t)*(bts)); + mbstowcs(button_label,labelopt,bls+1); + mbstowcs(button_tooltip,tooltipopt,bts+1); + printf("Got the string options\n"); + + //If the element has a parrent + int parent = luaL_optint(L,7,0); + + //Create the button + IGUIEnvironment* env = device->getGUIEnvironment(); + IGUIButton* nbut = (IGUIButton*) env->addButton(core::rect(startx,starty,endx,endy), guielements[parent], gui_elenum++, button_label, button_tooltip); + + //Register it's callback + registerguicallback(nbut,EGET_BUTTON_CLICKED,iguibuttonevent); + printf("Finished registering callback\n"); + + //Create the lua representation of the button + LIGUIElement* lbut = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement)); + + //Make it callbackable + int tref = luaL_ref(L,LUA_REGISTRYINDEX); + iguielements[nbut] = tref; + lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. + + //Set it's metatable + luaL_getmetatable(L, "gui.iguibutton"); + lua_setmetatable(L, -2); + + //Create the struct + lbut->e = nbut; + lbut->funcmap = hashmap_new(); + lbut->type = "iguibutton"; + + //Free up anything made in the function + free(button_label); + free(button_tooltip); + + //Put it on top and return it + lua_rawgeti(L,LUA_REGISTRYINDEX,tref); + return 1; +} + +static const luaL_reg iguibutton_f[] = { + {"new", newiguibutton}, + {"gethandeler", guigethandeler}, + {"sethandeler", guisethandeler}, + {0,0}, +}; + +static const luaL_reg iguibutton_m[] = { + {"move", moveiguielement}, + {"settext", setiguitext}, + {"remove", removeiguielement}, + {0,0}, +}; + +int iguibutton_register(lua_State* L, IrrlichtDevice* d){ + device = d; + tL = L; + + luaL_newmetatable(L, "gui.iguibutton"); + + luaL_register(L,"iguibutton",iguibutton_f); + + lua_pushstring(L,"__index"); + lua_pushstring(L,"gethandeler"); + lua_gettable(L,-3); + lua_settable(L,-4); + + lua_pushstring(L,"__newindex"); + lua_pushstring(L,"sethandeler"); + lua_gettable(L,-3); + lua_settable(L,-4); + + luaL_register(L, NULL, iguibutton_m); + + return 1; +} diff --git a/src/client/lua_api/gui/iguibutton.hpp b/src/client/lua_api/gui/iguibutton.hpp new file mode 100644 index 0000000..4059767 --- /dev/null +++ b/src/client/lua_api/gui/iguibutton.hpp @@ -0,0 +1,11 @@ +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +int iguibutton_register(lua_State* L, irr::IrrlichtDevice* d); diff --git a/src/client/lua_api/gui/iguielement.cpp b/src/client/lua_api/gui/iguielement.cpp new file mode 100644 index 0000000..cb395af --- /dev/null +++ b/src/client/lua_api/gui/iguielement.cpp @@ -0,0 +1,93 @@ +/*This file defines some things that all igui stuff can do*/ +extern "C" { + #include + #include + #include +} +#include +#include "../guiparts.hpp" + +using namespace irr; +using namespace core; + +static LIGUIElement* toiguielement(lua_State* L,int index){ + LIGUIElement* ret = (LIGUIElement*)lua_touserdata(L,index); + if(ret == NULL) + luaL_typerror(L,index,"LIGUIButton"); + return ret; +} + +static LIGUIElement* toiguielement(lua_State* L){ + return toiguielement(L,1); +} + +int moveiguielement(lua_State* L){ + LIGUIElement* ele = toiguielement(L,1); + int x = luaL_optint(L,2,0); + int y = luaL_optint(L,3,0); + ele->e->move(position2d(x,y)); + return 0; +} + +int setiguitext(lua_State* L){ + LIGUIElement* ele = toiguielement(L,1); + const char* str = luaL_optstring(L,2,""); + int size = strlen(str); + wchar_t* al = (wchar_t*)malloc(sizeof(wchar_t)*size); + mbstowcs(al,str,size); + ele->e->setText(al); + free(al); + return 0; +} + +int removeiguielement(lua_State* L){ + LIGUIElement* ele = toiguielement(L,1); + ele->e->remove(); + hashmap_free(ele->funcmap); + free(ele); + return 0; +} + +int guigethandeler(lua_State* L){ + printf("Called the get index handeler!\n"); + LIGUIElement* button = toiguielement(L); + if(!lua_isstring(L,2)){ + luaL_error(L,"index of iguibutton must be of type 'string'"); + } + const char* lstr = lua_tostring(L,2); + char* hashkey = (char*)malloc(sizeof(char)*strlen(lstr)); + strcpy(hashkey,lstr); + int ref; + if(hashmap_get(button->funcmap,hashkey,(void**)&ref) == MAP_OK){ + //We found the value in our hashmap! + lua_rawgeti(L,LUA_REGISTRYINDEX,ref); + return 1; + }else{ + //Could not find in hashmap, check parrent + lua_getglobal(L,button->type); + printf("Button's type is %s\n",button->type); + lua_getfield(L,-1,lstr); + return 1; + } +} + +int guisethandeler(lua_State* L){ + printf("Called the set index handeler\n"); + LIGUIElement* button = toiguielement(L); + if(!lua_isstring(L,2)){ + luaL_error(L,"index of iguibutton must be of type 'string'"); + } + const char* lstr = lua_tostring(L,2); + char* hashkey = (char*)malloc(sizeof(char)*strlen(lstr)); + strcpy(hashkey,lstr); + int oldref; + if(hashmap_get(button->funcmap,hashkey,(void**)&oldref) == MAP_OK){ + luaL_unref(L,LUA_REGISTRYINDEX,oldref); + hashmap_remove(button->funcmap,hashkey); + } + int ref = luaL_ref(L,LUA_REGISTRYINDEX); + if(hashmap_put(button->funcmap,hashkey,(void*)ref) != MAP_OK){ + luaL_error(L,"Error while setting the hashkey on iguibutton"); + } + return 0; +} diff --git a/src/client/lua_api/gui/iguielement.hpp b/src/client/lua_api/gui/iguielement.hpp new file mode 100644 index 0000000..5756a34 --- /dev/null +++ b/src/client/lua_api/gui/iguielement.hpp @@ -0,0 +1,15 @@ + +#include +#include +extern "C" { + #include + #include + #include +} +#include + +int moveiguielement(lua_State* L); +int setiguitext(lua_State* L); +int removeiguielement(lua_State* L); +int guigethandeler(lua_State* L); +int guisethandeler(lua_State* L); diff --git a/src/client/lua_api/gui/iguilabel.cpp b/src/client/lua_api/gui/iguilabel.cpp new file mode 100644 index 0000000..da720f9 --- /dev/null +++ b/src/client/lua_api/gui/iguilabel.cpp @@ -0,0 +1,128 @@ + +#include +#include +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include "../guiparts.hpp" +#include "iguielement.hpp" +#include "../../callbackhandeler.hpp" + +using namespace irr; +using namespace gui; + +//IrrlichtDevice* guidevice; + +static LIGUIElement* checkiguilabel(lua_State* L, int index){ + void* ud = luaL_checkudata(L,index,"gui.iguilabel"); + luaL_argcheck(L,ud != NULL, index, "'gui.iguilabel' expected"); + return (LIGUIElement*) ud; +} + +static LIGUIElement* checkiguilabel(lua_State* L){ + return checkiguilabel(L,1); +} + +static void iguilabelevent(irr::SEvent e){ + printf("Oh no! an iguilabel generated an event!"); +} + +static int newiguilabel(lua_State* L){ + printf("Createing label!\n"); + int nargs = lua_gettop(L); + //The position of the text + int startx = luaL_optint(L,1,0); + int starty = luaL_optint(L,2,0); + int endx = luaL_optint(L,3,startx+100); + int endy = luaL_optint(L,4,starty+100); + + //Label and tooltip + wchar_t* label; + const char* labelopt = luaL_optstring(L,5,"Label"); + int bls = strlen(labelopt); + label = (wchar_t*)malloc(sizeof(wchar_t)*(bls)); + mbstowcs(label,labelopt,bls); + printf("Got the string option\n"); + + //If the element has a parrent + int parent = 0; + if(nargs >= 6){ + parent = luaL_optint(L,6,0); + printf("got the parrent\n"); + } + + + //Create the button + IGUIEnvironment* env = guidevice->getGUIEnvironment(); + //printf("Createing button with data %d %d %d %d, %p, %d, %s, %s\n", startx,starty,endx,endy,guielements[parent],gui_elenum,button_label,button_tooltip); + //Create the label + IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false); + printf("Created the button\n"); + + //Register it's callback + registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent); + + //Create it's lua representation + LIGUIElement* ltext = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement)); + int tref = luaL_ref(L,LUA_REGISTRYINDEX); + iguielements[llabel] = tref; + lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. + + //Set it's metatable + luaL_getmetatable(L, "gui.iguilabel"); + lua_setmetatable(L, -2); + + //Create the struct + ltext->e = llabel; + ltext->funcmap = hashmap_new(); + ltext->type = "iguilabel"; + + //Free up anything made in this function + free(label); + + //Put it on top and return it + lua_rawgeti(L,LUA_REGISTRYINDEX,tref); + return 1; +} + +static const luaL_reg iguilabel_f[] = { + {"new", newiguilabel}, + {"gethandeler", guigethandeler}, + {"sethandeler", guisethandeler}, + {0,0}, +}; + +static const luaL_reg iguilabel_m[] = { + {"move", moveiguielement}, + {"settext", setiguitext}, + {"remove", removeiguielement}, + {0, 0}, +}; + +int iguilabel_register(lua_State* L, IrrlichtDevice* d){ + + luaL_newmetatable(L, "gui.iguilabel"); + + luaL_register(L,"iguilabel",iguilabel_f); + + lua_pushstring(L,"__index"); + lua_pushstring(L,"gethandeler"); + lua_gettable(L,-3); + lua_settable(L,-4); + + lua_pushstring(L,"__newindex"); + lua_pushstring(L,"sethandeler"); + lua_gettable(L,-3); + lua_settable(L,-4); + + luaL_register(L, NULL, iguilabel_m); + + return 1; +} diff --git a/src/client/lua_api/gui/iguilabel.hpp b/src/client/lua_api/gui/iguilabel.hpp new file mode 100644 index 0000000..c779c70 --- /dev/null +++ b/src/client/lua_api/gui/iguilabel.hpp @@ -0,0 +1,11 @@ + +#include +#include +extern "C" { + #include + #include + #include +} +#include + +int iguilabel_register(lua_State* L, irr::IrrlichtDevice* d); diff --git a/src/client/lua_api/guiparts.hpp b/src/client/lua_api/guiparts.hpp new file mode 100644 index 0000000..fba3862 --- /dev/null +++ b/src/client/lua_api/guiparts.hpp @@ -0,0 +1,29 @@ +#ifndef __H_guiparts +#define __H_guiparts +#include +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include "../util/hashmap.h" + + +typedef struct LIGUIElement { + irr::gui::IGUIElement* e; + map_t funcmap; + const char* type; +} LIGUIElement; + + +extern lua_State* tL; +extern irr::IrrlichtDevice* guidevice; +extern long gui_elenum; +extern std::vector guielements; +extern std::map iguielements; +#endif diff --git a/src/client/lua_api/load_core.cpp b/src/client/lua_api/load_core.cpp new file mode 100644 index 0000000..910115f --- /dev/null +++ b/src/client/lua_api/load_core.cpp @@ -0,0 +1,32 @@ +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +int makevector(lua_State* L){ + lua_newtable(L); + + lua_pushstring("x"); + lua_optint(L,1,0); + lua_settable(L,-2); + + lua_pushstring("y"); + lua_optint(L,2,0); + lua_settable(L,-2); + + lua_pushstring("z"); + lua_optint(L,3,0); + lua_settable(L,-2); + +} + +void load_corefuncs(lua_State* L, IrrlichtDevice* d){ + lua_newtable(L); + lua_setglobal(L,"GAME"); +} diff --git a/src/client/lua_api/load_core.hpp b/src/client/lua_api/load_core.hpp new file mode 100644 index 0000000..641ca08 --- /dev/null +++ b/src/client/lua_api/load_core.hpp @@ -0,0 +1,14 @@ +#ifndef __H_loadgame +#define __H_loadgame +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +void load_corefuncs(lua_State* L, IrrlichtDevice* device); +#endif diff --git a/src/client/lua_api/load_game.cpp b/src/client/lua_api/load_game.cpp new file mode 100644 index 0000000..fb51595 --- /dev/null +++ b/src/client/lua_api/load_game.cpp @@ -0,0 +1,24 @@ +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +#include "gui/iguibutton.hpp" +#include "gui/iguilabel.hpp" +#include "../callbackhandeler.hpp" +#include "guiparts.hpp" + +using namespace irr; +using namespace gui; +using namespace core; + +void load_gamefuncs(lua_State* L, IrrlichtDevice* d){ + lua_newtable(L); + lua_setglobal(L,"GAME"); +} diff --git a/src/client/lua_api/load_game.hpp b/src/client/lua_api/load_game.hpp new file mode 100644 index 0000000..f20e0c6 --- /dev/null +++ b/src/client/lua_api/load_game.hpp @@ -0,0 +1,14 @@ +#ifndef __H_loadgame +#define __H_loadgame +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +void load_gamefuncs(lua_State* L, IrrlichtDevice* device); +#endif diff --git a/src/client/lua_api/load_gui.cpp b/src/client/lua_api/load_gui.cpp new file mode 100644 index 0000000..ed7faac --- /dev/null +++ b/src/client/lua_api/load_gui.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +#include "gui/iguibutton.hpp" +#include "gui/iguilabel.hpp" +#include "../callbackhandeler.hpp" +#include "guiparts.hpp" + +using namespace irr; +using namespace gui; +using namespace core; + +//Things from guiparts.hpp +std::map iguielements; +IrrlichtDevice* guidevice; +long gui_elenum; +std::vector guielements(1); +lua_State* tL; + +int screenwidth(lua_State* L); +int screenheight(lua_State* L); + +void load_guifuncs(lua_State* L, IrrlichtDevice* d){ + tL = L; + guidevice = d; + gui_elenum = 0; + guielements[0] = NULL; + printf("About to initalize guielements vector\n"); + printf("Done initalizeing guilements vector\n"); + + iguibutton_register(L,d); + iguilabel_register(L,d); + lua_pop(L, 1); + + lua_newtable(L); + //lua_pushcfunction(L,createiguibutton); + //lua_setfield(L,-2,"createButton"); + lua_setglobal(L,"gui"); + + lua_pushcfunction(L,screenwidth); + lua_setglobal(L,"scrw"); + + lua_pushcfunction(L,screenheight); + lua_setglobal(L,"scrh"); + +} + + +int screenheight(lua_State* L){ + core::rect dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect(); + lua_pushnumber(L,dim.getHeight()); + printf("Got screen height:%d\n",dim.getWidth()); + return 1; +} + +int screenwidth(lua_State* L){ + core::rect dim = guidevice->getGUIEnvironment()->getRootGUIElement()->getAbsoluteClippingRect(); + lua_pushnumber(L,dim.getWidth()); + printf("Got screen width:%d\n",dim.getWidth()); + return 1; +} diff --git a/src/client/lua_api/load_gui.hpp b/src/client/lua_api/load_gui.hpp new file mode 100644 index 0000000..eb76634 --- /dev/null +++ b/src/client/lua_api/load_gui.hpp @@ -0,0 +1,14 @@ +#ifndef __H_loadgui +#define __H_loadgui +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include + +void load_guifuncs(lua_State* L, IrrlichtDevice* device); +#endif diff --git a/src/client/lua_api/scene/icamera.cpp b/src/client/lua_api/scene/icamera.cpp new file mode 100644 index 0000000..2dd5a67 --- /dev/null +++ b/src/client/lua_api/scene/icamera.cpp @@ -0,0 +1,124 @@ + +#include +#include +#include +#include +#include +#include +extern "C" { + #include + #include + #include +} +#include +#include "../gameparts.hpp" +#include "icamera.hpp" + +using namespace irr; +using namespace scene; + +//IrrlichtDevice* guidevice; + +static LISceneNode* checkiscenecamera(lua_State* L, int index){ + void* ud = luaL_checkudata(L,index,"scene.icamera"); + luaL_argcheck(L,ud != NULL, index, "'scene.icamera' expected"); + return (LISceneNode*) ud; +} + +static LISceneNode* checkiscenecamera(lua_State* L){ + return checkiscenecamera(L,1); +} + +//iscenecamera.new(Vector position, Vector lookat, parrent) +static int newiscenecamera(lua_State* L){ + printf("Createing camera!\n"); + int nargs = lua_gettop(L); + //The position of the camera + int startx = luaL_optint(L,1,0); + int starty = luaL_optint(L,2,0); + int endx = luaL_optint(L,3,startx+100); + int endy = luaL_optint(L,4,starty+100); + + //Label and tooltip + wchar_t* label; + const char* labelopt = luaL_optstring(L,5,"Label"); + int bls = strlen(labelopt); + label = (wchar_t*)malloc(sizeof(wchar_t)*(bls)); + mbstowcs(label,labelopt,bls); + printf("Got the string option\n"); + + //If the element has a parrent + int parent = 0; + if(nargs >= 6){ + parent = luaL_optint(L,6,0); + printf("got the parrent\n"); + } + + + //Create the button + IGUIEnvironment* env = guidevice->getGUIEnvironment(); + //printf("Createing button with data %d %d %d %d, %p, %d, %s, %s\n", startx,starty,endx,endy,guielements[parent],gui_elenum,button_label,button_tooltip); + //Create the label + IGUIStaticText* llabel = (IGUIStaticText*) env->addStaticText(label,core::rect(startx,starty,endx,endy),false,false, guielements[parent], gui_elenum++, false); + printf("Created the button\n"); + + //Register it's callback + registerguicallback(llabel,EGET_ELEMENT_HOVERED,iguilabelevent); + + //Create it's lua representation + LIGUIElement* ltext = (LIGUIElement*)lua_newuserdata(L, sizeof(LIGUIElement)); + int tref = luaL_ref(L,LUA_REGISTRYINDEX); + iguielements[llabel] = tref; + lua_rawgeti(L,LUA_REGISTRYINDEX,tref);//Put it back on the stack since luaL_ref pops the object. + + //Set it's metatable + luaL_getmetatable(L, "gui.iguilabel"); + lua_setmetatable(L, -2); + + //Create the struct + ltext->e = llabel; + ltext->funcmap = hashmap_new(); + ltext->type = "iguilabel"; + + //Free up anything made in this function + free(label); + + //Put it on top and return it + lua_rawgeti(L,LUA_REGISTRYINDEX,tref); + return 1; +} + +static const luaL_reg iguilabel_f[] = { + {"new", newiguilabel}, + {"gethandeler", guigethandeler}, + {"sethandeler", guisethandeler}, + {0,0}, +}; + +static const luaL_reg iguilabel_m[] = { + {"move", moveiguielement}, + {"settext", setiguitext}, + {"remove", removeiguielement}, + {0, 0}, +}; + +int iguilabel_register(lua_State* L, IrrlichtDevice* d){ + + luaL_newmetatable(L, "gui.iguilabel"); + + luaL_register(L,"iguilabel",iguilabel_f); + + lua_pushstring(L,"__index"); + lua_pushstring(L,"gethandeler"); + lua_gettable(L,-3); + lua_settable(L,-4); + + lua_pushstring(L,"__newindex"); + lua_pushstring(L,"sethandeler"); + lua_gettable(L,-3); + lua_settable(L,-4); + + luaL_register(L, NULL, iguilabel_m); + + return 1; +} diff --git a/src/client/lua_api/scene/icamera.hpp b/src/client/lua_api/scene/icamera.hpp new file mode 100644 index 0000000..15525f8 --- /dev/null +++ b/src/client/lua_api/scene/icamera.hpp @@ -0,0 +1,11 @@ + +#include +#include +extern "C" { + #include + #include + #include +} +#include + +int icamera_register(lua_State* L, irr::IrrlichtDevice* d); -- cgit v1.2.3-70-g09d2