show information for non-card items in spell shop card details panel

This commit is contained in:
myk
2013-03-05 22:23:20 +00:00
parent 127dfd3c00
commit ff3e861303
14 changed files with 234 additions and 311 deletions

View File

@@ -1,6 +1,5 @@
package forge.card;
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import forge.item.CardPrinted;
@@ -8,44 +7,15 @@ import forge.item.IPaperCard;
import forge.util.FileSection;
import forge.util.storage.StorageReaderFile;
/**
* The Class BoosterData.
*/
public class BoosterData {
private final String edition;
public final String getEdition() {
return edition;
}
private final String landEdition;
public final String getLandEdition() {
return landEdition;
}
public class BoosterData extends PackData {
private final int nCommon;
private final int nUncommon;
private final int nRare;
private final int nSpecial;
private final int nDoubleFaced;
private final int nLand;
private final int foilRate;
private static final int CARDS_PER_BOOSTER = 15;
// private final String landCode;
/**
* Instantiates a new booster data.
*
* @param nC
* the n c
* @param nU
* the n u
* @param nR
* the n r
* @param nS
* the n s
* @param nDF
* the n df
*/
public BoosterData(final String edition, final String editionLand, final int nC, final int nU, final int nR, final int nS, final int nDF) {
// if this booster has more that 10 cards, there must be a land in
// 15th slot unless it's already taken
@@ -53,132 +23,116 @@ public class BoosterData {
- nS - nDF : 0, 68);
}
/**
* Instantiates a new booster data.
*
* @param nC
* the n c
* @param nU
* the n u
* @param nR
* the n r
* @param nS
* the n s
* @param nDF
* the n df
* @param nL
* the n l
* @param oneFoilPer
* the one foil per
*/
public BoosterData(final String edition0, final String editionLand, final int nC, final int nU, final int nR, final int nS, final int nDF, final int nL,
final int oneFoilPer) {
super(edition0, editionLand, nL > 0 ? nL : 0);
this.nCommon = nC;
this.nUncommon = nU;
this.nRare = nR;
this.nSpecial = nS;
this.nDoubleFaced = nDF;
this.nLand = nL > 0 ? nL : 0;
this.foilRate = oneFoilPer;
this.edition = edition0;
this.landEdition = editionLand;
}
/**
* Gets the common.
*
* @return the common
*/
public final int getCommon() {
return this.nCommon;
}
public final Predicate<CardPrinted> getEditionFilter() {
return IPaperCard.Predicates.printedInSets(edition);
return IPaperCard.Predicates.printedInSets(getEdition());
}
public final Predicate<CardPrinted> getLandEditionFilter() {
return IPaperCard.Predicates.printedInSets(landEdition);
return IPaperCard.Predicates.printedInSets(getLandEdition());
}
/**
* Gets the uncommon.
*
* @return the uncommon
*/
public final int getUncommon() {
return this.nUncommon;
}
/**
* Gets the rare.
*
* @return the rare
*/
public final int getRare() {
return this.nRare;
}
/**
* Gets the special.
*
* @return the special
*/
public final int getSpecial() {
return this.nSpecial;
}
/**
* Gets the double faced.
*
* @return the double faced
*/
public final int getDoubleFaced() {
return this.nDoubleFaced;
}
/**
* Gets the land.
*
* @return the land
*/
public final int getLand() {
return this.nLand;
}
/**
* Gets the total.
*
* @return the total
*/
public final int getTotal() {
return this.nCommon + this.nUncommon + this.nRare + this.nSpecial + this.nDoubleFaced + this.nLand;
return this.nCommon + this.nUncommon + this.nRare + this.nSpecial + this.nDoubleFaced + getCntLands();
}
/**
* Gets the foil chance.
*
* @return the foil chance
*/
public final int getFoilChance() {
return this.foilRate;
}
public static final Function<BoosterData, String> FN_GET_CODE = new Function<BoosterData, String>() {
private void _append(StringBuilder s, int val, String name) {
if (0 >= val) {
return;
}
s.append(val).append(' ').append(name);
if (1 < val) {
s.append('s');
}
s.append(", ");
}
@Override
public String apply(BoosterData arg1) {
return arg1.edition;
public String toString() {
int total = getTotal();
if (0 >= total) {
return "no cards";
}
StringBuilder s = new StringBuilder();
_append(s, total, "card");
if (0 < total) {
// remove comma
s.deleteCharAt(s.length() - 2);
}
s.append("consisting of ");
_append(s, nSpecial, "special");
_append(s, nDoubleFaced, "double faced card");
_append(s, nRare, "rare");
_append(s, nUncommon, "uncommon");
_append(s, nCommon, "common");
if (getEdition().equalsIgnoreCase(getLandEdition())) {
_append(s, getCntLands(), "land");
} else if (0 < getCntLands()) {
s.append(getCntLands()).append("land");
if (1 < getCntLands()) {
s.append("s");
}
s.append("from edition: ").append(getLandEdition()).append(", ");
}
// trim the last comma and space
s.replace(s.length() - 2, s.length(), "");
// put an 'and' before the previous comma
int lastCommaIdx = s.lastIndexOf(",");
if (0 < lastCommaIdx) {
s.replace(lastCommaIdx+1, lastCommaIdx+1, " and");
}
if (0 < foilRate) {
s.append(", with a foil rate of 1 in ").append(foilRate);
}
return s.toString();
}
};
public static final class Reader extends StorageReaderFile<BoosterData> {
public Reader(String pathname) {
super(pathname, BoosterData.FN_GET_CODE);
}
/* (non-Javadoc)
* @see forge.util.StorageReaderFile#read(java.lang.String)
*/
@Override
protected BoosterData read(String line, int i) {
final FileSection section = FileSection.parse(line, ":", "|");
@@ -194,6 +148,7 @@ public class BoosterData {
if (editionLand == null) {
editionLand = edition;
}
return new BoosterData(edition, editionLand, nC, nU, nR, nS, nDf, nLand, nFoilRate);
}
}

View File

@@ -213,7 +213,7 @@ public class BoosterGenerator {
*/
public final List<CardPrinted> getBoosterPack(BoosterData booster) {
return this.getBoosterPack(booster.getCommon(), booster.getUncommon(), booster.getRare(), 0, 0, booster.getSpecial(),
booster.getDoubleFaced(), 0, booster.getLand());
booster.getDoubleFaced(), 0, booster.getCntLands());
}
/**

View File

@@ -1,7 +1,5 @@
package forge.card;
import com.google.common.base.Function;
import forge.util.FileSection;
import forge.util.storage.StorageReaderFile;
@@ -9,53 +7,23 @@ import forge.util.storage.StorageReaderFile;
* TODO: Write javadoc for this type.
*
*/
public class FatPackData {
private final String edition;
public final String getEdition() {
return edition;
}
private final String landsEdition;
public final String getLandsEdition() {
return landsEdition == null ? edition : landsEdition;
}
public class FatPackData extends PackData {
private final int cntBoosters;
public int getCntBoosters() {
return cntBoosters;
}
public int getCntLands() {
return cntLands;
}
private final int cntBoosters;
private final int cntLands;
public FatPackData(String edition0, String landsEdition0, int nBoosters, int nBasicLands)
public FatPackData(String edition0, String landEdition0, int nBoosters, int nBasicLands)
{
super(edition0, landEdition0, nBasicLands);
cntBoosters = nBoosters;
cntLands = nBasicLands;
edition = edition0;
landsEdition = landsEdition0;
}
public static final Function<FatPackData, String> FN_GET_CODE = new Function<FatPackData, String>() {
@Override
public String apply(FatPackData arg1) {
return arg1.edition;
}
};
public static final class Reader extends StorageReaderFile<FatPackData> {
public Reader(String pathname) {
super(pathname, FatPackData.FN_GET_CODE);
super(pathname, PackData.FN_GET_CODE);
}
/* (non-Javadoc)
* @see forge.util.StorageReaderFile#read(java.lang.String)
*/
@Override
protected FatPackData read(String line, int i) {
final FileSection section = FileSection.parse(line, ":", "|");
@@ -64,4 +32,34 @@ public class FatPackData {
return new FatPackData(section.get("Set"), section.get("LandSet"), nBoosters, nLand);
}
}
@Override
public String toString() {
if (0 >= cntBoosters) {
return "no cards";
}
StringBuilder s = new StringBuilder();
if (0 < getCntLands()) {
s.append(getCntLands()).append(" land");
if (1 < getCntLands()) {
s.append("s");
}
if (!getEdition().equalsIgnoreCase(getLandEdition())) {
s.append(" from edition: ").append(getLandEdition());
}
if (0 < cntBoosters) {
s.append(" and ");
}
}
if (0 < cntBoosters) {
s.append(cntBoosters).append(" booster packs, each containing ");
}
return s.toString();
}
}

View File

@@ -0,0 +1,52 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.card;
import com.google.common.base.Function;
public class PackData {
private final String edition;
public final String getEdition() {
return edition;
}
private final String landEdition;
public final String getLandEdition() {
return landEdition == null ? edition : landEdition;
}
private final int cntLands;
public int getCntLands() {
return cntLands;
}
public PackData(String edition0, String landEdition0, int nBasicLands)
{
edition = edition0;
landEdition = landEdition0;
cntLands = nBasicLands;
}
public static final Function<? super PackData, String> FN_GET_CODE = new Function<PackData, String>() {
@Override
public String apply(PackData arg1) {
return arg1.edition;
}
};
}

View File

@@ -33,6 +33,8 @@ import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import javax.swing.border.EtchedBorder;
import org.apache.commons.lang3.StringUtils;
import forge.Card;
import forge.CounterType;
import forge.GameEntity;
@@ -45,6 +47,7 @@ import forge.gui.toolbox.FPanel;
import forge.gui.toolbox.FScrollPane;
import forge.gui.toolbox.FSkin;
import forge.gui.toolbox.FTextArea;
import forge.item.InventoryItemFromSet;
/**
* The class CardDetailPanel. Shows the details of a card.
@@ -66,18 +69,11 @@ public class CardDetailPanel extends FPanel {
private final FTextArea cdArea;
private final FScrollPane scrArea;
/**
* <p>
* Constructor for CardDetailPanel.
* </p>
*
* @param card
* a {@link forge.Card} object.
*/
public CardDetailPanel(final Card card) {
super();
this.setLayout(new GridBagLayout());
this.setBorder(new EtchedBorder());
this.setBorderToggle(false);
GridBagConstraints labelConstrains = new GridBagConstraints();
labelConstrains.fill = GridBagConstraints.BOTH;
@@ -126,6 +122,9 @@ public class CardDetailPanel extends FPanel {
//4, 12
this.cdArea = new FTextArea();
this.cdArea.setFont(new java.awt.Font("Dialog", 0, 14));
this.cdArea.setBorder(new EmptyBorder(4, 4, 4, 4));
this.cdArea.setOpaque(false);
this.scrArea = new FScrollPane(this.cdArea);
GridBagConstraints areaConstraints = new GridBagConstraints();
@@ -135,10 +134,6 @@ public class CardDetailPanel extends FPanel {
areaConstraints.weightx = 1.0;
areaConstraints.weighty = 1.0;
this.add(scrArea, areaConstraints);
this.cdArea.setLineWrap(true);
this.cdArea.setWrapStyleWord(true);
this.cdArea.setEditable(false);
this.cdArea.setBorder(new EmptyBorder(4, 4, 4, 4));
this.nameCostLabel.setFont(new java.awt.Font("Dialog", 0, 14));
this.typeLabel.setFont(new java.awt.Font("Dialog", 0, 14));
@@ -149,15 +144,49 @@ public class CardDetailPanel extends FPanel {
f = f.deriveFont(java.awt.Font.BOLD);
this.setInfoLabel.setFont(f);
this.cdArea.setFont(new java.awt.Font("Dialog", 0, 14));
this.setCard(card);
}
public final void setItem(InventoryItemFromSet item) {
nameCostLabel.setText(item.getName());
typeLabel.setVisible(false);
powerToughnessLabel.setVisible(false);
idLabel.setText(null);
cdArea.setText(item.getDescription());
setBorder(GuiDisplayUtil.getBorder(null));
String set = item.getEdition();
setInfoLabel.setText(set);
setInfoLabel.setToolTipText("");
if (StringUtils.isEmpty(set)) {
setInfoLabel.setOpaque(false);
setInfoLabel.setBorder(null);
} else {
CardEdition edition = Singletons.getModel().getEditions().get(set);
if (null != edition) {
setInfoLabel.setToolTipText(edition.getName());
}
this.setInfoLabel.setOpaque(true);
this.setInfoLabel.setBackground(Color.BLACK);
this.setInfoLabel.setForeground(Color.WHITE);
this.setInfoLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
scrArea.getVerticalScrollBar().setValue(scrArea.getVerticalScrollBar().getMinimum());
}
});
}
/** {@inheritDoc} */
public final void setCard(final Card card) {
this.nameCostLabel.setText("");
this.typeLabel.setVisible(true);
this.typeLabel.setText("");
this.powerToughnessLabel.setVisible(true);
this.powerToughnessLabel.setText("");
this.idLabel.setText("");
this.setInfoLabel.setText("");
@@ -167,8 +196,9 @@ public class CardDetailPanel extends FPanel {
this.cdArea.setText("");
this.setBorder(GuiDisplayUtil.getBorder(card));
if ( null == card )
if (null == card) {
return;
}
final boolean canShowThis = card.canBeShownTo(Singletons.getControl().getPlayer());
if (canShowThis) {

View File

@@ -26,6 +26,7 @@ import forge.gui.framework.ICDoc;
import forge.gui.match.views.VDetail;
import forge.item.IPaperCard;
import forge.item.InventoryItem;
import forge.item.InventoryItemFromSet;
/**
*
@@ -38,7 +39,6 @@ public enum CDetail implements ICDoc {
SINGLETON_INSTANCE;
private VDetail view = VDetail.SINGLETON_INSTANCE;
//private InventoryItem item = null;
/**
* Shows card details and/or picture in sidebar cardview tabber.
@@ -54,14 +54,13 @@ public enum CDetail implements ICDoc {
public void showCard(InventoryItem item) {
if (item instanceof IPaperCard) {
showCard(((IPaperCard)item).getMatchingForgeCard());
return;
}
// TODO If we want to display an Items Written Text in the Detail Panel we need to add something into CardDetailPanel
//this.item = item;
} else if (item instanceof InventoryItemFromSet) {
view.getLblFlipcard().setVisible(false);
view.getPnlDetail().setCard(null);
view.getPnlDetail().setItem((InventoryItemFromSet)item);
view.getParentCell().repaintSelf();
} else {
showCard((Card)null);
}
}
/* (non-Javadoc)

View File

@@ -15,8 +15,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.item;
package forge.item;
import com.google.common.base.Function;
@@ -25,13 +25,7 @@ import forge.Singletons;
import forge.card.BoosterData;
import forge.card.CardEdition;
/**
* TODO Write javadoc for this type.
*
*/
public class BoosterPack extends OpenablePack {
/** The Constant fnFromSet. */
public static final Function<CardEdition, BoosterPack> FN_FROM_SET = new Function<CardEdition, BoosterPack>() {
@Override
public BoosterPack apply(final CardEdition arg1) {
@@ -40,26 +34,10 @@ public class BoosterPack extends OpenablePack {
}
};
/**
* Instantiates a new booster pack.
*
* @param set
* the set
*/
public BoosterPack(final String name0, final BoosterData boosterData) {
super(name0, boosterData);
}
/*
* (non-Javadoc)
*
* @see forge.item.InventoryItemFromSet#getImageFilename()
*/
/**
* Gets the image filename.
*
* @return String
*/
@Override
public final String getImageFilename() {
return ImageCache.SEALED_PRODUCT + "booster/" + this.contents.getEdition() + ".png";
@@ -70,20 +48,8 @@ public class BoosterPack extends OpenablePack {
return "Booster Pack";
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#clone()
*/
/**
* Clone.
*
* @return Object
*/
@Override
public final Object clone() {
return new BoosterPack(name, contents);
}
}

View File

@@ -70,6 +70,11 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
return this.name;
}
@Override
public String getDescription() {
return name;
}
/*
* (non-Javadoc)
*

View File

@@ -23,6 +23,8 @@ public class CardToken implements InventoryItemFromSet, IPaperCard {
}
@Override public String getName() { return name; }
@Override public String getDescription() { return name; }
@Override public String getEdition() { return edition; }
@Override public int getArtIndex() { return 0; } // This might change however

View File

@@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.item;
import java.util.ArrayList;
@@ -27,10 +28,6 @@ import forge.Singletons;
import forge.card.CardEdition;
import forge.card.FatPackData;
/**
* TODO Write javadoc for this type.
*
*/
public class FatPack extends OpenablePack {
/** The Constant fnFromSet. */
@@ -44,17 +41,15 @@ public class FatPack extends OpenablePack {
private final FatPackData fpData;
/**
* Instantiates a new booster pack.
*
* @param set
* the set
*/
public FatPack(final String name0, final FatPackData fpData0) {
super(name0, Singletons.getModel().getBoosters().get(fpData0.getEdition()));
fpData = fpData0;
}
@Override
public String getDescription() {
return fpData.toString() + contents.toString();
}
@Override
public final String getImageFilename() {
@@ -73,20 +68,10 @@ public class FatPack extends OpenablePack {
for (int i = 0; i < fpData.getCntBoosters(); i++) {
result.addAll(super.generate());
}
result.addAll(getRandomBasicLands(fpData.getLandsEdition(), fpData.getCntLands()));
result.addAll(getRandomBasicLands(fpData.getLandEdition(), fpData.getCntLands()));
return result;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#clone()
*/
/**
* Clone.
*
* @return Object
*/
@Override
public final Object clone() {
return new FatPack(name, fpData);
@@ -96,6 +81,4 @@ public class FatPack extends OpenablePack {
public int getTotalCards() {
return super.getTotalCards() * fpData.getCntBoosters() + fpData.getCntLands();
}
}

View File

@@ -22,22 +22,10 @@ package forge.item;
* CardPrinted, Booster, Pets, Plants... etc
*/
public interface InventoryItemFromSet extends InventoryItem {
/**
* An inventory item has to provide a name.
*
* @return the name
* The description to display for the item
*/
@Override
String getName();
/**
* An inventory item has to provide a picture.
*
* @return the image filename
*/
@Override
String getImageFilename();
String getDescription();
/**
* An item belonging to a set should return its set as well.

View File

@@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.item;
import java.util.List;
@@ -28,73 +29,46 @@ import forge.card.BoosterGenerator;
import forge.card.CardRulesPredicates;
import forge.util.Aggregates;
/**
* TODO: Write javadoc for this type.
*/
public abstract class OpenablePack implements InventoryItemFromSet {
/** The contents. */
protected final BoosterData contents;
/** The name. */
protected final String name;
private List<CardPrinted> cards = null;
private BoosterGenerator generator = null;
/**
* Instantiates a new openable pack.
*
* @param name0 the name0
* @param boosterData the booster data
*/
public OpenablePack(final String name0, final BoosterData boosterData) {
this.contents = boosterData;
this.name = name0;
}
/* (non-Javadoc)
* @see forge.item.InventoryItemFromSet#getName()
*/
@Override
public final String getName() {
return this.name + " " + this.getItemType();
}
/* (non-Javadoc)
* @see forge.item.InventoryItemFromSet#getEdition()
*/
@Override
public String getDescription() {
return contents.toString();
}
@Override
public final String getEdition() {
return this.contents.getEdition();
}
/**
* Gets the cards.
*
* @return the cards
*/
public final List<CardPrinted> getCards() {
if (null == this.cards) {
this.cards = this.generate();
}
return this.cards;
}
/**
* Gets the total cards.
*
* @return the total cards
*/
public int getTotalCards() {
return this.contents.getTotal();
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public final boolean equals(final Object obj) {
if (this == obj) {
@@ -117,16 +91,6 @@ public abstract class OpenablePack implements InventoryItemFromSet {
return true;
}
/*
* (non-Javadoc)
*
* @see java.lang.Object#hashCode()
*/
/**
* Hash code.
*
* @return int
*/
@Override
public final int hashCode() {
final int prime = 31;
@@ -135,47 +99,27 @@ public abstract class OpenablePack implements InventoryItemFromSet {
return result;
}
/**
* Generate.
*
* @return the list
*/
protected List<CardPrinted> generate() {
if (null == this.generator) {
this.generator = new BoosterGenerator(this.contents.getEditionFilter());
}
final List<CardPrinted> myCards = this.generator.getBoosterPack(this.contents);
final int cntLands = this.contents.getLand();
final int cntLands = this.contents.getCntLands();
if (cntLands > 0) {
myCards.add(this.getRandomBasicLand(this.contents.getLandEdition()));
}
return myCards;
}
/**
* Gets the random basic land.
*
* @param set the set
* @return the random basic land
*/
protected CardPrinted getRandomBasicLand(final String setCode) {
return this.getRandomBasicLands(setCode, 1).get(0);
}
/**
* Gets the random basic lands.
*
* @param set the set
* @param count the count
* @return the random basic lands
*/
protected List<CardPrinted> getRandomBasicLands(final String setCode, final int count) {
Predicate<CardPrinted> cardsRule = Predicates.and(
IPaperCard.Predicates.printedInSets(setCode),
Predicates.compose(CardRulesPredicates.Presets.IS_BASIC_LAND, CardPrinted.FN_GET_RULES));
return Aggregates.random(Iterables.filter(CardDb.instance().getAllCards(), cardsRule), count);
}
}

View File

@@ -133,6 +133,7 @@ public class PreconDeck implements InventoryItemFromSet {
*
* @return the description
*/
@Override
public final String getDescription() {
return this.description;
}

View File

@@ -40,7 +40,7 @@ import forge.util.IItemReader;
public abstract class StorageReaderFile<T> implements IItemReader<T> {
private final File file;
private final Function<T, String> keySelector;
private final Function<? super T, String> keySelector;
/**
* Instantiates a new storage reader file.
@@ -48,7 +48,7 @@ public abstract class StorageReaderFile<T> implements IItemReader<T> {
* @param pathname the pathname
* @param keySelector0 the key selector0
*/
public StorageReaderFile(final String pathname, final Function<T, String> keySelector0) {
public StorageReaderFile(final String pathname, final Function<? super T, String> keySelector0) {
this(new File(pathname), keySelector0);
}
@@ -58,7 +58,7 @@ public abstract class StorageReaderFile<T> implements IItemReader<T> {
* @param file0 the file0
* @param keySelector0 the key selector0
*/
public StorageReaderFile(final File file0, final Function<T, String> keySelector0) {
public StorageReaderFile(final File file0, final Function<? super T, String> keySelector0) {
this.file = file0;
this.keySelector = keySelector0;
}