From c88eb2ead63ef7f57daa5ddd22c082af7eaffe68 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Mon, 24 Mar 2014 14:57:55 +0100 Subject: [PATCH] * Player types - If you connect to another MAGE server, the available player types are updated now correctly. Removed some redundant update of server information in client. --- .../mage/client/dialog/ConnectDialog.java | 5 +- .../mage/client/dialog/NewTableDialog.java | 51 +++++++++++-------- .../client/dialog/NewTournamentDialog.java | 34 ++++++++----- Mage.Common/src/mage/remote/SessionImpl.java | 5 ++ .../src/mage/remote/interfaces/Connect.java | 3 ++ Mage.Common/src/mage/view/GameTypeView.java | 16 +++--- 6 files changed, 72 insertions(+), 42 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java b/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java index 48e69336be..bc3e583884 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java @@ -246,10 +246,11 @@ public class ConnectDialog extends MageDialog { private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected())); - if (task != null && !task.isDone()) + if (task != null && !task.isDone()) { task.cancel(true); - else + } else { this.hideDialog(); + } }//GEN-LAST:event_btnCancelActionPerformed private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java index 001eb69d55..29af39e8a4 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java @@ -63,18 +63,22 @@ public class NewTableDialog extends MageDialog { private TableView table; private UUID playerId; private UUID roomId; - private Session session; - private List players = new ArrayList(); - private List prefPlayerTypes = new ArrayList(); + private final Session session; + private String lastSessionId; + private final List players = new ArrayList<>(); + private final List prefPlayerTypes = new ArrayList<>(); private static final String LIMITED = "Limited"; /** Creates new form NewTableDialog */ public NewTableDialog() { + session = MageFrame.getSession(); + lastSessionId = ""; initComponents(); player1Panel.showLevel(false); this.spnNumWins.setModel(new SpinnerNumberModel(1, 1, 5, 1)); this.spnFreeMulligans.setModel(new SpinnerNumberModel(0, 0, 5, 1)); + MageFrame.getUI().addButton(MageComponents.NEW_TABLE_OK_BUTTON, btnOK); } /** This method is called from within the constructor to @@ -391,6 +395,7 @@ public class NewTableDialog extends MageDialog { } private void createPlayers(int numPlayers) { + // add missing player panels if (numPlayers > players.size()) { while (players.size() != numPlayers) { TablePlayerPanel playerPanel = new TablePlayerPanel(); @@ -409,7 +414,9 @@ public class NewTableDialog extends MageDialog { } ); } - } + + } + // remove player panels no longer needed else if (numPlayers < players.size()) { while (players.size() != numPlayers) { players.remove(players.size() - 1); @@ -435,22 +442,26 @@ public class NewTableDialog extends MageDialog { } public void showDialog(UUID roomId) { - session = MageFrame.getSession(); - MageFrame.getUI().addButton(MageComponents.NEW_TABLE_OK_BUTTON, btnOK); - this.player1Panel.setPlayerName(session.getUserName()); - cbGameType.setModel(new DefaultComboBoxModel(session.getGameTypes().toArray())); - cbDeckType.setModel(new DefaultComboBoxModel(session.getDeckTypes())); - selectLimitedByDefault(); - cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values())); - cbRange.setModel(new DefaultComboBoxModel(RangeOfInfluence.values())); - cbAttackOption.setModel(new DefaultComboBoxModel(MultiplayerAttackOption.values())); - - setGameSettingsFromPrefs(); - - this.roomId = roomId; - this.setModal(true); - setGameOptions(); - this.setLocation(150, 100); + this.roomId = roomId; + if (!lastSessionId.equals(MageFrame.getSession().getSessionId())) { + lastSessionId = session.getSessionId(); + this.player1Panel.setPlayerName(session.getUserName()); + cbGameType.setModel(new DefaultComboBoxModel(session.getGameTypes().toArray())); + cbDeckType.setModel(new DefaultComboBoxModel(session.getDeckTypes())); + selectLimitedByDefault(); + cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values())); + cbRange.setModel(new DefaultComboBoxModel(RangeOfInfluence.values())); + cbAttackOption.setModel(new DefaultComboBoxModel(MultiplayerAttackOption.values())); + // Update the existing player panels (neccessary if server was changes = new session) + int i=2; + for (TablePlayerPanel tablePlayerPanel :players) { + tablePlayerPanel.init(i++, tablePlayerPanel.getPlayerType()); + } + setGameSettingsFromPrefs(); + this.setModal(true); + setGameOptions(); + this.setLocation(150, 100); + } this.setVisible(true); } diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java index d850cb210e..0ac337d9ae 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -45,6 +45,7 @@ import javax.swing.SpinnerNumberModel; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; import mage.client.MageFrame; +import mage.client.table.TablePlayerPanel; import mage.client.table.TournamentPlayerPanel; import mage.constants.MatchTimeLimit; import mage.constants.MultiplayerAttackOption; @@ -71,12 +72,15 @@ public class NewTournamentDialog extends MageDialog { private UUID playerId; private UUID roomId; private Session session; + private String lastSessionId; private final List players = new ArrayList<>(); private final List packs = new ArrayList<>(); /** Creates new form NewTournamentDialog */ public NewTournamentDialog() { initComponents(); + session = MageFrame.getSession(); + lastSessionId = ""; txtName.setText("Tournament"); this.spnNumWins.setModel(new SpinnerNumberModel(2, 1, 5, 1)); this.spnFreeMulligans.setModel(new SpinnerNumberModel(0, 0, 5, 1)); @@ -86,18 +90,23 @@ public class NewTournamentDialog extends MageDialog { public void showDialog(UUID roomId) { this.roomId = roomId; - session = MageFrame.getSession(); - this.txtPlayer1Name.setText(session.getUserName()); - cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray())); - cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values())); - cbDraftCube.setModel(new DefaultComboBoxModel(session.getDraftCubes())); - cbDraftTiming.setModel(new DefaultComboBoxModel(DraftOptions.TimingOption.values())); - cbAllowSpectators.setSelected(true); - - setTournamentSettingsFromPrefs(); - - this.setModal(true); - this.setLocation(150, 100); + if (!lastSessionId.equals(MageFrame.getSession().getSessionId())) { + lastSessionId = session.getSessionId(); + this.txtPlayer1Name.setText(session.getUserName()); + cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray())); + cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values())); + cbDraftCube.setModel(new DefaultComboBoxModel(session.getDraftCubes())); + cbDraftTiming.setModel(new DefaultComboBoxModel(DraftOptions.TimingOption.values())); + // update player types + int i=2; + for (TournamentPlayerPanel tournamentPlayerPanel :players) { + tournamentPlayerPanel.init(i++); + } + cbAllowSpectators.setSelected(true); + setTournamentSettingsFromPrefs(); + this.setModal(true); + this.setLocation(150, 100); + } this.setVisible(true); } @@ -574,6 +583,7 @@ public class NewTournamentDialog extends MageDialog { } private void createPlayers(int numPlayers) { + // add/remove player panels if (numPlayers > players.size()) { while (players.size() != numPlayers) { TournamentPlayerPanel playerPanel = new TournamentPlayerPanel(); diff --git a/Mage.Common/src/mage/remote/SessionImpl.java b/Mage.Common/src/mage/remote/SessionImpl.java index 08569415d8..13dd76e11d 100644 --- a/Mage.Common/src/mage/remote/SessionImpl.java +++ b/Mage.Common/src/mage/remote/SessionImpl.java @@ -109,6 +109,11 @@ public class SessionImpl implements Session { this.client = client; } + @Override + public String getSessionId() { + return sessionId; + } + @Override public synchronized boolean connect(Connection connection) { if (isConnected()) { diff --git a/Mage.Common/src/mage/remote/interfaces/Connect.java b/Mage.Common/src/mage/remote/interfaces/Connect.java index b21a435c1a..da736cd578 100644 --- a/Mage.Common/src/mage/remote/interfaces/Connect.java +++ b/Mage.Common/src/mage/remote/interfaces/Connect.java @@ -27,6 +27,7 @@ */ package mage.remote.interfaces; +import java.util.UUID; import mage.remote.Connection; /** @@ -47,4 +48,6 @@ public interface Connect { boolean isConnected(); boolean disconnectUser(String userSessionId); + + String getSessionId(); } diff --git a/Mage.Common/src/mage/view/GameTypeView.java b/Mage.Common/src/mage/view/GameTypeView.java index 293d041967..49c3c58149 100644 --- a/Mage.Common/src/mage/view/GameTypeView.java +++ b/Mage.Common/src/mage/view/GameTypeView.java @@ -35,16 +35,16 @@ import mage.game.match.MatchType; * * @author BetaSteward_at_googlemail.com */ -public class GameTypeView implements Serializable { +public class GameTypeView extends Object implements Serializable { private static final long serialVersionUID = 1L; - private String name; - private int minPlayers; - private int maxPlayers; - private int numTeams; - private int playersPerTeam; - private boolean useRange; - private boolean useAttackOption; + private final String name; + private final int minPlayers; + private final int maxPlayers; + private final int numTeams; + private final int playersPerTeam; + private final boolean useRange; + private final boolean useAttackOption; public GameTypeView(MatchType gameType) { this.name = gameType.getName();