Search in sources :

Example 16 with SimpleUri

use of org.terasology.engine.core.SimpleUri 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 17 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class WorldSetupScreen method setWorld.

/**
 * This method sets the world whose properties are to be changed. This function is called before the screen comes
 * to the forefront.
 *
 * @param subContext    the new environment created in {@link UniverseSetupScreen}
 * @param worldSelected the world whose configurations are to be changed.
 * @throws UnresolvedWorldGeneratorException
 */
public void setWorld(Context subContext, WorldSetupWrapper worldSelected, UIDropdownScrollable dropDown) throws UnresolvedWorldGeneratorException {
    world = worldSelected;
    context = subContext;
    worldsDropdown = dropDown;
    SimpleUri worldGenUri = worldSelected.getWorldGeneratorInfo().getUri();
    environment = context.get(ModuleEnvironment.class);
    context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
    if (world.getWorldGenerator() == null) {
        worldGenerator = WorldGeneratorManager.createWorldGenerator(worldGenUri, context, environment);
        world.setWorldGenerator(worldGenerator);
    } else {
        worldGenerator = world.getWorldGenerator();
    }
    configureProperties();
}
Also used : ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) SimpleUri(org.terasology.engine.core.SimpleUri) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary)

Example 18 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class NewGameScreen method setDefaultGeneratorOfGameplayModule.

// Sets the default generator of the passed in gameplay module. Make sure it's already selected.
private void setDefaultGeneratorOfGameplayModule(Module module) {
    // Set the default generator of the selected gameplay module
    SimpleUri defaultWorldGenerator = StandardModuleExtension.getDefaultWorldGenerator(module);
    if (defaultWorldGenerator != null) {
        for (WorldGeneratorInfo worldGenInfo : worldGeneratorManager.getWorldGenerators()) {
            if (worldGenInfo.getUri().equals(defaultWorldGenerator)) {
                config.getWorldGeneration().setDefaultGenerator(worldGenInfo.getUri());
            }
        }
    }
    config.save();
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) WorldGeneratorInfo(org.terasology.engine.world.generator.internal.WorldGeneratorInfo)

Example 19 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class AutoConfigManagerTest method testLoad.

@Test
public void testLoad() {
    autoConfigManager.loadConfigsIn(context);
    ArgumentCaptor<TestAutoConfig> argumentCaptor = ArgumentCaptor.forClass(TestAutoConfig.class);
    verify(context).put(eq(TestAutoConfig.class), argumentCaptor.capture());
    TestAutoConfig value = argumentCaptor.getValue();
    assertEquals(new SimpleUri(PROVIDING_MODULE, TestAutoConfig.class.getName()), value.getId());
}
Also used : SimpleUri(org.terasology.engine.core.SimpleUri) Test(org.junit.jupiter.api.Test)

Example 20 with SimpleUri

use of org.terasology.engine.core.SimpleUri in project Terasology by MovingBlocks.

the class BindsSubsystemTest method testUpdateBinds.

@Test
public void testUpdateBinds() {
    registerBindButtonClasses.add(TestEventButton.class);
    bindsSubsystem.updateConfigWithDefaultBinds();
    List<Input> defaultBinds = bindsSubsystem.getDefaultBindsConfig().getBinds(new SimpleUri(TEST_MODULE, "testEvent"));
    assertEquals(defaultBinds.size(), 1);
    assertEquals(defaultBinds.get(0).getType(), InputType.KEY);
    assertEquals(defaultBinds.get(0).getId(), KeyId.T);
    assertEquals(defaultBinds.get(0).getName(), Key.T.getName());
    assertEquals(defaultBinds.get(0).getDisplayName(), Key.T.getDisplayName());
    List<Input> binds = bindsSubsystem.getBindsConfig().getBinds(new SimpleUri(TEST_MODULE, "testEvent"));
    assertEquals(binds.size(), 1);
    assertEquals(binds.get(0).getType(), InputType.KEY);
    assertEquals(binds.get(0).getId(), KeyId.T);
    assertEquals(binds.get(0).getName(), Key.T.getName());
    assertEquals(binds.get(0).getDisplayName(), Key.T.getDisplayName());
}
Also used : Input(org.terasology.input.Input) SimpleUri(org.terasology.engine.core.SimpleUri) Test(org.junit.jupiter.api.Test)

Aggregations

SimpleUri (org.terasology.engine.core.SimpleUri)51 Name (org.terasology.gestalt.naming.Name)13 Map (java.util.Map)6 ModuleManager (org.terasology.engine.core.module.ModuleManager)6 FBO (org.terasology.engine.rendering.opengl.FBO)6 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)6 DependencyResolver (org.terasology.gestalt.module.dependencyresolution.DependencyResolver)6 ResolutionResult (org.terasology.gestalt.module.dependencyresolution.ResolutionResult)6 Config (org.terasology.engine.config.Config)5 BindableButton (org.terasology.engine.input.BindableButton)5 Module (org.terasology.gestalt.module.Module)5 Input (org.terasology.input.Input)5 Test (org.junit.jupiter.api.Test)4 RegisterBindButton (org.terasology.engine.input.RegisterBindButton)4 Lists (com.google.common.collect.Lists)3 List (java.util.List)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 GameManifest (org.terasology.engine.game.GameManifest)3 FboConfig (org.terasology.engine.rendering.opengl.FboConfig)3