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<>();
}
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);
}
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));
}
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();
}
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()));
}
Aggregations