Search in sources :

Example 1 with SplashScreen

use of org.terasology.splash.SplashScreen in project Terasology by MovingBlocks.

the class Terasology method main.

public static void main(String[] args) {
    handlePrintUsageRequest(args);
    handleLaunchArguments(args);
    SplashScreen splashScreen = splashEnabled ? configureSplashScreen() : SplashScreenBuilder.createStub();
    splashScreen.post("Java Runtime " + System.getProperty("java.version") + " loaded");
    setupLogging();
    try {
        TerasologyEngineBuilder builder = new TerasologyEngineBuilder();
        populateSubsystems(builder);
        TerasologyEngine engine = builder.build();
        engine.subscribe(newStatus -> {
            if (newStatus == StandardGameStatus.RUNNING) {
                splashScreen.close();
            } else {
                splashScreen.post(newStatus.getDescription());
            }
        });
        if (isHeadless) {
            engine.subscribeToStateChange(new HeadlessStateChangeListener(engine));
            engine.run(new StateHeadlessSetup());
        } else {
            if (loadLastGame) {
                engine.getFromEngineContext(ThreadManager.class).submitTask("loadGame", () -> {
                    GameManifest gameManifest = getLatestGameManifest();
                    if (gameManifest != null) {
                        engine.changeState(new StateLoading(gameManifest, NetworkMode.NONE));
                    }
                });
            }
            engine.run(new StateMainMenu());
        }
    } catch (Throwable e) {
        // also catch Errors such as UnsatisfiedLink, NoSuchMethodError, etc.
        splashScreen.close();
        reportException(e);
    }
}
Also used : GameManifest(org.terasology.game.GameManifest) StateLoading(org.terasology.engine.modes.StateLoading) HeadlessStateChangeListener(org.terasology.engine.subsystem.headless.mode.HeadlessStateChangeListener) StateMainMenu(org.terasology.engine.modes.StateMainMenu) SplashScreen(org.terasology.splash.SplashScreen) StateHeadlessSetup(org.terasology.engine.subsystem.headless.mode.StateHeadlessSetup) ThreadManager(org.terasology.engine.subsystem.common.ThreadManager)

Example 2 with SplashScreen

use of org.terasology.splash.SplashScreen in project Terasology by MovingBlocks.

the class Terasology method configureSplashScreen.

private static SplashScreen configureSplashScreen() {
    int imageHeight = 283;
    int maxTextWidth = 450;
    int width = 600;
    int height = 30;
    int left = 20;
    int top = imageHeight - height - 20;
    Rectangle rectRc = new Rectangle(left, top, width, height);
    Rectangle textRc = new Rectangle(left + 10, top + 5, maxTextWidth, height);
    Rectangle boxRc = new Rectangle(left + maxTextWidth + 10, top, width - maxTextWidth - 20, height);
    SplashScreenBuilder builder = new SplashScreenBuilder();
    String[] imgFiles = new String[] { "splash_1.png", "splash_2.png", "splash_3.png", "splash_4.png", "splash_5.png" };
    Point[] imgOffsets = new Point[] { new Point(0, 0), new Point(150, 0), new Point(300, 0), new Point(450, 0), new Point(630, 0) };
    EngineStatus[] trigger = new EngineStatus[] { TerasologyEngineStatus.PREPARING_SUBSYSTEMS, TerasologyEngineStatus.INITIALIZING_MODULE_MANAGER, TerasologyEngineStatus.INITIALIZING_ASSET_TYPES, TerasologyEngineStatus.INITIALIZING_SUBSYSTEMS, TerasologyEngineStatus.INITIALIZING_ASSET_MANAGEMENT };
    try {
        for (int index = 0; index < 5; index++) {
            URL resource = Terasology.class.getResource("/splash/" + imgFiles[index]);
            builder.add(new TriggerImageOverlay(resource).setTrigger(trigger[index].getDescription()).setPosition(imgOffsets[index].x, imgOffsets[index].y));
        }
        builder.add(new ImageOverlay(Terasology.class.getResource("/splash/splash_text.png")));
    } catch (IOException e) {
        e.printStackTrace();
    }
    SplashScreen instance = builder.add(new RectOverlay(rectRc)).add(new TextOverlay(textRc)).add(new AnimatedBoxRowOverlay(boxRc)).build();
    return instance;
}
Also used : Rectangle(java.awt.Rectangle) AnimatedBoxRowOverlay(org.terasology.splash.overlay.AnimatedBoxRowOverlay) TriggerImageOverlay(org.terasology.splash.overlay.TriggerImageOverlay) Point(java.awt.Point) IOException(java.io.IOException) RectOverlay(org.terasology.splash.overlay.RectOverlay) Point(java.awt.Point) SplashScreenBuilder(org.terasology.splash.SplashScreenBuilder) URL(java.net.URL) TextOverlay(org.terasology.splash.overlay.TextOverlay) SplashScreen(org.terasology.splash.SplashScreen) ImageOverlay(org.terasology.splash.overlay.ImageOverlay) TriggerImageOverlay(org.terasology.splash.overlay.TriggerImageOverlay)

Example 3 with SplashScreen

use of org.terasology.splash.SplashScreen in project Terasology by MovingBlocks.

the class Terasology method call.

@Override
public Integer call() throws IOException {
    handleLaunchArguments();
    setupLogging();
    SplashScreen splashScreen;
    if (splashEnabled) {
        CountDownLatch splashInitLatch = new CountDownLatch(1);
        GLFWSplashScreen glfwSplash = new GLFWSplashScreen(splashInitLatch);
        Thread thread = new Thread(glfwSplash, "splashscreen-loop");
        thread.setDaemon(true);
        thread.start();
        try {
            // wait splash initialize... we will lose some post messages otherwise.
            // noinspection ResultOfMethodCallIgnored
            splashInitLatch.await(1, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
        // ignore
        }
        splashScreen = glfwSplash;
    } else {
        splashScreen = SplashScreenBuilder.createStub();
    }
    splashScreen.post("Java Runtime " + System.getProperty("java.version") + " loaded");
    try {
        TerasologyEngineBuilder builder = new TerasologyEngineBuilder();
        populateSubsystems(builder);
        TerasologyEngine engine = builder.build();
        engine.subscribe(newStatus -> {
            if (newStatus == StandardGameStatus.RUNNING) {
                splashScreen.close();
            } else {
                splashScreen.post(newStatus.getDescription());
            }
        });
        if (isHeadless) {
            engine.subscribeToStateChange(new HeadlessStateChangeListener(engine));
            engine.run(new StateHeadlessSetup());
        } else if (loadLastGame) {
            // initialize the managers first
            engine.initialize();
            GameScheduler.scheduleParallel("loadGame", () -> {
                GameManifest gameManifest = getLatestGameManifest();
                if (gameManifest != null) {
                    engine.changeState(new StateLoading(gameManifest, NetworkMode.NONE));
                }
            });
        } else {
            if (createLastGame) {
                engine.initialize();
                GameScheduler.scheduleParallel("createLastGame", () -> {
                    GameManifest gameManifest = getLatestGameManifest();
                    if (gameManifest != null) {
                        String title = gameManifest.getTitle();
                        if (!title.startsWith("New Created")) {
                            // if first time run
                            gameManifest.setTitle("New Created " + title + " 1");
                        } else {
                            // if not first time run
                            gameManifest.setTitle(getNewTitle(title));
                        }
                        engine.changeState(new StateLoading(gameManifest, NetworkMode.NONE));
                    }
                });
            }
            engine.run(new StateMainMenu());
        }
    } catch (Throwable e) {
        // also catch Errors such as UnsatisfiedLink, NoSuchMethodError, etc.
        splashScreen.close();
        reportException(e);
    }
    return 0;
}
Also used : TerasologyEngineBuilder(org.terasology.engine.core.TerasologyEngineBuilder) StateLoading(org.terasology.engine.core.modes.StateLoading) CountDownLatch(java.util.concurrent.CountDownLatch) StateHeadlessSetup(org.terasology.engine.core.subsystem.headless.mode.StateHeadlessSetup) TerasologyEngine(org.terasology.engine.core.TerasologyEngine) GameManifest(org.terasology.engine.game.GameManifest) HeadlessStateChangeListener(org.terasology.engine.core.subsystem.headless.mode.HeadlessStateChangeListener) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) SplashScreen(org.terasology.splash.SplashScreen)

Aggregations

SplashScreen (org.terasology.splash.SplashScreen)3 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1 URL (java.net.URL)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TerasologyEngine (org.terasology.engine.core.TerasologyEngine)1 TerasologyEngineBuilder (org.terasology.engine.core.TerasologyEngineBuilder)1 StateLoading (org.terasology.engine.core.modes.StateLoading)1 StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)1 HeadlessStateChangeListener (org.terasology.engine.core.subsystem.headless.mode.HeadlessStateChangeListener)1 StateHeadlessSetup (org.terasology.engine.core.subsystem.headless.mode.StateHeadlessSetup)1 GameManifest (org.terasology.engine.game.GameManifest)1 StateLoading (org.terasology.engine.modes.StateLoading)1 StateMainMenu (org.terasology.engine.modes.StateMainMenu)1 ThreadManager (org.terasology.engine.subsystem.common.ThreadManager)1 HeadlessStateChangeListener (org.terasology.engine.subsystem.headless.mode.HeadlessStateChangeListener)1 StateHeadlessSetup (org.terasology.engine.subsystem.headless.mode.StateHeadlessSetup)1 GameManifest (org.terasology.game.GameManifest)1 SplashScreenBuilder (org.terasology.splash.SplashScreenBuilder)1