use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method clearDragging.
private void clearDragging(MageCard clearCard) {
if (this.startedDragging && prevCardPanel != null && clearCard != null) {
// distribute cards between cards container and a drag container
for (Component comp : clearCard.getCardContainer().getComponents()) {
if (comp instanceof MageCard) {
MageCard realCard = (MageCard) comp;
if (draggingCards.contains(realCard)) {
realCard.setCardLocation(realCard.getCardLocation().getCardX(), realCard.getCardLocation().getCardY() - GO_DOWN_ON_DRAG_Y_OFFSET);
}
}
}
clearCard.setCardLocation(clearCard.getCardLocation().getCardX(), clearCard.getCardLocation().getCardY() + GO_UP_ON_DRAG_Y_OFFSET);
sortHandCards(clearCard, clearCard.getCardContainer(), true);
draggingCards.clear();
}
prevCardPanel = null;
}
use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method mouseDragged.
@Override
public void mouseDragged(MouseEvent e, TransferData data) {
// start the dragging
MageCard cardPanel = data.getComponent().getTopPanelRef();
if (cardPanel.getZone() != Zone.HAND) {
// drag'n'drop is allowed for HAND zone only
return;
}
if (!SwingUtilities.isLeftMouseButton(e)) {
// only allow draging with the left mouse button
return;
}
isDragging = true;
prevCardPanel = cardPanel;
Point cardPanelLocationOld = cardPanel.getCardLocation().getCardPoint();
Point mouse = new Point(e.getX(), e.getY());
SwingUtilities.convertPointToScreen(mouse, data.getComponent());
// starting position
int xOffset = 0;
// TODO: fix
int newX = Math.max(initialCardPos.x + (int) (mouse.getX() - initialMousePos.x) - xOffset, 0);
cardPanel.setCardBounds(newX, cardPanelLocationOld.y, cardPanel.getCardLocation().getCardWidth(), cardPanel.getCardLocation().getCardHeight());
cardPanel.getCardContainer().setComponentZOrder(cardPanel, 0);
sortHandCards(cardPanel, cardPanel.getCardContainer(), false);
if (!this.startedDragging) {
this.startedDragging = true;
}
}
use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method startCardHintPopup.
private void startCardHintPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
MageCard cardPanel = data.getComponent().getTopPanelRef();
if (data.getTooltipDelay() > 0) {
// custom tooltip
tooltipDelay = data.getTooltipDelay();
} else {
// from preferences
tooltipDelay = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_TOOLTIPS_DELAY, 300);
}
if (tooltipDelay == 0) {
// disabled
return;
}
if (cardInfoPane == null) {
// create new popup
if (data.getLocationOnScreen() == null) {
data.setLocationOnScreen(cardPanel.getCardLocationOnScreen().getCardPoint());
}
PopupFactory factory = PopupFactory.getSharedInstance();
data.getPopupText().updateText();
tooltipPopup = factory.getPopup(cardPanel, data.getPopupText(), (int) data.getLocationOnScreen().getX() + data.getPopupOffsetX(), (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() + 40);
tooltipPopup.show();
// hack to get popup to resize to fit text
tooltipPopup.hide();
tooltipPopup = factory.getPopup(cardPanel, data.getPopupText(), (int) data.getLocationOnScreen().getX() + data.getPopupOffsetX(), (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() + 40);
tooltipPopup.show();
} else {
showCardHintPopup(data, parentComponent, parentPoint);
}
}
use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method handleMouseMoveOverNewCard.
private void handleMouseMoveOverNewCard(TransferData data) {
MageCard cardPanel = data.getComponent().getTopPanelRef();
// Prevent to show tooltips from panes not in front
MagePane topPane = MageFrame.getTopMost(null);
if (topPane instanceof GamePane) {
if (data.getGameId() != null && !((GamePane) topPane).getGameId().equals(data.getGameId())) {
return;
}
}
hideTooltipPopup();
cancelTimeout();
Component parentComponent = SwingUtilities.getRoot(cardPanel);
if (parentComponent == null) {
// virtual card (example: show card popup in non cards panel like PickChoiceDialog)
parentComponent = MageFrame.getDesktop();
}
Point parentPoint = parentComponent.getLocationOnScreen();
if (data.getLocationOnScreen() == null) {
data.setLocationOnScreen(cardPanel.getCardLocationOnScreen().getCardPoint());
}
ArrowUtil.drawArrowsForTargets(data, parentPoint);
ArrowUtil.drawArrowsForSource(data, parentPoint);
ArrowUtil.drawArrowsForPairedCards(data, parentPoint);
ArrowUtil.drawArrowsForBandedCards(data, parentPoint);
ArrowUtil.drawArrowsForEnchantPlayers(data, parentPoint);
tooltipCard = data.getCard();
startCardHintPopup(data, parentComponent, parentPoint);
}
use of mage.cards.MageCard in project mage by magefree.
the class MageActionCallback method showCardHintPopup.
private void showCardHintPopup(final TransferData data, final Component parentComponent, final Point parentPoint) {
MageCard cardPanel = data.getComponent().getTopPanelRef();
ThreadUtils.threadPool2.submit(new Runnable() {
@Override
public void run() {
ThreadUtils.sleep(tooltipDelay);
if (tooltipCard == null || !tooltipCard.equals(data.getCard()) || SessionHandler.getSession() == null || !popupTextWindowOpen || enlargedWindowState != EnlargedWindowState.CLOSED) {
return;
}
try {
final Component popupContainer = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
Component popupInfo = MageFrame.getUI().getComponent(MageComponents.CARD_INFO_PANE);
((CardInfoPane) popupInfo).setCard(data.getCard(), popupContainer);
showPopup(popupContainer, popupInfo);
} catch (InterruptedException e) {
logger.error("Can't show card tooltip", e);
Thread.currentThread().interrupt();
}
}
public void showPopup(final Component popupContainer, final Component infoPane) throws InterruptedException {
final Component c = MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
SwingUtilities.invokeLater(() -> {
if (!popupTextWindowOpen || enlargedWindowState != EnlargedWindowState.CLOSED) {
return;
}
if (data.getLocationOnScreen() == null) {
data.setLocationOnScreen(cardPanel.getCardLocationOnScreen().getCardPoint());
}
Point location = new Point((int) data.getLocationOnScreen().getX() + data.getPopupOffsetX() - 40, (int) data.getLocationOnScreen().getY() + data.getPopupOffsetY() - 40);
location = GuiDisplayUtil.keepComponentInsideParent(location, parentPoint, infoPane, parentComponent);
location.translate(-parentPoint.x, -parentPoint.y);
popupContainer.setLocation(location);
popupContainer.setVisible(true);
c.repaint();
});
}
});
}
Aggregations