Search in sources :

Example 1 with GameInfo

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);
    }
}
Also used : GameInfo(org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo)

Example 2 with GameInfo

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));
}
Also used : EngineEntityManager(org.terasology.entitySystem.entity.internal.EngineEntityManager) GameInfo(org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo) StateLoading(org.terasology.engine.modes.StateLoading) ConsoleImpl(org.terasology.logic.console.ConsoleImpl) CanvasRenderer(org.terasology.rendering.nui.internal.CanvasRenderer) LocalPlayer(org.terasology.logic.players.LocalPlayer) InputSystem(org.terasology.input.InputSystem) CoreCommands(org.terasology.logic.console.commands.CoreCommands) ClientComponent(org.terasology.network.ClientComponent) NUIManagerInternal(org.terasology.rendering.nui.internal.NUIManagerInternal) ComponentSystemManager(org.terasology.engine.ComponentSystemManager) ConsoleSystem(org.terasology.logic.console.ConsoleSystem) GameManifest(org.terasology.game.GameManifest) EventSystem(org.terasology.entitySystem.event.internal.EventSystem) NUIManager(org.terasology.rendering.nui.NUIManager) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 3 with GameInfo

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());
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Path(java.nio.file.Path) GameInfo(org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo)

Aggregations

GameInfo (org.terasology.rendering.nui.layers.mainMenu.savedGames.GameInfo)3 Path (java.nio.file.Path)1 ComponentSystemManager (org.terasology.engine.ComponentSystemManager)1 StateLoading (org.terasology.engine.modes.StateLoading)1 EntityRef (org.terasology.entitySystem.entity.EntityRef)1 EngineEntityManager (org.terasology.entitySystem.entity.internal.EngineEntityManager)1 EventSystem (org.terasology.entitySystem.event.internal.EventSystem)1 GameManifest (org.terasology.game.GameManifest)1 InputSystem (org.terasology.input.InputSystem)1 ConsoleImpl (org.terasology.logic.console.ConsoleImpl)1 ConsoleSystem (org.terasology.logic.console.ConsoleSystem)1 CoreCommands (org.terasology.logic.console.commands.CoreCommands)1 LocalPlayer (org.terasology.logic.players.LocalPlayer)1 ClientComponent (org.terasology.network.ClientComponent)1 NUIManager (org.terasology.rendering.nui.NUIManager)1 CanvasRenderer (org.terasology.rendering.nui.internal.CanvasRenderer)1 NUIManagerInternal (org.terasology.rendering.nui.internal.NUIManagerInternal)1 UILabel (org.terasology.rendering.nui.widgets.UILabel)1