mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
[UI] displaying tooltips: clean up and code refactoring
This commit is contained in:
parent
7443e2a9fa
commit
44a3c05ba8
1 changed files with 108 additions and 118 deletions
|
@ -79,13 +79,53 @@ public class MageActionCallback implements ActionCallback {
|
||||||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||||
hidePopup();
|
hidePopup();
|
||||||
cancelTimeout();
|
cancelTimeout();
|
||||||
|
|
||||||
this.popupCard = data.card;
|
this.popupCard = data.card;
|
||||||
this.popupData = data;
|
this.popupData = data;
|
||||||
|
|
||||||
Component parentComponent = SwingUtilities.getRoot(data.component);
|
Component parentComponent = SwingUtilities.getRoot(data.component);
|
||||||
Point parentPoint = parentComponent.getLocationOnScreen();
|
Point parentPoint = parentComponent.getLocationOnScreen();
|
||||||
|
|
||||||
// Draw Arrows for targets
|
drawArrowsForTargets(data, parentPoint);
|
||||||
|
drawArrowsForSource(data, parentPoint);
|
||||||
|
drawArrowsForPairedCards(data, parentPoint);
|
||||||
|
|
||||||
|
showPopup(data, parentComponent, parentPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawArrowsForPairedCards(TransferData data, Point parentPoint) {
|
||||||
|
if (data.card.getPairedCard() != null) {
|
||||||
|
Point me = new Point(data.locationOnScreen);
|
||||||
|
me.translate(-parentPoint.x, -parentPoint.y);
|
||||||
|
UUID uuid = data.card.getPairedCard();
|
||||||
|
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).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.green, ArrowBuilder.Type.PAIRED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawArrowsForSource(TransferData data, Point parentPoint) {
|
||||||
|
if (data.card.isAbility()) {
|
||||||
|
Point me = new Point(data.locationOnScreen);
|
||||||
|
me.translate(-parentPoint.x, -parentPoint.y);
|
||||||
|
UUID uuid = data.card.getParentId();
|
||||||
|
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).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, ArrowBuilder.Type.SOURCE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawArrowsForTargets(TransferData data, Point parentPoint) {
|
||||||
List<UUID> targets = data.card.getTargets();
|
List<UUID> targets = data.card.getTargets();
|
||||||
if (targets != null) {
|
if (targets != null) {
|
||||||
Point me = new Point(data.locationOnScreen);
|
Point me = new Point(data.locationOnScreen);
|
||||||
|
@ -109,38 +149,6 @@ public class MageActionCallback implements ActionCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 : MageFrame.getGame(data.gameId).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, ArrowBuilder.Type.SOURCE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Draw Arrows for paired cards
|
|
||||||
if (data.card.getPairedCard() != null) {
|
|
||||||
Point me = new Point(data.locationOnScreen);
|
|
||||||
me.translate(-parentPoint.x, -parentPoint.y);
|
|
||||||
UUID uuid = data.card.getPairedCard();
|
|
||||||
for (PlayAreaPanel pa : MageFrame.getGame(data.gameId).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.green, ArrowBuilder.Type.PAIRED);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
showPopup(data, parentComponent, parentPoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
|
private void showPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
|
||||||
|
@ -150,14 +158,10 @@ public class MageActionCallback implements ActionCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.component instanceof MageCard) {
|
if (data.component instanceof MageCard) {
|
||||||
//String zone = ((MageCard)(data.component)).getZone();
|
|
||||||
//if (zone != null && zone.equals(Constants.Zone.HAND.toString())) {
|
|
||||||
// for performance getting cached value
|
|
||||||
String showTooltips = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_ANY_ZONE, "true");
|
String showTooltips = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_ANY_ZONE, "true");
|
||||||
if (showTooltips.equals("false")) {
|
if (showTooltips.equals("false")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cardInfoPane == null) {
|
if (cardInfoPane == null) {
|
||||||
|
@ -169,7 +173,11 @@ public class MageActionCallback implements ActionCallback {
|
||||||
popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||||
popup.show();
|
popup.show();
|
||||||
} else {
|
} else {
|
||||||
|
sumbitShowPopupTask(data, parentComponent, parentPoint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sumbitShowPopupTask(final TransferData data, final Component parentComponent, final Point parentPoint) {
|
||||||
ThreadUtils.threadPool2.submit(new Runnable() {
|
ThreadUtils.threadPool2.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -183,14 +191,19 @@ public class MageActionCallback implements ActionCallback {
|
||||||
if (session == null || !state || enlarged) {
|
if (session == null || !state || enlarged) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||||
Component popup2 = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
|
Component popup2 = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
|
||||||
|
|
||||||
((CardInfoPane) popup2).setCard(data.card);
|
((CardInfoPane) popup2).setCard(data.card);
|
||||||
|
|
||||||
Point location = new Point((int) data.locationOnScreen.getX() + data.popupOffsetX - 40, (int) data.locationOnScreen.getY() + data.popupOffsetY - 40);
|
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 = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, popup2, parentComponent);
|
||||||
location.translate(-parentPoint.x, -parentPoint.y);
|
location.translate(-parentPoint.x, -parentPoint.y);
|
||||||
popupContainer.setLocation(location);
|
popupContainer.setLocation(location);
|
||||||
|
|
||||||
ThreadUtils.sleep(200);
|
ThreadUtils.sleep(200);
|
||||||
|
|
||||||
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
|
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -203,13 +216,12 @@ public class MageActionCallback implements ActionCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -231,21 +243,7 @@ public class MageActionCallback implements ActionCallback {
|
||||||
}
|
}
|
||||||
state = true;
|
state = true;
|
||||||
Image image = card.getImage();
|
Image image = card.getImage();
|
||||||
if (image != null && image instanceof BufferedImage) {
|
displayCardInfo(card, image, bigCard);
|
||||||
// XXX: scaled to fit width
|
|
||||||
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth());
|
|
||||||
bigCard.setCard(card.getOriginal().getId(), image, card.getOriginal().getRules(), card.isFoil());
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -358,6 +356,16 @@ public class MageActionCallback implements ActionCallback {
|
||||||
MageCard card = (MageCard) data.component;
|
MageCard card = (MageCard) data.component;
|
||||||
Image image = card.getImage();
|
Image image = card.getImage();
|
||||||
BigCard bigCard = (BigCard)cardPreview;
|
BigCard bigCard = (BigCard)cardPreview;
|
||||||
|
displayCardInfo(card, image, bigCard);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void displayCardInfo(MageCard card, Image image, BigCard bigCard) {
|
||||||
if (image != null && image instanceof BufferedImage) {
|
if (image != null && image instanceof BufferedImage) {
|
||||||
// XXX: scaled to fit width
|
// XXX: scaled to fit width
|
||||||
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth());
|
image = ImageHelper.getResizedImage((BufferedImage) image, bigCard.getWidth());
|
||||||
|
@ -373,24 +381,6 @@ public class MageActionCallback implements ActionCallback {
|
||||||
bigCard.hideTextComponent();
|
bigCard.hideTextComponent();
|
||||||
bigCard.addJXPanel(card.getOriginal().getId(), panel);
|
bigCard.addJXPanel(card.getOriginal().getId(), panel);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!enlarged) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
popupContainer.setVisible(true);
|
|
||||||
c.repaint();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);*/
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void startHideTimeout() {
|
private synchronized void startHideTimeout() {
|
||||||
|
|
Loading…
Reference in a new issue