mirror of
https://github.com/correl/mage.git
synced 2025-01-12 03:00:13 +00:00
Fixed some exception problems (deck layout, mana symbols).
This commit is contained in:
parent
db31264538
commit
7c4b40073c
3 changed files with 47 additions and 49 deletions
|
@ -27,17 +27,6 @@
|
|||
*/
|
||||
package mage.client.deck.generator;
|
||||
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.util.gui.ColorsChooser;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
@ -46,6 +35,16 @@ import java.awt.event.ItemListener;
|
|||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.CompoundBorder;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.border.EtchedBorder;
|
||||
import mage.cards.Sets;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.util.gui.ColorsChooser;
|
||||
import mage.client.util.sets.ConstructedFormats;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -62,8 +61,7 @@ public class DeckGeneratorDialog {
|
|||
private static SimpleDateFormat dateFormat;
|
||||
private static RatioAdjustingSliderPanel adjustingSliderPanel;
|
||||
|
||||
public DeckGeneratorDialog()
|
||||
{
|
||||
public DeckGeneratorDialog() {
|
||||
initDialog();
|
||||
dateFormat = new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss-SSS");
|
||||
}
|
||||
|
@ -143,12 +141,11 @@ public class DeckGeneratorDialog {
|
|||
c.ipadx = 30;
|
||||
c.insets = new Insets(5, 10, 0, 10);
|
||||
c.weightx = 0.90;
|
||||
cbDeckSize = new JComboBox<>(new String[] { "40", "60" });
|
||||
cbDeckSize = new JComboBox<>(new String[]{"40", "60"});
|
||||
cbDeckSize.setSelectedIndex(0);
|
||||
cbDeckSize.setAlignmentX(Component.LEFT_ALIGNMENT);
|
||||
mainPanel.add(cbDeckSize, c);
|
||||
|
||||
|
||||
String prefSize = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_DECK_GENERATOR_DECK_SIZE, "60");
|
||||
if (prefSet != null) {
|
||||
cbDeckSize.setSelectedItem(prefSize);
|
||||
|
@ -218,7 +215,6 @@ public class DeckGeneratorDialog {
|
|||
c.insets = new Insets(5, 10, 0, 5);
|
||||
mainPanel.add(advancedPanel, c);
|
||||
|
||||
|
||||
btnGenerate = new JButton("Ok");
|
||||
btnGenerate.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
|
@ -306,7 +302,7 @@ public class DeckGeneratorDialog {
|
|||
c.ipady = 0;
|
||||
c.weightx = 1.0;
|
||||
c.anchor = GridBagConstraints.LAST_LINE_END;
|
||||
c.insets = new Insets(10,10, 0, 0);
|
||||
c.insets = new Insets(10, 10, 0, 0);
|
||||
c.gridx = 2;
|
||||
c.gridwidth = 1;
|
||||
c.gridy = 2;
|
||||
|
@ -329,16 +325,16 @@ public class DeckGeneratorDialog {
|
|||
}
|
||||
|
||||
public void cleanUp() {
|
||||
for (ActionListener al: btnGenerate.getActionListeners()) {
|
||||
for (ActionListener al : btnGenerate.getActionListeners()) {
|
||||
btnGenerate.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al: btnCancel.getActionListeners()) {
|
||||
for (ActionListener al : btnCancel.getActionListeners()) {
|
||||
btnCancel.removeActionListener(al);
|
||||
}
|
||||
for (ActionListener al: btnReset.getActionListeners()) {
|
||||
for (ActionListener al : btnReset.getActionListeners()) {
|
||||
btnReset.removeActionListener(al);
|
||||
}
|
||||
for(ItemListener il: cAdvanced.getItemListeners()) {
|
||||
for (ItemListener il : cAdvanced.getItemListeners()) {
|
||||
cAdvanced.removeItemListener(il);
|
||||
}
|
||||
}
|
||||
|
@ -356,7 +352,7 @@ public class DeckGeneratorDialog {
|
|||
cleanUp();
|
||||
return tmp.getAbsolutePath();
|
||||
} catch (Exception e) {
|
||||
JOptionPane.showMessageDialog(null, "Couldn't generate deck. Try again.");
|
||||
MageFrame.getInstance().showError("Couldn't generate deck. Try again.");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -418,13 +414,11 @@ public class DeckGeneratorDialog {
|
|||
}
|
||||
|
||||
public DeckGeneratorCMC getDeckGeneratorCMC() {
|
||||
DeckGeneratorCMC selectedCMC = (DeckGeneratorCMC)cbCMC.getSelectedItem();
|
||||
DeckGeneratorCMC selectedCMC = (DeckGeneratorCMC) cbCMC.getSelectedItem();
|
||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_DECK_GENERATOR_ADVANCED_CMC, selectedCMC.name());
|
||||
return selectedCMC;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getSelectedColors() {
|
||||
if (selectedColors != null) {
|
||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_DECK_GENERATOR_DECK_SIZE, cbDeckSize.getSelectedItem().toString());
|
||||
|
|
|
@ -156,8 +156,10 @@ public class ManaSymbols {
|
|||
//Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
|
||||
BufferedImage image = ImageIO.read(file);
|
||||
//BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
|
||||
BufferedImage resized = ImageHelper.getResizedImage(image, r);
|
||||
sizedSymbols.put(symbol, resized);
|
||||
if (image != null) {
|
||||
BufferedImage resized = ImageHelper.getResizedImage(image, r);
|
||||
sizedSymbols.put(symbol, resized);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error for symbol:" + symbol);
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* 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
|
||||
|
@ -20,18 +20,16 @@
|
|||
* 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.cards;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.*;
|
||||
|
||||
import mage.cards.decks.DeckCardInfo;
|
||||
import mage.cards.decks.DeckCardLayout;
|
||||
import mage.cards.decks.DeckCardLists;
|
||||
|
@ -41,7 +39,6 @@ import mage.cards.repository.CardRepository;
|
|||
import mage.constants.CardType;
|
||||
import mage.constants.ColoredManaSymbol;
|
||||
import mage.util.ClassScanner;
|
||||
|
||||
import mage.util.RandomUtil;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
@ -52,7 +49,7 @@ import org.apache.log4j.Logger;
|
|||
public class Sets extends HashMap<String, ExpansionSet> {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(Sets.class);
|
||||
private static final Sets fINSTANCE = new Sets();
|
||||
private static final Sets fINSTANCE = new Sets();
|
||||
|
||||
public static Sets getInstance() {
|
||||
return fINSTANCE;
|
||||
|
@ -72,9 +69,13 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
}
|
||||
|
||||
public void addSet(ExpansionSet set) {
|
||||
if(containsKey(set.getCode())) throw new IllegalArgumentException("Set code "+set.getCode()+" already exists.");
|
||||
if (containsKey(set.getCode())) {
|
||||
throw new IllegalArgumentException("Set code " + set.getCode() + " already exists.");
|
||||
}
|
||||
this.put(set.getCode(), set);
|
||||
if(set.isCustomSet()) customSets.add(set.getCode());
|
||||
if (set.isCustomSet()) {
|
||||
customSets.add(set.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isCustomSet(String setCode) {
|
||||
|
@ -82,7 +83,8 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generates card pool of cardsCount cards that have manacost of allowed colors.
|
||||
* Generates card pool of cardsCount cards that have manacost of allowed
|
||||
* colors.
|
||||
*
|
||||
* @param cardsCount
|
||||
* @param allowedColors
|
||||
|
@ -149,29 +151,27 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
if (deck.getAuthor() != null && deck.getAuthor().length() > 0) {
|
||||
out.println("AUTHOR:" + deck.getAuthor());
|
||||
}
|
||||
for (DeckCardInfo deckCardInfo: deck.getCards()) {
|
||||
for (DeckCardInfo deckCardInfo : deck.getCards()) {
|
||||
if (deckCards.containsKey(deckCardInfo.getCardKey())) {
|
||||
deckCards.put(deckCardInfo.getCardKey(), deckCards.get(deckCardInfo.getCardKey()).increaseQuantity());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
deckCards.put(deckCardInfo.getCardKey(), deckCardInfo);
|
||||
}
|
||||
}
|
||||
|
||||
for (DeckCardInfo deckCardInfo: deck.getSideboard()) {
|
||||
for (DeckCardInfo deckCardInfo : deck.getSideboard()) {
|
||||
if (sideboard.containsKey(deckCardInfo.getCardKey())) {
|
||||
sideboard.put(deckCardInfo.getCardKey(), sideboard.get(deckCardInfo.getCardKey()).increaseQuantity());
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
sideboard.put(deckCardInfo.getCardKey(), deckCardInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// Write out all of the cards
|
||||
for (Map.Entry<String, DeckCardInfo> entry: deckCards.entrySet()) {
|
||||
for (Map.Entry<String, DeckCardInfo> entry : deckCards.entrySet()) {
|
||||
out.printf("%d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName());
|
||||
}
|
||||
for (Map.Entry<String, DeckCardInfo> entry: sideboard.entrySet()) {
|
||||
for (Map.Entry<String, DeckCardInfo> entry : sideboard.entrySet()) {
|
||||
out.printf("SB: %d [%s:%s] %s%n", entry.getValue().getQuantity(), entry.getValue().getSetCode(), entry.getValue().getCardNum(), entry.getValue().getCardName());
|
||||
}
|
||||
|
||||
|
@ -182,13 +182,15 @@ public class Sets extends HashMap<String, ExpansionSet> {
|
|||
out.print("LAYOUT SIDEBOARD:");
|
||||
writeCardLayout(out, deck.getSideboardLayout());
|
||||
out.print("\n");
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static void writeCardLayout(PrintWriter out, DeckCardLayout layout) {
|
||||
if (layout == null) {
|
||||
return;
|
||||
}
|
||||
List<List<List<DeckCardInfo>>> cardGrid = layout.getCards();
|
||||
int height = cardGrid.size();
|
||||
int width = (height > 0) ? cardGrid.get(0).size() : 0;
|
||||
|
|
Loading…
Reference in a new issue