use of mage.cards.MageCard in project mage by magefree.
the class CardPluginImpl method calculateNeededNumberOfVerticalColumns.
private AttachmentLayoutInfos calculateNeededNumberOfVerticalColumns(int currentCol, Map<UUID, MageCard> cards, MageCard cardWithAttachments) {
int maxCol = ++currentCol;
int attachments = 0;
MagePermanent permWithAttachments = (MagePermanent) cardWithAttachments.getMainPanel();
for (UUID attachmentId : permWithAttachments.getOriginalPermanent().getAttachments()) {
MageCard attachedCard = cards.get(attachmentId);
if (attachedCard != null) {
attachments++;
MagePermanent attachedPerm = (MagePermanent) attachedCard.getMainPanel();
if (attachedPerm.getOriginalPermanent().getAttachments() != null && !attachedPerm.getOriginalPermanent().getAttachments().isEmpty()) {
AttachmentLayoutInfos attachmentLayoutInfos = calculateNeededNumberOfVerticalColumns(currentCol, cards, attachedCard);
if (attachmentLayoutInfos.getColumns() > maxCol) {
maxCol = attachmentLayoutInfos.getColumns();
attachments += attachmentLayoutInfos.getAttachments();
}
}
}
}
return new AttachmentLayoutInfos(maxCol, attachments);
}
use of mage.cards.MageCard in project mage by magefree.
the class CardLayoutStrategyImpl method doLayout.
@Override
public void doLayout(BattlefieldPanel battlefieldPanel, int battlefieldWidth) {
Map<UUID, MageCard> cards = battlefieldPanel.getPermanentPanels();
JLayeredPane mainPanel = battlefieldPanel.getMainPanel();
// does the basic layout of rows and colums
int height = Plugins.instance.sortPermanents(battlefieldPanel.getUiComponentsList(), cards, battlefieldPanel.isTopPanelBattlefield());
mainPanel.setPreferredSize(new Dimension(battlefieldWidth - 30, height));
for (PermanentView permanent : battlefieldPanel.getBattlefield().values()) {
if (permanent.getAttachments() != null && !permanent.isAttachedTo()) {
// Layout only permanents that are not attached to other permanents itself
groupAttachments(battlefieldPanel, mainPanel, cards, permanent);
}
}
}
use of mage.cards.MageCard in project mage by magefree.
the class Animation method tapCardToggle.
public static void tapCardToggle(final CardPanel source, final boolean tapped, final boolean flipped) {
CardPanel mainPanel = source;
MageCard parentPanel = mainPanel.getTopPanelRef();
new Animation(300) {
@Override
protected void start() {
parentPanel.onBeginAnimation();
}
@Override
protected void update(float percentage) {
if (tapped) {
mainPanel.setTappedAngle(CardPanel.TAPPED_ANGLE * percentage);
// reverse movement if untapping
if (!mainPanel.isTapped()) {
mainPanel.setTappedAngle(CardPanel.TAPPED_ANGLE - mainPanel.getTappedAngle());
}
}
if (flipped) {
mainPanel.setFlippedAngle(CardPanel.FLIPPED_ANGLE * percentage);
if (!mainPanel.isFlipped()) {
mainPanel.setFlippedAngle(CardPanel.FLIPPED_ANGLE - mainPanel.getFlippedAngle());
}
}
parentPanel.repaint();
}
@Override
protected void end() {
if (tapped) {
mainPanel.setTappedAngle(mainPanel.isTapped() ? CardPanel.TAPPED_ANGLE : 0);
}
if (flipped) {
mainPanel.setFlippedAngle(mainPanel.isFlipped() ? CardPanel.FLIPPED_ANGLE : 0);
}
parentPanel.onEndAnimation();
parentPanel.repaint();
}
};
}
use of mage.cards.MageCard in project mage by magefree.
the class Animation method transformCard.
public static void transformCard(final CardPanel source) {
CardPanel mainPanel = source;
MageCard parentPanel = mainPanel.getTopPanelRef();
new Animation(600) {
private boolean state = false;
@Override
protected void start() {
parentPanel.onBeginAnimation();
}
@Override
protected void update(float percentage) {
double p = percentage * 2;
if (percentage > 0.5) {
if (!state) {
parentPanel.toggleTransformed();
}
state = true;
p = (p - 0.5) * 2;
}
if (!state) {
mainPanel.transformAngle = Math.max(0.01, 1 - p);
} else {
mainPanel.transformAngle = Math.max(0.01, p - 1);
}
parentPanel.repaint();
}
@Override
protected void end() {
if (!state) {
parentPanel.toggleTransformed();
}
state = true;
mainPanel.transformAngle = 1;
parentPanel.onEndAnimation();
parentPanel.repaint();
}
};
}
use of mage.cards.MageCard in project mage by magefree.
the class ArrowUtil method drawArrowsForSource.
public static void drawArrowsForSource(TransferData data, Point parentPoint) {
if (data.getCard().isAbility()) {
Point me = new Point(data.getLocationOnScreen());
me.translate(-parentPoint.x, -parentPoint.y);
UUID uuid = data.getCard().getParentId();
for (PlayAreaPanel pa : MageFrame.getGamePlayers(data.getGameId()).values()) {
MageCard permanent = pa.getBattlefieldPanel().getPermanentPanels().get(uuid);
if (permanent != null) {
Point source = permanent.getCardLocationOnScreen().getCardPoint();
source.translate(-parentPoint.x, -parentPoint.y);
ArrowBuilder.getBuilder().addArrow(data.getGameId(), (int) source.getX() + 40, (int) source.getY() + 10, (int) me.getX() + 35, (int) me.getY() + 20, Color.blue, ArrowBuilder.Type.SOURCE);
}
}
}
}
Aggregations