mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-03 18:34:25 +02:00
dice button now works and update dice images accordingly
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.List;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.ColorRGBA;
|
||||
@@ -21,6 +19,7 @@ public class TestWorld {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private CameraController cameraController; // Steuert die Kamera
|
||||
private Toolbar toolbar;
|
||||
|
||||
/**
|
||||
* Konstruktor für TestWorld.
|
||||
@@ -51,7 +50,8 @@ public class TestWorld {
|
||||
);
|
||||
|
||||
// Füge die Toolbar hinzu
|
||||
new Toolbar(app).open();
|
||||
toolbar = new Toolbar(app);
|
||||
toolbar.open();
|
||||
|
||||
cameraController.setPosition(0);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.jme3.font.BitmapText;
|
||||
@@ -18,20 +19,23 @@ import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.game.server.Player;
|
||||
import pp.monopoly.game.server.PlayerHandler;
|
||||
import pp.monopoly.message.client.RollDice;
|
||||
import pp.monopoly.notification.DiceRollEvent;
|
||||
import pp.monopoly.notification.GameEventListener;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
* Toolbar Klasse, die am unteren Rand der Szene angezeigt wird.
|
||||
* Die Buttons bewegen den Würfel auf dem Spielfeld.
|
||||
*/
|
||||
public class Toolbar extends Dialog {
|
||||
public class Toolbar extends Dialog implements GameEventListener{
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container toolbarContainer;
|
||||
private final BitmapText positionText; // Anzeige für die aktuelle Position
|
||||
private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld
|
||||
private String diceOneImage = "Pictures/dice/one.png";
|
||||
private String diceTwoImage = "Pictures/dice/two.png";
|
||||
private Label imageLabel;
|
||||
private Label imageLabel2;
|
||||
|
||||
|
||||
/**
|
||||
@@ -43,6 +47,8 @@ public class Toolbar extends Dialog {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
app.getGameLogic().addListener(this);
|
||||
|
||||
// Erstelle die Toolbar
|
||||
toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar");
|
||||
|
||||
@@ -99,13 +105,13 @@ public class Toolbar extends Dialog {
|
||||
Container leftContainer = new Container();
|
||||
leftContainer.setPreferredSize(new Vector3f(100, 150, 0)); // Adjust size as needed
|
||||
|
||||
Label imageLabel = new Label("");
|
||||
IconComponent icon = new IconComponent(diceOneImage); // Icon mit Textur erstellen
|
||||
imageLabel = new Label("");
|
||||
IconComponent icon = new IconComponent("Pictures/dice/one.png"); // Icon mit Textur erstellen
|
||||
icon.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
|
||||
imageLabel.setIcon(icon);
|
||||
|
||||
Label imageLabel2 = new Label("");
|
||||
IconComponent icon2 = new IconComponent(diceTwoImage); // Icon mit Textur erstellen
|
||||
imageLabel2 = new Label("");
|
||||
IconComponent icon2 = new IconComponent("Pictures/dice/two.png"); // Icon mit Textur erstellen
|
||||
icon2.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
|
||||
imageLabel2.setIcon(icon2);
|
||||
|
||||
@@ -138,7 +144,7 @@ public class Toolbar extends Dialog {
|
||||
Button diceButton = new Button("Würfeln");
|
||||
diceButton.setPreferredSize(new Vector3f(200, 50, 0)); // Full width for Würfeln button
|
||||
diceButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
//TODO dice roll logic
|
||||
app.getGameLogic().send(new RollDice());
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
}));
|
||||
diceContainer.addChild(diceButton);
|
||||
@@ -223,4 +229,46 @@ public class Toolbar extends Dialog {
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receivedEvent(DiceRollEvent event) {
|
||||
updateDiceImages(event.a(), event.b());
|
||||
}
|
||||
|
||||
|
||||
private void updateDiceImages(int a, int b) {
|
||||
IconComponent icon1 = new IconComponent(diceToString(a));
|
||||
IconComponent icon2 = new IconComponent(diceToString(b));
|
||||
icon1.setIconSize(new Vector2f(100, 100));
|
||||
icon2.setIconSize(new Vector2f(100, 100));
|
||||
imageLabel.setIcon(icon1);
|
||||
imageLabel2.setIcon(icon2);
|
||||
System.out.println("Dice images set");
|
||||
}
|
||||
|
||||
private String diceToString(int i) {
|
||||
switch (i) {
|
||||
case 1:
|
||||
return "Pictures/dice/one.png";
|
||||
|
||||
case 2:
|
||||
return "Pictures/dice/two.png";
|
||||
|
||||
case 3:
|
||||
return "Pictures/dice/three.png";
|
||||
|
||||
case 4:
|
||||
return "Pictures/dice/four.png";
|
||||
|
||||
case 5:
|
||||
return "Pictures/dice/five.png";
|
||||
|
||||
case 6:
|
||||
return "Pictures/dice/six.png";
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid dice number: " + i);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user