mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-04-17 01:10:58 +02:00
Compare commits
5 Commits
29cc73e83b
...
7f6011720c
Author | SHA1 | Date | |
---|---|---|---|
|
7f6011720c | ||
|
bdc5f0269f | ||
|
a6054e825e | ||
|
156e76fe0a | ||
|
89587a4c78 |
@ -68,7 +68,7 @@ public class ChoosePartner extends Dialog {
|
||||
// Add buttons
|
||||
mainContainer.addChild(createButtonContainer());
|
||||
|
||||
addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged);
|
||||
addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged);
|
||||
|
||||
// Attach main container to GUI node
|
||||
app.getGuiNode().attachChild(mainContainer);
|
||||
@ -104,6 +104,7 @@ public class ChoosePartner extends Dialog {
|
||||
dimens2.setX( dimens.getX() );
|
||||
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3));
|
||||
playerSelector.setLocalTranslation(0,0,5);
|
||||
onDropdownSelectionChanged(playerOptions.get(0));
|
||||
|
||||
return dropdownContainer;
|
||||
}
|
||||
@ -204,13 +205,13 @@ public class ChoosePartner extends Dialog {
|
||||
public void update(float tpf) {
|
||||
if (selectionRef.update()) {
|
||||
String selected = selectionRef.get().toString();
|
||||
System.out.println(selected);
|
||||
listener.onSelectionChanged(selected);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize(Application app) {
|
||||
update(1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -233,7 +234,6 @@ public class ChoosePartner extends Dialog {
|
||||
* Callback for when the dropdown selection changes.
|
||||
*/
|
||||
private void onDropdownSelectionChanged(String selected) {
|
||||
System.out.println("Selected: " + selected);
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
int idStart = selected.indexOf("(ID: ") + 5; // Find start of the ID
|
||||
int idEnd = selected.indexOf(")", idStart); // Find end of the ID
|
||||
@ -245,9 +245,6 @@ public class ChoosePartner extends Dialog {
|
||||
|
||||
if (selectedPlayer != null) {
|
||||
tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler
|
||||
System.out.println("Receiver set to: " + selectedPlayer.getName() + " (ID: " + selectedPlayer.getId() + ")");
|
||||
} else {
|
||||
System.err.println("Player with ID " + playerId + " not found.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class LobbyMenu extends Dialog {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
playerInputField = new TextField("Spieler "+app.getId()+1);
|
||||
playerInputField = new TextField("Spieler "+(app.getId()+1));
|
||||
// Hintergrundbild laden und hinzufügen
|
||||
addBackgroundImage();
|
||||
|
||||
@ -120,6 +120,8 @@ public class LobbyMenu extends Dialog {
|
||||
figures.add("OOP");
|
||||
figures.add("Handyholster");
|
||||
|
||||
|
||||
|
||||
Selector<String> figureDropdown = new Selector<>(figures, "glass");
|
||||
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
||||
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
|
||||
@ -128,7 +130,8 @@ public class LobbyMenu extends Dialog {
|
||||
Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize();
|
||||
dimens2.setX( dimens.getX() );
|
||||
figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5));
|
||||
|
||||
figureDropdown.getSelectionModel().setSelection(0);
|
||||
figure = "Laptop";
|
||||
|
||||
addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);
|
||||
|
||||
@ -160,6 +163,7 @@ public class LobbyMenu extends Dialog {
|
||||
readyButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
toggleReady();
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
|
||||
}));
|
||||
lowerRightMenu.addChild(readyButton);
|
||||
|
||||
@ -238,7 +242,6 @@ public class LobbyMenu extends Dialog {
|
||||
public void update(float tpf) {
|
||||
if (selectionRef.update()) {
|
||||
String selected = selectionRef.get().toString();
|
||||
System.out.println(selected);
|
||||
listener.onSelectionChanged(selected);
|
||||
}
|
||||
}
|
||||
@ -267,7 +270,6 @@ public class LobbyMenu extends Dialog {
|
||||
* Callback for when the dropdown selection changes.
|
||||
*/
|
||||
private void onDropdownSelectionChanged(String selected) {
|
||||
System.out.println("Selected: " + selected);
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
switch (selected) {
|
||||
case "[0]":
|
||||
|
@ -223,7 +223,6 @@ public class Toolbar extends Dialog implements GameEventListener{
|
||||
}
|
||||
}
|
||||
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
System.out.println("pdate");
|
||||
}
|
||||
|
||||
|
||||
@ -236,7 +235,6 @@ public class Toolbar extends Dialog implements GameEventListener{
|
||||
icon2.setIconSize(new Vector2f(100, 100));
|
||||
imageLabel.setIcon(icon1);
|
||||
imageLabel2.setIcon(icon2);
|
||||
System.out.println("Dice images set");
|
||||
}
|
||||
|
||||
private String diceToString(int i) {
|
||||
|
@ -30,6 +30,10 @@ public class TradeMenu extends Dialog {
|
||||
private final Button tradeButton = new Button("Handeln");
|
||||
private Container lowerLeftMenu, lowerRightMenu;
|
||||
private TextField leftSelectionsField;
|
||||
private TextField rightSelectionsField;
|
||||
private TextField leftCurrencyInput;
|
||||
private TextField rightCurrencyInput;
|
||||
|
||||
QuadBackgroundComponent translucentWhiteBackground =
|
||||
new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White));
|
||||
|
||||
@ -63,7 +67,7 @@ public class TradeMenu extends Dialog {
|
||||
7
|
||||
);
|
||||
}
|
||||
//TODO Logik
|
||||
|
||||
|
||||
/**
|
||||
* Creates a container for the header with a fixed size.
|
||||
@ -109,24 +113,34 @@ public class TradeMenu extends Dialog {
|
||||
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));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
addCustomSelectionListener(leftBuildingSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
||||
addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
||||
// Add change listener for the currency input
|
||||
monitorTextFieldChanges(leftCurrencyInput, () -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector));
|
||||
|
||||
Label arrows = middleSection.addChild(new Label("⇅"));
|
||||
arrows.setFontSize(40);
|
||||
|
||||
// Right Column
|
||||
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
|
||||
|
||||
|
||||
// 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..."));
|
||||
// Add the Zielobjekte TextField
|
||||
rightSelectionsField = middleSection.addChild(new TextField(""));
|
||||
rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0));
|
||||
|
||||
addCustomSelectionListener(rightBuildingSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
||||
addCustomSelectionListener(rightSpecialCardSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
||||
|
||||
// Add change listener for the currency input
|
||||
monitorTextFieldChanges(rightCurrencyInput, () -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector));
|
||||
|
||||
|
||||
// "Bestätigen" button
|
||||
lowerRightMenu = new Container();
|
||||
tradeButton.setPreferredSize(new Vector3f(200, 60, 0));
|
||||
@ -144,9 +158,6 @@ public class TradeMenu extends Dialog {
|
||||
|
||||
|
||||
|
||||
// Right Column
|
||||
mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false));
|
||||
|
||||
Label spacer = middleSection.addChild(new Label("")); // Spacer
|
||||
spacer.setPreferredSize(new Vector3f(1, 50, 0));
|
||||
|
||||
@ -189,10 +200,7 @@ public class TradeMenu extends Dialog {
|
||||
if (isLeft) {
|
||||
leftBuildingSelector = buildingSelector;
|
||||
leftSpecialCardSelector = specialCardSelector;
|
||||
|
||||
// Add listeners for left selectors to update the middle text field
|
||||
addCustomSelectionListener(buildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField));
|
||||
addCustomSelectionListener(specialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField));
|
||||
leftCurrencyInput = currencyInput;
|
||||
|
||||
// "Abbrechen" button
|
||||
lowerLeftMenu = new Container();
|
||||
@ -200,12 +208,12 @@ public class TradeMenu extends Dialog {
|
||||
cancelButton.setFontSize(30);
|
||||
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
this.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
|
||||
lowerLeftMenu.setLocalTranslation(new Vector3f(50, 100, 8)); // Adjust X and Y to align with the bottom-left corner
|
||||
app.getGuiNode().attachChild(lowerLeftMenu);
|
||||
|
||||
Label spacer = column.addChild(new Label("")); // Spacer
|
||||
@ -214,6 +222,7 @@ public class TradeMenu extends Dialog {
|
||||
} else {
|
||||
rightBuildingSelector = buildingSelector;
|
||||
rightSpecialCardSelector = specialCardSelector;
|
||||
rightCurrencyInput = currencyInput;
|
||||
|
||||
Label spacer = column.addChild(new Label("")); // Spacer
|
||||
spacer.setPreferredSize(new Vector3f(1, 130, 0));
|
||||
@ -247,26 +256,50 @@ 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()
|
||||
private String truncateText(String text, int maxLength) {
|
||||
return text.length() > maxLength ? text.substring(0, maxLength) + "..." : text;
|
||||
}
|
||||
|
||||
private void updateSelectionsField(TextField selectionsField, Selector<String> buildingSelector, TextField currencyInput, Selector<String> specialCardSelector) {
|
||||
// Get selections from the building selector
|
||||
String buildingSelections = buildingSelector != null && buildingSelector.getSelectedItem() != null
|
||||
? buildingSelector.getSelectedItem().trim()
|
||||
: "";
|
||||
|
||||
// Get the direct input from the middle part of the TextField
|
||||
String manualInput = leftSelectionsField.getText();
|
||||
// Get text from the currency input
|
||||
String currencySelections = currencyInput != null
|
||||
? currencyInput.getText().trim()
|
||||
: "";
|
||||
|
||||
// Combine all parts into one formatted string
|
||||
String combinedText = String.format("%-30s %-30s %-30s", buildingSelections, manualInput, specialCardSelections);
|
||||
// Get selections from the special card selector
|
||||
String specialCardSelections = specialCardSelector != null && specialCardSelector.getSelectedItem() != null
|
||||
? specialCardSelector.getSelectedItem().trim()
|
||||
: "";
|
||||
// Build the combined text without adding unnecessary spaces
|
||||
StringBuilder combinedText = new StringBuilder();
|
||||
|
||||
if (!buildingSelections.isEmpty()) {
|
||||
combinedText.append(buildingSelections);
|
||||
}
|
||||
if (!currencySelections.isEmpty()) {
|
||||
if (combinedText.length() > 0) {
|
||||
combinedText.append(" | "); // Add a separator if there's already text
|
||||
}
|
||||
combinedText.append(currencySelections);
|
||||
}
|
||||
if (!specialCardSelections.isEmpty()) {
|
||||
if (combinedText.length() > 0) {
|
||||
combinedText.append(" | "); // Add a separator if there's already text
|
||||
}
|
||||
combinedText.append(specialCardSelections);
|
||||
}
|
||||
|
||||
// Update the content of the TextField
|
||||
leftSelectionsField.setText(combinedText);
|
||||
selectionsField.setText(combinedText.toString());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Handles the escape action for the dialog.
|
||||
*/
|
||||
@ -321,4 +354,29 @@ public class TradeMenu extends Dialog {
|
||||
});
|
||||
}
|
||||
|
||||
private void monitorTextFieldChanges(TextField textField, Runnable onChange) {
|
||||
VersionedReference<DocumentModel> ref = textField.getDocumentModel().createReference();
|
||||
|
||||
app.getStateManager().attach(new BaseAppState() {
|
||||
@Override
|
||||
public void update(float tpf) {
|
||||
if (ref.update()) {
|
||||
onChange.run();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initialize(Application app) {}
|
||||
|
||||
@Override
|
||||
protected void cleanup(Application app) {}
|
||||
|
||||
@Override
|
||||
protected void onEnable() {}
|
||||
|
||||
@Override
|
||||
protected void onDisable() {}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -146,7 +146,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
|
||||
} else {
|
||||
clientSender.send(msg);
|
||||
System.out.println("Message gesendet");
|
||||
}
|
||||
}
|
||||
|
||||
@ -216,7 +215,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(DiceResult msg) {
|
||||
playSound(Sound.DICE_ROLL);
|
||||
System.out.println("Message kam an");
|
||||
notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1)));
|
||||
}
|
||||
|
||||
@ -344,7 +342,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(NextPlayerTurn msg) {
|
||||
|
||||
System.out.println("Du bsit am zug message empfangen");
|
||||
setState(new ActiveState(this));
|
||||
}
|
||||
}
|
||||
|
@ -395,7 +395,6 @@ public class Player implements FieldVisitor<Void>{
|
||||
* @return the result of a dice roll (1 to 6)
|
||||
*/
|
||||
private static int rollDice() {
|
||||
System.out.println("Gewuerfelt");
|
||||
return random.nextInt(6) + 1;
|
||||
}
|
||||
}
|
||||
|
@ -156,7 +156,6 @@ public class PlayerHandler {
|
||||
public Player getPlayerById(int id) {
|
||||
for (Player player : players) {
|
||||
if (player.getId() == id) return player;
|
||||
System.out.println(player.getId());
|
||||
}
|
||||
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
|
||||
}
|
||||
|
@ -132,7 +132,6 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
|
||||
playerHandler.addPlayer(player);
|
||||
LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId());
|
||||
System.out.println("Anzahl Spieler verbunden:"+ playerHandler.getPlayerCount());
|
||||
|
||||
return player;
|
||||
}
|
||||
@ -221,7 +220,6 @@ public class ServerGameLogic implements ClientInterpreter {
|
||||
public void received(RollDice msg, int from) {
|
||||
Player player = playerHandler.getPlayerById(from);
|
||||
if (player != null) {
|
||||
System.out.println("Ergebniss gesendet");
|
||||
send(player, player.rollDice());
|
||||
}
|
||||
}
|
||||
|
@ -104,10 +104,10 @@ public class TradeHandler {
|
||||
*/
|
||||
public boolean initiateTrade() {
|
||||
if (!validateTrade()) {
|
||||
System.out.println("Trade offer is invalid.");
|
||||
|
||||
return false;
|
||||
}
|
||||
System.out.println("Trade initiated by " + sender.getName() + " to " + receiver.getName());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -138,14 +138,14 @@ public class TradeHandler {
|
||||
transferJailCards(sender, receiver, offeredJailCards);
|
||||
transferJailCards(receiver, sender, requestedJailCards);
|
||||
|
||||
System.out.println("Trade completed between " + sender.getName() + " and " + receiver.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Rejects the trade.
|
||||
*/
|
||||
public void rejectTrade() {
|
||||
System.out.println(receiver.getName() + " rejected the trade.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -156,13 +156,13 @@ public class TradeHandler {
|
||||
private boolean validateTrade() {
|
||||
// Validate sender's ability to offer money
|
||||
if (sender.getAccountBalance() < offeredAmount) {
|
||||
System.out.println("Sender does not have enough money to offer.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Validate receiver's ability to fulfill the requested amount
|
||||
if (receiver.getAccountBalance() < requestedAmount) {
|
||||
System.out.println("Receiver does not have enough money to fulfill the request.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ public class TradeHandler {
|
||||
if (offeredProperties != null) {
|
||||
for (PropertyField property : offeredProperties) {
|
||||
if (!sender.getProperties().contains(property)) {
|
||||
System.out.println("Sender does not own property: " + property.getName());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -178,7 +178,7 @@ public class TradeHandler {
|
||||
if (requestedProperties != null) {
|
||||
for (PropertyField property : requestedProperties) {
|
||||
if (!receiver.getProperties().contains(property)) {
|
||||
System.out.println("Receiver does not own property: " + property.getName());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -186,11 +186,11 @@ public class TradeHandler {
|
||||
|
||||
// Validate jail cards
|
||||
if (sender.getNumJailCard() < offeredJailCards) {
|
||||
System.out.println("Sender does not have enough jail cards to offer.");
|
||||
|
||||
return false;
|
||||
}
|
||||
if (receiver.getNumJailCard() < requestedJailCards) {
|
||||
System.out.println("Receiver does not have enough jail cards to fulfill the request.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -208,7 +208,7 @@ public class TradeHandler {
|
||||
from.sellProperty(property);
|
||||
to.buyProperty(property);
|
||||
property.setOwner(to);
|
||||
System.out.println("Property " + property.getName() + " transferred from " + from.getName() + " to " + to.getName());
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -223,7 +223,7 @@ public class TradeHandler {
|
||||
from.removeJailCard();
|
||||
to.addJailCard();
|
||||
}
|
||||
System.out.println(numCards + " jail card(s) transferred from " + from.getName() + " to " + to.getName());
|
||||
|
||||
}
|
||||
|
||||
public void setOfferedAmount(int offeredAmount) {
|
||||
|
@ -147,7 +147,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
|
||||
@Override
|
||||
public void messageReceived(HostedConnection source, Message message) {
|
||||
System.out.println("Message recieved");
|
||||
LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS
|
||||
if (message instanceof ClientMessage clientMessage)
|
||||
pendingMessages.add(new ReceivedMessage(clientMessage, source.getId()));
|
||||
@ -157,7 +156,6 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
public void connectionAdded(Server server, HostedConnection hostedConnection) {
|
||||
LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS
|
||||
logic.addPlayer(hostedConnection.getId());
|
||||
System.out.println("Spieler verbunden: ID = " + hostedConnection.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user