* Allow to addd hint texts to stack abilities. Swicthed to html text format for text box of stack abilites.

This commit is contained in:
LevelX2 2020-07-02 00:53:46 +02:00
parent f409f56c05
commit 84370ee5ab
11 changed files with 64 additions and 46 deletions

View file

@ -6,7 +6,7 @@
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="new Dimension(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT)" type="code"/> <Connection code="new Dimension(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT)" type="code"/>
</Property> </Property>
<Property name="opaque" type="boolean" value="false"/> <Property name="name" type="java.lang.String" value="bigCardPanel" noResource="true"/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor"> <Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection component="Form" name="minimumSize" type="property"/> <Connection component="Form" name="minimumSize" type="property"/>
</Property> </Property>
@ -30,11 +30,18 @@
<SubComponents> <SubComponents>
<Container class="javax.swing.JScrollPane" name="scrollPane"> <Container class="javax.swing.JScrollPane" name="scrollPane">
<Properties> <Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="dc" green="dc" red="dc" type="rgb"/>
</Property>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor"> <Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="null"/> <Border info="null"/>
</Property> </Property>
<Property name="horizontalScrollBarPolicy" type="int" value="31"/> <Property name="horizontalScrollBarPolicy" type="int" value="31"/>
<Property name="opaque" type="boolean" value="false"/> <Property name="viewportBorder" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.EtchedBorderInfo">
<EtchetBorder/>
</Border>
</Property>
</Properties> </Properties>
<AuxValues> <AuxValues>
<AuxValue name="JavaCodeGenerator_allCodePost" type="java.lang.String" value="scrollPane.setBounds(new Rectangle(CONTENT_MAX_XOFFSET, TEXT_MAX_YOFFSET, TEXT_MAX_WIDTH, TEXT_MAX_HEIGHT));"/> <AuxValue name="JavaCodeGenerator_allCodePost" type="java.lang.String" value="scrollPane.setBounds(new Rectangle(CONTENT_MAX_XOFFSET, TEXT_MAX_YOFFSET, TEXT_MAX_WIDTH, TEXT_MAX_HEIGHT));"/>
@ -42,7 +49,7 @@
</AuxValues> </AuxValues>
<Constraints> <Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription"> <Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout" value="org.netbeans.modules.form.compat2.layouts.DesignAbsoluteLayout$AbsoluteConstraintsDescription">
<AbsoluteConstraints x="20" y="230" width="210" height="120"/> <AbsoluteConstraints x="20" y="220" width="210" height="130"/>
</Constraint> </Constraint>
</Constraints> </Constraints>
@ -50,9 +57,7 @@
<SubComponents> <SubComponents>
<Component class="javax.swing.JTextPane" name="text"> <Component class="javax.swing.JTextPane" name="text">
<Properties> <Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="focusable" type="boolean" value="false"/> <Property name="focusable" type="boolean" value="false"/>
<Property name="opaque" type="boolean" value="false"/>
</Properties> </Properties>
</Component> </Component>
</SubComponents> </SubComponents>

View file

@ -8,6 +8,7 @@
package mage.client.cards; package mage.client.cards;
import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Image; import java.awt.Image;
@ -15,9 +16,10 @@ import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyledDocument; import javax.swing.text.StyleConstants;
import static mage.client.constants.Constants.CONTENT_MAX_XOFFSET; import static mage.client.constants.Constants.CONTENT_MAX_XOFFSET;
import static mage.client.constants.Constants.FRAME_MAX_HEIGHT; import static mage.client.constants.Constants.FRAME_MAX_HEIGHT;
import static mage.client.constants.Constants.FRAME_MAX_WIDTH; import static mage.client.constants.Constants.FRAME_MAX_WIDTH;
@ -29,6 +31,7 @@ import mage.client.util.ImageHelper;
import mage.constants.EnlargeMode; import mage.constants.EnlargeMode;
import org.jdesktop.swingx.JXPanel; import org.jdesktop.swingx.JXPanel;
import mage.client.util.TransformedImageCache; import mage.client.util.TransformedImageCache;
import org.mage.card.arcane.UI;
/** /**
* Class for displaying big image of the card * Class for displaying big image of the card
@ -62,6 +65,9 @@ public class BigCard extends JComponent {
setOpaque(true); setOpaque(true);
this.scrollPane.setOpaque(true); this.scrollPane.setOpaque(true);
this.scrollPane.setVisible(false); this.scrollPane.setVisible(false);
UI.setHTMLEditorKit(text);
text.setEditable(false);
} }
private void initBounds(boolean rotated) { private void initBounds(boolean rotated) {
@ -69,8 +75,8 @@ public class BigCard extends JComponent {
if (rotated) { if (rotated) {
scrollPane.setBounds(50, 50, 100, 100); scrollPane.setBounds(50, 50, 100, 100);
} else { } else {
scrollPane.setBounds(this.getWidth()*1000/17777,this.getWidth()*1000/1100, scrollPane.setBounds(this.getWidth()*1000/17777,this.getWidth()*1000/1150,
this.getWidth()*1000/1142,this.getWidth()*1000/2539); this.getWidth()*1000/1130,this.getWidth()*1000/2100);
} }
} }
@ -96,7 +102,13 @@ public class BigCard extends JComponent {
source = null; source = null;
hue = 0.000f; hue = 0.000f;
} }
drawText(strings); StringBuilder displayedText = new StringBuilder();
for (String textLine: strings) {
if (textLine != null && !textLine.replace(".", "").trim().isEmpty()) {
displayedText.append("<p style='margin: 2px'>").append(textLine).append("</p>");
}
}
this.text.setText(displayedText.toString());
repaint(); repaint();
} }
} }
@ -109,19 +121,6 @@ public class BigCard extends JComponent {
this.cardId = null; this.cardId = null;
} }
private void drawText(java.util.List<String> strings) {
text.setText("");
StyledDocument doc = text.getStyledDocument();
try {
for (String line : strings) {
doc.insertString(doc.getLength(), line + '\n', doc.getStyle("regular"));
}
} catch (BadLocationException ble) {
}
text.setCaretPosition(0);
}
@Override @Override
public void paintComponent(Graphics graphics) { public void paintComponent(Graphics graphics) {
if (bigImage != null) { if (bigImage != null) {
@ -169,21 +168,19 @@ public class BigCard extends JComponent {
setFocusable(false); setFocusable(false);
setMinimumSize(new Dimension(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT)); setMinimumSize(new Dimension(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT));
setName("bigCardPanel"); // NOI18N setName("bigCardPanel"); // NOI18N
setOpaque(false);
setPreferredSize(getMinimumSize()); setPreferredSize(getMinimumSize());
setLayout(null); setLayout(null);
scrollPane.setBackground(new java.awt.Color(220, 220, 220));
scrollPane.setBorder(null); scrollPane.setBorder(null);
scrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setOpaque(false); scrollPane.setViewportBorder(javax.swing.BorderFactory.createEtchedBorder());
text.setEditable(false);
text.setFocusable(false); text.setFocusable(false);
text.setOpaque(false);
scrollPane.setViewportView(text); scrollPane.setViewportView(text);
add(scrollPane); add(scrollPane);
scrollPane.setBounds(20, 230, 210, 120); scrollPane.setBounds(20, 220, 210, 130);
scrollPane.setBounds(new Rectangle(CONTENT_MAX_XOFFSET, TEXT_MAX_YOFFSET, TEXT_MAX_WIDTH, TEXT_MAX_HEIGHT)); scrollPane.setBounds(new Rectangle(CONTENT_MAX_XOFFSET, TEXT_MAX_YOFFSET, TEXT_MAX_WIDTH, TEXT_MAX_HEIGHT));
}// </editor-fold>//GEN-END:initComponents }// </editor-fold>//GEN-END:initComponents

View file

@ -321,7 +321,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
@Override @Override
public void mouseMoved(MouseEvent arg0) { public void mouseMoved(MouseEvent arg0) {
this.bigCard.showTextComponent(); // this.bigCard.showTextComponent();
this.bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, getRules(), false); this.bigCard.setCard(card.getId(), EnlargeMode.NORMAL, image, getRules(), false);
} }

View file

@ -242,7 +242,7 @@ public class MageActionCallback implements ActionCallback {
if (this.startedDragging && prevCardPanel != null && card != null) { if (this.startedDragging && prevCardPanel != null && card != null) {
for (Component component : card.getCardArea().getComponents()) { for (Component component : card.getCardArea().getComponents()) {
if (component instanceof CardPanel) { if (component instanceof CardPanel) {
if (cardPanels.contains(component)) { if (cardPanels.contains((CardPanel) component)) {
component.setLocation(component.getLocation().x, component.getLocation().y - GO_DOWN_ON_DRAG_Y_OFFSET); component.setLocation(component.getLocation().x, component.getLocation().y - GO_DOWN_ON_DRAG_Y_OFFSET);
} }
} }
@ -316,7 +316,7 @@ public class MageActionCallback implements ActionCallback {
for (Component component : container.getComponents()) { for (Component component : container.getComponents()) {
if (component instanceof CardPanel) { if (component instanceof CardPanel) {
if (!component.equals(card)) { if (!component.equals(card)) {
if (!cardPanels.contains(component)) { if (!cardPanels.contains((CardPanel) component)) {
component.setLocation(component.getLocation().x, component.getLocation().y + GO_DOWN_ON_DRAG_Y_OFFSET); component.setLocation(component.getLocation().x, component.getLocation().y + GO_DOWN_ON_DRAG_Y_OFFSET);
} }
cardPanels.add((CardPanel) component); cardPanels.add((CardPanel) component);
@ -593,8 +593,7 @@ public class MageActionCallback implements ActionCallback {
image = mageCard.getImage(); image = mageCard.getImage();
} }
// shows the card in the popup Container // shows the card in the popup Container
BigCard bigCard = (BigCard) cardPreviewPane; displayCardInfo(mageCard, image, (BigCard) cardPreviewPane);
displayCardInfo(mageCard, image, bigCard);
} else { } else {
LOGGER.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName()); LOGGER.warn("No Card preview Pane in Mage Frame defined. Card: " + cardView.getName());

View file

@ -18,6 +18,7 @@ public abstract class MageBufferedImageOp implements BufferedImageOp {
/** /**
* Creates compatible image for @param src image. * Creates compatible image for @param src image.
*/ */
@Override
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dest) { public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dest) {
if (dest == null) { if (dest == null) {
dest = src.getColorModel(); dest = src.getColorModel();
@ -25,14 +26,17 @@ public abstract class MageBufferedImageOp implements BufferedImageOp {
return new BufferedImage(dest, dest.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), dest.isAlphaPremultiplied(), null); return new BufferedImage(dest, dest.createCompatibleWritableRaster(src.getWidth(), src.getHeight()), dest.isAlphaPremultiplied(), null);
} }
@Override
public RenderingHints getRenderingHints() { public RenderingHints getRenderingHints() {
return null; return null;
} }
@Override
public Rectangle2D getBounds2D(BufferedImage src) { public Rectangle2D getBounds2D(BufferedImage src) {
return new Rectangle(0, 0, src.getWidth(), src.getHeight()); return new Rectangle(0, 0, src.getWidth(), src.getHeight());
} }
@Override
public Point2D getPoint2D(Point2D srcPt, Point2D destPt) { public Point2D getPoint2D(Point2D srcPt, Point2D destPt) {
if (destPt == null) { if (destPt == null) {
destPt = new Point2D.Double(); destPt = new Point2D.Double();

View file

@ -4,7 +4,6 @@ import java.util.ArrayList;
import java.util.EnumSet; import java.util.EnumSet;
import mage.ObjectColor; import mage.ObjectColor;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.constants.CardType;
import mage.constants.SuperType; import mage.constants.SuperType;
import mage.util.SubTypeList; import mage.util.SubTypeList;
@ -28,7 +27,7 @@ public class AbilityView extends CardView {
this.power = ""; this.power = "";
this.toughness = ""; this.toughness = "";
this.loyalty = ""; this.loyalty = "";
this.cardTypes = new ArrayList<CardType>(); this.cardTypes = new ArrayList<>();
this.subTypes = new SubTypeList(); this.subTypes = new SubTypeList();
this.superTypes = EnumSet.noneOf(SuperType.class); this.superTypes = EnumSet.noneOf(SuperType.class);
this.color = new ObjectColor(); this.color = new ObjectColor();

View file

@ -55,7 +55,7 @@ public class GameView implements Serializable {
private final PhaseStep step; private final PhaseStep step;
private final UUID activePlayerId; private final UUID activePlayerId;
private String activePlayerName = ""; private String activePlayerName = "";
private String priorityPlayerName; private final String priorityPlayerName;
private final int turn; private final int turn;
private boolean special = false; private boolean special = false;
private final boolean isPlayer; // false = watching user private final boolean isPlayer; // false = watching user
@ -138,7 +138,7 @@ public class GameView implements Serializable {
// can happen if a player times out while ability is on the stack // can happen if a player times out while ability is on the stack
LOGGER.debug("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule()); LOGGER.debug("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule());
} }
} else { } else if (stackObject != null) {
LOGGER.fatal("Unknown type of StackObject: " + stackObject.getName() + ' ' + stackObject.toString() + ' ' + stackObject.getClass().toString()); LOGGER.fatal("Unknown type of StackObject: " + stackObject.getName() + ' ' + stackObject.toString() + ' ' + stackObject.getClass().toString());
} }
//stackOrder.add(stackObject.getId()); //stackOrder.add(stackObject.getId());

View file

@ -17,6 +17,8 @@ import mage.util.GameLog;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.abilities.hint.Hint;
import mage.abilities.hint.HintUtils;
/** /**
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -115,6 +117,18 @@ public class StackAbilityView extends CardView {
this.rules.add("<span color='green'><i>Chosen mode: " + mode.getEffects().getText(mode) + "</i></span>"); this.rules.add("<span color='green'><i>Chosen mode: " + mode.getEffects().getText(mode) + "</i></span>");
} }
} }
if (HintUtils.ABILITY_HINTS_ENABLE) {
List<String> abilityHints = new ArrayList<>();
for (Hint hint : ability.getHints()) {
abilityHints.add(hint.getText(game, ability));
}
// total hints
if (!abilityHints.isEmpty()) {
rules.add(HintUtils.HINT_START_MARK);
HintUtils.appendHints(rules, abilityHints);
}
}
} }
public CardView getSourceCard() { public CardView getSourceCard() {

View file

@ -9,8 +9,8 @@ import mage.game.Game;
*/ */
public class ValueHint implements Hint { public class ValueHint implements Hint {
private String name; private final String name;
private DynamicValue value; private final DynamicValue value;
public ValueHint(String name, DynamicValue value) { public ValueHint(String name, DynamicValue value) {
this.name = name; this.name = name;

View file

@ -12,7 +12,7 @@ import mage.game.Game;
public enum AbilityResolutionCountHint implements Hint { public enum AbilityResolutionCountHint implements Hint {
instance; instance;
private static final Hint hint = new ValueHint("Resolution count:", AbilityResolutionCount.instance); private static final Hint hint = new ValueHint("Resolution count", AbilityResolutionCount.instance);
@Override @Override
public String getText(Game game, Ability ability) { public String getText(Game game, Ability ability) {

View file

@ -953,7 +953,7 @@ public abstract class GameImpl implements Game, Serializable {
} }
// Choose a companion from the list of legal companions // Choose a companion from the list of legal companions
for (Card card : potentialCompanions) { for (Card card : potentialCompanions) {
if (player.chooseUse(Outcome.Benefit, "Use " + card.getName() + " as your companion?", null, this)) { if (player.chooseUse(Outcome.Benefit, "Use " + card.getLogName() + " as your companion?", null, this)) {
playerCompanionMap.put(player, card); playerCompanionMap.put(player, card);
break; break;
} }