promote gui
This commit is contained in:
@@ -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));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user