Search in sources :

Example 36 with CardView

use of mage.view.CardView 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();
}
Also used : DropTarget(java.awt.dnd.DropTarget) java.util(java.util) MageFrame(mage.client.MageFrame) DeckEditorMode(mage.client.constants.Constants.DeckEditorMode) DeckGenerator(mage.client.deck.generator.DeckGenerator) AudioManager(mage.client.util.audio.AudioManager) mage.cards.decks(mage.cards.decks) SimpleCardView(mage.view.SimpleCardView) Border(javax.swing.border.Border) Logger(org.apache.log4j.Logger) CardInfoPane(mage.components.CardInfoPane) Card(mage.cards.Card) SessionHandler(mage.client.SessionHandler) ICardGrid(mage.client.cards.ICardGrid) Session(mage.remote.Session) java.util.concurrent(java.util.concurrent) DeckImporter(mage.cards.decks.importer.DeckImporter) AddLandDialog(mage.client.dialog.AddLandDialog) IOException(java.io.IOException) CardRepository(mage.cards.repository.CardRepository) FileFilter(javax.swing.filechooser.FileFilter) File(java.io.File) java.awt(java.awt) PreferencesDialog(mage.client.dialog.PreferencesDialog) Plugins(mage.client.plugins.impl.Plugins) List(java.util.List) BigCard(mage.client.cards.BigCard) DeckGeneratorException(mage.client.deck.generator.DeckGenerator.DeckGeneratorException) Event(mage.client.util.Event) Listener(mage.client.util.Listener) CardInfo(mage.cards.repository.CardInfo) DeckUtil(mage.util.DeckUtil) java.awt.event(java.awt.event) LegalityLabel(mage.client.components.LegalityLabel) CardView(mage.view.CardView) XMAGE_INFO(mage.cards.decks.DeckFormats.XMAGE_INFO) GameException(mage.game.GameException) XMAGE(mage.cards.decks.DeckFormats.XMAGE) javax.swing(javax.swing) ICardGrid(mage.client.cards.ICardGrid) SimpleCardView(mage.view.SimpleCardView) SimpleCardView(mage.view.SimpleCardView) CardView(mage.view.CardView) Event(mage.client.util.Event) List(java.util.List) DropTarget(java.awt.dnd.DropTarget) Card(mage.cards.Card) BigCard(mage.client.cards.BigCard)

Example 37 with CardView

use of mage.view.CardView in project mage by magefree.

the class UpdateDeckTask method setCardNumberToCardsList.

private void setCardNumberToCardsList(Event event, Set<Card> cards) {
    CardView cardView = (CardView) event.getSource();
    int numberToSet = event.getNumber();
    int cardsFound = 0;
    java.util.List<Card> toDelete = new ArrayList<>();
    for (Card card : cards) {
        if (card.getName().equals(cardView.getName()) && Objects.equals(card.getCardNumber(), cardView.getCardNumber()) && card.getExpansionSetCode().equals(cardView.getExpansionSetCode())) {
            cardsFound++;
            if (cardsFound > numberToSet) {
                toDelete.add(card);
            }
        }
    }
    if (toDelete.isEmpty()) {
        // add cards
        CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
        for (int i = cardsFound; i < numberToSet; i++) {
            cards.add(cardInfo.getMockCard());
        }
    } else {
        // remove cards
        for (Card card : toDelete) {
            cards.remove(card);
        }
    }
    hidePopup();
    refreshDeck();
}
Also used : java.util(java.util) SimpleCardView(mage.view.SimpleCardView) CardView(mage.view.CardView) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card) BigCard(mage.client.cards.BigCard)

Example 38 with CardView

use of mage.view.CardView 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();
}
Also used : SimpleCardView(mage.view.SimpleCardView) SimpleCardView(mage.view.SimpleCardView) CardView(mage.view.CardView) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card) BigCard(mage.client.cards.BigCard) CardInfoPane(mage.components.CardInfoPane)

Example 39 with CardView

use of mage.view.CardView in project mage by magefree.

the class ChoiceDialog method displayCards.

private void displayCards(CardsView cards, UUID gameId, BigCard bigCard) {
    if (cards.isEmpty()) {
        return;
    }
    java.util.List<Component> toRemove = new ArrayList<>();
    for (int i = getComponentCount() - 1; i > 0; i--) {
        Component o = getComponent(i);
        if (o instanceof MageCard) {
            toRemove.add(o);
        }
    }
    for (Component aToRemove : toRemove) {
        remove(aToRemove);
    }
    java.util.List<CardView> cardList = new ArrayList<>(cards.values());
    int width = SettingsManager.instance.getCardSize().width;
    int height = SettingsManager.instance.getCardSize().height;
    int dx = 0;
    int dy = 30;
    int startIndex = (page - 1) * (in_a_row * rows);
    int countPerPage = (in_a_row * rows);
    int j = 0;
    for (int i = startIndex; i < cards.size() && i < startIndex + countPerPage; i++) {
        if (i > startIndex && i % in_a_row == 0) {
            // next row
            j++;
            dx = 0;
        }
        CardView card = cardList.get(i);
        MageCard cardImg = Plugins.instance.getMageCard(card, bigCard, new CardIconRenderSettings(), getCardDimension(), gameId, true, true, PreferencesDialog.getRenderMode(), true);
        cardImg.setCardContainerRef(this);
        cardImg.update(card);
        cardImg.setCardBounds(dx, dy + j * (height + 30), width, height);
        this.add(cardImg);
        dx += (width + 20);
    }
    repaint();
}
Also used : ArrayList(java.util.ArrayList) CardView(mage.view.CardView) MageCard(mage.cards.MageCard) CardIconRenderSettings(mage.abilities.icon.CardIconRenderSettings)

Example 40 with CardView

use of mage.view.CardView in project mage by magefree.

the class CardInfoWindowDialog method qtyCardTypes.

private int qtyCardTypes(mage.view.CardsView cardsView) {
    Set<String> cardTypesPresent = new LinkedHashSet<String>() {
    };
    for (CardView card : cardsView.values()) {
        Set<CardType> cardTypes = EnumSet.noneOf(CardType.class);
        cardTypes.addAll(card.getCardTypes());
        for (CardType cardType : cardTypes) {
            cardTypesPresent.add(cardType.toString());
        }
    }
    if (cardTypesPresent.isEmpty()) {
        return 0;
    } else {
        return cardTypesPresent.size();
    }
}
Also used : CardType(mage.constants.CardType) CardView(mage.view.CardView)

Aggregations

CardView (mage.view.CardView)41 List (java.util.List)15 MageCard (mage.cards.MageCard)10 CardInfo (mage.cards.repository.CardInfo)9 Card (mage.cards.Card)6 DeckCardInfo (mage.cards.decks.DeckCardInfo)5 java.util (java.util)4 BigCard (mage.client.cards.BigCard)4 CardIconRenderSettings (mage.abilities.icon.CardIconRenderSettings)3 GameView (mage.view.GameView)3 PlayerView (mage.view.PlayerView)3 SimpleCardView (mage.view.SimpleCardView)3 Test (org.junit.Test)3 java.awt (java.awt)2 java.awt.event (java.awt.event)2 ArrayList (java.util.ArrayList)2 Entry (java.util.Map.Entry)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 javax.swing (javax.swing)2