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); logger.log(Level.SEVERE, null, ex);
} }
Plugins.getInstance().loadPlugins();
ManaSymbols.loadImages(); ManaSymbols.loadImages();
Plugins.getInstance().loadPlugins();
initComponents(); initComponents();
setSize(1024, 768); setSize(1024, 768);
@ -229,6 +229,9 @@ public class MageFrame extends javax.swing.JFrame {
private void addTooltipContainer() { private void addTooltipContainer() {
final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane(); final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane();
if (cardInfoPane == null) {
return;
}
cardInfoPane.setSize(320, 201); cardInfoPane.setSize(320, 201);
cardInfoPane.setLocation(40, 40); cardInfoPane.setLocation(40, 40);
cardInfoPane.setBackground(new Color(0, 0, 0, 0)); 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 mage.client.util.gui.ImageResizeUtil;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -23,8 +26,8 @@ public class ManaSymbols {
static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}"); static private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
static private boolean noManaSymbols = false; static private boolean noManaSymbols = false;
static public void loadImages () { 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", 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"*/}; "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU", "X" /*, "Y", "Z", "slash"*/};
for (String symbol : symbols) { for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_LARGE + "/" + symbol + ".jpg"); File file = new File(Constants.RESOURCE_PATH_MANA_LARGE + "/" + symbol + ".jpg");
@ -40,7 +43,8 @@ public class ManaSymbols {
try { try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage(); Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
manaImagesOriginal.put(symbol, image); manaImagesOriginal.put(symbol, image);
} catch (Exception e) {} } catch (Exception e) {
}
} }
for (String set : CardsStorage.getSetCodes()) { for (String set : CardsStorage.getSetCodes()) {
String _set = set.equals("CON") ? "CFX" : set; String _set = set.equals("CON") ? "CFX" : set;
@ -51,14 +55,51 @@ public class ManaSymbols {
if (width > 21) { if (width > 21) {
int h = image.getHeight(null); int h = image.getHeight(null);
if (h > 0) { if (h > 0) {
Rectangle r = new Rectangle(21, (int)(h * 21.0f / width)); Rectangle r = new Rectangle(21, (int) (h * 21.0f / width));
BufferedImage resized = ImageResizeUtil.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r); BufferedImage resized = ImageResizeUtil.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
setImages.put(set, resized); setImages.put(set, resized);
} }
} else { } else {
setImages.put(set, image); setImages.put(set, image);
} }
} catch (Exception e) {} } 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) {
}
} }
} }
@ -70,7 +111,7 @@ public class ManaSymbols {
return setImages.get(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; if (manaCost.length() == 0) return;
manaCost = manaCost.replace("\\", ""); manaCost = manaCost.replace("\\", "");
manaCost = UI.getDisplayManaCost(manaCost); manaCost = UI.getDisplayManaCost(manaCost);
@ -106,7 +147,7 @@ public class ManaSymbols {
return width; return width;
} }
static public synchronized String replaceSymbolsWithHTML (String value, boolean small) { static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
if (noManaSymbols) { if (noManaSymbols) {
return value; return value;
} else { } else {

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_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_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 = 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 static final String BASE_SOUND_PATH = "plugins" + File.separator + "sounds" + File.separator;
public interface IO { public interface IO {

View file

@ -1,8 +1,6 @@
package org.mage.card.arcane; package org.mage.card.arcane;
import java.awt.Graphics; import java.awt.*;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.HashMap;
@ -16,14 +14,21 @@ import org.mage.plugins.card.constants.Constants;
import org.mage.plugins.card.images.ImageCache; import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.utils.BufferedImageBuilder; import org.mage.plugins.card.utils.BufferedImageBuilder;
import javax.imageio.ImageIO;
public class ManaSymbols { public class ManaSymbols {
private static final Logger log = Logger.getLogger(ManaSymbols.class); 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> manaImages = new HashMap<String, Image>();
static private final Map<String, Image> manaImagesOriginal = 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 private Pattern replaceSymbolsPattern = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
static public void loadImages () { private static final String[] sets = {"DIS", "GPT", "RAV", "MRD",
String[] symbols = new String[] {"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", "B", "BG", "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"}; "BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU", "X", "Y", "Z", "slash"};
for (String symbol : symbols) { for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA_LARGE + "/" + symbol + ".jpg"); File file = new File(Constants.RESOURCE_PATH_MANA_LARGE + "/" + symbol + ".jpg");
@ -32,12 +37,29 @@ public class ManaSymbols {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage(); Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
BufferedImage resized = ImageCache.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r); BufferedImage resized = ImageCache.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
manaImages.put(symbol, resized); manaImages.put(symbol, resized);
} catch (Exception e) {} } catch (Exception e) {
}
file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg"); file = new File(Constants.RESOURCE_PATH_MANA_MEDIUM + "/" + symbol + ".jpg");
try { try {
Image image = UI.getImageIcon(file.getAbsolutePath()).getImage(); Image image = UI.getImageIcon(file.getAbsolutePath()).getImage();
manaImagesOriginal.put(symbol, image); 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) {
}
} }
} }
@ -45,7 +67,7 @@ public class ManaSymbols {
return manaImagesOriginal.get(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; if (manaCost.length() == 0) return;
manaCost = manaCost.replace("\\", ""); manaCost = manaCost.replace("\\", "");
manaCost = UI.getDisplayManaCost(manaCost); manaCost = UI.getDisplayManaCost(manaCost);
@ -81,7 +103,7 @@ public class ManaSymbols {
return width; return width;
} }
static public synchronized String replaceSymbolsWithHTML (String value, boolean small) { static public synchronized String replaceSymbolsWithHTML(String value, boolean small) {
if (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>"); return replaceSymbolsPattern.matcher(value).replaceAll("<img src='file:plugins/images/symbols/small/$1$2.jpg' alt='$1$2' width=11 height=11>");
else { 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>"); 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() { public String toString() {
return "[Card plugin, version 0.4]"; return "[Card plugin, version 0.5]";
} }
@Override @Override

View file

@ -7,6 +7,9 @@ public class Constants {
public static final String RESOURCE_PATH_MANA_LARGE = IO.imageBaseDir + "symbols" + File.separator + "large"; 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_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 static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
public interface IO { public interface IO {

View file

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

View file

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