Compare commits

...

2 Commits

Author SHA1 Message Date
Johannes Schmelz
4095d9e79d fixed buyCard color and button function 2024-11-25 21:29:00 +01:00
Johannes Schmelz
547a4c2353 cleanup toolbar 2024-11-25 21:14:38 +01:00
3 changed files with 48 additions and 129 deletions

View File

@ -61,4 +61,9 @@ public class ChoosePartner extends Dialog {
app.getGuiNode().attachChild(background);
}
@Override
public void escape() {
new SettingsMenu(app).open();
}
}

View File

@ -27,11 +27,10 @@ public class Toolbar extends Dialog {
private final MonopolyApp app;
private final Container toolbarContainer;
private final BitmapText positionText; // Anzeige für die aktuelle Position
private final float boardLimit = 0.95f; // Grenzen des Bretts
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
private final Random random = new Random(); // Zufallsgenerator für den Würfelwurf
private String diceOneImage = "Pictures/dice/one.png";
private String diceTwoImage = "Pictures/dice/two.png";
/**
* Konstruktor für die Toolbar.
@ -94,12 +93,12 @@ public class Toolbar extends Dialog {
leftContainer.setPreferredSize(new Vector3f(100, 150, 0)); // Adjust size as needed
Label imageLabel = new Label("");
IconComponent icon = new IconComponent("Pictures/dice/one.png"); // Icon mit Textur erstellen
IconComponent icon = new IconComponent(diceOneImage); // Icon mit Textur erstellen
icon.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
imageLabel.setIcon(icon);
Label imageLabel2 = new Label("");
IconComponent icon2 = new IconComponent("Pictures/dice/two.png"); // Icon mit Textur erstellen
IconComponent icon2 = new IconComponent(diceTwoImage); // Icon mit Textur erstellen
icon2.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes
imageLabel2.setIcon(icon2);
@ -132,7 +131,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(() -> {
rollDice();
//TODO dice roll logic
app.getGameLogic().playSound(Sound.BUTTON);
}));
diceContainer.addChild(diceButton);
@ -142,9 +141,9 @@ public class Toolbar extends Dialog {
// Menü-Container: Ein Nested-Container für Handeln, Grundstücke und Zug beenden
Container menuContainer = toolbarContainer.addChild(new Container());
menuContainer.addChild(new Button("Handeln"));
menuContainer.addChild(new Button("Grundstücke"));
menuContainer.addChild(new Button("Zug beenden"));
menuContainer.addChild(addTradeMenuButton());
menuContainer.addChild(addPropertyMenuButton());
menuContainer.addChild(addEndTurnButton());
menuContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Füge die Toolbar zur GUI hinzu
@ -155,107 +154,35 @@ public class Toolbar extends Dialog {
updatePositionDisplay(); // Initialisiere die Anzeige mit der Startposition
}
/**
* Initialisiert die Buttons in der Toolbar.
*/
private void initializeButtons() {
addTradeMenuButton(); // Bewegung nach vorne
addEndTurnButton(); // Bewegung nach hinten
addDiceRollButton(); // Würfel-Button
}
/**
* 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);
}*/
/**
* Fügt den Würfel-Button hinzu, der die Figur entsprechend der gewürfelten Zahl bewegt.
*/
private Button addDiceRollButton() {
Button diceButton = new Button("Würfeln");
diceButton.setPreferredSize(new Vector3f(50, 20, 0));
diceButton.addClickCommands(s -> ifTopDialog(() -> {
rollDice();
app.getGameLogic().playSound(Sound.BUTTON);
}));
toolbarContainer.addChild(diceButton);
return diceButton;
}
private void addTradeMenuButton() {
Button diceButton = new Button("Handeln");
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
diceButton.addClickCommands(s -> {
rollDice();
private Button addTradeMenuButton() {
Button tradebutton = new Button("Handeln");
tradebutton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
tradebutton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
this.close();
System.out.println("test");
new ChoosePartner(app).open();
});
toolbarContainer.addChild(diceButton);
}// TODO Funktion der Buttons Überarbeiten und prüfen
private void addEndTurnButton() {
Button diceButton = new Button("Grundstücke");
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
diceButton.addClickCommands(s -> ifTopDialog(() -> {
rollDice();
app.getGameLogic().playSound(Sound.BUTTON);
}));
toolbarContainer.addChild(diceButton);
return tradebutton;
}
private void addPropertyMenuButton() {
Button diceButton = new Button("Zug beenden");
diceButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
diceButton.addClickCommands(s -> ifTopDialog(() -> {
rollDice();
private Button addEndTurnButton() {
Button endTurnButton = new Button("Grundstücke");
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO open property dialog
}));
toolbarContainer.addChild(diceButton);
return endTurnButton;
}
/**
* Simuliert einen Würfelwurf und bewegt die Figur entsprechend.
*/
private void rollDice() {
int diceRoll = random.nextInt(6) + 1; // Zahl zwischen 1 und 6
System.out.println("Gewürfelt: " + diceRoll);
}
/**
* 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);
}
private Button addPropertyMenuButton() {
Button propertyMenuButton = new Button("Zug beenden");
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO send end turn
}));
return propertyMenuButton;
}
/**

View File

@ -15,13 +15,13 @@ import pp.monopoly.client.MonopolyApp;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.model.fields.BoardManager;
import pp.monopoly.model.fields.BuildingProperty;
import pp.monopoly.notification.Sound;
/**
* SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann.
*/
public class BuyCard extends Dialog {
private final MonopolyApp app;
private final Geometry overlayBackground;
private final Container buyCardContainer;
private final Container backgroundContainer;
@ -34,22 +34,18 @@ public class BuyCard extends Dialog {
//Generate the corresponfing field
BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index);
// Halbtransparentes Overlay hinzufügen
overlayBackground = createOverlayBackground();
app.getGuiNode().attachChild(overlayBackground);
// Create the background container
backgroundContainer = new Container();
backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background
app.getGuiNode().attachChild(backgroundContainer);
attachChild(backgroundContainer);
// Hauptcontainer für die Gebäudekarte
buyCardContainer = new Container();
buyCardContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
Label settingsTitle = buyCardContainer.addChild(new Label( field.getName(), new ElementId("settings-title")));
settingsTitle.setFontSize(48);
Label title = buyCardContainer.addChild(new Label( field.getName(), new ElementId("label-Bold")));
title.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
title.setFontSize(48);
// Text, der auf der Karte steht
// Die Preise werden dynamisch dem BoardManager entnommen
@ -70,9 +66,17 @@ public class BuyCard extends Dialog {
// Beenden-Button
Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button")));
quitButton.setFontSize(32);
quitButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
close();
}));
// Kaufen-Button
Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button")));
buyButton.setFontSize(32);
buyButton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO send buy property request
}));
float padding = 10; // Padding around the settingsContainer for the background
backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0));
@ -94,22 +98,6 @@ public class BuyCard extends Dialog {
app.getGuiNode().attachChild(buyCardContainer);
}
/**
* Erstellt einen halbtransparenten Hintergrund für das Menü.
*
* @return Geometrie des Overlays
*/
private Geometry createOverlayBackground() {
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
Geometry overlay = new Geometry("Overlay", quad);
Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
overlay.setMaterial(material);
overlay.setLocalTranslation(0, 0, 0);
return overlay;
}
/**
* Schließt das Menü und entfernt die GUI-Elemente.
*/
@ -117,7 +105,6 @@ public class BuyCard extends Dialog {
public void close() {
app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
super.close();
}