added and centered buttons

This commit is contained in:
Yvonne Schmidt 2024-11-26 18:25:23 +01:00
parent f4c4f6bc93
commit ada067a2a0

View File

@ -43,12 +43,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());
@ -64,6 +60,26 @@ public class TradeMenu extends Dialog {
//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(32); // 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 +87,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));
@ -86,11 +103,29 @@ public class TradeMenu extends Dialog {
arrows.setFontSize(40);
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 +138,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 +147,46 @@ public class TradeMenu extends Dialog {
// Add dropdowns
column.addChild(new Label("Gebäude:"));
Selector<String> buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
buildingSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
column.addChild(new Label("Währung:"));
Selector<String> currencySelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
currencySelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
column.addChild(new Label("Sonderkarten:"));
Selector<String> specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
specialCardSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
// Assign selectors to corresponding fields
if (isLeft) {
leftBuildingSelector = buildingSelector;
leftCurrencySelector = currencySelector;
leftSpecialCardSelector = specialCardSelector;
// "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;