mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
spjspj - Add the option of having a .dck file as a cube
This commit is contained in:
parent
548b05ba74
commit
26d38f0773
6 changed files with 153 additions and 13 deletions
|
@ -31,10 +31,10 @@
|
||||||
*
|
*
|
||||||
* Created on Jan 28, 2011, 12:15:56 PM
|
* Created on Jan 28, 2011, 12:15:56 PM
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package mage.client.dialog;
|
package mage.client.dialog;
|
||||||
|
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -44,9 +44,11 @@ import javax.swing.ComboBoxModel;
|
||||||
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JComboBox;
|
import javax.swing.JComboBox;
|
||||||
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.SpinnerNumberModel;
|
import javax.swing.SpinnerNumberModel;
|
||||||
|
import javax.swing.filechooser.FileFilter;
|
||||||
import mage.cards.decks.importer.DeckImporterUtil;
|
import mage.cards.decks.importer.DeckImporterUtil;
|
||||||
import mage.cards.repository.ExpansionInfo;
|
import mage.cards.repository.ExpansionInfo;
|
||||||
import mage.cards.repository.ExpansionRepository;
|
import mage.cards.repository.ExpansionRepository;
|
||||||
|
@ -66,7 +68,6 @@ import mage.view.TableView;
|
||||||
import mage.view.TournamentTypeView;
|
import mage.view.TournamentTypeView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -88,7 +89,7 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
private final int CONSTRUCTION_TIME_MAX = 30;
|
private final int CONSTRUCTION_TIME_MAX = 30;
|
||||||
private boolean isRandom = false;
|
private boolean isRandom = false;
|
||||||
private boolean isRichMan = false;
|
private boolean isRichMan = false;
|
||||||
|
private String cubeFromDeckFilename = "";
|
||||||
private boolean automaticChange = false;
|
private boolean automaticChange = false;
|
||||||
|
|
||||||
/** Creates new form NewTournamentDialog */
|
/** Creates new form NewTournamentDialog */
|
||||||
|
@ -557,6 +558,9 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
|
tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
|
||||||
if (tournamentType.isCubeBooster()) {
|
if (tournamentType.isCubeBooster()) {
|
||||||
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
|
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
|
||||||
|
if (!(cubeFromDeckFilename.equals(""))) {
|
||||||
|
tOptions.getLimitedOptions().setCubeFromDeckFilename(cubeFromDeckFilename);
|
||||||
|
}
|
||||||
} else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
|
} else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
|
||||||
this.isRandom = tournamentType.isRandom();
|
this.isRandom = tournamentType.isRandom();
|
||||||
this.isRichMan = tournamentType.isRichMan();
|
this.isRichMan = tournamentType.isRichMan();
|
||||||
|
@ -649,8 +653,32 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
// TODO add your handling code here:
|
// TODO add your handling code here:
|
||||||
}//GEN-LAST:event_spnNumWinsnumPlayersChanged
|
}//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
|
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
|
}//GEN-LAST:event_cbDraftCubeActionPerformed
|
||||||
|
|
||||||
private void cbDraftTimingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbDraftTimingActionPerformed
|
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());
|
// this.cbRange.setEnabled(gameType.isUseRange());
|
||||||
createPlayers((Integer) spnNumPlayers.getValue() - 1);
|
createPlayers((Integer) spnNumPlayers.getValue() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setTournamentOptions(int numPlayers) {
|
private void setTournamentOptions(int numPlayers) {
|
||||||
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
|
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
|
||||||
activatePanelElements(tournamentType);
|
activatePanelElements(tournamentType);
|
||||||
|
@ -709,6 +738,7 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
this.revalidate();
|
this.revalidate();
|
||||||
this.repaint();
|
this.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets elements of the panel to visible or not visible
|
* Sets elements of the panel to visible or not visible
|
||||||
*
|
*
|
||||||
|
@ -911,7 +941,6 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
automaticChange = false;
|
automaticChange = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the tournament settings from java prefs
|
* 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"));
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TOURNAMENT_RATED, (tOptions.getMatchOptions().isRated() ? "Yes" : "No"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TableView getTable() {
|
public TableView getTable() {
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
@ -1107,3 +1135,27 @@ public class NewTournamentDialog extends MageDialog {
|
||||||
// End of variables declaration//GEN-END:variables
|
// 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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -110,6 +110,7 @@
|
||||||
<draftCube name="MTGO Vintage Cube 2016" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.VintageCube2016"/>
|
<draftCube name="MTGO Vintage Cube 2016" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.VintageCube2016"/>
|
||||||
<draftCube name="The Peasant's Toolbox (800 cards)" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.PeasantsToolboxCube"/>
|
<draftCube name="The Peasant's Toolbox (800 cards)" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.PeasantsToolboxCube"/>
|
||||||
<draftCube name="www.MTGCube.com (502 cards)" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.MTGCube"/>
|
<draftCube name="www.MTGCube.com (502 cards)" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.MTGCube"/>
|
||||||
|
<draftCube name="Cube From Deck" jar="mage-tournament-booster-draft.jar" className="mage.tournament.cubes.CubeFromDeck"/>
|
||||||
</draftCubes>
|
</draftCubes>
|
||||||
<deckTypes>
|
<deckTypes>
|
||||||
<deckType name="Constructed - Standard" jar="mage-deck-constructed.jar" className="mage.deck.Standard"/>
|
<deckType name="Constructed - Standard" jar="mage-deck-constructed.jar" className="mage.deck.Standard"/>
|
||||||
|
|
|
@ -67,6 +67,22 @@ public class CubeFactory {
|
||||||
return draftCube;
|
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<String> getDraftCubes() {
|
public Set<String> getDraftCubes() {
|
||||||
return draftCubes.keySet();
|
return draftCubes.keySet();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@ import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import mage.cards.Sets;
|
import mage.cards.Sets;
|
||||||
|
import mage.game.draft.DraftCube;
|
||||||
import mage.game.tournament.Tournament;
|
import mage.game.tournament.Tournament;
|
||||||
import mage.game.tournament.TournamentOptions;
|
import mage.game.tournament.TournamentOptions;
|
||||||
import mage.game.tournament.TournamentType;
|
import mage.game.tournament.TournamentType;
|
||||||
|
@ -78,7 +79,14 @@ public class TournamentFactory {
|
||||||
}
|
}
|
||||||
tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());
|
tournament.getOptions().getLimitedOptions().setNumberBoosters(tournament.getTournamentType().getNumBoosters());
|
||||||
if (tournament.getTournamentType().isCubeBooster()) {
|
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());
|
tournament.setBoosterInfo(tournament.getOptions().getLimitedOptions().getDraftCubeName());
|
||||||
} else if (tournament.getTournamentType().isRandom()) {
|
} else if (tournament.getTournamentType().isRandom()) {
|
||||||
StringBuilder rv = new StringBuilder( "Random Draft using sets: ");
|
StringBuilder rv = new StringBuilder( "Random Draft using sets: ");
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class LimitedOptions implements Serializable {
|
||||||
protected DraftCube draftCube;
|
protected DraftCube draftCube;
|
||||||
protected int numberBoosters;
|
protected int numberBoosters;
|
||||||
protected boolean isRandom;
|
protected boolean isRandom;
|
||||||
|
protected String cubeFromDeckFilename = "";
|
||||||
|
|
||||||
public List<String> getSetCodes() {
|
public List<String> getSetCodes() {
|
||||||
return sets;
|
return sets;
|
||||||
|
@ -66,6 +67,14 @@ public class LimitedOptions implements Serializable {
|
||||||
this.draftCubeName = draftCubeName;
|
this.draftCubeName = draftCubeName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCubeFromDeckFilename(String cubeFromDeckFilename) {
|
||||||
|
this.cubeFromDeckFilename = cubeFromDeckFilename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCubeFromDeckFilename() {
|
||||||
|
return cubeFromDeckFilename;
|
||||||
|
}
|
||||||
|
|
||||||
public DraftCube getDraftCube() {
|
public DraftCube getDraftCube() {
|
||||||
return draftCube;
|
return draftCube;
|
||||||
}
|
}
|
||||||
|
@ -88,4 +97,5 @@ public class LimitedOptions implements Serializable {
|
||||||
public void setIsRandom(boolean isRandom){
|
public void setIsRandom(boolean isRandom){
|
||||||
this.isRandom = isRandom;
|
this.isRandom = isRandom;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue