* 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">
<Connection code="new Dimension(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT)" type="code"/>
</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">
<Connection component="Form" name="minimumSize" type="property"/>
</Property>
@ -30,11 +30,18 @@
<SubComponents>
<Container class="javax.swing.JScrollPane" name="scrollPane">
<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">
<Border info="null"/>
</Property>
<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>
<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));"/>
@ -42,7 +49,7 @@
</AuxValues>
<Constraints>
<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>
</Constraints>
@ -50,9 +57,7 @@
<SubComponents>
<Component class="javax.swing.JTextPane" name="text">
<Properties>
<Property name="editable" type="boolean" value="false"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="opaque" type="boolean" value="false"/>
</Properties>
</Component>
</SubComponents>

View file

@ -8,6 +8,7 @@
package mage.client.cards;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
@ -15,9 +16,10 @@ import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.List;
import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.text.BadLocationException;
import javax.swing.text.StyledDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
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_WIDTH;
@ -29,6 +31,7 @@ import mage.client.util.ImageHelper;
import mage.constants.EnlargeMode;
import org.jdesktop.swingx.JXPanel;
import mage.client.util.TransformedImageCache;
import org.mage.card.arcane.UI;
/**
* Class for displaying big image of the card
@ -62,6 +65,9 @@ public class BigCard extends JComponent {
setOpaque(true);
this.scrollPane.setOpaque(true);
this.scrollPane.setVisible(false);
UI.setHTMLEditorKit(text);
text.setEditable(false);
}
private void initBounds(boolean rotated) {
@ -69,8 +75,8 @@ public class BigCard extends JComponent {
if (rotated) {
scrollPane.setBounds(50, 50, 100, 100);
} else {
scrollPane.setBounds(this.getWidth()*1000/17777,this.getWidth()*1000/1100,
this.getWidth()*1000/1142,this.getWidth()*1000/2539);
scrollPane.setBounds(this.getWidth()*1000/17777,this.getWidth()*1000/1150,
this.getWidth()*1000/1130,this.getWidth()*1000/2100);
}
}
@ -96,7 +102,13 @@ public class BigCard extends JComponent {
source = null;
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();
}
}
@ -109,19 +121,6 @@ public class BigCard extends JComponent {
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
public void paintComponent(Graphics graphics) {
if (bigImage != null) {
@ -169,21 +168,19 @@ public class BigCard extends JComponent {
setFocusable(false);
setMinimumSize(new Dimension(FRAME_MAX_WIDTH, FRAME_MAX_HEIGHT));
setName("bigCardPanel"); // NOI18N
setOpaque(false);
setPreferredSize(getMinimumSize());
setLayout(null);
scrollPane.setBackground(new java.awt.Color(220, 220, 220));
scrollPane.setBorder(null);
scrollPane.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
scrollPane.setOpaque(false);
scrollPane.setViewportBorder(javax.swing.BorderFactory.createEtchedBorder());
text.setEditable(false);
text.setFocusable(false);
text.setOpaque(false);
scrollPane.setViewportView(text);
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));
}// </editor-fold>//GEN-END:initComponents

View file

@ -321,7 +321,7 @@ public class Card extends MagePermanent implements MouseMotionListener, MouseLis
@Override
public void mouseMoved(MouseEvent arg0) {
this.bigCard.showTextComponent();
// this.bigCard.showTextComponent();
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) {
for (Component component : card.getCardArea().getComponents()) {
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);
}
}
@ -316,7 +316,7 @@ public class MageActionCallback implements ActionCallback {
for (Component component : container.getComponents()) {
if (component instanceof CardPanel) {
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);
}
cardPanels.add((CardPanel) component);
@ -593,8 +593,7 @@ public class MageActionCallback implements ActionCallback {
image = mageCard.getImage();
}
// shows the card in the popup Container
BigCard bigCard = (BigCard) cardPreviewPane;
displayCardInfo(mageCard, image, bigCard);
displayCardInfo(mageCard, image, (BigCard) cardPreviewPane);
} else {
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.
*/
@Override
public BufferedImage createCompatibleDestImage(BufferedImage src, ColorModel dest) {
if (dest == null) {
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);
}
@Override
public RenderingHints getRenderingHints() {
return null;
}
@Override
public Rectangle2D getBounds2D(BufferedImage src) {
return new Rectangle(0, 0, src.getWidth(), src.getHeight());
}
@Override
public Point2D getPoint2D(Point2D srcPt, Point2D destPt) {
if (destPt == null) {
destPt = new Point2D.Double();

View file

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

View file

@ -55,7 +55,7 @@ public class GameView implements Serializable {
private final PhaseStep step;
private final UUID activePlayerId;
private String activePlayerName = "";
private String priorityPlayerName;
private final String priorityPlayerName;
private final int turn;
private boolean special = false;
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
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());
}
//stackOrder.add(stackObject.getId());

View file

@ -17,6 +17,8 @@ import mage.util.GameLog;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.hint.Hint;
import mage.abilities.hint.HintUtils;
/**
* @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>");
}
}
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() {

View file

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

View file

@ -12,7 +12,7 @@ import mage.game.Game;
public enum AbilityResolutionCountHint implements Hint {
instance;
private static final Hint hint = new ValueHint("Resolution count:", AbilityResolutionCount.instance);
private static final Hint hint = new ValueHint("Resolution count", AbilityResolutionCount.instance);
@Override
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
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);
break;
}