Merge pull request #5580 from magefree/5497-dynamic-hints-for-cards

UI: Add dynamic hints for cards
This commit is contained in:
Oleg Agafonov 2019-02-09 14:44:42 +04:00 committed by GitHub
commit c52a3c8a48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
215 changed files with 1840 additions and 1137 deletions

View file

@ -1,14 +1,9 @@
package mage.client.util.gui;
import java.awt.*;
import java.util.ArrayList;
import java.util.Locale;
import javax.swing.*;
import mage.client.dialog.PreferencesDialog;
import static mage.client.dialog.PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE;
import mage.client.MageFrame;
import mage.client.dialog.PreferencesDialog;
import mage.client.table.PlayersChatPanel;
import mage.client.util.GUISizeHelper;
import mage.client.table.*;
import mage.constants.*;
import mage.view.CardView;
import mage.view.CounterView;
@ -17,6 +12,13 @@ import org.jdesktop.swingx.JXPanel;
import org.mage.card.arcane.ManaSymbols;
import org.mage.card.arcane.UI;
import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;
import java.util.Locale;
import static mage.client.dialog.PreferencesDialog.KEY_MAGE_PANEL_LAST_SIZE;
public final class GuiDisplayUtil {
private static final Font cardNameFont = new Font("Calibri", Font.BOLD, 15);
@ -30,32 +32,32 @@ public final class GuiDisplayUtil {
}
public static void restoreDividerLocations(Rectangle bounds, String lastDividerLocation, JComponent component) {
String currentBounds = Double.toString(bounds.getWidth()) + 'x' + Double.toString(bounds.getHeight());
String savedBounds = PreferencesDialog.getCachedValue(KEY_MAGE_PANEL_LAST_SIZE, null);
// use divider positions only if screen size is the same as it was the time the settings were saved
if (savedBounds != null && savedBounds.equals(currentBounds)) {
if (lastDividerLocation != null && component != null) {
if (component instanceof JSplitPane) {
JSplitPane jSplitPane = (JSplitPane) component;
jSplitPane.setDividerLocation(Integer.parseInt(lastDividerLocation));
}
String currentBounds = Double.toString(bounds.getWidth()) + 'x' + bounds.getHeight();
String savedBounds = PreferencesDialog.getCachedValue(KEY_MAGE_PANEL_LAST_SIZE, null);
// use divider positions only if screen size is the same as it was the time the settings were saved
if (savedBounds != null && savedBounds.equals(currentBounds)) {
if (lastDividerLocation != null && component != null) {
if (component instanceof JSplitPane) {
JSplitPane jSplitPane = (JSplitPane) component;
jSplitPane.setDividerLocation(Integer.parseInt(lastDividerLocation));
}
if (component instanceof PlayersChatPanel) {
PlayersChatPanel playerChatPanel = (PlayersChatPanel) component;
playerChatPanel.setSplitDividerLocation(Integer.parseInt(lastDividerLocation));
}
if (component instanceof PlayersChatPanel) {
PlayersChatPanel playerChatPanel = (PlayersChatPanel) component;
playerChatPanel.setSplitDividerLocation(Integer.parseInt(lastDividerLocation));
}
}
}
}
}
public static void saveCurrentBoundsToPrefs() {
Rectangle rec = MageFrame.getDesktop().getBounds();
String currentBounds = Double.toString(rec.getWidth()) + 'x' + Double.toString(rec.getHeight());
PreferencesDialog.saveValue(KEY_MAGE_PANEL_LAST_SIZE, currentBounds);
Rectangle rec = MageFrame.getDesktop().getBounds();
String currentBounds = Double.toString(rec.getWidth()) + 'x' + rec.getHeight();
PreferencesDialog.saveValue(KEY_MAGE_PANEL_LAST_SIZE, currentBounds);
}
public static void saveDividerLocationToPrefs(String dividerPrefKey, int position) {
PreferencesDialog.saveValue(dividerPrefKey, Integer.toString(position));
PreferencesDialog.saveValue(dividerPrefKey, Integer.toString(position));
}
public static JXPanel getDescription(CardView card, int width, int height) {
@ -204,6 +206,10 @@ public final class GuiDisplayUtil {
return textLines;
}
public static String getHintIconHtml(String iconName, int symbolSize) {
return "<img src='" + getResourcePath("hint/" + iconName + ".png") + "' alt='" + iconName + "' width=" + symbolSize + " height=" + symbolSize + ">";
}
public static StringBuilder getRulefromCardView(CardView card, TextLines textLines) {
String manaCost = "";
for (String m : card.getManaCost()) {
@ -236,7 +242,7 @@ public final class GuiDisplayUtil {
buffer.append("<tr><td valign='top'><b>");
buffer.append(card.getDisplayName());
if (card.isGameObject()) {
buffer.append(" [").append(card.getId().toString().substring(0, 3)).append(']');
buffer.append(" [").append(card.getId().toString(), 0, 3).append(']');
}
buffer.append("</b></td><td align='right' valign='top' style='width:");
buffer.append(symbolCount * GUISizeHelper.cardTooltipFontSize);

View file

@ -5,6 +5,7 @@
*/
package org.mage.card.arcane;
import mage.abilities.hint.HintUtils;
import mage.cards.ArtRect;
import mage.client.dialog.PreferencesDialog;
import mage.constants.AbilityType;
@ -137,12 +138,18 @@ public abstract class CardRenderer {
}
protected void parseRules(List<String> stringRules, ArrayList<TextboxRule> keywords, ArrayList<TextboxRule> rules) {
// Translate the textbox text
// Translate the textbox text and remove card hints
for (String rule : stringRules) {
// remove all card hints
if (rule.equals(HintUtils.HINT_START_MARK)) {
break;
}
// Kill reminder text
if (PreferencesDialog.getCachedValue(PreferencesDialog.KEY_CARD_RENDERING_REMINDER_TEXT, "false").equals("false")) {
rule = CardRendererUtils.killReminderText(rule).trim();
}
if (!rule.isEmpty()) {
TextboxRule tbRule = TextboxRuleParser.parse(cardView, rule);
if (tbRule.type == TextboxRuleType.SIMPLE_KEYWORD) {

View file

@ -1,43 +1,6 @@
package org.mage.card.arcane;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import javax.imageio.ImageIO;
import javax.swing.*;
import mage.abilities.hint.HintUtils;
import mage.cards.repository.ExpansionRepository;
import mage.client.MageFrame;
import mage.client.constants.Constants;
@ -46,6 +9,7 @@ import mage.client.constants.Constants.ResourceSymbolSize;
import mage.client.util.GUISizeHelper;
import mage.client.util.ImageHelper;
import mage.client.util.gui.BufferedImageBuilder;
import mage.client.util.gui.GuiDisplayUtil;
import mage.utils.StreamUtils;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.transcoder.TranscoderException;
@ -57,6 +21,26 @@ import org.apache.batik.util.SVGConstants;
import org.apache.log4j.Logger;
import org.mage.plugins.card.utils.CardImageUtils;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.List;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.regex.Pattern;
import java.util.stream.IntStream;
import static org.mage.plugins.card.utils.CardImageUtils.getImagesDir;
public final class ManaSymbols {
@ -786,7 +770,18 @@ public final class ManaSymbols {
"<img src='" + filePathToUrl(htmlImagesPath) + "$1$2" + ".png' alt='$1$2' width="
+ symbolSize + " height=" + symbolSize + '>');
// ignore data restore
// replace hint icons
if (replaced.contains(HintUtils.HINT_ICON_GOOD)) {
replaced = replaced.replace(HintUtils.HINT_ICON_GOOD, GuiDisplayUtil.getHintIconHtml("good", symbolSize) + "&nbsp;");
}
if (replaced.contains(HintUtils.HINT_ICON_BAD)) {
replaced = replaced.replace(HintUtils.HINT_ICON_BAD, GuiDisplayUtil.getHintIconHtml("bad", symbolSize) + "&nbsp;");
}
if (replaced.contains(HintUtils.HINT_ICON_RESTRICT)) {
replaced = replaced.replace(HintUtils.HINT_ICON_RESTRICT, GuiDisplayUtil.getHintIconHtml("restrict", symbolSize) + "&nbsp;");
}
// ignored data restore
replaced = replaced
.replace("|source|", "{source}")
.replace("|this|", "{this}")

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.5 KiB