using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameMenuState : BaseGameState {

    public override void InitState () {
        base.InitState();

        this.gameController.UIController.MenuView.OnNewGameClicked += OnNewGame;
        this.gameController.UIController.MenuView.OnQuitClicked += OnQuit;
        this.gameController.UIController.MenuView.ShowMenu(this.gameController.DataStorage.GlobalStatistics);

        this.gameController.MapController.GenerateMap(10, 10);

        var menuCamera = new MenuCameraState();
        menuCamera.focusPosition = this.gameController.MapController.MapInstance.Tiles[5, 5].transform.position;
        this.gameController.CameraController.ChangeState(menuCamera);

        this.gameController.UIController.BlackedView.HideView();
    }

    public override void DeinitState () {
        this.gameController.UIController.MenuView.OnNewGameClicked -= OnNewGame;
        this.gameController.UIController.MenuView.OnQuitClicked -= OnQuit;
        this.gameController.UIController.MenuView.HideView();
    
        base.DeinitState();
    }

    private void OnNewGame () {
        this.gameController.UIController.BlackedView.OnScreenBlacked += OnBlackedNewGame;
        this.gameController.UIController.BlackedView.ShowView();
    }

    private void OnBlackedNewGame () {
        this.gameController.UIController.BlackedView.OnScreenBlacked -= OnBlackedNewGame;
        this.gameController.ChangeState(new GenerateNewGameState());
    }

    private void OnQuit () {
        this.gameController.UIController.BlackedView.OnScreenBlacked += OnBlackedQuit;
        this.gameController.UIController.BlackedView.ShowView();
    }

    private void OnBlackedQuit () {
        this.gameController.UIController.BlackedView.OnScreenBlacked -= OnBlackedQuit;
        Application.Quit();
    }
}
