package eu.jonahbauer.wizard.client.libgdx.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import eu.jonahbauer.wizard.client.libgdx.WizardGame;
import eu.jonahbauer.wizard.common.messages.server.ServerMessage;

public class MainMenuScreen extends MenuScreen {

    private TextButton buttonPlay;
    private TextButton buttonQuit;

    private final ChangeListener listener = new ChangeListener() {
        @Override
        public void changed(ChangeEvent event, Actor actor) {
            if (actor == buttonPlay) {
                game.setScreen(new ConnectScreen(game));
                sfxClick();
            } else if (actor == buttonQuit) {
                sfxClick();
                dispose = true;
                Gdx.app.exit();
            }
        }
    };

    public MainMenuScreen(WizardGame game) {
        super(game);
    }

    @Override
    public void show() {
        super.show();

        buttonPlay = new TextButton(game.messages.get("menu.main.play"), game.data.skin);
        buttonPlay.setPosition((WizardGame.WIDTH - buttonPlay.getWidth()) / 2f, 192 + 504 - 120f - 125f);
        buttonQuit = new TextButton(game.messages.get("menu.main.quit"), game.data.skin);
        buttonQuit.setPosition((WizardGame.WIDTH - buttonQuit.getWidth()) / 2f, 192 + 120f);

        Gdx.input.setInputProcessor(game.data.stage);
        game.data.stage.addActor(buttonPlay);
        game.data.stage.addActor(buttonQuit);

        buttonPlay.addListener(listener);
        buttonQuit.addListener(listener);
    }

    @Override
    protected void renderForeground(float delta) {
        super.renderForeground(delta);
        int width = 160, height = 224;
        int left = 384, right = 384, top = 384, bottom = 192;
        this.game.batch.draw(game.data.symbols[0], left, bottom, width, height);
        this.game.batch.draw(game.data.symbols[1], left, WizardGame.HEIGHT - top - height, width, height);
        this.game.batch.draw(game.data.symbols[2], WizardGame.WIDTH - right - width, bottom, width, height);
        this.game.batch.draw(game.data.symbols[3], WizardGame.WIDTH - right - width, WizardGame.HEIGHT - top - height, width, height);
    }
}
