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