Public feed #892500

Untitled

public text v1 · immutable
Raw Edit
·published 2008-02-05 14:14 UTC
rendered paste body
#include "../src/Stylus.h"
#include "AEEVCodes.h"
#include "../src/Constants.h"
#include "../TFC/TFCStaticProvider.h"
#include "../src/UIController.h"
#include "../src/StaticProvider.h"

	#define NO_ZONE_INFO  -1
	
	#define NB_INFO_PER_ZONE 5
	
	#define PRESS		0
	#define RELEASE 	1
	#define DRAG 		2

	
	//uniquely identify ZONE,not these are not the same as index into zoneInfo[]
	//infact these zones can be added and removed anywhere within zoneInfo[] 
	
	#define ZONE_SOFTKEYLEFT  				  0
	#define ZONE_SOFTKEYRIGHT 				  1
	
	#define ZONE_MAINMENU_PLAY 				  2
	#define ZONE_MAINMENU_ARCHIVES 			  3
	#define ZONE_MAINMENU_OPTIONS 			  4
	#define ZONE_MAINMENU_HELP	 			  5
	#define ZONE_MAINMENU_GMG	 			  6

	#define ZONE_PLAYMENU_CLASSIC 			  7
	#define ZONE_PLAYMENU_ACTION 			  8
	
	#define ZONE_ARCHIVESMENU_HIGHSCORES 	  9
	#define ZONE_ARCHIVESMENU_BESTWORDS 	  10
	#define ZONE_ARCHIVESMENU_LONGESTWORDS 	  11
	
	#define ZONE_OPTIONSMENU_SOUND			  12
	#define ZONE_OPTIONSMENU_INPUT			  13
	#define ZONE_OPTIONSMENU_RESETARCHIVES 	  14
	#define ZONE_OPTIONSMENU_RESETTUTORIAL 	  15
	
	#define ZONE_HELPMENU_TUTORIAL			  16
	#define ZONE_HELPMENU_PLAYGUIDE			  17
	#define ZONE_HELPMENU_CREDITS			  18
	#define ZONE_HELPMENU_ABOUT				  19
	
	#define ZONE_TUTORIALMENU_CURSOR 		  20
	#define ZONE_TUTORIALMENU_SINGLETAP 	  21

	#define ZONE_CLASSICMENU_RESUME 		  22
	#define ZONE_CLASSICMENU_NEWGAME 		  23

	#define ZONE_ACTIONMENU_RESUME 			  24
	#define ZONE_ACTIONMENU_NEWGAME 		  25
	
	#define ZONE_PAUSEMENU_MAINMENU			  26
	#define ZONE_PAUSEMENU_SOUND			  27
	#define ZONE_PAUSEMENU_INPUT			  28
	
	////////////////TILES///////////////////////////////////////
	#define ZONE_TILE_0 					29
	#define ZONE_GAME_TILE_1				  30
	#define ZONE_GAME_TILE_2 				  31
	#define ZONE_GAME_TILE_3 				  32
	#define ZONE_GAME_TILE_4 				  33
	#define ZONE_GAME_TILE_5 				  34
	#define ZONE_GAME_TILE_6 				  35
	#define ZONE_GAME_TILE_7 				  36
	#define ZONE_GAME_TILE_8 				  37
	#define ZONE_GAME_TILE_9 				  38
	
	#define ZONE_GAME_TILE_10 				  39
	#define ZONE_GAME_TILE_11				  40
	#define ZONE_GAME_TILE_12 				  41
	#define ZONE_GAME_TILE_13 				  42
	#define ZONE_GAME_TILE_14 				  43
	#define ZONE_GAME_TILE_15 				  44
	#define ZONE_GAME_TILE_16 				  45
	#define ZONE_GAME_TILE_17 				  46
	#define ZONE_GAME_TILE_18 				  47
	#define ZONE_GAME_TILE_19 				  48
	
	#define ZONE_GAME_TILE_20 				  49
	#define ZONE_GAME_TILE_21				  50
	#define ZONE_GAME_TILE_22 				  51
	#define ZONE_GAME_TILE_23 				  52
	#define ZONE_GAME_TILE_24 				  53
	#define ZONE_GAME_TILE_25 				  54
	#define ZONE_GAME_TILE_26 				  55
	#define ZONE_GAME_TILE_27 				  56
	#define ZONE_GAME_TILE_28 				  57
	#define ZONE_GAME_TILE_29 				  58
	
	#define ZONE_GAME_TILE_30 				  59
	#define ZONE_GAME_TILE_31				  60
	#define ZONE_GAME_TILE_32 				  61
	#define ZONE_GAME_TILE_33 				  62
	#define ZONE_GAME_TILE_34 				  63
	#define ZONE_GAME_TILE_35 				  64
	#define ZONE_GAME_TILE_36 				  65
	#define ZONE_GAME_TILE_37 				  66
	#define ZONE_GAME_TILE_38 				  67
	#define ZONE_GAME_TILE_39 				  68
	
	#define ZONE_GAME_TILE_40 				  69
	#define ZONE_GAME_TILE_41				  70
	#define ZONE_GAME_TILE_42 				  71
	#define ZONE_GAME_TILE_43 				  72
	#define ZONE_GAME_TILE_44 				  7
	#define ZONE_GAME_TILE_45 				  74
	#define ZONE_GAME_TILE_46 				  75
	#define ZONE_GAME_TILE_47 				  76
	#define ZONE_GAME_TILE_48 				  77
	#define ZONE_GAME_TILE_49 				  78
	
	#define ZONE_GAME_TILE_50 				  79
	#define ZONE_GAME_TILE_51				  80
	
	#define ZONE_SOUND_MENU_OFF				  81
	#define ZONE_SOUND_MENU_QUIET			  82
	#define ZONE_SOUND_MENU_MEDIUM 			  83
	#define ZONE_SOUND_MENU_LOUD			  84
	
	#define	ZONE_INPUT_MENU_SINGLE 			  85
	#define ZONE_INPUT_MENU_MULTI 			  86
	#define ZONE_INPUT_MENU_CURSOR 			  87
	
	#define ZONE_SCROLLBAR 					  88
	#define ZONE_SCROLLBAR_UP 				  89	
	#define ZONE_SCROLLBAR_DOWN 			  90


//	 Add a zone
	static void addZone(int x, int y, int w, int h, int id)
	{
		Game * pMe = Game::getInstance();
		StaticProvider  * sp = pMe->sp;


		////System.out.println("ADD ZONE id " + id + " @ " + zoneNb);
		sp->zoneInfo[sp->zoneNb * NB_INFO_PER_ZONE] = x;
		sp->zoneInfo[sp->zoneNb * NB_INFO_PER_ZONE + 1] = y;
		sp->zoneInfo[sp->zoneNb * NB_INFO_PER_ZONE + 2] = w;
		sp->zoneInfo[sp->zoneNb * NB_INFO_PER_ZONE + 3] = h;
		sp->zoneInfo[sp->zoneNb * NB_INFO_PER_ZONE + 4] = id;
		
		sp->zoneNb++;
	}

	static void addSoftkeyZones()
	{
		//System.out.println("addSoftkeyZones");
		addZone(0, 295, 43, 25, ZONE_SOFTKEYLEFT);
		addZone(197, 295, 43, 25, ZONE_SOFTKEYRIGHT);
	}

	static void initBoard()
	{

		Game * pMe = Game::getInstance();
		StaticProvider  * sp = pMe->sp;

		//System.out.println("initBoard Zones");
		resetZones();
		
		//addZone(GCanvas.BOARD_POSITION_X,GCanvas.BOARD_POSITION_Y, 26, 26, ZONE_TILE_0);
		
		int currZone = ZONE_TILE_0;
		
		int x = 28;//GCanvas.BOARD_POSITION_X;
		int y = 48;//GCanvas.BOARD_POSITION_Y;
		int numR = 7; //every secong row has 8 tiles;
		for(int c = 0 ; c<7 ; c++)
		{
			if(c%2 ==0)
			{
				numR = 7; 
				y = 48;
			}
			else
			{
				numR = 8; 
				y = 48 - (sp->GCanvas_m_nTileH/2);
			}
		
			
			for(int r = 0; r <numR ; r++)
			{				
								
				addZone(x ,y,sp->GCanvas_m_nTileW , sp->GCanvas_m_nTileH, currZone);
				////System.out.println("currZone "  + currZone + " x: " + x + " y: " + y + " w " + GCanvas.m_nTileW + " h " + GCanvas.m_nTileH);
				y += (sp->GCanvas_m_nTileH);
				currZone++;				
			}
			x += (sp->GCanvas_m_nTileW);
		}
		
		//addZone(66,255,167,28,ZONE_TEXT_BOX);
		
	}

	static void initMainMenu()
	{
		resetZones();
		addZone(101, 101, 101, 26, ZONE_MAINMENU_PLAY);
		addZone(30, 130, 130, 43, ZONE_MAINMENU_ARCHIVES);
		addZone(87, 180, 120, 30, ZONE_MAINMENU_OPTIONS);
		addZone(37, 209, 124, 34, ZONE_MAINMENU_HELP);
		addZone(54, 244, 155, 40, ZONE_MAINMENU_GMG);
	}


	static void zonePress(int zoneId)
	{

	Game * pMe = Game::getInstance();
	StaticProvider  * sp = pMe->sp;

		//System.out.println("Zonepress " + zoneId);
		switch (zoneId)
		{
			case ZONE_SOFTKEYLEFT:
			//Input.HandleKeyPress((short)Constants.KEY_MAPPING_CODES.charAt(0));
			//System.out.println("LEFT " + (short)Constants.KEY_MAPPING_CODES.charAt(0));
			break;

			case ZONE_SOFTKEYRIGHT:
			// To be filled generate a SOFTKEY_RIGHT in Input.java
			//System.out.println("RIGHT");
			//Input.HandleKeyPress((short)Constants.KEY_MAPPING_CODES.charAt(1));
			break;

			case ZONE_MAINMENU_PLAY:
				//System.out.println("Zonepress ZONE_MAINMENU_PLAY");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_MAINMENU_ARCHIVES:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;

			case ZONE_MAINMENU_OPTIONS:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;
			break;

			case ZONE_MAINMENU_HELP:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 3;
			break;

			case ZONE_MAINMENU_GMG:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 4;
			break;
			///////////////////////////////////////////////
			case ZONE_PLAYMENU_CLASSIC:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_PLAYMENU_ACTION:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;

			///////////////////////////////////////////////
			case ZONE_ARCHIVESMENU_HIGHSCORES:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_ARCHIVESMENU_BESTWORDS:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;

			case ZONE_ARCHIVESMENU_LONGESTWORDS:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;
			break;
			
			///////////////////////////////////////////////
			case ZONE_OPTIONSMENU_SOUND:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;
//#ifndef NO_INPUT_MENU	
			case ZONE_OPTIONSMENU_INPUT:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;
//#endif
			case ZONE_OPTIONSMENU_RESETARCHIVES:
//#ifndef NO_INPUT_MENU
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;
//#else
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
//#endif
			break;

			case ZONE_OPTIONSMENU_RESETTUTORIAL:
//#ifndef NO_INPUT_MENU				
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 3;
//#else
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;
//#endif
			break;
			
			///////////////////////////////////////////////
			case ZONE_HELPMENU_TUTORIAL:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_HELPMENU_PLAYGUIDE:
				//System.out.println("Zonepress ZONE_HELPMENU_PLAYGUIDE");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;

			case ZONE_HELPMENU_CREDITS:
				//System.out.println("Zonepress ZONE_HELPMENU_CREDITS");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;				
			break;

			case ZONE_HELPMENU_ABOUT:
				//System.out.println("Zonepress ZONE_HELPMENU_ABOUT");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 3;				
			break;
			
			///////////////////////////////////////////////
			case ZONE_TUTORIALMENU_CURSOR:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_TUTORIALMENU_SINGLETAP:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;
			
			///////////////////////////////////////////////
			case ZONE_CLASSICMENU_RESUME:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_CLASSICMENU_NEWGAME:
				//GCanvas.stylusOP = "CLASSICMENU_NEWGAME";
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;
			
			///////////////////////////////////////////////
			case ZONE_ACTIONMENU_RESUME:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_ACTIONMENU_NEWGAME:
				//System.out.println("Zonepress ");
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;

			///////////////////////////////////////////////
			case ZONE_PAUSEMENU_MAINMENU:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;

			case ZONE_PAUSEMENU_SOUND:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;
//#ifndef NO_INPUT_MENU	
			case ZONE_PAUSEMENU_INPUT:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;
			break;
//#endif
			//SOUND MENU
			case ZONE_SOUND_MENU_OFF:			
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;
			
			case ZONE_SOUND_MENU_QUIET:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;	
			
			case ZONE_SOUND_MENU_MEDIUM: 		
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;
			break;
			
			case ZONE_SOUND_MENU_LOUD:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 3;
			break;
			//INPUT MENU
			case ZONE_INPUT_MENU_SINGLE:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 0;
			break;
			
//#ifndef QWERTY
			case ZONE_INPUT_MENU_MULTI:
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
			break;
//#endif			
			case ZONE_INPUT_MENU_CURSOR:
//#ifdef QWERTY
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 1;
//#else				
				sp->UIModel_UI_MENU_CURRENT_SELECTION[sp->UIModel_m_nUIState] = 2;
//#endif
			break;
		}
	}

	// Just record the zone that was released at the moment and treat it only at the end of the loop	
	static void zoneRelease(int zoneId)
	{
		Game * pMe = Game::getInstance();
		TFCStaticProvider  * tfcsp = pMe->tfcsp;
		tfcsp->zonePressed = zoneId;
	}
	
	// Fill this method with the appropriate zone handling. You recieve the zone value and according to it, do the appropriate action
	// Call that along with the flush of key presses in the TFC to have an equivalent functionnalities (must be synchronous)
	// TODO this is being called everyframe should really only do this when zonePressed !=-1
	static void flushZoneRelease()
	{		
		Game * pMe = Game::getInstance();
		TFCStaticProvider  * tfcsp = pMe->tfcsp;
		StaticProvider  * sp = pMe->sp;


		switch(tfcsp->zonePressed)
		{
		
			case ZONE_SOFTKEYLEFT:
				// To be filled generate a SOFTKEY_LEFT in Input.java
			
				//System.out.println( "REL: LEFT");
				//GCanvas.stylusOP = "REL: L " + zonePressed;				
				//Input::HandleKeyPress((short)Constants.KEY_MAPPING_CODES.charAt(0));
				Input::HandleKeyPress( Constants::KEY_MAPPING_CODES[0]);
			break;

			case ZONE_SOFTKEYRIGHT:
				//System.out.println( "REL: R");
				//GCanvas.stylusOP = "REL: R";	
				//Input::HandleKeyPress((short)Constants.KEY_MAPPING_CODES.charAt(1));
				Input::HandleKeyPress( Constants::KEY_MAPPING_CODES[1]);
			break;

			case ZONE_MAINMENU_PLAY:
				//System.out.println( "REL: MAINMENU_PLAY");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_MAIN_MENU[0]);
			break;
			
			case ZONE_MAINMENU_ARCHIVES:
				//System.out.println( "REL: MAINMENU_ARCHIVES");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_MAIN_MENU[1]);
			break;
			
			case ZONE_MAINMENU_OPTIONS:
				//System.out.println( "REL: MAINMENU_OPTIONS");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_MAIN_MENU[2]);
			break;
			
			case ZONE_MAINMENU_HELP:
				//System.out.println( "REL: MAINMENU_HELP");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_MAIN_MENU[3]);
			break;
			
			//If get more games is not defined this option quit
			case ZONE_MAINMENU_GMG:
				//System.out.println( "REL: MAINMENU_GMG");
//#ifdef GET_MORE_GAMES
				UIController::handleMenuSelection(UI_ACTION_GET_MORE_GAMES);
//#else
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_MAIN_MENU[4]);
//#endif
			break;

			case ZONE_PLAYMENU_CLASSIC:
				//System.out.println( "REL: PLAYMENU_CLASSIC");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_GAME_MENU[0]);
			break;
			
			case ZONE_PLAYMENU_ACTION:
				//System.out.println( "REL: PLAYMENU_ACTION");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_GAME_MENU[1]);
			break;
	
			case ZONE_ARCHIVESMENU_HIGHSCORES:
				//System.out.println( "REL: ARCHIVESMENU_HIGHSCORES");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_ACHIEVEMENTS_MENU[0]);
			break;
			
			case ZONE_ARCHIVESMENU_BESTWORDS:
				//System.out.println( "REL: ARCHIVESMENU_BESTWORDS");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_ACHIEVEMENTS_MENU[1]);
			break;
			
			case ZONE_ARCHIVESMENU_LONGESTWORDS:
				//System.out.println( "REL: ARCHIVESMENU_LONGESTWORDS");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_ACHIEVEMENTS_MENU[2]);
			break;
			///////////////////////////////////////////////
			case ZONE_OPTIONSMENU_SOUND:
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_OPTIONS_MENU[0]);
			break;
//#ifndef NO_INPUT_MENU	
			case ZONE_OPTIONSMENU_INPUT:
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_OPTIONS_MENU[1]);
			break;
//#endif
			case ZONE_OPTIONSMENU_RESETARCHIVES:
//#ifdef NO_INPUT_MENU	
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_OPTIONS_MENU[1]);
//#else				
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_OPTIONS_MENU[2]);
//#endif
			break;
			
			case ZONE_OPTIONSMENU_RESETTUTORIAL:
//#ifndef NO_INPUT_MENU	
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_OPTIONS_MENU[3]);
//#else	
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_OPTIONS_MENU[2]);
//#endif
			break;
			/////////////////////////////////////////////////
			case ZONE_HELPMENU_TUTORIAL:
				UIController::showMenu(UIConstants::GOTO_STATES_HELP_MENU[0]);
			break;
			
			case ZONE_HELPMENU_PLAYGUIDE:
				UIController::showMenu(UIConstants::GOTO_STATES_HELP_MENU[1]);
			break;
			
			case ZONE_HELPMENU_CREDITS:
				UIController::showMenu(UIConstants::GOTO_STATES_HELP_MENU[2]);
			break;
			
			case ZONE_HELPMENU_ABOUT:
				UIController::showMenu(UIConstants::GOTO_STATES_HELP_MENU[3]);
			break;
	
			case ZONE_TUTORIALMENU_CURSOR:
				//System.out.println( "REL: TUTORIALMENU_CURSOR");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_TUTORIAL_MENU[0]);
			break;
			
			case ZONE_TUTORIALMENU_SINGLETAP:
				//System.out.println( "REL: TUTORIALMENU_SINGLETAP");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_TUTORIAL_MENU[1]);
			break;

			case ZONE_CLASSICMENU_RESUME:
				//System.out.println( "REL: CLASSICMENU_RESUME");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_CLASSIC_GAME_MENU[0]);
			break;
			
			case ZONE_CLASSICMENU_NEWGAME:
				//System.out.println( "REL: CLASSICMENU_NEWGAME");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_CLASSIC_GAME_MENU[1]);
			break;

			case ZONE_ACTIONMENU_RESUME:
				//System.out.println( "REL: ACTIONMENU_RESUME");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_ACTION_GAME_MENU[0]);
			break;
			
			case ZONE_ACTIONMENU_NEWGAME:
				//System.out.println( "REL: ACTIONMENU_NEWGAME");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_ACTION_GAME_MENU[1]);
			break;

			case ZONE_PAUSEMENU_MAINMENU:
				//System.out.println( "REL:PAUSEMENU_MAINMENU");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_PAUSE_MENU[0]);
			break;
			
			case ZONE_PAUSEMENU_SOUND:
				//System.out.println( "REL:PAUSEMENU_SOUND");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_PAUSE_MENU[1]);
			break;
			
			case ZONE_PAUSEMENU_INPUT:
				//System.out.println( "REL:PAUSEMENU_INPUT");
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_PAUSE_MENU[2]);
			break;
			
			//SOUND MENU
			case ZONE_SOUND_MENU_OFF:			
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_SOUND[0]);
			break;
			
			case ZONE_SOUND_MENU_QUIET:
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_SOUND[1]);
			break;	
			
			case ZONE_SOUND_MENU_MEDIUM: 		
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_SOUND[2]);
			break;
			
			case ZONE_SOUND_MENU_LOUD:
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_SOUND[3]);
			break;
			//INPUT MENU
			case ZONE_INPUT_MENU_SINGLE:
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_CONTROL_METHOD[0]);
			break;
//#ifndef QWERTY			
			case ZONE_INPUT_MENU_MULTI:
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_CONTROL_METHOD[1]);
			break;
//#endif	
			case ZONE_INPUT_MENU_CURSOR:
//#ifdef QWERTY
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_CONTROL_METHOD[1]);
//#else
				UIController::handleMenuSelection(UIConstants::GOTO_STATES_BUTTON_MENU_CONTROL_METHOD[2]);
//#endif
			break;
			//SCROLL_BAR
			case ZONE_SCROLLBAR_DOWN:
				Text::scrollTextWindow(sp->UIController_m_nNumScrollLines);
			break;
				
			case ZONE_SCROLLBAR_UP:
				Text::scrollTextWindow(-sp->UIController_m_nNumScrollLines);
			break;
			

			default:
				////System.out.println("UNHANDLED RELEASE!!! " +  zonePressed);
			break;
			 
		}
		
		//zonePressed = -1;
	}
	
	static int lastY = -1;// this is the last position of the scroll bar
	

	static void onScrollBar(int currY)
	{
		
		/*
		 * from text.java this is how the scroller is drawn
		int barHeight = (m_nTextWindowHeight - 2 * TEXT_WINDOW_SCROLLER_SIZE - 4);
		int height = Math.min((m_nTextWindowVisibleLines * barHeight) / m_nTextWindowLinesCount, m_nTextWindowHeight);
		drawY = y + TEXT_WINDOW_SCROLLER_SIZE + 2 + (m_nTextWindowFirstLine * (barHeight - height)) / (m_nTextWindowLinesCount - m_nTextWindowVisibleLines);
		g.fillRect(drawX, drawY, TEXT_WINDOW_SCROLLER_SIZE, height);
		*/
		
		//GCanvas.stylusOP = "Down CY: " + currY + " LY: " + lastY;
		
		int linesToMove = 0;
		int dy = currY-lastY;
		
		//scroll speed depends on cursor movement
//		if(abs(dy)>0 && (abs(dy)<4))
//			linesToMove = 1;
//		else if((abs(dy)>4) && (abs(dy)<20))
//			linesToMove = 2;
//		else if(abs(dy)>20)
//			linesToMove = 3;
		
		if(dy>0)//Down
		{		
			Text::scrollTextWindow(linesToMove);
		}
		else if(dy<0)//Up
		{
			Text::scrollTextWindow(-linesToMove);
		}
		lastY=currY;
	}
	


	
	// Call this method from showMenu of UIController.java
	//this maps zones to tiles
	//the zones are labelled vertically because its easier to create them that way
	// the tiles are labelled horizontally
	/*
	 * I had to do this from within game code to make it work with tutorial
	 * for example there are points in the game where u cant accept a tile press and this is handled in games logic
	static void onTileRelease(int zone)
	{
		//System.out.println("press tile zone " + zone );
		
		//selectAndMoveTo(zoneToTile[zone] - 29);

		////System.out.println("Zone " + zone + " Tile "  +  (zone - ZONE_TILE_0));
	}
	*/
	
	static void selectAndMoveTo(int tile)
	{
		Game * pMe = Game::getInstance();
		StaticProvider  * sp = pMe->sp;
		sp->GCursor_m_nCursorTile= tile;
		GCursor::selectCursorTile(tile);				
	}
	
	//recieves the zoneID
	//the tiles Zones are currently labelled from 29 (ZONE_TILE_0) so I subtract this to get array element 0
	//returns the tile number as they are labeled in the game
	static int zoneToTile(int zone)
	{
		Game * pMe = Game::getInstance();
		StaticProvider  * sp = pMe->sp;
		int temp = sp->zoneToTile[zone - ZONE_TILE_0];
		return temp;
	}
	//check whether the current zone is a tile
	static bool isTile(int zone)
	{
		//when I && statements  with '<=' I get the error "generics not supported"		
		//if((zone >= ZONE_TILE_0) && (zone <= ZONE_GAME_TILE_51))//this doesn't compile !!
		if((zone > ZONE_TILE_0-1) && (zone < ZONE_GAME_TILE_51+1))
			return true;
		else
			return false;
	}
	
	
	
	
	//-------------------------------------------------------------------------------------------------------------------------------
	// Zone additions for all screens
	//-------------------------------------------------------------------------------------------------------------------------------

	// Call this method from showMenu of UIController.java
	static void activateMenuZones(int menuId)
	{
		//System.out.println("ACTIVATING MENU " + menuId);
		////System.out.println("activateMenuZones");
		switch (menuId)
		{
			case UI_STATE_MAIN_MENU:
				//System.out.println("initMainMenu");
				initMainMenu();
			break;

			case UI_STATE_NEW_GAME_MENU:
				//System.out.println("initMenuPlay");
				initMenuPlay();
			break;

			case UI_STATE_ACHIEVEMENTS_MENU:
				//System.out.println("initMenuArchives");
				initMenuArchives();
			break;

			case UI_STATE_OPTIONS_MENU:
				//System.out.println("initMenuOptions");
				initMenuOptions();
			break;

			case UI_STATE_HELP_MENU:
				//System.out.println("initMenuHelp");
				initMenuHelp();
			break;

			case UI_STATE_CLASSIC_GAME_MENU:
				//System.out.println("initMenuClassic");
				initMenuClassic();
			break;

			case UI_STATE_ACTION_GAME_MENU:
				//System.out.println("initMenuAction");
				initMenuAction();
			break;

			case UI_STATE_TUTORIAL_MENU:
				//System.out.println("initMenuTutorial");
				initMenuTutorial();
			break;

			case UI_STATE_PAUSE_MENU:
				initPauseScreen();
			break;
			
			case UI_STATE_NONE://going from pause menu back to game
				//System.out.println("initBorad");
				initBoard();
			break;
			
			case UI_STATE_BUTTON_MENU_SOUND://going from pause menu back to game
				initMenuSound();
			break;
			
			case UI_STATE_BUTTON_MENU_CONTROL_METHOD://going from pause menu back to game
				initMenuInput();
			break;
			
			case UI_STATE_INSTRUCTIONS_SCREEN:
			case UI_STATE_CREDITS_SCREEN:
			case UI_STATE_ABOUT_SCREEN:
				initScrollBar();
				break;

			default:
				//System.out.println("ACTIVATING MENU DEFAULT");
				resetZones();
				break;
		}
	}


	
	static void initMenuPlay()
	{
		resetZones();
		addZone(38, 148, 152, 31, ZONE_PLAYMENU_CLASSIC);
		addZone(37, 183, 166, 33, ZONE_PLAYMENU_ACTION);
	}
	
	static void initMenuArchives()
	{
		resetZones();
		addZone(38, 130, 152, 31, ZONE_ARCHIVESMENU_HIGHSCORES);
		addZone(41, 166, 165, 30, ZONE_ARCHIVESMENU_BESTWORDS);
		addZone(44, 202, 154, 30, ZONE_ARCHIVESMENU_LONGESTWORDS);
	}

	static void initMenuOptions()
	{
		//System.out.println("initMenuOptions");
		resetZones();
//#ifndef NO_INPUT_MENU		
		addZone(38, 112, 151, 30, ZONE_OPTIONSMENU_SOUND);
		addZone(41, 146, 164, 34, ZONE_OPTIONSMENU_INPUT);
		addZone(35, 183, 156, 32, ZONE_OPTIONSMENU_RESETARCHIVES);
		addZone(40, 220, 160, 33, ZONE_OPTIONSMENU_RESETTUTORIAL);
//#else
		addZone(37,129, 151, 30, ZONE_OPTIONSMENU_SOUND);
		addZone(42,166, 156, 32, ZONE_OPTIONSMENU_RESETARCHIVES);
		addZone(43,200, 160, 33, ZONE_OPTIONSMENU_RESETTUTORIAL);
//#endif
	}	

	static void initMenuHelp()
	{
		resetZones();
		addZone(38, 112, 151, 31, ZONE_HELPMENU_TUTORIAL);
		addZone(41, 148, 161, 31, ZONE_HELPMENU_PLAYGUIDE);
		addZone(35, 183, 153, 31, ZONE_HELPMENU_CREDITS);
		addZone(41, 220, 159, 31, ZONE_HELPMENU_ABOUT);
	}	
	
	static void initMenuSound() 
	{
		resetZones();
		addZone(39,111,152,32, ZONE_SOUND_MENU_OFF);
		addZone(40,148,165,32, ZONE_SOUND_MENU_QUIET);
		addZone(34,184,155,32, ZONE_SOUND_MENU_MEDIUM);
		addZone(40,220,162,32, ZONE_SOUND_MENU_LOUD);
			
	}	
	//todo implement cursor menu
	static void initMenuInput()
	{
		resetZones();
//#ifdef QWERTY
		addZone(37,147,150,32, ZONE_INPUT_MENU_SINGLE);
		addZone(37,183,154,32, ZONE_INPUT_MENU_CURSOR);
//#else
		addZone(37,130,150,32, ZONE_INPUT_MENU_SINGLE);
		addZone(40,165,164,32, ZONE_INPUT_MENU_MULTI);	
		addZone(43,202,154,32, ZONE_INPUT_MENU_CURSOR);
//#endif
	}	

	static void initMenuTutorial()
	{
		resetZones();
		addZone(38,148,151,33, ZONE_TUTORIALMENU_CURSOR);
		addZone(38,185,162,34, ZONE_TUTORIALMENU_SINGLETAP);
	}

	static void initMenuClassic()
	{
		resetZones();
		addZone(32,145,165,35, ZONE_CLASSICMENU_RESUME);
		addZone(33,181,170,38, ZONE_CLASSICMENU_NEWGAME);		
	}
	
	static void initMenuAction()
	{
		resetZones();
		addZone(32,145,165,35,ZONE_ACTIONMENU_RESUME);
		addZone(33,181,170,38,  ZONE_ACTIONMENU_NEWGAME);	
	}

	static void initPauseScreen()
	{
		resetZones();
//#ifndef NO_INPUT_MENU	
		addZone(37,130,153,29, ZONE_PAUSEMENU_MAINMENU);
		addZone(40,165,165,33, ZONE_PAUSEMENU_SOUND);		
		addZone(40,200,160,40, ZONE_PAUSEMENU_INPUT);
//#else
		addZone(37,146,153,32, ZONE_PAUSEMENU_MAINMENU);
		addZone(36,183,165,33, ZONE_PAUSEMENU_SOUND);		
//#endif
	}
	
	//the scroll bars to the side of texts windows, used on credits etc.
	//this is used in multiple menus so its called from other initMenus
	//therefore we do not reset zones
	static void initScrollBar()
	{
		resetZones();
		addZone(208,42,29,245,ZONE_SCROLLBAR);
		addZone(228,32,10,10,ZONE_SCROLLBAR_UP);		
		addZone(228,286,10,10,ZONE_SCROLLBAR_DOWN);
		//System.out.println("initScrollBar()");
	}
	
	//sets up tile zones for the game board

	
	//-------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------------------------
	// This must be called at the beginning of the game to initialise the max number of zones we will support
	static void init(int nbZones)
	{
		//System.out.println("init");
		// Allocate the info necessary to store the zones coordinates + action ID

		Game * pMe = Game::getInstance();
		TFCStaticProvider  * tfcsp = pMe->tfcsp;
		StaticProvider  * sp = pMe->sp;

		//zoneInfo = new int[NB_INFO_PER_ZONE * nbZones]; moved to Static Provider

		tfcsp->zonePressed= -1;

		sp->zoneProtected = 0;
		
		// Clear all the existing zones by putting a -1 as the X coordinate
		resetZones();

		addSoftkeyZones();
		setZoneProtected(2);
	}
	
	//TODO maybe add a b
	// Reset the zones not protected by the setProtectedZones
	static void resetZones()
	{
		Game * pMe = Game::getInstance();
		StaticProvider  * sp = pMe->sp;

		//System.out.println("resetZones()");
		sp->zoneNb = sp->zoneProtected;
		for(int i =2;i<255;i++)  // This is probably all messed up. //TODO come back and redo this code. Seems a little over complicated.
		{
			sp->zoneInfo[i * NB_INFO_PER_ZONE + 4] = -1;//set ids to 0 deactivating the zone 	
		}
			
	}



	static void setZoneProtected(int zoneId)
	{
		Game * pMe = Game::getInstance();
		StaticProvider  * sp = pMe->sp;
		sp->zoneProtected = zoneId;
	}
	

/*
	static int abs(int x)
	{
		return x = x > 0 ? x : 0 - x;	
	}
*/
	// Check if the stylus is actually in one zone and call the callback to handle the event in that case
	// Please call this method when pointerPresse(x, y) is called and pointerRelease(x, y)
	//type can be PRESS RELEASE DRAG
	static void checkZones(int x, int y, int type)
	{

		Game * pMe = Game::getInstance();
		StaticProvider  * sp = pMe->sp;

		int i;
		
		boolean a = false;
		boolean b = false;
		boolean c = false;
		boolean d = false;
		int zone = -1;
		
		if(type == DRAG)
		{
			sp->dragging = true;
		}
		else
		{
			sp->dragging = false;
		}
		
		//this is to dismiss the speech bubble, slightly hacky 
		//but probably the neatest way to do it
		//#if DEBUG
		//System.out.println("m_bDrawSpeechBubble " +  GCanvasController.m_bDrawSpeechBubble);
		//System.out.println("Type " +  type );
		//System.out.println("y " +  y );
		
		//#endif
		if(sp->GCanvasController_m_bDrawSpeechBubble && (type == RELEASE) && (y <200) && (y > 133)
				&& (sp->UIModel_m_nUIState == UI_STATE_NONE) )
		{
			//zoneRelease(ZONE_SOFTKEYLEFT);	
			Input::HandleKeyPress( Constants::KEY_MAPPING_CODES[0]);
			//System.out.println("STATE= " + UIModel.m_nUIState + " UI_STATE_PAUSE_MENU: " +  UI_STATE_PAUSE_MENU);
			return;
		}
		
		for (i = 0 ; i < sp->zoneNb ; i++)
		{			
			//bounding box collision
			a = (sp->zoneInfo[i * NB_INFO_PER_ZONE]     < x);
			b = (sp->zoneInfo[i * NB_INFO_PER_ZONE + 1] < y);
			c = (sp->zoneInfo[i * NB_INFO_PER_ZONE] + sp->zoneInfo[i * NB_INFO_PER_ZONE + 2] > x);//Position + width
			d = (sp->zoneInfo[i * NB_INFO_PER_ZONE + 1] + sp->zoneInfo[i * NB_INFO_PER_ZONE + 3] > y); //position + height
				
			if ( a && b && c && d )//a collision has occurred
			{
				//System.out.println("COLLISION " + zone + " Type " + type);
				zone = sp->zoneInfo[i * NB_INFO_PER_ZONE + 4];
				
				if(type == PRESS || type == DRAG)
				{
					//this means you can drag select on tiles
					if(type == DRAG && isTile(zone))
					{
						zoneRelease(zone);
					}
					else if(zone != ZONE_SCROLLBAR)
					{						
						zonePress(zone);
						
					}
					else if(zone == ZONE_SCROLLBAR && type == DRAG)
					{
						onScrollBar(y);
					}					
					
				}
				else
				{
					zoneRelease(zone);
					////System.out.println("zoneRelease " + i * NB_INFO_PER_ZONE + 4 );
				}
				//TODO u dont always want to do this on scroll only if Y has changed
				if(zone == ZONE_SCROLLBAR || zone == ZONE_SCROLLBAR_UP || zone == ZONE_SCROLLBAR_DOWN)
				{
					//UIModel.UI_STATE_DRAW_NEXT_FRAME[UIModel.m_nUIState] = true;//refresh
					sp->UIModel_UI_STATE_DRAW_NEXT_FRAME[sp->UIModel_m_nUIState] = true;
				}
				//lastY = y;	
				return;
			}
		}
	}