mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 10:40:06 -08:00
Fade in\fade out effects for adding and removing permanents.
This commit is contained in:
parent
55eba04697
commit
850f931bc7
9 changed files with 109 additions and 65 deletions
Binary file not shown.
|
|
@ -484,4 +484,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
|
||||||
public PermanentView getOriginalPermanent() {
|
public PermanentView getOriginalPermanent() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public float getAlpha() {return 0;}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,16 +39,19 @@ import java.awt.Dimension;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentAdapter;
|
||||||
import java.awt.event.ComponentEvent;
|
import java.awt.event.ComponentEvent;
|
||||||
import java.awt.event.ComponentListener;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.swing.JComponent;
|
import javax.swing.JComponent;
|
||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
|
|
||||||
|
import com.sun.swing.internal.plaf.synth.resources.synth;
|
||||||
|
|
||||||
import mage.cards.MagePermanent;
|
import mage.cards.MagePermanent;
|
||||||
import mage.client.cards.BigCard;
|
import mage.client.cards.BigCard;
|
||||||
import mage.client.cards.Permanent;
|
import mage.client.cards.Permanent;
|
||||||
|
|
@ -61,7 +64,7 @@ import mage.view.PermanentView;
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class BattlefieldPanel extends javax.swing.JLayeredPane implements ComponentListener {
|
public class BattlefieldPanel extends javax.swing.JLayeredPane {
|
||||||
|
|
||||||
private Map<UUID, MagePermanent> permanents = new HashMap<UUID, MagePermanent>();
|
private Map<UUID, MagePermanent> permanents = new HashMap<UUID, MagePermanent>();
|
||||||
private UUID gameId;
|
private UUID gameId;
|
||||||
|
|
@ -71,6 +74,7 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
protected static DefaultActionCallback defaultCallback = DefaultActionCallback.getInstance();
|
||||||
protected static Map<UUID, PermanentView> battlefield;
|
protected static Map<UUID, PermanentView> battlefield;
|
||||||
protected static Map<UUID, Integer> attachmentCache = new HashMap<UUID, Integer>();
|
protected static Map<UUID, Integer> attachmentCache = new HashMap<UUID, Integer>();
|
||||||
|
protected static List<Thread> threads = new ArrayList<Thread>();
|
||||||
|
|
||||||
/** Creates new form BattlefieldPanel */
|
/** Creates new form BattlefieldPanel */
|
||||||
public BattlefieldPanel(JScrollPane jScrollPane) {
|
public BattlefieldPanel(JScrollPane jScrollPane) {
|
||||||
|
|
@ -123,6 +127,12 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
if (changed) {
|
if (changed) {
|
||||||
BattlefieldPanel.battlefield = battlefield;
|
BattlefieldPanel.battlefield = battlefield;
|
||||||
sortLayout();
|
sortLayout();
|
||||||
|
synchronized (this) {
|
||||||
|
for (Thread t : threads) {
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
threads.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,19 +147,32 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPermanent(PermanentView permanent) {
|
private void addPermanent(PermanentView permanent) {
|
||||||
MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);
|
final MagePermanent perm = Plugins.getInstance().getMagePermanent(permanent, bigCard, Config.dimensions, gameId);
|
||||||
perm.addComponentListener(this);
|
|
||||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||||
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
perm.setBounds(findEmptySpace(new Dimension(Config.dimensions.frameWidth, Config.dimensions.frameHeight)));
|
||||||
|
} else {
|
||||||
|
perm.setAlpha(0);
|
||||||
}
|
}
|
||||||
permanents.put(permanent.getId(), perm);
|
permanents.put(permanent.getId(), perm);
|
||||||
this.add(perm, 10);
|
|
||||||
|
BattlefieldPanel.this.add(perm, 10);
|
||||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||||
moveToFront(perm);
|
moveToFront(perm);
|
||||||
perm.update(permanent);
|
perm.update(permanent);
|
||||||
|
} else {
|
||||||
|
Thread t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Plugins.getInstance().onAddCard(perm);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
synchronized (this) {
|
||||||
|
threads.add(t);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,14 +185,17 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
if (!Plugins.getInstance().isCardPluginLoaded()) {
|
||||||
for (UUID attachmentId: permanent.getAttachments()) {
|
for (UUID attachmentId: permanent.getAttachments()) {
|
||||||
MagePermanent link = permanents.get(attachmentId);
|
MagePermanent link = permanents.get(attachmentId);
|
||||||
|
if (link != null) {
|
||||||
perm.getLinks().add(link);
|
perm.getLinks().add(link);
|
||||||
r.translate(20, 20);
|
r.translate(20, 20);
|
||||||
link.setBounds(r);
|
link.setBounds(r);
|
||||||
setPosition(link, ++position);
|
setPosition(link, ++position);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
for (UUID attachmentId: permanent.getAttachments()) {
|
for (UUID attachmentId: permanent.getAttachments()) {
|
||||||
MagePermanent link = permanents.get(attachmentId);
|
MagePermanent link = permanents.get(attachmentId);
|
||||||
|
if (link != null) {
|
||||||
link.setBounds(r);
|
link.setBounds(r);
|
||||||
perm.getLinks().add(link);
|
perm.getLinks().add(link);
|
||||||
r.translate(8, 10);
|
r.translate(8, 10);
|
||||||
|
|
@ -178,18 +204,27 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
moveToFront(perm);
|
moveToFront(perm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePermanent(UUID permanentId) {
|
private void removePermanent(UUID permanentId) {
|
||||||
for (Component comp: this.getComponents()) {
|
for (Component c: this.getComponents()) {
|
||||||
|
final Component comp = c;
|
||||||
if (comp instanceof Permanent) {
|
if (comp instanceof Permanent) {
|
||||||
if (((Permanent)comp).getPermanentId().equals(permanentId)) {
|
if (((Permanent)comp).getPermanentId().equals(permanentId)) {
|
||||||
this.remove(comp);
|
this.remove(comp);
|
||||||
}
|
}
|
||||||
} else if (comp instanceof MagePermanent) {
|
} else if (comp instanceof MagePermanent) {
|
||||||
if (((MagePermanent)comp).getOriginal().getId().equals(permanentId)) {
|
if (((MagePermanent)comp).getOriginal().getId().equals(permanentId)) {
|
||||||
this.remove(comp);
|
Thread t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Plugins.getInstance().onRemoveCard((MagePermanent)comp);
|
||||||
|
BattlefieldPanel.this.remove(comp);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -241,48 +276,6 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane implements Compon
|
||||||
setOpaque(true);
|
setOpaque(true);
|
||||||
}// </editor-fold>//GEN-END:initComponents
|
}// </editor-fold>//GEN-END:initComponents
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentResized(ComponentEvent e) {
|
|
||||||
resizeBattlefield();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentMoved(ComponentEvent e) {
|
|
||||||
resizeBattlefield();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentShown(ComponentEvent e) {
|
|
||||||
resizeBattlefield();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void componentHidden(ComponentEvent e) {
|
|
||||||
resizeBattlefield();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resizeBattlefield() {
|
|
||||||
/*Dimension area = new Dimension(0, 0);
|
|
||||||
Dimension size = getPreferredSize();
|
|
||||||
|
|
||||||
for (Component comp: getComponents()) {
|
|
||||||
Rectangle r = comp.getBounds();
|
|
||||||
if (r.x + r.width > area.width) {
|
|
||||||
area.width = r.x + r.width;
|
|
||||||
}
|
|
||||||
if (r.y + r.height > area.height) {
|
|
||||||
area.height = r.y + r.height;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (size.height != area.height || size.width != area.width) {
|
|
||||||
setPreferredSize(area);
|
|
||||||
revalidate();
|
|
||||||
repaint();
|
|
||||||
}*/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
// End of variables declaration//GEN-END:variables
|
// End of variables declaration//GEN-END:variables
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,4 +32,6 @@ public interface MagePlugins {
|
||||||
int getGamesPlayed();
|
int getGamesPlayed();
|
||||||
void addGamesPlayed();
|
void addGamesPlayed();
|
||||||
Image getManaSymbolImage(String symbol);
|
Image getManaSymbolImage(String symbol);
|
||||||
|
void onAddCard(MagePermanent card);
|
||||||
|
void onRemoveCard(MagePermanent card);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,4 +167,18 @@ public class Plugins implements MagePlugins {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddCard(MagePermanent card) {
|
||||||
|
if (this.cardPlugin != null) {
|
||||||
|
this.cardPlugin.onAddCard(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoveCard(MagePermanent card) {
|
||||||
|
if (this.cardPlugin != null) {
|
||||||
|
this.cardPlugin.onRemoveCard(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ public abstract class MageCard extends JPanel {
|
||||||
abstract public void onEndAnimation();
|
abstract public void onEndAnimation();
|
||||||
abstract public boolean isTapped();
|
abstract public boolean isTapped();
|
||||||
abstract public void setAlpha(float transparency);
|
abstract public void setAlpha(float transparency);
|
||||||
|
abstract public float getAlpha();
|
||||||
abstract public CardView getOriginal();
|
abstract public CardView getOriginal();
|
||||||
abstract public void setCardBounds(int x, int y, int width, int height);
|
abstract public void setCardBounds(int x, int y, int width, int height);
|
||||||
abstract public void update(CardView card);
|
abstract public void update(CardView card);
|
||||||
|
|
|
||||||
|
|
@ -31,4 +31,6 @@ public interface CardPlugin extends Plugin {
|
||||||
void downloadImages(Set<Card> allCards);
|
void downloadImages(Set<Card> allCards);
|
||||||
void downloadSymbols();
|
void downloadSymbols();
|
||||||
Image getManaSymbolImage(String symbol);
|
Image getManaSymbolImage(String symbol);
|
||||||
|
void onAddCard(MagePermanent card);
|
||||||
|
void onRemoveCard(MagePermanent card);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -287,30 +287,30 @@ abstract public class Animation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void showCard(final CardPanel panel) {
|
static public void showCard(final MagePermanent card) {
|
||||||
new Animation(600) {
|
new Animation(600) {
|
||||||
protected void start () {
|
protected void start () {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void update (float percentage) {
|
protected void update (float percentage) {
|
||||||
float alpha = percentage;
|
float alpha = percentage;
|
||||||
panel.setAlpha(alpha);
|
card.setAlpha(alpha);
|
||||||
panel.repaint();
|
card.repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void end () {
|
protected void end () {
|
||||||
|
card.setAlpha(1.f);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static public void hideCard(final CardPanel panel, final MagePermanent card) {
|
static public void hideCard(final MagePermanent card) {
|
||||||
new Animation(600) {
|
new Animation(600) {
|
||||||
protected void start () {
|
protected void start () {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void update (float percentage) {
|
protected void update (float percentage) {
|
||||||
float alpha = 1 - percentage;
|
float alpha = 1 - percentage;
|
||||||
panel.setAlpha(alpha);
|
|
||||||
card.setAlpha(alpha);
|
card.setAlpha(alpha);
|
||||||
card.repaint();
|
card.repaint();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import net.xeoh.plugins.base.annotations.events.PluginLoaded;
|
||||||
import net.xeoh.plugins.base.annotations.meta.Author;
|
import net.xeoh.plugins.base.annotations.meta.Author;
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
import org.mage.card.arcane.Animation;
|
||||||
import org.mage.card.arcane.CardPanel;
|
import org.mage.card.arcane.CardPanel;
|
||||||
import org.mage.card.arcane.ManaSymbols;
|
import org.mage.card.arcane.ManaSymbols;
|
||||||
import org.mage.plugins.card.constants.Constants;
|
import org.mage.plugins.card.constants.Constants;
|
||||||
|
|
@ -433,4 +434,32 @@ public class CardPluginImpl implements CardPlugin {
|
||||||
public Image getManaSymbolImage(String symbol) {
|
public Image getManaSymbolImage(String symbol) {
|
||||||
return ManaSymbols.getManaSymbolImage(symbol);
|
return ManaSymbols.getManaSymbolImage(symbol);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAddCard(MagePermanent card) {
|
||||||
|
if (card != null) {
|
||||||
|
Animation.showCard((CardPanel) card);
|
||||||
|
try {
|
||||||
|
while ((card).getAlpha() + 0.05f < 1) {
|
||||||
|
Thread.sleep(30);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onRemoveCard(MagePermanent card) {
|
||||||
|
if (card != null) {
|
||||||
|
Animation.hideCard((CardPanel) card);
|
||||||
|
try {
|
||||||
|
while ((card).getAlpha() - 0.05f > 0) {
|
||||||
|
Thread.sleep(30);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue