GUI, table: improved save/load table config to support player types, AI skill level and deck files (closes #12981)

This commit is contained in:
Oleg Agafonov 2024-10-11 17:09:15 +04:00
parent f652665f87
commit 3475249c99
4 changed files with 100 additions and 32 deletions

View file

@ -18,16 +18,12 @@ public class TablePlayerPanel extends javax.swing.JPanel {
protected final PlayerTypeEventSource playerTypeEventSource = new PlayerTypeEventSource();
/**
* Creates new form TablePlayerPanel
*/
public TablePlayerPanel() {
initComponents();
this.newPlayerPanel.setVisible(false);
}
public void init(int playerNum, PlayerType playerType) {
public void init(int playerNum, PlayerType playerType, int playerSkill, String playerDeck) {
cbPlayerType.setModel(new DefaultComboBoxModel(SessionHandler.getPlayerTypes()));
this.lblPlayerNum.setText("Player " + playerNum);
if (ClientDefaultSettings.otherPlayerIndex != null) {
@ -41,11 +37,14 @@ public class TablePlayerPanel extends javax.swing.JPanel {
if (playerType != null) {
this.cbPlayerType.setSelectedItem(playerType);
}
this.newPlayerPanel.setDeckFile(playerDeck);
this.newPlayerPanel.setSkillLevel(playerSkill);
}
public boolean joinTable(UUID roomId, UUID tableId) throws IOException, ClassNotFoundException {
if (this.cbPlayerType.getSelectedItem() != PlayerType.HUMAN) {
return SessionHandler.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), (PlayerType) this.cbPlayerType.getSelectedItem(), this.newPlayerPanel.getLevel(), DeckImporter.importDeckFromFile(this.newPlayerPanel.getDeckFile(), true), "");
return SessionHandler.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), (PlayerType) this.cbPlayerType.getSelectedItem(), this.newPlayerPanel.getSkillLevel(), DeckImporter.importDeckFromFile(this.newPlayerPanel.getDeckFile(), true), "");
}
return true;
}
@ -54,6 +53,14 @@ public class TablePlayerPanel extends javax.swing.JPanel {
return PlayerType.getByDescription(this.cbPlayerType.getSelectedItem().toString());
}
public int getPlayerSkill() {
return newPlayerPanel.getSkillLevel();
}
public String getPlayerDeck() {
return newPlayerPanel.getDeckFile();
}
public void addPlayerTypeEventListener(Listener<Event> listener) {
playerTypeEventSource.addListener(listener);
}