Search in sources :

Example 1 with PreloaderCallback

use of com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback in project Mindustry by Anuken.

the class HtmlLauncher method getPreloaderCallback.

@Override
public PreloaderCallback getPreloaderCallback() {
    final Panel preloaderPanel = new VerticalPanel();
    preloaderPanel.setStyleName("gdx-preloader");
    final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
    logo.setStyleName("logo");
    preloaderPanel.add(logo);
    final Panel meterPanel = new SimplePanel();
    meterPanel.setStyleName("gdx-meter");
    meterPanel.addStyleName("red");
    final InlineHTML meter = new InlineHTML();
    final Style meterStyle = meter.getElement().getStyle();
    meterStyle.setWidth(0, Unit.PCT);
    meterPanel.add(meter);
    preloaderPanel.add(meterPanel);
    getRootPanel().add(preloaderPanel);
    return new PreloaderCallback() {

        @Override
        public void error(String file) {
            System.out.println("error: " + file);
        }

        @Override
        public void update(PreloaderState state) {
            meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
        }
    };
}
Also used : PreloaderCallback(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback) PreloaderState(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState) Style(com.google.gwt.dom.client.Style)

Example 2 with PreloaderCallback

use of com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback in project libgdx by libgdx.

the class GwtApplication method getPreloaderCallback.

public PreloaderCallback getPreloaderCallback() {
    final Panel preloaderPanel = new VerticalPanel();
    preloaderPanel.setStyleName("gdx-preloader");
    final Image logo = new Image(GWT.getModuleBaseURL() + "logo.png");
    logo.setStyleName("logo");
    preloaderPanel.add(logo);
    final Panel meterPanel = new SimplePanel();
    meterPanel.setStyleName("gdx-meter");
    meterPanel.addStyleName("red");
    final InlineHTML meter = new InlineHTML();
    final Style meterStyle = meter.getElement().getStyle();
    meterStyle.setWidth(0, Unit.PCT);
    meterPanel.add(meter);
    preloaderPanel.add(meterPanel);
    getRootPanel().add(preloaderPanel);
    return new PreloaderCallback() {

        @Override
        public void error(String file) {
            System.out.println("error: " + file);
        }

        @Override
        public void update(PreloaderState state) {
            meterStyle.setWidth(100f * state.getProgress(), Unit.PCT);
        }
    };
}
Also used : PreloaderCallback(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) Panel(com.google.gwt.user.client.ui.Panel) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) RootPanel(com.google.gwt.user.client.ui.RootPanel) PreloaderState(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) InlineHTML(com.google.gwt.user.client.ui.InlineHTML) SimplePanel(com.google.gwt.user.client.ui.SimplePanel) Style(com.google.gwt.dom.client.Style) Image(com.google.gwt.user.client.ui.Image)

Example 3 with PreloaderCallback

use of com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback in project libgdx by libgdx.

the class GwtApplication method onModuleLoad.

@Override
public void onModuleLoad() {
    GwtApplication.agentInfo = computeAgentInfo();
    this.listener = createApplicationListener();
    this.config = getConfig();
    setApplicationLogger(new GwtApplicationLogger(this.config.log));
    addEventListeners();
    if (config.rootPanel != null) {
        this.root = config.rootPanel;
    } else {
        Element element = Document.get().getElementById("embed-" + GWT.getModuleName());
        if (element == null) {
            VerticalPanel panel = new VerticalPanel();
            panel.setWidth("" + config.width + "px");
            panel.setHeight("" + config.height + "px");
            panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
            panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
            RootPanel.get().add(panel);
            RootPanel.get().setWidth("" + config.width + "px");
            RootPanel.get().setHeight("" + config.height + "px");
            this.root = panel;
        } else {
            VerticalPanel panel = new VerticalPanel();
            panel.setWidth("" + config.width + "px");
            panel.setHeight("" + config.height + "px");
            panel.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_CENTER);
            panel.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
            element.appendChild(panel.getElement());
            root = panel;
        }
    }
    // initialize SoundManager2
    SoundManager.init(GWT.getModuleBaseURL(), 9, config.preferFlash, new SoundManager.SoundManagerCallback() {

        @Override
        public void onready() {
            final PreloaderCallback callback = getPreloaderCallback();
            preloader = createPreloader();
            preloader.preload("assets.txt", new PreloaderCallback() {

                @Override
                public void error(String file) {
                    callback.error(file);
                }

                @Override
                public void update(PreloaderState state) {
                    callback.update(state);
                    if (state.hasEnded()) {
                        getRootPanel().clear();
                        if (loadingListener != null)
                            loadingListener.beforeSetup();
                        setupLoop();
                        if (loadingListener != null)
                            loadingListener.afterSetup();
                    }
                }
            });
        }

        @Override
        public void ontimeout(String status, String errorType) {
            error("SoundManager", status + " " + errorType);
        }
    });
}
Also used : PreloaderCallback(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback) PreloaderState(com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState) VerticalPanel(com.google.gwt.user.client.ui.VerticalPanel) CanvasElement(com.google.gwt.dom.client.CanvasElement) Element(com.google.gwt.dom.client.Element) SoundManager(com.badlogic.gdx.backends.gwt.soundmanager2.SoundManager)

Aggregations

PreloaderCallback (com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderCallback)3 PreloaderState (com.badlogic.gdx.backends.gwt.preloader.Preloader.PreloaderState)3 Style (com.google.gwt.dom.client.Style)2 VerticalPanel (com.google.gwt.user.client.ui.VerticalPanel)2 SoundManager (com.badlogic.gdx.backends.gwt.soundmanager2.SoundManager)1 CanvasElement (com.google.gwt.dom.client.CanvasElement)1 Element (com.google.gwt.dom.client.Element)1 Image (com.google.gwt.user.client.ui.Image)1 InlineHTML (com.google.gwt.user.client.ui.InlineHTML)1 Panel (com.google.gwt.user.client.ui.Panel)1 RootPanel (com.google.gwt.user.client.ui.RootPanel)1 SimplePanel (com.google.gwt.user.client.ui.SimplePanel)1