package scenes;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.ggj2k20.game.GameMain;

import helpers.GameInfo;
import huds.MainMenuButtons;


public class MainMenu implements Screen
{

    private GameMain gameMain;

    private OrthographicCamera mainCamera;

    private Texture bgImage;

    private FitViewport gameViewport;

    private MainMenuButtons mainMenuButtons;

    public MainMenu(GameMain gameMain)
    {
        this.gameMain = gameMain;

        mainCamera = new OrthographicCamera(GameInfo.W, GameInfo.H);
        mainCamera.position.set(GameInfo.W / 2f, GameInfo.H / 2f, 0);

        gameViewport = new FitViewport(GameInfo.W, GameInfo.H);

        bgImage = new Texture("Backgrounds/Dam Final.jpeg");

        mainMenuButtons = new MainMenuButtons(gameMain);

    }

    @Override
    public void show()
    {

    }

    @Override
    public void render(float delta)
    {
        // clear the color and the screen
        Gdx.gl.glClearColor(0, 0, 0, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        gameMain.getBatch().begin();
        gameMain.getBatch().draw(bgImage, 0, 0);
        gameMain.getBatch().end();

        gameMain.getBatch().setProjectionMatrix(mainMenuButtons.getStage().getCamera().combined);
        mainMenuButtons.getStage().draw(); // to draw button to the screen
        mainMenuButtons.getStage().act();
    }

    @Override
    public void resize(int width, int height)
    {
        gameViewport.update(width, height);
    }

    @Override
    public void pause()
    {

    }

    @Override
    public void resume()
    {

    }

    @Override
    public void hide()
    {

    }

    @Override
    public void dispose()
    {
        bgImage.dispose();
        mainMenuButtons.getStage().dispose();
    }
}
