Quellcode durchsuchen

update Lua binds according to gui implementation

mikymod vor 12 Jahren
Ursprung
Commit
802ef55bda
4 geänderte Dateien mit 77 neuen und 0 gelöschten Zeilen
  1. 2 0
      engine/lua/LuaEnvironment.cpp
  2. 1 0
      engine/lua/LuaEnvironment.h
  3. 31 0
      engine/lua/LuaStack.h
  4. 43 0
      engine/lua/LuaWorld.cpp

+ 2 - 0
engine/lua/LuaEnvironment.cpp

@@ -82,6 +82,8 @@ CE_EXPORT int luaopen_libcrown(lua_State* /*L*/)
 	load_controller(*env);
 	load_physics_world(*env);
 
+	load_gui(*env);
+
 	return 1;
 }
 

+ 1 - 0
engine/lua/LuaEnvironment.h

@@ -114,6 +114,7 @@ void load_sprite(LuaEnvironment& env);
 void load_actor(LuaEnvironment& env);
 void load_controller(LuaEnvironment& env);
 void load_physics_world(LuaEnvironment& env);
+void load_gui(LuaEnvironment& env);
 
 CE_EXPORT int32_t luaopen_libcrown(lua_State* L);
 

+ 31 - 0
engine/lua/LuaStack.h

@@ -46,7 +46,10 @@ class PhysicsWorld;
 struct Actor;
 struct Controller;
 class ResourcePackage;
+struct Gui;
+
 typedef Id SoundInstanceId;
+typedef Id GuiId;
 
 void clear_lua_temporaries();
 
@@ -308,6 +311,34 @@ public:
 		return id;
 	}
 
+	//-----------------------------------------------------------------------------
+	void push_gui_id(GuiId id)
+	{
+		uintptr_t enc = id.encode();
+		lua_pushlightuserdata(m_state, (void*)enc);
+	}
+
+	//-----------------------------------------------------------------------------
+	GuiId get_gui_id(int32_t index)
+	{
+		uint32_t enc = (uintptr_t) lua_touserdata(m_state, index);
+		GuiId id;
+		id.decode(enc);
+		return id;
+	}
+
+	//-----------------------------------------------------------------------------
+	void push_gui(Gui* gui)
+	{
+		lua_pushlightuserdata(m_state, gui);
+	}
+
+	//-----------------------------------------------------------------------------
+	Gui* get_gui(int32_t index)
+	{
+		return (Gui*) lua_touserdata(m_state, index);
+	}
+
 	bool is_vector2(int32_t index);
 	bool is_vector3(int32_t index);
 	bool is_matrix4x4(int32_t index);

+ 43 - 0
engine/lua/LuaWorld.cpp

@@ -172,6 +172,45 @@ CE_EXPORT int world_set_sound_volume(lua_State* L)
 	return 0;
 }
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int world_create_window_gui(lua_State* L)
+{
+	LuaStack stack(L);
+
+	World* world = stack.get_world(1);
+
+	GuiId gui = world->create_window_gui(stack.get_string(2));
+	stack.push_gui_id(gui);
+
+	return 1;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int world_destroy_gui(lua_State* L)
+{
+	LuaStack stack(L);
+
+	World* world = stack.get_world(1);
+
+	world->destroy_gui(stack.get_gui_id(2));
+
+	return 0;
+}
+
+//-----------------------------------------------------------------------------
+CE_EXPORT int world_lookup_gui(lua_State* L)
+{
+	LuaStack stack(L);
+
+	World* world = stack.get_world(1);
+
+	Gui* gui = world->lookup_gui(stack.get_gui_id(2));
+
+	stack.push_gui(gui);
+
+	return 1;	
+}
+
 //-----------------------------------------------------------------------------
 CE_EXPORT int world_physics_world(lua_State* L)
 {
@@ -198,6 +237,10 @@ void load_world(LuaEnvironment& env)
 	env.load_module_function("World", "set_sound_range", 	world_set_sound_range);
 	env.load_module_function("World", "set_sound_volume", 	world_set_sound_volume);
 
+	env.load_module_function("World", "create_window_gui",	world_create_window_gui);
+	env.load_module_function("World", "destroy_gui",		world_destroy_gui);
+	env.load_module_function("World", "lookup_gui",			world_lookup_gui);
+
 	env.load_module_function("World", "physics_world",		world_physics_world);
 }