Search in sources :

Example 6 with UIText

use of org.terasology.nui.widgets.UIText in project Terasology by MovingBlocks.

the class NewGameScreen 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 (isLoadingAsServer()) {
                    return translationSystem.translate("${engine:menu#select-multiplayer-game-sub-title}");
                } else {
                    return translationSystem.translate("${engine:menu#select-singleplayer-game-sub-title}");
                }
            }
        });
    }
    final UIText gameName = find("gameName", UIText.class);
    setGameName(gameName);
    final UIDropdownScrollable<Module> gameplay = find("gameplay", UIDropdownScrollable.class);
    gameplay.setOptions(getGameplayModules());
    gameplay.setVisibleOptions(5);
    gameplay.bindSelection(new Binding<Module>() {

        Module selected;

        @Override
        public Module get() {
            return selected;
        }

        @Override
        public void set(Module value) {
            setSelectedGameplayModule(value);
            selected = value;
        }
    });
    gameplay.setOptionRenderer(new StringTextRenderer<Module>() {

        @Override
        public String getString(Module value) {
            return value.getMetadata().getDisplayName().value();
        }

        @Override
        public void draw(Module value, Canvas canvas) {
            canvas.getCurrentStyle().setTextColor(validateModuleDependencies(value.getId()) ? Color.WHITE : Color.RED);
            super.draw(value, canvas);
            canvas.getCurrentStyle().setTextColor(Color.WHITE);
        }
    });
    UILabel gameplayDescription = find("gameplayDescription", UILabel.class);
    gameplayDescription.bindText(new ReadOnlyBinding<String>() {

        @Override
        public String get() {
            Module selectedModule = gameplay.getSelection();
            if (selectedModule != null) {
                return selectedModule.getMetadata().getDescription().value();
            } else {
                return "";
            }
        }
    });
    AdvancedGameSetupScreen advancedSetupGameScreen = getManager().createScreen(AdvancedGameSetupScreen.ASSET_URI, AdvancedGameSetupScreen.class);
    WidgetUtil.trySubscribe(this, "advancedSetup", button -> {
        universeWrapper.setGameName(gameName.getText());
        advancedSetupGameScreen.setUniverseWrapper(universeWrapper);
        triggerForwardAnimation(advancedSetupGameScreen);
    });
    WidgetUtil.trySubscribe(this, "play", button -> {
        if (gameName.getText().isEmpty()) {
            universeWrapper.setGameName(GameProvider.getNextGameName());
        }
        universeWrapper.setGameName(GameProvider.getNextGameName(gameName.getText()));
        if (gameplay.getOptions().isEmpty()) {
            logger.error("No gameplay modules present");
            MessagePopup errorPopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            errorPopup.setMessage("Error", "Can't create new game without modules!");
        }
        GameManifest gameManifest = GameManifestProvider.createGameManifest(universeWrapper, moduleManager, config);
        if (gameManifest != null) {
            gameEngine.changeState(new StateLoading(gameManifest, (isLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
        } else {
            MessagePopup errorPopup = getManager().createScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            errorPopup.setMessage("Error", "Can't create new game!");
        }
    });
    WidgetUtil.trySubscribe(this, "close", button -> {
        if (GameProvider.isSavesFolderEmpty()) {
            // skip selectGameScreen and get back directly to main screen
            getManager().pushScreen("engine:mainMenuScreen");
        } else {
            triggerBackAnimation();
        }
    });
    WidgetUtil.trySubscribe(this, "mainMenu", button -> {
        getManager().pushScreen("engine:mainMenuScreen");
    });
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) StateLoading(org.terasology.engine.core.modes.StateLoading) Canvas(org.terasology.nui.Canvas) AdvancedGameSetupScreen(org.terasology.engine.rendering.nui.layers.mainMenu.advancedGameSetupScreen.AdvancedGameSetupScreen) GameManifest(org.terasology.engine.game.GameManifest) UIText(org.terasology.nui.widgets.UIText) Module(org.terasology.gestalt.module.Module)

Example 7 with UIText

use of org.terasology.nui.widgets.UIText in project Terasology by MovingBlocks.

the class WorldSetupScreen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    UILabel subitle = find("subtitle", UILabel.class);
    subitle.setText(translationSystem.translate("${engine:menu#world-setup}") + " for " + world.getWorldName().toString());
    UIText customWorldName = find("customisedWorldName", UIText.class);
    setCustomWorldName(customWorldName);
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UIText(org.terasology.nui.widgets.UIText)

Example 8 with UIText

use of org.terasology.nui.widgets.UIText in project Terasology by MovingBlocks.

the class TypeWidgetTestScreen method initialise.

@Override
public void initialise() {
    mainContainer = find("mainContainer", ColumnLayout.class);
    assert mainContainer != null;
    mainContainer.setAutoSizeColumns(true);
    mainContainer.setFillVerticalSpace(false);
    mainContainer.setVerticalSpacing(5);
    bindingsLog = new UIText();
    bindingsLog.setReadOnly(true);
    bindingsLog.setMultiline(true);
    addWidgets();
    mainContainer.addWidget(bindingsLog);
}
Also used : ColumnLayout(org.terasology.nui.layouts.ColumnLayout) UIText(org.terasology.nui.widgets.UIText)

Aggregations

UIText (org.terasology.nui.widgets.UIText)8 UILabel (org.terasology.nui.widgets.UILabel)4 Module (org.terasology.gestalt.module.Module)3 List (java.util.List)2 StateLoading (org.terasology.engine.core.modes.StateLoading)2 GameManifest (org.terasology.engine.game.GameManifest)2 Name (org.terasology.gestalt.naming.Name)2 Canvas (org.terasology.nui.Canvas)2 TargetLengthBasedClassNameAbbreviator (ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1