Search in sources :

Example 41 with SimpleUri

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

the class SortOrderSystem method postBegin.

/**
 * Initializes sort order.
 */
public void postBegin() {
    initialized = true;
    controlPressed = false;
    Map<Integer, BindableButton> keys = bindsManager.getKeyBinds();
    BindButtonSubscriber controlSubscriber = new BindButtonSubscriber() {

        @Override
        public boolean onPress(float delta, EntityRef target) {
            if (!containsConsole()) {
                controlPressed = true;
            } else {
                controlPressed = false;
            }
            return false;
        }

        @Override
        public boolean onRepeat(float delta, EntityRef target) {
            return false;
        }

        @Override
        public boolean onRelease(float delta, EntityRef target) {
            controlPressed = false;
            return false;
        }
    };
    BindButtonSubscriber tabSubscriber = new BindButtonSubscriber() {

        @Override
        public boolean onPress(float delta, EntityRef target) {
            if (controlPressed) {
                target.send(new FocusChangedEvent());
            }
            return false;
        }

        @Override
        public boolean onRepeat(float delta, EntityRef target) {
            if (controlPressed) {
                target.send(new FocusChangedEvent());
            }
            return false;
        }

        @Override
        public boolean onRelease(float delta, EntityRef target) {
            return false;
        }
    };
    if (keys.containsKey(Keyboard.Key.RIGHT_CTRL.getId())) {
        keys.get(Keyboard.Key.RIGHT_CTRL.getId()).subscribe(controlSubscriber);
    } else {
        keys.put(Keyboard.Key.RIGHT_CTRL.getId(), new BindableButtonImpl(new SimpleUri("ctrlMod"), "Control Modifier", new BindButtonEvent()));
        keys.get(Keyboard.Key.RIGHT_CTRL.getId()).subscribe(controlSubscriber);
    }
    if (keys.containsKey(Keyboard.Key.LEFT_CTRL.getId())) {
        keys.get(Keyboard.Key.LEFT_CTRL.getId()).subscribe(controlSubscriber);
    } else {
        keys.put(Keyboard.Key.LEFT_CTRL.getId(), new BindableButtonImpl(new SimpleUri("ctrlMod"), "Control Modifier", new BindButtonEvent()));
        keys.get(Keyboard.Key.LEFT_CTRL.getId()).subscribe(controlSubscriber);
    }
    if (keys.containsKey(Keyboard.Key.TAB.getId())) {
        keys.get(Keyboard.Key.TAB.getId()).subscribe(tabSubscriber);
    } else {
        keys.put(Keyboard.Key.TAB.getId(), new BindableButtonImpl(new SimpleUri("changeFocus"), "Change Focus", new BindButtonEvent()));
        keys.get(Keyboard.Key.TAB.getId()).subscribe(tabSubscriber);
    }
    current = 0;
    index = 0;
    layersFilled = new ArrayList<>();
    enabledWidgets = new ArrayList<>();
    used = new ArrayList<>();
    inSortOrder = false;
}
Also used : BindableButton(org.terasology.engine.input.BindableButton) BindButtonEvent(org.terasology.engine.input.BindButtonEvent) BindButtonSubscriber(org.terasology.engine.input.BindButtonSubscriber) SimpleUri(org.terasology.engine.core.SimpleUri) BindableButtonImpl(org.terasology.engine.input.internal.BindableButtonImpl) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 42 with SimpleUri

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

the class AdvancedGameSetupScreen method saveConfiguration.

private void saveConfiguration() {
    // moduleConfig passes the module collection to other screens
    ModuleConfig moduleConfig = config.getDefaultModSelection();
    moduleConfig.clear();
    // Fetch all the selected/activated modules using allSortedModules
    // instead of fetching only selected/activated modules from filtered collection
    // of modules using sortedModules
    allSortedModules.stream().filter(info -> info.isSelected() && info.isExplicitSelection()).forEach(info -> moduleConfig.addModule(info.getMetadata().getId()));
    SimpleUri defaultGenerator = config.getWorldGeneration().getDefaultGenerator();
    ModuleSelectionInfo info = modulesLookup.get(defaultGenerator.getModuleName());
    if (info != null && !info.isSelected()) {
        config.getWorldGeneration().setDefaultGenerator(new SimpleUri());
    }
    worldGenManager.refresh();
    config.save();
}
Also used : ModuleInstaller(org.terasology.engine.core.module.ModuleInstaller) WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) In(org.terasology.engine.registry.In) LoggerFactory(org.slf4j.LoggerFactory) WidgetUtil(org.terasology.nui.WidgetUtil) ModuleMetadata(org.terasology.gestalt.module.ModuleMetadata) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) Future(java.util.concurrent.Future) Map(java.util.Map) AbstractItemRenderer(org.terasology.nui.itemRendering.AbstractItemRenderer) DependencyInfo(org.terasology.gestalt.module.dependencyresolution.DependencyInfo) Canvas(org.terasology.nui.Canvas) ResettableUIText(org.terasology.nui.widgets.ResettableUIText) StateLoading(org.terasology.engine.core.modes.StateLoading) ReadOnlyBinding(org.terasology.nui.databinding.ReadOnlyBinding) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Binding(org.terasology.nui.databinding.Binding) ImmutableSet(com.google.common.collect.ImmutableSet) StringUtils(org.codehaus.plexus.util.StringUtils) GameEngine(org.terasology.engine.core.GameEngine) CancellationException(java.util.concurrent.CancellationException) Module(org.terasology.gestalt.module.Module) Collection(java.util.Collection) UniverseWrapper(org.terasology.engine.rendering.nui.layers.mainMenu.UniverseWrapper) WaitPopup(org.terasology.engine.rendering.nui.layers.mainMenu.WaitPopup) Set(java.util.Set) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) SimpleUri(org.terasology.engine.core.SimpleUri) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Vector2i(org.joml.Vector2i) UIList(org.terasology.nui.widgets.UIList) Name(org.terasology.gestalt.naming.Name) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) 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) NetworkMode(org.terasology.engine.network.NetworkMode) TargetLengthBasedClassNameAbbreviator(ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator) DependencyResolutionFailedException(org.terasology.engine.core.module.DependencyResolutionFailedException) FastRandom(org.terasology.engine.utilities.random.FastRandom) ArrayList(java.util.ArrayList) StandardModuleExtension(org.terasology.engine.core.module.StandardModuleExtension) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) GameManifest(org.terasology.engine.game.GameManifest) Lists(com.google.common.collect.Lists) ConfirmPopup(org.terasology.engine.rendering.nui.layers.mainMenu.ConfirmPopup) GameManifestProvider(org.terasology.engine.rendering.nui.layers.mainMenu.GameManifestProvider) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) ModuleConfig(org.terasology.engine.config.ModuleConfig) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) UILabel(org.terasology.nui.widgets.UILabel) SelectModulesConfig(org.terasology.engine.config.SelectModulesConfig) Maps(com.google.common.collect.Maps) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) UICheckbox(org.terasology.nui.widgets.UICheckbox) ExecutionException(java.util.concurrent.ExecutionException) Config(org.terasology.engine.config.Config) TextChangeEventListener(org.terasology.nui.widgets.TextChangeEventListener) UIButton(org.terasology.nui.widgets.UIButton) UniverseSetupScreen(org.terasology.engine.rendering.nui.layers.mainMenu.UniverseSetupScreen) Comparator(java.util.Comparator) SimpleUri(org.terasology.engine.core.SimpleUri) ModuleConfig(org.terasology.engine.config.ModuleConfig)

Example 43 with SimpleUri

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

the class PreviewWorldScreen method setEnvironment.

public void setEnvironment() throws Exception {
    // TODO: pass world gen and module list directly rather than using the config
    SimpleUri worldGenUri = config.getWorldGeneration().getDefaultGenerator();
    DependencyResolver resolver = new DependencyResolver(moduleManager.getRegistry());
    ResolutionResult result = resolver.resolve(config.getDefaultModSelection().listModules());
    if (result.isSuccess()) {
        subContext = new ContextImpl(context);
        CoreRegistry.setContext(subContext);
        environment = moduleManager.loadEnvironment(result.getModules(), false);
        subContext.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, subContext));
        EnvironmentSwitchHandler environmentSwitchHandler = context.get(EnvironmentSwitchHandler.class);
        environmentSwitchHandler.handleSwitchToPreviewEnvironment(subContext, environment);
        genTexture();
        worldGenerator = WorldGeneratorManager.createWorldGenerator(worldGenUri, subContext, environment);
        worldGenerator.setWorldSeed(seed.getText());
        List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
        if (previewZones.isEmpty()) {
            zoneSelector.setVisible(false);
            previewGen = new FacetLayerPreview(environment, worldGenerator);
        } else {
            zoneSelector.setVisible(true);
            zoneSelector.setOptions(previewZones);
            zoneSelector.setSelection(previewZones.get(0));
        }
        configureProperties();
    } else {
        throw new UnresolvedDependencyException("Unable to resolve dependencies for " + worldGenUri);
    }
}
Also used : WorldGeneratorManager(org.terasology.engine.world.generator.internal.WorldGeneratorManager) Component(org.terasology.gestalt.entitysystem.component.Component) In(org.terasology.engine.registry.In) Texture(org.terasology.engine.rendering.assets.texture.Texture) LoggerFactory(org.slf4j.LoggerFactory) WidgetUtil(org.terasology.nui.WidgetUtil) OneOfProviderFactory(org.terasology.nui.properties.OneOfProviderFactory) ByteBuffer(java.nio.ByteBuffer) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) ModuleAwareAssetTypeManager(org.terasology.gestalt.assets.module.ModuleAwareAssetTypeManager) Map(java.util.Map) TeraMath(org.terasology.math.TeraMath) PropertyLayout(org.terasology.nui.layouts.PropertyLayout) Property(org.terasology.nui.properties.Property) Binding(org.terasology.nui.databinding.Binding) PreviewGenerator(org.terasology.engine.rendering.nui.layers.mainMenu.preview.PreviewGenerator) WorldConfigurator(org.terasology.engine.world.generator.WorldConfigurator) ComponentLibrary(org.terasology.engine.entitySystem.metadata.ComponentLibrary) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) UIImage(org.terasology.nui.widgets.UIImage) Collectors(java.util.stream.Collectors) SimpleUri(org.terasology.engine.core.SimpleUri) NUIManager(org.terasology.engine.rendering.nui.NUIManager) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) Objects(java.util.Objects) UnresolvedDependencyException(org.terasology.gestalt.module.exceptions.UnresolvedDependencyException) UIText(org.terasology.nui.widgets.UIText) List(java.util.List) Context(org.terasology.engine.context.Context) ContextImpl(org.terasology.engine.context.internal.ContextImpl) ReflectFactory(org.terasology.reflection.reflect.ReflectFactory) TextureData(org.terasology.engine.rendering.assets.texture.TextureData) CoreRegistry(org.terasology.engine.registry.CoreRegistry) MenuAnimationSystems(org.terasology.engine.rendering.nui.animation.MenuAnimationSystems) UIDropdown(org.terasology.nui.widgets.UIDropdown) UISlider(org.terasology.nui.widgets.UISlider) ModuleManager(org.terasology.engine.core.module.ModuleManager) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) WorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.WorldGeneratorPluginLibrary) Zone(org.terasology.engine.world.zones.Zone) Callable(java.util.concurrent.Callable) PropertyProvider(org.terasology.nui.properties.PropertyProvider) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Lists(com.google.common.collect.Lists) WorldGenerator(org.terasology.engine.world.generator.WorldGenerator) PropertyOrdering(org.terasology.nui.properties.PropertyOrdering) Logger(org.slf4j.Logger) Assets(org.terasology.engine.utilities.Assets) FieldMetadata(org.terasology.reflection.metadata.FieldMetadata) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) CoreScreenLayer(org.terasology.engine.rendering.nui.CoreScreenLayer) Config(org.terasology.engine.config.Config) UIButton(org.terasology.nui.widgets.UIButton) Zone(org.terasology.engine.world.zones.Zone) ResolutionResult(org.terasology.gestalt.module.dependencyresolution.ResolutionResult) SimpleUri(org.terasology.engine.core.SimpleUri) TempWorldGeneratorPluginLibrary(org.terasology.engine.world.generator.plugin.TempWorldGeneratorPluginLibrary) UnresolvedDependencyException(org.terasology.gestalt.module.exceptions.UnresolvedDependencyException) ContextImpl(org.terasology.engine.context.internal.ContextImpl) FacetLayerPreview(org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview) DependencyResolver(org.terasology.gestalt.module.dependencyresolution.DependencyResolver) EnvironmentSwitchHandler(org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)

Example 44 with SimpleUri

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

the class StartPlayingScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
    WidgetUtil.trySubscribe(this, "play", button -> {
        universeWrapper.setTargetWorld(targetWorld);
        final GameManifest gameManifest = GameManifestProvider.createGameManifest(universeWrapper, moduleManager, config);
        if (gameManifest != null) {
            gameEngine.changeState(new StateLoading(gameManifest, (universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
        } else {
            getManager().createScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", "Can't create new game!");
        }
        SimpleUri uri;
        WorldInfo worldInfo;
        // gameManifest.addWorld(worldInfo);
        int i = 0;
        for (WorldSetupWrapper world : worldSetupWrappers) {
            if (world != targetWorld) {
                i++;
                uri = world.getWorldGeneratorInfo().getUri();
                worldInfo = new WorldInfo(TerasologyConstants.MAIN_WORLD + i, world.getWorldName().toString(), world.getWorldGenerator().getWorldSeed(), (long) (WorldTime.DAY_LENGTH * WorldTime.NOON_OFFSET), uri);
                gameManifest.addWorld(worldInfo);
                config.getUniverseConfig().addWorldManager(worldInfo);
            }
        }
        gameEngine.changeState(new StateLoading(gameManifest, (universeWrapper.getLoadingAsServer()) ? NetworkMode.DEDICATED_SERVER : NetworkMode.NONE));
    });
    WidgetUtil.trySubscribe(this, "mainMenu", button -> {
        getManager().pushScreen("engine:mainMenuScreen");
    });
    WidgetUtil.trySubscribe(this, "renderingSettings", button -> {
        RenderingModuleSettingScreen renderingModuleSettingScreen = (RenderingModuleSettingScreen) getManager().getScreen(RenderingModuleSettingScreen.ASSET_URI);
        if (renderingModuleSettingScreen == null) {
            renderingModuleSettingScreen = getManager().createScreen(RenderingModuleSettingScreen.ASSET_URI, RenderingModuleSettingScreen.class);
            renderingModuleSettingScreen.setSubContext(this.subContext);
            renderingModuleSettingScreen.postInit();
        }
        triggerForwardAnimation(renderingModuleSettingScreen);
    });
}
Also used : GameManifest(org.terasology.engine.game.GameManifest) StateLoading(org.terasology.engine.core.modes.StateLoading) RenderingModuleSettingScreen(org.terasology.engine.rendering.nui.layers.mainMenu.videoSettings.RenderingModuleSettingScreen) SimpleUri(org.terasology.engine.core.SimpleUri) WorldInfo(org.terasology.engine.world.internal.WorldInfo) WorldSetupWrapper(org.terasology.engine.rendering.world.WorldSetupWrapper)

Example 45 with SimpleUri

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

the class ImmutableFbo method request.

@Override
public FBO request(FboConfig fboConfig) {
    FBO fbo;
    SimpleUri fboName = fboConfig.getName();
    if (fboConfigs.containsKey(fboName)) {
        if (!fboConfig.equals(fboConfigs.get(fboName))) {
            throw new IllegalArgumentException("Requested FBO is already available with different configuration");
        }
        fbo = fboLookup.get(fboConfig.getName());
    } else {
        fbo = generateWithDimensions(fboConfig, fboConfig.getDimensions());
    }
    retain(fboName);
    return fbo;
}
Also used : FBO(org.terasology.engine.rendering.opengl.FBO) SimpleUri(org.terasology.engine.core.SimpleUri)

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