Removed a couple of duplicate files.

This commit is contained in:
North 2011-09-02 00:18:04 +03:00
parent 8ec8be115c
commit e8426e6e71
13 changed files with 171 additions and 618 deletions

View file

@ -1,6 +1,9 @@
package org.mage.card.arcane;
import java.awt.*;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
@ -8,125 +11,171 @@ import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import mage.client.cards.CardsStorage;
import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder;
import org.apache.log4j.Logger;
import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.utils.BufferedImageBuilder;
public class ManaSymbols {
static private final Map<String, Image> manaImages = new HashMap<String, Image>();
static private final Map<String, Image> manaImagesOriginal = new HashMap<String, Image>();
static private final Map<String, Dimension> setImagesExist = new HashMap<String, Dimension>();
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
private static final String[] sets = {
"10E", "M10", "M11", "M12",
"HOP", "DDF",
"TMP", "INV", "PLS", "APC",
"MRD", "DST", "5DN", "CHK", "RAV", "GPT", "DIS",
"LRW", "MOR", "SHM", "EVE", "ALA", "CFX", "ARB",
"ZEN", "WWK", "ROE", "SOM", "MBS", "NPH"
};
private static final Logger log = Logger.getLogger(ManaSymbols.class);
static private final Map<String, BufferedImage> manaImages = new HashMap<String, BufferedImage>();
static private final Map<String, Image> manaImagesOriginal = new HashMap<String, Image>();
static private final Map<String, Image> setImages = new HashMap<String, Image>();
static private final Map<String, Dimension> setImagesExist = new HashMap<String, Dimension>();
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
static public void loadImages() {
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", "B", "BG",
"BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
"WP", "UP", "BP", "RP", "GP", "X" /*, "Y", "Z", "slash"*/};
for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
Rectangle r = new Rectangle(11, 11);
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
manaImages.put(symbol, resized);
} catch (Exception e) {
log.error("Error for symbol:" + symbol);
//e.printStackTrace();
}
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
manaImagesOriginal.put(symbol, image);
} catch (Exception e) {
}
}
for (String set : CardsStorage.getSetCodes()) {
String _set = set.equals("CON") ? "CFX" : set;
File file = new File(Constants.RESOURCE_PATH_SET + _set + "-C.jpg");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
int width = image.getWidth(null);
if (width > 21) {
int h = image.getHeight(null);
if (h > 0) {
Rectangle r = new Rectangle(21, (int) (h * 21.0f / width));
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
setImages.put(set, resized);
}
} else {
setImages.put(set, image);
}
} catch (Exception e) {
}
String[] codes = new String[]{"C", "U", "R", "M"};
try {
file = new File(Constants.RESOURCE_PATH_SET_SMALL);
if (!file.exists()) {
file.mkdirs();
}
static public void loadImages() {
String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9",
"B", "BG", "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
"WP", "UP", "BP", "RP", "GP", "X", "Y", "Z", "slash"};
for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
Rectangle r = new Rectangle(11, 11);
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
BufferedImage resized = ImageCache.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
manaImages.put(symbol, resized);
} catch (Exception e) {
}
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
manaImagesOriginal.put(symbol, image);
} catch (Exception e) {
}
}
File file;
for (String set : sets) {
file = new File(Constants.RESOURCE_PATH_SET_SMALL);
if (!file.exists()) {
break;
}
file = new File(Constants.RESOURCE_PATH_SET_SMALL + set + "-C.png");
try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
int width = image.getWidth(null);
int height = image.getHeight(null);
setImagesExist.put(set, new Dimension(width, height));
} catch (Exception e) {
}
}
}
for (String code : codes) {
file = new File(Constants.RESOURCE_PATH_SET_SMALL + set + "-" + code + ".png");
if (file.exists()) {
continue;
}
file = new File(Constants.RESOURCE_PATH_SET + _set + "-" + code + ".jpg");
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
try {
int width = image.getWidth(null);
int height = image.getHeight(null);
if (height > 0) {
int dx = 0;
if (set.equals("M10") || set.equals("M11")) {
dx = 6;
}
Rectangle r = new Rectangle(15 + dx, (int) (height * (15.0f + dx) / width));
BufferedImage resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
File newFile = new File(Constants.RESOURCE_PATH_SET_SMALL + File.separator + _set + "-" + code + ".png");
ImageIO.write(resized, "png", newFile);
}
} catch (Exception e) {
if (file != null && file.exists()) {
file.delete();
}
}
}
static public Image getManaSymbolImage(String symbol) {
return manaImagesOriginal.get(symbol);
}
} catch (Exception e) {
}
}
}
static public void draw(Graphics g, String manaCost, int x, int y) {
if (manaCost.length() == 0) return;
manaCost = manaCost.replace("\\", "");
manaCost = UI.getDisplayManaCost(manaCost);
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
Image image = manaImages.get(symbol);
if (image == null) {
//log.error("Symbol not recognized \"" + symbol + "\" in mana cost: " + manaCost);
continue;
}
g.drawImage(image, x, y, null);
x += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
}
static public Image getManaSymbolImage(String symbol) {
return manaImagesOriginal.get(symbol);
}
static public String getStringManaCost(List<String> manaCost) {
StringBuilder sb = new StringBuilder();
for (String s : manaCost) {
sb.append(s);
}
return sb.toString().replace("{", "").replace("}", " ").trim();
}
static public void draw(Graphics g, String manaCost, int x, int y) {
if (manaCost.length() == 0) {
return;
}
manaCost = manaCost.replace("\\", "");
manaCost = UI.getDisplayManaCost(manaCost);
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
Image image = manaImages.get(symbol);
if (image == null) {
//log.error("Symbol not recognized \"" + symbol + "\" in mana cost: " + manaCost);
continue;
}
g.drawImage(image, x, y, null);
x += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
}
static public int getWidth(String manaCost) {
int width = 0;
manaCost = manaCost.replace("\\", "");
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
width += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
return width;
}
static public String getStringManaCost(List<String> manaCost) {
StringBuilder sb = new StringBuilder();
for (String s : manaCost) {
sb.append(s);
}
return sb.toString().replace("{", "").replace("}", " ").trim();
}
static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
if (small)
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>");
else {
value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>");
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=13 height=13>");
}
}
static public int getWidth(String manaCost) {
int width = 0;
manaCost = manaCost.replace("\\", "");
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
String symbol = tok.nextToken().substring(0);
width += symbol.length() > 2 ? 10 : 12; // slash.png is only 10 pixels wide.
}
return width;
}
static public String replaceSetCodeWithHTML(String set, String rarity) {
String _set = set;
if (_set.equals("CON")) {
_set = "CFX";
}
if (setImagesExist.containsKey(_set)) {
Integer width = setImagesExist.get(_set).width;
Integer height = setImagesExist.get(_set).height;
return "<img src='file:plugins/images/sets/small/" + _set + "-" + rarity + ".png' alt='" + rarity + " ' width=" + width + " height=" + height + ">";
} else {
return set;
}
}
static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
if (small) {
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>");
} else {
value = value.replace("{slash}", "<img src='file:plugins/images/symbols/medium/slash.jpg' alt='slash' width=10 height=13>");
return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/medium/$1$2.jpg' alt='$1$2' width=13 height=13>");
}
}
static public String replaceSetCodeWithHTML(String set, String rarity) {
String _set = set;
if (_set.equals("CON")) {
_set = "CFX";
}
if (setImagesExist.containsKey(_set)) {
Integer width = setImagesExist.get(_set).width;
Integer height = setImagesExist.get(_set).height;
return "<img src='file:plugins/images/sets/small/" + _set + "-" + rarity + ".png' alt='" + rarity + " ' width=" + width + " height=" + height + ">";
} else {
return set;
}
}
static public Image getSetSymbolImage(String set) {
return setImages.get(set);
}
static public BufferedImage getManaSymbolImageSmall(String symbol) {
return manaImages.get(symbol);
}
}

View file

@ -1,71 +0,0 @@
package org.mage.plugins.card.utils;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ImageObserver;
/**
* Utility class for creating BufferedImage object from Image instance.
*
* @author nantuko
*/
public class BufferedImageBuilder {
private static final int DEFAULT_IMAGE_TYPE = BufferedImage.TYPE_INT_RGB;
/**
* Hide constructor
*/
private BufferedImageBuilder() {
}
public static BufferedImage bufferImage(Image image) {
return bufferImage(image, DEFAULT_IMAGE_TYPE);
}
public static BufferedImage bufferImage(Image image, int type) {
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), type);
Graphics2D g = bufferedImage.createGraphics();
g.drawImage(image, null, null);
//waitForImage(bufferedImage);
return bufferedImage;
}
private void waitForImage(BufferedImage bufferedImage) {
final ImageLoadStatus imageLoadStatus = new ImageLoadStatus();
bufferedImage.getHeight(new ImageObserver() {
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if (infoflags == ALLBITS) {
imageLoadStatus.heightDone = true;
return true;
}
return false;
}
});
bufferedImage.getWidth(new ImageObserver() {
public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height) {
if (infoflags == ALLBITS) {
imageLoadStatus.widthDone = true;
return true;
}
return false;
}
});
while (!imageLoadStatus.widthDone && !imageLoadStatus.heightDone) {
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
}
class ImageLoadStatus {
public boolean widthDone = false;
public boolean heightDone = false;
}
}

View file

@ -11,7 +11,7 @@ import java.net.URL;
import javax.imageio.ImageIO;
import org.mage.plugins.card.utils.BufferedImageBuilder;
import mage.client.util.gui.BufferedImageBuilder;
import org.mage.plugins.card.utils.ImageManager;
import org.mage.plugins.card.utils.Transparency;