package tanks.gui.screen;

import tanks.Drawing;
import tanks.Game;
import tanks.gui.Button;
import tanks.gui.TextBox;

public class ScreenOptionsSpeedrun extends Screen
{
    public static final String deterministicText = "Deterministic: ";
    public static final String timerText = "Timer: ";

    Button timer = new Button(this.centerX, this.centerY - this.objYSpace, this.objWidth, this.objHeight, "", new Runnable()
    {
        @Override
        public void run()
        {
            Game.showSpeedrunTimer = !Game.showSpeedrunTimer;

            if (Game.showSpeedrunTimer)
                timer.text = timerText + ScreenOptions.onText;
            else
                timer.text = timerText + ScreenOptions.offText;
        }
    },
            "When enabled, time spent---in the current level attempt---and crusade will be displayed");

    Button deterministic = new Button(this.centerX, this.centerY, this.objWidth, this.objHeight, "", new Runnable()
    {
        @Override
        public void run()
        {
            Game.deterministicMode = !Game.deterministicMode;

            if (Game.deterministicMode)
                deterministic.text = deterministicText + ScreenOptions.onText;
            else
                deterministic.text = deterministicText + ScreenOptions.offText;
        }
    },
            "Deterministic mode changes the random number---generation to be fixed based on a seed, and---the game speed to be locked and independent---of framerate." +
                    "------This is useful for fair speedruns but may---provide for a less smooth experience.");

    TextBox deterministicSeed = new TextBox(this.centerX, this.centerY + this.objYSpace * 1.5, this.objWidth, this.objHeight, "Deterministic mode seed", new Runnable() {
        @Override
        public void run() {
            if (deterministicSeed.inputText.length() > 0)
                Game.seed = Integer.parseInt(deterministicSeed.inputText);
            else
                deterministicSeed.inputText = deterministicSeed.previousInputText;
        }
    }, Game.seed + "");

    Button back = new Button(this.centerX, this.centerY + this.objYSpace * 4, this.objWidth, this.objHeight, "Back", () -> Game.screen = new ScreenOptionsGame()
    );

    public ScreenOptionsSpeedrun()
    {
        this.music = "menu_options.ogg";
        this.musicID = "menu";

        if (Game.showSpeedrunTimer)
            timer.text = timerText + ScreenOptions.onText;
        else
            timer.text = timerText + ScreenOptions.offText;

        if (Game.deterministicMode)
            deterministic.text = deterministicText + ScreenOptions.onText;
        else
            deterministic.text = deterministicText + ScreenOptions.offText;

        deterministicSeed.allowSpaces = false;
        deterministicSeed.allowLetters = false;
        deterministicSeed.allowNumbers = true;
        deterministicSeed.maxChars = 9;
    }

    @Override
    public void update()
    {
        back.update();
        timer.update();
        deterministicSeed.update();
        deterministic.update();
    }

    @Override
    public void draw()
    {
        this.drawDefaultBackground();

        back.draw();
        deterministicSeed.draw();
        deterministic.draw();
        timer.draw();

        Drawing.drawing.setInterfaceFontSize(this.titleSize);
        Drawing.drawing.setColor(0, 0, 0);
        Drawing.drawing.drawInterfaceText(this.centerX, this.centerY - this.objYSpace * 3.5, "Speedrunning options");
    }
}
