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 72ae40ffa8..440b41853d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTournamentDialog.java @@ -31,10 +31,10 @@ * * Created on Jan 28, 2011, 12:15:56 PM */ - package mage.client.dialog; import java.awt.Component; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -44,9 +44,11 @@ import javax.swing.ComboBoxModel; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; +import javax.swing.JFileChooser; import javax.swing.JOptionPane; import javax.swing.JTextArea; import javax.swing.SpinnerNumberModel; +import javax.swing.filechooser.FileFilter; import mage.cards.decks.importer.DeckImporterUtil; import mage.cards.repository.ExpansionInfo; import mage.cards.repository.ExpansionRepository; @@ -66,7 +68,6 @@ import mage.view.TableView; import mage.view.TournamentTypeView; import org.apache.log4j.Logger; - /** * * @author BetaSteward_at_googlemail.com @@ -88,7 +89,7 @@ public class NewTournamentDialog extends MageDialog { private final int CONSTRUCTION_TIME_MAX = 30; private boolean isRandom = false; private boolean isRichMan = false; - + private String cubeFromDeckFilename = ""; private boolean automaticChange = false; /** Creates new form NewTournamentDialog */ @@ -557,6 +558,9 @@ public class NewTournamentDialog extends MageDialog { tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom()); if (tournamentType.isCubeBooster()) { tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString()); + if (!(cubeFromDeckFilename.equals(""))) { + tOptions.getLimitedOptions().setCubeFromDeckFilename(cubeFromDeckFilename); + } } else if (tournamentType.isRandom() || tournamentType.isRichMan()) { this.isRandom = tournamentType.isRandom(); this.isRichMan = tournamentType.isRichMan(); @@ -649,8 +653,32 @@ public class NewTournamentDialog extends MageDialog { // TODO add your handling code here: }//GEN-LAST:event_spnNumWinsnumPlayersChanged + private JFileChooser fcSelectDeck = null; + + protected String playerLoadDeck() { + if (fcSelectDeck == null) { + fcSelectDeck = new JFileChooser(); + fcSelectDeck.setAcceptAllFileFilterUsed(false); + fcSelectDeck.addChoosableFileFilter(new DeckFilter()); + } + String lastFolder = MageFrame.getPreferences().get("lastDeckFolder", ""); + if (!lastFolder.isEmpty()) { + fcSelectDeck.setCurrentDirectory(new File(lastFolder)); + } + int ret = fcSelectDeck.showDialog(this, "Select Deck"); + if (ret == JFileChooser.APPROVE_OPTION) { + File file = fcSelectDeck.getSelectedFile(); + return (file.getPath()); + } + return ""; + } + + private void cbDraftCubeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDraftCubeActionPerformed - // TODO add your handling code here: + cubeFromDeckFilename = ""; + if (cbDraftCube.getSelectedItem().toString().equals("Cube From Deck")) { + cubeFromDeckFilename = playerLoadDeck(); + } }//GEN-LAST:event_cbDraftCubeActionPerformed private void cbDraftTimingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDraftTimingActionPerformed @@ -676,6 +704,7 @@ public class NewTournamentDialog extends MageDialog { // this.cbRange.setEnabled(gameType.isUseRange()); createPlayers((Integer) spnNumPlayers.getValue() - 1); } + private void setTournamentOptions(int numPlayers) { TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem(); activatePanelElements(tournamentType); @@ -709,6 +738,7 @@ public class NewTournamentDialog extends MageDialog { this.revalidate(); this.repaint(); } + /** * Sets elements of the panel to visible or not visible * @@ -911,7 +941,6 @@ public class NewTournamentDialog extends MageDialog { automaticChange = false; } - /** * set the tournament settings from java prefs */ @@ -1053,7 +1082,6 @@ public class NewTournamentDialog extends MageDialog { PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_RATED, (tOptions.getMatchOptions().isRated() ? "Yes" : "No")); } - public TableView getTable() { return table; } @@ -1106,4 +1134,28 @@ public class NewTournamentDialog extends MageDialog { private org.jdesktop.beansbinding.BindingGroup bindingGroup; // End of variables declaration//GEN-END:variables -} +} + +class DeckFilter extends FileFilter { + + @Override + public boolean accept(File f) { + if (f.isDirectory()) { + return true; + } + + String ext = null; + String s = f.getName(); + int i = s.lastIndexOf('.'); + + if (i > 0 && i < s.length() - 1) { + ext = s.substring(i + 1).toLowerCase(); + } + return (ext == null) ? false : ext.equals("dck"); + } + + @Override + public String getDescription() { + return "Deck Files"; + } +} diff --git a/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java new file mode 100644 index 0000000000..2d55daa72e --- /dev/null +++ b/Mage.Server.Plugins/Mage.Tournament.BoosterDraft/src/mage/tournament/cubes/CubeFromDeck.java @@ -0,0 +1,53 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.tournament.cubes; + +import mage.cards.decks.DeckCardInfo; +import mage.cards.decks.DeckCardLists; +import mage.cards.decks.importer.DeckImporterUtil; +import mage.game.draft.DraftCube.CardIdentity; +import mage.game.draft.DraftCube; + +/** + * + * @author spjspj + */ +public class CubeFromDeck extends DraftCube { + + public CubeFromDeck(String chosenDckFile) { + super("Cube From Deck"); + + DeckCardLists cards = DeckImporterUtil.importDeck(chosenDckFile); + + if (cards != null) { + for (DeckCardInfo card : cards.getCards()) { + cubeCards.add(new CardIdentity(card.getCardName(), card.getSetCode())); + } + } + } +} diff --git a/Mage.Server/config/config.xml b/Mage.Server/config/config.xml index b211ab08a1..1a93d7eda8 100644 --- a/Mage.Server/config/config.xml +++ b/Mage.Server/config/config.xml @@ -110,6 +110,7 @@ + diff --git a/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java b/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java index 91c046c464..ca1e2dd9c8 100644 --- a/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java +++ b/Mage.Server/src/main/java/mage/server/draft/CubeFactory.java @@ -67,6 +67,22 @@ public class CubeFactory { return draftCube; } + public DraftCube createDeckDraftCube(String draftCubeName, String chosenDckFile) { + + DraftCube draftCube; + Constructor con; + try { + con = draftCubes.get(draftCubeName).getConstructor(new Class[]{String.class}); + draftCube = (DraftCube)con.newInstance(new Object[] {chosenDckFile}); + } catch (Exception ex) { + logger.fatal("CubeFactory error", ex); + return null; + } + logger.debug("Draft cube created: " + draftCube.getName()); + + return draftCube; + } + public Set getDraftCubes() { return draftCubes.keySet(); } diff --git a/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java b/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java index 9575acc3bb..32ce0dbb97 100644 --- a/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java +++ b/Mage.Server/src/main/java/mage/server/tournament/TournamentFactory.java @@ -1,16 +1,16 @@ /* * Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * + * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * + * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * + * * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR @@ -20,7 +20,7 @@ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. @@ -35,6 +35,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import mage.cards.Sets; +import mage.game.draft.DraftCube; import mage.game.tournament.Tournament; import mage.game.tournament.TournamentOptions; import mage.game.tournament.TournamentType; @@ -78,7 +79,14 @@ public class TournamentFactory { } tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters()); if (tournament.getTournamentType().isCubeBooster()) { - tournament.getOptions().getLimitedOptions().setDraftCube(CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName())); + DraftCube draftCube = null; + + if (tournament.getOptions().getLimitedOptions().getCubeFromDeckFilename().length() != 0) { + draftCube = CubeFactory.getInstance().createDeckDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName(), tournament.getOptions().getLimitedOptions().getCubeFromDeckFilename()); + } else { + draftCube = CubeFactory.getInstance().createDraftCube(tournament.getOptions().getLimitedOptions().getDraftCubeName()); + } + tournament.getOptions().getLimitedOptions().setDraftCube(draftCube); tournament.setBoosterInfo(tournament.getOptions().getLimitedOptions().getDraftCubeName()); } else if (tournament.getTournamentType().isRandom()) { StringBuilder rv = new StringBuilder( "Random Draft using sets: "); diff --git a/Mage/src/main/java/mage/game/tournament/LimitedOptions.java b/Mage/src/main/java/mage/game/tournament/LimitedOptions.java index 1d65ef1217..9845e420f3 100644 --- a/Mage/src/main/java/mage/game/tournament/LimitedOptions.java +++ b/Mage/src/main/java/mage/game/tournament/LimitedOptions.java @@ -45,6 +45,7 @@ public class LimitedOptions implements Serializable { protected DraftCube draftCube; protected int numberBoosters; protected boolean isRandom; + protected String cubeFromDeckFilename = ""; public List getSetCodes() { return sets; @@ -66,6 +67,14 @@ public class LimitedOptions implements Serializable { this.draftCubeName = draftCubeName; } + public void setCubeFromDeckFilename(String cubeFromDeckFilename) { + this.cubeFromDeckFilename = cubeFromDeckFilename; + } + + public String getCubeFromDeckFilename() { + return cubeFromDeckFilename; + } + public DraftCube getDraftCube() { return draftCube; } @@ -88,4 +97,5 @@ public class LimitedOptions implements Serializable { public void setIsRandom(boolean isRandom){ this.isRandom = isRandom; } + }