Search in sources :

Example 1 with JoinStatus

use of org.terasology.engine.network.JoinStatus in project Terasology by MovingBlocks.

the class CoreCommands method join.

/**
 * Join a game
 *
 * @param address   String containing address of game server
 * @param portParam Integer containing game server port
 */
@Command(shortDescription = "Join a game", requiredPermission = PermissionManager.NO_PERMISSION)
public void join(@CommandParam("address") final String address, @CommandParam(value = "port", required = false) Integer portParam) {
    final int port = portParam != null ? portParam : TerasologyConstants.DEFAULT_PORT;
    Callable<JoinStatus> operation = () -> networkSystem.join(address, port);
    final WaitPopup<JoinStatus> popup = nuiManager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
    popup.setMessage("Join Game", "Connecting to '" + address + ":" + port + "' - please wait ...");
    popup.onSuccess(result -> {
        if (result.getStatus() != JoinStatus.Status.FAILED) {
            gameEngine.changeState(new StateLoading(result));
        } else {
            MessagePopup screen = nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            screen.setMessage("Failed to Join", "Could not connect to server - " + result.getErrorMessage());
        }
    });
    popup.startOperation(operation, true);
}
Also used : StateLoading(org.terasology.engine.core.modes.StateLoading) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) JoinStatus(org.terasology.engine.network.JoinStatus) Command(org.terasology.engine.logic.console.commandSystem.annotations.Command) ConsoleCommand(org.terasology.engine.logic.console.commandSystem.ConsoleCommand)

Example 2 with JoinStatus

use of org.terasology.engine.network.JoinStatus in project Terasology by MovingBlocks.

the class JoinGameScreen method join.

private void join(final String address, final int port) {
    Callable<JoinStatus> operation = () -> {
        JoinStatus joinStatus = networkSystem.join(address, port);
        return joinStatus;
    };
    final WaitPopup<JoinStatus> popup = getManager().pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
    popup.setMessage(translationSystem.translate("${engine:menu#join-game-online}"), translationSystem.translate("${engine:menu#connecting-to}") + " '" + address + ":" + port + "' - " + translationSystem.translate("${engine:menu#please-wait}"));
    popup.onSuccess(result -> {
        if (result.getStatus() != JoinStatus.Status.FAILED) {
            engine.changeState(new StateLoading(result));
        } else {
            MessagePopup screen = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            screen.setMessage(translationSystem.translate("${engine:menu#failed-to-join}"), translationSystem.translate("${engine:menu#could-not-connect-to-server}") + " - " + result.getErrorMessage());
        }
    });
    popup.startOperation(operation, true);
}
Also used : StateLoading(org.terasology.engine.core.modes.StateLoading) JoinStatus(org.terasology.engine.network.JoinStatus)

Aggregations

StateLoading (org.terasology.engine.core.modes.StateLoading)2 JoinStatus (org.terasology.engine.network.JoinStatus)2 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)1 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)1 MessagePopup (org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup)1