/*
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package macampcorp.macamp.activities;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import macampcorp.macamp.activities.R;
import macampcorp.macamp.game.Game;

public class MenuActivity extends AppCompatActivity {

    protected boolean mIsSaved;
    protected Button mContinue;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);
        mContinue = findViewById(R.id.b_continue);
        Game g = Game.load(this);
        if(g==null)
        {
            mContinue.setVisibility(View.GONE);
            mIsSaved=false;
        }else
        {
            mContinue.setVisibility(View.VISIBLE);
            mIsSaved=true;
        }

    }

    public void onNew(View v)
    {
        if(!mIsSaved)
        {
            SelectDifficultActivity.start(this);
            return;
        }
        askForReset();

    }

    public void onContinue(View v)
    {
        HostActivity.startGame(this, false);
    }

    public void askForReset()
    {
        final Activity t = this;
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        // Add the buttons
        builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                SelectDifficultActivity.start(t);
            }
        });
        builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {

            }
        });
        // Set other dialog properties
        builder.setMessage(R.string.toast_continue);

        // Create the AlertDialog
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    public static void start(Activity a)
    {
        Intent i = new Intent(a, MenuActivity.class);
        a.startActivity(i);
    }
}
