mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
Card Plugin implementation. Added displaying card and card layout.
This commit is contained in:
parent
b223d83be5
commit
48e3a65d3a
25 changed files with 687 additions and 72 deletions
|
|
@ -80,6 +80,7 @@ import mage.client.MageFrame;
|
|||
import mage.client.game.PlayAreaPanel;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
import mage.sets.Sets;
|
||||
|
|
@ -96,7 +97,8 @@ import mage.view.StackAbilityView;
|
|||
public class Card extends MagePermanent implements MouseMotionListener, MouseListener, FocusListener, ComponentListener {
|
||||
|
||||
protected static Session session = MageFrame.getSession();
|
||||
|
||||
protected static DefaultActionCallback callback = new DefaultActionCallback();
|
||||
|
||||
protected Point p;
|
||||
protected CardDimensions dimension;
|
||||
|
||||
|
|
@ -340,10 +342,9 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
|||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent arg0) {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
requestFocusInWindow();
|
||||
if (gameId != null)
|
||||
session.sendPlayerUUID(gameId, card.getId());
|
||||
callback.mouseClicked(e, gameId, session, card);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -441,11 +442,32 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
|||
}
|
||||
|
||||
@Override
|
||||
public void update(PermanentView card) {
|
||||
public List<MagePermanent> getLinks() {return null;}
|
||||
|
||||
@Override
|
||||
public boolean isTapped() {return false;}
|
||||
|
||||
@Override
|
||||
public void onBeginAnimation() {}
|
||||
|
||||
@Override
|
||||
public void onEndAnimation() {}
|
||||
|
||||
@Override
|
||||
public void setAlpha(float transparency) {}
|
||||
|
||||
@Override
|
||||
public PermanentView getOriginal() {
|
||||
throw new RuntimeException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MagePermanent> getLinks() {
|
||||
return null;
|
||||
public void setCardBounds(int x, int y, int width, int height) {
|
||||
throw new RuntimeException("Not implemented");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCard(PermanentView card) {
|
||||
update(card);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ import mage.view.PermanentView;
|
|||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class Permanent extends Card implements mage.cards.interfaces.PermanentInterface {
|
||||
public class Permanent extends Card {
|
||||
|
||||
protected PermanentView permanent;
|
||||
|
||||
|
|
|
|||
|
|
@ -42,8 +42,11 @@ import java.awt.event.ComponentListener;
|
|||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JScrollPane;
|
||||
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.client.cards.BigCard;
|
||||
|
|
@ -61,9 +64,11 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
|||
private Map<UUID, MagePermanent> permanents = new HashMap<UUID, MagePermanent>();
|
||||
private UUID gameId;
|
||||
private BigCard bigCard;
|
||||
private Map<String, JComponent> ui = new HashMap<String, JComponent>();
|
||||
|
||||
/** Creates new form BattlefieldPanel */
|
||||
public BattlefieldPanel() {
|
||||
public BattlefieldPanel(JScrollPane jScrollPane) {
|
||||
ui.put("jScrollPane", jScrollPane);
|
||||
initComponents();
|
||||
}
|
||||
|
||||
|
|
@ -78,7 +83,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
|||
addPermanent(permanent);
|
||||
}
|
||||
else {
|
||||
permanents.get(permanent.getId()).update(permanent);
|
||||
permanents.get(permanent.getId()).updateCard(permanent);
|
||||
}
|
||||
}
|
||||
for (Iterator<Entry<UUID, MagePermanent>> i = permanents.entrySet().iterator(); i.hasNext();) {
|
||||
|
|
@ -93,16 +98,20 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
|||
groupAttachments(permanent);
|
||||
}
|
||||
}
|
||||
|
||||
Plugins.getInstance().sortPermanents(ui, permanents.values());
|
||||
}
|
||||
|
||||
private void addPermanent(PermanentView permanent) {
|
||||
MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);;
|
||||
perm.addComponentListener(this);
|
||||
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
||||
}
|
||||
permanents.put(permanent.getId(), perm);
|
||||
this.add(perm);
|
||||
moveToFront(perm);
|
||||
perm.update(permanent);
|
||||
perm.updateCard(permanent);
|
||||
}
|
||||
|
||||
private void groupAttachments(PermanentView permanent) {
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
|
|||
manaPool = new mage.client.game.ManaPool();
|
||||
btnCheat = new javax.swing.JButton();
|
||||
jScrollPane1 = new javax.swing.JScrollPane();
|
||||
battlefieldPanel = new mage.client.game.BattlefieldPanel();
|
||||
battlefieldPanel = new mage.client.game.BattlefieldPanel(jScrollPane1);
|
||||
|
||||
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package mage.client.plugins;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -15,4 +16,6 @@ public interface MagePlugins {
|
|||
void shutdown();
|
||||
void updateGamePanel(Map<String, JComponent> ui);
|
||||
MagePermanent getMagePermanent(PermanentView card, BigCard bigCard, CardDimensions dimension, UUID gameId);
|
||||
boolean isCardPluginLoaded();
|
||||
void sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent> permanents);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package mage.client.plugins.impl;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Level;
|
||||
|
|
@ -10,10 +12,14 @@ import javax.swing.JComponent;
|
|||
|
||||
import mage.cards.CardDimensions;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.interfaces.ActionCallback;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.Permanent;
|
||||
import mage.client.plugins.MagePlugins;
|
||||
import mage.client.remote.Session;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
import mage.constants.Constants;
|
||||
import mage.interfaces.plugin.CardPlugin;
|
||||
import mage.interfaces.plugin.ThemePlugin;
|
||||
|
|
@ -29,6 +35,8 @@ public class Plugins implements MagePlugins {
|
|||
private static final MagePlugins fINSTANCE = new Plugins();
|
||||
private static PluginManager pm;
|
||||
private final static Logger logger = Logging.getLogger(Plugins.class.getName());
|
||||
private CardPlugin cardPlugin = null;
|
||||
protected static DefaultActionCallback defaultCallback = new DefaultActionCallback();
|
||||
|
||||
public static MagePlugins getInstance() {
|
||||
return fINSTANCE;
|
||||
|
|
@ -39,6 +47,7 @@ public class Plugins implements MagePlugins {
|
|||
logger.log(Level.INFO, "Loading plugins...");
|
||||
pm = PluginManagerFactory.createPluginManager();
|
||||
pm.addPluginsFrom(new File(Constants.PLUGINS_DIRECTORY).toURI());
|
||||
this.cardPlugin = pm.getPlugin(CardPlugin.class);
|
||||
logger.log(Level.INFO, "Done.");
|
||||
}
|
||||
|
||||
|
|
@ -57,12 +66,26 @@ public class Plugins implements MagePlugins {
|
|||
}
|
||||
|
||||
@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);
|
||||
public MagePermanent getMagePermanent(final PermanentView card, BigCard bigCard, CardDimensions dimension, final UUID gameId) {
|
||||
if (cardPlugin != null) {
|
||||
return cardPlugin.getMagePermanent(card, dimension, gameId, new ActionCallback() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
defaultCallback.mouseClicked(e, gameId, MageFrame.getSession(), card);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
return new Permanent(card, bigCard, Config.dimensions, gameId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCardPluginLoaded() {
|
||||
return this.cardPlugin != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent> permanents) {
|
||||
if (this.cardPlugin != null) this.cardPlugin.sortPermanents(ui, permanents);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
package mage.client.util;
|
||||
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.client.remote.Session;
|
||||
import mage.view.CardView;
|
||||
|
||||
|
||||
public class DefaultActionCallback {
|
||||
public void mouseClicked(MouseEvent e, UUID gameId, Session session, CardView card) {
|
||||
System.out.println("gameId:" + gameId);
|
||||
if (gameId != null)
|
||||
session.sendPlayerUUID(gameId, card.getId());
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue