#pragma once

#include <Windows.h>
#include <stdio.h>
#include <string>
#include <vector>
#include "DefRegisterEvent.h"
#include "../ui/core/ui.h"

class CInterface;
extern	CInterface*			g_pInterface;

using namespace std;

#define INTERFACE_SAVE_PATH		"C:\\Temp"

class CInterfaceBase
{
public:
	CInterfaceBase(CInterface* object);
	virtual ~CInterfaceBase();
	
	virtual	void				Update(float elapsedTime)				{}	
	virtual	void				RegisterFunc()							{}
	virtual	lua_State*			GetLuaStateLogin();
	virtual	lua_State*			GetLuaStateWorld();
	virtual	void				SendLoginEvent(const char* event);
	virtual	void				SendWorldEvent(const char* event);
	virtual	void				LockedItem()							{}
	virtual	void				UnlockedItem()							{}
	virtual	void				Save()									{}
	virtual	void				Load()									{}
	virtual	void				BuildFrames()							{}

protected:
	virtual	bool				GetGlobalPath(const char* name, char* outPath, int outSize);
	virtual	bool				GetLocalPath(const char* name, char* outPath, int outSize);	

protected:
	CInterface*					m_interface;
};

class CInterface
{
public:
	CInterface(const char* resourcePath=NULL);	
	~CInterface();

	enum {
		eIntreface_Process_Login		= 1,
		eIntreface_Process_World,
	};	
	
	virtual	void				BuildFramesLogin(int width, int height);
	virtual	void				BuildFramesWorld(int width, int height);
	virtual	void				RegisterFunc(lua_State* L);
	virtual	bool				WndProc(UINT iMsg, WPARAM wParam, LPARAM lParam);
	virtual	void				Update(float elapsedTime, InputState &state);
	virtual	void				Render2D();
	virtual	void				Render3D();
	virtual	void				SetScreenSize(float x, float y);
	virtual	void				SetResourcePath(const char* resourcePath);
	virtual	const char*			GetResourcePath()						{ return m_resourcePath.c_str(); }
	virtual	void				SetVisible(bool isVisible)				{ m_isVisible = isVisible; }
	virtual	bool				IsVisible()								{ return m_isVisible; }
	virtual	void				SetEnable(bool isEnable)				{ m_isEnable = isEnable; }
	virtual	bool				IsEnable()								{ return m_isEnable; }
	virtual	CUi*				GetUi();
	virtual	CUi*				GetUiLogin()							{ return m_uiLogin; }
	virtual	CUi*				GetUiWorld()							{ return m_uiWorld; }
	virtual	CUiInput*			GetUiInput();
	virtual void				SetProcessType(int type);
	virtual	void				SetCapture();
	virtual	void				ReleaseCapture();
	virtual	void				SetPlayerName(const char* playerName);
	virtual const char*			GetPlayerName()							{ return m_playerName.c_str(); }
	virtual	const char*			GetSavePath()							{ return m_savePath.c_str(); }

	virtual	void				LoadPlayerData();
	virtual	void				SavePlayerData();

protected:
	virtual	bool				IsTocFile(const char* filename);
	virtual	void				LoadFiles(CUi* ui, const char* filename);
	virtual	void				LoadFolders(CUi* ui, const char* foldername);
	virtual	void				CreateUiLogin(int width, int height);
	virtual	void				CreateUiWorld(int width, int height);

protected:
	int							m_processType;
	CUi*						m_uiLogin;
	CUi*						m_uiWorld;
	string						m_resourcePath;
	string						m_playerName;
	string						m_savePath;
	bool						m_isVisible;
	bool						m_isEnable;

	vector<CInterfaceBase*>		m_loginFrames;
	vector<CInterfaceBase*>		m_worldFrames;
};