mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Refactor: improved language support in card images sources;
This commit is contained in:
parent
bd644c273f
commit
70012af6db
6 changed files with 125 additions and 35 deletions
|
@ -236,7 +236,7 @@
|
|||
<Property name="toolTipText" type="java.lang.String" value="Write the card's name on the card to make the card name more recognizable."/>
|
||||
<Property name="actionCommand" type="java.lang.String" value=""/>
|
||||
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
|
||||
<Color id="Standardcursor"/>
|
||||
<Color id="Default Cursor"/>
|
||||
</Property>
|
||||
</Properties>
|
||||
<Events>
|
||||
|
@ -267,7 +267,7 @@
|
|||
<Property name="selected" type="boolean" value="true"/>
|
||||
<Property name="toolTipText" type="java.lang.String" value="Show the path Xmage is expecting for this card's image (only displays if missing)"/>
|
||||
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
|
||||
<Color id="Standardcursor"/>
|
||||
<Color id="Default Cursor"/>
|
||||
</Property>
|
||||
<Property name="label" type="java.lang.String" value="Display image path for missing images"/>
|
||||
</Properties>
|
||||
|
@ -4425,6 +4425,7 @@
|
|||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="cbPreferedImageLanguage">
|
||||
<Properties>
|
||||
<Property name="maximumRowCount" type="int" value="20"/>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="4">
|
||||
<StringItem index="0" value="Item 1"/>
|
||||
|
@ -4451,6 +4452,7 @@
|
|||
</Component>
|
||||
<Component class="javax.swing.JComboBox" name="cbNumberOfDownloadThreads">
|
||||
<Properties>
|
||||
<Property name="maximumRowCount" type="int" value="20"/>
|
||||
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
|
||||
<StringArray count="4">
|
||||
<StringItem index="0" value="Item 1"/>
|
||||
|
|
|
@ -41,6 +41,8 @@ import mage.client.MageFrame;
|
|||
import mage.client.SessionHandler;
|
||||
import mage.client.components.KeyBindButton;
|
||||
import static mage.client.constants.Constants.BATTLEFIELD_FEEDBACK_COLORIZING_MODE_ENABLE_BY_MULTICOLOR;
|
||||
|
||||
import mage.client.util.CardLanguage;
|
||||
import mage.client.util.Config;
|
||||
import mage.client.util.GUISizeHelper;
|
||||
import mage.client.util.ImageHelper;
|
||||
|
@ -338,6 +340,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
fc_i.addChoosableFileFilter(new ImageFileFilter());
|
||||
}
|
||||
|
||||
public static CardLanguage getPrefImagesLanguage() {
|
||||
return CardLanguage.valueByCode(getCachedValue(PreferencesDialog.KEY_CARD_IMAGES_PREF_LANGUAGE, CardLanguage.ENGLISH.getCode()));
|
||||
}
|
||||
|
||||
private static class ImageFileFilter extends FileFilter {
|
||||
|
||||
@Override
|
||||
|
@ -374,7 +380,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
cbProxyType.setModel(new DefaultComboBoxModel<>(Connection.ProxyType.values()));
|
||||
addAvatars();
|
||||
|
||||
cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(new String[]{"en", "de", "fr", "it", "es", "pt", "jp", "cn", "ru", "tw", "ko"}));
|
||||
cbPreferedImageLanguage.setModel(new DefaultComboBoxModel<>(CardLanguage.toList()));
|
||||
cbNumberOfDownloadThreads.setModel(new DefaultComboBoxModel<>(new String[]{"10", "9", "8", "7", "6", "5", "4", "3", "2", "1"}));
|
||||
}
|
||||
|
||||
|
@ -1558,6 +1564,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
}
|
||||
});
|
||||
|
||||
cbPreferedImageLanguage.setMaximumRowCount(20);
|
||||
cbPreferedImageLanguage.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
|
||||
|
||||
labelPreferedImageLanguage.setText("Prefered image language:");
|
||||
|
@ -1565,6 +1572,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
|
||||
labelNumberOfDownloadThreads.setText("Number of download threads:");
|
||||
|
||||
cbNumberOfDownloadThreads.setMaximumRowCount(20);
|
||||
cbNumberOfDownloadThreads.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
|
||||
|
||||
org.jdesktop.layout.GroupLayout panelCardImagesLayout = new org.jdesktop.layout.GroupLayout(panelCardImages);
|
||||
|
@ -3411,7 +3419,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
load(prefs, dialog.cbCheckForNewImages, KEY_CARD_IMAGES_CHECK, "true");
|
||||
load(prefs, dialog.cbSaveToZipFiles, KEY_CARD_IMAGES_SAVE_TO_ZIP, "true");
|
||||
dialog.cbNumberOfDownloadThreads.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_THREADS, "10"));
|
||||
dialog.cbPreferedImageLanguage.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_PREF_LANGUAGE, "en"));
|
||||
dialog.cbPreferedImageLanguage.setSelectedItem(MageFrame.getPreferences().get(KEY_CARD_IMAGES_PREF_LANGUAGE, CardLanguage.ENGLISH.getCode()));
|
||||
|
||||
// rendering settings
|
||||
load(prefs, dialog.cbCardRenderImageFallback, KEY_CARD_RENDERING_FALLBACK, "true");
|
||||
|
|
68
Mage.Client/src/main/java/mage/client/util/CardLanguage.java
Normal file
68
Mage.Client/src/main/java/mage/client/util/CardLanguage.java
Normal file
|
@ -0,0 +1,68 @@
|
|||
package mage.client.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author JayDi85
|
||||
*/
|
||||
public enum CardLanguage {
|
||||
|
||||
ENGLISH("en", "English"),
|
||||
SPANISH("es", "Spanish"),
|
||||
FRENCH("fr", "French"),
|
||||
GERMAN("de", "German"),
|
||||
ITALIAN("it", "Italian"),
|
||||
PORTUGUESE("pt", "Portuguese"),
|
||||
JAPANESE("jp", "Japanese"),
|
||||
KOREAN("ko", "Korean"),
|
||||
RUSSIAN("ru", "Russian"),
|
||||
CHINES_SIMPLE("cns", "Chinese Simplified"),
|
||||
CHINES_TRADITION("cnt", "Chinese Traditional");
|
||||
|
||||
private final String code;
|
||||
private final String text;
|
||||
|
||||
CardLanguage(String code, String text) {
|
||||
this.code = code;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static String[] toList() {
|
||||
ArrayList<String> res = new ArrayList<>();
|
||||
for (CardLanguage l : values()) {
|
||||
res.add(l.toString());
|
||||
}
|
||||
return res.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public static CardLanguage valueByText(String text) {
|
||||
for (CardLanguage type : values()) {
|
||||
if (type.text.equals(text)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return CardLanguage.ENGLISH;
|
||||
}
|
||||
|
||||
public static CardLanguage valueByCode(String code) {
|
||||
for (CardLanguage type : values()) {
|
||||
if (type.code.equals(code)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return CardLanguage.ENGLISH;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
package org.mage.plugins.card.dl.sources;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import mage.client.util.CardLanguage;
|
||||
import org.mage.plugins.card.images.CardDownloadData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public interface CardImageSource {
|
||||
|
@ -31,10 +32,21 @@ public interface CardImageSource {
|
|||
return false;
|
||||
}
|
||||
|
||||
default boolean isLanguagesSupport() {
|
||||
return false;
|
||||
}
|
||||
|
||||
default void setCurrentLanguage(CardLanguage cardLanguage) {
|
||||
}
|
||||
|
||||
default CardLanguage getCurrentLanguage() {
|
||||
return CardLanguage.ENGLISH;
|
||||
}
|
||||
|
||||
void doPause(String httpImageUrl);
|
||||
|
||||
default ArrayList<String> getSupportedSets() {
|
||||
return null;
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
default boolean isSetSupportedComplete(String setCode) {
|
||||
|
|
|
@ -13,23 +13,23 @@ public enum ScryfallImageSource implements CardImageSource {
|
|||
instance;
|
||||
|
||||
private final Set<String> supportedSets;
|
||||
private final Map<String, String> languageAliases;
|
||||
private final Map<CardLanguage, String> languageAliases;
|
||||
private CardLanguage currentLanguage = CardLanguage.ENGLISH; // working language
|
||||
|
||||
ScryfallImageSource() {
|
||||
// https://scryfall.com/docs/api/languages
|
||||
languageAliases = new HashMap<>();
|
||||
languageAliases.put(CardLanguage.ENGLISH.getCode(), "en");
|
||||
languageAliases.put(CardLanguage.SPANISH.getCode(), "es");
|
||||
languageAliases.put(CardLanguage.FRENCH.getCode(), "fr");
|
||||
languageAliases.put(CardLanguage.GERMAN.getCode(), "de");
|
||||
languageAliases.put(CardLanguage.ITALIAN.getCode(), "it");
|
||||
languageAliases.put(CardLanguage.PORTUGUESE.getCode(), "pt");
|
||||
languageAliases.put(CardLanguage.JAPANESE.getCode(), "ja");
|
||||
languageAliases.put(CardLanguage.KOREAN.getCode(), "ko");
|
||||
languageAliases.put(CardLanguage.RUSSIAN.getCode(), "ru");
|
||||
languageAliases.put(CardLanguage.CHINES_SIMPLE.getCode(), "zhs");
|
||||
languageAliases.put(CardLanguage.CHINES_TRADITION.getCode(), "zht");
|
||||
languageAliases.put(CardLanguage.ENGLISH, "en");
|
||||
languageAliases.put(CardLanguage.SPANISH, "es");
|
||||
languageAliases.put(CardLanguage.FRENCH, "fr");
|
||||
languageAliases.put(CardLanguage.GERMAN, "de");
|
||||
languageAliases.put(CardLanguage.ITALIAN, "it");
|
||||
languageAliases.put(CardLanguage.PORTUGUESE, "pt");
|
||||
languageAliases.put(CardLanguage.JAPANESE, "ja");
|
||||
languageAliases.put(CardLanguage.KOREAN, "ko");
|
||||
languageAliases.put(CardLanguage.RUSSIAN, "ru");
|
||||
languageAliases.put(CardLanguage.CHINES_SIMPLE, "zhs");
|
||||
languageAliases.put(CardLanguage.CHINES_TRADITION, "zht");
|
||||
|
||||
supportedSets = new LinkedHashSet<>();
|
||||
// supportedSets.add("PTC"); //
|
||||
|
@ -249,7 +249,7 @@ public enum ScryfallImageSource implements CardImageSource {
|
|||
|
||||
String preferredCode = this.getCurrentLanguage().getCode();
|
||||
String defaultCode = CardLanguage.ENGLISH.getCode();
|
||||
String localizedCode = languageAliases.getOrDefault(preferredCode, defaultCode);
|
||||
String localizedCode = languageAliases.getOrDefault(this.getCurrentLanguage(), defaultCode);
|
||||
// loc example: https://api.scryfall.com/cards/xln/121/ru?format=image
|
||||
|
||||
// WARNING, some cards haven't direct images and uses random GUID:
|
||||
|
|
|
@ -28,7 +28,7 @@ public enum WizardCardsImageSource implements CardImageSource {
|
|||
private static final Logger logger = Logger.getLogger(WizardCardsImageSource.class);
|
||||
|
||||
private final Map<String, String> setsAliases;
|
||||
private final Map<String, String> languageAliases;
|
||||
private final Map<CardLanguage, String> languageAliases;
|
||||
private final Map<String, Map<String, String>> sets;
|
||||
private final Set<String> supportedSets;
|
||||
private CardLanguage currentLanguage = CardLanguage.ENGLISH; // working language
|
||||
|
@ -41,17 +41,17 @@ public enum WizardCardsImageSource implements CardImageSource {
|
|||
WizardCardsImageSource() {
|
||||
|
||||
languageAliases = new HashMap<>();
|
||||
languageAliases.put(CardLanguage.ENGLISH.getCode(), "English");
|
||||
languageAliases.put(CardLanguage.SPANISH.getCode(), "Spanish");
|
||||
languageAliases.put(CardLanguage.FRENCH.getCode(), "French");
|
||||
languageAliases.put(CardLanguage.GERMAN.getCode(), "German");
|
||||
languageAliases.put(CardLanguage.ITALIAN.getCode(), "Italian");
|
||||
languageAliases.put(CardLanguage.PORTUGUESE.getCode(), "Portuguese (Brazil)");
|
||||
languageAliases.put(CardLanguage.JAPANESE.getCode(), "Japanese");
|
||||
languageAliases.put(CardLanguage.KOREAN.getCode(), "Korean");
|
||||
languageAliases.put(CardLanguage.RUSSIAN.getCode(), "Russian");
|
||||
languageAliases.put(CardLanguage.CHINES_SIMPLE.getCode(), "Chinese Simplified");
|
||||
languageAliases.put(CardLanguage.CHINES_TRADITION.getCode(), "Chinese Traditional ");
|
||||
languageAliases.put(CardLanguage.ENGLISH, "English");
|
||||
languageAliases.put(CardLanguage.SPANISH, "Spanish");
|
||||
languageAliases.put(CardLanguage.FRENCH, "French");
|
||||
languageAliases.put(CardLanguage.GERMAN, "German");
|
||||
languageAliases.put(CardLanguage.ITALIAN, "Italian");
|
||||
languageAliases.put(CardLanguage.PORTUGUESE, "Portuguese (Brazil)");
|
||||
languageAliases.put(CardLanguage.JAPANESE, "Japanese");
|
||||
languageAliases.put(CardLanguage.KOREAN, "Korean");
|
||||
languageAliases.put(CardLanguage.RUSSIAN, "Russian");
|
||||
languageAliases.put(CardLanguage.CHINES_SIMPLE, "Chinese Simplified");
|
||||
languageAliases.put(CardLanguage.CHINES_TRADITION, "Chinese Traditional ");
|
||||
|
||||
supportedSets = new LinkedHashSet<>();
|
||||
// supportedSets.add("PTC"); // Prerelease Events
|
||||
|
@ -552,7 +552,7 @@ public enum WizardCardsImageSource implements CardImageSource {
|
|||
cardName = cardName.substring(0, pos1);
|
||||
}
|
||||
}
|
||||
Integer preferredMultiverseId = getLocalizedMultiverseId(getCurrentLanguage().getCode(), multiverseId);
|
||||
Integer preferredMultiverseId = getLocalizedMultiverseId(getCurrentLanguage(), multiverseId);
|
||||
setLinks.put(cardName.toLowerCase(Locale.ENGLISH) + numberChar, generateLink(preferredMultiverseId));
|
||||
}
|
||||
}
|
||||
|
@ -614,8 +614,8 @@ public enum WizardCardsImageSource implements CardImageSource {
|
|||
return "/Handlers/Image.ashx?multiverseid=" + landMultiverseId + "&type=card";
|
||||
}
|
||||
|
||||
private int getLocalizedMultiverseId(String preferredLanguage, Integer multiverseId) throws IOException {
|
||||
if (preferredLanguage.equals(CardLanguage.ENGLISH.getCode())) {
|
||||
private int getLocalizedMultiverseId(CardLanguage preferredLanguage, Integer multiverseId) throws IOException {
|
||||
if (preferredLanguage.equals(CardLanguage.ENGLISH)) {
|
||||
return multiverseId;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue