/*
 * Copyright (C) 2013 Snowsun <http://wyrez.org> and contributors
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.wyrez.shootingstars.gui;

import com.jme3.input.event.MouseButtonEvent;
import com.jme3.math.Vector2f;
import java.util.List;
import org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.listener.HighscoreListener;
import org.wyrez.shootingstars.gui.model.Score;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;

/**
 *
 * @author Snowsun
 */
public class HighscoreGUI extends Panel implements Gui {

    private HighscoreListener listener;
    //private HighscoreManager highscoreManager;

    public HighscoreGUI(Screen screen, HighscoreListener listener) {
        super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f));
        this.listener = listener;
        this.setIgnoreMouse(true);
        this.setIsVisible(false);
        //highscoreManager = new HighscoreManager();
        create();
    }

    public void attach() {
        screen.addElement(this);
    }

    public void detach() {
        screen.removeElement(this);
    }

    private void create() {
        float startPointx = 32f;
        float startPointy = 18f;

        //Only Test
//        highscoreManager.addScore("Lied Name", "Chris", 50);
//        highscoreManager.addScore("Lied Name", "Chris", 150);
//        highscoreManager.addScore("Lied Name", "Chris", 250);
//        highscoreManager.addScore("Lied Name", "Chris", 350);
//        highscoreManager.addScore("Lied Name", "Chris", 450);
//        highscoreManager.addScore("Lied Name", "Chris", 550);
//        highscoreManager.addScore("Lied Name", "Chris", 650);
//        highscoreManager.addScore("Lied Name", "Chris", 750);
//        highscoreManager.addScore("Lied Name", "Chris", 850);
//        highscoreManager.addScore("Lied Name", "Chris", 950);
//        highscoreManager.updateScoreFile();


        float marginScoreNameLeft = 14f;
        float marginScorePointsLeft = 300f;
        float marginScoreSongNameLeft = 600f;

        float marginScoreTop = 50f;

        //List<Score> highscores = highscoreManager.getScores();

        Label lblScoreNameHead = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy), new Vector2f(250f, 40f));
        lblScoreNameHead.setText("Name");

        Label lblScorePointsHead = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy), new Vector2f(250f, 40f));
        lblScorePointsHead.setText("Points");

        Label lblScoreSongNameHead = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy), new Vector2f(600f, 40f));
        lblScoreSongNameHead.setText("Song Name");

//        for (int i = 0; i < 10; i++) {
//            Score score = highscores.get(i);
//            Label lblScoreName = new Label(screen, new Vector2f(startPointx + marginScoreNameLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f));
//            lblScoreName.setText(score.getPlayerName());
//
//            Label lblScorePoints = new Label(screen, new Vector2f(startPointx + marginScorePointsLeft, startPointy + marginScoreTop), new Vector2f(250f, 40f));
//            lblScorePoints.setText(String.valueOf(score.getScore()));
//
//            Label lblScoreSongName = new Label(screen, new Vector2f(startPointx + marginScoreSongNameLeft, startPointy + marginScoreTop), new Vector2f(600f, 40f));
//            lblScoreSongName.setText(score.getSongName());
//
//            this.addChild(lblScoreName);
//            this.addChild(lblScorePoints);
//            this.addChild(lblScoreSongName);
//            marginScoreTop += 50f;
//        }

        Button btnBack = new ButtonBase(screen, new Vector2f(startPointx + 1060f, startPointy + 622.8f), new Vector2f(153f, 40)) {
            @Override
            public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
                listener.back();
            }
        };
        btnBack.setText("Back");

        this.addChild(lblScoreNameHead);
        this.addChild(lblScorePointsHead);
        this.addChild(lblScoreSongNameHead);
        this.addChild(btnBack);
    }
}
