mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 19:11:59 -08:00
Updated mageactioncallback. Commented out popups for a while (not always work correctly). Added delayed viewer.
This commit is contained in:
parent
0721c843d2
commit
1fcac53bf7
2 changed files with 78 additions and 41 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package mage.client.plugins.adapters;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
|
@ -8,8 +9,9 @@ import java.awt.image.BufferedImage;
|
|||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.swing.JDesktopPane;
|
||||
import javax.swing.JLayeredPane;
|
||||
import javax.swing.Popup;
|
||||
import javax.swing.PopupFactory;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import mage.cards.MageCard;
|
||||
|
|
@ -18,9 +20,11 @@ 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;
|
||||
import mage.client.thread.DelayedViewerThread;
|
||||
import mage.client.util.DefaultActionCallback;
|
||||
import mage.client.util.ImageHelper;
|
||||
import mage.client.util.gui.ArrowBuilder;
|
||||
|
|
@ -62,10 +66,7 @@ public class MageActionCallback implements ActionCallback {
|
|||
public void mouseEntered(MouseEvent e, final TransferData data) {
|
||||
this.popupCard = data.card;
|
||||
if (popup != null) {
|
||||
//synchronized (MageActionCallback.this) {
|
||||
popup.hide();
|
||||
state = 0;
|
||||
//}
|
||||
//DelayedViewerThread.getInstance().hide(data.popupText);
|
||||
}
|
||||
|
||||
// Draw Arrows for targets
|
||||
|
|
@ -111,34 +112,22 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e1) {}
|
||||
state = 1;
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
showPopup(data);
|
||||
//showPopup(data);
|
||||
}
|
||||
|
||||
private void showPopup( final TransferData data) {
|
||||
while (state == 0) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
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();
|
||||
}
|
||||
if (state > 1) {
|
||||
return;
|
||||
}
|
||||
PopupFactory factory = PopupFactory.getSharedInstance();
|
||||
popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||
popup.show();
|
||||
|
||||
//PopupFactory factory = PopupFactory.getSharedInstance();
|
||||
//popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||
//popup.show();
|
||||
// hack to get popup to resize to fit text
|
||||
//popup.hide();
|
||||
//popup = factory.getPopup(data.component, data.popupText, (int) data.locationOnScreen.getX() + data.popupOffsetX, (int) data.locationOnScreen.getY() + data.popupOffsetY + 40);
|
||||
|
|
@ -176,20 +165,13 @@ public class MageActionCallback implements ActionCallback {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
public void mouseExited(MouseEvent e, final TransferData data) {
|
||||
this.popupCard = null;
|
||||
//DelayedViewerThread.getInstance().hide(data.popupText);
|
||||
if (popup != null) {
|
||||
//synchronized (MageActionCallback.this) {
|
||||
if (t != null) {
|
||||
try {
|
||||
t.stop();
|
||||
} catch (Exception e1) {}
|
||||
}
|
||||
popup.hide();
|
||||
state = 0;
|
||||
//}
|
||||
ArrowBuilder.removeAllArrows();
|
||||
//popup.hide();
|
||||
}
|
||||
ArrowBuilder.removeAllArrows();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
package mage.client.thread;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class DelayedViewerThread extends Thread {
|
||||
private static DelayedViewerThread fInstance = new DelayedViewerThread();
|
||||
|
||||
public static DelayedViewerThread getInstance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
private final Map<Component, Long> delayedViewers;
|
||||
|
||||
protected DelayedViewerThread() {
|
||||
delayedViewers = new HashMap<Component, Long>();
|
||||
start();
|
||||
}
|
||||
|
||||
public synchronized void show(Component component, long delay) {
|
||||
delayedViewers.put(component, System.currentTimeMillis() + delay);
|
||||
notify();
|
||||
}
|
||||
|
||||
public synchronized void hide(Component component) {
|
||||
delayedViewers.remove(component);
|
||||
component.setVisible(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void run() {
|
||||
while (true) {
|
||||
try {
|
||||
if (delayedViewers.isEmpty()) {
|
||||
wait();
|
||||
}
|
||||
final long time = System.currentTimeMillis();
|
||||
for (Iterator<Component> it = delayedViewers.keySet().iterator(); it.hasNext();) {
|
||||
Component component = it.next();
|
||||
final long delayedTime = delayedViewers.get(component);
|
||||
if (delayedTime <= time) {
|
||||
component.setVisible(true);
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
wait(100);
|
||||
} catch (final InterruptedException ex) {
|
||||
System.out.println("Interrupted : " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue