use of org.terasology.engine.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 depencencies for " + worldGenUri);
}
}
use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.
the class InputSettingsScreen method addInputSection.
private void addInputSection(InputCategory category, ColumnLayout layout, Map<SimpleUri, RegisterBindButton> inputsById) {
if (category != null) {
layout.addWidget(new UISpace(new Vector2i(0, 16)));
UILabel categoryHeader = new UILabel(translationSystem.translate(category.displayName()));
categoryHeader.setFamily("subheading");
layout.addWidget(categoryHeader);
Set<SimpleUri> processedBinds = Sets.newHashSet();
for (String bindId : category.ordering()) {
SimpleUri bindUri = new SimpleUri(bindId);
if (bindUri.isValid()) {
RegisterBindButton bind = inputsById.get(new SimpleUri(bindId));
if (bind != null) {
addInputBindRow(bindUri, bind, layout);
processedBinds.add(bindUri);
}
}
}
List<ExtensionBind> extensionBindList = Lists.newArrayList();
for (Map.Entry<SimpleUri, RegisterBindButton> bind : inputsById.entrySet()) {
if (bind.getValue().category().equals(category.id()) && !processedBinds.contains(bind.getKey())) {
extensionBindList.add(new ExtensionBind(bind.getKey(), bind.getValue()));
}
}
Collections.sort(extensionBindList);
for (ExtensionBind extension : extensionBindList) {
addInputBindRow(extension.uri, extension.bind, layout);
}
}
}
use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.
the class InputSettingsScreen method initialise.
@Override
public void initialise() {
setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
ColumnLayout mainLayout = new ColumnLayout();
mainLayout.setHorizontalSpacing(8);
mainLayout.setVerticalSpacing(8);
mainLayout.setFamily("option-grid");
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));
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);
if (module.isCodeModule()) {
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);
}
}
}
}
}
}
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);
}
ScrollableArea area = find("area", ScrollableArea.class);
area.setContent(mainLayout);
WidgetUtil.trySubscribe(this, "reset", button -> {
inputDeviceConfiguration.reset();
bindsManager.getBindsConfig().setBinds(bindsManager.getDefaultBindsConfig());
});
WidgetUtil.trySubscribe(this, "back", button -> triggerBackAnimation());
}
use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.
the class AbstractNode method dispose.
@Override
public void dispose() {
for (Map.Entry<SimpleUri, BaseFBOsManager> entry : fboUsages.entrySet()) {
SimpleUri fboName = entry.getKey();
BaseFBOsManager baseFBOsManager = entry.getValue();
baseFBOsManager.release(fboName);
}
fboUsages.clear();
}
use of org.terasology.engine.SimpleUri in project Terasology by MovingBlocks.
the class OutputToScreenNode method handleCommand.
@Override
public void handleCommand(String command, String... arguments) {
switch(command) {
case "setFbo":
if (arguments.length != 1) {
throw new RuntimeException("Invalid number of arguments; expected 1, received " + arguments.length + "!");
}
FBO fbo;
switch(arguments[0]) {
case "engine:fbo.gBuffer":
case "engine:fbo.lastUpdatedGBuffer":
fbo = lastUpdatedGBuffer;
break;
case "engine:fbo.staleGBuffer":
fbo = staleGBuffer;
break;
default:
fbo = displayResolutionDependentFBOs.get(new SimpleUri(arguments[0]));
if (fbo == null) {
throw new RuntimeException(("No FBO is associated with URI '" + arguments[0] + "'"));
}
break;
}
setFbo(fbo);
break;
default:
throw new RuntimeException("Unrecognized command: '" + command + "'");
}
}
Aggregations