use of org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method onOpened.
@Override
public void onOpened() {
super.onOpened();
try {
if (findWorldByName(selectedWorld).getWorldGenerator() == null) {
worldGenerator = WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(), context, environment);
findWorldByName(selectedWorld).setWorldGenerator(worldGenerator);
} else {
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
}
if (worldGenerator.getWorldSeed().isEmpty()) {
worldGenerator.setWorldSeed(createSeed(selectedWorld));
}
previewGen = new FacetLayerPreview(environment, worldGenerator);
updatePreview();
} catch (UnresolvedWorldGeneratorException e) {
e.printStackTrace();
}
}
use of org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method setEnvironment.
/**
* A function called before the screen comes to the forefront to setup the environment
* and extract necessary objects from the new Context.
*
* @param subContext The new environment created in {@link UniverseSetupScreen}
* @throws UnresolvedWorldGeneratorException The creation of a world generator can throw this Exception
*/
public void setEnvironment(Context subContext) throws UnresolvedWorldGeneratorException {
context = subContext;
environment = context.get(ModuleEnvironment.class);
context.put(WorldGeneratorPluginLibrary.class, new TempWorldGeneratorPluginLibrary(environment, context));
worldList = context.get(UniverseSetupScreen.class).getWorldsList();
selectedWorld = context.get(UniverseSetupScreen.class).getSelectedWorld();
worldNames = context.get(UniverseSetupScreen.class).worldNames();
setWorldGenerators();
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.setOptions(worldNames);
genTexture();
List<Zone> previewZones = Lists.newArrayList(worldGenerator.getZones()).stream().filter(z -> !z.getPreviewLayers().isEmpty()).collect(Collectors.toList());
if (previewZones.isEmpty()) {
previewGen = new FacetLayerPreview(environment, worldGenerator);
}
}
use of org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
zoomSlider = find("zoomSlider", UISlider.class);
if (zoomSlider != null) {
zoomSlider.setValue(2f);
zoomSlider.setUiSliderOnChangeTriggeredListener(this);
}
final UIDropdownScrollable worldsDropdown = find("worlds", UIDropdownScrollable.class);
worldsDropdown.bindSelection(new Binding<String>() {
@Override
public String get() {
return selectedWorld;
}
@Override
public void set(String value) {
selectedWorld = value;
try {
if (findWorldByName(selectedWorld).getWorldGenerator() == null) {
worldGenerator = WorldGeneratorManager.createWorldGenerator(findWorldByName(selectedWorld).getWorldGeneratorInfo().getUri(), context, environment);
findWorldByName(selectedWorld).setWorldGenerator(worldGenerator);
} else {
worldGenerator = findWorldByName(selectedWorld).getWorldGenerator();
}
if (worldGenerator.getWorldSeed() == null) {
worldGenerator.setWorldSeed(createSeed(selectedWorld));
}
previewGen = new FacetLayerPreview(environment, worldGenerator);
updatePreview();
} catch (UnresolvedWorldGeneratorException e) {
e.printStackTrace();
}
}
});
WidgetUtil.trySubscribe(this, "reRoll", button -> {
worldGenerator.setWorldSeed(createSeed(selectedWorld));
updatePreview();
});
StartPlayingScreen startPlayingScreen = getManager().createScreen(StartPlayingScreen.ASSET_URI, StartPlayingScreen.class);
WidgetUtil.trySubscribe(this, "continue", button -> {
startPlayingScreen.setTargetWorld(worldList, findWorldByName(selectedWorld), texture, context);
triggerForwardAnimation(startPlayingScreen);
});
WorldSetupScreen worldSetupScreen = getManager().createScreen(WorldSetupScreen.ASSET_URI, WorldSetupScreen.class);
WidgetUtil.trySubscribe(this, "config", button -> {
try {
if (!selectedWorld.isEmpty()) {
worldSetupScreen.setWorld(context, findWorldByName(selectedWorld), worldsDropdown);
triggerForwardAnimation(worldSetupScreen);
} else {
getManager().pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Worlds List Empty!", "No world found to configure.");
}
} catch (UnresolvedWorldGeneratorException e) {
e.printStackTrace();
}
});
WidgetUtil.trySubscribe(this, "close", button -> {
final UniverseSetupScreen universeSetupScreen = getManager().createScreen(UniverseSetupScreen.ASSET_URI, UniverseSetupScreen.class);
UIDropdownScrollable worldsDropdownOfUniverse = universeSetupScreen.find("worlds", UIDropdownScrollable.class);
universeSetupScreen.refreshWorldDropdown(worldsDropdownOfUniverse);
triggerBackAnimation();
});
WidgetUtil.trySubscribe(this, "mainMenu", button -> {
getManager().pushScreen("engine:mainMenuScreen");
});
}
use of org.terasology.engine.rendering.nui.layers.mainMenu.preview.FacetLayerPreview 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);
}
}
Aggregations