mirror of
https://github.com/correl/mage.git
synced 2024-11-29 03:00:12 +00:00
* Adventure cards - improved game logs (card hint works with adventure spell now, added original card info to cast's log);
This commit is contained in:
parent
713110eb03
commit
862fe69b53
9 changed files with 141 additions and 62 deletions
|
@ -1,31 +1,27 @@
|
||||||
package mage.client.components;
|
package mage.client.components;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Color;
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Graphics;
|
|
||||||
import java.awt.MouseInfo;
|
|
||||||
import java.awt.Point;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
import javax.swing.JEditorPane;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JTextPane;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.event.HyperlinkEvent.EventType;
|
|
||||||
import javax.swing.text.html.HTMLDocument;
|
|
||||||
import javax.swing.text.html.HTMLEditorKit;
|
|
||||||
|
|
||||||
import mage.cards.repository.CardInfo;
|
import mage.cards.repository.CardInfo;
|
||||||
import mage.cards.repository.CardRepository;
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.dialog.PreferencesDialog;
|
import mage.client.dialog.PreferencesDialog;
|
||||||
import mage.client.util.gui.GuiDisplayUtil;
|
import mage.client.util.gui.GuiDisplayUtil;
|
||||||
import mage.components.CardInfoPane;
|
import mage.components.CardInfoPane;
|
||||||
|
import mage.util.CardUtil;
|
||||||
import mage.utils.ThreadUtils;
|
import mage.utils.ThreadUtils;
|
||||||
import mage.view.CardView;
|
import mage.view.CardView;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.HyperlinkEvent.EventType;
|
||||||
|
import javax.swing.text.SimpleAttributeSet;
|
||||||
|
import javax.swing.text.html.HTMLDocument;
|
||||||
|
import javax.swing.text.html.HTMLEditorKit;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enhanced {@link JTextPane} with text highlighting support.
|
* Enhanced {@link JTextPane} with text highlighting support.
|
||||||
*
|
*
|
||||||
|
@ -50,8 +46,37 @@ public class ColorPane extends JEditorPane {
|
||||||
if (tooltipDelay == 0) {
|
if (tooltipDelay == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String name = e.getDescription().substring(1);
|
|
||||||
CardInfo card = CardRepository.instance.findCard(name);
|
// finds extra data in html element like object_id, alternative_name, etc
|
||||||
|
Map<String, String> extraData = new HashMap<>();
|
||||||
|
if (e.getSourceElement() instanceof HTMLDocument.RunElement) {
|
||||||
|
HTMLDocument.RunElement el = (HTMLDocument.RunElement) e.getSourceElement();
|
||||||
|
Enumeration attNames = el.getAttributeNames();
|
||||||
|
while (attNames.hasMoreElements()) {
|
||||||
|
Object attName = attNames.nextElement();
|
||||||
|
Object attValue = el.getAttribute(attName);
|
||||||
|
// custom attributes in SimpleAttributeSet element
|
||||||
|
if (attValue instanceof SimpleAttributeSet) {
|
||||||
|
SimpleAttributeSet attReal = (SimpleAttributeSet) attValue;
|
||||||
|
Enumeration attRealNames = attReal.getAttributeNames();
|
||||||
|
while (attRealNames.hasMoreElements()) {
|
||||||
|
Object attRealName = attRealNames.nextElement();
|
||||||
|
Object attRealValue = attReal.getAttribute(attRealName);
|
||||||
|
String name = attRealName.toString();
|
||||||
|
String value = attRealValue.toString();
|
||||||
|
extraData.put(name, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String cardName = e.getDescription().substring(1);
|
||||||
|
String alternativeName = CardUtil.urlDecode(extraData.getOrDefault("alternative_name", ""));
|
||||||
|
if (!alternativeName.isEmpty()) {
|
||||||
|
cardName = alternativeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
CardInfo card = CardRepository.instance.findCard(cardName);
|
||||||
try {
|
try {
|
||||||
final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
final Component container = MageFrame.getUI().getComponent(MageComponents.POPUP_CONTAINER);
|
||||||
if (e.getEventType() == EventType.EXITED) {
|
if (e.getEventType() == EventType.EXITED) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.mage.plugins.card.dl.sources;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.remote.Connection;
|
import mage.remote.Connection;
|
||||||
import mage.remote.Connection.ProxyType;
|
import mage.remote.Connection.ProxyType;
|
||||||
|
import mage.util.CardUtil;
|
||||||
import org.jsoup.Jsoup;
|
import org.jsoup.Jsoup;
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
@ -13,7 +14,10 @@ import org.mage.plugins.card.images.CardDownloadData;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.*;
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.Proxy;
|
||||||
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.prefs.Preferences;
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
|
@ -298,7 +302,7 @@ public enum MythicspoilerComSource implements CardImageSource {
|
||||||
Preferences prefs = MageFrame.getPreferences();
|
Preferences prefs = MageFrame.getPreferences();
|
||||||
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
Connection.ProxyType proxyType = Connection.ProxyType.valueByText(prefs.get("proxyType", "None"));
|
||||||
for (String setName : setNames.split("\\^")) {
|
for (String setName : setNames.split("\\^")) {
|
||||||
String URLSetName = URLEncoder.encode(setName, "UTF-8");
|
String URLSetName = CardUtil.urlEncode(setName);
|
||||||
String baseUrl = "http://mythicspoiler.com/" + URLSetName + '/';
|
String baseUrl = "http://mythicspoiler.com/" + URLSetName + '/';
|
||||||
|
|
||||||
Map<String, String> pageLinks = getSetLinksFromPage(cardSet, aliasesStart, prefs, proxyType, baseUrl, baseUrl);
|
Map<String, String> pageLinks = getSetLinksFromPage(cardSet, aliasesStart, prefs, proxyType, baseUrl, baseUrl);
|
||||||
|
|
|
@ -7,17 +7,16 @@ import com.google.gson.JsonParser;
|
||||||
import mage.cards.ExpansionSet;
|
import mage.cards.ExpansionSet;
|
||||||
import mage.cards.Sets;
|
import mage.cards.Sets;
|
||||||
import mage.client.util.CardLanguage;
|
import mage.client.util.CardLanguage;
|
||||||
|
import mage.util.CardUtil;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.mage.plugins.card.dl.DownloadServiceInfo;
|
import org.mage.plugins.card.dl.DownloadServiceInfo;
|
||||||
import org.mage.plugins.card.images.CardDownloadData;
|
import org.mage.plugins.card.images.CardDownloadData;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.Proxy;
|
import java.net.Proxy;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLConnection;
|
import java.net.URLConnection;
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,12 +95,7 @@ public enum ScryfallImageSource implements CardImageSource {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
scryfallCollectorId = CardUtil.urlEncode(scryfallCollectorId);
|
||||||
scryfallCollectorId = URLEncoder.encode(scryfallCollectorId, "utf-8");
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// URL failed to encode, this will cause download to miss in certain environments
|
|
||||||
}
|
|
||||||
|
|
||||||
baseUrl = "https://api.scryfall.com/cards/" + formatSetName(card.getSet(), isToken) + "/"
|
baseUrl = "https://api.scryfall.com/cards/" + formatSetName(card.getSet(), isToken) + "/"
|
||||||
+ scryfallCollectorId + "/" + localizedCode + "?format=image";
|
+ scryfallCollectorId + "/" + localizedCode + "?format=image";
|
||||||
alternativeUrl = "https://api.scryfall.com/cards/" + formatSetName(card.getSet(), isToken) + "/"
|
alternativeUrl = "https://api.scryfall.com/cards/" + formatSetName(card.getSet(), isToken) + "/"
|
||||||
|
@ -227,7 +221,7 @@ public enum ScryfallImageSource implements CardImageSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String searchCard(Proxy proxy, String set, String name) throws Exception {
|
private String searchCard(Proxy proxy, String set, String name) throws Exception {
|
||||||
final URL searchUrl = new URL("https://api.scryfall.com/cards/search?q=s:" + URLEncoder.encode(set + " " + name, "UTF-8"));
|
final URL searchUrl = new URL("https://api.scryfall.com/cards/search?q=s:" + CardUtil.urlEncode(set + " " + name));
|
||||||
URLConnection request = proxy == null ? searchUrl.openConnection() : searchUrl.openConnection(proxy);
|
URLConnection request = proxy == null ? searchUrl.openConnection() : searchUrl.openConnection(proxy);
|
||||||
request.connect();
|
request.connect();
|
||||||
|
|
||||||
|
|
|
@ -522,7 +522,6 @@ public enum WizardCardsImageSource implements CardImageSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String setName : setNames.split("\\^")) {
|
for (String setName : setNames.split("\\^")) {
|
||||||
// String URLSetName = URLEncoder.encode(setName, "UTF-8");
|
|
||||||
String URLSetName = setName.replaceAll(" ", "%20");
|
String URLSetName = setName.replaceAll(" ", "%20");
|
||||||
int page = 0;
|
int page = 0;
|
||||||
int firstMultiverseIdLastPage = 0;
|
int firstMultiverseIdLastPage = 0;
|
||||||
|
|
|
@ -99,6 +99,12 @@ public class AdventureCardSpellImpl extends CardImpl implements AdventureCardSpe
|
||||||
public AdventureCard getParentCard() {
|
public AdventureCard getParentCard() {
|
||||||
return this.adventureCardParent;
|
return this.adventureCardParent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdName() {
|
||||||
|
// id must send to main card (popup card hint in game logs)
|
||||||
|
return getName() + " [" + adventureCardParent.getId().toString().substring(0, 3) + ']';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class AdventureCardSpellAbility extends SpellAbility {
|
class AdventureCardSpellAbility extends SpellAbility {
|
||||||
|
|
|
@ -15,10 +15,7 @@ import mage.abilities.costs.mana.ManaCosts;
|
||||||
import mage.abilities.keyword.BestowAbility;
|
import mage.abilities.keyword.BestowAbility;
|
||||||
import mage.abilities.keyword.MorphAbility;
|
import mage.abilities.keyword.MorphAbility;
|
||||||
import mage.abilities.text.TextPart;
|
import mage.abilities.text.TextPart;
|
||||||
import mage.cards.Card;
|
import mage.cards.*;
|
||||||
import mage.cards.CardsImpl;
|
|
||||||
import mage.cards.FrameStyle;
|
|
||||||
import mage.cards.SplitCard;
|
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
import mage.counters.Counter;
|
import mage.counters.Counter;
|
||||||
import mage.counters.Counters;
|
import mage.counters.Counters;
|
||||||
|
@ -168,6 +165,13 @@ public class Spell extends StackObjImpl implements Card {
|
||||||
return "a card face down";
|
return "a card face down";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (card instanceof AdventureCardSpell) {
|
||||||
|
AdventureCard adventureCard = ((AdventureCardSpell) card).getParentCard();
|
||||||
|
return GameLog.replaceNameByColoredName(card, getSpellAbility().toString(), adventureCard)
|
||||||
|
+ " as Adventure spell of " + GameLog.getColoredObjectIdName(adventureCard);
|
||||||
|
}
|
||||||
|
|
||||||
return GameLog.replaceNameByColoredName(card, getSpellAbility().toString());
|
return GameLog.replaceNameByColoredName(card, getSpellAbility().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -421,7 +425,11 @@ public class Spell extends StackObjImpl implements Card {
|
||||||
public String getIdName() {
|
public String getIdName() {
|
||||||
String idName;
|
String idName;
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
|
if (card instanceof AdventureCardSpell) {
|
||||||
|
idName = ((AdventureCardSpell) card).getParentCard().getId().toString().substring(0, 3);
|
||||||
|
} else {
|
||||||
idName = card.getId().toString().substring(0, 3);
|
idName = card.getId().toString().substring(0, 3);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
idName = getId().toString().substring(0, 3);
|
idName = getId().toString().substring(0, 3);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,5 @@
|
||||||
package mage.util;
|
package mage.util;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
@ -17,6 +14,13 @@ import mage.game.permanent.Permanent;
|
||||||
import mage.game.permanent.token.Token;
|
import mage.game.permanent.token.Token;
|
||||||
import mage.util.functions.CopyTokenFunction;
|
import mage.util.functions.CopyTokenFunction;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author nantuko
|
* @author nantuko
|
||||||
*/
|
*/
|
||||||
|
@ -577,4 +581,28 @@ public final class CardUtil {
|
||||||
Card card = game.getCard(objectId);
|
Card card = game.getCard(objectId);
|
||||||
return card != null ? card.getMainCard().getId() : objectId;
|
return card != null ? card.getMainCard().getId() : objectId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String urlEncode(String data) {
|
||||||
|
if (data.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return URLEncoder.encode(data, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String urlDecode(String encodedData) {
|
||||||
|
if (encodedData.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return URLDecoder.decode(encodedData, "UTF-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
|
|
||||||
package mage.util;
|
package mage.util;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.jar.JarEntry;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.jar.JarInputStream;
|
import java.util.jar.JarInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author North
|
* @author North
|
||||||
*/
|
*/
|
||||||
public final class ClassScanner {
|
public final class ClassScanner {
|
||||||
|
@ -56,7 +53,7 @@ public final class ClassScanner {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String filePath : jars) {
|
for (String filePath : jars) {
|
||||||
File file = new File(URLDecoder.decode(filePath, "UTF-8"));
|
File file = new File(CardUtil.urlDecode(filePath));
|
||||||
cards.addAll(findClassesInJar(classLoader, file, packages, type));
|
cards.addAll(findClassesInJar(classLoader, file, packages, type));
|
||||||
}
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
|
|
|
@ -33,32 +33,50 @@ public final class GameLog {
|
||||||
return text.replaceAll(mageObject.getName(), getColoredObjectIdName(mageObject));
|
return text.replaceAll(mageObject.getName(), getColoredObjectIdName(mageObject));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param mageObject - original object name to replace
|
||||||
|
* @param text - original text to insert object's html name
|
||||||
|
* @param alternativeObject - alternative object (object to show in card's hint in GUI)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String replaceNameByColoredName(MageObject mageObject, String text, MageObject alternativeObject) {
|
||||||
|
return text.replaceAll(mageObject.getName(), getColoredObjectIdName(mageObject, alternativeObject));
|
||||||
|
}
|
||||||
|
|
||||||
public static String getColoredObjectName(MageObject mageObject) {
|
public static String getColoredObjectName(MageObject mageObject) {
|
||||||
return "<font color=\'" + getColorName(mageObject.getColor(null)) + "\'>" + mageObject.getName() + "</font>";
|
return "<font color='" + getColorName(mageObject.getColor(null)) + "'>" + mageObject.getName() + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getColoredObjectIdName(MageObject mageObject) {
|
public static String getColoredObjectIdName(MageObject mageObject) {
|
||||||
return "<font color=\'" + getColorName(mageObject.getColor(null)) + "\'>" + mageObject.getIdName() + "</font>";
|
return getColoredObjectIdName(mageObject, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getColoredObjectIdName(MageObject mageObject, MageObject alternativeObject) {
|
||||||
|
return "<font"
|
||||||
|
+ " color='" + getColorName(mageObject.getColor(null)) + "'"
|
||||||
|
+ " object_id='" + mageObject.getId() + "'"
|
||||||
|
+ (alternativeObject == null ? "" : " alternative_name='" + CardUtil.urlEncode(alternativeObject.getName()) + "'")
|
||||||
|
+ ">" + mageObject.getIdName() + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getColoredObjectIdNameForTooltip(MageObject mageObject) {
|
public static String getColoredObjectIdNameForTooltip(MageObject mageObject) {
|
||||||
return "<font color=\'" + getTooltipColorName(mageObject.getColor(null)) + "\'>" + mageObject.getIdName() + "</font>";
|
return "<font color='" + getTooltipColorName(mageObject.getColor(null)) + "'>" + mageObject.getIdName() + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getNeutralColoredText(String text) {
|
public static String getNeutralColoredText(String text) {
|
||||||
return "<font color=\'" + LOG_COLOR_NEUTRAL + "\'>" + text + "</font>";
|
return "<font color='" + LOG_COLOR_NEUTRAL + "'>" + text + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getColoredPlayerName(String name) {
|
public static String getColoredPlayerName(String name) {
|
||||||
return "<font color=\'" + LOG_COLOR_PLAYER + "\'>" + name + "</font>";
|
return "<font color='" + LOG_COLOR_PLAYER + "'>" + name + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPlayerRequestColoredText(String name) {
|
public static String getPlayerRequestColoredText(String name) {
|
||||||
return "<font color=\'" + LOG_COLOR_PLAYER_REQUEST + "\'>" + name + "</font>";
|
return "<font color='" + LOG_COLOR_PLAYER_REQUEST + "'>" + name + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getPlayerConfirmColoredText(String name) {
|
public static String getPlayerConfirmColoredText(String name) {
|
||||||
return "<font color=\'" + LOG_COLOR_PLAYER_CONFIRM + "\'>" + name + "</font>";
|
return "<font color='" + LOG_COLOR_PLAYER_CONFIRM + "'>" + name + "</font>";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSmallSecondLineText(String text) {
|
public static String getSmallSecondLineText(String text) {
|
||||||
|
|
Loading…
Reference in a new issue