1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-10 01:01:05 -09:00

* 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.

This commit is contained in:
LevelX2 2014-03-24 14:57:55 +01:00
parent 27d441de0a
commit c88eb2ead6
6 changed files with 72 additions and 42 deletions
Mage.Client/src/main/java/mage/client/dialog
Mage.Common/src/mage

View file

@ -246,10 +246,11 @@ public class ConnectDialog extends MageDialog {
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected())); MageFrame.getPreferences().put("autoConnect", Boolean.toString(chkAutoConnect.isSelected()));
if (task != null && !task.isDone()) if (task != null && !task.isDone()) {
task.cancel(true); task.cancel(true);
else } else {
this.hideDialog(); this.hideDialog();
}
}//GEN-LAST:event_btnCancelActionPerformed }//GEN-LAST:event_btnCancelActionPerformed
private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed

View file

@ -63,18 +63,22 @@ public class NewTableDialog extends MageDialog {
private TableView table; private TableView table;
private UUID playerId; private UUID playerId;
private UUID roomId; private UUID roomId;
private Session session; private final Session session;
private List<TablePlayerPanel> players = new ArrayList<TablePlayerPanel>(); private String lastSessionId;
private List<String> prefPlayerTypes = new ArrayList<String>(); private final List<TablePlayerPanel> players = new ArrayList<>();
private final List<String> prefPlayerTypes = new ArrayList<>();
private static final String LIMITED = "Limited"; private static final String LIMITED = "Limited";
/** Creates new form NewTableDialog */ /** Creates new form NewTableDialog */
public NewTableDialog() { public NewTableDialog() {
session = MageFrame.getSession();
lastSessionId = "";
initComponents(); initComponents();
player1Panel.showLevel(false); player1Panel.showLevel(false);
this.spnNumWins.setModel(new SpinnerNumberModel(1, 1, 5, 1)); this.spnNumWins.setModel(new SpinnerNumberModel(1, 1, 5, 1));
this.spnFreeMulligans.setModel(new SpinnerNumberModel(0, 0, 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 /** This method is called from within the constructor to
@ -391,6 +395,7 @@ public class NewTableDialog extends MageDialog {
} }
private void createPlayers(int numPlayers) { private void createPlayers(int numPlayers) {
// add missing player panels
if (numPlayers > players.size()) { if (numPlayers > players.size()) {
while (players.size() != numPlayers) { while (players.size() != numPlayers) {
TablePlayerPanel playerPanel = new TablePlayerPanel(); TablePlayerPanel playerPanel = new TablePlayerPanel();
@ -409,7 +414,9 @@ public class NewTableDialog extends MageDialog {
} }
); );
} }
}
}
// remove player panels no longer needed
else if (numPlayers < players.size()) { else if (numPlayers < players.size()) {
while (players.size() != numPlayers) { while (players.size() != numPlayers) {
players.remove(players.size() - 1); players.remove(players.size() - 1);
@ -435,22 +442,26 @@ public class NewTableDialog extends MageDialog {
} }
public void showDialog(UUID roomId) { public void showDialog(UUID roomId) {
session = MageFrame.getSession(); this.roomId = roomId;
MageFrame.getUI().addButton(MageComponents.NEW_TABLE_OK_BUTTON, btnOK); if (!lastSessionId.equals(MageFrame.getSession().getSessionId())) {
this.player1Panel.setPlayerName(session.getUserName()); lastSessionId = session.getSessionId();
cbGameType.setModel(new DefaultComboBoxModel(session.getGameTypes().toArray())); this.player1Panel.setPlayerName(session.getUserName());
cbDeckType.setModel(new DefaultComboBoxModel(session.getDeckTypes())); cbGameType.setModel(new DefaultComboBoxModel(session.getGameTypes().toArray()));
selectLimitedByDefault(); cbDeckType.setModel(new DefaultComboBoxModel(session.getDeckTypes()));
cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values())); selectLimitedByDefault();
cbRange.setModel(new DefaultComboBoxModel(RangeOfInfluence.values())); cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values()));
cbAttackOption.setModel(new DefaultComboBoxModel(MultiplayerAttackOption.values())); cbRange.setModel(new DefaultComboBoxModel(RangeOfInfluence.values()));
cbAttackOption.setModel(new DefaultComboBoxModel(MultiplayerAttackOption.values()));
setGameSettingsFromPrefs(); // Update the existing player panels (neccessary if server was changes = new session)
int i=2;
this.roomId = roomId; for (TablePlayerPanel tablePlayerPanel :players) {
this.setModal(true); tablePlayerPanel.init(i++, tablePlayerPanel.getPlayerType());
setGameOptions(); }
this.setLocation(150, 100); setGameSettingsFromPrefs();
this.setModal(true);
setGameOptions();
this.setLocation(150, 100);
}
this.setVisible(true); this.setVisible(true);
} }

View file

@ -45,6 +45,7 @@ import javax.swing.SpinnerNumberModel;
import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository; import mage.cards.repository.ExpansionRepository;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.table.TablePlayerPanel;
import mage.client.table.TournamentPlayerPanel; import mage.client.table.TournamentPlayerPanel;
import mage.constants.MatchTimeLimit; import mage.constants.MatchTimeLimit;
import mage.constants.MultiplayerAttackOption; import mage.constants.MultiplayerAttackOption;
@ -71,12 +72,15 @@ public class NewTournamentDialog extends MageDialog {
private UUID playerId; private UUID playerId;
private UUID roomId; private UUID roomId;
private Session session; private Session session;
private String lastSessionId;
private final List<TournamentPlayerPanel> players = new ArrayList<>(); private final List<TournamentPlayerPanel> players = new ArrayList<>();
private final List<JComboBox> packs = new ArrayList<>(); private final List<JComboBox> packs = new ArrayList<>();
/** Creates new form NewTournamentDialog */ /** Creates new form NewTournamentDialog */
public NewTournamentDialog() { public NewTournamentDialog() {
initComponents(); initComponents();
session = MageFrame.getSession();
lastSessionId = "";
txtName.setText("Tournament"); txtName.setText("Tournament");
this.spnNumWins.setModel(new SpinnerNumberModel(2, 1, 5, 1)); this.spnNumWins.setModel(new SpinnerNumberModel(2, 1, 5, 1));
this.spnFreeMulligans.setModel(new SpinnerNumberModel(0, 0, 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) { public void showDialog(UUID roomId) {
this.roomId = roomId; this.roomId = roomId;
session = MageFrame.getSession(); if (!lastSessionId.equals(MageFrame.getSession().getSessionId())) {
this.txtPlayer1Name.setText(session.getUserName()); lastSessionId = session.getSessionId();
cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray())); this.txtPlayer1Name.setText(session.getUserName());
cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values())); cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray()));
cbDraftCube.setModel(new DefaultComboBoxModel(session.getDraftCubes())); cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values()));
cbDraftTiming.setModel(new DefaultComboBoxModel(DraftOptions.TimingOption.values())); cbDraftCube.setModel(new DefaultComboBoxModel(session.getDraftCubes()));
cbAllowSpectators.setSelected(true); cbDraftTiming.setModel(new DefaultComboBoxModel(DraftOptions.TimingOption.values()));
// update player types
setTournamentSettingsFromPrefs(); int i=2;
for (TournamentPlayerPanel tournamentPlayerPanel :players) {
this.setModal(true); tournamentPlayerPanel.init(i++);
this.setLocation(150, 100); }
cbAllowSpectators.setSelected(true);
setTournamentSettingsFromPrefs();
this.setModal(true);
this.setLocation(150, 100);
}
this.setVisible(true); this.setVisible(true);
} }
@ -574,6 +583,7 @@ public class NewTournamentDialog extends MageDialog {
} }
private void createPlayers(int numPlayers) { private void createPlayers(int numPlayers) {
// add/remove player panels
if (numPlayers > players.size()) { if (numPlayers > players.size()) {
while (players.size() != numPlayers) { while (players.size() != numPlayers) {
TournamentPlayerPanel playerPanel = new TournamentPlayerPanel(); TournamentPlayerPanel playerPanel = new TournamentPlayerPanel();

View file

@ -109,6 +109,11 @@ public class SessionImpl implements Session {
this.client = client; this.client = client;
} }
@Override
public String getSessionId() {
return sessionId;
}
@Override @Override
public synchronized boolean connect(Connection connection) { public synchronized boolean connect(Connection connection) {
if (isConnected()) { if (isConnected()) {

View file

@ -27,6 +27,7 @@
*/ */
package mage.remote.interfaces; package mage.remote.interfaces;
import java.util.UUID;
import mage.remote.Connection; import mage.remote.Connection;
/** /**
@ -47,4 +48,6 @@ public interface Connect {
boolean isConnected(); boolean isConnected();
boolean disconnectUser(String userSessionId); boolean disconnectUser(String userSessionId);
String getSessionId();
} }

View file

@ -35,16 +35,16 @@ import mage.game.match.MatchType;
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class GameTypeView implements Serializable { public class GameTypeView extends Object implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String name; private final String name;
private int minPlayers; private final int minPlayers;
private int maxPlayers; private final int maxPlayers;
private int numTeams; private final int numTeams;
private int playersPerTeam; private final int playersPerTeam;
private boolean useRange; private final boolean useRange;
private boolean useAttackOption; private final boolean useAttackOption;
public GameTypeView(MatchType gameType) { public GameTypeView(MatchType gameType) {
this.name = gameType.getName(); this.name = gameType.getName();