/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/utils/menusystem/menu_handler.hpp

*/

#ifndef SGX_UTILS_MENUSYSTEM_MENU_HANDLER_HPP
#define SGX_UTILS_MENUSYSTEM_MENU_HANDLER_HPP	1

#include "sgx/graphics/graphics.hpp"
#include "sgx/gui/gui.hpp"

#define MAX_MENU_BUTTONS	8

class CGameMenuHandler : public CGameObject, public sgxGUIWidgetCallbackHandler  {
public:
	class CButtonInfo {
	public:
		const char *pText;
		tUINT32		userdata;

		CButtonInfo(){}

		CButtonInfo(const char *p, tUINT32 u=0) : 
			pText(p),
			userdata(u) {
		}

		void set(const char *p, tUINT32 u=0) {
			pText = p;
			userdata = u;
		}
	};

	class CGameMenuHandlerSettings {
	public:
		CGameMenuHandlerSettings();
	};

	typedef enum {
		eYesNo,
		eOk,
		eYes,
		eCancel,
		eOkCancel,
		eNone,
	} tAlertType;
	//
	typedef enum {
		eMainMenu,
		eStdMenu,
	} tMenuType;
	//
	typedef enum {
		eNull,	// at menu start
		eEnter,
		eProcess,
		eExit,
	} tMenuState;
	//	
	CGameMenuHandler(const CGameMenuHandlerSettings &settings=CGameMenuHandlerSettings());
	virtual ~CGameMenuHandler();

	void prepareAlert(const sgxString &msg, const sgxString &question, tAlertType alert=eYesNo);
	void prepareMenu(const sgxString &msg, const sgxVector<sgxString> &buttonList, tMenuType type=eStdMenu);
	void prepareMenu(const sgxString &msg, const char *buttonList[], tMenuType type=eStdMenu);
	void prepareMenu(const sgxString &msg, const CButtonInfo *buttonList, tMenuType type=eStdMenu);

	tBOOL		isMenu();
	tMenuType	getMenuType();
	tAlertType	getAlertType();

	tBOOL		isMenuOpen() const;
	void		closeMenu();

	virtual 	void 	changeMenu(CSGXMenu *pMenu);
	virtual 	void 	openAlert(CSGXAlert *pAlert);
	
	virtual 	void 	draw() const;
	
	virtual 	void 	update(const tREAL32 telaps);
	virtual 	void 	updateMenu(const tREAL32 telaps);
	virtual 	void 	updateAlert(const tREAL32 telaps);

	virtual	   	sgxWidget *getButtonWidget(const tUINT32 index);

	virtual		void		pushMenuStack(CSGXMenu *pMenu);
	virtual		CSGXMenu *	popMenuStack();
	virtual		void		clearMenuStack();

	sgxString	m_Message;
	sgxString	m_Question;

	// Menu handler
	virtual		tBOOL	onGUIWidgetSelectActive(const sgxWidget *pWidget);

	 
protected:
	void		openMenu();

	tMenuState					m_State;
	CSGXMenu * 					m_pCurrentMenu;
	CSGXMenu * 					m_pNewMenu;
	CGameMenuHandlerSettings	m_Settings;
	
	CSGXAlert *					m_pCurrentAlert;
	
	sgxStack<CSGXMenu *>		m_MenuStack;

	tBOOL						m_bIsMenu;
	tMenuType					m_MenuType;
	tAlertType					m_AlertType;
	tUINT32						m_AlertID;

	sgxWidget *					m_pOldGUIRoot;

	sgxWidget *					m_pFrame;
	sgxWidget *					m_pBackButton;
	sgxWidget *					m_pButtons[MAX_MENU_BUTTONS];

};


#endif	// SGX_UTILS_MENUSYSTEM_MENU_HANDLER_HPP

