mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
check for new card images when client starts
This commit is contained in:
parent
0ce1b4b918
commit
f9cb39ea7e
6 changed files with 51 additions and 1 deletions
|
|
@ -286,6 +286,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
disableButtons();
|
||||
checkForNewImages();
|
||||
if (autoConnect())
|
||||
enableButtons();
|
||||
else {
|
||||
|
|
@ -424,6 +425,17 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
menu.show(component, 0, component.getHeight());
|
||||
}
|
||||
|
||||
private void checkForNewImages() {
|
||||
HashSet<Card> cards = new HashSet<Card>(CardsStorage.getAllCards());
|
||||
List<Card> notImplemented = CardsStorage.getNotImplementedCards();
|
||||
cards.addAll(notImplemented);
|
||||
if (Plugins.getInstance().newImage(cards)) {
|
||||
if (JOptionPane.showConfirmDialog(null, "New cards are available. Do you want to download the images?") == JOptionPane.OK_OPTION) {
|
||||
Plugins.getInstance().downloadImage(cards);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void btnImagesActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
HashSet<Card> cards = new HashSet<Card>(CardsStorage.getAllCards());
|
||||
List<Card> notImplemented = CardsStorage.getNotImplementedCards();
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public interface MagePlugins {
|
|||
boolean isCardPluginLoaded();
|
||||
boolean isCounterPluginLoaded();
|
||||
void sortPermanents(Map<String, JComponent> ui, Collection<MagePermanent> permanents);
|
||||
boolean newImage(Set<Card> allCards);
|
||||
void downloadImage(Set<Card> allCards);
|
||||
void downloadSymbols();
|
||||
int getGamesPlayed();
|
||||
|
|
|
|||
|
|
@ -110,6 +110,13 @@ public class Plugins implements MagePlugins {
|
|||
if (this.cardPlugin != null) this.cardPlugin.sortPermanents(ui, permanents, sortingOptions);
|
||||
}
|
||||
|
||||
@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");
|
||||
|
|
|
|||
|
|
@ -420,6 +420,11 @@ public class CardPluginImpl implements CardPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean newImages(Set<Card> allCards, String imagesPath) {
|
||||
return DownloadPictures.checkForNewCards(allCards, imagesPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Download images.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -232,7 +232,24 @@ public class DownloadPictures extends DefaultBoundedRangeModel implements Runnab
|
|||
Object[] options = { startDownloadButton, closeButton = new JButton("Cancel") };
|
||||
dlg = new JOptionPane(p0, JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]);
|
||||
}
|
||||
|
||||
|
||||
public static boolean checkForNewCards(Set<Card> allCards, String imagesPath) {
|
||||
File file;
|
||||
for (Card card : allCards) {
|
||||
if (card.getCardNumber() > 0 && !card.getExpansionSetCode().isEmpty()) {
|
||||
CardInfo url = new CardInfo(card.getName(), card.getExpansionSetCode(), card.getCardNumber(), false);
|
||||
boolean withCollectorId = false;
|
||||
if (card.getName().equals("Forest") || card.getName().equals("Mountain") || card.getName().equals("Swamp") || card.getName().equals("Island") || card.getName().equals("Plains")) {
|
||||
withCollectorId = true;
|
||||
}
|
||||
file = new File(CardImageUtils.getImagePath(url, withCollectorId, imagesPath));
|
||||
if (!file.exists())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static ArrayList<CardInfo> getNeededCards(Set<Card> allCards, String imagesPath) {
|
||||
|
||||
ArrayList<CardInfo> cardsToDownload = new ArrayList<CardInfo>();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue