* Create tournament dialog - Set min number of swiss rounds in relation to number of players.

This commit is contained in:
LevelX2 2014-10-29 17:20:10 +01:00
parent d8d25dc00a
commit ab9c0ae893

View file

@ -41,6 +41,7 @@ import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel; import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox; import javax.swing.JComboBox;
import javax.swing.JOptionPane; import javax.swing.JOptionPane;
import javax.swing.SpinnerModel;
import javax.swing.SpinnerNumberModel; import javax.swing.SpinnerNumberModel;
import mage.cards.decks.importer.DeckImporterUtil; import mage.cards.decks.importer.DeckImporterUtil;
import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionInfo;
@ -594,23 +595,33 @@ public class NewTournamentDialog extends MageDialog {
// this.cbRange.setEnabled(gameType.isUseRange()); // this.cbRange.setEnabled(gameType.isUseRange());
createPlayers((Integer) spnNumPlayers.getValue() - 1); createPlayers((Integer) spnNumPlayers.getValue() - 1);
} }
private void setTournamentOptions(int numbPlayers) { private void setTournamentOptions(int numPlayers) {
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem(); TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
activatePanelElements(tournamentType); activatePanelElements(tournamentType);
if (numbPlayers < tournamentType.getMinPlayers() || numbPlayers > tournamentType.getMaxPlayers()) { if (numPlayers < tournamentType.getMinPlayers() || numPlayers > tournamentType.getMaxPlayers()) {
numbPlayers = tournamentType.getMinPlayers(); numPlayers = tournamentType.getMinPlayers();
createPlayers(numbPlayers - 1); createPlayers(numPlayers - 1);
} }
this.spnNumPlayers.setModel(new SpinnerNumberModel(numbPlayers, tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1)); this.spnNumPlayers.setModel(new SpinnerNumberModel(numPlayers, tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers()); this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
createPlayers((Integer) spnNumPlayers.getValue() - 1);
if (tournamentType.isLimited()) { if (tournamentType.isLimited()) {
createPacks(tournamentType.getNumBoosters()); createPacks(tournamentType.getNumBoosters());
} }
} }
private void setNumberOfSwissRoundsMin(int numPlayers) {
// set the number of minimum swiss rounds related to the number of players
int minRounds = (int) Math.ceil(Math.log(numPlayers + 1) / Math.log(2));
int newValue = Math.max((Integer)spnNumRounds.getValue(), minRounds);
this.spnNumRounds.setModel(new SpinnerNumberModel(newValue, minRounds, 10, 1));
this.pack();
this.revalidate();
this.repaint();
}
/** /**
* Sets elements of the panel to visible or not visible * Sets elements of the panel to visible or not visible
* *
@ -705,6 +716,9 @@ public class NewTournamentDialog extends MageDialog {
} }
} }
drawPlayers(); drawPlayers();
setNumberOfSwissRoundsMin(numPlayers);
} }
private void drawPlayers() { private void drawPlayers() {