use of org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo in project Terasology by MovingBlocks.
the class CreateGameScreen method setGameName.
private void setGameName(UIText worldName) {
if (worldName != null) {
int gameNum = 1;
for (GameInfo info : GameProvider.getSavedGames()) {
if (info.getManifest().getTitle().startsWith(DEFAULT_GAME_NAME_PREFIX)) {
String remainder = info.getManifest().getTitle().substring(DEFAULT_GAME_NAME_PREFIX.length());
try {
gameNum = Math.max(gameNum, Integer.parseInt(remainder) + 1);
} catch (NumberFormatException e) {
logger.trace("Could not parse {} as integer (not an error)", remainder, e);
}
}
}
worldName.setText(DEFAULT_GAME_NAME_PREFIX + gameNum);
}
}
use of org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo in project Terasology by MovingBlocks.
the class StateHeadlessSetup method init.
@Override
public void init(GameEngine gameEngine) {
context = gameEngine.createChildContext();
CoreRegistry.setContext(context);
// let's get the entity event system running
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
entityManager = context.get(EngineEntityManager.class);
eventSystem = context.get(EventSystem.class);
context.put(Console.class, new ConsoleImpl(context));
NUIManager nuiManager = new NUIManagerInternal(context.get(CanvasRenderer.class), context);
context.put(NUIManager.class, nuiManager);
componentSystemManager = new ComponentSystemManager(context);
context.put(ComponentSystemManager.class, componentSystemManager);
componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
componentSystemManager.register(context.get(InputSystem.class), "engine:InputSystem");
EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
LocalPlayer localPlayer = new LocalPlayer();
context.put(LocalPlayer.class, localPlayer);
localPlayer.setClientEntity(localPlayerEntity);
componentSystemManager.initialise();
GameManifest gameManifest = null;
List<GameInfo> savedGames = GameProvider.getSavedGames();
if (savedGames.size() > 0) {
gameManifest = savedGames.get(0).getManifest();
} else {
gameManifest = createGameManifest();
}
gameEngine.changeState(new StateLoading(gameManifest, NetworkMode.LISTEN_SERVER));
}
use of org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo in project Terasology by MovingBlocks.
the class SelectGameScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
UILabel gameTypeTitle = find("gameTypeTitle", UILabel.class);
if (gameTypeTitle != null) {
gameTypeTitle.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
if (loadingAsServer) {
return translationSystem.translate("${engine:menu#select-multiplayer-game-sub-title}");
} else {
return translationSystem.translate("${engine:menu#select-singleplayer-game-sub-title}");
}
}
});
}
final UILabel saveGamePath = find("saveGamePath", UILabel.class);
if (saveGamePath != null) {
saveGamePath.setText(translationSystem.translate("${engine:menu#save-game-path} ") + PathManager.getInstance().getSavesPath().toAbsolutePath().toString());
}
final UIList<GameInfo> gameList = find("gameList", UIList.class);
refreshList(gameList);
gameList.select(0);
gameList.subscribe((widget, item) -> loadGame(item));
CreateGameScreen screen = getManager().createScreen(CreateGameScreen.ASSET_URI, CreateGameScreen.class);
WidgetUtil.trySubscribe(this, "create", button -> {
screen.setLoadingAsServer(loadingAsServer);
triggerForwardAnimation(screen);
});
WidgetUtil.trySubscribe(this, "load", button -> {
GameInfo gameInfo = gameList.getSelection();
if (gameInfo != null) {
loadGame(gameInfo);
}
});
WidgetUtil.trySubscribe(this, "delete", button -> {
GameInfo gameInfo = gameList.getSelection();
if (gameInfo != null) {
Path world = PathManager.getInstance().getSavePath(gameInfo.getManifest().getTitle());
try {
FilesUtil.recursiveDelete(world);
gameList.getList().remove(gameInfo);
gameList.setSelection(null);
} catch (Exception e) {
logger.error("Failed to delete saved game", e);
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error Deleting Game", e.getMessage());
}
}
});
WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
}
Aggregations