package com.lubjam16.epiceggsmash.credits;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.viewport.FitViewport;
import com.badlogic.gdx.utils.viewport.Viewport;
import com.lubjam16.epiceggsmash.EpicEggSmash;
import com.lubjam16.epiceggsmash.game.Graphics;
import com.lubjam16.epiceggsmash.game.Sounds;
import com.lubjam16.epiceggsmash.global.Fonts;
import com.lubjam16.epiceggsmash.mainMenu.MainMenu;

/**
 * Created by stonek on 1/30/16.
 */
public class CreditsScreen
        extends InputAdapter
        implements Screen {
    private final EpicEggSmash game;

    private GlyphLayout backGL;
    private GlyphLayout creditsGL;

    private Vector2 backPosition;
    private Vector2 creditsPosition;

    private SpriteBatch batch;
    private Viewport viewport;

    public CreditsScreen(EpicEggSmash epicEggSmash) {
        viewport = new FitViewport(MainMenu.WIDTH, MainMenu.HEIGHT);
        batch = new SpriteBatch();
        game = epicEggSmash;

        creditsGL = new GlyphLayout(Fonts.smallFont,
                "Graphics:\nYuliia Tereshchenko\nAnna Stepaniuk\n\n" +
                        "Sounds:\nDamian Zwolinski\n\n" +
                        "Code:\nMichal Stankiewicz\n\n" +
                        "Music:\n\"Epic song\" by BoxCat Games",
                Color.CYAN,800, Align.center, true);

        backGL = new GlyphLayout(Fonts.menuItemSelected,"[Back]");

        creditsPosition = new Vector2(0,550);
        backPosition = new Vector2(400 - backGL.width/2,50);
    }

    @Override
    public void show() {
        Gdx.input.setInputProcessor(this);
    }

    @Override
    public void render(float delta) {
        viewport.apply();
        Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        batch.setProjectionMatrix(viewport.getCamera().combined);
        batch.begin();

        batch.draw(Graphics.bg1,0,0);

        Fonts.smallFont.draw(batch,
                creditsGL,
                creditsPosition.x,
                creditsPosition.y);

        Fonts.menuItemSelected.draw(batch,
                backGL,
                backPosition.x,
                backPosition.y);

        batch.end();
    }

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

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        batch.dispose();
    }

    @Override
    public boolean keyDown(int keycode) {
        if(keycode == Input.Keys.ENTER ||
                keycode == Input.Keys.ENTER){
            Sounds.menuSelected.play(0.55f);
            game.goToMainMenu();
        }

        return true;
    }
}
