mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 11:32:00 -08:00
Fixed a bug that the mana symbols for monocolored hybrid mana were not shown.
This commit is contained in:
parent
2fb8926432
commit
fe5743b29e
2 changed files with 82 additions and 83 deletions
|
|
@ -1,6 +1,14 @@
|
||||||
package org.mage.card.arcane;
|
package org.mage.card.arcane;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Color;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.Toolkit;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.awt.image.FilteredImageSource;
|
import java.awt.image.FilteredImageSource;
|
||||||
import java.awt.image.ImageProducer;
|
import java.awt.image.ImageProducer;
|
||||||
|
|
@ -18,13 +26,18 @@ import java.nio.file.Paths;
|
||||||
import java.nio.file.SimpleFileVisitor;
|
import java.nio.file.SimpleFileVisitor;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
import java.nio.file.attribute.BasicFileAttributes;
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import javax.imageio.ImageIO;
|
import javax.imageio.ImageIO;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
|
||||||
import mage.cards.repository.ExpansionRepository;
|
import mage.cards.repository.ExpansionRepository;
|
||||||
|
import mage.client.constants.Constants;
|
||||||
|
import mage.client.constants.Constants.ResourceSetSize;
|
||||||
|
import mage.client.constants.Constants.ResourceSymbolSize;
|
||||||
import mage.client.util.GUISizeHelper;
|
import mage.client.util.GUISizeHelper;
|
||||||
import mage.client.util.ImageHelper;
|
import mage.client.util.ImageHelper;
|
||||||
import mage.client.util.gui.BufferedImageBuilder;
|
import mage.client.util.gui.BufferedImageBuilder;
|
||||||
|
|
@ -36,13 +49,6 @@ import org.apache.batik.transcoder.TranscodingHints;
|
||||||
import org.apache.batik.transcoder.image.ImageTranscoder;
|
import org.apache.batik.transcoder.image.ImageTranscoder;
|
||||||
import org.apache.batik.util.SVGConstants;
|
import org.apache.batik.util.SVGConstants;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import mage.client.constants.Constants;
|
|
||||||
import mage.client.constants.Constants.ResourceSymbolSize;
|
|
||||||
import mage.client.constants.Constants.ResourceSetSize;
|
|
||||||
|
|
||||||
import org.jdesktop.swingx.graphics.ShadowRenderer;
|
|
||||||
import org.jdesktop.swingx.graphics.GraphicsUtilities;
|
|
||||||
import org.mage.plugins.card.utils.CardImageUtils;
|
import org.mage.plugins.card.utils.CardImageUtils;
|
||||||
|
|
||||||
public final class ManaSymbols {
|
public final class ManaSymbols {
|
||||||
|
|
@ -71,9 +77,14 @@ public final class ManaSymbols {
|
||||||
private static final Map<String, Dimension> setImagesExist = new HashMap<>();
|
private static final Map<String, Dimension> setImagesExist = new HashMap<>();
|
||||||
private static final Pattern REPLACE_SYMBOLS_PATTERN = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
private static final Pattern REPLACE_SYMBOLS_PATTERN = Pattern.compile("\\{([^}/]*)/?([^}]*)\\}");
|
||||||
private static String cachedPath;
|
private static String cachedPath;
|
||||||
private static final String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9", "B", "BG",
|
private static final String[] symbols = new String[]{"0", "1", "10", "11", "12", "15", "16", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||||
"BR", "G", "GU", "GW", "R", "RG", "RW", "S", "T", "U", "UB", "UR", "W", "WB", "WU",
|
"B", "BG", "BR", "BP", "2B",
|
||||||
"WP", "UP", "BP", "RP", "GP", "X", "C", "E"};
|
"G", "GU", "GW", "GP", "2G",
|
||||||
|
"R", "RG", "RW", "RP", "2R",
|
||||||
|
"S", "T",
|
||||||
|
"U", "UB", "UR", "UP", "2U",
|
||||||
|
"W", "WB", "WU", "WP", "2W",
|
||||||
|
"X", "C", "E"};
|
||||||
|
|
||||||
private static final JLabel labelRender = new JLabel(); // render mana text
|
private static final JLabel labelRender = new JLabel(); // render mana text
|
||||||
|
|
||||||
|
|
@ -101,8 +112,7 @@ public final class ManaSymbols {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String symbol : symbols) {
|
for (String symbol : symbols) {
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
BufferedImage image = pngImages.get(symbol);
|
BufferedImage image = pngImages.get(symbol);
|
||||||
if (image != null) {
|
if (image != null) {
|
||||||
File newFile = new File(pngPath.getPath() + File.separator + symbol + ".png");
|
File newFile = new File(pngPath.getPath() + File.separator + symbol + ".png");
|
||||||
|
|
@ -222,7 +232,6 @@ public final class ManaSymbols {
|
||||||
// load SVG image
|
// load SVG image
|
||||||
// base loader code: https://stackoverflow.com/questions/11435671/how-to-get-a-buffererimage-from-a-svg
|
// base loader code: https://stackoverflow.com/questions/11435671/how-to-get-a-buffererimage-from-a-svg
|
||||||
// resize code: https://vibranttechie.wordpress.com/2015/05/15/svg-loading-to-javafx-stage-and-auto-scaling-when-stage-resize/
|
// resize code: https://vibranttechie.wordpress.com/2015/05/15/svg-loading-to-javafx-stage-and-auto-scaling-when-stage-resize/
|
||||||
|
|
||||||
if (useShadow && ((resizeToWidth <= 0) || (resizeToHeight <= 0))) {
|
if (useShadow && ((resizeToWidth <= 0) || (resizeToHeight <= 0))) {
|
||||||
throw new IllegalArgumentException("Must use non zero sizes for shadow.");
|
throw new IllegalArgumentException("Must use non zero sizes for shadow.");
|
||||||
}
|
}
|
||||||
|
|
@ -234,12 +243,12 @@ public final class ManaSymbols {
|
||||||
// These defaults emphasize quality and precision, and
|
// These defaults emphasize quality and precision, and
|
||||||
// are more similar to the defaults of other SVG viewers.
|
// are more similar to the defaults of other SVG viewers.
|
||||||
// SVG documents can still override these defaults.
|
// SVG documents can still override these defaults.
|
||||||
String css = "svg {" +
|
String css = "svg {"
|
||||||
"shape-rendering: geometricPrecision;" +
|
+ "shape-rendering: geometricPrecision;"
|
||||||
"text-rendering: geometricPrecision;" +
|
+ "text-rendering: geometricPrecision;"
|
||||||
"color-rendering: optimizeQuality;" +
|
+ "color-rendering: optimizeQuality;"
|
||||||
"image-rendering: optimizeQuality;" +
|
+ "image-rendering: optimizeQuality;"
|
||||||
"}";
|
+ "}";
|
||||||
File cssFile = File.createTempFile("batik-default-override-", ".css");
|
File cssFile = File.createTempFile("batik-default-override-", ".css");
|
||||||
FileWriter w = new FileWriter(cssFile);
|
FileWriter w = new FileWriter(cssFile);
|
||||||
w.write(css);
|
w.write(css);
|
||||||
|
|
@ -293,8 +302,7 @@ public final class ManaSymbols {
|
||||||
t.transcode(input, null);
|
t.transcode(input, null);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IOException("Couldn't convert svg file: " + svgFile + " , reason: " + e.getMessage());
|
throw new IOException("Couldn't convert svg file: " + svgFile + " , reason: " + e.getMessage());
|
||||||
}
|
} finally {
|
||||||
finally {
|
|
||||||
cssFile.delete();
|
cssFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -309,11 +317,12 @@ public final class ManaSymbols {
|
||||||
ImageProducer prod = new FilteredImageSource(originImage.getSource(), new RGBImageFilter() {
|
ImageProducer prod = new FilteredImageSource(originImage.getSource(), new RGBImageFilter() {
|
||||||
@Override
|
@Override
|
||||||
public int filterRGB(int x, int y, int rgb) {
|
public int filterRGB(int x, int y, int rgb) {
|
||||||
if (rgb == 0)
|
if (rgb == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
else
|
} else {
|
||||||
return 0xff000000;
|
return 0xff000000;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// create whe black image
|
// create whe black image
|
||||||
Image shadow = Toolkit.getDefaultToolkit().createImage(prod);
|
Image shadow = Toolkit.getDefaultToolkit().createImage(prod);
|
||||||
|
|
@ -341,7 +350,6 @@ public final class ManaSymbols {
|
||||||
Color.GRAY);
|
Color.GRAY);
|
||||||
return renderer.createShadow(base);
|
return renderer.createShadow(base);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//imagePointer[0];
|
//imagePointer[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -503,8 +511,7 @@ public final class ManaSymbols {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix double separator if size folder is not set
|
// fix double separator if size folder is not set
|
||||||
while(path.endsWith(File.separator))
|
while (path.endsWith(File.separator)) {
|
||||||
{
|
|
||||||
path = path.substring(0, path.length() - 1);
|
path = path.substring(0, path.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -533,8 +540,7 @@ public final class ManaSymbols {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix double separator if size folder is not set
|
// fix double separator if size folder is not set
|
||||||
while(path.endsWith(File.separator))
|
while (path.endsWith(File.separator)) {
|
||||||
{
|
|
||||||
path = path.substring(0, path.length() - 1);
|
path = path.substring(0, path.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -593,9 +599,6 @@ public final class ManaSymbols {
|
||||||
manaPanel.paint(gg);
|
manaPanel.paint(gg);
|
||||||
g.drawImage(image, x, y, null);
|
g.drawImage(image, x, y, null);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// OLD version with custom draw
|
// OLD version with custom draw
|
||||||
Map<String, BufferedImage> sizedSymbols = manaImages.get(symbolWidth);
|
Map<String, BufferedImage> sizedSymbols = manaImages.get(symbolWidth);
|
||||||
if (manaCost.isEmpty()) {
|
if (manaCost.isEmpty()) {
|
||||||
|
|
@ -680,7 +683,6 @@ public final class ManaSymbols {
|
||||||
|
|
||||||
// mana cost to HTML images (urls to files)
|
// mana cost to HTML images (urls to files)
|
||||||
// do not use it for new code - try to suppotr svg render
|
// do not use it for new code - try to suppotr svg render
|
||||||
|
|
||||||
int symbolSize;
|
int symbolSize;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case TABLE:
|
case TABLE:
|
||||||
|
|
@ -711,13 +713,11 @@ public final class ManaSymbols {
|
||||||
}
|
}
|
||||||
|
|
||||||
// replace every {symbol} to <img> link
|
// replace every {symbol} to <img> link
|
||||||
|
|
||||||
// ignore data backup
|
// ignore data backup
|
||||||
String replaced = value
|
String replaced = value
|
||||||
.replace("{source}", "|source|")
|
.replace("{source}", "|source|")
|
||||||
.replace("{this}", "|this|");
|
.replace("{this}", "|this|");
|
||||||
|
|
||||||
|
|
||||||
// not need to add different images (width and height do the work)
|
// not need to add different images (width and height do the work)
|
||||||
// use best png size (generated on startup) TODO: add reload images after update
|
// use best png size (generated on startup) TODO: add reload images after update
|
||||||
String htmlImagesPath = getResourceSymbolsPath(ResourceSymbolSize.PNG);
|
String htmlImagesPath = getResourceSymbolsPath(ResourceSymbolSize.PNG);
|
||||||
|
|
@ -774,4 +774,3 @@ public final class ManaSymbols {
|
||||||
return sizedSymbols.get(symbol);
|
return sizedSymbols.get(symbol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,6 @@ import com.google.common.collect.AbstractIterator;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import static java.lang.String.format;
|
import static java.lang.String.format;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import mage.client.constants.Constants;
|
import mage.client.constants.Constants;
|
||||||
import org.mage.plugins.card.dl.DownloadJob;
|
import org.mage.plugins.card.dl.DownloadJob;
|
||||||
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
|
import static org.mage.plugins.card.dl.DownloadJob.fromURL;
|
||||||
|
|
@ -76,8 +75,9 @@ public class GathererSymbols implements Iterable<DownloadJob> {
|
||||||
File dst = new File(dir, symbol + ".gif");
|
File dst = new File(dir, symbol + ".gif");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle a bug on Gatherer where a few symbols are missing at the large size.
|
* Handle a bug on Gatherer where a few symbols are missing
|
||||||
* Fall back to using the medium symbol for those cases.
|
* at the large size. Fall back to using the medium symbol
|
||||||
|
* for those cases.
|
||||||
*/
|
*/
|
||||||
int modSizeIndex = sizeIndex;
|
int modSizeIndex = sizeIndex;
|
||||||
if (sizeIndex == 2) {
|
if (sizeIndex == 2) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue