#ifndef __CTILEGAME_INTERFACES__
#define __CTILEGAME_INTERFACES__

//#include "TileGameMenu.h"

enum TextureID
{
	TexLogo=1,
	TexPieces,
	TexPiecesSelected,
	TexFontScore,
	TexGradient,
	TexMeter,
	TexMeterBase,
	TexParticle,
	TexFont,
	TexBackground,
        TexExtra1,
	
	TexEndOfList
};

struct GameTexture
{
	TextureID id;
	const char *name;
	int tilesX;
	int tilesY;
	unsigned int glId;
	
	//float ow;
	//float oh;

	float matrix[16];
};



extern GameTexture gameTextures[];




enum eTILEGAME_EFFECT {
	eCLICK=1, 
	eCHANGING,
	eCHANGE_COMPLETED,
	eEFFECT_LEVELCOMPLETED,
	eEFFECT_NEWLEVEL,
	eEFFECT_GAMEOVER,
	eILLEGAL_MOVE,
	eEFFECT_DESTROYING,
	eEFFECT_DESTROYING_BONUS,
	eEFFECT_MENU,
	eEFFECT_BUYMORE,
	eEFFECT_EXIT,
        eEFFECT_BLOCK_BEGIN_FINISHED,
        eEFFECT_BLOCK_VANISH_STARTED,
        eEFFECT_XBONUS,
        eEFFECT_SCORECHANGED,

	// number of items
	eTILEGAME_EFFECT_MAX
};


class ITileGame;			// forward declaration


class ITileRenderer {
public:
	ITileRenderer() {};
	virtual ~ITileRenderer() {};

	void setGame( ITileGame *game ) { m_game = game; }			// should be called after game is created. 
	
	
	virtual void renderTile( int fixedx, int fixedy, 
							 int fixedWidth, int fixedHeight, 
							int angle, // FIXME remove default
 							int mode,
							 unsigned int tileIndex, unsigned int arg ) {};


	virtual void renderBackground( unsigned int index ) {};
	virtual void renderForeground( unsigned int index ) {};
	
	
	
	virtual void effectNotify( eTILEGAME_EFFECT effect, unsigned int arg1, unsigned int arg2 ) {};

	virtual int run( int fixedFrameTime16Bit ) { return 0; };


protected:
	ITileGame *m_game;
	
};




enum eTILEGAME_ATTRIBUTE {
	eSCORE=1, 
	eATTRIBUTE_HIGHSCORE,
	eTIMELIMIT_CURRENT,
	eTIMELIMIT_MAX,
	eATTRIBUTE_CURRENTLEVEL,
	eATTRIBUTE_DIFFICULTY
};


enum eTILEGAMESTATE {
	eTILEGAMESTATE_NOTSET=1,
	eTILEGAMESTATE_MENU,
	eTILEGAMESTATE_RUNGAME, 
	eTILEGAMESTATE_GAMEOVER,
	eTILEGAMESTATE_PAUSED,
        eTILEGAMESTATE_SHOWINFOSCREEN,
	//jne..
};
	
enum eMOUSEEVENT {
	eMOUSEEVENT_BUTTONUP=1, 
	eMOUSEEVENT_BUTTONDOWN,
	eMOUSEEVENT_MOUSEDRAG
};


class CParticleEngine;


class ITileGame {
public:
	ITileGame( ITileRenderer *renderer, int x=0, int y=0, int width=65536, int height=65536 );
	virtual ~ITileGame();

	virtual void endGame() {};			// Call this to end the game, if ongoing.

	
			// SHOULD BE named mouseevent or similar, ... let's change it some day. 
	void click( int fixedx, int fixedy, eMOUSEEVENT etype );		

	int run( int fixedFrameTime16Bit );
	int draw();

	void setGameState( eTILEGAMESTATE newstate );
	
	virtual void gameClick( int fixedx, int fixedy, eMOUSEEVENT etype ) = 0;
	virtual int gameRun( int fixedFrameTime16Bit ) = 0;
	virtual int gameDraw() = 0;
	virtual void gameStateChanged() = 0;
	


	virtual int getIntAttribute( eTILEGAME_ATTRIBUTE att, unsigned int arg ) = 0;
	virtual void setIntAttribyte( eTILEGAME_ATTRIBUTE att, int set ) = 0;
			
	
	
	// return nonzero if game is on going
	virtual int load() = 0;
	virtual int save() = 0;

        virtual void pause() {};
        virtual void resume() {};
	// unlink



	

	void setGameArea( int x, int y, int width, int height ) {
		m_areaX = x; 
		m_areaY = y;
		m_areaWidth = width;
		m_areaHeight = height;
	};

	

protected:
	CParticleEngine *m_pengine;
	ITileRenderer *m_renderer;
	
	
	int m_areaX, m_areaY, m_areaWidth, m_areaHeight;

	


	// basic functionality of any game (which we are doing)
	eTILEGAMESTATE			m_state;
	
	int						m_logoState;			// states: 0 - invisible, 65536 - completely visible
	int						m_hudState;

	//CTileGameMenu			*m_menu;				// will receive al control as long as exists.
	
};



extern "C" ITileGame *createTileGame( ITileRenderer *renderer, int x=0, int y=0, int width = 65536, int height=65536 );


#endif
