mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
- change terminology from filename to image key
- make icons use the image cache - display the avatar icon for the player when assigning damage from creatures with trample
This commit is contained in:
@@ -251,9 +251,6 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
this.characteristicsMap.put(CardCharacteristicName.FaceDown, CardUtil.getFaceDownCharacteristic());
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*/
|
||||
public void refreshUniqueNumber() {
|
||||
this.setUniqueNumber(Card.nextUniqueNumber++);
|
||||
}
|
||||
@@ -8514,27 +8511,12 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
return CardDb.instance().getCard(this.getName()).getEdition();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* setImageFilename.
|
||||
* </p>
|
||||
*
|
||||
* @param iFN
|
||||
* a {@link java.lang.String} object.
|
||||
*/
|
||||
public final void setImageFilename(final String iFN) {
|
||||
this.getCharacteristics().setImageFilename(iFN);
|
||||
public final void setImageKey(final String iFN) {
|
||||
this.getCharacteristics().setImageKey(iFN);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getImageFilename.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String} object.
|
||||
*/
|
||||
public final String getImageFilename() {
|
||||
return this.getCharacteristics().getImageFilename();
|
||||
public final String getImageKey() {
|
||||
return this.getCharacteristics().getImageKey();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -202,7 +202,7 @@ public final class CardUtil {
|
||||
ret.setName("");
|
||||
ret.setType(types);
|
||||
|
||||
ret.setImageFilename(NewConstants.CACHE_MORPH_IMAGE_FILE);
|
||||
ret.setImageKey(NewConstants.CACHE_MORPH_IMAGE_FILE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -20,11 +20,15 @@ package forge;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import com.mortennobel.imagescaling.ResampleOp;
|
||||
|
||||
import forge.game.player.IHasIcon;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.properties.NewConstants;
|
||||
@@ -46,6 +50,7 @@ import forge.properties.NewConstants;
|
||||
public class ImageCache {
|
||||
// short prefixes to save memory
|
||||
public static final String TOKEN_PREFIX = "t:";
|
||||
public static final String ICON_PREFIX = "i:";
|
||||
public static final String BOOSTER_PREFIX = "b:";
|
||||
public static final String FATPACK_PREFIX = "f:";
|
||||
public static final String PRECON_PREFIX = "p:";
|
||||
@@ -53,22 +58,42 @@ public class ImageCache {
|
||||
|
||||
static private final LoadingCache<String, BufferedImage> CACHE = CacheBuilder.newBuilder().softValues().build(new ImageLoader());
|
||||
|
||||
public static BufferedImage getImage(final Card card, final int width, final int height) {
|
||||
/**
|
||||
* retrieve an image from the cache. returns null if the image is not found in the cache
|
||||
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.
|
||||
*/
|
||||
public static BufferedImage getImage(Card card, int width, int height) {
|
||||
final String key;
|
||||
if (!card.canBeShownTo(Singletons.getControl().getPlayer()) || card.isFaceDown()) {
|
||||
key = TOKEN_PREFIX + NewConstants.CACHE_MORPH_IMAGE_FILE;
|
||||
} else {
|
||||
key = card.getImageFilename();
|
||||
key = card.getImageKey();
|
||||
}
|
||||
return scaleImage(key, width, height);
|
||||
}
|
||||
|
||||
public static BufferedImage getImage(final InventoryItem ii, final int width, final int height) {
|
||||
return scaleImage(ii.getImageFilename(), width, height);
|
||||
/**
|
||||
* retrieve an image from the cache. returns null if the image is not found in the cache
|
||||
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.
|
||||
*/
|
||||
public static BufferedImage getImage(InventoryItem ii, int width, int height) {
|
||||
return scaleImage(ii.getImageKey(), width, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve an icon from the cache. returns the current skin's ICO_UNKNOWN if the icon image is not found
|
||||
* in the cache and cannot be loaded from disk.
|
||||
*/
|
||||
public static ImageIcon getIcon(IHasIcon ihi) {
|
||||
BufferedImage i = scaleImage(ihi.getIconImageKey(), -1, -1);
|
||||
if (null == i) {
|
||||
return FSkin.getIcon(FSkin.InterfaceIcons.ICO_UNKNOWN);
|
||||
}
|
||||
return new ImageIcon(i);
|
||||
}
|
||||
|
||||
private static BufferedImage scaleImage(String key, final int width, final int height) {
|
||||
if (3 > width || 3 > height) {
|
||||
if ((3 > width && -1 != width) || (3 > height && -1 != height)) {
|
||||
// picture too small; return a blank
|
||||
return null;
|
||||
}
|
||||
@@ -84,26 +109,29 @@ public class ImageCache {
|
||||
|
||||
boolean mayEnlarge = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_SCALE_LARGER);
|
||||
BufferedImage original = getImage(key);
|
||||
if ( null == original )
|
||||
if (null == original) {
|
||||
return null;
|
||||
}
|
||||
|
||||
double scale = Math.min((double) width / original.getWidth(), (double) height / original.getHeight());
|
||||
// here would be the place to limit the scaling option in menu ?
|
||||
double scale = Math.min(
|
||||
-1 == width ? 1 : (double)width / original.getWidth(),
|
||||
-1 == height? 1 : (double)height / original.getHeight());
|
||||
if ((scale > 1) && !mayEnlarge) {
|
||||
scale = 1;
|
||||
}
|
||||
|
||||
BufferedImage result;
|
||||
if ( 1 == scale ) {
|
||||
if (1 == scale) {
|
||||
result = original;
|
||||
} else {
|
||||
int destWidth = (int) (original.getWidth() * scale);
|
||||
int destHeight = (int) (original.getHeight() * scale);
|
||||
int destWidth = (int)(original.getWidth() * scale);
|
||||
int destHeight = (int)(original.getHeight() * scale);
|
||||
ResampleOp resampler = new ResampleOp(destWidth, destHeight);
|
||||
|
||||
result = resampler.filter(original, null);
|
||||
CACHE.put(resizedKey, result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@ import java.io.IOException;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.cache.CacheLoader;
|
||||
|
||||
import forge.error.BugReporter;
|
||||
@@ -18,11 +20,18 @@ final class ImageLoader extends CacheLoader<String, BufferedImage> {
|
||||
|
||||
@Override
|
||||
public BufferedImage load(String key) {
|
||||
if (StringUtils.isEmpty(key)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String path;
|
||||
final String filename;
|
||||
if (key.startsWith(ImageCache.TOKEN_PREFIX)) {
|
||||
filename = key.substring(ImageCache.TOKEN_PREFIX.length());
|
||||
path = NewConstants.CACHE_TOKEN_PICS_DIR;
|
||||
} else if (key.startsWith(ImageCache.ICON_PREFIX)) {
|
||||
filename = key.substring(ImageCache.ICON_PREFIX.length());
|
||||
path = NewConstants.CACHE_ICON_PICS_DIR;
|
||||
} else if (key.startsWith(ImageCache.BOOSTER_PREFIX)) {
|
||||
filename = key.substring(ImageCache.BOOSTER_PREFIX.length());
|
||||
path = NewConstants.CACHE_BOOSTER_PICS_DIR;
|
||||
|
||||
@@ -50,7 +50,7 @@ public class CardCharacteristics {
|
||||
private ArrayList<ReplacementEffect> replacementEffects = new ArrayList<ReplacementEffect>();
|
||||
private ArrayList<StaticAbility> staticAbilities = new ArrayList<StaticAbility>();
|
||||
private ArrayList<String> staticAbilityStrings = new ArrayList<String>();
|
||||
private String imageFilename = "";
|
||||
private String imageKey = "";
|
||||
private Map<String, String> sVars = new TreeMap<String, String>();
|
||||
|
||||
private CardRarity rarity = CardRarity.Unknown;
|
||||
@@ -279,8 +279,8 @@ public class CardCharacteristics {
|
||||
*
|
||||
* @return the imageFilename
|
||||
*/
|
||||
public final String getImageFilename() {
|
||||
return this.imageFilename;
|
||||
public final String getImageKey() {
|
||||
return this.imageKey;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -289,8 +289,8 @@ public class CardCharacteristics {
|
||||
* @param imageFilename0
|
||||
* the imageFilename to set
|
||||
*/
|
||||
public final void setImageFilename(final String imageFilename0) {
|
||||
this.imageFilename = imageFilename0;
|
||||
public final void setImageKey(final String imageFilename0) {
|
||||
this.imageKey = imageFilename0;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -410,7 +410,7 @@ public class CardCharacteristics {
|
||||
// ArrayList<String> staticAbilityStrings : list of String objects so use copy constructor
|
||||
this.staticAbilityStrings = new ArrayList<String>(source.getStaticAbilityStrings());
|
||||
// String imageFilename = copy reference
|
||||
this.imageFilename = source.getImageFilename();
|
||||
this.imageKey = source.getImageKey();
|
||||
this.rarity = source.rarity;
|
||||
this.curSetCode = source.curSetCode;
|
||||
// Map<String, String> sVars
|
||||
|
||||
@@ -86,7 +86,7 @@ public class CloneEffect extends SpellAbilityEffect {
|
||||
tgtCard = cloneTargets.get(0);
|
||||
}
|
||||
|
||||
String imageFileName = host.getImageFilename();
|
||||
String imageFileName = host.getImageKey();
|
||||
|
||||
boolean keepName = sa.hasParam("KeepName");
|
||||
String originalName = tgtCard.getName();
|
||||
@@ -152,7 +152,7 @@ public class CloneEffect extends SpellAbilityEffect {
|
||||
}
|
||||
tgtCard.setFlipCard(true);
|
||||
//keep the Clone card image for the cloned card
|
||||
tgtCard.setImageFilename(imageFileName);
|
||||
tgtCard.setImageKey(imageFileName);
|
||||
|
||||
if (!tgtCard.isFlipped()) {
|
||||
tgtCard.setState(CardCharacteristicName.Original);
|
||||
@@ -171,7 +171,7 @@ public class CloneEffect extends SpellAbilityEffect {
|
||||
tgtCard.clearImprinted();
|
||||
|
||||
//keep the Clone card image for the cloned card
|
||||
tgtCard.setImageFilename(imageFileName);
|
||||
tgtCard.setImageKey(imageFileName);
|
||||
|
||||
// check if clone is now an Aura that needs to be attached
|
||||
if (tgtCard.isAura()) {
|
||||
|
||||
@@ -94,7 +94,7 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
|
||||
copy = CardFactory.copyStats(c);
|
||||
|
||||
copy.setName(c.getName());
|
||||
copy.setImageFilename(c.getImageFilename());
|
||||
copy.setImageKey(c.getImageKey());
|
||||
|
||||
copy.setOwner(controller);
|
||||
copy.addController(controller);
|
||||
@@ -126,7 +126,7 @@ public class CopyPermanentEffect extends SpellAbilityEffect {
|
||||
if (c.isFlipCard()) { // Cloned Flips CAN flip.
|
||||
copy.setState(CardCharacteristicName.Original);
|
||||
c.setState(CardCharacteristicName.Original);
|
||||
copy.setImageFilename(c.getImageFilename());
|
||||
copy.setImageKey(c.getImageKey());
|
||||
if (!c.isInAlternateState()) {
|
||||
copy.setState(CardCharacteristicName.Flipped);
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class EffectEffect extends SpellAbilityEffect {
|
||||
// nuked
|
||||
eff.addController(controller);
|
||||
eff.setOwner(controller);
|
||||
eff.setImageFilename(sa.hasParam("Image") ? sa.getParam("Image") : hostCard.getImageFilename());
|
||||
eff.setImageKey(sa.hasParam("Image") ? sa.getParam("Image") : hostCard.getImageKey());
|
||||
eff.setColor(hostCard.getColor());
|
||||
eff.setImmutable(true);
|
||||
eff.setEffectSource(hostCard);
|
||||
|
||||
@@ -224,27 +224,27 @@ public class CardFactory {
|
||||
c.setCurSetCode(cp.getEdition());
|
||||
c.setRarity(cp.getRarity());
|
||||
|
||||
String originalPicture = cp.getImageFilename();
|
||||
String originalPicture = cp.getImageKey();
|
||||
//System.out.println(c.getName() + " -> " + originalPicture);
|
||||
c.setImageFilename(originalPicture);
|
||||
c.setImageKey(originalPicture);
|
||||
c.setToken(cp.isToken());
|
||||
|
||||
if (c.hasAlternateState()) {
|
||||
if (c.isFlipCard()) {
|
||||
c.setState(CardCharacteristicName.Flipped);
|
||||
c.setImageFilename(originalPicture); // should assign a 180 degrees rotated picture here?
|
||||
c.setImageKey(originalPicture); // should assign a 180 degrees rotated picture here?
|
||||
}
|
||||
else if (c.isDoubleFaced() && cp instanceof CardPrinted) {
|
||||
c.setState(CardCharacteristicName.Transformed);
|
||||
c.setImageFilename(((CardPrinted)cp).getImageFilename(true));
|
||||
c.setImageKey(((CardPrinted)cp).getImageKey(true));
|
||||
}
|
||||
else if (c.getRules().getSplitType() == CardSplitType.Split) {
|
||||
c.setState(CardCharacteristicName.LeftSplit);
|
||||
c.setImageFilename(originalPicture);
|
||||
c.setImageKey(originalPicture);
|
||||
c.setCurSetCode(cp.getEdition());
|
||||
c.setRarity(cp.getRarity());
|
||||
c.setState(CardCharacteristicName.RightSplit);
|
||||
c.setImageFilename(originalPicture);
|
||||
c.setImageKey(originalPicture);
|
||||
}
|
||||
|
||||
c.setCurSetCode(cp.getEdition());
|
||||
@@ -456,7 +456,7 @@ public class CardFactory {
|
||||
to.setSVars(from.getSVars());
|
||||
to.setIntrinsicAbilities(from.getIntrinsicAbilities());
|
||||
|
||||
to.setImageFilename(from.getImageFilename());
|
||||
to.setImageKey(from.getImageKey());
|
||||
to.setTriggers(from.getTriggers());
|
||||
to.setReplacementEffects(from.getReplacementEffects());
|
||||
to.setStaticAbilityStrings(from.getStaticAbilityStrings());
|
||||
|
||||
@@ -2448,7 +2448,7 @@ public class CardFactoryUtil {
|
||||
final List<Card> list = new ArrayList<Card>();
|
||||
final Card c = new Card();
|
||||
c.setName(name);
|
||||
c.setImageFilename(imageName);
|
||||
c.setImageKey(imageName);
|
||||
|
||||
// TODO - most tokens mana cost is 0, this needs to be fixed
|
||||
// c.setManaCost(manaCost);
|
||||
@@ -2509,7 +2509,7 @@ public class CardFactoryUtil {
|
||||
final List<String> kal = thisToken.getIntrinsicKeyword();
|
||||
final String[] tokenKeywords = new String[kal.size()];
|
||||
kal.toArray(tokenKeywords);
|
||||
final List<Card> tokens = CardFactoryUtil.makeToken(thisToken.getName(), thisToken.getImageFilename(),
|
||||
final List<Card> tokens = CardFactoryUtil.makeToken(thisToken.getName(), thisToken.getImageKey(),
|
||||
thisToken.getController(), thisToken.getManaCost().toString(), tokenTypes, thisToken.getBaseAttack(),
|
||||
thisToken.getBaseDefense(), tokenKeywords);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ public class GameNew {
|
||||
if (preferences.getPrefBoolean(FPref.UI_RANDOM_CARD_ART)) {
|
||||
final int cntVariants = cardPrinted.getRules().getEditionInfo(cardPrinted.getEdition()).getCopiesCount();
|
||||
if (cntVariants > 1) {
|
||||
card.setImageFilename(cardPrinted.getImageFilename(false, generator.nextInt(cntVariants), true));
|
||||
card.setImageKey(cardPrinted.getImageKey(false, generator.nextInt(cntVariants), true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
6
src/main/java/forge/game/player/IHasIcon.java
Normal file
6
src/main/java/forge/game/player/IHasIcon.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package forge.game.player;
|
||||
|
||||
public interface IHasIcon {
|
||||
String getIconImageKey();
|
||||
void setIconImageKey(String iconImageKey);
|
||||
}
|
||||
@@ -6,18 +6,15 @@ package forge.game.player;
|
||||
* May store player's assets here.
|
||||
*
|
||||
*/
|
||||
public class LobbyPlayer {
|
||||
public class LobbyPlayer implements IHasIcon {
|
||||
|
||||
protected final PlayerType type;
|
||||
public final PlayerType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected final String name;
|
||||
// string with picture is more important than avatar index
|
||||
protected String picture;
|
||||
protected String imageKey;
|
||||
private int avatarIndex = -1;
|
||||
|
||||
public LobbyPlayer(PlayerType type, String name) {
|
||||
@@ -26,18 +23,16 @@ public class LobbyPlayer {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public final String getPicture() {
|
||||
return picture;
|
||||
@Override
|
||||
public final String getIconImageKey() {
|
||||
return imageKey;
|
||||
}
|
||||
|
||||
public final void setPicture(String picture) {
|
||||
this.picture = picture;
|
||||
@Override
|
||||
public final void setIconImageKey(String imageKey) {
|
||||
this.imageKey = imageKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class MigrationSourceAnalyzer {
|
||||
|
||||
int numPics = urls.split("\\\\").length;
|
||||
for (int artIdx = 0; numPics > artIdx; ++artIdx) {
|
||||
String filename = c.getImageFilename(backFace, artIdx, false) + ".jpg";
|
||||
String filename = c.getImageKey(backFace, artIdx, false) + ".jpg";
|
||||
_defaultPicNames.add(filename);
|
||||
|
||||
String oldFilenameBase = _oldCleanString(filename.replace(".full.jpg", ""));
|
||||
@@ -360,9 +360,9 @@ public class MigrationSourceAnalyzer {
|
||||
private static void _addSetCards(Set<String> cardFileNames, Iterable<CardPrinted> library, Predicate<CardPrinted> filter) {
|
||||
for (CardPrinted c : Iterables.filter(library, filter)) {
|
||||
boolean hasBackFace = null != c.getRules().getPictureOtherSideUrl();
|
||||
cardFileNames.add(c.getImageFilename(false, c.getArtIndex(), true) + ".jpg");
|
||||
cardFileNames.add(c.getImageKey(false, c.getArtIndex(), true) + ".jpg");
|
||||
if (hasBackFace) {
|
||||
cardFileNames.add(c.getImageFilename(true, c.getArtIndex(), true) + ".jpg");
|
||||
cardFileNames.add(c.getImageKey(true, c.getArtIndex(), true) + ".jpg");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class GuiDownloadPicturesLQ extends GuiDownloader {
|
||||
for (String url : urls.split("\\\\")) {
|
||||
++artIdx;
|
||||
|
||||
String filename = c.getImageFilename(backFace, artIdx, false);
|
||||
String filename = c.getImageKey(backFace, artIdx, false);
|
||||
if (filenames.contains(filename)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -45,9 +45,9 @@ public class GuiDownloadSetPicturesLQ extends GuiDownloader {
|
||||
continue;
|
||||
}
|
||||
|
||||
addDLObject(c.getImageUrlPath(false), c.getImageFilename(), downloads);
|
||||
addDLObject(c.getImageUrlPath(false), c.getImageKey(), downloads);
|
||||
|
||||
String backFaceImage = c.getImageFilename(true);
|
||||
String backFaceImage = c.getImageKey(true);
|
||||
if (backFaceImage != null) {
|
||||
addDLObject(c.getImageUrlPath(true), backFaceImage, downloads);
|
||||
}
|
||||
|
||||
@@ -7,19 +7,17 @@ import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JRadioButton;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
import javax.swing.event.ChangeListener;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.ImageCache;
|
||||
import forge.gui.toolbox.FRadioButton;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FTextArea;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.QuestEvent;
|
||||
|
||||
/**
|
||||
@@ -52,16 +50,7 @@ class PnlEvent extends JPanel {
|
||||
public PnlEvent(final QuestEvent e0) {
|
||||
super();
|
||||
this.event = e0;
|
||||
|
||||
// Icon
|
||||
final File file = new File(NewConstants.CACHE_ICON_PICS_DIR, event.getIconFilename());
|
||||
|
||||
if (!file.exists()) {
|
||||
img = FSkin.getIcon(FSkin.InterfaceIcons.ICO_UNKNOWN).getImage();
|
||||
}
|
||||
else {
|
||||
img = (new ImageIcon(file.toString())).getImage();
|
||||
}
|
||||
img = ImageCache.getIcon(e0).getImage();
|
||||
|
||||
wSrc = img.getWidth(null);
|
||||
hSrc = img.getHeight(null);
|
||||
@@ -103,8 +92,6 @@ class PnlEvent extends JPanel {
|
||||
|
||||
@Override
|
||||
public void paintComponent(final Graphics g) {
|
||||
// super.paintComponent(g);
|
||||
|
||||
Graphics2D g2d = (Graphics2D) g.create();
|
||||
g2d.setPaint(new GradientPaint(0, 0, clr3, getWidth(), 0, clr2));
|
||||
g2d.fillRect(0, 0, getWidth(), getHeight());
|
||||
|
||||
@@ -419,7 +419,7 @@ public class SSubmenuQuestUtil {
|
||||
msh.addPlayer(Singletons.getControl().getLobby().getQuestPlayer(), humanStart);
|
||||
|
||||
LobbyPlayer aiPlayer = Singletons.getControl().getLobby().findLocalPlayer(PlayerType.COMPUTER, event.getOpponent() == null ? event.getTitle() : event.getOpponent());
|
||||
aiPlayer.setPicture(event.getIconFilename());
|
||||
aiPlayer.setIconImageKey(event.getIconImageKey());
|
||||
msh.addPlayer(aiPlayer, aiStart);
|
||||
|
||||
Singletons.getModel().getMatch().initMatch(GameType.Quest, msh.getPlayerMap());
|
||||
|
||||
@@ -17,8 +17,6 @@
|
||||
*/
|
||||
package forge.gui.match;
|
||||
|
||||
import java.awt.Image;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -28,8 +26,10 @@ import javax.swing.ImageIcon;
|
||||
|
||||
import forge.Card;
|
||||
import forge.GameEntity;
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.framework.EDocID;
|
||||
import forge.gui.match.controllers.CDetail;
|
||||
@@ -42,7 +42,6 @@ import forge.gui.match.nonsingleton.VHand;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
/**
|
||||
* Constructs instance of match UI controller, used as a single point of
|
||||
@@ -53,25 +52,21 @@ import forge.properties.NewConstants;
|
||||
* <br><br><i>(C at beginning of class name denotes a control class.)</i>
|
||||
*/
|
||||
public enum CMatchUI {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private Image getPlayerAvatar(final Player p, final int defaultIndex) {
|
||||
String strAvatarIcon = p.getLobbyPlayer().getPicture();
|
||||
if (strAvatarIcon != null) {
|
||||
final File f = new File(NewConstants.CACHE_ICON_PICS_DIR, strAvatarIcon);
|
||||
if (f.exists()) {
|
||||
return new ImageIcon(f.getPath()).getImage();
|
||||
private ImageIcon getPlayerAvatar(final Player p, final int defaultIndex) {
|
||||
LobbyPlayer lp = p.getLobbyPlayer();
|
||||
ImageIcon ret = ImageCache.getIcon(lp);
|
||||
if (null == ret) {
|
||||
int iAvatar = lp.getAvatarIndex();
|
||||
return new ImageIcon(FSkin.getAvatars().get(iAvatar >= 0 ? iAvatar : defaultIndex));
|
||||
}
|
||||
}
|
||||
int iAvatar = p.getLobbyPlayer().getAvatarIndex();
|
||||
return FSkin.getAvatars().get(iAvatar >= 0 ? iAvatar : defaultIndex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private void setAvatar(final VField view, final Image img) {
|
||||
|
||||
view.getLblAvatar().setIcon(new ImageIcon(img));
|
||||
private void setAvatar(VField view, ImageIcon img) {
|
||||
view.getLblAvatar().setIcon(img);
|
||||
view.getLblAvatar().getResizeTimer().start();
|
||||
}
|
||||
|
||||
@@ -95,7 +90,7 @@ public enum CMatchUI {
|
||||
VCommand humanCommand = new VCommand(EDocID.COMMAND_0, localPlayer);
|
||||
fields.add(0, humanField);
|
||||
commands.add(0, humanCommand);
|
||||
setAvatar(humanField, FSkin.getAvatars().get(Integer.parseInt(indices[0])));
|
||||
setAvatar(humanField, new ImageIcon(FSkin.getAvatars().get(Integer.parseInt(indices[0]))));
|
||||
humanField.getLayoutControl().initialize();
|
||||
humanCommand.getLayoutControl().initialize();
|
||||
|
||||
@@ -107,7 +102,7 @@ public enum CMatchUI {
|
||||
// A field must be initialized after it's instantiated, to update player info.
|
||||
// No player, no init.
|
||||
VField f = new VField(EDocID.valueOf("FIELD_" + i), p, localPlayer);
|
||||
setAvatar(f, getPlayerAvatar(p, Integer.parseInt(indices[i % 2])));
|
||||
setAvatar(f, getPlayerAvatar(p, Integer.parseInt(indices[1])));
|
||||
f.getLayoutControl().initialize();
|
||||
fields.add(f);
|
||||
VCommand c = new VCommand(EDocID.valueOf("COMMAND_" + i), p);
|
||||
|
||||
@@ -187,9 +187,14 @@ public class VAssignDamage {
|
||||
this.damage.put(null, dt);
|
||||
this.defenders.add(dt);
|
||||
Card fakeCard;
|
||||
if( defender instanceof Card )
|
||||
if (defender instanceof Card)
|
||||
fakeCard = (Card)defender;
|
||||
else {
|
||||
else if (defender instanceof Player) {
|
||||
fakeCard = new Card();
|
||||
fakeCard.setName(this.defender.getName());
|
||||
Player p = (Player)defender;
|
||||
fakeCard.setImageKey(p.getLobbyPlayer().getIconImageKey());
|
||||
} else {
|
||||
fakeCard = new Card();
|
||||
fakeCard.setName(this.defender.getName());
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class BoosterPack extends OpenablePack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getImageFilename() {
|
||||
public final String getImageKey() {
|
||||
return ImageCache.BOOSTER_PREFIX + this.contents.getEdition();
|
||||
}
|
||||
|
||||
|
||||
@@ -139,15 +139,15 @@ public final class CardPrinted implements Comparable<IPaperCard>, InventoryItemF
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
public String getImageKey() {
|
||||
return getImageLocator(getImageName(), getArtIndex(), true, false);
|
||||
}
|
||||
|
||||
public String getImageFilename(boolean backFace) {
|
||||
return getImageFilename(backFace, getArtIndex(), true);
|
||||
public String getImageKey(boolean backFace) {
|
||||
return getImageKey(backFace, getArtIndex(), true);
|
||||
}
|
||||
|
||||
public String getImageFilename(boolean backFace, int artIdx, boolean includeSet) {
|
||||
public String getImageKey(boolean backFace, int artIdx, boolean includeSet) {
|
||||
final String nameToUse;
|
||||
if (backFace) {
|
||||
if (null == card.getOtherPart()) {
|
||||
|
||||
@@ -61,7 +61,7 @@ public class CardToken implements InventoryItemFromSet, IPaperCard {
|
||||
|
||||
@Override public CardRarity getRarity() { return CardRarity.Common; } // They don't have rarity though!
|
||||
|
||||
@Override public String getImageFilename() { return imageFileName; }
|
||||
@Override public String getImageKey() { return imageFileName; }
|
||||
|
||||
@Override public String getItemType() { return "Token"; }
|
||||
@Override public Card getMatchingForgeCard() { return toForgeCard(null); } // hope this won't be queried too frequently, so no cache
|
||||
|
||||
@@ -52,7 +52,7 @@ public class FatPack extends OpenablePack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getImageFilename() {
|
||||
public final String getImageKey() {
|
||||
return ImageCache.FATPACK_PREFIX + this.contents.getEdition();
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ public interface IPaperCard {
|
||||
public abstract boolean isToken();
|
||||
public abstract CardRules getRules();
|
||||
public abstract CardRarity getRarity();
|
||||
public abstract String getImageFilename();
|
||||
public abstract String getImageKey();
|
||||
|
||||
public abstract String getItemType();
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ public interface InventoryItem {
|
||||
*
|
||||
* @return the image filename
|
||||
*/
|
||||
String getImageFilename();
|
||||
String getImageKey();
|
||||
|
||||
/**
|
||||
* Return type as a string.
|
||||
|
||||
@@ -59,7 +59,7 @@ public class PreconDeck implements InventoryItemFromSet {
|
||||
* @see forge.item.InventoryItemFromSet#getImageFilename()
|
||||
*/
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
public String getImageKey() {
|
||||
return ImageCache.PRECON_PREFIX + imageFilename;
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class TournamentPack extends OpenablePack {
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getImageFilename() {
|
||||
public final String getImageKey() {
|
||||
return ImageCache.TOURNAMENTPACK_PREFIX + contents.getEdition();
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import forge.deck.Deck;
|
||||
import forge.game.player.IHasIcon;
|
||||
import forge.item.InventoryItem;
|
||||
|
||||
/**
|
||||
@@ -32,177 +33,74 @@ import forge.item.InventoryItem;
|
||||
* MODEL - A basic event instance in Quest mode. Can be extended for use in
|
||||
* unique event types: battles, quests, and others.
|
||||
*/
|
||||
public abstract class QuestEvent {
|
||||
public abstract class QuestEvent implements IHasIcon {
|
||||
// Default vals if none provided in the event file.
|
||||
/** The event deck. */
|
||||
private Deck eventDeck = null;
|
||||
|
||||
/** The title. */
|
||||
private String title = "Mystery Event";
|
||||
|
||||
/** The description. */
|
||||
private String description = "";
|
||||
|
||||
/** The difficulty. */
|
||||
private String difficulty = "Medium";
|
||||
|
||||
/** Filename of the icon for this event. */
|
||||
private String iconFilename = "unknown";
|
||||
|
||||
/** The name. */
|
||||
private String imageKey = "";
|
||||
private String name = "Noname";
|
||||
|
||||
/** The card reward. */
|
||||
private String cardReward = null;
|
||||
|
||||
/** The card reward list. */
|
||||
private List<InventoryItem> cardRewardList = null;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getTitle.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String}.
|
||||
*/
|
||||
public final String getTitle() {
|
||||
return this.title;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getOpponent.
|
||||
* Returns null for standard quest events, may return something different for challenges.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String}.
|
||||
*/
|
||||
public String getOpponent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDifficulty.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String}.
|
||||
*/
|
||||
public final String getDifficulty() {
|
||||
return this.difficulty;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getDescription.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String}.
|
||||
*/
|
||||
public final String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getEventDeck.
|
||||
* </p>
|
||||
*
|
||||
* @return {@link forge.deck.Deck}
|
||||
*/
|
||||
public final Deck getEventDeck() {
|
||||
return this.eventDeck;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getIconFilename.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String}.
|
||||
*/
|
||||
public final String getIconFilename() {
|
||||
return this.iconFilename;
|
||||
@Override
|
||||
public final String getIconImageKey() {
|
||||
return this.imageKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getName.
|
||||
* </p>
|
||||
*
|
||||
* @return a {@link java.lang.String}.
|
||||
*/
|
||||
public final String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the name.
|
||||
*
|
||||
* @param name0
|
||||
* the name to set
|
||||
*/
|
||||
public void setName(final String name0) {
|
||||
this.name = name0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the title.
|
||||
*
|
||||
* @param title0
|
||||
* the title to set
|
||||
*/
|
||||
public void setTitle(final String title0) {
|
||||
this.title = title0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the difficulty.
|
||||
*
|
||||
* @param difficulty0
|
||||
* the difficulty to set
|
||||
*/
|
||||
public void setDifficulty(final String difficulty0) {
|
||||
this.difficulty = difficulty0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the description.
|
||||
*
|
||||
* @param description0
|
||||
* the description to set
|
||||
*/
|
||||
public void setDescription(final String description0) {
|
||||
this.description = description0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the event deck.
|
||||
*
|
||||
* @param eventDeck0
|
||||
* the eventDeck to set
|
||||
*/
|
||||
public void setEventDeck(final Deck eventDeck0) {
|
||||
this.eventDeck = eventDeck0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the icon filename.
|
||||
*
|
||||
* @param s0
|
||||
* filename of the icon to set
|
||||
*/
|
||||
public void setIconFilename(final String s0) {
|
||||
this.iconFilename = s0;
|
||||
@Override
|
||||
public void setIconImageKey(final String s0) {
|
||||
this.imageKey = s0;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getCardRewardList.
|
||||
* </p>
|
||||
*
|
||||
* @return the card reward list
|
||||
*/
|
||||
public final List<InventoryItem> getCardRewardList() {
|
||||
if (cardReward == null) {
|
||||
return null;
|
||||
@@ -213,12 +111,6 @@ public abstract class QuestEvent {
|
||||
return this.cardRewardList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the card reward.
|
||||
*
|
||||
* @param cardReward0
|
||||
* the cardReward to set
|
||||
*/
|
||||
public void setCardReward(final String cardReward0) {
|
||||
this.cardReward = cardReward0;
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.ImageCache;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.io.DeckSerializer;
|
||||
@@ -396,7 +397,7 @@ public class QuestEventManager {
|
||||
} else if (key.equalsIgnoreCase("Description")) {
|
||||
qe.setDescription(value);
|
||||
} else if (key.equalsIgnoreCase("Icon")) {
|
||||
qe.setIconFilename(value);
|
||||
qe.setIconImageKey(ImageCache.ICON_PREFIX + value);
|
||||
} else if (key.equalsIgnoreCase("Card Reward")) {
|
||||
qe.setCardReward(value);
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class QuestRewardCardChooser implements InventoryItem {
|
||||
* @return an empty string
|
||||
*/
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
public String getImageKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public class QuestRewardCardDuplicate implements IQuestRewardCard {
|
||||
* @return an empty string
|
||||
*/
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
public String getImageKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ public class QuestRewardCardFiltered implements IQuestRewardCard {
|
||||
* @return an empty string
|
||||
*/
|
||||
@Override
|
||||
public String getImageFilename() {
|
||||
public String getImageKey() {
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
@@ -315,8 +315,8 @@ public class CardPanel extends JPanel implements CardContainer {
|
||||
// + White borders for Core sets Unlimited - 9th +
|
||||
final int cornerSize = Math.max(4, Math.round(this.cardWidth * CardPanel.ROUNDED_CORNER_SIZE));
|
||||
|
||||
if (this.getGameCard() != null && this.getGameCard().getImageFilename() != null
|
||||
&& !this.getGameCard().getImageFilename().equals("none") && !this.getGameCard().getName().equals("Morph")) {
|
||||
if (this.getGameCard() != null && this.getGameCard().getImageKey() != null
|
||||
&& !this.getGameCard().getImageKey().equals("none") && !this.getGameCard().getName().equals("Morph")) {
|
||||
CardEdition ed = Singletons.getModel().getEditions().get(this.getGameCard().getCurSetCode());
|
||||
|
||||
if (ed != null && ed.isWhiteBorder()) {
|
||||
|
||||
Reference in New Issue
Block a user