mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 20:41:58 -08:00
[UI] removing y offset effect because of no rely on mouse message existing/order
This commit is contained in:
parent
acd6514bab
commit
5dc2a1b8f5
1 changed files with 36 additions and 21 deletions
|
|
@ -49,7 +49,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
public static final double COMPARE_GAP_X = 30;
|
||||
|
||||
public static final int GO_DOWN_ON_DRAG_Y_OFFSET = 0;
|
||||
public static final int GO_UP_ON_DRAG_Y_OFFSET = 10;
|
||||
public static final int GO_UP_ON_DRAG_Y_OFFSET = 0;
|
||||
|
||||
public static final int MIN_X_OFFSET_REQUIRED = 20;
|
||||
|
||||
|
|
@ -73,6 +73,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
private static final ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(1);
|
||||
private ScheduledFuture<?> hideTimeout;
|
||||
|
||||
private CardPanel prevCard;
|
||||
private boolean startedDragging;
|
||||
private boolean isDragging;
|
||||
private Point initialCardPos;
|
||||
|
|
@ -200,8 +201,14 @@ public class MageActionCallback implements ActionCallback {
|
|||
@Override
|
||||
public void mousePressed(MouseEvent e, TransferData data) {
|
||||
data.component.requestFocusInWindow();
|
||||
|
||||
// for some reason sometime mouseRelease happens before numerous Mouse_Dragged events
|
||||
// that results in not finished dragging
|
||||
clearDragging(this.prevCard);
|
||||
|
||||
isDragging = false;
|
||||
startedDragging = false;
|
||||
prevCard = null;
|
||||
cardPanels.clear();
|
||||
Point mouse = new Point(e.getX(), e.getY());
|
||||
SwingUtilities.convertPointToScreen(mouse, data.component);
|
||||
|
|
@ -221,19 +228,9 @@ public class MageActionCallback implements ActionCallback {
|
|||
SwingUtilities.convertPointToScreen(mouse, transferData.component);
|
||||
int xOffset = card.getXOffset(card.getCardWidth());
|
||||
maxXOffset = Math.abs((int) (mouse.getX() - initialMousePos.x) - xOffset);
|
||||
|
||||
}
|
||||
|
||||
for (Component component : card.getCardArea().getComponents()) {
|
||||
if (component instanceof CardPanel) {
|
||||
if (cardPanels.contains(component)) {
|
||||
component.setLocation(component.getLocation().x, component.getLocation().y - GO_DOWN_ON_DRAG_Y_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
card.setLocation(card.getLocation().x, card.getLocation().y + GO_UP_ON_DRAG_Y_OFFSET);
|
||||
sort(card, card.getCardArea(), true);
|
||||
cardPanels.clear();
|
||||
clearDragging(card);
|
||||
|
||||
this.startedDragging = false;
|
||||
if (maxXOffset < MIN_X_OFFSET_REQUIRED) { // we need this for protection from small card movements
|
||||
|
|
@ -250,6 +247,22 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
}
|
||||
|
||||
private void clearDragging(CardPanel card) {
|
||||
if (this.startedDragging && prevCard != null && card != null) {
|
||||
for (Component component : card.getCardArea().getComponents()) {
|
||||
if (component instanceof CardPanel) {
|
||||
if (cardPanels.contains(component)) {
|
||||
component.setLocation(component.getLocation().x, component.getLocation().y - GO_DOWN_ON_DRAG_Y_OFFSET);
|
||||
}
|
||||
}
|
||||
}
|
||||
card.setLocation(card.getLocation().x, card.getLocation().y + GO_UP_ON_DRAG_Y_OFFSET);
|
||||
sort(card, card.getCardArea(), true);
|
||||
cardPanels.clear();
|
||||
}
|
||||
prevCard = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseMoved(MouseEvent e, TransferData transferData) {
|
||||
handlePopup(transferData);
|
||||
|
|
@ -263,6 +276,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
return;
|
||||
}
|
||||
isDragging = true;
|
||||
prevCard = card;
|
||||
Point p = card.getCardLocation();
|
||||
Point mouse = new Point(e.getX(), e.getY());
|
||||
SwingUtilities.convertPointToScreen(mouse, transferData.component);
|
||||
|
|
@ -281,6 +295,16 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
if (data != null) {
|
||||
hideAll(data.gameId);
|
||||
} else {
|
||||
hideAll(null);
|
||||
}
|
||||
///clearDragging((CardPanel)data.component);
|
||||
}
|
||||
|
||||
private void sort(CardPanel card, JPanel container, boolean sortSource) {
|
||||
java.util.List<CardPanel> cards = new ArrayList<CardPanel>();
|
||||
for (Component component : container.getComponents()) {
|
||||
|
|
@ -388,15 +412,6 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
if (data != null) {
|
||||
hideAll(data.gameId);
|
||||
} else {
|
||||
hideAll(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void hideGameUpdate(UUID gameId) {
|
||||
ArrowBuilder.getBuilder().removeArrowsByType(gameId, ArrowBuilder.Type.TARGET);
|
||||
ArrowBuilder.getBuilder().removeArrowsByType(gameId, ArrowBuilder.Type.PAIRED);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue