mirror of
https://github.com/correl/mage.git
synced 2025-01-11 11:05:23 +00:00
New tooltips.
This commit is contained in:
parent
6ae4ac3c5e
commit
3123207b0d
15 changed files with 432 additions and 275 deletions
Binary file not shown.
|
@ -50,22 +50,14 @@ import java.util.logging.Logger;
|
|||
import java.util.prefs.Preferences;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.swing.Box;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JDesktopPane;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.*;
|
||||
import javax.swing.JToolBar.Separator;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import com.sun.java.swing.Painter;
|
||||
import mage.client.cards.CardsStorage;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.components.MageJDesktop;
|
||||
import mage.client.components.MageRoundPane;
|
||||
import mage.client.components.arcane.ManaSymbols;
|
||||
import mage.client.dialog.*;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
|
@ -122,7 +114,8 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
});
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||
UIManager.put("desktop", new Color(0,0,0,0));
|
||||
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
|
||||
//MageSynthStyleFactory f = new MageSynthStyleFactory(SynthLookAndFeel.getStyleFactory());
|
||||
//SynthLookAndFeel.setStyleFactory(f);
|
||||
} catch (Exception ex) {
|
||||
|
@ -145,12 +138,22 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
desktopPane.add(pickNumber, JLayeredPane.POPUP_LAYER);
|
||||
session.getUI().addComponent(MageComponents.DESKTOP_PANE, desktopPane);
|
||||
|
||||
JComponent cardInfoPane = Plugins.getInstance().getCardInfoPane();
|
||||
cardInfoPane.setSize(161, 221);
|
||||
cardInfoPane.setPreferredSize(new Dimension(161, 221));
|
||||
cardInfoPane.setVisible(false);
|
||||
final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane();
|
||||
cardInfoPane.setSize(320, 201);
|
||||
cardInfoPane.setLocation(40, 40);
|
||||
cardInfoPane.setBackground(new Color(0,0,0,0));
|
||||
|
||||
MageRoundPane popupContainer = new MageRoundPane();
|
||||
popupContainer.setLayout(null);
|
||||
|
||||
popupContainer.add(cardInfoPane);
|
||||
popupContainer.setVisible(false);
|
||||
popupContainer.setBounds(0, 0, 320 + 80, 201 + 80);
|
||||
|
||||
desktopPane.add(popupContainer, JLayeredPane.POPUP_LAYER);
|
||||
|
||||
session.getUI().addComponent(MageComponents.CARD_INFO_PANE, cardInfoPane);
|
||||
desktopPane.add(cardInfoPane, JLayeredPane.POPUP_LAYER);
|
||||
session.getUI().addComponent(MageComponents.POPUP_CONTAINER, popupContainer);
|
||||
|
||||
ManaSymbols.loadImages();
|
||||
|
||||
|
@ -337,7 +340,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
|
||||
private void initComponents() {
|
||||
|
||||
desktopPane = new javax.swing.JDesktopPane();
|
||||
desktopPane = new MageJDesktop();
|
||||
tablesPane = new mage.client.table.TablesPane();
|
||||
gamePane = new mage.client.game.GamePane();
|
||||
deckEditorPane = new mage.client.deckeditor.DeckEditorPane();
|
||||
|
@ -595,7 +598,7 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
private javax.swing.JButton btnExit;
|
||||
private javax.swing.JButton btnGames;
|
||||
private mage.client.deckeditor.DeckEditorPane deckEditorPane;
|
||||
private static javax.swing.JDesktopPane desktopPane;
|
||||
private static MageJDesktop desktopPane;
|
||||
private mage.client.game.GamePane gamePane;
|
||||
private javax.swing.JToolBar.Separator jSeparator1;
|
||||
private javax.swing.JToolBar.Separator jSeparator2;
|
||||
|
|
|
@ -6,7 +6,8 @@ public enum MageComponents {
|
|||
NEW_TABLE_OK_BUTTON("btnOK"),
|
||||
TABLE_WAITING_START_BUTTON("btnStart"),
|
||||
DESKTOP_PANE("desktopPane"),
|
||||
CARD_INFO_PANE("cardInfoPane");
|
||||
CARD_INFO_PANE("cardInfoPane"),
|
||||
POPUP_CONTAINER("popupContainer");
|
||||
|
||||
private String name;
|
||||
MageComponents(String name) {
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
package mage.client.components;
|
||||
|
||||
import com.sun.java.swing.Painter;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* Overrides JDesktopPane settings for Nimbus LAF.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class MageJDesktop extends JDesktopPane {
|
||||
|
||||
@Override
|
||||
public void updateUI() {
|
||||
if ("Nimbus".equals(UIManager.getLookAndFeel().getName())) {
|
||||
UIDefaults map = new UIDefaults();
|
||||
Painter painter = new Painter() {
|
||||
|
||||
Color color = null;
|
||||
|
||||
@Override
|
||||
public void paint(Graphics2D g, Object c, int w, int h) {
|
||||
g.setColor(color == null ? UIManager.getDefaults().getColor("desktop") : color);
|
||||
g.fillRect(0,0,w,h);
|
||||
}
|
||||
};
|
||||
map.put("DesktopPane[Enabled].backgroundPainter", painter);
|
||||
putClientProperty("Nimbus.Overrides", map);
|
||||
}
|
||||
super.updateUI();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package mage.client.components;
|
||||
|
||||
import org.jdesktop.swingx.graphics.GraphicsUtilities;
|
||||
import org.jdesktop.swingx.graphics.ShadowRenderer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.RoundRectangle2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
/**
|
||||
* Mage round pane with transparency.
|
||||
* Used for tooltips.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class MageRoundPane extends JPanel {
|
||||
|
||||
private static int X_OFFSET = 30;
|
||||
private static int Y_OFFSET = 30;
|
||||
private BufferedImage shadow = null;
|
||||
private Color backgroundColor = new Color(255, 255, 255, 220);
|
||||
private int alpha = 0;
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
int x = X_OFFSET;
|
||||
int y = Y_OFFSET;
|
||||
int w = getWidth() - 2 * X_OFFSET;
|
||||
int h = getHeight() - 2 * Y_OFFSET;
|
||||
int arc = 10;
|
||||
|
||||
Graphics2D g2 = (Graphics2D) g.create();
|
||||
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
|
||||
if (shadow != null) {
|
||||
int xOffset = (shadow.getWidth() - w) / 2;
|
||||
int yOffset = (shadow.getHeight() - h) / 2;
|
||||
g2.drawImage(shadow, x - xOffset, y - yOffset, null);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// fill content
|
||||
|
||||
/**
|
||||
* Add white translucent substrate
|
||||
*/
|
||||
/*if (alpha != 0) {
|
||||
g2.setColor(new Color(255, 255, 255, alpha));
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
}*/
|
||||
|
||||
g2.setColor(backgroundColor);
|
||||
g2.fillRoundRect(x, y, w, h, arc, arc);
|
||||
//////////////////////////////////////////////////////////////////
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
// draw border
|
||||
g2.setStroke(new BasicStroke(1.5f));
|
||||
g2.setColor(Color.BLACK);
|
||||
g2.drawRoundRect(x, y, w, h, arc, arc);
|
||||
// ////////////////////////////////////////////////////////////////
|
||||
|
||||
g2.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBounds(int x, int y, int width, int height) {
|
||||
super.setBounds(x, y, width, height);
|
||||
|
||||
int w = getWidth() - 2 * X_OFFSET;
|
||||
int h = getHeight() - 2 * Y_OFFSET;
|
||||
int arc = 10;
|
||||
int shadowSize = 50;
|
||||
|
||||
shadow = GraphicsUtilities.createCompatibleTranslucentImage(w, h);
|
||||
Graphics2D g2 = shadow.createGraphics();
|
||||
g2.setColor(Color.WHITE);
|
||||
g2.fillRoundRect(0, 0, w, h, arc, arc);
|
||||
g2.dispose();
|
||||
|
||||
ShadowRenderer renderer = new ShadowRenderer(shadowSize, 0.5f,
|
||||
Color.GRAY);
|
||||
shadow = renderer.createShadow(shadow);
|
||||
}
|
||||
|
||||
public void showDialog(boolean bShow) {
|
||||
setVisible(bShow);
|
||||
}
|
||||
|
||||
/**
|
||||
* Default UID.
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -96,14 +96,14 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
}
|
||||
|
||||
public void update(Map<UUID, PermanentView> battlefield) {
|
||||
boolean changed = false;
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
List<PermanentView> permanentsToAdd = new ArrayList<PermanentView>();
|
||||
for (PermanentView permanent: battlefield.values()) {
|
||||
if (!permanents.containsKey(permanent.getId())) {
|
||||
addPermanent(permanent);
|
||||
permanentsToAdd.add(permanent);
|
||||
changed = true;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
MagePermanent p = permanents.get(permanent.getId());
|
||||
if (!changed) {
|
||||
int s1 = permanent.getAttachments() == null ? 0 : permanent.getAttachments().size();
|
||||
|
@ -115,10 +115,15 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
permanents.get(permanent.getId()).update(permanent);
|
||||
}
|
||||
}
|
||||
int count = permanentsToAdd.size();
|
||||
for (PermanentView permanent : permanentsToAdd) {
|
||||
addPermanent(permanent, count);
|
||||
}
|
||||
|
||||
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());
|
||||
removePermanent(entry.getKey(), 1);
|
||||
i.remove();
|
||||
changed = true;
|
||||
}
|
||||
|
@ -150,12 +155,12 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
repaint();
|
||||
}
|
||||
|
||||
private void addPermanent(PermanentView permanent) {
|
||||
private void addPermanent(PermanentView permanent, final int count) {
|
||||
final MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
||||
} else {
|
||||
perm.setAlpha(0);
|
||||
//perm.setAlpha(0);
|
||||
}
|
||||
permanents.put(permanent.getId(), perm);
|
||||
|
||||
|
@ -164,15 +169,16 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
moveToFront(perm);
|
||||
perm.update(permanent);
|
||||
} else {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
Plugins.getInstance().onAddCard(perm, 1);
|
||||
/*Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Plugins.getInstance().onAddCard(perm);
|
||||
Plugins.getInstance().onAddCard(perm, count);
|
||||
}
|
||||
});
|
||||
synchronized (this) {
|
||||
threads.add(t);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -208,7 +214,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
|
||||
}
|
||||
|
||||
private void removePermanent(UUID permanentId) {
|
||||
private void removePermanent(UUID permanentId, final int count) {
|
||||
for (Component c: this.getComponents()) {
|
||||
final Component comp = c;
|
||||
if (comp instanceof Permanent) {
|
||||
|
@ -220,7 +226,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
|||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Plugins.getInstance().onRemoveCard((MagePermanent)comp);
|
||||
Plugins.getInstance().onRemoveCard((MagePermanent)comp, count);
|
||||
BattlefieldPanel.this.remove(comp);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -32,7 +32,7 @@ public interface MagePlugins {
|
|||
int getGamesPlayed();
|
||||
void addGamesPlayed();
|
||||
Image getManaSymbolImage(String symbol);
|
||||
void onAddCard(MagePermanent card);
|
||||
void onRemoveCard(MagePermanent card);
|
||||
void onAddCard(MagePermanent card, int count);
|
||||
void onRemoveCard(MagePermanent card, int count);
|
||||
JComponent getCardInfoPane();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.awt.*;
|
|||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import mage.cards.action.TransferData;
|
|||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.components.MageRoundPane;
|
||||
import mage.client.game.PlayAreaPanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.remote.Session;
|
||||
|
@ -31,95 +33,95 @@ import org.jdesktop.swingx.JXPanel;
|
|||
|
||||
public class MageActionCallback implements ActionCallback {
|
||||
|
||||
private Popup popup;
|
||||
private Popup popup;
|
||||
private JPopupMenu jPopupMenu;
|
||||
private BigCard bigCard;
|
||||
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
||||
protected static Session session = MageFrame.getSession();
|
||||
private CardView popupCard;
|
||||
private Thread t;
|
||||
private int state = 0;
|
||||
private BigCard bigCard;
|
||||
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
||||
protected static Session session = MageFrame.getSession();
|
||||
private CardView popupCard;
|
||||
private Thread t;
|
||||
private int state = 0;
|
||||
private JComponent cardInfoPane;
|
||||
|
||||
public MageActionCallback() {
|
||||
}
|
||||
|
||||
public void setCardPreviewComponent(BigCard bigCard) {
|
||||
this.bigCard = bigCard;
|
||||
}
|
||||
|
||||
public void refreshSession() {
|
||||
if (session == null) {
|
||||
session = MageFrame.getSession();
|
||||
}
|
||||
|
||||
public MageActionCallback() {
|
||||
}
|
||||
|
||||
public void setCardPreviewComponent(BigCard bigCard) {
|
||||
this.bigCard = bigCard;
|
||||
}
|
||||
|
||||
public void refreshSession() {
|
||||
if (session == null) {
|
||||
session = MageFrame.getSession();
|
||||
}
|
||||
if (cardInfoPane == null) {
|
||||
cardInfoPane = Plugins.getInstance().getCardInfoPane();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e, TransferData data) {
|
||||
data.component.requestFocusInWindow();
|
||||
defaultCallback.mouseClicked(e, data.gameId, session, data.card);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||
hidePopup();
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e, TransferData data) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e, TransferData data) {
|
||||
data.component.requestFocusInWindow();
|
||||
defaultCallback.mouseClicked(e, data.gameId, session, data.card);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||
hidePopup();
|
||||
this.popupCard = data.card;
|
||||
|
||||
Component parentComponent = SwingUtilities.getRoot(data.component);
|
||||
Point parentPoint = parentComponent.getLocationOnScreen();
|
||||
|
||||
// Draw Arrows for targets
|
||||
List<UUID> targets = data.card.getTargets();
|
||||
if (targets != null) {
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parentPoint.x, -parentPoint.y);
|
||||
for (UUID uuid : targets) {
|
||||
//System.out.println("Getting play area panel for uuid: " + uuid);
|
||||
|
||||
PlayAreaPanel p = session.getGame().getPlayers().get(uuid);
|
||||
if (p != null) {
|
||||
Point target = p.getLocationOnScreen();
|
||||
target.translate(-parentPoint.x, -parentPoint.y);
|
||||
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()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point target = permanent.getLocationOnScreen();
|
||||
target.translate(-parentPoint.x, -parentPoint.y);
|
||||
ArrowBuilder.addArrow((int)me.getX() + 35, (int)me.getY(), (int)target.getX() + 40, (int)target.getY() + 10, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw Arrows for source
|
||||
if (data.card.isAbility()) {
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parentPoint.x, -parentPoint.y);
|
||||
UUID uuid = data.card.getParentId();
|
||||
for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point source = permanent.getLocationOnScreen();
|
||||
source.translate(-parentPoint.x, -parentPoint.y);
|
||||
ArrowBuilder.addArrow((int)source.getX() + 40, (int)source.getY() + 10, (int)me.getX() + 35, (int)me.getY() + 20, Color.blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showPopup(data, parentComponent, parentPoint);
|
||||
}
|
||||
// Draw Arrows for targets
|
||||
List<UUID> targets = data.card.getTargets();
|
||||
if (targets != null) {
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parentPoint.x, -parentPoint.y);
|
||||
for (UUID uuid : targets) {
|
||||
//System.out.println("Getting play area panel for uuid: " + uuid);
|
||||
|
||||
private void showPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
|
||||
PlayAreaPanel p = session.getGame().getPlayers().get(uuid);
|
||||
if (p != null) {
|
||||
Point target = p.getLocationOnScreen();
|
||||
target.translate(-parentPoint.x, -parentPoint.y);
|
||||
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()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point target = permanent.getLocationOnScreen();
|
||||
target.translate(-parentPoint.x, -parentPoint.y);
|
||||
ArrowBuilder.addArrow((int) me.getX() + 35, (int) me.getY(), (int) target.getX() + 40, (int) target.getY() + 10, Color.red);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw Arrows for source
|
||||
if (data.card.isAbility()) {
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parentPoint.x, -parentPoint.y);
|
||||
UUID uuid = data.card.getParentId();
|
||||
for (PlayAreaPanel pa : session.getGame().getPlayers().values()) {
|
||||
MagePermanent permanent = pa.getBattlefieldPanel().getPermanents().get(uuid);
|
||||
if (permanent != null) {
|
||||
Point source = permanent.getLocationOnScreen();
|
||||
source.translate(-parentPoint.x, -parentPoint.y);
|
||||
ArrowBuilder.addArrow((int) source.getX() + 40, (int) source.getY() + 10, (int) me.getX() + 35, (int) me.getY() + 20, Color.blue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
showPopup(data, parentComponent, parentPoint);
|
||||
}
|
||||
|
||||
private void showPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
|
||||
if (cardInfoPane == null) {
|
||||
PopupFactory factory = PopupFactory.getSharedInstance();
|
||||
popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||
|
@ -133,72 +135,73 @@ public class MageActionCallback implements ActionCallback {
|
|||
ThreadUtils.threadPool2.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ThreadUtils.threadPool2.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ThreadUtils.sleep(700);
|
||||
ThreadUtils.sleep(700);
|
||||
|
||||
if (!popupCard.equals(data.card)) {
|
||||
return;
|
||||
}
|
||||
if (!popupCard.equals(data.card)) {
|
||||
return;
|
||||
}
|
||||
|
||||
/*PopupFactory factory = PopupFactory.getSharedInstance();
|
||||
((CardInfoPane)cardInfoPane).setCard(data.card);
|
||||
cardInfoPane.setSize(161, 221);
|
||||
cardInfoPane.setPreferredSize(new Dimension(161, 221));
|
||||
popup = factory.getPopup(data.component, cardInfoPane, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||
popup.show();
|
||||
*/
|
||||
|
||||
try {
|
||||
Component popup2 = session.getUI().getComponent(MageComponents.CARD_INFO_PANE);
|
||||
((CardInfoPane)popup2).setCard(data.card);
|
||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, popup2, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popup2.setLocation(location);
|
||||
ThreadUtils.sleep(200);
|
||||
popup2.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
final Component popupContainer = session.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||
Component popup2 = session.getUI().getComponent(MageComponents.CARD_INFO_PANE);
|
||||
((CardInfoPane) popup2).setCard(data.card);
|
||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
|
||||
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, popup2, parentComponent);
|
||||
location.translate(-parentPoint.x, -parentPoint.y);
|
||||
popupContainer.setLocation(location);
|
||||
ThreadUtils.sleep(200);
|
||||
final Component c = session.getUI().getComponent(MageComponents.DESKTOP_PANE);
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
popupContainer.setVisible(true);
|
||||
c.repaint();
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e, TransferData data) {
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {return;}
|
||||
if (bigCard == null) {return;}
|
||||
|
||||
MageCard card = (MageCard) data.component;
|
||||
if (card.getOriginal().getId() != bigCard.getCardId()) {
|
||||
synchronized (MageActionCallback.class) {
|
||||
if (card.getOriginal().getId() != bigCard.getCardId()) {
|
||||
Image image = card.getImage();
|
||||
if (image != null && image instanceof BufferedImage) {
|
||||
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth(), bigCard.getHeight());
|
||||
bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules());
|
||||
bigCard.showTextComponent();
|
||||
if (card.getOriginal().isAbility()) {
|
||||
bigCard.showTextComponent();
|
||||
} else {
|
||||
bigCard.hideTextComponent();
|
||||
};
|
||||
} else {
|
||||
JXPanel panel = GuiDisplayUtil.getDescription(card.getOriginal(), bigCard.getWidth(), bigCard.getHeight());
|
||||
panel.setVisible(true);
|
||||
bigCard.hideTextComponent();
|
||||
bigCard.addJXPanel(card.getOriginal().getId(), panel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e, TransferData data) {
|
||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||
return;
|
||||
}
|
||||
if (bigCard == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MageCard card = (MageCard) data.component;
|
||||
if (card.getOriginal().getId() != bigCard.getCardId()) {
|
||||
synchronized (MageActionCallback.class) {
|
||||
if (card.getOriginal().getId() != bigCard.getCardId()) {
|
||||
Image image = card.getImage();
|
||||
if (image != null && image instanceof BufferedImage) {
|
||||
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth(), bigCard.getHeight());
|
||||
bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules());
|
||||
bigCard.showTextComponent();
|
||||
if (card.getOriginal().isAbility()) {
|
||||
bigCard.showTextComponent();
|
||||
} else {
|
||||
bigCard.hideTextComponent();
|
||||
}
|
||||
;
|
||||
} else {
|
||||
JXPanel panel = GuiDisplayUtil.getDescription(card.getOriginal(), bigCard.getWidth(), bigCard.getHeight());
|
||||
panel.setVisible(true);
|
||||
bigCard.hideTextComponent();
|
||||
bigCard.addJXPanel(card.getOriginal().getId(), panel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void hidePopup() {
|
||||
this.popupCard = null;
|
||||
|
@ -209,17 +212,17 @@ public class MageActionCallback implements ActionCallback {
|
|||
jPopupMenu.setVisible(false);
|
||||
}
|
||||
try {
|
||||
Component popup2 = session.getUI().getComponent(MageComponents.CARD_INFO_PANE);
|
||||
popup2.setVisible(false);
|
||||
Component popupContainer = session.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||
popupContainer.setVisible(false);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();;
|
||||
e2.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
hidePopup();
|
||||
ArrowBuilder.removeAllArrows();
|
||||
}
|
||||
ArrowBuilder.removeAllArrows();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -169,16 +169,16 @@ public class Plugins implements MagePlugins {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAddCard(MagePermanent card) {
|
||||
public void onAddCard(MagePermanent card, int count) {
|
||||
if (this.cardPlugin != null) {
|
||||
this.cardPlugin.onAddCard(card);
|
||||
this.cardPlugin.onAddCard(card, count);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoveCard(MagePermanent card) {
|
||||
public void onRemoveCard(MagePermanent card, int count) {
|
||||
if (this.cardPlugin != null) {
|
||||
this.cardPlugin.onRemoveCard(card);
|
||||
this.cardPlugin.onRemoveCard(card, count);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -11,10 +11,12 @@ import mage.utils.CardUtil;
|
|||
import mage.view.CardView;
|
||||
|
||||
import org.jdesktop.swingx.JXPanel;
|
||||
import sun.plugin.com.event.COMEventHandler;
|
||||
|
||||
public class GuiDisplayUtil {
|
||||
private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15);
|
||||
private static Insets DEFAULT_INSETS = new Insets(0,0, 68, 15);
|
||||
private static Insets DEFAULT_INSETS = new Insets(0, 0, 70, 25);
|
||||
private static Insets COMPONENT_INSETS = new Insets(0, 0, 40, 40);
|
||||
|
||||
public static JXPanel getDescription(CardView card, int width, int height) {
|
||||
JXPanel descriptionPanel = new JXPanel();
|
||||
|
@ -127,12 +129,12 @@ public class GuiDisplayUtil {
|
|||
}
|
||||
|
||||
public static Point keepComponentInsideParent(Point l, Point parentPoint, Component c, Component parent) {
|
||||
int dx = parentPoint.x + parent.getWidth() - DEFAULT_INSETS.right;
|
||||
int dx = parentPoint.x + parent.getWidth() - DEFAULT_INSETS.right - COMPONENT_INSETS.right;
|
||||
if (l.x + c.getWidth() > dx) {
|
||||
l.x = dx - c.getWidth();
|
||||
}
|
||||
|
||||
int dy = parentPoint.y + parent.getHeight() - DEFAULT_INSETS.bottom;
|
||||
int dy = parentPoint.y + parent.getHeight() - DEFAULT_INSETS.bottom - COMPONENT_INSETS.bottom;
|
||||
if (l.y + c.getHeight() > dy) {
|
||||
l.y = Math.max(10, dy - c.getHeight());
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public interface CardPlugin extends Plugin {
|
|||
void downloadImages(Set<Card> allCards);
|
||||
void downloadSymbols();
|
||||
Image getManaSymbolImage(String symbol);
|
||||
void onAddCard(MagePermanent card);
|
||||
void onRemoveCard(MagePermanent card);
|
||||
void onAddCard(MagePermanent card, int count);
|
||||
void onRemoveCard(MagePermanent card, int count);
|
||||
JComponent getCardInfoPane();
|
||||
}
|
||||
|
|
|
@ -287,8 +287,11 @@ abstract public class Animation {
|
|||
}
|
||||
}
|
||||
|
||||
static public void showCard(final MagePermanent card) {
|
||||
new Animation(600) {
|
||||
static public void showCard(final MagePermanent card, int count) {
|
||||
if (count == 0) {
|
||||
count = 1;
|
||||
}
|
||||
new Animation(600 / count) {
|
||||
protected void start () {
|
||||
}
|
||||
|
||||
|
@ -304,8 +307,11 @@ abstract public class Animation {
|
|||
};
|
||||
}
|
||||
|
||||
static public void hideCard(final MagePermanent card) {
|
||||
new Animation(600) {
|
||||
static public void hideCard(final MagePermanent card, int count) {
|
||||
if (count == 0) {
|
||||
count = 1;
|
||||
}
|
||||
new Animation(600 / count) {
|
||||
protected void start () {
|
||||
}
|
||||
|
||||
|
|
|
@ -416,6 +416,13 @@ public class CardPanel extends MagePermanent implements MouseListener, MouseMoti
|
|||
@Override
|
||||
public void setAlpha(float alpha) {
|
||||
this.alpha = alpha;
|
||||
if (alpha == 0) {
|
||||
this.ptText.setVisible(false);
|
||||
this.titleText.setVisible(false);
|
||||
} else if (alpha == 1.0f) {
|
||||
this.ptText.setVisible(true);
|
||||
this.titleText.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public float getAlpha() {
|
||||
|
|
|
@ -438,9 +438,9 @@ public class CardPluginImpl implements CardPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onAddCard(MagePermanent card) {
|
||||
public void onAddCard(MagePermanent card, int count) {
|
||||
if (card != null) {
|
||||
Animation.showCard((CardPanel) card);
|
||||
Animation.showCard((CardPanel) card, count > 0 ? count : 1);
|
||||
try {
|
||||
while ((card).getAlpha() + 0.05f < 1) {
|
||||
Thread.sleep(30);
|
||||
|
@ -452,9 +452,9 @@ public class CardPluginImpl implements CardPlugin {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onRemoveCard(MagePermanent card) {
|
||||
public void onRemoveCard(MagePermanent card, int count) {
|
||||
if (card != null) {
|
||||
Animation.hideCard((CardPanel) card);
|
||||
Animation.hideCard((CardPanel) card, count > 0 ? count : 1);
|
||||
try {
|
||||
while ((card).getAlpha() - 0.05f > 0) {
|
||||
Thread.sleep(30);
|
||||
|
|
|
@ -24,98 +24,77 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
|
||||
public CardInfoPaneImpl() {
|
||||
UI.setHTMLEditorKit(this);
|
||||
setEditable(false);
|
||||
setBackground(Color.white);
|
||||
setSize(170, Integer.MAX_VALUE);
|
||||
setEditable(false);
|
||||
setBackground(Color.white);
|
||||
}
|
||||
|
||||
public void setCard (final CardView card) {
|
||||
public void setCard(final CardView card) {
|
||||
if (card == null) return;
|
||||
if (isCurrentCard(card)) return;
|
||||
currentCard = card;
|
||||
if (isCurrentCard(card)) return;
|
||||
currentCard = card;
|
||||
|
||||
ThreadUtils.threadPool.submit(new Runnable() {
|
||||
public void run () {
|
||||
if (!card.equals(currentCard)) return;
|
||||
public void run() {
|
||||
if (!card.equals(currentCard)) return;
|
||||
|
||||
String manaCost = "";
|
||||
for (String m : card.getManaCost()) {
|
||||
manaCost += m;
|
||||
}
|
||||
String castingCost = UI.getDisplayManaCost(manaCost);
|
||||
castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, false);
|
||||
castingCost = ManaSymbols.replaceSymbolsWithHTML(castingCost, false);
|
||||
|
||||
int symbolCount = 0;
|
||||
int offset = 0;
|
||||
while ((offset = castingCost.indexOf("<img", offset) + 1) != 0)
|
||||
symbolCount++;
|
||||
int offset = 0;
|
||||
while ((offset = castingCost.indexOf("<img", offset) + 1) != 0)
|
||||
symbolCount++;
|
||||
|
||||
List<String> rulings = card.getRules();
|
||||
|
||||
boolean smallImages = true;
|
||||
int fontSize = 11;
|
||||
int fontSize = 11;
|
||||
|
||||
String fontFamily = "tahoma";
|
||||
/*if (prefs.fontFamily == CardFontFamily.arial)
|
||||
fontFamily = "arial";
|
||||
else if (prefs.fontFamily == CardFontFamily.verdana) {
|
||||
fontFamily = "verdana";
|
||||
}*/
|
||||
String fontFamily = "tahoma";
|
||||
/*if (prefs.fontFamily == CardFontFamily.arial)
|
||||
fontFamily = "arial";
|
||||
else if (prefs.fontFamily == CardFontFamily.verdana) {
|
||||
fontFamily = "verdana";
|
||||
}*/
|
||||
|
||||
final StringBuffer buffer = new StringBuffer(512);
|
||||
buffer.append("<html><body style='font-family:");
|
||||
buffer.append(fontFamily);
|
||||
buffer.append(";font-size:");
|
||||
buffer.append(fontSize);
|
||||
buffer.append("pt;margin:0px 1px 0px 1px'>");
|
||||
buffer.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'>");
|
||||
buffer.append("<tr><td valign='top'><b>");
|
||||
buffer.append(card.getName());
|
||||
buffer.append("</b></td><td align='right' valign='top' style='width:");
|
||||
buffer.append(symbolCount * 11 + 1);
|
||||
buffer.append("px'>");
|
||||
buffer.append(castingCost);
|
||||
buffer.append("</td></tr></table>");
|
||||
buffer.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'><tr><td>");
|
||||
buffer.append(getTypes(card));
|
||||
final StringBuffer buffer = new StringBuffer(512);
|
||||
buffer.append("<html><body style='font-family:");
|
||||
buffer.append(fontFamily);
|
||||
buffer.append(";font-size:");
|
||||
buffer.append(fontSize);
|
||||
buffer.append("pt;margin:0px 1px 0px 1px'>");
|
||||
buffer.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'>");
|
||||
buffer.append("<tr><td valign='top'><b>");
|
||||
buffer.append(card.getName());
|
||||
buffer.append("</b></td><td align='right' valign='top' style='width:");
|
||||
buffer.append(symbolCount * 11 + 1);
|
||||
buffer.append("px'>");
|
||||
buffer.append(castingCost);
|
||||
buffer.append("</td></tr></table>");
|
||||
buffer.append("<table cellspacing=0 cellpadding=0 border=0 width='100%'><tr><td style='margin-left: 1px'>");
|
||||
buffer.append(getTypes(card));
|
||||
buffer.append("</td><td align='right'>");
|
||||
switch (card.getRarity()) {
|
||||
case RARE:
|
||||
buffer.append("<b color='#E1D519'>");
|
||||
break;
|
||||
case UNCOMMON:
|
||||
buffer.append("<b color='silver'>");
|
||||
break;
|
||||
case COMMON:
|
||||
buffer.append("<b color='black'>");
|
||||
break;
|
||||
case RARE:
|
||||
buffer.append("<b color='#FFBF00'>");
|
||||
break;
|
||||
case UNCOMMON:
|
||||
buffer.append("<b color='silver'>");
|
||||
break;
|
||||
case COMMON:
|
||||
buffer.append("<b color='black'>");
|
||||
break;
|
||||
case MYTHIC:
|
||||
buffer.append("<b color='#D5330B'>");
|
||||
break;
|
||||
}
|
||||
buffer.append(card.getExpansionSetCode().toUpperCase());
|
||||
buffer.append("<b color='#D5330B'>");
|
||||
break;
|
||||
}
|
||||
buffer.append(card.getExpansionSetCode().toUpperCase());
|
||||
buffer.append("</td></tr></table>");
|
||||
|
||||
String legal = "";
|
||||
if (rulings.size() > 0) {
|
||||
legal = legal.replaceAll("#([^#]+)#", "<i>$1</i>");
|
||||
legal = legal.replaceAll("\\s*//\\s*", "<hr width='50%'>");
|
||||
legal = legal.replace("\r\n", "<div style='font-size:5pt'></div>");
|
||||
legal += "<br>";
|
||||
for (String ruling : rulings) {
|
||||
legal += "<p style='margin: 2px'>";
|
||||
legal += ruling;
|
||||
legal += "</p>";
|
||||
}
|
||||
}
|
||||
|
||||
if (legal.length() > 0) {
|
||||
buffer.append("<br>");
|
||||
legal = legal.replaceAll("\\{this\\}", card.getName());
|
||||
legal = legal.replaceAll("\\{source\\}", card.getName());
|
||||
buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, smallImages));
|
||||
}
|
||||
|
||||
String pt = "";
|
||||
if (CardUtil.isCreature(card)) {
|
||||
pt = card.getPower() + "/" + card.getToughness();
|
||||
|
@ -124,23 +103,42 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
}
|
||||
if (pt.length() > 0) {
|
||||
buffer.append("<table cellspacing=0 cellpadding=0 border=0 width='100%' valign='bottom'><tr><td>");
|
||||
buffer.append("</td><td align='right'>");
|
||||
buffer.append("<b>");
|
||||
buffer.append(pt);
|
||||
buffer.append("</b>");
|
||||
buffer.append("</td></tr></table>");
|
||||
buffer.append("<b>");
|
||||
buffer.append(pt);
|
||||
buffer.append("</b>");
|
||||
buffer.append("</td></tr></table>");
|
||||
}
|
||||
|
||||
String legal = "";
|
||||
if (rulings.size() > 0) {
|
||||
legal = legal.replaceAll("#([^#]+)#", "<i>$1</i>");
|
||||
legal = legal.replaceAll("\\s*//\\s*", "<hr width='50%'>");
|
||||
legal = legal.replace("\r\n", "<div style='font-size:5pt'></div>");
|
||||
legal += "<br>";
|
||||
for (String ruling : rulings) {
|
||||
legal += "<p style='margin: 2px'>";
|
||||
legal += ruling;
|
||||
legal += "</p>";
|
||||
}
|
||||
}
|
||||
|
||||
if (legal.length() > 0) {
|
||||
//buffer.append("<br>");
|
||||
legal = legal.replaceAll("\\{this\\}", card.getName());
|
||||
legal = legal.replaceAll("\\{source\\}", card.getName());
|
||||
buffer.append(ManaSymbols.replaceSymbolsWithHTML(legal, smallImages));
|
||||
}
|
||||
|
||||
buffer.append("<br></body></html>");
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run () {
|
||||
if (!card.equals(currentCard)) return;
|
||||
setText(buffer.toString());
|
||||
public void run() {
|
||||
if (!card.equals(currentCard)) return;
|
||||
setText(buffer.toString());
|
||||
//System.out.println(buffer.toString());
|
||||
setCaretPosition(0);
|
||||
}
|
||||
});
|
||||
setCaretPosition(0);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -162,7 +160,7 @@ public class CardInfoPaneImpl extends JEditorPane implements CardInfoPane {
|
|||
return types.trim();
|
||||
}
|
||||
|
||||
public boolean isCurrentCard (CardView card) {
|
||||
return currentCard != null && card.equals(currentCard);
|
||||
}
|
||||
public boolean isCurrentCard(CardView card) {
|
||||
return currentCard != null && card.equals(currentCard);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue