#include "../../mainproc/GameMain.h"
#include "LoginParent.h"

CLoginParent*				g_pLoginParent = NULL;

int	LuaFunc_QuitGame			(lua_State *L);
int	LuaFunc_SetCurrentScreen	(lua_State *L);

// ----------------------------------------------------------------------------
CLoginParent::CLoginParent(CInterface* object) : CInterfaceBase(object)
{
	m_currentScreen.clear();

	g_pLoginParent = this;
}

// ----------------------------------------------------------------------------
CLoginParent::~CLoginParent()
{
	g_pLoginParent = NULL;
}

// ----------------------------------------------------------------------------
void CLoginParent::RegisterFunc()
{
	lua_State* L = GetLuaStateLogin();
	if (L)
	{
		lua_register(L, "QuitGame",				LuaFunc_QuitGame);
		lua_register(L, "SetCurrentScreen",		LuaFunc_SetCurrentScreen);		
	}
}

// --------------------------------------------------------------------------------------
void CLoginParent::SendLoginScreen(const char* arg)
{
	lua_State* L = m_interface->GetUiLogin()->GetLuaState();
	if ( L )
	{
		lua_pushstring(L, arg);
		lua_setglobal(L, "arg1");
		SendLoginEvent(UiEvent_SetLoginScreen);
	}
}

// ----------------------------------------------------------------------------
int	LuaFunc_QuitGame (lua_State *L)
{
	g_pGameMain->Exit();
	return 0;
}

// ----------------------------------------------------------------------------
int LuaFunc_SetCurrentScreen (lua_State *L)
{
	g_pLoginParent->SetCurrentScreen(luaL_checkstring(L, 1));
	return 0;
}