package app.brest.testmin3d;

import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.Toast;

import app.brest.testmin3d.R;
import app.brest.utils.Settings;
import app.brest.utils.app.brest.game.Game;
import app.brest.utils.app.brest.game.Resource;
import app.brest.utils.app.brest.game.Stage;

public class MenuActivity extends AppCompatActivity {
    protected Game mGame;
    protected ImageButton mICarte;
    protected ImageButton mIInventaire;
    protected ImageButton mIOptions;
    protected ImageButton mIScanner;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);

        Display display = getWindowManager().getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        int width = size.x;
        int height = size.y;
        int buttonHieght = (height-5*40)/6;
        mICarte = (ImageButton) findViewById(R.id.ib_carte);
        mIInventaire = (ImageButton) findViewById(R.id.ib_inventaire);
        mIOptions = (ImageButton) findViewById(R.id.ib_options);
        mIScanner = (ImageButton) findViewById(R.id.ib_scanner);

        mICarte.setLayoutParams(new LinearLayout.LayoutParams(buttonHieght, buttonHieght));
        mIInventaire.setLayoutParams(new LinearLayout.LayoutParams(buttonHieght, buttonHieght));
        mIOptions.setLayoutParams(new LinearLayout.LayoutParams(buttonHieght, buttonHieght));
        mIScanner.setLayoutParams(new LinearLayout.LayoutParams(buttonHieght, buttonHieght));


        Game g = null;//Game.load(this);

        if (g!= null && mGame==null) {
            mGame = g;
            mGame.newSensorManager(this);
            Toast.makeText(this, "Chargement", Toast.LENGTH_LONG).show();
        }
        else if( mGame==null)
        {
            mGame = new Game("game_medium", this);
            Toast.makeText(this, "Nouveau Jeu", Toast.LENGTH_LONG).show();
        }else if( mGame==null)
        {
            Toast.makeText(this, "Erreur", Toast.LENGTH_LONG).show();
            throw new Error("Le jeu n'est pas sauvegardé");
        }
        if(mGame!=null)
        {
            mGame.pickResource("b");
            mGame.pickResource("c");
            mGame.pickResource("d");
            mGame.pickResource("e");
        }
    }

    public void onResume()
    {
        super.onResume();
        mGame.printNResource("N res Resume");
        Log.e("________", "mGame : "+mGame);
    }

    public void onOptionsClick(View v)
    {
        Intent intent = new Intent(this, SettingsActivity.class);
        intent.putExtra("game", mGame);
        startActivity(intent);
    }


    public void onCarteClick(View v)
    {
        Intent intent = new Intent(this, ViewerActivity.class);
        intent.putExtra("map", mGame.getName()+"_map");
        startActivity(intent);
    }


    public void onScannerClick(View v)
    {
        Intent intent = new Intent(this, ARActivity.class);
        intent.putExtra("game", mGame);
        startActivity(intent);
    }


    public void onInventaireClick(View v)
    {
        Intent intent = new Intent(this, ResourceListActivity.class);
        intent.putExtra("game", mGame);
        startActivity(intent);
    }


    public void onInfoClick(View v) {
        Intent intent = new Intent(this, ViewerActivity.class);
        Stage s = mGame.getCurrentStageObj();
        Resource r = (s!=null)?s.getResource(): null;
        intent.putExtra("resource", r );
        startActivity(intent);
    }
}
