Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
omomthings committed Mar 22, 2017
1 parent abc2845 commit 1d73785
Showing 1 changed file with 14 additions and 3 deletions.
Expand Up @@ -16,6 +16,7 @@
package org.terasology.engine.modes;

import org.terasology.audio.AudioManager;
import org.terasology.audio.StreamingSound;
import org.terasology.context.Context;
import org.terasology.engine.ComponentSystemManager;
import org.terasology.engine.GameEngine;
Expand Down Expand Up @@ -57,6 +58,8 @@ public class StateMainMenu implements GameState {
private InputSystem inputSystem;

private String messageOnLoad = "";
private boolean isAlive;
private StreamingSound backgroundMusic;

public StateMainMenu() {
}
Expand All @@ -68,6 +71,7 @@ public StateMainMenu(String showMessageOnLoad) {

@Override
public void init(GameEngine gameEngine) {
isAlive = true;
context = gameEngine.createChildContext();
CoreRegistry.setContext(context);

Expand Down Expand Up @@ -115,17 +119,18 @@ public void init(GameEngine gameEngine) {

componentSystemManager.initialise();

playBackgroundMusic();

//guiManager.openWindow("main");
context.get(NUIManager.class).pushScreen("engine:mainMenuScreen");
if (!messageOnLoad.isEmpty()) {
nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", messageOnLoad);
}

playBackgroundMusic();
}

@Override
public void dispose() {
isAlive=false;
eventSystem.process();

componentSystemManager.shutdown();
Expand All @@ -136,7 +141,13 @@ public void dispose() {
}

private void playBackgroundMusic() {
context.get(AudioManager.class).playMusic(Assets.getMusic("engine:MenuTheme").get(),() -> playBackgroundMusic());
if (backgroundMusic == null)
backgroundMusic = Assets.getMusic("engine:MenuTheme").get();

context.get(AudioManager.class).playMusic(backgroundMusic,() -> {
if(isAlive)
playBackgroundMusic();
});
}

private void stopBackgroundMusic() {
Expand Down

0 comments on commit 1d73785

Please sign in to comment.