Compare commits

...

5 Commits

Author SHA1 Message Date
Yvonne Schmidt
d6ce859fcd ChoosePartner accept-button opens TradeMenu 2024-11-26 01:12:29 +01:00
Yvonne Schmidt
e5f69c9536 Merge remote-tracking branch 'origin/gui' into gui
# Conflicts:
#	Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java
2024-11-26 01:08:59 +01:00
Yvonne Schmidt
d8a2225038 added framework for TradeMenu 2024-11-26 01:07:59 +01:00
Johannes Schmelz
7b91a679f5 abbrechen button in chossePatner 2024-11-26 00:57:22 +01:00
Yvonne Schmidt
840658b590 fixed background location again 2024-11-26 00:34:49 +01:00
3 changed files with 199 additions and 17 deletions

View File

@ -1,7 +1,5 @@
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;
@ -11,20 +9,16 @@ import com.jme3.texture.Texture;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Insets3f;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Selector;
import com.simsilica.lemur.TextField;
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 pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.notification.Sound;
import java.util.Set;
public class ChoosePartner extends Dialog {
private final MonopolyApp app;
private Selector<String> playerSelector;
@ -33,6 +27,7 @@ public class ChoosePartner extends Dialog {
private final Container mainContainer;
private Container lowerLeftMenu;
private Container lowerRightMenu;
private Geometry background;
QuadBackgroundComponent translucentWhiteBackground =
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
@ -70,7 +65,7 @@ public class ChoosePartner extends Dialog {
mainContainer.setLocalTranslation(
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
0
4
);
}
@ -95,7 +90,8 @@ public class ChoosePartner extends Dialog {
Vector3f dimens = dropdownContainer.getPreferredSize();
Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize();
dimens2.setX( dimens.getX() );
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,5));
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3));
playerSelector.setLocalTranslation(0,0,5);
return dropdownContainer;
}
@ -115,13 +111,12 @@ public class ChoosePartner extends Dialog {
cancelButton.setFontSize(30);
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
this.close();
new Toolbar(app).open();
close();
}));
lowerLeftMenu.addChild(cancelButton);
// Position the container near the bottom-left corner
lowerLeftMenu.setLocalTranslation(new Vector3f(120, 170, 3)); // Adjust X and Y to align with the bottom-left corner
lowerLeftMenu.setLocalTranslation(new Vector3f(120, 170, 5)); // Adjust X and Y to align with the bottom-left corner
app.getGuiNode().attachChild(lowerLeftMenu);
@ -133,13 +128,13 @@ public class ChoosePartner extends Dialog {
app.getGameLogic().playSound(Sound.BUTTON);
String selectedPlayer = playerSelector.getSelectedItem();
System.out.println("Selected player: " + selectedPlayer);
this.close();
// TODO: Open trade menu or next step
close();
new TradeMenu(app).open();
}));
lowerRightMenu.addChild(confirmButton);
// Position the container near the bottom-right corner
lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 3)); // X: 220px from the right, Y: 50px above the bottom
lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 5)); // X: 220px from the right, Y: 50px above the bottom
app.getGuiNode().attachChild(lowerRightMenu);
@ -152,11 +147,11 @@ public class ChoosePartner extends Dialog {
private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
Geometry background = new Geometry("Background", quad);
background = new Geometry("Background", quad);
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial);
background.setLocalTranslation(0, 0, 1); // Position behind other GUI elements
background.setLocalTranslation(0, 0, 3); // Position behind other GUI elements
app.getGuiNode().attachChild(background);
}
@ -177,6 +172,16 @@ public class ChoosePartner extends Dialog {
public void update(float delta) {
// Periodic updates (if needed) can be implemented here
}
@Override
public void close() {
app.getGuiNode().detachChild(playerSelector);
app.getGuiNode().detachChild(lowerLeftMenu);
app.getGuiNode().detachChild(lowerRightMenu);
app.getGuiNode().detachChild(mainContainer);
app.getGuiNode().detachChild(background);
super.close();
}
}

View File

@ -166,7 +166,6 @@ public class Toolbar extends Dialog {
tradebutton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
tradebutton.addClickCommands(s -> ifTopDialog( () -> {
app.getGameLogic().playSound(Sound.BUTTON);
this.close();
new ChoosePartner(app).open();
}));
return tradebutton;

View File

@ -0,0 +1,178 @@
package pp.monopoly.client.gui;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Quad;
import com.jme3.texture.Texture;
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.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.notification.Sound;
public class TradeMenu extends Dialog {
private final MonopolyApp app;
private final Container mainContainer;
private Selector<String> leftBuildingSelector, leftCurrencySelector, leftSpecialCardSelector;
private Selector<String> rightBuildingSelector, rightCurrencySelector, rightSpecialCardSelector;
private final Button cancelButton = new Button("Abbrechen");
private final Button tradeButton = new Button("Handeln");
private Container lowerLeftMenu, lowerRightMenu;
QuadBackgroundComponent translucentWhiteBackground =
new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White));
/**
* Constructs the TradeMenu dialog.
*
* @param app The Monopoly application instance.
*/
public TradeMenu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
// Background Image
addBackgroundImage();
// Main container for the UI components
mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
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 main content (three columns: left, middle, right)
mainContainer.addChild(createMainContent());
// Attach main container to GUI node
app.getGuiNode().attachChild(mainContainer);
mainContainer.setLocalTranslation(
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
7
);
}
//TODO Logik
//TODO Ebenen prüfen und eine Ebene Hochsetzen
//TODO Farben der Label anpassen
/**
* Creates the main content layout (left, middle, right columns).
*
* @return The main content container.
*/
private Container createMainContent() {
Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y));
// Left Column
mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true));
// Middle Section
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..."));
Label arrows = middleSection.addChild(new Label(""));
arrows.setFontSize(40);
TextField rightSelectionsField = middleSection.addChild(new TextField("Zielobjekte..."));
// Right Column
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
return mainContent;
}
/**
* Creates a column for trade objects (left or right side).
*
* @param label The label for the column.
* @param isLeft Whether this column is the left side.
* @return The column container.
*/
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)));
Label columnLabel = column.addChild(new Label(label));
columnLabel.setFontSize(24);
columnLabel.setBackground(translucentWhiteBackground);
// Add dropdowns
column.addChild(new Label("Gebäude:"));
Selector<String> buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
column.addChild(new Label("Währung:"));
Selector<String> currencySelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
column.addChild(new Label("Sonderkarten:"));
Selector<String> specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass"));
// Assign selectors to corresponding fields
if (isLeft) {
leftBuildingSelector = buildingSelector;
leftCurrencySelector = currencySelector;
leftSpecialCardSelector = specialCardSelector;
} else {
rightBuildingSelector = buildingSelector;
rightCurrencySelector = currencySelector;
rightSpecialCardSelector = specialCardSelector;
}
return column;
}
/**
* Provides sample dropdown items.
*/
private VersionedList<String> getSampleItems() {
VersionedList<String> items = new VersionedList<>();
items.add("Option 1");
items.add("Option 2");
items.add("Option 3");
return items;
}
/**
* Adds a background image to the dialog.
*/
private void addBackgroundImage() {
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
Geometry background = new Geometry("Background", quad);
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
backgroundMaterial.setTexture("ColorMap", backgroundImage);
background.setMaterial(backgroundMaterial);
background.setLocalTranslation(0, 0, 6); // Position behind other GUI elements
app.getGuiNode().attachChild(background);
}
/**
* Handles the escape action for the dialog.
*/
@Override
public void escape() {
new SettingsMenu(app).open();
}
/**
* Updates the dialog periodically, called by the dialog manager.
*
* @param delta The time elapsed since the last update.
*/
@Override
public void update(float delta) {
// Periodic updates (if needed) can be implemented here
}
}