package com.uoc.educationalVG.memorycon;

import java.util.List;

import com.uoc.educationalVG.framework.Game;
import com.uoc.educationalVG.framework.Graphics;
import com.uoc.educationalVG.framework.Input.TouchEvent;
import com.uoc.educationalVG.utils.Assets;
import com.uoc.educationalVG.utils.Settings;

/**
 * @author "Beginning Android 4 Games Development"
 * @author (adapted by Sergi Colina)
 * 
 */
public class MainMenuScreen extends GameScreen {
	
    public MainMenuScreen(Game game) {
        super(game);
    }   

    @Override
    public void update(float deltaTime) {
        Graphics g = game.getGraphics();
        List<TouchEvent> touchEvents = game.getInput().getTouchEvents();
        game.getInput().getKeyEvents();       
        
        int len = touchEvents.size();
        for(int i = 0; i < len; i++) {
            TouchEvent event = touchEvents.get(i);
            if(event.type == TouchEvent.TOUCH_UP) {	//touch on screen
            	
            	if(inBounds(event, g.getWidth() - 75, 420, 70, 70)) { //volume on/off
                    Settings.setSoundEnabled(!Settings.isSoundEnabled());
                    if(Settings.isSoundEnabled())
                        Assets.getClick().play(1);
                }
            	
            	else if(inBounds(event, g.getWidth() - 130, g.getHeight() - 220, 70, 70)) { //volume on/off
            		game.setScreen(new TreasureScreen(game));
                    if(Settings.isSoundEnabled())
                        Assets.getClick().play(1);
                }
            	
            	else if(inBounds(event, 10, 170, 80, 80)) { // intro
            		game.setScreen(new IntroScreen(game));
                    if(Settings.isSoundEnabled())
                        Assets.getClick().play(1);
                    return;
                }
            	
            	else if(inBounds(event, 50, 270, 70, 70)) { // how to play
            		game.setScreen(new HowToScreen(game));
                    if(Settings.isSoundEnabled())
                        Assets.getClick().play(1);
                    return;
                }
            	
            	else if(inBounds(event, g.getWidth() - 100, 170, 90, 90) ) { // high scores
            		game.setScreen(new HighscoreScreen(game));
                    if(Settings.isSoundEnabled())
                        Assets.getClick().play(1);
                    return;
                }
            	
            	else if(inBounds(event, 110, 180, 95, 95) ) { // start
            		game.setScreen(new Exercise01IntroScreen(game));
                    if(Settings.isSoundEnabled())
                        Assets.getClick().play(1);
                    return;
                }
            }
        }
    }
    
   
    @Override
    public void present(float deltaTime) {
        Graphics g = game.getGraphics();
        
        g.drawPixmap(Assets.getMainMenuScreen(), 0, 0);
        
        if(Settings.isSoundEnabled())
        	g.drawPixmap(Assets.getButtons(), g.getWidth() - 75, 420, 0, 50, 60, 55);	//sound on
        else
        	g.drawPixmap(Assets.getButtons(), g.getWidth() - 75, 420, 0, 0, 60, 53);	//sound off
    }

    @Override
    public void pause() {        
        Settings.save(game.getFileIO());
    }

    @Override
    public void resume() {

    }

    @Override
    public void dispose() {

    }
}
