Search in sources :

Example 61 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class CollectionPanelGUI method initPopupCollection.

public void initPopupCollection() throws SQLException {
    popupMenuEdition = new JPopupMenu();
    popupMenuCards = new JPopupMenu();
    JMenu menuItemAdd = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("ADD_MISSING_CARDS_IN"));
    JMenu menuItemMove = new JMenu(MTGControler.getInstance().getLangService().getCapitalize("MOVE_CARD_TO"));
    for (MagicCollection mc : dao.getCollections()) {
        JMenuItem adds = new JMenuItem(mc.getName());
        JMenuItem movs = new JMenuItem(mc.getName());
        movs.addActionListener(e -> {
            DefaultMutableTreeNode nodeCol = ((DefaultMutableTreeNode) path.getPathComponent(1));
            DefaultMutableTreeNode nodeCd = ((DefaultMutableTreeNode) path.getPathComponent(3));
            MagicCard card = (MagicCard) nodeCd.getUserObject();
            MagicCollection oldCol = (MagicCollection) nodeCol.getUserObject();
            final String collec = ((JMenuItem) e.getSource()).getText();
            MagicCollection nmagicCol = new MagicCollection();
            nmagicCol.setName(collec);
            try {
                dao.removeCard(card, oldCol);
                dao.saveCard(card, nmagicCol);
                nodeCd.removeFromParent();
                nodeCol.add(new DefaultMutableTreeNode(card));
                tree.refresh();
            } catch (SQLException e1) {
                logger.error(e1);
            }
        });
        adds.addActionListener(e -> {
            final String destinationCollection = ((JMenuItem) e.getSource()).getText();
            ThreadManager.getInstance().execute(() -> {
                try {
                    DefaultMutableTreeNode node = ((DefaultMutableTreeNode) path.getPathComponent(2));
                    MagicEdition me = (MagicEdition) node.getUserObject();
                    MagicCollection col = new MagicCollection();
                    col.setName(destinationCollection);
                    List<MagicCard> sets = provider.searchCardByCriteria("set", me.getId(), null, false);
                    MagicCollection sourceCol = new MagicCollection();
                    sourceCol.setName(node.getPath()[1].toString());
                    List<MagicCard> list = dao.listCardsFromCollection(sourceCol, me);
                    sets.removeAll(list);
                    for (MagicCard m : sets) dao.saveCard(m, col);
                    tree.refresh();
                } catch (Exception e1) {
                    MTGLogger.printStackTrace(e1);
                }
            }, "btnAdds addCardsCollection");
        });
        menuItemAdd.add(adds);
        menuItemMove.add(movs);
    }
    JMenuItem menuItemOpen = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("OPEN"));
    menuItemOpen.addActionListener(e -> {
        MagicCollection col = (MagicCollection) ((DefaultMutableTreeNode) path.getPathComponent(1)).getUserObject();
        MagicEdition edition = (MagicEdition) ((DefaultMutableTreeNode) path.getPathComponent(2)).getUserObject();
        try {
            CardSearchPanel.getInstance().open(MTGControler.getInstance().getEnabledDAO().listCardsFromCollection(col, edition));
        } catch (SQLException e1) {
            logger.error(e1);
        }
    });
    popupMenuEdition.add(menuItemOpen);
    JMenuItem it = new JMenuItem(MTGControler.getInstance().getLangService().getCapitalize("MASS_MOVEMENTS"));
    it.addActionListener(e -> {
        MagicCollection col = (MagicCollection) ((DefaultMutableTreeNode) path.getPathComponent(1)).getUserObject();
        MagicEdition edition = (MagicEdition) ((DefaultMutableTreeNode) path.getPathComponent(2)).getUserObject();
        MassMoverDialog d = new MassMoverDialog(col, edition);
        d.setVisible(true);
        logger.debug("closing mass import with change =" + d.hasChange());
    });
    popupMenuEdition.add(it);
    popupMenuEdition.add(menuItemAdd);
    popupMenuCards.add(menuItemMove);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) MagicCard(org.magic.api.beans.MagicCard) SQLException(java.sql.SQLException) MagicEdition(org.magic.api.beans.MagicEdition) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu) JMenu(javax.swing.JMenu) MagicCollection(org.magic.api.beans.MagicCollection) SQLException(java.sql.SQLException) IOException(java.io.IOException) MassMoverDialog(org.magic.gui.components.dialog.MassMoverDialog)

Example 62 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class MeldActions method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DisplayableCard card2;
    try {
        card2 = GamePanelGUI.getInstance().getPanelBattleField().lookupCardBy("name", meldWith).get(0);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(null, "Could not meld the card, " + meldWith + " is not on the battlefield");
        return;
    }
    GamePanelGUI.getInstance().getPlayer().logAction("Meld " + card.getMagicCard() + " and " + meldWith + " to " + card.getMagicCard().getRotatedCardName());
    card.removeAllCounters();
    GamePanelGUI.getInstance().getPlayer().exileCardFromBattleField(card.getMagicCard());
    GamePanelGUI.getInstance().getPanelBattleField().remove(card);
    card2.removeAllCounters();
    GamePanelGUI.getInstance().getPlayer().exileCardFromBattleField(card2.getMagicCard());
    GamePanelGUI.getInstance().getPanelBattleField().remove(card2);
    MagicCard mc;
    try {
        mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", card.getMagicCard().getRotatedCardName(), card.getMagicCard().getEditions().get(0), true).get(0);
        Dimension d = new Dimension((int) (MTGControler.getInstance().getCardsDimension().getWidth() * 1.5), (int) (MTGControler.getInstance().getCardsDimension().getHeight() * 1.5));
        DisplayableCard c = new DisplayableCard(mc, d, true);
        c.initActions();
        GamePanelGUI.getInstance().getPanelBattleField().addComponent(c);
    } catch (Exception e1) {
        logger.error(e1);
    }
    GamePanelGUI.getInstance().getPanelBattleField().revalidate();
    GamePanelGUI.getInstance().getPanelBattleField().repaint();
}
Also used : MagicCard(org.magic.api.beans.MagicCard) DisplayableCard(org.magic.game.gui.components.DisplayableCard) Dimension(java.awt.Dimension)

Example 63 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class MorphActions method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (!card.isRotated()) {
        MagicCard mc = new MagicCard();
        mc.setName("Morphed Creature");
        mc.setPower("2");
        mc.setToughness("2");
        mc.getTypes().add("Creature");
        mc.setCost("{3}");
        mc.setEditions(card.getMagicCard().getEditions());
        mc.setRotatedCardName(card.getMagicCard().getName());
        MagicRuling r = new MagicRuling();
        r.setText(MTGControler.getInstance().getKeyWordManager().generateFromString(k).getDescription());
        mc.getRulings().add(r);
        mc.setText(k + " " + cost);
        mc.setLayout(card.getMagicCard().getLayout());
        mc.setId(card.getMagicCard().getId());
        card.setMagicCard(mc);
        card.setRotated(true);
        card.showPT(true);
        card.initActions();
        try {
            card.setImage(new ImageIcon(MTGControler.getInstance().getEnabledPicturesProvider().getBackPicture().getScaledInstance(card.getWidth(), card.getHeight(), BufferedImage.SCALE_SMOOTH)));
        } catch (Exception e1) {
            logger.error(e1);
        }
    } else {
        try {
            MagicCard mc = MTGControler.getInstance().getEnabledProviders().searchCardByCriteria("name", card.getMagicCard().getRotatedCardName(), card.getMagicCard().getEditions().get(0), true).get(0);
            card.setMagicCard(mc);
            card.setRotated(false);
            card.removeAllCounters();
            card.showPT(false);
            card.initActions();
        } catch (Exception e1) {
            logger.error(e1);
        }
    }
    card.revalidate();
    card.repaint();
}
Also used : ImageIcon(javax.swing.ImageIcon) MagicCard(org.magic.api.beans.MagicCard) MagicRuling(org.magic.api.beans.MagicRuling)

Example 64 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class CreateActions method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    try {
        MagicCard tok = GamePanelGUI.getInstance().getTokenGenerator().generateTokenFor(card.getMagicCard());
        DisplayableCard dc = new DisplayableCard(tok, MTGControler.getInstance().getCardsDimension(), true);
        dc.setMagicCard(tok);
        GamePanelGUI.getInstance().getPanelBattleField().addComponent(dc);
        GamePanelGUI.getInstance().getPanelBattleField().revalidate();
        GamePanelGUI.getInstance().getPanelBattleField().repaint();
        GamePanelGUI.getInstance().getPlayer().playToken(tok);
    } catch (Exception ex) {
        logger.error(ex);
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) DisplayableCard(org.magic.game.gui.components.DisplayableCard)

Example 65 with MagicCard

use of org.magic.api.beans.MagicCard in project MtgDesktopCompanion by nicho92.

the class EmbalmActions method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    try {
        MagicCard tok = GamePanelGUI.getInstance().getTokenGenerator().generateTokenFor(card.getMagicCard());
        DisplayableCard dc = new DisplayableCard(tok, MTGControler.getInstance().getCardsDimension(), true);
        dc.addCounter(new ItemCounter("Embalm", Color.YELLOW));
        dc.setMagicCard(tok);
        GamePanelGUI.getInstance().getPlayer().exileCardFromGraveyard(card.getMagicCard());
        GamePanelGUI.getInstance().getPanelGrave().remove(card);
        GamePanelGUI.getInstance().getPanelBattleField().addComponent(dc);
        GamePanelGUI.getInstance().getPanelBattleField().revalidate();
        GamePanelGUI.getInstance().getPanelBattleField().repaint();
        GamePanelGUI.getInstance().getPanelGrave().postTreatment(card);
        GamePanelGUI.getInstance().getPlayer().playToken(tok);
        GamePanelGUI.getInstance().getPlayer().logAction("Embalm " + card);
    } catch (Exception ex) {
        logger.error(ex);
    }
}
Also used : MagicCard(org.magic.api.beans.MagicCard) DisplayableCard(org.magic.game.gui.components.DisplayableCard) ItemCounter(org.magic.game.model.counters.ItemCounter)

Aggregations

MagicCard (org.magic.api.beans.MagicCard)106 MagicEdition (org.magic.api.beans.MagicEdition)40 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)28 MagicDeck (org.magic.api.beans.MagicDeck)21 MagicCollection (org.magic.api.beans.MagicCollection)14 SQLException (java.sql.SQLException)12 Date (java.util.Date)11 MagicCardStock (org.magic.api.beans.MagicCardStock)10 DisplayableCard (org.magic.game.gui.components.DisplayableCard)10 JsonArray (com.google.gson.JsonArray)8 List (java.util.List)8 FileReader (java.io.FileReader)7 Before (org.junit.Before)7 BufferedReader (java.io.BufferedReader)6 File (java.io.File)6 FileWriter (java.io.FileWriter)6 MalformedURLException (java.net.MalformedURLException)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6