mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
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:
parent
ce4537c6c4
commit
9eb8b0e487
18 changed files with 258 additions and 41 deletions
|
|
@ -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.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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.*;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue