/*
 * 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.asset.AssetManager;
import com.jme3.font.BitmapFont;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector2f;
import org.wyrez.shootingstars.gui.controls.IndicatorBase;
import org.wyrez.shootingstars.helper.ScreenHelper;
import org.wyrez.shootingstars.states.util.LoadingProgress;
import tonegod.gui.controls.extras.Indicator;
import tonegod.gui.controls.text.Label;
import tonegod.gui.core.Screen;

/**
 *
 * @author Darth Affe
 */
public class LoadingGui extends BackgroundedGui implements Gui {

    private Label lblStatus;
    private Indicator indProgress;
    private ScreenHelper screenHelper;

    public LoadingGui(Screen screen, ScreenHelper screenHelper, AssetManager assetManager) {
        super(screen, new Vector2f(0f, 0f), new Vector2f(1280f, 720f),
                assetManager, "Textures/ShootingStars.png"); //create for full hd
        this.screenHelper = screenHelper;
        this.setIgnoreMouse(true);
        this.setIsVisible(false);
        create();
    }

    private void create() {

        float startPointx = screenHelper.calcX(537f);
        float startPointy = screenHelper.calcY(576f);
        float distancePogressbarLabely = screenHelper.calcY(36f);
        float labelFontSize = screenHelper.calcX(20f);

        indProgress = new IndicatorBase(screen, new Vector2f(startPointx, startPointy),
                new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f)), Indicator.Orientation.HORIZONTAL);
        indProgress.setDisplayValues();
        indProgress.setMaxValue(LoadingProgress.getProgressCount());
        indProgress.setIndicatorColor(ColorRGBA.Black);

        lblStatus = new Label(screen, new Vector2f(startPointx, startPointy + distancePogressbarLabely), new Vector2f(screenHelper.calcX(200f), screenHelper.calcY(30f)));
        lblStatus.setTextAlign(BitmapFont.Align.Center);
        lblStatus.setFontSize(labelFontSize);

        this.addChild(indProgress);
        this.addChild(lblStatus);
    }

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

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

    public void updateProgress(LoadingProgress progress) {
        lblStatus.setText(progress.getText());
        indProgress.setCurrentValue(progress.getValue());
    }

    public void refresh() {
    }
}
