Search in sources :

Example 6 with StateMainMenu

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());
}
Also used : UILabel(org.terasology.nui.widgets.UILabel) RespawnRequestEvent(org.terasology.engine.logic.players.event.RespawnRequestEvent) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu)

Example 7 with StateMainMenu

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()));
// }
}
Also used : UISlider(org.terasology.nui.widgets.UISlider) UIDropdownScrollable(org.terasology.nui.widgets.UIDropdownScrollable) Canvas(org.terasology.nui.Canvas) GameEngine(org.terasology.engine.core.GameEngine) ModuleEnvironment(org.terasology.gestalt.module.ModuleEnvironment) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) ModuleRendering(org.terasology.engine.rendering.dag.ModuleRendering) UIButton(org.terasology.nui.widgets.UIButton) UIText(org.terasology.nui.widgets.UIText) RenderingModuleRegistry(org.terasology.engine.core.module.rendering.RenderingModuleRegistry)

Example 8 with StateMainMenu

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);
    }
}
Also used : LwjglPortlet(org.terasology.editor.subsystem.LwjglPortlet) LwjglAudio(org.terasology.engine.core.subsystem.lwjgl.LwjglAudio) TerasologyEngineBuilder(org.terasology.engine.core.TerasologyEngineBuilder) UIManager(javax.swing.UIManager) AwtInput(org.terasology.editor.subsystem.AwtInput) BindsSubsystem(org.terasology.engine.core.subsystem.config.BindsSubsystem) StateMainMenu(org.terasology.engine.core.modes.StateMainMenu) SceneProperties(org.terasology.editor.properties.SceneProperties) MainWindow(org.terasology.editor.ui.MainWindow) LwjglTimer(org.terasology.engine.core.subsystem.lwjgl.LwjglTimer) AWTGLCanvas(org.lwjgl.opengl.awt.AWTGLCanvas)

Aggregations

StateMainMenu (org.terasology.engine.core.modes.StateMainMenu)8 GameEngine (org.terasology.engine.core.GameEngine)4 ModuleManager (org.terasology.engine.core.module.ModuleManager)3 ModuleEnvironment (org.terasology.gestalt.module.ModuleEnvironment)3 TerasologyEngineBuilder (org.terasology.engine.core.TerasologyEngineBuilder)2 EnvironmentSwitchHandler (org.terasology.engine.core.bootstrap.EnvironmentSwitchHandler)2 RenderingModuleRegistry (org.terasology.engine.core.module.rendering.RenderingModuleRegistry)2 ModuleRendering (org.terasology.engine.rendering.dag.ModuleRendering)2 Module (org.terasology.gestalt.module.Module)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 UIManager (javax.swing.UIManager)1 AWTGLCanvas (org.lwjgl.opengl.awt.AWTGLCanvas)1 SceneProperties (org.terasology.editor.properties.SceneProperties)1 AwtInput (org.terasology.editor.subsystem.AwtInput)1 LwjglPortlet (org.terasology.editor.subsystem.LwjglPortlet)1