* GUI: fixed random/richman tourney settings that allows to freeze the client (#8224);

This commit is contained in:
Oleg Agafonov 2023-03-17 23:04:11 +04:00
parent 0bcf0320d0
commit 00ebef654f
2 changed files with 23 additions and 20 deletions

View file

@ -680,8 +680,13 @@ public class NewTournamentDialog extends MageDialog {
// CHECKS
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
if (tournamentType.isRandom() || tournamentType.isRichMan()) {
if (tOptions.getLimitedOptions().getSetCodes().isEmpty()) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Warning, you must select packs for the pool", "Warning", JOptionPane.WARNING_MESSAGE);
if (tOptions.getLimitedOptions().getSetCodes().size() < tournamentType.getNumBoosters()) {
JOptionPane.showMessageDialog(
MageFrame.getDesktop(),
String.format("Warning, you must select %d packs for the pool", tournamentType.getNumBoosters()),
"Warning",
JOptionPane.WARNING_MESSAGE
);
return;
}
}
@ -1013,7 +1018,7 @@ public class NewTournamentDialog extends MageDialog {
private void createRandomPacks() {
if (pnlRandomPacks.getComponentCount() == 0) {
if (randomPackSelector == null) {
randomPackSelector = new RandomPacksSelectorDialog(isRandom, isRichMan);
randomPackSelector = new RandomPacksSelectorDialog();
randomPackSelector.setLocationRelativeTo(this);
}
txtRandomPacks = new JTextArea();
@ -1039,8 +1044,8 @@ public class NewTournamentDialog extends MageDialog {
}
private void showRandomPackSelectorDialog() {
randomPackSelector.setType(isRandom, isRichMan);
randomPackSelector.showDialog();
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
randomPackSelector.showDialog(isRandom, isRichMan, tournamentType.getNumBoosters());
this.txtRandomPacks.setText(String.join(";", randomPackSelector.getSelectedPacks()));
this.pack();
this.revalidate();

View file

@ -18,31 +18,31 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
* Creates new form RandomPacksSelectorDialog
*/
private boolean boxesCreated;
private boolean isRandomDraft;
private boolean isRichManDraft;
private String title = "";
private int needSetsAmount;
public static final String randomDraftDescription = ("The selected packs will be randomly distributed to players. Each player may open different packs. Duplicates will be avoided.");
public RandomPacksSelectorDialog(boolean isRandomDraft, boolean isRichManDraft) {
public RandomPacksSelectorDialog() {
initComponents();
setType(isRandomDraft, isRichManDraft);
this.pnlApply.setToolTipText(randomDraftDescription);
this.pnlSelect.setToolTipText(randomDraftDescription);
boxesCreated = false;
}
public void setType(boolean isRandomDraft, boolean isRichManDraft) {
this.isRandomDraft = isRandomDraft;
this.isRichManDraft = isRichManDraft;
if (this.isRandomDraft) {
private void setType(boolean isRandomDraft, boolean isRichManDraft, int needSetsAmount) {
this.needSetsAmount = needSetsAmount;
String title = "";
if (isRandomDraft) {
title = "Random Booster Draft Packs Selector";
} else if (this.isRichManDraft) {
} else if (isRichManDraft) {
title = "Rich Man Booster Draft Packs Selector";
} else {
title = "Booster Draft Packs Selector";
}
setTitle(title);
}
public void showDialog() {
public void showDialog(boolean isRandomDraft, boolean isRichManDraft, int needSetsAmount) {
setType(isRandomDraft, isRichManDraft, needSetsAmount);
createCheckboxes();
pnlPacks.setVisible(true);
pnlPacks.revalidate();
@ -204,10 +204,8 @@ public class RandomPacksSelectorDialog extends javax.swing.JDialog {
}//GEN-LAST:event_formWindowClosing
public void doApply() {
if (getSelectedPacks().size() < 2 && isRandomDraft) {
JOptionPane.showMessageDialog(this, "At least 2 sets must be selected", "Error", JOptionPane.ERROR_MESSAGE);
} else if (getSelectedPacks().isEmpty() && isRichManDraft) {
JOptionPane.showMessageDialog(this, "At least 1 set must be selected", "Error", JOptionPane.ERROR_MESSAGE);
if (getSelectedPacks().size() < needSetsAmount) {
JOptionPane.showMessageDialog(this, String.format("At least %d sets must be selected", needSetsAmount), "Error", JOptionPane.ERROR_MESSAGE);
} else {
this.setVisible(false);
}