Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svg mana icons support #4203

Merged
merged 11 commits into from
Nov 27, 2017
7 changes: 7 additions & 0 deletions Mage.Client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@
<artifactId>balloontip</artifactId>
<version>1.2.4.1</version>
</dependency>
<!-- svg support start -->
<dependency>
<groupId>batik</groupId>
<artifactId>batik-transcoder</artifactId>
<version>1.6-1</version>
</dependency>
<!-- svg support end -->
</dependencies>

<!-- to get the reference to local repository with com\googlecode\jspf\jspf-core\0.9.1\ -->
Expand Down
1 change: 0 additions & 1 deletion Mage.Client/serverlist.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
XMage.de 1 (Europe/Germany) fast :xmage.de:17171
woogerworks (North America/USA) :xmage.woogerworks.com:17171
xmage.lukeskywalk.com (North America) :xmage.lukeskywalk.com:17171
play.xmage.net (North America/Canada) :play.xmage.net:17171
XMageBr. (South America/Brazil) :magic.ncs3sistemas.com.br:17171
XMage.tahiti :xmage.tahiti.one:443
Expand Down
2 changes: 2 additions & 0 deletions Mage.Client/src/main/java/mage/client/MageFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
import org.mage.plugins.card.info.CardInfoPaneImpl;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;

import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;

/**
* @author BetaSteward_at_googlemail.com
*/
Expand Down
4 changes: 4 additions & 0 deletions Mage.Client/src/main/java/mage/client/cards/CardsList.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import mage.view.CardsView;
import mage.view.SimpleCardView;
import org.mage.card.arcane.CardPanel;
import org.mage.card.arcane.ManaSymbolsCellRenderer;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
Expand Down Expand Up @@ -164,6 +165,9 @@ private void initListViewComponents() {
mainTable.getColumnModel().getColumn(6).setPreferredWidth(15);
mainTable.getColumnModel().getColumn(7).setPreferredWidth(15);

// new mana render (svg support)
mainTable.getColumnModel().getColumn(mainModel.COLUMN_INDEX_COST).setCellRenderer(new ManaSymbolsCellRenderer());

if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_DRAFT_VIEW, "cardView").equals("listView")) {
jToggleListView.setSelected(true);
panelCardArea.setViewportView(mainTable);
Expand Down
44 changes: 36 additions & 8 deletions Mage.Client/src/main/java/mage/client/constants/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package mage.client.constants;

import java.awt.*;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.border.Border;
Expand Down Expand Up @@ -72,18 +73,45 @@ private Constants() {

public static final double SCALE_FACTOR = 0.5;

public static final String PLUGINS_DIRECTORY = "plugins/";
// cards render
public static final Rectangle CARD_SIZE_FULL = new Rectangle(101, 149);
public static final Rectangle THUMBNAIL_SIZE_FULL = new Rectangle(102, 146);

// resources - default images
public static final String RESOURCE_PATH_DEFAUL_IMAGES = File.separator + "default";

// resources - symbols
public static final String RESOURCE_PATH_SYMBOLS = File.separator + "symbols";
public static final String RESOURCE_SYMBOL_FOLDER_SMALL = "small";
public static final String RESOURCE_SYMBOL_FOLDER_MEDIUM = "medium";
public static final String RESOURCE_SYMBOL_FOLDER_LARGE = "large";
public static final String RESOURCE_SYMBOL_FOLDER_SVG = "svg";
public static final String RESOURCE_SYMBOL_FOLDER_PNG = "png";
public enum ResourceSymbolSize {
SMALL,
MEDIUM,
LARGE,
SVG,
PNG
}

// resources - sets
public static final String RESOURCE_PATH_SETS = File.separator + "sets";
public static final String RESOURCE_SET_FOLDER_SMALL = "small";
public static final String RESOURCE_SET_FOLDER_MEDIUM = ""; // empty, medium images laydown in "sets" folder, TODO: delete that and auto gen, use png for html, not gif
public static final String RESOURCE_SET_FOLDER_SVG = "svg";
public enum ResourceSetSize {
SMALL,
MEDIUM,
SVG
}

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 = "sounds" + File.separator;
// sound
public static final String BASE_SOUND_PATH = "sounds" + File.separator; // TODO: check path with File.separator
public static final String BASE_MUSICS_PATH = "music" + File.separator;

public interface IO {

String imageBaseDir = "plugins" + File.separator + "images" + File.separator;
String DEFAULT_IMAGES_DIR = "plugins" + File.separator + "images" + File.separator;
String IMAGE_PROPERTIES_FILE = "image.url.properties";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import mage.filter.predicate.other.ExpansionSetPredicate;
import mage.view.CardView;
import mage.view.CardsView;
import org.mage.card.arcane.ManaSymbolsCellRenderer;

/**
*
Expand Down Expand Up @@ -133,6 +134,9 @@ private void initListViewComponents() {
mainTable.getColumnModel().getColumn(6).setPreferredWidth(15);
mainTable.getColumnModel().getColumn(7).setPreferredWidth(15);

// new mana render (svg support)
mainTable.getColumnModel().getColumn(mainModel.COLUMN_INDEX_COST).setCellRenderer(new ManaSymbolsCellRenderer());

// mainTable.setToolTipText(cardSelectorScrollPane.getToolTipText());
cardSelectorScrollPane.setViewportView(mainTable);
mainTable.setOpaque(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void addSetTabs() {
if (setImage != null) {
tab.setOverlayImage(setImage);
} else {
System.out.println("Couldn't find symbol image: " + "/plugins/images/sets/" + set + "-C.jpg");
System.out.println("Couldn't find symbol image: " + set + "-C.jpg");
}
tab.setSet(set);
tab.setBounds(0, y, 39, 120);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class TableModel extends AbstractTableModel implements ICardGrid {
private UpdateCountsCallback updateCountsCallback;

private final String column[] = {"Qty", "Name", "Cost", "Color", "Type", "Stats", "Rarity", "Set", "#"};
public final int COLUMN_INDEX_COST = 2;

private SortSetting sortSetting;
private int recentSortedColumn;
Expand Down Expand Up @@ -239,13 +240,19 @@ private Object getColumn(Object obj, int column) {
case 1:
return c.getName();
case 2:
// new svg images version
return ManaSymbols.getStringManaCost(c.getManaCost());
/*
// old html images version
String manaCost = "";
for (String m : c.getManaCost()) {
manaCost += m;
}
String castingCost = UI.getDisplayManaCost(manaCost);
castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, ManaSymbols.Type.TABLE);
return "<html>" + castingCost + "</html>";
return castingCost;
*/
case 3:
return c.getColorText();
case 4:
Expand Down
11 changes: 6 additions & 5 deletions Mage.Client/src/main/java/mage/client/plugins/impl/Plugins.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
import org.mage.plugins.card.CardPluginImpl;
import org.mage.plugins.theme.ThemePluginImpl;

import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;

public enum Plugins implements MagePlugins {
instance;
public static final String PLUGINS_DIRECTORY = "plugins/";
public static final String PLUGINS_DIRECTORY = "plugins";

private static final Logger LOGGER = Logger.getLogger(Plugins.class);
private static PluginManager pm;
Expand All @@ -48,9 +50,10 @@ public enum Plugins implements MagePlugins {

@Override
public void loadPlugins() {

LOGGER.info("Loading plugins...");
pm = PluginManagerFactory.createPluginManager();
pm.addPluginsFrom(new File(PLUGINS_DIRECTORY).toURI());
pm.addPluginsFrom(new File(PLUGINS_DIRECTORY + File.separator).toURI());
this.cardPlugin = new CardPluginImpl();
this.counterPlugin = pm.getPlugin(CounterPlugin.class);
this.themePlugin = new ThemePluginImpl();
Expand Down Expand Up @@ -131,10 +134,8 @@ public int sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent>

@Override
public void downloadSymbols() {
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
String path = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
if (this.cardPlugin != null) {
this.cardPlugin.downloadSymbols(path);
this.cardPlugin.downloadSymbols(getImagesDir());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,21 @@
import mage.view.CounterView;
import mage.view.PermanentView;
import mage.view.StackAbilityView;
import net.java.truevfs.access.TFile;
import org.apache.log4j.Logger;
import org.jdesktop.swingx.graphics.GraphicsUtilities;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.images.ImageCache;
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
import mage.client.constants.Constants;

import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.UUID;

import static org.mage.plugins.card.constants.Constants.THUMBNAIL_SIZE_FULL;

/**
* Class for drawing the mage card object by using a form based JComponent
* approach
Expand Down Expand Up @@ -479,8 +477,10 @@ protected void paintChildren(Graphics g) {

if (getShowCastingCost() && !isAnimationPanel() && canShowCardIcons(getCardWidth(), hasImage)) {

int symbolMarginX = 2; // 2 px between icons

String manaCost = ManaSymbols.getStringManaCost(gameCard.getManaCost());
int manaWidth = getManaWidth(manaCost);
int manaWidth = getManaWidth(manaCost, symbolMarginX);

// right top corner with margin (sizes from any sample card, length from black border to mana icon)
int manaMarginRight = Math.round(22f / 672f * getCardWidth());
Expand All @@ -489,25 +489,19 @@ protected void paintChildren(Graphics g) {
int manaX = getCardXOffset() + getCardWidth() - manaMarginRight - manaWidth;
int manaY = getCardYOffset() + manaMarginTop;

if (hasImage) {
// top right corner if have image like real card
ManaSymbols.draw(g, manaCost, manaX, manaY, getSymbolWidth());
} else {
// old version - bottom left corner if haven't card
// ManaSymbols.draw(g, manaCost, getCardXOffset() + manaMarginRight, getCardYOffset() + getCardHeight() - manaMarginTop - getSymbolWidth(), getSymbolWidth());

// new version - like a normal image (it's best to view and construct decks)
ManaSymbols.draw(g, manaCost, manaX, manaY, getSymbolWidth());
}
ManaSymbols.draw(g, manaCost, manaX, manaY, getSymbolWidth(), Color.black, symbolMarginX);
}
}

private int getManaWidth(String manaCost) {
private int getManaWidth(String manaCost, int symbolMarginX) {
int width = 0;
manaCost = manaCost.replace("\\", "");
StringTokenizer tok = new StringTokenizer(manaCost, " ");
while (tok.hasMoreTokens()) {
tok.nextToken();
if(width != 0) {
width += symbolMarginX;
}
width += getSymbolWidth();
}
return width;
Expand Down Expand Up @@ -654,7 +648,7 @@ public void updateArtImage() {
final BufferedImage srcImage;
if (gameCard.isFaceDown()) {
srcImage = getFaceDownImage();
} else if (getCardWidth() > THUMBNAIL_SIZE_FULL.width) {
} else if (getCardWidth() > Constants.THUMBNAIL_SIZE_FULL.width) {
srcImage = ImageCache.getImage(gameCard, getCardWidth(), getCardHeight());
} else {
srcImage = ImageCache.getThumbnail(gameCard);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@
import org.jdesktop.swingx.graphics.GraphicsUtilities;
import org.mage.plugins.card.dl.sources.DirectLinksForDownload;
import org.mage.plugins.card.images.ImageCache;
import mage.client.constants.Constants;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Map;
import java.util.UUID;

import static org.mage.plugins.card.constants.Constants.THUMBNAIL_SIZE_FULL;

public class CardPanelRenderImpl extends CardPanel {

private static final Logger LOGGER = Logger.getLogger(CardPanelRenderImpl.class);
Expand Down Expand Up @@ -341,7 +340,7 @@ public void updateArtImage() {
// Nothing to do
srcImage = null;
faceArtSrcImage = null;
} else if (getCardWidth() > THUMBNAIL_SIZE_FULL.width) {
} else if (getCardWidth() > Constants.THUMBNAIL_SIZE_FULL.width) {
srcImage = ImageCache.getImage(gameCard, getCardWidth(), getCardHeight());
faceArtSrcImage = ImageCache.getFaceImage(gameCard, getCardWidth(), getCardHeight());
} else {
Expand Down
Loading