mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-19 00:06:16 +01:00
added documentation for TradeMenu
This commit is contained in:
parent
a73384c436
commit
acb5c75379
@ -23,12 +23,25 @@ import pp.monopoly.notification.Sound;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Represents the trade menu dialog in the Monopoly application.
|
||||
* <p>
|
||||
* Facilitates trade interactions between players, including selection of properties,
|
||||
* currency, and special cards for offers and requests.
|
||||
* </p>
|
||||
*/
|
||||
public class TradeMenu extends Dialog {
|
||||
|
||||
/** The Monopoly application instance. */
|
||||
private final MonopolyApp app;
|
||||
|
||||
/** The trade handler managing trade logic. */
|
||||
private final TradeHandler tradeHandler;
|
||||
|
||||
/** Main container for the trade menu UI. */
|
||||
private final Container mainContainer;
|
||||
|
||||
/** Background geometry for the menu. */
|
||||
private Geometry background;
|
||||
private Selector<String> leftBuildingSelector, leftSpecialCardSelector;
|
||||
private Selector<String> rightBuildingSelector, rightSpecialCardSelector;
|
||||
@ -44,6 +57,12 @@ public class TradeMenu extends Dialog {
|
||||
|
||||
private static final ColorRGBA TRANSLUCENT_WHITE = new ColorRGBA(1, 1, 1, 0.5f);
|
||||
|
||||
/**
|
||||
* Constructs the trade menu dialog.
|
||||
*
|
||||
* @param app the Monopoly application instance
|
||||
* @param tradeHandler the handler managing trade interactions
|
||||
*/
|
||||
public TradeMenu(MonopolyApp app, TradeHandler tradeHandler) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
@ -57,7 +76,7 @@ public class TradeMenu extends Dialog {
|
||||
|
||||
initializeReferences();
|
||||
}
|
||||
|
||||
/** Creates the main container for the trade menu UI. */
|
||||
private Container createMainContainer() {
|
||||
Container container = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
container.setPreferredSize(new Vector3f(1200, 800, 0));
|
||||
@ -67,7 +86,7 @@ public class TradeMenu extends Dialog {
|
||||
container.addChild(createMainContent());
|
||||
return container;
|
||||
}
|
||||
|
||||
/** Creates the header label for the trade menu. */
|
||||
private Label createHeader() {
|
||||
Label header = new Label("Handelsmenü", new ElementId("label-Bold"));
|
||||
header.setFontSize(50);
|
||||
@ -75,7 +94,7 @@ public class TradeMenu extends Dialog {
|
||||
header.setBackground(new QuadBackgroundComponent(TRANSLUCENT_WHITE));
|
||||
return header;
|
||||
}
|
||||
|
||||
/** Creates the main content section of the trade menu. */
|
||||
private Container createMainContent() {
|
||||
Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||
mainContent.setPreferredSize(new Vector3f(1200, 700, 0));
|
||||
@ -87,6 +106,7 @@ public class TradeMenu extends Dialog {
|
||||
return mainContent;
|
||||
}
|
||||
|
||||
/** Sets the trade data based on the current selections. */
|
||||
private void setTrades() {
|
||||
String leftCurreny = leftCurrencyInput.getText().equals("")? "0" : leftCurrencyInput.getText();
|
||||
String rightCurreny = rightCurrencyInput.getText().equals("")? "0" : rightCurrencyInput.getText();
|
||||
@ -109,6 +129,12 @@ public class TradeMenu extends Dialog {
|
||||
tradeHandler.setRequestedProperties(requestedProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a trade column for either the sender or receiver.
|
||||
*
|
||||
* @param label the label text for the column
|
||||
* @param isLeft true if the column is for the sender; false otherwise
|
||||
*/
|
||||
private Container createTradeColumn(String label, boolean isLeft) {
|
||||
Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
column.setBackground(new QuadBackgroundComponent(ColorRGBA.White));
|
||||
@ -134,6 +160,12 @@ public class TradeMenu extends Dialog {
|
||||
return column;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a property selector for buildings.
|
||||
*
|
||||
* @param isLeft true if the selector is for the sender; false otherwise
|
||||
* @return the created property selector
|
||||
*/
|
||||
private Selector<String> createPropertySelector(boolean isLeft) {
|
||||
VersionedList<String> properties = new VersionedList<>();
|
||||
for (PropertyField field : getPropertyFields(isLeft)) {
|
||||
@ -144,6 +176,12 @@ public class TradeMenu extends Dialog {
|
||||
return selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a selector for special cards.
|
||||
*
|
||||
* @param isLeft true if the selector is for the sender; false otherwise
|
||||
* @return the created special card selector
|
||||
*/
|
||||
private Selector<String> createSpecialCardSelector(boolean isLeft) {
|
||||
VersionedList<String> numbers = new VersionedList<>();
|
||||
for (int i = 0; i <= app.getGameLogic().getPlayerHandler().getPlayerById(isLeft ? tradeHandler.getReceiver().getId() : tradeHandler.getSender().getId()).getNumJailCard(); i++) {
|
||||
@ -154,6 +192,12 @@ public class TradeMenu extends Dialog {
|
||||
return selector;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the property fields owned by the respective player.
|
||||
*
|
||||
* @param isLeft true if retrieving fields for the sender; false otherwise
|
||||
* @return an iterable of property fields
|
||||
*/
|
||||
private Iterable<PropertyField> getPropertyFields(boolean isLeft) {
|
||||
return app.getGameLogic()
|
||||
.getBoardManager()
|
||||
@ -162,13 +206,13 @@ public class TradeMenu extends Dialog {
|
||||
.getPlayerById(isLeft ? tradeHandler.getSender().getId() : tradeHandler.getReceiver().getId())
|
||||
.getProperties());
|
||||
}
|
||||
|
||||
/** Creates a text field for currency input. */
|
||||
private TextField createCurrencyInput() {
|
||||
TextField currencyInput = new TextField("0");
|
||||
styleTextField(currencyInput);
|
||||
return currencyInput;
|
||||
}
|
||||
|
||||
/** Creates the middle section containing buttons and summary fields. */
|
||||
private Container createMiddleSection() {
|
||||
Container middleSection = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f)));
|
||||
@ -207,17 +251,28 @@ public class TradeMenu extends Dialog {
|
||||
return middleSection;
|
||||
}
|
||||
|
||||
/** Styles the given selector with insets and background color. */
|
||||
private void styleSelector(Selector<String> selector) {
|
||||
selector.setInsets(new Insets3f(5, 10, 5, 10));
|
||||
selector.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
|
||||
}
|
||||
|
||||
/** Styles the given text field with insets and background color. */
|
||||
private void styleTextField(TextField textField) {
|
||||
textField.setInsets(new Insets3f(5, 10, 5, 10));
|
||||
textField.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));
|
||||
textField.setPreferredSize(new Vector3f(300, 30, 0));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assigns selectors and input fields to either the left or right column.
|
||||
*
|
||||
* @param buildingSelector the building selector
|
||||
* @param specialCardSelector the special card selector
|
||||
* @param currencyInput the currency input field
|
||||
* @param isLeft true if assigning to the left column; false otherwise
|
||||
*/
|
||||
private void assignSelectors(Selector<String> buildingSelector, Selector<String> specialCardSelector, TextField currencyInput, boolean isLeft) {
|
||||
if (isLeft) {
|
||||
leftBuildingSelector = buildingSelector;
|
||||
@ -229,7 +284,7 @@ public class TradeMenu extends Dialog {
|
||||
rightCurrencyInput = currencyInput;
|
||||
}
|
||||
}
|
||||
|
||||
/** Positions the main container at the center of the screen. */
|
||||
private void positionMainContainer() {
|
||||
mainContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
|
||||
@ -237,7 +292,7 @@ public class TradeMenu extends Dialog {
|
||||
7
|
||||
);
|
||||
}
|
||||
|
||||
/** Adds a background image to the trade menu. */
|
||||
private void addBackgroundImage() {
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
@ -248,7 +303,7 @@ public class TradeMenu extends Dialog {
|
||||
background.setLocalTranslation(0, 0, 6);
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
/** Initializes references for tracking UI changes. */
|
||||
private void initializeReferences() {
|
||||
leftBuildingRef = leftBuildingSelector.getSelectionModel().createReference();
|
||||
leftCardRef = leftSpecialCardSelector.getSelectionModel().createReference();
|
||||
@ -259,6 +314,11 @@ public class TradeMenu extends Dialog {
|
||||
rightCurrencyRef = rightCurrencyInput.getDocumentModel().createReference();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the trade menu state, including selected properties and values.
|
||||
*
|
||||
* @param delta the time elapsed since the last update
|
||||
*/
|
||||
@Override
|
||||
public void update(float delta) {
|
||||
if (leftBuildingRef.update() || leftCardRef.update() || leftCurrencyRef.update()) {
|
||||
@ -270,6 +330,15 @@ public class TradeMenu extends Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the displayed selections for properties, currency, and cards.
|
||||
*
|
||||
* @param target the target text field to update
|
||||
* @param building the building selector
|
||||
* @param currency the currency input field
|
||||
* @param card the special card selector
|
||||
* @param isLeft true if updating the left column; false otherwise
|
||||
*/
|
||||
private void updateSelections(TextField target, Selector<String> building, TextField currency, Selector<String> card, boolean isLeft) {
|
||||
StringBuilder buildingText = new StringBuilder();
|
||||
if (isLeft) {
|
||||
@ -297,11 +366,13 @@ public class TradeMenu extends Dialog {
|
||||
target.setText(String.join(" | ", buildingText, currencyText, cardText));
|
||||
}
|
||||
|
||||
/** Opens the settings menu when the escape key is pressed. */
|
||||
@Override
|
||||
public void escape() {
|
||||
new SettingsMenu(app).open();
|
||||
}
|
||||
|
||||
/** Closes the trade menu and detaches UI elements. */
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(mainContainer);
|
||||
|
Loading…
Reference in New Issue
Block a user