From b477077b9b5bd3d9e398bb62b4193d1125e24300 Mon Sep 17 00:00:00 2001 From: Luca Puderbach Date: Wed, 4 Dec 2024 16:39:32 +0100 Subject: [PATCH] Kamera Teil1 --- .../client/gui/CameraInputHandler.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraInputHandler.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraInputHandler.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraInputHandler.java new file mode 100644 index 0000000..bbfeca2 --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CameraInputHandler.java @@ -0,0 +1,59 @@ +package pp.monopoly.client.gui; + +import com.jme3.input.InputManager; +import com.jme3.input.KeyInput; +import com.jme3.input.controls.ActionListener; +import com.jme3.input.controls.KeyTrigger; + +/** + * Handhabt die Eingaben für die Kamera. + */ +public class CameraInputHandler { + + private CameraController cameraController; // Kamera-Controller + + /** + * Konstruktor für den CameraInputHandler. + * + * @param cameraController Der Kamera-Controller, der gesteuert werden soll. + * @param inputManager Der InputManager, um Eingaben zu registrieren. + */ + public CameraInputHandler(CameraController cameraController, InputManager inputManager) { + if (cameraController == null || inputManager == null) { + throw new IllegalArgumentException("CameraController und InputManager dürfen nicht null sein"); + } + this.cameraController = cameraController; + + // Mappings für Kamerasteuerung + inputManager.addMapping("FocusCurrentPlayer", new KeyTrigger(KeyInput.KEY_1)); // Modus 1 + inputManager.addMapping("FocusSelf", new KeyTrigger(KeyInput.KEY_2)); // Modus 2 + inputManager.addMapping("FreeCam", new KeyTrigger(KeyInput.KEY_3)); // Modus 3 + + // Listener für die Kameramodi + inputManager.addListener(actionListener, "FocusCurrentPlayer", "FocusSelf", "FreeCam"); + } + + /** + * ActionListener für die Kamerasteuerung. + */ + private final ActionListener actionListener = (name, isPressed, tpf) -> { + if (!isPressed) return; + + // Umschalten der Kamera-Modi basierend auf der Eingabe + switch (name) { + case "FocusCurrentPlayer" -> { + cameraController.setMode(CameraController.CameraMode.FOCUS_CURRENT_PLAYER); + System.out.println("Kameramodus: Fokus auf aktuellen Spieler"); + } + case "FocusSelf" -> { + cameraController.setMode(CameraController.CameraMode.FOCUS_SELF); + System.out.println("Kameramodus: Fokus auf eigene Figur"); + } + case "FreeCam" -> { + cameraController.setMode(CameraController.CameraMode.FREECAM); + System.out.println("Kameramodus: Freie Kamera"); + } + default -> System.err.println("Unbekannter Kameramodus: " + name); + } + }; +}