Interfaces and abstract classes for Mage.Card.Plugin. Replaced creating permanent by calling plugin manager that returns old implementation but new is also possible since now.

This commit is contained in:
magenoxx 2010-11-03 06:59:55 +00:00
parent ce4537c6c4
commit 9eb8b0e487
18 changed files with 258 additions and 41 deletions

View file

@ -42,7 +42,7 @@ import java.util.List;
import java.util.UUID;
import javax.swing.text.BadLocationException;
import javax.swing.text.StyledDocument;
import static mage.client.util.Constants.*;
import static mage.constants.Constants.*;
/**
*

View file

@ -34,16 +34,16 @@
package mage.client.cards;
import static mage.client.util.Constants.CONTENT_MAX_XOFFSET;
import static mage.client.util.Constants.FRAME_MAX_HEIGHT;
import static mage.client.util.Constants.FRAME_MAX_WIDTH;
import static mage.client.util.Constants.NAME_FONT_MAX_SIZE;
import static mage.client.util.Constants.NAME_MAX_YOFFSET;
import static mage.client.util.Constants.POWBOX_TEXT_MAX_LEFT;
import static mage.client.util.Constants.POWBOX_TEXT_MAX_TOP;
import static mage.client.util.Constants.SYMBOL_MAX_XOFFSET;
import static mage.client.util.Constants.SYMBOL_MAX_YOFFSET;
import static mage.client.util.Constants.TYPE_MAX_YOFFSET;
import static mage.constants.Constants.CONTENT_MAX_XOFFSET;
import static mage.constants.Constants.FRAME_MAX_HEIGHT;
import static mage.constants.Constants.FRAME_MAX_WIDTH;
import static mage.constants.Constants.NAME_FONT_MAX_SIZE;
import static mage.constants.Constants.NAME_MAX_YOFFSET;
import static mage.constants.Constants.POWBOX_TEXT_MAX_LEFT;
import static mage.constants.Constants.POWBOX_TEXT_MAX_TOP;
import static mage.constants.Constants.SYMBOL_MAX_XOFFSET;
import static mage.constants.Constants.SYMBOL_MAX_YOFFSET;
import static mage.constants.Constants.TYPE_MAX_YOFFSET;
import java.awt.Color;
import java.awt.Dimension;
@ -74,6 +74,8 @@ import javax.swing.text.StyleContext;
import javax.swing.text.StyledDocument;
import mage.Constants.CardType;
import mage.cards.CardDimensions;
import mage.cards.MagePermanent;
import mage.client.MageFrame;
import mage.client.game.PlayAreaPanel;
import mage.client.remote.Session;
@ -83,13 +85,15 @@ import mage.client.util.gui.ArrowBuilder;
import mage.sets.Sets;
import mage.view.AbilityView;
import mage.view.CardView;
import mage.view.PermanentView;
import mage.view.StackAbilityView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Card extends javax.swing.JPanel implements MouseMotionListener, MouseListener, FocusListener, ComponentListener {
@SuppressWarnings("serial")
public class Card extends MagePermanent implements MouseMotionListener, MouseListener, FocusListener, ComponentListener {
protected static Session session = MageFrame.getSession();
@ -377,7 +381,7 @@ public class Card extends javax.swing.JPanel implements MouseMotionListener, Mou
ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() - 40, Color.red);
} else {
for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
Permanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
if (permanent != null) {
Point target = permanent.getLocationOnScreen();
Point me = this.getLocationOnScreen();
@ -436,4 +440,12 @@ public class Card extends javax.swing.JPanel implements MouseMotionListener, Mou
popup.hide();
}
@Override
public void update(PermanentView card) {
}
@Override
public List<MagePermanent> getLinks() {
return null;
}
}

View file

@ -41,6 +41,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import mage.client.util.Config;
import mage.view.CardView;
import mage.view.CardsView;

View file

@ -34,6 +34,9 @@
package mage.client.cards;
import static mage.constants.Constants.DAMAGE_MAX_LEFT;
import static mage.constants.Constants.POWBOX_TEXT_MAX_TOP;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
@ -45,24 +48,27 @@ import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.swing.PopupFactory;
import mage.Constants.CardType;
import mage.cards.CardDimensions;
import mage.cards.MagePermanent;
import mage.client.util.Config;
import mage.client.util.ImageHelper;
import mage.sets.Sets;
import mage.view.CounterView;
import mage.view.PermanentView;
import static mage.client.util.Constants.*;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Permanent extends Card {
public class Permanent extends Card implements mage.cards.interfaces.PermanentInterface {
protected PermanentView permanent;
protected List<Permanent> links = new ArrayList<Permanent>();
protected List<MagePermanent> links = new ArrayList<MagePermanent>();
protected boolean linked;
protected BufferedImage tappedImage;
protected BufferedImage flippedImage;
@ -79,7 +85,7 @@ public class Permanent extends Card {
return permanent.getId();
}
public List<Permanent> getLinks() {
public List<MagePermanent> getLinks() {
return links;
}
@ -152,7 +158,7 @@ public class Permanent extends Card {
if (r.y < 0) r.y = 0;
this.setBounds(r);
this.repaint();
for (Permanent perm: links) {
for (MagePermanent perm: links) {
r.x += 20;
r.y += 20;
perm.setBounds(r);

View file

@ -39,11 +39,13 @@ import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.UUID;
import javax.swing.JLayeredPane;
import mage.cards.CardDimensions;
import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.cards.Card;
import mage.client.cards.CardDimensions;
import mage.client.util.Config;
import mage.view.CardView;
import mage.view.CardsView;

View file

@ -39,20 +39,17 @@ import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
import java.util.UUID;
import javax.imageio.ImageIO;
import mage.cards.MagePermanent;
import mage.client.cards.BigCard;
import mage.client.cards.Permanent;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.client.util.gui.ImagePanel;
import mage.view.PermanentView;
/**
@ -61,7 +58,7 @@ import mage.view.PermanentView;
*/
public class BattlefieldPanel extends javax.swing.JLayeredPane implements ComponentListener {
private Map<UUID, Permanent> permanents = new HashMap<UUID, Permanent>();
private Map<UUID, MagePermanent> permanents = new HashMap<UUID, MagePermanent>();
private UUID gameId;
private BigCard bigCard;
@ -84,8 +81,8 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
permanents.get(permanent.getId()).update(permanent);
}
}
for (Iterator<Entry<UUID, Permanent>> i = permanents.entrySet().iterator(); i.hasNext();) {
Entry<UUID, Permanent> entry = i.next();
for (Iterator<Entry<UUID, MagePermanent>> i = permanents.entrySet().iterator(); i.hasNext();) {
Entry<UUID, MagePermanent> entry = i.next();
if (!battlefield.containsKey(entry.getKey())) {
removePermanent(entry.getKey());
i.remove();
@ -99,7 +96,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
}
private void addPermanent(PermanentView permanent) {
Permanent perm = new Permanent(permanent, bigCard, Config.dimensions, gameId);
MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);;
perm.addComponentListener(this);
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
permanents.put(permanent.getId(), perm);
@ -109,12 +106,12 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
}
private void groupAttachments(PermanentView permanent) {
Permanent perm = permanents.get(permanent.getId());
MagePermanent perm = permanents.get(permanent.getId());
int position = getPosition(perm);
perm.getLinks().clear();
Rectangle r = perm.getBounds();
for (UUID attachmentId: permanent.getAttachments()) {
Permanent link = permanents.get(attachmentId);
MagePermanent link = permanents.get(attachmentId);
perm.getLinks().add(link);
r.translate(20, 20);
link.setBounds(r);
@ -138,7 +135,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
boolean intersects;
while (true) {
intersects = false;
for (Permanent perm: permanents.values()) {
for (MagePermanent perm: permanents.values()) {
Rectangle pr = perm.getBounds();
if (r.intersects(pr)) {
intersects = true;
@ -160,7 +157,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
return false;
}
public Map<UUID, Permanent> getPermanents() {
public Map<UUID, MagePermanent> getPermanents() {
return permanents;
}

View file

@ -1,11 +1,18 @@
package mage.client.plugins;
import java.util.Map;
import java.util.UUID;
import javax.swing.JComponent;
import mage.cards.CardDimensions;
import mage.cards.MagePermanent;
import mage.client.cards.BigCard;
import mage.view.PermanentView;
public interface MagePlugins {
void loadPlugins();
void shutdown();
void updateGamePanel(Map<String, JComponent> ui);
MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, CardDimensions dimension, UUID gameId);
}

View file

@ -2,15 +2,23 @@ package mage.client.plugins.impl;
import java.io.File;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComponent;
import mage.cards.CardDimensions;
import mage.cards.MagePermanent;
import mage.client.cards.BigCard;
import mage.client.cards.Permanent;
import mage.client.plugins.MagePlugins;
import mage.client.util.Constants;
import mage.client.util.Config;
import mage.constants.Constants;
import mage.interfaces.plugin.CardPlugin;
import mage.interfaces.plugin.ThemePlugin;
import mage.util.Logging;
import mage.view.PermanentView;
import net.xeoh.plugins.base.PluginManager;
import net.xeoh.plugins.base.impl.PluginManagerFactory;
import net.xeoh.plugins.base.util.PluginManagerUtil;
@ -47,4 +55,14 @@ public class Plugins implements MagePlugins {
pl.apply(ui);
}
}
@Override
public MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, CardDimensions dimension, UUID gameId) {
CardPlugin cp = pm.getPlugin(CardPlugin.class);
if (cp != null) {
return cp.getMagePermanent(card, dimension, gameId);
} else {
return new Permanent(card, bigCard, Config.dimensions, gameId);
}
}
}

View file

@ -35,7 +35,7 @@ import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.client.cards.CardDimensions;
import mage.cards.CardDimensions;
import mage.util.Logging;
/**

View file

@ -28,9 +28,8 @@
package mage.client.util;
import java.awt.Image;
import static mage.constants.Constants.*;
import java.awt.image.BufferedImage;
import static mage.client.util.Constants.*;
/**
*

View file

@ -28,6 +28,8 @@
package mage.client.util;
import static mage.constants.Constants.*;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
@ -39,15 +41,16 @@ import java.awt.image.PixelGrabber;
import java.io.File;
import java.util.HashMap;
import java.util.List;
import javax.imageio.ImageIO;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.client.cards.CardDimensions;
import mage.cards.CardDimensions;
import mage.sets.Sets;
import mage.view.AbilityView;
import mage.view.CardView;
import mage.view.StackAbilityView;
import static mage.client.util.Constants.*;
/**
*

View file

@ -31,7 +31,7 @@ package mage.client.util;
import java.awt.Image;
import java.util.HashMap;
import java.util.Map;
import static mage.client.util.Constants.*;
import static mage.constants.Constants.*;
/**
*

View file

@ -0,0 +1,69 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.cards;
import static mage.constants.Constants.*;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CardDimensions {
public int frameHeight;
public int frameWidth;
public int symbolHeight;
public int symbolWidth;
public int contentXOffset;
public int nameYOffset;
public int typeYOffset;
public int textYOffset;
public int textWidth;
public int textHeight;
public int powBoxTextTop;
public int powBoxTextLeft;
public int nameFontSize;
public CardDimensions(double scaleFactor) {
frameHeight = (int)(FRAME_MAX_HEIGHT * scaleFactor);
frameWidth = (int)(FRAME_MAX_WIDTH * scaleFactor);
symbolHeight = (int)(SYMBOL_MAX_HEIGHT * scaleFactor);
symbolWidth = (int)(SYMBOL_MAX_WIDTH * scaleFactor);
contentXOffset = (int)(CONTENT_MAX_XOFFSET * scaleFactor);
nameYOffset = (int)(NAME_MAX_YOFFSET * scaleFactor);
typeYOffset = (int)(TYPE_MAX_YOFFSET * scaleFactor);
textYOffset = (int)(TEXT_MAX_YOFFSET * scaleFactor);
textWidth = (int)(TEXT_MAX_WIDTH * scaleFactor);
textHeight = (int)(TEXT_MAX_HEIGHT * scaleFactor);
powBoxTextTop = (int)(POWBOX_TEXT_MAX_TOP * scaleFactor);
powBoxTextLeft = (int)(POWBOX_TEXT_MAX_LEFT * scaleFactor);
nameFontSize = Math.max(9, (int)(NAME_FONT_MAX_SIZE * scaleFactor));
}
}

View file

@ -0,0 +1,13 @@
package mage.cards;
import java.util.List;
import javax.swing.JPanel;
import mage.cards.interfaces.CardInterface;
import mage.cards.interfaces.PermanentInterface;
public abstract class MagePermanent extends JPanel implements PermanentInterface, CardInterface {
private static final long serialVersionUID = -3469258620601702171L;
abstract public List<MagePermanent> getLinks();
}

View file

@ -0,0 +1,5 @@
package mage.cards.interfaces;
public interface CardInterface {
}

View file

@ -0,0 +1,7 @@
package mage.cards.interfaces;
import mage.view.PermanentView;
public interface PermanentInterface {
void update(PermanentView card);
}

View file

@ -0,0 +1,73 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.constants;
import java.io.File;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public final class Constants {
private Constants() {
throw new AssertionError();
}
public static final int FRAME_MAX_HEIGHT = 367;
public static final int FRAME_MAX_WIDTH = 256;
public static final int ART_MAX_HEIGHT = 168;
public static final int ART_MAX_WIDTH = 227;
public static final int SYMBOL_MAX_HEIGHT = 14;
public static final int SYMBOL_MAX_WIDTH = 14;
public static final int SYMBOL_MAX_XOFFSET = 27;
public static final int SYMBOL_MAX_YOFFSET = 15;
public static final int SYMBOL_MAX_SPACE = 14;
public static final int CONTENT_MAX_XOFFSET = 15;
public static final int ART_MAX_YOFFSET = 37;
public static final int NAME_MAX_YOFFSET = 28;
public static final int TYPE_MAX_YOFFSET = 223;
public static final int ICON_MAX_HEIGHT = 16;
public static final int ICON_MAX_WIDTH = 16;
public static final int ICON_MAX_XOFFSET = 238;
public static final int ICON_MAX_YOFFSET = 210;
public static final int TEXT_MAX_YOFFSET = 232;
public static final int TEXT_MAX_WIDTH = 227;
public static final int TEXT_MAX_HEIGHT = 105;
public static final int NAME_FONT_MAX_SIZE = 13;
public static final int TEXT_FONT_MAX_SIZE = 11;
public static final int POWBOX_MAX_TOP = 336;
public static final int POWBOX_MAX_LEFT = 202;
public static final int POWBOX_TEXT_MAX_TOP = 352;
public static final int POWBOX_TEXT_MAX_LEFT = 212;
public static final int DAMAGE_MAX_LEFT = 180;
public static final double SCALE_FACTOR = 0.5;
public static final String PLUGINS_DIRECTORY = "plugins/";
}

View file

@ -1,5 +1,10 @@
package mage.interfaces.plugin;
import java.util.UUID;
import mage.cards.CardDimensions;
import mage.cards.MagePermanent;
import mage.view.CardView;
import net.xeoh.plugins.base.Plugin;
/**
@ -9,5 +14,5 @@ import net.xeoh.plugins.base.Plugin;
* @author nantuko
*/
public interface CardPlugin extends Plugin {
MagePermanent getMagePermanent(CardView card, CardDimensions dimension, UUID gameId);
}