mirror of
https://github.com/correl/mage.git
synced 2024-11-15 03:00:16 +00:00
Rewrote displaying tooltips (fixes grayed rectangle bug and wrong tooltip location on the edge).
This commit is contained in:
parent
caae384903
commit
760f059fb8
4 changed files with 74 additions and 51 deletions
|
@ -34,12 +34,7 @@
|
|||
|
||||
package mage.client;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.SplashScreen;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
|
@ -148,7 +143,14 @@ public class MageFrame extends javax.swing.JFrame {
|
|||
combat.hideDialog();
|
||||
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);
|
||||
session.getUI().addComponent(MageComponents.CARD_INFO_PANE, cardInfoPane);
|
||||
desktopPane.add(cardInfoPane, JLayeredPane.POPUP_LAYER);
|
||||
|
||||
String filename = "/background.jpg";
|
||||
try {
|
||||
if (Plugins.getInstance().isThemePluginLoaded()) {
|
||||
|
|
|
@ -5,7 +5,8 @@ public enum MageComponents {
|
|||
NEW_GAME_BUTTON("btnNewTable"),
|
||||
NEW_TABLE_OK_BUTTON("btnOK"),
|
||||
TABLE_WAITING_START_BUTTON("btnStart"),
|
||||
DESKTOP_PANE("desktopPane");
|
||||
DESKTOP_PANE("desktopPane"),
|
||||
CARD_INFO_PANE("cardInfoPane");
|
||||
|
||||
private String name;
|
||||
MageComponents(String name) {
|
||||
|
|
|
@ -15,6 +15,7 @@ import mage.cards.action.ActionCallback;
|
|||
import mage.cards.action.TransferData;
|
||||
import mage.client.MageFrame;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.components.MageComponents;
|
||||
import mage.client.game.PlayAreaPanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.remote.Session;
|
||||
|
@ -68,32 +69,31 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||
this.popupCard = data.card;
|
||||
if (popup != null) {
|
||||
//DelayedViewerThread.getInstance().hide(data.popupText);
|
||||
popup.hide();
|
||||
}
|
||||
|
||||
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 parent = SwingUtilities.getRoot(data.component).getLocationOnScreen();
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parent.x, -parent.y);
|
||||
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(-parent.x, -parent.y);
|
||||
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(-parent.x, -parent.y);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -103,33 +103,23 @@ public class MageActionCallback implements ActionCallback {
|
|||
|
||||
// Draw Arrows for source
|
||||
if (data.card.isAbility()) {
|
||||
Point parent = SwingUtilities.getRoot(data.component).getLocationOnScreen();
|
||||
Point me = new Point(data.locationOnScreen);
|
||||
me.translate(-parent.x, -parent.y);
|
||||
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(-parent.x, -parent.y);
|
||||
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);
|
||||
showPopup(data, parentComponent, parentPoint);
|
||||
}
|
||||
|
||||
private void showPopup(final TransferData data) {
|
||||
/*try {
|
||||
((JDesktopPane)session.getUI().getComponent(MageComponents.DESKTOP_PANE)).add(data.popupText, JLayeredPane.POPUP_LAYER);
|
||||
data.popupText.setBounds((int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40, 200, 200);
|
||||
data.popupText.setText("Test");
|
||||
DelayedViewerThread.getInstance().show((Component)data.popupText, 500);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}*/
|
||||
|
||||
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);
|
||||
|
@ -146,20 +136,31 @@ public class MageActionCallback implements ActionCallback {
|
|||
ThreadUtils.threadPool2.submit(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(900);
|
||||
} catch (InterruptedException ie) {
|
||||
ie.printStackTrace();
|
||||
}
|
||||
ThreadUtils.sleep(900);
|
||||
|
||||
if (!popupCard.equals(data.card)) {
|
||||
return;
|
||||
}
|
||||
PopupFactory factory = PopupFactory.getSharedInstance();
|
||||
|
||||
/*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);
|
||||
popup2.setVisible(true);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -198,16 +199,25 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
this.popupCard = null;
|
||||
//DelayedViewerThread.getInstance().hide(data.popupText);
|
||||
if (popup != null) {
|
||||
popup.hide();
|
||||
}
|
||||
private void hidePopup() {
|
||||
this.popupCard = null;
|
||||
if (popup != null) {
|
||||
popup.hide();
|
||||
}
|
||||
if (jPopupMenu != null) {
|
||||
jPopupMenu.setVisible(false);
|
||||
}
|
||||
try {
|
||||
Component popup2 = session.getUI().getComponent(MageComponents.CARD_INFO_PANE);
|
||||
popup2.setVisible(false);
|
||||
} catch (Exception e2) {
|
||||
e2.printStackTrace();;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
hidePopup();
|
||||
ArrowBuilder.removeAllArrows();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
package mage.client.util.gui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Insets;
|
||||
import java.awt.*;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
|
@ -19,6 +14,7 @@ import org.jdesktop.swingx.JXPanel;
|
|||
|
||||
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);
|
||||
|
||||
public static JXPanel getDescription(CardView card, int width, int height) {
|
||||
JXPanel descriptionPanel = new JXPanel();
|
||||
|
@ -129,4 +125,18 @@ public class GuiDisplayUtil {
|
|||
System.out.println("null");
|
||||
}
|
||||
}
|
||||
|
||||
public static Point keepComponentInsideParent(Point l, Point parentPoint, Component c, Component parent) {
|
||||
int dx = parentPoint.x + parent.getWidth() - DEFAULT_INSETS.right;
|
||||
if (l.x + c.getWidth() > dx) {
|
||||
l.x = dx - c.getWidth();
|
||||
}
|
||||
|
||||
int dy = parentPoint.y + parent.getHeight() - DEFAULT_INSETS.bottom;
|
||||
if (l.y + c.getHeight() > dy) {
|
||||
l.y = Math.max(10, dy - c.getHeight());
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue