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

/**
 *
 * @author Darth Affe
 */
public class LoadingGui extends Panel {

    private Label lblStatus;
    private Indicator indProgress;

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

    private void create() {
        
        float startPointx = 537f;//screen.getWidth() * 0.42f;
        float startPointy = 576f;//screen.getHeight() * 0.80f;
        float distancePogressbarLabely = 36f;

        indProgress = new IndicatorBase(screen, new Vector2f(startPointx, startPointy),
                new Vector2f(200f, 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(200f, 30f));
        lblStatus.setTextAlign(BitmapFont.Align.Center);

        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());
    }
}
