mirror of
https://github.com/correl/mage.git
synced 2025-04-08 17:00:07 -09:00
Replaced CardStorage references from MageFrame with CardRepository
This commit is contained in:
parent
4a4ed72324
commit
56a11f4da2
6 changed files with 46 additions and 75 deletions
Mage.Client/src/main/java
mage/client
org/mage/plugins/card
Mage.Common/src/mage/interfaces/plugin
|
@ -39,8 +39,10 @@ import de.schlichtherle.truezip.file.TConfig;
|
|||
import de.schlichtherle.truezip.fs.FsOutputOption;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.cards.repository.CardInfo;
|
||||
import mage.cards.repository.CardRepository;
|
||||
import mage.cards.repository.CardScanner;
|
||||
import mage.client.cards.BigCard;
|
||||
import mage.client.cards.CardsStorage;
|
||||
import mage.client.chat.ChatPanel;
|
||||
import mage.client.components.*;
|
||||
import mage.client.components.ext.dlg.DialogManager;
|
||||
|
@ -74,6 +76,7 @@ import mage.server.Main;
|
|||
import mage.utils.MageVersion;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.mage.card.arcane.ManaSymbols;
|
||||
import org.mage.plugins.card.images.DownloadPictures;
|
||||
import org.mage.plugins.card.utils.impl.ImageManagerImpl;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
@ -81,19 +84,27 @@ import javax.swing.*;
|
|||
import javax.swing.JToolBar.Separator;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
import java.awt.*;
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Color;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.SplashScreen;
|
||||
import java.awt.event.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.beans.PropertyVetoException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.prefs.Preferences;
|
||||
import mage.cards.repository.CardScanner;
|
||||
|
||||
/**
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -469,22 +480,36 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
menu.show(component, 0, component.getHeight());
|
||||
}
|
||||
|
||||
private List<Card> getAllCards() {
|
||||
List<Card> cards = new ArrayList<Card>();
|
||||
List<CardInfo> allCards = CardRepository.instance.getAllCards();
|
||||
for (CardInfo cardInfo : allCards) {
|
||||
cards.add(cardInfo.getCard());
|
||||
}
|
||||
|
||||
return cards;
|
||||
}
|
||||
|
||||
private void checkForNewImages() {
|
||||
HashSet<Card> cards = new HashSet<Card>(CardsStorage.getAllCards());
|
||||
List<Card> notImplemented = CardsStorage.getNotImplementedCards();
|
||||
cards.addAll(notImplemented);
|
||||
if (Plugins.getInstance().newImage(cards)) {
|
||||
List<Card> cards = getAllCards();
|
||||
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String path = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
if (DownloadPictures.checkForNewCards(cards, path)) {
|
||||
if (JOptionPane.showConfirmDialog(null, "New cards are available. Do you want to download the images?", "New images available", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
|
||||
Plugins.getInstance().downloadImage(cards);
|
||||
DownloadPictures.startDownload(null, cards, path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void btnImagesActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
HashSet<Card> cards = new HashSet<Card>(CardsStorage.getAllCards());
|
||||
List<Card> notImplemented = CardsStorage.getNotImplementedCards();
|
||||
cards.addAll(notImplemented);
|
||||
Plugins.getInstance().downloadImage(cards);
|
||||
List<Card> cards = getAllCards();
|
||||
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String path = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
|
||||
DownloadPictures.startDownload(null, cards, path);
|
||||
}
|
||||
|
||||
public void btnSymbolsActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
|
@ -1149,4 +1174,4 @@ class MagePaneMenuItem extends JCheckBoxMenuItem {
|
|||
public MagePane getFrame() {
|
||||
return frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package mage.client.plugins;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.MageCard;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.action.ActionCallback;
|
||||
|
@ -13,7 +12,6 @@ import java.awt.*;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface MagePlugins {
|
||||
|
@ -27,8 +25,6 @@ public interface MagePlugins {
|
|||
boolean isCardPluginLoaded();
|
||||
boolean isCounterPluginLoaded();
|
||||
int sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent> permanents);
|
||||
boolean newImage(Set<Card> allCards);
|
||||
void downloadImage(Set<Card> allCards);
|
||||
void downloadSymbols();
|
||||
int getGamesPlayed();
|
||||
void addGamesPlayed();
|
||||
|
|
|
@ -119,22 +119,6 @@ public class Plugins implements MagePlugins {
|
|||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean newImage(Set<mage.cards.Card> allCards) {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String path = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
return this.cardPlugin.newImages(allCards, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadImage(Set<mage.cards.Card> allCards) {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
String path = useDefault.equals("true") ? null : PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PATH, null);
|
||||
if (this.cardPlugin != null) {
|
||||
this.cardPlugin.downloadImages(allCards, path);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadSymbols() {
|
||||
String useDefault = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_USE_DEFAULT, "true");
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.mage.plugins.card;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.interfaces.plugin.CardPlugin;
|
||||
|
@ -21,7 +20,6 @@ import org.mage.plugins.card.dl.DownloadJob;
|
|||
import org.mage.plugins.card.dl.Downloader;
|
||||
import org.mage.plugins.card.dl.sources.GathererSets;
|
||||
import org.mage.plugins.card.dl.sources.GathererSymbols;
|
||||
import org.mage.plugins.card.images.DownloadPictures;
|
||||
import org.mage.plugins.card.images.ImageCache;
|
||||
import org.mage.plugins.card.info.CardInfoPaneImpl;
|
||||
|
||||
|
@ -421,22 +419,6 @@ public class CardPluginImpl implements CardPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean newImages(Set<Card> allCards, String imagesPath) {
|
||||
return DownloadPictures.checkForNewCards(allCards, imagesPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download images.
|
||||
*
|
||||
* @param allCards Set of cards to download images for.
|
||||
* @param imagesPath Path to check in and store images to. Can be null, in such case default path should be used.
|
||||
*/
|
||||
@Override
|
||||
public void downloadImages(Set<Card> allCards, String imagesPath) {
|
||||
DownloadPictures.startDownload(null, allCards, imagesPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download various symbols (mana, tap, set).
|
||||
*
|
||||
|
|
|
@ -21,7 +21,9 @@ import javax.imageio.ImageWriteParam;
|
|||
import javax.imageio.ImageWriter;
|
||||
import javax.imageio.stream.FileImageOutputStream;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.image.BufferedImage;
|
||||
|
@ -32,7 +34,7 @@ import java.net.URL;
|
|||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.regex.Pattern;
|
||||
|
@ -67,7 +69,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
startDownload(null, null, null);
|
||||
}
|
||||
|
||||
public static void startDownload(JFrame frame, Set<Card> allCards, String imagesPath) {
|
||||
public static void startDownload(JFrame frame, List<Card> allCards, String imagesPath) {
|
||||
ArrayList<CardInfo> cards = getNeededCards(allCards, imagesPath);
|
||||
|
||||
/*
|
||||
|
@ -207,7 +209,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
dlg = new JOptionPane(p0, JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
|
||||
}
|
||||
|
||||
public static boolean checkForNewCards(Set<Card> allCards, String imagesPath) {
|
||||
public static boolean checkForNewCards(List<Card> allCards, String imagesPath) {
|
||||
TFile file;
|
||||
for (Card card : allCards) {
|
||||
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
|
||||
|
@ -221,7 +223,7 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
return false;
|
||||
}
|
||||
|
||||
private static ArrayList<CardInfo> getNeededCards(Set<Card> allCards, String imagesPath) {
|
||||
private static ArrayList<CardInfo> getNeededCards(List<Card> allCards, String imagesPath) {
|
||||
|
||||
ArrayList<CardInfo> cardsToDownload = new ArrayList<CardInfo>();
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package mage.interfaces.plugin;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.MagePermanent;
|
||||
import mage.cards.action.ActionCallback;
|
||||
import mage.view.CardView;
|
||||
|
@ -12,7 +11,6 @@ import java.awt.*;
|
|||
import java.awt.image.BufferedImage;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -29,22 +27,6 @@ public interface CardPlugin extends Plugin {
|
|||
MagePermanent getMageCard(CardView permanent, Dimension dimension, UUID gameId, ActionCallback callback, boolean canBeFoil, boolean loadImage);
|
||||
int sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent> cards, Map<String, String> options);
|
||||
|
||||
/**
|
||||
* Check for new images.
|
||||
*
|
||||
* @param allCards Set of cards to check images for.
|
||||
* @param imagesPath Path to check in. Can be null, in such case default path should be used.
|
||||
*/
|
||||
public boolean newImages(Set<Card> allCards, String imagesPath);
|
||||
|
||||
/**
|
||||
* Download images.
|
||||
*
|
||||
* @param allCards Set of cards to download images for.
|
||||
* @param imagesPath Path to check in and store images to. Can be null, in such case default path should be used.
|
||||
*/
|
||||
void downloadImages(Set<Card> allCards, String imagesPath);
|
||||
|
||||
/**
|
||||
* Download various symbols (mana, tap, set).
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue