From 00ebef654fdd2f787a1fdd4aabd5af7708f5017b Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Fri, 17 Mar 2023 23:04:11 +0400 Subject: [PATCH] * GUI: fixed random/richman tourney settings that allows to freeze the client (#8224); --- .../client/dialog/NewTournamentDialog.java | 15 ++++++---- .../dialog/RandomPacksSelectorDialog.java | 28 +++++++++---------- 2 files changed, 23 insertions(+), 20 deletions(-) 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 cb186e4886..065723c0f5 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -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(); diff --git a/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java b/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java index 2f90a66837..be57cebc55 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/RandomPacksSelectorDialog.java @@ -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); }