Mana symbols in ColorsChooser for deck generator.

This commit is contained in:
magenoxx 2010-11-30 18:14:15 +00:00
parent 2e86ffa300
commit 30b341f7d9
9 changed files with 66 additions and 9 deletions

View file

@ -1,5 +1,6 @@
package mage.client.plugins;
import java.awt.Image;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@ -30,4 +31,5 @@ public interface MagePlugins {
void downloadSymbols();
int getGamesPlayed();
void addGamesPlayed();
Image getManaSymbolImage(String symbol);
}

View file

@ -1,5 +1,6 @@
package mage.client.plugins.impl;
import java.awt.Image;
import java.io.File;
import java.util.Collection;
import java.util.Map;
@ -158,4 +159,12 @@ public class Plugins implements MagePlugins {
public boolean isThemePluginLoaded() {
return this.themePlugin != null;
}
@Override
public Image getManaSymbolImage(String symbol) {
if (this.cardPlugin != null) {
return this.cardPlugin.getManaSymbolImage(symbol);
}
return null;
}
}

View file

@ -1,16 +1,23 @@
package mage.client.util.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
import javax.swing.ImageIcon;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Constants;
public class ColorsChooser extends JComboBox implements ListCellRenderer {
@ -41,7 +48,7 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected,
final boolean cellHasFocus) {
final JPanel panel = new JPanel(new GridLayout(1, 3));
final JPanel panel = new JPanel(new FlowLayout());
drawOn(panel, (String) value);
panel.setBorder(Constants.EMPTY_BORDER);
if (isSelected) {
@ -51,7 +58,30 @@ public class ColorsChooser extends JComboBox implements ListCellRenderer {
}
private void drawOn(JPanel panel, String value) {
String s = value.replace("b", "{B}").replace("r", "{R}").replace("g", "{G}").replace("w", "{W}").replace("u", "{U}");
panel.add(new JLabel(s));
List<Image> images = new ArrayList<Image>();
value = value.toUpperCase();
for (int i = 0; i < value.length(); i++) {
char symbol = value.charAt(i);
Image image = Plugins.getInstance().getManaSymbolImage(String.valueOf(symbol));
if (image != null) {
images.add(image);
}
}
if (images.size() == value.length()) {
int dx = 0;
for (Image image : images) {
ImageIcon icon = new ImageIcon(image);
JLabel imageLabel = new JLabel();
imageLabel.setSize(11, 11);
imageLabel.setLocation(dx, 0);
imageLabel.setIcon(icon);
panel.add(imageLabel);
dx += 13;
}
} else {
String s = value.replace("B", "{B}").replace("R", "{R}").replace("G", "{G}").replace("W", "{W}").replace("U", "{U}");
panel.add(new JLabel(s));
}
}
}

View file

@ -10,9 +10,6 @@ import mage.client.components.MageComponents;
import mage.client.components.MageUI;
import mage.util.Logging;
import org.junit.Ignore;
import org.junit.Test;
public class StartMultiGamesTest {
private final static Logger logger = Logging.getLogger(StartMultiGamesTest.class.getName());
@ -31,7 +28,7 @@ public class StartMultiGamesTest {
}
@Test
//@Test
public void testEmpty() {
}

View file

@ -1,5 +1,6 @@
package mage.interfaces.plugin;
import java.awt.Image;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
@ -29,4 +30,5 @@ public interface CardPlugin extends Plugin {
void sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent> cards);
void downloadImages(Set<Card> allCards);
void downloadSymbols();
Image getManaSymbolImage(String symbol);
}

View file

@ -19,13 +19,14 @@ import org.mage.plugins.card.utils.BufferedImageBuilder;
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 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"};
for (String symbol : symbols) {
File file = new File(Constants.RESOURCE_PATH_MANA + "/" + symbol + ".jpg");
File file = new File(Constants.RESOURCE_PATH_MANA_LARGE + "/" + symbol + ".jpg");
BufferedImageBuilder builder = new BufferedImageBuilder();
Rectangle r = new Rectangle(11, 11);
try {
@ -33,9 +34,18 @@ public class ManaSymbols {
BufferedImage resized = ImageCache.getResizedImage(builder.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) {}
}
}
static public Image getManaSymbolImage(String symbol) {
return manaImagesOriginal.get(symbol);
}
static public void draw (Graphics g, String manaCost, int x, int y) {
if (manaCost.length() == 0) return;
manaCost = manaCost.replace("\\", "");

View file

@ -2,6 +2,7 @@ package org.mage.plugins.card;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
@ -427,4 +428,9 @@ public class CardPluginImpl implements CardPlugin {
d.pack();
d.setVisible(true);
}
@Override
public Image getManaSymbolImage(String symbol) {
return ManaSymbols.getManaSymbolImage(symbol);
}
}

View file

@ -4,7 +4,8 @@ import java.awt.Rectangle;
import java.io.File;
public class Constants {
public static final String RESOURCE_PATH_MANA = 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 Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);