promote gui

This commit is contained in:
2025-04-03 22:06:34 +02:00
parent 927ba129f6
commit 0d72e015f1
5 changed files with 91 additions and 15 deletions

View File

@@ -196,7 +196,42 @@ public class Window extends JFrame implements OutputSystem {
@Override
public void promotePawn(Coordinate pieceCoords) {
sendCommand(new PromoteCommand(PromoteType.Queen, pieceCoords));
SwingUtilities.invokeLater(() -> {
// String result = JOptionPane.showInputDialog(this, "Choisissez le type !");
// sendCommand(new PromoteCommand(PromoteType.Queen, pieceCoords));
String result = null;
Object[] possibilities = new Object[PromoteType.values().length];
int i = 0;
for (PromoteType type : PromoteType.values()) {
possibilities[i] = type.name();
i++;
}
while (result == null || result.isEmpty()) {
result = (String) JOptionPane.showInputDialog(
this,
"Choose the type of piece to upgrade the pawn",
"Promote Dialog",
JOptionPane.PLAIN_MESSAGE,
null,
possibilities,
possibilities[0]);
}
PromoteType choosedType = null;
for (PromoteType type : PromoteType.values()) {
if (type.name().equals(result)) {
choosedType = type;
break;
}
}
if (choosedType != null)
sendCommand(new PromoteCommand(choosedType, pieceCoords));
});
}
}