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 810f173..280edc2 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 @@ -1,5 +1,7 @@ package pp.monopoly.client.gui; +import com.jme3.app.Application; +import com.jme3.app.state.BaseAppState; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; @@ -10,11 +12,15 @@ import com.simsilica.lemur.*; import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.SpringGridLayout; import com.simsilica.lemur.core.VersionedList; +import com.simsilica.lemur.core.VersionedReference; import com.simsilica.lemur.style.ElementId; +import com.simsilica.lemur.text.DocumentModel; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.notification.Sound; +import java.util.Set; + public class TradeMenu extends Dialog { private final MonopolyApp app; private final Container mainContainer; @@ -23,6 +29,7 @@ public class TradeMenu extends Dialog { private final Button cancelButton = new Button("Abbrechen"); private final Button tradeButton = new Button("Handeln"); private Container lowerLeftMenu, lowerRightMenu; + private TextField leftSelectionsField; QuadBackgroundComponent translucentWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White)); @@ -43,12 +50,8 @@ public class TradeMenu extends Dialog { mainContainer.setPreferredSize(new Vector3f(1200, 800, 0)); mainContainer.setBackground(translucentWhiteBackground); - - // Add title with background - Label headerLabel = mainContainer.addChild(new Label("Handelsmenu", new ElementId("label-Bold"))); - headerLabel.setFontSize(40); - headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); - + // Add header container + mainContainer.addChild(createHeaderContainer()); // Add main content (three columns: left, middle, right) mainContainer.addChild(createMainContent()); @@ -61,8 +64,25 @@ public class TradeMenu extends Dialog { ); } //TODO Logik - //TODO Ebenen prüfen und eine Ebene Hochsetzen - //TODO Farben der Label anpassen + + /** + * Creates a container for the header with a fixed size. + * + * @return The header container. + */ + private Container createHeaderContainer() { + // Create a container for the header + Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + headerContainer.setPreferredSize(new Vector3f(200, 100, 0)); // Set fixed width and height + + // Add the header label + Label headerLabel = headerContainer.addChild(new Label("Handelsmenü", new ElementId("label-Bold"))); + headerLabel.setFontSize(50); // Adjust font size as needed + headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); // Add padding around the label + headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); // Optional background + + return headerContainer; + } /** * Creates the main content layout (left, middle, right columns). @@ -71,6 +91,7 @@ public class TradeMenu extends Dialog { */ private Container createMainContent() { Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + mainContent.setPreferredSize(new Vector3f(1200, 700, 0)); // Left Column mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true)); @@ -79,18 +100,56 @@ public class TradeMenu extends Dialog { Container middleSection = mainContent.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X))); middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f))); - TextField leftSelectionsField = middleSection.addChild(new TextField("Quellobjekte...")); + // Add combined label + Label middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:")); + middleLabel.setFontSize(24); // Adjust font size as needed + middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label + + // Add the Quellobjekte TextField + leftSelectionsField = middleSection.addChild(new TextField("")); + leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); // Larger width to fit the split sections + + // Add listeners to update the TextField dynamically + addCustomSelectionListener(leftBuildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + + + + Label arrows = middleSection.addChild(new Label("⇅")); arrows.setFontSize(40); + // Add combined label + middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:")); + middleLabel.setFontSize(24); // Adjust font size as needed + middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label + TextField rightSelectionsField = middleSection.addChild(new TextField("Zielobjekte...")); + // "Bestätigen" button + lowerRightMenu = new Container(); + tradeButton.setPreferredSize(new Vector3f(200, 60, 0)); + tradeButton.setFontSize(30); + tradeButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + new TradeMenu(app).open(); + })); + lowerRightMenu.addChild(tradeButton); + + // Position the container near the bottom-right corner + lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 680, 100, 8)); // X: 220px from the right, Y: 50px above the bottom + app.getGuiNode().attachChild(lowerRightMenu); + // Right Column mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false)); + Label spacer = middleSection.addChild(new Label("")); // Spacer + spacer.setPreferredSize(new Vector3f(1, 50, 0)); + return mainContent; } @@ -103,7 +162,7 @@ public class TradeMenu extends Dialog { */ private Container createTradeColumn(String label, boolean isLeft) { Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - column.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); + column.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White))); Label columnLabel = column.addChild(new Label(label)); columnLabel.setFontSize(24); @@ -112,22 +171,52 @@ public class TradeMenu extends Dialog { // Add dropdowns column.addChild(new Label("Gebäude:")); Selector buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + buildingSelector.setInsets(new Insets3f(5, 10, 5, 10)); + buildingSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); column.addChild(new Label("Währung:")); - Selector currencySelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + TextField currencyInput = column.addChild(new TextField("")); + currencyInput.setInsets(new Insets3f(5, 10, 5, 10)); + currencyInput.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); column.addChild(new Label("Sonderkarten:")); Selector specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + specialCardSelector.setInsets(new Insets3f(5, 10, 5, 10)); + specialCardSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); + // Assign selectors to corresponding fields if (isLeft) { leftBuildingSelector = buildingSelector; - leftCurrencySelector = currencySelector; leftSpecialCardSelector = specialCardSelector; - } else { + + // Add listeners for left selectors to update the middle text field + addCustomSelectionListener(buildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + addCustomSelectionListener(specialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + + // "Abbrechen" button + lowerLeftMenu = new Container(); + cancelButton.setPreferredSize(new Vector3f(200, 60, 0)); + cancelButton.setFontSize(30); + cancelButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); + lowerLeftMenu.addChild(cancelButton); + + // Position the container near the bottom-left corner + lowerLeftMenu.setLocalTranslation(new Vector3f(70, 100, 8)); // Adjust X and Y to align with the bottom-left corner + app.getGuiNode().attachChild(lowerLeftMenu); + + Label spacer = column.addChild(new Label("")); // Spacer + spacer.setPreferredSize(new Vector3f(1, 130, 0)); + + } else { rightBuildingSelector = buildingSelector; - rightCurrencySelector = currencySelector; rightSpecialCardSelector = specialCardSelector; + + Label spacer = column.addChild(new Label("")); // Spacer + spacer.setPreferredSize(new Vector3f(1, 130, 0)); } return column; @@ -158,6 +247,26 @@ public class TradeMenu extends Dialog { app.getGuiNode().attachChild(background); } + private void updateLeftSelectionsField(TextField leftSelectionsField) { + // Get all selections from the leftBuildingSelector and leftSpecialCardSelector + String buildingSelections = leftBuildingSelector.getSelectedItem() != null + ? leftBuildingSelector.getSelectedItem() + : ""; + String specialCardSelections = leftSpecialCardSelector.getSelectedItem() != null + ? leftSpecialCardSelector.getSelectedItem() + : ""; + + // Get the direct input from the middle part of the TextField + String manualInput = leftSelectionsField.getText(); + + // Combine all parts into one formatted string + String combinedText = String.format("%-30s %-30s %-30s", buildingSelections, manualInput, specialCardSelections); + + // Update the content of the TextField + leftSelectionsField.setText(combinedText); + } + + /** * Handles the escape action for the dialog. */ @@ -175,4 +284,41 @@ public class TradeMenu extends Dialog { public void update(float delta) { // Periodic updates (if needed) can be implemented here } + + /** + * Functional interface for a selection action listener. + */ + @FunctionalInterface + private interface SelectionActionListener { + void onSelectionChanged(T selection); + } + /** + * Adds a custom action listener to the Selector. + */ + private void addCustomSelectionListener(Selector selector, SelectionActionListener listener) { + VersionedReference> selectionRef = selector.getSelectionModel().createReference(); + + app.getStateManager().attach(new BaseAppState() { + @Override + public void update(float tpf) { + if (selectionRef.update()) { + String selected = selector.getSelectedItem(); + listener.onSelectionChanged(selected); + } + } + + @Override + protected void initialize(Application app) {} + + @Override + protected void cleanup(Application app) {} + + @Override + protected void onEnable() {} + + @Override + protected void onDisable() {} + }); + } + }