Fix so canceled spells return to same place in your hand as they were cast from

This commit is contained in:
drdev
2013-12-10 02:50:24 +00:00
parent d0b5e78f7a
commit afeb4eb815
2 changed files with 46 additions and 23 deletions

View File

@@ -87,7 +87,6 @@ public class CHand implements ICDoc {
return; return;
} }
final Rectangle rctLibraryLabel = vf.getDetailsPanel().getLblLibrary().getBounds(); final Rectangle rctLibraryLabel = vf.getDetailsPanel().getLblLibrary().getBounds();
final List<Card> cc = player.getZone(ZoneType.Hand).getCards();
// Animation starts from the library label and runs to the hand panel. // Animation starts from the library label and runs to the hand panel.
// This check prevents animation running if label hasn't been realized yet. // This check prevents animation running if label hasn't been realized yet.
@@ -95,24 +94,24 @@ public class CHand implements ICDoc {
return; return;
} }
List<Card> tmp, diff; //update card panels in hand area
tmp = new ArrayList<Card>(); final List<Card> cards = player.getZone(ZoneType.Hand).getCards();
for (final forge.view.arcane.CardPanel cpa : p.getCardPanels()) { final List<CardPanel> placeholders = new ArrayList<CardPanel>();
tmp.add(cpa.getGameCard()); final List<CardPanel> cardPanels = new ArrayList<CardPanel>();
}
diff = new ArrayList<Card>(tmp); for (Card card : cards) {
diff.removeAll(cc); CardPanel cardPanel = p.getCardPanel(card.getUniqueNumber());
if (diff.size() == p.getCardPanels().size()) { if (cardPanel == null) { //create placeholders for new cards
p.clear(); cardPanel = new CardPanel(card);
} cardPanel.setDisplayEnabled(false);
else { placeholders.add(cardPanel);
for (final Card card : diff) {
p.removeCardPanel(p.getCardPanel(card.getUniqueNumber()));
} }
cardPanels.add(cardPanel);
} }
diff = new ArrayList<Card>(cc);
diff.removeAll(tmp);
p.setCardPanels(cardPanels);
//animate new cards into positions defined by placeholders
JLayeredPane layeredPane = Singletons.getView().getFrame().getLayeredPane(); JLayeredPane layeredPane = Singletons.getView().getFrame().getLayeredPane();
int fromZoneX = 0, fromZoneY = 0; int fromZoneX = 0, fromZoneY = 0;
@@ -127,20 +126,19 @@ public class CHand implements ICDoc {
int endWidth, endX, endY; int endWidth, endX, endY;
for (final Card card : diff) { for (final CardPanel placeholder : placeholders) {
CardPanel toPanel = p.addCard(card); endWidth = placeholder.getCardWidth();
endWidth = toPanel.getCardWidth(); final Point toPos = SwingUtilities.convertPoint(view.getHandArea(), placeholder.getCardLocation(), layeredPane);
final Point toPos = SwingUtilities.convertPoint(view.getHandArea(), toPanel.getCardLocation(), layeredPane);
endX = toPos.x; endX = toPos.x;
endY = toPos.y; endY = toPos.y;
final forge.view.arcane.CardPanel animationPanel = new forge.view.arcane.CardPanel(card); final CardPanel animationPanel = new CardPanel(placeholder.getGameCard());
if (Singletons.getView().getFrame().isShowing()) { if (Singletons.getView().getFrame().isShowing()) {
Animation.moveCard(startX, startY, startWidth, endX, endY, endWidth, animationPanel, toPanel, Animation.moveCard(startX, startY, startWidth, endX, endY, endWidth, animationPanel, placeholder,
layeredPane, 500); layeredPane, 500);
} }
else { else {
Animation.moveCard(toPanel); Animation.moveCard(placeholder);
} }
} }
} }

View File

@@ -346,6 +346,31 @@ public abstract class CardPanelContainer extends JPanel {
CardPanelContainer.this.repaint(); CardPanelContainer.this.repaint();
} }
/**
* <p>
* setCardPanels.
* </p>
*
* @param cardPanels
*/
public final void setCardPanels(List<CardPanel> cardPanels) {
if (cardPanels.size() == 0) {
clear();
return;
}
this.getCardPanels().clear();
this.removeAll();
this.getCardPanels().addAll(cardPanels);
for (CardPanel cardPanel : cardPanels) {
this.add(cardPanel);
}
this.doLayout();
this.invalidate();
this.getParent().validate();
this.repaint();
}
/** /**
* <p> * <p>
* clear. * clear.