From 49b9972adef76703b17db385a2fa24a3203f53fb Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Wed, 4 Dec 2024 01:10:12 +0100 Subject: [PATCH] replaced textinput with dynamic label --- .../pp/monopoly/client/gui/TradeMenu.java | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java index f94c04a..f45d287 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java @@ -23,6 +23,7 @@ import pp.monopoly.notification.Sound; import java.util.HashSet; import java.util.Set; + /** * Represents the trade menu dialog in the Monopoly application. *

@@ -45,7 +46,7 @@ public class TradeMenu extends Dialog { private Geometry background; private Selector leftBuildingSelector, leftSpecialCardSelector; private Selector rightBuildingSelector, rightSpecialCardSelector; - private TextField leftSelectionsField, rightSelectionsField; + private Label leftSelectionsLabel, rightSelectionsLabel; private TextField leftCurrencyInput, rightCurrencyInput; private VersionedReference> leftBuildingRef, rightBuildingRef; @@ -221,8 +222,8 @@ public class TradeMenu extends Dialog { middleLabelTop.setFontSize(24); middleLabelTop.setInsets(new Insets3f(5, 5, 5, 5)); - leftSelectionsField = middleSection.addChild(new TextField("")); - leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); + leftSelectionsLabel = middleSection.addChild(new Label("")); + leftSelectionsLabel.setPreferredSize(new Vector3f(600, 50, 0)); Container buttons = middleSection.addChild(new Container(new SpringGridLayout())); Button cancel = new Button("Abbrechen"); @@ -246,8 +247,8 @@ public class TradeMenu extends Dialog { middleLabelBottom.setFontSize(24); middleLabelBottom.setInsets(new Insets3f(5, 5, 5, 5)); - rightSelectionsField = middleSection.addChild(new TextField("")); - rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); + rightSelectionsLabel = middleSection.addChild(new Label("")); + rightSelectionsLabel.setPreferredSize(new Vector3f(600, 50, 0)); return middleSection; } @@ -322,11 +323,11 @@ public class TradeMenu extends Dialog { @Override public void update(float delta) { if (leftBuildingRef.update() || leftCardRef.update() || leftCurrencyRef.update()) { - updateSelections(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector, true); + updateSelections(leftSelectionsLabel, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector, true); } if (rightBuildingRef.update() || rightCardRef.update() || rightCurrencyRef.update()) { - updateSelections(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector, false); + updateSelections(rightSelectionsLabel, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector, false); } } @@ -339,7 +340,7 @@ public class TradeMenu extends Dialog { * @param card the special card selector * @param isLeft true if updating the left column; false otherwise */ - private void updateSelections(TextField target, Selector building, TextField currency, Selector card, boolean isLeft) { + private void updateSelections(Label target, Selector building, TextField currency, Selector card, boolean isLeft) { StringBuilder buildingText = new StringBuilder(); if (isLeft) { if (leftselBuildings.contains(building.getSelectedItem())) { @@ -347,8 +348,8 @@ public class TradeMenu extends Dialog { } else { leftselBuildings.add(building.getSelectedItem()); // Add if not already selected } - for (String property : leftselBuildings) { - buildingText.append(property); + for (String property : leftselBuildings) { + buildingText.append(property).append(", "); } } else { if (rightselBuildings.contains(building.getSelectedItem())) { @@ -356,14 +357,14 @@ public class TradeMenu extends Dialog { } else { rightselBuildings.add(building.getSelectedItem()); // Add if not already selected } - for (String property : rightselBuildings) { - buildingText.append(property); + for (String property : rightselBuildings) { + buildingText.append(property).append(", "); } } String currencyText = currency.getText() != null ? currency.getText().trim() : ""; String cardText = card.getSelectedItem() != null ? card.getSelectedItem() : ""; - target.setText(String.join(" | ", buildingText, currencyText, cardText)); + target.setText(String.join(" | ", buildingText.toString().replaceAll(", $", ""), currencyText, cardText)); } /** Opens the settings menu when the escape key is pressed. */