mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Displaying set images in tool tips.
This commit is contained in:
parent
4333603e0e
commit
66c04db9f4
9 changed files with 151 additions and 64 deletions
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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>");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue