package com.example.jmastermind.Menu;

import android.media.MediaPlayer;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.jmastermind.Events.CanVoidEvent;
import com.example.jmastermind.Events.MenuEvent;
import com.example.jmastermind.Game.ColorDefSelect;
import com.example.jmastermind.Game.Game;
import com.example.jmastermind.Rules.Rules;
import com.example.jmastermind.R;

public class Menu extends AppCompatActivity {
    private MediaPlayer mp;

    /**
     * Le menu du jeu.
     * */
    public Menu() {}

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

        this.mp = MediaPlayer.create(this, R.raw.menusong);
        this.mp.setLooping(true);
        this.mp.start();

        CanVoidEvent cve = new CanVoidEvent(this);
        CheckBox bc = (CheckBox) findViewById(R.id.canvoid);
        bc.setChecked(false);
        bc.setOnCheckedChangeListener(cve);

        Button btnSoloGame = (Button) findViewById(R.id.robotselect);
        btnSoloGame.setOnClickListener(new MenuEvent(this, Game.class, this.mp));

        Button btnMultiGame = (Button) findViewById(R.id.jcjselect);
        btnMultiGame.setOnClickListener(new MenuEvent(this, ColorDefSelect.class, this.mp));

        Button btnRules = (Button) findViewById(R.id.rules);
        btnRules.setOnClickListener(new MenuEvent(this, Rules.class, this.mp));
    }

    @Override
    public void onBackPressed() {
        this.mp.stop();
        this.finishAffinity();
    }
}
