use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.
the class DeathScreen method initialise.
@Override
public void initialise() {
deathDetails = find("deathDetails", UILabel.class);
WidgetUtil.trySubscribe(this, "respawn", widget -> {
localPlayer.getClientEntity().send(new RespawnRequestEvent());
getManager().closeScreen(DeathScreen.this);
});
WidgetUtil.trySubscribe(this, "settings", widget -> getManager().pushScreen("settingsMenuScreen"));
WidgetUtil.trySubscribe(this, "mainMenu", widget -> {
localPlayer.getClientEntity().send(new RespawnRequestEvent());
gameEngine.changeState(new StateMainMenu());
});
WidgetUtil.trySubscribe(this, "exitGame", widget -> CoreRegistry.get(GameEngine.class).shutdown());
}
use of org.terasology.engine.core.modes.StateMainMenu 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()));
// }
}
use of org.terasology.engine.core.modes.StateMainMenu in project Terasology by MovingBlocks.
the class TeraEd method run.
public void run() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (Exception e) {
// If Nimbus is not available, you can set the GUI to another look and feel.
logger.warn("Failed to set look and feel to Nimbus", e);
}
try {
LwjglPortlet portlet = new LwjglPortlet();
PathManager.getInstance().useDefaultHomePath();
engine = new TerasologyEngineBuilder().add(new LwjglTimer()).add(new LwjglAudio()).add(new AwtInput()).add(new BindsSubsystem()).add(portlet).build();
if (!GLFW.glfwInit()) {
throw new RuntimeException("Failed to initialize GLFW");
}
sceneProperties = new SceneProperties(engine);
mainWindow = new MainWindow(this, engine);
portlet.createCanvas();
AWTGLCanvas canvas = portlet.getCanvas();
engine.subscribeToStateChange(mainWindow);
engine.initializeRun(new StateMainMenu());
mainWindow.getViewport().setTerasology(canvas);
portlet.initInputs();
Runnable renderLoop = new Runnable() {
public void run() {
if (canvas.isValid()) {
canvas.render();
}
SwingUtilities.invokeLater(this);
}
};
// Setup swing thread as game thread
PerformanceMonitor.startActivity("Other");
SwingUtilities.invokeAndWait(portlet::setupThreads);
SwingUtilities.invokeLater(renderLoop);
PerformanceMonitor.endActivity();
} catch (Throwable t) {
logger.error("Uncaught Exception", t);
}
}
Aggregations