use of mage.view.SimpleCardView in project mage by magefree.
the class UpdateDeckTask method moveSelectorCardToDeck.
private void moveSelectorCardToDeck(Event event) {
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = null;
boolean gameMode = mode != DeckEditorMode.FREE_BUILDING;
if (gameMode) {
// game: use existing real cards
for (Card sideCard : deck.getSideboard()) {
if (sideCard.getId().equals(cardView.getId())) {
card = sideCard;
break;
}
}
} else {
// editor: create mock card
CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
card = cardInfo != null ? cardInfo.getMockCard() : null;
}
if (card != null) {
deck.getCards().add(card);
if (gameMode) {
// game: move card from another board
deck.getSideboard().remove(card);
cardSelector.removeCard(card.getId());
cardSelector.setCardCount(deck.getSideboard().size());
cardSelector.refresh();
}
// card hint update
if (cardInfoPane instanceof CardInfoPane) {
((CardInfoPane) cardInfoPane).setCard(new CardView(card), null);
}
hidePopup();
}
}
use of mage.view.SimpleCardView in project mage by magefree.
the class UpdateDeckTask method init.
private void init() {
// this.cardSelector.setVisible(true);
this.panelLeft.setVisible(true);
// TOP AREA: ENABLE ADDING/REMOVING BY DOUBLE CLICKS
for (ICardGrid component : this.cardSelector.getCardGridComponents()) {
// component.clearCardEventListeners();
component.addCardEventListener((Listener<Event>) event -> {
switch(event.getEventType()) {
case CARD_DOUBLE_CLICK:
{
boolean gameMode = mode != DeckEditorMode.FREE_BUILDING;
if (gameMode) {
moveSelectorCardToDeck(event);
} else {
if (event.isMouseAltDown()) {
moveSelectorCardToSideboard(event);
} else {
moveSelectorCardToDeck(event);
}
}
break;
}
case DECK_REMOVE_SELECTION_MAIN:
{
DeckEditorPanel.this.deckArea.getDeckList().removeSelection();
break;
}
case DECK_REMOVE_SELECTION_SIDEBOARD:
{
DeckEditorPanel.this.deckArea.getSideboardList().removeSelection();
break;
}
}
refreshDeck();
});
}
// BOTTOM AREA: ENABLE ADDING/REMOVING CARDS in MAINBOARD
// do not clear event listener - DragCardGrid already have own listeners for cards
// this.deckArea.clearDeckEventListeners();
this.deckArea.addDeckEventListener((Listener<Event>) event -> {
if (mode == DeckEditorMode.FREE_BUILDING) {
switch(event.getEventType()) {
case CARD_DOUBLE_CLICK:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findCard(cardView.getId());
if (card == null) {
return;
}
if (event.isMouseAltDown()) {
deck.getCards().remove(card);
deck.getSideboard().add(card);
} else {
deck.getCards().remove(card);
}
hidePopup();
refreshDeck();
break;
}
case SET_NUMBER:
{
setCardNumberToCardsList(event, deck.getCards());
break;
}
case DECK_REMOVE_SPECIFIC_CARD:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findCard(cardView.getId());
if (card == null) {
return;
}
deck.getCards().remove(card);
storeTemporaryCard(card);
break;
}
case DECK_ADD_SPECIFIC_CARD:
{
SimpleCardView cardView = (CardView) event.getSource();
deck.getCards().add(retrieveTemporaryCard(cardView));
break;
}
}
} else {
switch(event.getEventType()) {
case CARD_DOUBLE_CLICK:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findCard(cardView.getId());
if (card == null) {
return;
}
deck.getCards().remove(card);
deck.getSideboard().add(card);
cardSelector.loadSideboard(new ArrayList<>(deck.getSideboard()), this.bigCard);
hidePopup();
refreshDeck();
break;
}
case DECK_REMOVE_SPECIFIC_CARD:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findCard(cardView.getId());
if (card == null) {
return;
}
deck.getCards().remove(card);
storeTemporaryCard(card);
break;
}
case DECK_ADD_SPECIFIC_CARD:
{
SimpleCardView cardView = (CardView) event.getSource();
deck.getCards().add(retrieveTemporaryCard(cardView));
break;
}
}
}
});
// BOTTOM AREA: ENABLE ADDING/REMOVING CARDS in SIDEBOARD
// do not clear event listener - DragCardGrid already have own listeners for cards
// this.deckArea.clearSideboardEventListeners();
this.deckArea.addSideboardEventListener(// card manipulation events
(Listener<Event>) event -> {
if (mode == DeckEditorMode.FREE_BUILDING) {
switch(event.getEventType()) {
case CARD_DOUBLE_CLICK:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findSideboardCard(cardView.getId());
if (card == null) {
return;
}
if (event.isMouseAltDown()) {
deck.getSideboard().remove(card);
deck.getCards().add(card);
} else {
deck.getSideboard().remove(card);
}
hidePopup();
refreshDeck();
break;
}
case SET_NUMBER:
{
setCardNumberToCardsList(event, deck.getSideboard());
break;
}
case DECK_REMOVE_SPECIFIC_CARD:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findSideboardCard(cardView.getId());
if (card == null) {
return;
}
deck.getSideboard().remove(card);
storeTemporaryCard(card);
break;
}
case DECK_ADD_SPECIFIC_CARD:
{
SimpleCardView cardView = (CardView) event.getSource();
deck.getSideboard().add(retrieveTemporaryCard(cardView));
break;
}
}
} else {
switch(event.getEventType()) {
case DECK_REMOVE_SPECIFIC_CARD:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findSideboardCard(cardView.getId());
if (card == null) {
return;
}
deck.getSideboard().remove(card);
storeTemporaryCard(card);
break;
}
case DECK_ADD_SPECIFIC_CARD:
{
SimpleCardView cardView = (CardView) event.getSource();
deck.getSideboard().add(retrieveTemporaryCard(cardView));
break;
}
case CARD_DOUBLE_CLICK:
{
SimpleCardView cardView = (SimpleCardView) event.getSource();
Card card = deck.findSideboardCard(cardView.getId());
if (card == null) {
return;
}
deck.getSideboard().remove(card);
deck.getCards().add(card);
hidePopup();
refreshDeck();
break;
}
}
}
});
refreshDeck(true);
// auto-import dropped files from OS
if (mode == DeckEditorMode.FREE_BUILDING) {
setDropTarget(new DropTarget(this, new DnDDeckTargetListener() {
@Override
protected boolean handleFilesDrop(boolean move, List<File> files) {
loadDeck(files.get(0).getAbsolutePath(), true);
return true;
}
@Override
protected boolean handlePlainTextDrop(boolean move, String text) {
String tmpFile = DeckUtil.writeTextToTempFile(text);
loadDeck(tmpFile, false);
return true;
}
}));
}
this.setVisible(true);
this.repaint();
}
use of mage.view.SimpleCardView in project mage by magefree.
the class UpdateDeckTask method moveSelectorCardToSideboard.
private void moveSelectorCardToSideboard(Event event) {
boolean gameMode = mode != DeckEditorMode.FREE_BUILDING;
if (gameMode) {
throw new IllegalArgumentException("ERROR, you can move card to sideboard from selector in game mode.");
}
SimpleCardView cardView = (SimpleCardView) event.getSource();
CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
Card card = cardInfo != null ? cardInfo.getMockCard() : null;
if (card != null) {
deck.getSideboard().add(card);
}
// card hint update
if (cardInfoPane instanceof CardInfoPane) {
((CardInfoPane) cardInfoPane).setCard(new CardView(card), null);
}
hidePopup();
}
use of mage.view.SimpleCardView in project mage by magefree.
the class DeckUtil method construct.
public static Deck construct(DeckView view) {
Deck deck = new Deck();
for (SimpleCardView cardView : view.getCards().values()) {
CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
Card card = cardInfo != null ? cardInfo.getMockCard() : null;
if (card != null) {
deck.getCards().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
for (SimpleCardView cardView : view.getSideboard().values()) {
CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
Card card = cardInfo != null ? cardInfo.getMockCard() : null;
if (card != null) {
deck.getSideboard().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
return deck;
}
Aggregations