/*
 * Copyright (C) 2013 Darth Affe <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 org.wyrez.shootingstars.gui.controls.ButtonBase;
import org.wyrez.shootingstars.gui.listener.MenuListener;
import tonegod.gui.controls.buttons.Button;
import tonegod.gui.controls.text.Label;
import tonegod.gui.controls.windows.Panel;
import tonegod.gui.core.Screen;

/**
 *
 * @author Darth Affe
 */
public class MenuGUI extends Panel implements Gui {

    private MenuListener listener;

    public MenuGUI(Screen screen, MenuListener listener) {
        super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f)); //create for full hd
        this.listener = listener;
        this.setIgnoreMouse(true);
        this.setIsVisible(false);        
        create();
    }

    private void create() {
        
        float startPointx = 256f;
        float startPointy = 252f;
        float labelFontSize = 89f;
        float buttonLabelDistancex = 512f;
        float buttonButtonDistancex = buttonLabelDistancex + 192f;
        float buttonButtonDistancey = 90f;
        float buttonWidth = 153f;
        float marginButtonTop = 25f;
        float distanceLabelLabely = 60f;
        
        Label lblWyrez = new Label(screen, new Vector2f(startPointx, startPointy), new Vector2f(300, 40));
        lblWyrez.setFontSize(labelFontSize);
        lblWyrez.setText("Wyrez");
        
        Label lblShootingStars = new Label(screen, new Vector2f(startPointx, startPointy + distanceLabelLabely), new Vector2f(500, 40));
        lblShootingStars.setFontSize(labelFontSize);
        lblShootingStars.setText("Shooting Stars");

        Button btnStart = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, 40)) {
            @Override
            public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
                listener.selectFile();
            }
        };
        btnStart.setText("Start Game");
        
        Button btnHighscore = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + marginButtonTop), new Vector2f(buttonWidth, 40)) {
            @Override
            public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
                listener.openhighscore();
            }
        };
        btnHighscore.setText("Highscore");
        
        Button btnOptions = new ButtonBase(screen, new Vector2f(startPointx + buttonLabelDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, 40)) {
            @Override
            public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
                listener.openOptions();
            }
        };
        btnOptions.setText("Options");
        
        Button btnExit = new ButtonBase(screen, new Vector2f(startPointx + buttonButtonDistancex, startPointy + buttonButtonDistancey), new Vector2f(buttonWidth, 40)) {
            @Override
            public void onButtonMouseLeftUp(MouseButtonEvent evt, boolean toggled) {
                listener.exitGame();
            }
        };
        btnExit.setText("Exit Game");

        this.addChild(btnStart);
        this.addChild(btnHighscore);
        this.addChild(btnOptions);
        this.addChild(btnExit);
        this.addChild(lblWyrez);
        this.addChild(lblShootingStars);
    }

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

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