Search in sources :

Example 21 with Module

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

the class AdvancedGameSetupScreen method startDownloadingNewestModulesRequiredFor.

private void startDownloadingNewestModulesRequiredFor(ModuleSelectionInfo moduleMetadata) {
    Set<Module> modulesToDownload;
    try {
        modulesToDownload = moduleManager.getInstallManager().getAllModulesToDownloadFor(moduleMetadata.getMetadata().getId());
    } catch (DependencyResolutionFailedException ex) {
        MessagePopup messagePopup = getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
        messagePopup.setMessage("Error", ex.getMessage());
        return;
    }
    ConfirmPopup confirmPopup = getManager().pushScreen(ConfirmPopup.ASSET_URI, ConfirmPopup.class);
    confirmPopup.setMessage("Confirm Download", modulesToDownload.size() + " modules will be downloaded");
    confirmPopup.setOkHandler(() -> downloadModules(modulesToDownload));
}
Also used : ConfirmPopup(org.terasology.engine.rendering.nui.layers.mainMenu.ConfirmPopup) DependencyResolutionFailedException(org.terasology.engine.core.module.DependencyResolutionFailedException) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Module(org.terasology.gestalt.module.Module)

Example 22 with Module

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

the class InputSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    ColumnLayout mainLayout = find("main", ColumnLayout.class);
    UIButton azerty = find("azerty", UIButton.class);
    if (azerty != null) {
        azerty.subscribe(event -> {
            BindCommands.AZERTY.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton dvorak = find("dvorak", UIButton.class);
    if (dvorak != null) {
        dvorak.subscribe(event -> {
            BindCommands.DVORAK.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UIButton neo = find("neo", UIButton.class);
    if (neo != null) {
        neo.subscribe(event -> {
            BindCommands.NEO.forEach(this::setPrimaryBind);
            bindsManager.registerBinds();
        });
    }
    UISlider mouseSensitivity = new UISlider("mouseSensitivity");
    mouseSensitivity.bindValue(BindHelper.bindBeanProperty("mouseSensitivity", inputDeviceConfiguration, Float.TYPE));
    mouseSensitivity.setIncrement(0.025f);
    mouseSensitivity.setPrecision(3);
    UICheckbox mouseInverted = new UICheckbox("mouseYAxisInverted");
    mouseInverted.bindChecked(BindHelper.bindBeanProperty("mouseYAxisInverted", inputDeviceConfiguration, Boolean.TYPE));
    if (mainLayout != null) {
        mainLayout.addWidget(new UILabel("mouseLabel", "subheading", translationSystem.translate("${engine:menu" + "#category-mouse}")));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#mouse" + "-sensitivity}") + ":"), mouseSensitivity).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
        mainLayout.addWidget(new RowLayout(new UILabel(translationSystem.translate("${engine:menu#invert-mouse}") + ":"), mouseInverted).setColumnRatios(0.4f).setHorizontalSpacing(horizontalSpacing));
    }
    Map<String, InputCategory> inputCategories = Maps.newHashMap();
    Map<SimpleUri, RegisterBindButton> inputsById = Maps.newHashMap();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    for (Name moduleId : moduleManager.getRegistry().getModuleIds()) {
        Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleId);
        ResolutionResult result = resolver.resolve(moduleId);
        if (result.isSuccess()) {
            try (ModuleEnvironment environment = moduleManager.loadEnvironment(result.getModules(), false)) {
                for (Class<?> holdingType : environment.getTypesAnnotatedWith(InputCategory.class, new FromModule(environment, moduleId))) {
                    InputCategory inputCategory = holdingType.getAnnotation(InputCategory.class);
                    inputCategories.put(module.getId() + ":" + inputCategory.id(), inputCategory);
                }
                for (Class<?> bindEvent : environment.getTypesAnnotatedWith(RegisterBindButton.class, new FromModule(environment, moduleId))) {
                    if (BindButtonEvent.class.isAssignableFrom(bindEvent)) {
                        RegisterBindButton bindRegister = bindEvent.getAnnotation(RegisterBindButton.class);
                        inputsById.put(new SimpleUri(module.getId(), bindRegister.id()), bindRegister);
                    }
                }
            }
        }
    }
    if (mainLayout != null) {
        addInputSection(inputCategories.remove("engine:movement"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:interaction"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:inventory"), mainLayout, inputsById);
        addInputSection(inputCategories.remove("engine:general"), mainLayout, inputsById);
        for (InputCategory category : inputCategories.values()) {
            addInputSection(category, mainLayout, inputsById);
        }
        mainLayout.addWidget(new UISpace(new Vector2i(1, 16)));
        List<String> controllers = inputSystem.getControllerDevice().getControllers();
        for (String name : controllers) {
            ControllerInfo cfg = inputDeviceConfiguration.getController(name);
            addInputSection(mainLayout, name, cfg);
        }
    }
    WidgetUtil.trySubscribe(this, "reset", button -> {
        inputDeviceConfiguration.reset();
        bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
    });
    WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) UISlider(org.terasology.nui.widgets.UISlider) RegisterBindButton(org.terasology.engine.input.RegisterBindButton) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) UICheckbox(org.terasology.nui.widgets.UICheckbox) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Name(org.terasology.gestalt.naming.Name) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) ColumnLayout(org.terasology.nui.layouts.ColumnLayout) UIButton(org.terasology.nui.widgets.UIButton) RowLayout(org.terasology.nui.layouts.RowLayout) InputCategory(org.terasology.input.InputCategory) UISpace(org.terasology.nui.widgets.UISpace) Vector2i(org.joml.Vector2i) FromModule(org.terasology.gestalt.module.predicates.FromModule) Module(org.terasology.gestalt.module.Module) FromModule(org.terasology.gestalt.module.predicates.FromModule) ControllerInfo(org.terasology.engine.config.ControllerConfig.ControllerInfo)

Example 23 with Module

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

the class UniverseSetupScreen method recursivelyAddModuleDependencies.

private void recursivelyAddModuleDependencies(Set<Name> modules, Name moduleName) {
    Module module = moduleManager.getRegistry().getLatestModuleVersion(moduleName);
    if (module != null) {
        for (DependencyInfo dependencyInfo : module.getMetadata().getDependencies()) {
            modules.add(dependencyInfo.getId());
            recursivelyAddModuleDependencies(modules, dependencyInfo.getId());
        }
    }
}
Also used : Module(org.terasology.gestalt.module.Module) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo)

Example 24 with Module

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

the class GameDetailsScreen method openModuleDetailsScreen.

private void openModuleDetailsScreen() {
    final ModuleDetailsScreen moduleDetailsScreen = getManager().createScreen(ModuleDetailsScreen.ASSET_URI, ModuleDetailsScreen.class);
    final Collection<Module> modules = gameModules.getList().stream().map(ModuleSelectionInfo::getModule).filter(Objects::nonNull).collect(Collectors.toSet());
    moduleDetailsScreen.setModules(modules);
    moduleDetailsScreen.setSelectedModule(modules.stream().filter(module -> module.getId().equals(moduleInfoBinding.get().getModule().getId())).findFirst().orElse(null));
    getManager().pushScreen(moduleDetailsScreen);
}
Also used : WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) In(org.terasology.engine.registry.In) Date(java.util.Date) LoggerFactory(org.slf4j.LoggerFactory) WorldInfo(org.terasology.engine.world.internal.WorldInfo) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) Map(java.util.Map) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) DateFormat(java.text.DateFormat) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Binding(org.terasology.nui.databinding.Binding) SelectGameScreen(org.terasology.engine.rendering.nui.layers.mainMenu.SelectGameScreen) StringUtils(org.codehaus.plexus.util.StringUtils) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) UIImage(org.terasology.nui.widgets.UIImage) DateTimeHelper(org.terasology.engine.utilities.time.DateTimeHelper) Collectors(java.util.stream.Collectors) SimpleUri(org.terasology.engine.core.SimpleUri) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) Stream(java.util.stream.Stream) Vector2i(org.joml.Vector2i) NameVersion(org.terasology.gestalt.naming.NameVersion) GameInfo(org.terasology.engine.rendering.nui.layers.mainMenu.savedGames.GameInfo) UIList(org.terasology.nui.widgets.UIList) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) TerasologyConstants(org.terasology.engine.core.TerasologyConstants) ModuleManager(org.terasology.engine.core.module.ModuleManager) ModuleDetailsScreen(org.terasology.engine.rendering.nui.layers.mainMenu.moduleDetailsScreen.ModuleDetailsScreen) SimpleDateFormat(java.text.SimpleDateFormat) UITabBox(org.terasology.nui.widgets.UITabBox) ArrayList(java.util.ArrayList) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) UIImageSlideshow(org.terasology.nui.widgets.UIImageSlideshow) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) Logger(org.slf4j.Logger) UILabel(org.terasology.nui.widgets.UILabel) Maps(com.google.common.collect.Maps) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UIButton(org.terasology.nui.widgets.UIButton) Comparator(java.util.Comparator) ModuleDetailsScreen(org.terasology.engine.rendering.nui.layers.mainMenu.moduleDetailsScreen.ModuleDetailsScreen) Module(org.terasology.gestalt.module.Module)

Example 25 with Module

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

the class NewGameScreen method onOpened.

@Override
public void onOpened() {
    super.onOpened();
    final UIText gameName = find("gameName", UIText.class);
    setGameName(gameName);
    final UIDropdown<Module> gameplay = find("gameplay", UIDropdown.class);
    String configDefaultModuleName = config.getDefaultModSelection().getDefaultGameplayModuleName();
    String useThisModuleName = "";
    // Otherwise, default to DEFAULT_GAME_TEMPLATE_NAME.
    if ("".equalsIgnoreCase(configDefaultModuleName) || DEFAULT_GAME_TEMPLATE_NAME.equalsIgnoreCase(configDefaultModuleName)) {
        useThisModuleName = DEFAULT_GAME_TEMPLATE_NAME;
    } else {
        useThisModuleName = configDefaultModuleName;
    }
    Name defaultGameplayModuleName = new Name(useThisModuleName);
    Module defaultGameplayModule = moduleManager.getRegistry().getLatestModuleVersion(defaultGameplayModuleName);
    if (defaultGameplayModule != null) {
        gameplay.setSelection(defaultGameplayModule);
        setDefaultGeneratorOfGameplayModule(defaultGameplayModule);
    } else {
        // Find the first gameplay module that is available.
        for (Module module : moduleManager.getRegistry()) {
            // Module is null if it is no longer present.
            if (module != null && StandardModuleExtension.isGameplayModule(module)) {
                gameplay.setSelection(module);
                break;
            }
        }
    }
}
Also used : UIText(org.terasology.nui.widgets.UIText) Module(org.terasology.gestalt.module.Module) Name(org.terasology.gestalt.naming.Name)

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