use of org.terasology.engine.core.module.rendering.RenderingModuleRegistry in project Terasology by MovingBlocks.
the class WorldRendererImpl method initRenderingModules.
private void initRenderingModules() {
renderingModuleRegistry = context.get(RenderingModuleRegistry.class);
// registry not populated by new ModuleRendering instances in UI, populate now
if (renderingModuleRegistry.getOrderedRenderingModules().isEmpty()) {
List<ModuleRendering> renderingModules = renderingModuleRegistry.updateRenderingModulesOrder(context.get(ModuleManager.class).getEnvironment(), context);
if (renderingModules.isEmpty()) {
GameEngine gameEngine = context.get(GameEngine.class);
gameEngine.changeState(new StateMainMenu("No rendering module loaded, unable to render. Try enabling " + "CoreRendering."));
}
} else {
// registry populated by new ModuleRendering instances in UI
// Switch module's context from gamecreation subcontext to gamerunning context
renderingModuleRegistry.updateModulesContext(context);
}
for (ModuleRendering moduleRenderingInstance : renderingModuleRegistry.getOrderedRenderingModules()) {
if (moduleRenderingInstance.isEnabled()) {
logger.info(String.format("\nInitialising rendering class %s from %s module.\n", moduleRenderingInstance.getClass().getSimpleName(), moduleRenderingInstance.getProvidingModule()));
moduleRenderingInstance.initialise();
}
}
requestTaskListRefresh();
}
use of org.terasology.engine.core.module.rendering.RenderingModuleRegistry in project Terasology by MovingBlocks.
the class RenderingModuleSettingScreen method postInit.
public void postInit() {
moduleEnvironment = subContext.get(ModuleEnvironment.class);
renderingModuleRegistry = context.get(RenderingModuleRegistry.class);
orderedModuleRenderingInstances = renderingModuleRegistry.updateRenderingModulesOrder(moduleEnvironment, subContext);
if (orderedModuleRenderingInstances.isEmpty()) {
logger.error("No rendering module found!");
GameEngine gameEngine = context.get(GameEngine.class);
gameEngine.changeState(new StateMainMenu("No rendering module installed, unable to render. Try enabling CoreRendering."));
return;
}
renderingModuleInfo = find("modulesInfo", UIText.class);
recalculateOrder = find("update", UIButton.class);
setEnabledRenderingClassButton = find("setEnabledRenderingClassButton", UIButton.class);
// List<Name> orderedModuleNames = new ArrayList<>();
// orderedModuleRenderingInstances.forEach(module->orderedModuleNames.add(module.getProvidingModule()));
initPrioritySlider = find("moduleInitPrioritySlider", UISlider.class);
if (initPrioritySlider != null) {
initPrioritySlider.setValue(2f);
initPrioritySlider.setUiSliderOnChangeTriggeredListener(this);
}
moduleList = find("moduleNameList", UIDropdownScrollable.class);
if (moduleList != null) {
moduleList.bindSelection(new Binding<ModuleRendering>() {
ModuleRendering selected;
@Override
public ModuleRendering get() {
return selected;
}
@Override
public void set(ModuleRendering value) {
if (initPrioritySlider != null) {
initPrioritySlider.setValue(value.getInitPriority());
}
selected = value;
}
});
moduleList.setOptions(orderedModuleRenderingInstances);
moduleList.setVisibleOptions(5);
moduleList.setSelection(orderedModuleRenderingInstances.get(0));
if (initPrioritySlider != null) {
initPrioritySlider.setValue(moduleList.getSelection().getInitPriority());
}
moduleList.setOptionRenderer(new StringTextRenderer<ModuleRendering>() {
@Override
public String getString(ModuleRendering value) {
if (value != null) {
StringBuilder stringBuilder = new StringBuilder().append(String.format("%s", value.getClass().getSimpleName()));
return stringBuilder.toString();
}
return "";
}
@Override
public void draw(ModuleRendering value, Canvas canvas) {
canvas.drawText(getString(value), canvas.getRegion());
}
});
}
if (recalculateOrder != null) {
updateRenderingModuleInfo();
recalculateOrder.subscribe(button -> {
renderingModuleRegistry.updateRenderingModulesOrder(moduleEnvironment, subContext);
orderedModuleRenderingInstances = renderingModuleRegistry.getOrderedRenderingModules();
updateRenderingModuleInfo();
});
}
if (setEnabledRenderingClassButton != null && moduleList != null) {
setEnabledRenderingClassButton.bindText(new ReadOnlyBinding<String>() {
@Override
public String get() {
return (moduleList.getSelection().isEnabled()) ? translationSystem.translate("${engine:menu#disable-rendering-class}") : translationSystem.translate("${engine:menu#enable-rendering-class}");
}
});
setEnabledRenderingClassButton.subscribe(button -> {
moduleList.getSelection().toggleEnabled();
updateRenderingModuleInfo();
});
}
// TODO returns one more screen every time...gradually
WidgetUtil.trySubscribe(this, "return", widget -> getManager().pushScreen(StartPlayingScreen.ASSET_URI));
// Update slider if module selection changes
// if (initPrioritySlider != null && moduleList != null) {
// moduleList. (this, "moduleNameList", widget->initPrioritySlider.setValue(moduleList.getSelection().getInitPriority()));
// }
}
Aggregations