Displaying set images in tool tips.

This commit is contained in:
magenoxx 2011-01-17 03:05:22 +03:00
parent 4333603e0e
commit 66c04db9f4
9 changed files with 151 additions and 64 deletions

View file

@ -126,8 +126,8 @@ public class MageFrame extends javax.swing.JFrame {
logger.log(Level.SEVERE, null, ex);
}
ManaSymbols.loadImages();
Plugins.getInstance().loadPlugins();
ManaSymbols.loadImages();
initComponents();
setSize(1024, 768);
@ -229,6 +229,9 @@ public class MageFrame extends javax.swing.JFrame {
private void addTooltipContainer() {
final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane();
if (cardInfoPane == null) {
return;
}
cardInfoPane.setSize(320, 201);
cardInfoPane.setLocation(40, 40);
cardInfoPane.setBackground(new Color(0, 0, 0, 0));

View file

@ -6,9 +6,12 @@ import mage.client.util.gui.BufferedImageBuilder;
import mage.client.util.gui.ImageResizeUtil;
import org.apache.log4j.Logger;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -19,13 +22,13 @@ public class ManaSymbols {
private static final Logger log = Logger.getLogger(ManaSymbols.class);
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, Image> setImages = new HashMap<String, Image>();
static private final Map<String, Image> setImages = new HashMap<String, Image>();
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
static private boolean noManaSymbols = false;
static private boolean noManaSymbols = false;
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", "X" /*, "Y", "Z", "slash"*/};
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", "X" /*, "Y", "Z", "slash"*/};
for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_LARGE + "/" + symbol + ".jpg");
Rectangle r = new Rectangle(11, 11);
@ -34,43 +37,81 @@ public class ManaSymbols {
BufferedImage resized = ImageResizeUtil.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
manaImages.put(symbol, resized);
} catch (Exception e) {
noManaSymbols = true;
}
noManaSymbols = true;
}
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) {}
} 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 {
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 = ImageResizeUtil.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
setImages.put(set, resized);
}
} else {
setImages.put(set, image);
}
} catch (Exception e) {}
}
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 = ImageResizeUtil.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();
}
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 = ImageResizeUtil.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();
}
}
}
} catch (Exception e) {
}
}
}
static public Image getManaSymbolImage(String symbol) {
return manaImagesOriginal.get(symbol);
}
static public Image getSetSymbolImage(String set) {
static public Image getSetSymbolImage(String set) {
return setImages.get(set);
}
static public void draw (Graphics g, String manaCost, int x, int y) {
static public void draw(Graphics g, String manaCost, int x, int y) {
if (manaCost.length() == 0) return;
manaCost = manaCost.replace("\\", "");
manaCost = UI.getDisplayManaCost(manaCost);
@ -94,7 +135,7 @@ public class ManaSymbols {
}
return sb.toString().replace("{", "").replace("}", " ").trim();
}
static public int getWidth(String manaCost) {
int width = 0;
manaCost = manaCost.replace("\\", "");
@ -106,16 +147,16 @@ public class ManaSymbols {
return width;
}
static public synchronized String replaceSymbolsWithHTML (String value, boolean small) {
if (noManaSymbols) {
return value;
} else {
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 synchronized String replaceSymbolsWithHTML(String value, boolean small) {
if (noManaSymbols) {
return value;
} else {
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>");
}
}
}
}

View file

@ -78,6 +78,7 @@ public final class Constants {
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + "symbols" + File.separator + "large";
public static final String RESOURCE_PATH_MANA_MEDIUM = IO.imageBaseDir + "symbols" + File.separator + "medium";
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
public static final String BASE_SOUND_PATH = "plugins" + File.separator + "sounds" + File.separator;
public interface IO {

View file

@ -1,8 +1,6 @@
package org.mage.card.arcane;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
@ -16,15 +14,22 @@ import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.utils.BufferedImageBuilder;
import javax.imageio.ImageIO;
public class ManaSymbols {
private static final Logger log = Logger.getLogger(ManaSymbols.class);
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("\\{([^}/]*)/?([^}]*)\\}");
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", "X", "Y", "Z", "slash"};
private static final String[] sets = {"DIS", "GPT", "RAV", "MRD",
"10E", "HOP", "ALA", "CFX", "ARB", "ZEN", "WWK", "ROE", "SOM", "M10", "M11"};
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", "X", "Y", "Z", "slash"};
for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_LARGE + "/" + symbol + ".jpg");
Rectangle r = new Rectangle(11, 11);
@ -32,20 +37,37 @@ public class ManaSymbols {
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) {}
} 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) {}
} 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) {
}
}
}
static public Image getManaSymbolImage(String symbol) {
return manaImagesOriginal.get(symbol);
}
static public void draw (Graphics g, String manaCost, int x, int y) {
static public void draw(Graphics g, String manaCost, int x, int y) {
if (manaCost.length() == 0) return;
manaCost = manaCost.replace("\\", "");
manaCost = UI.getDisplayManaCost(manaCost);
@ -69,7 +91,7 @@ public class ManaSymbols {
}
return sb.toString().replace("{", "").replace("}", " ").trim();
}
static public int getWidth(String manaCost) {
int width = 0;
manaCost = manaCost.replace("\\", "");
@ -81,7 +103,7 @@ public class ManaSymbols {
return width;
}
static public synchronized String replaceSymbolsWithHTML (String value, boolean small) {
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 {
@ -89,4 +111,14 @@ public class ManaSymbols {
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) {
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;
}
}
}

View file

@ -73,7 +73,7 @@ public class CardPluginImpl implements CardPlugin {
}
public String toString() {
return "[Card plugin, version 0.4]";
return "[Card plugin, version 0.5]";
}
@Override

View file

@ -6,7 +6,10 @@ import java.io.File;
public class Constants {
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + "symbols" + File.separator + "large";
public static final String RESOURCE_PATH_MANA_MEDIUM = IO.imageBaseDir + "symbols" + File.separator + "medium";
public static final String RESOURCE_PATH_SET = IO.imageBaseDir + "sets" + File.separator;
public static final String RESOURCE_PATH_SET_SMALL = RESOURCE_PATH_SET + File.separator + "small" + File.separator;
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
public interface IO {

View file

@ -92,8 +92,9 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
buffer.append("<b color='#D5330B'>");
break;
}
buffer.append(card.getExpansionSetCode().toUpperCase());
buffer.append("</td></tr></table>");
String rarity = card.getRarity().getCode();
buffer.append(ManaSymbols.replaceSetCodeWithHTML(card.getExpansionSetCode().toUpperCase(), rarity));
buffer.append("</td></tr></table>");
String pt = "";
if (CardUtil.isCreature(card)) {
@ -137,6 +138,7 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
setText(buffer.toString());
//System.out.println(buffer.toString());
setCaretPosition(0);
//ThreadUtils.sleep(300);
}
});
}

View file

@ -90,19 +90,21 @@ public final class Constants {
public enum Rarity {
NA ("na", "na"),
LAND ("Land", "common"),
COMMON ("Common", "common"),
UNCOMMON ("Uncommon", "uncommon"),
RARE ("Rare", "rare"),
MYTHIC ("Mythic", "mythic");
NA ("na", "na", "N"),
LAND ("Land", "common", "C"),
COMMON ("Common", "common", "C"),
UNCOMMON ("Uncommon", "uncommon", "U"),
RARE ("Rare", "rare", "R"),
MYTHIC ("Mythic", "mythic", "M");
private String text;
private String symbolCode;
private String code;
Rarity(String text, String symbolCode) {
Rarity(String text, String symbolCode, String code) {
this.text = text;
this.symbolCode = symbolCode;
this.code = code;
}
@Override
@ -114,6 +116,9 @@ public final class Constants {
return symbolCode;
}
public String getCode() {
return code;
}
}
public enum AbilityType {