Search in sources :

Example 46 with Module

use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.

the class AdvancedGameSetupScreen method advancedModuleFilter.

private void advancedModuleFilter() {
    Iterator<ModuleSelectionInfo> iter = sortedModules.iterator();
    while (iter.hasNext()) {
        ModuleSelectionInfo m = iter.next();
        Module module;
        if (m.isPresent()) {
            module = moduleManager.getRegistry().getLatestModuleVersion(m.getMetadata().getId());
        } else {
            module = (m.getOnlineVersion() == null) ? m.getLatestVersion() : m.getOnlineVersion();
        }
        boolean matches = false;
        Collection<StandardModuleExtension> selectedStandardModuleExtensions = selectModulesConfig.getSelectedStandardModuleExtensions();
        for (StandardModuleExtension standardModuleExtension : selectedStandardModuleExtensions) {
            if (standardModuleExtension != null && standardModuleExtension.isProvidedBy(module)) {
                matches = true;
                break;
            }
        }
        if (!matches) {
            iter.remove();
        }
    }
}
Also used : StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) Module(org.terasology.gestalt.module.Module)

Example 47 with Module

use of org.terasology.gestalt.module.Module 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 48 with Module

use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.

the class NewGameScreen method getGameplayModules.

private List<Module> getGameplayModules() {
    List<Module> gameplayModules = Lists.newArrayList();
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module latestVersion = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        if (StandardModuleExtension.isGameplayModule(latestVersion)) {
            gameplayModules.add(latestVersion);
        }
    }
    gameplayModules.sort(Comparator.comparing(o -> o.getMetadata().getDisplayName().value()));
    return gameplayModules;
}
Also used : MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) UIDropdown(org.terasology.nui.widgets.UIDropdown) In(org.terasology.engine.registry.In) Color(org.terasology.nui.Color) ModuleManager(org.terasology.engine.core.module.ModuleManager) LoggerFactory(org.slf4j.LoggerFactory) NetworkMode(org.terasology.engine.network.NetworkMode) WidgetUtil(org.terasology.nui.WidgetUtil) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) GameManifest(org.terasology.engine.game.GameManifest) Lists(com.google.common.collect.Lists) NUIKeyEvent(org.terasology.nui.events.NUIKeyEvent) Canvas(org.terasology.nui.Canvas) StateLoading(org.terasology.engine.core.modes.StateLoading) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) StringTextRenderer(org.terasology.nui.itemRendering.StringTextRenderer) Binding(org.terasology.nui.databinding.Binding) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) ModuleConfig(org.terasology.engine.config.ModuleConfig) Logger(org.slf4j.Logger) GameEngine(org.terasology.engine.core.GameEngine) UILabel(org.terasology.nui.widgets.UILabel) Keyboard(org.terasology.input.Keyboard) Module(org.terasology.gestalt.module.Module) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) SimpleUri(org.terasology.engine.core.SimpleUri) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) AdvancedGameSetupScreen(org.terasology.engine.rendering.nui.layers.mainMenu.advancedGameSetupScreen.AdvancedGameSetupScreen) Config(org.terasology.engine.config.Config) GameProvider(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameProvider) Comparator(java.util.Comparator) Name(org.terasology.gestalt.naming.Name) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

Example 49 with Module

use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.

the class ModuleDetailsScreen method updateOpenInBrowserButton.

private void updateOpenInBrowserButton() {
    openInBrowser.setEnabled(false);
    final Module module = moduleInfoBinding.get();
    if (module == null) {
        return;
    }
    final String moduleOrigin = getOriginModuleUrl(moduleManager.getRegistry().getLatestModuleVersion(module.getMetadata().getId()));
    if (StringUtils.isNotBlank(moduleOrigin)) {
        openInBrowser.setEnabled(true);
        openInBrowser.setUrl(moduleOrigin).setNuiManager(getManager()).setTranslationSystem(translationSystem);
    }
}
Also used : Module(org.terasology.gestalt.module.Module)

Example 50 with Module

use of org.terasology.gestalt.module.Module in project Terasology by MovingBlocks.

the class ModulesMetric method createTelemetryFieldToValue.

@Override
public Map<String, ?> createTelemetryFieldToValue() {
    updateModules();
    telemetryFieldToValue = new HashMap();
    for (Module module : modules) {
        telemetryFieldToValue.put(module.getId().toString(), module.getVersion().toString());
    }
    return telemetryFieldToValue;
}
Also used : HashMap(java.util.HashMap) Module(org.terasology.gestalt.module.Module)

Aggregations

Module (org.terasology.gestalt.module.Module)51 ModuleManager (org.terasology.engine.core.module.ModuleManager)18 Name (org.terasology.gestalt.naming.Name)17 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)13 ModuleMetadata (org.terasology.gestalt.module.ModuleMetadata)11 List (java.util.List)9 Logger (org.slf4j.Logger)9 LoggerFactory (org.slf4j.LoggerFactory)9 SimpleUri (org.terasology.engine.core.SimpleUri)9 UILabel (org.terasology.nui.widgets.UILabel)9 UIText (org.terasology.nui.widgets.UIText)9 DependencyInfo (org.terasology.gestalt.module.dependencyresolution.DependencyInfo)8 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)8 Canvas (org.terasology.nui.Canvas)8 Collection (java.util.Collection)7 Comparator (java.util.Comparator)7 Map (java.util.Map)7 Collectors (java.util.stream.Collectors)7 TranslationSystem (org.terasology.engine.i18n.TranslationSystem)7 In (org.terasology.engine.registry.In)7