Search in sources :

Example 6 with InputSystem

use of org.terasology.engine.input.InputSystem in project Terasology by MovingBlocks.

the class InputSystemTests method setUp.

@BeforeEach
public void setUp() {
    Context context = new ContextImpl();
    setUpLocalPlayer(context);
    setUpDisplayDevice(context);
    setUpBindsManager(context);
    setUpTargetSystem(context);
    context.put(Time.class, new TimeSystem());
    inputSystem = new InputSystem();
    InjectionHelper.inject(inputSystem, context);
    testKeyboard = new TestKeyboard();
    inputSystem.setKeyboardDevice(testKeyboard);
    clientEntityKeyEvents = new ArrayList<>();
    characterEntityKeyEvents = new ArrayList<>();
}
Also used : Context(org.terasology.engine.context.Context) InputSystem(org.terasology.engine.input.InputSystem) ContextImpl(org.terasology.engine.context.internal.ContextImpl) TimeSystem(org.terasology.engine.core.subsystem.headless.device.TimeSystem) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with InputSystem

use of org.terasology.engine.input.InputSystem in project Terasology by MovingBlocks.

the class OpenVRInput method postInitialise.

/**
 * Set up listeners and input devices.
 * @param rootContext
 */
@Override
public void postInitialise(Context rootContext) {
    config = context.get(Config.class);
    if (!config.getRendering().isVrSupport()) {
        return;
    }
    this.context = rootContext;
    InputSystem inputSystem = context.get(InputSystem.class);
    if (inputSystem == null) {
        inputSystem = new InputSystem();
        inputSystem.setMouseDevice(new LwjglMouseDevice(config.getRendering()));
        inputSystem.setKeyboardDevice(new LwjglKeyboardDevice());
        context.put(InputSystem.class, inputSystem);
        long window = GLFW.glfwGetCurrentContext();
        ((LwjglKeyboardDevice) inputSystem.getKeyboard()).registerToLwjglWindow(window);
        ((LwjglMouseDevice) inputSystem.getMouseDevice()).registerToLwjglWindow(window);
    }
    controllerDevice = new OpenVRControllers();
    vrProvider.getState().addControllerListener(controllerDevice);
    inputSystem.setControllerDevice(controllerDevice);
}
Also used : Config(org.terasology.engine.config.Config) LwjglMouseDevice(org.terasology.engine.input.lwjgl.LwjglMouseDevice) LwjglKeyboardDevice(org.terasology.engine.input.lwjgl.LwjglKeyboardDevice) InputSystem(org.terasology.engine.input.InputSystem)

Example 8 with InputSystem

use of org.terasology.engine.input.InputSystem in project Terasology by MovingBlocks.

the class ContextMenuUtilsTest method setupInput.

@BeforeAll
public static void setupInput() {
    context.put(InputSystem.class, new InputSystem());
    context.put(TranslationSystem.class, new TranslationSystemImpl(context));
    context.put(CanvasRenderer.class, new HeadlessCanvasRenderer());
    context.put(NUIManager.class, new NUIManagerInternal((TerasologyCanvasRenderer) context.get(CanvasRenderer.class), context));
    File file = new File(ContextMenuUtilsTest.class.getClassLoader().getResource("contextMenuBuilderInput.ui").getFile());
    String content = null;
    try {
        content = Files.asCharSource(file, Charsets.UTF_8).read();
    } catch (IOException e) {
        fail("Could not load input file", e);
    }
    inputTree = JsonTreeConverter.serialize(new JsonParser().parse(content));
}
Also used : TranslationSystemImpl(org.terasology.engine.i18n.TranslationSystemImpl) CanvasRenderer(org.terasology.nui.canvas.CanvasRenderer) TerasologyCanvasRenderer(org.terasology.engine.rendering.nui.internal.TerasologyCanvasRenderer) HeadlessCanvasRenderer(org.terasology.engine.core.subsystem.headless.renderer.HeadlessCanvasRenderer) InputSystem(org.terasology.engine.input.InputSystem) IOException(java.io.IOException) TerasologyCanvasRenderer(org.terasology.engine.rendering.nui.internal.TerasologyCanvasRenderer) File(java.io.File) HeadlessCanvasRenderer(org.terasology.engine.core.subsystem.headless.renderer.HeadlessCanvasRenderer) NUIManagerInternal(org.terasology.engine.rendering.nui.internal.NUIManagerInternal) JsonParser(com.google.gson.JsonParser) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 9 with InputSystem

use of org.terasology.engine.input.InputSystem in project Terasology by MovingBlocks.

the class StateMainMenu method init.

@Override
public void init(GameEngine gameEngine) {
    context = gameEngine.createChildContext();
    headless = context.get(DisplayDevice.class).isHeadless();
    initEntityAndComponentManagers(headless);
    createLocalPlayer(context);
    if (!headless) {
        // TODO: REMOVE this and handle refreshing of core game state at the engine level - see Issue #1127
        new RegisterInputSystem(context).step();
        nuiManager = context.get(NUIManager.class);
        eventSystem.registerEventHandler(nuiManager);
        NUIEditorSystem nuiEditorSystem = new NUIEditorSystem();
        context.put(NUIEditorSystem.class, nuiEditorSystem);
        componentSystemManager.register(nuiEditorSystem, "engine:NUIEditorSystem");
        NUISkinEditorSystem nuiSkinEditorSystem = new NUISkinEditorSystem();
        context.put(NUISkinEditorSystem.class, nuiSkinEditorSystem);
        componentSystemManager.register(nuiSkinEditorSystem, "engine:NUISkinEditorSystem");
        inputSystem = context.get(InputSystem.class);
    }
    componentSystemManager.initialise();
    console = context.get(Console.class);
    storageServiceWorker = context.get(StorageServiceWorker.class);
    playBackgroundMusic();
    if (!headless) {
        // guiManager.openWindow("main");
        context.get(NUIManager.class).pushScreen("engine:mainMenuScreen");
    }
    if (!messageOnLoad.isEmpty()) {
        TranslationSystem translationSystem = context.get(TranslationSystem.class);
        if (headless) {
            throw new RuntimeException(String.format("Game could not be started, server attempted to return to main menu: [%s]. See logs before", translationSystem.translate(messageOnLoad)));
        } else {
            MessagePopup popup = nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class);
            popup.setMessage("Error", translationSystem.translate(messageOnLoad));
        }
    }
// TODO: enable it when exposing the telemetry to users
// pushLaunchPopup();
}
Also used : NUIEditorSystem(org.terasology.engine.rendering.nui.editor.systems.NUIEditorSystem) TranslationSystem(org.terasology.engine.i18n.TranslationSystem) Console(org.terasology.engine.logic.console.Console) MessagePopup(org.terasology.engine.rendering.nui.layers.mainMenu.MessagePopup) RegisterInputSystem(org.terasology.engine.core.modes.loadProcesses.RegisterInputSystem) NUISkinEditorSystem(org.terasology.engine.rendering.nui.editor.systems.NUISkinEditorSystem) RegisterInputSystem(org.terasology.engine.core.modes.loadProcesses.RegisterInputSystem) InputSystem(org.terasology.engine.input.InputSystem) NUIManager(org.terasology.engine.rendering.nui.NUIManager) StorageServiceWorker(org.terasology.engine.identity.storageServiceClient.StorageServiceWorker)

Example 10 with InputSystem

use of org.terasology.engine.input.InputSystem in project Terasology by MovingBlocks.

the class NUIManagerInternal method update.

@Override
public void update(float delta) {
    canvas.processMousePosition(mouse.getPosition());
    // modifying a collection while iterating of it is typically not supported
    for (UIScreenLayer screen : new ArrayList<>(screens)) {
        screen.update(delta);
    }
    for (ControlWidget widget : overlays.values()) {
        widget.update(delta);
    }
    InputSystem inputSystem = context.get(InputSystem.class);
    inputSystem.getMouseDevice().setGrabbed(inputSystem.isCapturingMouse() && !(this.isReleasingMouse()));
}
Also used : ControlWidget(org.terasology.nui.ControlWidget) ArrayList(java.util.ArrayList) InputSystem(org.terasology.engine.input.InputSystem) UIScreenLayer(org.terasology.engine.rendering.nui.UIScreenLayer)

Aggregations

InputSystem (org.terasology.engine.input.InputSystem)10 Config (org.terasology.engine.config.Config)3 AwtKeyboardDevice (org.terasology.editor.input.AwtKeyboardDevice)2 AwtMouseDevice (org.terasology.editor.input.AwtMouseDevice)2 ControllerConfig (org.terasology.engine.config.ControllerConfig)2 LwjglControllerDevice (org.terasology.engine.input.lwjgl.LwjglControllerDevice)2 LwjglKeyboardDevice (org.terasology.engine.input.lwjgl.LwjglKeyboardDevice)2 LwjglMouseDevice (org.terasology.engine.input.lwjgl.LwjglMouseDevice)2 JsonParser (com.google.gson.JsonParser)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Context (org.terasology.engine.context.Context)1 ContextImpl (org.terasology.engine.context.internal.ContextImpl)1 ComponentSystemManager (org.terasology.engine.core.ComponentSystemManager)1 RegisterInputSystem (org.terasology.engine.core.modes.loadProcesses.RegisterInputSystem)1 TimeSystem (org.terasology.engine.core.subsystem.headless.device.TimeSystem)1 HeadlessCanvasRenderer (org.terasology.engine.core.subsystem.headless.renderer.HeadlessCanvasRenderer)1