mirror of
				https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
				synced 2025-10-31 12:01:51 +01:00 
			
		
		
		
	Merge remote-tracking branch 'origin/gui' into gui
This commit is contained in:
		| @@ -12,13 +12,14 @@ import com.jme3.texture.Texture; | ||||
| import pp.monopoly.client.MonopolyApp; | ||||
|  | ||||
| /** | ||||
|  * TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat und einem kleinen Würfel. | ||||
|  * Die Kamera wird durch den CameraController gesteuert, und die Koordinaten des Würfels werden angezeigt. | ||||
|  * TestWorld zeigt eine einfache Szene mit einem texturierten Quadrat und einem Würfel. | ||||
|  * Die Kamera wird durch den CameraController gesteuert. | ||||
|  */ | ||||
| public class TestWorld { | ||||
|  | ||||
|     private final MonopolyApp app; | ||||
|     private CameraController cameraController; // Steuert die Kamera | ||||
|     private Toolbar toolbar;                   // Toolbar-Instanz | ||||
|  | ||||
|     /** | ||||
|      * Konstruktor für TestWorld. | ||||
| @@ -37,15 +38,16 @@ public class TestWorld { | ||||
|         app.getRootNode().detachAllChildren(); // Entferne andere Szenenobjekte | ||||
|  | ||||
|         createBoard(); // Erstelle das Spielfeld | ||||
|         createCube();  // Füge den Würfel hinzu | ||||
|         Geometry cube = createCube(); // Erstelle den Würfel und speichere ihn | ||||
|         toolbar = new Toolbar(app, cube); // Erstelle die Toolbar und übergebe den Würfel | ||||
|  | ||||
|         // Übergib die Kamerasteuerung an CameraController | ||||
|         cameraController = new CameraController( | ||||
|                 app.getCamera(),  // Die Kamera der App | ||||
|                 Vector3f.ZERO,    // Fokus auf die Mitte des Spielfelds | ||||
|                 5,                // Radius des Kreises | ||||
|                 3,                // Höhe der Kamera | ||||
|                 0.5f              // Geschwindigkeit der Bewegung | ||||
|                 3,                // Radius des Kreises | ||||
|                 2,                // Höhe der Kamera | ||||
|                 0.05f              // Geschwindigkeit der Bewegung | ||||
|         ); | ||||
|     } | ||||
|  | ||||
| @@ -80,9 +82,9 @@ public class TestWorld { | ||||
|     /** | ||||
|      * Füge einen kleinen blauen 3D-Würfel hinzu und zeige seine Koordinaten an. | ||||
|      */ | ||||
|     private void createCube() { | ||||
|     private Geometry createCube() { | ||||
|         // Erstelle einen kleinen 3D-Würfel | ||||
|         Box cube = new Box(0.1f, 0.1f, 0.1f); // Sehr kleine Kantenlänge | ||||
|         Box cube = new Box(0.04f, 0.04f, 0.04f); // Sehr kleine Kantenlänge | ||||
|         Geometry cubeGeom = new Geometry("PlayerPiece", cube); | ||||
|      | ||||
|         // Erstelle ein Material mit einer blauen Farbe | ||||
| @@ -91,20 +93,12 @@ public class TestWorld { | ||||
|         cubeGeom.setMaterial(cubeMat); | ||||
|      | ||||
|         // Positioniere den Würfel | ||||
|         float boardWidth = 1; // Breite des Bretts (aus `createBoard`) | ||||
|         float boardDepth = 1; // Tiefe des Bretts (aus `createBoard`) | ||||
|         Vector3f cubePosition = new Vector3f( | ||||
|                 boardWidth + 0.3f, // Verschiebe den Würfel nach rechts | ||||
|                 0.1f,              // Höhe knapp über dem Brett | ||||
|                 boardDepth - 0.3f  // Position in Richtung der unteren rechten Ecke | ||||
|         ); | ||||
|         cubeGeom.setLocalTranslation(cubePosition); | ||||
|         cubeGeom.setLocalTranslation(0.9f, 0.01f, -0.9f); | ||||
|      | ||||
|         // Füge den Würfel zur Szene hinzu | ||||
|         app.getRootNode().attachChild(cubeGeom); | ||||
|      | ||||
|         // Zeige die Koordinaten des Würfels an | ||||
|         displayCubeCoordinates(cubePosition); | ||||
|         return cubeGeom; // Rückgabe des Würfels | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -0,0 +1,116 @@ | ||||
| package pp.monopoly.client.gui; | ||||
|  | ||||
| import com.jme3.math.Vector3f; | ||||
| import com.jme3.scene.Geometry; | ||||
| import com.simsilica.lemur.Button; | ||||
| import com.simsilica.lemur.Container; | ||||
| import com.simsilica.lemur.component.SpringGridLayout; | ||||
|  | ||||
| import pp.monopoly.client.MonopolyApp; | ||||
|  | ||||
| /** | ||||
|  * Toolbar Klasse, die am unteren Rand der Szene angezeigt wird. | ||||
|  * Die Buttons bewegen den Würfel auf dem Spielfeld. | ||||
|  */ | ||||
| public class Toolbar { | ||||
|  | ||||
|     private final MonopolyApp app; | ||||
|     private final Container toolbarContainer; | ||||
|     private final Geometry cube; // Referenz auf den Würfel | ||||
|     private final float boardLimit = 0.95f; // Grenzen des Bretts (leicht angepasst) | ||||
|     private final float stepSize = 0.18f; // Schrittgröße pro Bewegung | ||||
|     private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld | ||||
|     private final int positionsPerSide = 10; // Anzahl der Positionen pro Seite | ||||
|  | ||||
|     /** | ||||
|      * Konstruktor für die Toolbar. | ||||
|      * | ||||
|      * @param app  Die Hauptanwendung (MonopolyApp) | ||||
|      * @param cube Der Würfel, der bewegt werden soll | ||||
|      */ | ||||
|     public Toolbar(MonopolyApp app, Geometry cube) { | ||||
|         this.app = app; | ||||
|         this.cube = cube; | ||||
|  | ||||
|         // Erstelle die Toolbar | ||||
|         toolbarContainer = new Container(new SpringGridLayout()); | ||||
|  | ||||
|         // Setze die Position am unteren Rand und die Breite | ||||
|         toolbarContainer.setLocalTranslation( | ||||
|                 0,                                 // Links bündig | ||||
|                 100,                               // Höhe über dem unteren Rand | ||||
|                 0                                  // Z-Ebene | ||||
|         ); | ||||
|         toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0)); // Volle Breite | ||||
|  | ||||
|         // Füge Buttons zur Toolbar hinzu | ||||
|         initializeButtons(); | ||||
|  | ||||
|         // Füge die Toolbar zur GUI hinzu | ||||
|         app.getGuiNode().attachChild(toolbarContainer); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Initialisiert die Buttons in der Toolbar. | ||||
|      */ | ||||
|     private void initializeButtons() { | ||||
|         addButton("Vorwärts", 1);  // Bewegung nach vorne | ||||
|         addButton("Rückwärts", -1); // Bewegung nach hinten | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Fügt einen Button mit einer Bewegung hinzu. | ||||
|      * | ||||
|      * @param label   Der Text des Buttons | ||||
|      * @param step    Schrittweite (+1 für vorwärts, -1 für rückwärts) | ||||
|      */ | ||||
|     private void addButton(String label, int step) { | ||||
|         Button button = new Button(label); | ||||
|         button.setPreferredSize(new Vector3f(150, 50, 0)); // Größe der Buttons | ||||
|         button.addClickCommands(source -> moveCube(step)); | ||||
|         toolbarContainer.addChild(button); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Bewegt den Würfel basierend auf der aktuellen Position auf dem Brett. | ||||
|      * | ||||
|      * @param step Schrittweite (+1 für vorwärts, -1 für rückwärts) | ||||
|      */ | ||||
|     private void moveCube(int step) { | ||||
|         currentPosition = (currentPosition + step + 4 * positionsPerSide) % (4 * positionsPerSide); | ||||
|         Vector3f newPosition = calculatePosition(currentPosition); | ||||
|         cube.setLocalTranslation(newPosition); | ||||
|         System.out.println("Würfelposition: " + newPosition); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Berechnet die neue Position des Würfels basierend auf der aktuellen Brettseite und Position. | ||||
|      * | ||||
|      * @param position Aktuelle Position auf dem Spielfeld | ||||
|      * @return Die berechnete Position als Vector3f | ||||
|      */ | ||||
|     private Vector3f calculatePosition(int position) { | ||||
|         int side = position / positionsPerSide; // Seite des Bretts (0 = unten, 1 = rechts, 2 = oben, 3 = links) | ||||
|         int offset = position % positionsPerSide; // Position auf der aktuellen Seite | ||||
|  | ||||
|         switch (side) { | ||||
|             case 0: // Unten (positive x-Achse) | ||||
|                 return new Vector3f(-boardLimit + offset * stepSize, 0.1f, -boardLimit + 0.05f); | ||||
|             case 1: // Rechts (positive z-Achse) | ||||
|                 return new Vector3f(boardLimit - 0.05f, 0.1f, -boardLimit + offset * stepSize); | ||||
|             case 2: // Oben (negative x-Achse) | ||||
|                 return new Vector3f(boardLimit - offset * stepSize, 0.1f, boardLimit - 0.05f); | ||||
|             case 3: // Links (negative z-Achse) | ||||
|                 return new Vector3f(-boardLimit + 0.05f, 0.1f, boardLimit - offset * stepSize); | ||||
|             default: | ||||
|                 throw new IllegalArgumentException("Ungültige Position: " + position); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * Entfernt die Toolbar. | ||||
|      */ | ||||
|     public void remove() { | ||||
|         app.getGuiNode().detachChild(toolbarContainer); | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user