mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
Prevent being able to view information in detail pane for hidden cards
Prevent foil overlay appearing for hidden cards
This commit is contained in:
@@ -31,6 +31,7 @@ import javax.swing.border.EmptyBorder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.card.CardDetailUtil;
|
||||
import forge.card.CardRarity;
|
||||
import forge.card.CardDetailUtil.DetailColors;
|
||||
import forge.card.CardEdition;
|
||||
import forge.game.card.Card;
|
||||
@@ -38,6 +39,7 @@ import forge.game.card.CardView;
|
||||
import forge.game.card.CardView.CardStateView;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.InventoryItemFromSet;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.toolbox.FHtmlViewer;
|
||||
import forge.toolbox.FLabel;
|
||||
@@ -69,33 +71,33 @@ public class CardDetailPanel extends SkinnedPanel {
|
||||
|
||||
public CardDetailPanel() {
|
||||
super();
|
||||
this.setLayout(null);
|
||||
this.setOpaque(false);
|
||||
setLayout(null);
|
||||
setOpaque(false);
|
||||
|
||||
this.nameCostLabel = new FLabel.Builder().fontAlign(SwingConstants.CENTER).build();
|
||||
this.typeLabel = new FLabel.Builder().fontAlign(SwingConstants.CENTER).build();
|
||||
this.idLabel = new FLabel.Builder().fontAlign(SwingConstants.LEFT).tooltip("Card ID").build();
|
||||
this.powerToughnessLabel = new FLabel.Builder().fontAlign(SwingConstants.CENTER).build();
|
||||
this.setInfoLabel = new JLabel();
|
||||
this.setInfoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
nameCostLabel = new FLabel.Builder().fontAlign(SwingConstants.CENTER).build();
|
||||
typeLabel = new FLabel.Builder().fontAlign(SwingConstants.CENTER).build();
|
||||
idLabel = new FLabel.Builder().fontAlign(SwingConstants.LEFT).tooltip("Card ID").build();
|
||||
powerToughnessLabel = new FLabel.Builder().fontAlign(SwingConstants.CENTER).build();
|
||||
setInfoLabel = new JLabel();
|
||||
setInfoLabel.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
|
||||
final Font font = new Font("Dialog", 0, 14);
|
||||
this.nameCostLabel.setFont(font);
|
||||
this.typeLabel.setFont(font);
|
||||
this.idLabel.setFont(font);
|
||||
this.powerToughnessLabel.setFont(font);
|
||||
nameCostLabel.setFont(font);
|
||||
typeLabel.setFont(font);
|
||||
idLabel.setFont(font);
|
||||
powerToughnessLabel.setFont(font);
|
||||
|
||||
this.cdArea = new FHtmlViewer();
|
||||
this.cdArea.setBorder(new EmptyBorder(2, 6, 2, 6));
|
||||
this.cdArea.setOpaque(false);
|
||||
this.scrArea = new FScrollPane(this.cdArea, false);
|
||||
cdArea = new FHtmlViewer();
|
||||
cdArea.setBorder(new EmptyBorder(2, 6, 2, 6));
|
||||
cdArea.setOpaque(false);
|
||||
scrArea = new FScrollPane(cdArea, false);
|
||||
|
||||
this.add(this.nameCostLabel);
|
||||
this.add(this.typeLabel);
|
||||
this.add(this.idLabel);
|
||||
this.add(this.powerToughnessLabel);
|
||||
this.add(this.setInfoLabel);
|
||||
this.add(this.scrArea);
|
||||
add(nameCostLabel);
|
||||
add(typeLabel);
|
||||
add(idLabel);
|
||||
add(powerToughnessLabel);
|
||||
add(setInfoLabel);
|
||||
add(scrArea);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,23 +107,23 @@ public class CardDetailPanel extends SkinnedPanel {
|
||||
int x = insets;
|
||||
int y = insets;
|
||||
int lineWidth = getWidth() - 2 * insets;
|
||||
int lineHeight = this.nameCostLabel.getPreferredSize().height;
|
||||
int lineHeight = nameCostLabel.getPreferredSize().height;
|
||||
int dy = lineHeight + 1;
|
||||
|
||||
this.nameCostLabel.setBounds(x, y, lineWidth, lineHeight);
|
||||
nameCostLabel.setBounds(x, y, lineWidth, lineHeight);
|
||||
y += dy;
|
||||
|
||||
this.typeLabel.setBounds(x, y, lineWidth, lineHeight);
|
||||
typeLabel.setBounds(x, y, lineWidth, lineHeight);
|
||||
y += dy;
|
||||
|
||||
this.idLabel.setBounds(x, y, this.idLabel.getAutoSizeWidth(), lineHeight);
|
||||
this.powerToughnessLabel.setBounds(x, y, lineWidth, lineHeight);
|
||||
idLabel.setBounds(x, y, idLabel.getAutoSizeWidth(), lineHeight);
|
||||
powerToughnessLabel.setBounds(x, y, lineWidth, lineHeight);
|
||||
|
||||
//+1 to x,y so set info label right up against border and the baseline matches ID and P/T
|
||||
this.setInfoLabel.setBounds(x + lineWidth - setInfoWidth + 1, y + 1, setInfoWidth, lineHeight);
|
||||
setInfoLabel.setBounds(x + lineWidth - setInfoWidth + 1, y + 1, setInfoWidth, lineHeight);
|
||||
y += dy;
|
||||
|
||||
this.scrArea.setBounds(0, y, getWidth(), getHeight() - y);
|
||||
scrArea.setBounds(0, y, getWidth(), getHeight() - y);
|
||||
}
|
||||
|
||||
public final void setItem(final InventoryItemFromSet item) {
|
||||
@@ -130,7 +132,7 @@ public class CardDetailPanel extends SkinnedPanel {
|
||||
powerToughnessLabel.setVisible(false);
|
||||
idLabel.setText("");
|
||||
cdArea.setText(CardDetailUtil.getItemDescription(item));
|
||||
this.updateBorder(item instanceof IPaperCard ? Card.getCardForUi((IPaperCard)item).getView().getCurrentState() : null);
|
||||
updateBorder(item instanceof IPaperCard ? Card.getCardForUi((IPaperCard)item).getView().getCurrentState() : null, true);
|
||||
|
||||
String set = item.getEdition();
|
||||
setInfoLabel.setText(set);
|
||||
@@ -144,10 +146,10 @@ public class CardDetailPanel extends SkinnedPanel {
|
||||
setInfoLabel.setToolTipText(edition.getName());
|
||||
}
|
||||
|
||||
this.setInfoLabel.setOpaque(true);
|
||||
this.setInfoLabel.setBackground(Color.BLACK);
|
||||
this.setInfoLabel.setForeground(Color.WHITE);
|
||||
this.setInfoLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
|
||||
setInfoLabel.setOpaque(true);
|
||||
setInfoLabel.setBackground(Color.BLACK);
|
||||
setInfoLabel.setForeground(Color.WHITE);
|
||||
setInfoLabel.setBorder(BorderFactory.createLineBorder(Color.WHITE));
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@@ -159,56 +161,66 @@ public class CardDetailPanel extends SkinnedPanel {
|
||||
}
|
||||
|
||||
public final void setCard(final CardView card) {
|
||||
this.setCard(card, false);
|
||||
setCard(card, false);
|
||||
}
|
||||
|
||||
public final void setCard(final CardView card, final boolean isInAltState) {
|
||||
this.nameCostLabel.setText("");
|
||||
this.typeLabel.setVisible(true);
|
||||
this.typeLabel.setText("");
|
||||
this.powerToughnessLabel.setVisible(true);
|
||||
this.powerToughnessLabel.setText("");
|
||||
this.idLabel.setText("");
|
||||
this.setInfoLabel.setText("");
|
||||
this.setInfoLabel.setToolTipText("");
|
||||
this.setInfoLabel.setOpaque(false);
|
||||
this.setInfoLabel.setBorder(null);
|
||||
this.cdArea.setText("");
|
||||
nameCostLabel.setText("");
|
||||
typeLabel.setVisible(true);
|
||||
typeLabel.setText("");
|
||||
powerToughnessLabel.setVisible(true);
|
||||
powerToughnessLabel.setText("");
|
||||
idLabel.setText("");
|
||||
setInfoLabel.setText("");
|
||||
setInfoLabel.setToolTipText("");
|
||||
setInfoLabel.setOpaque(false);
|
||||
setInfoLabel.setBorder(null);
|
||||
cdArea.setText("");
|
||||
if (card == null) {
|
||||
this.updateBorder(null);
|
||||
updateBorder(null, false);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean canShow = MatchUtil.canCardBeShown(card);
|
||||
|
||||
final CardStateView state = card.getState(isInAltState);
|
||||
|
||||
if (state.getManaCost().isNoCost()) {
|
||||
this.nameCostLabel.setText(CardDetailUtil.formatCardName(state));
|
||||
} else {
|
||||
if (state.getManaCost().isNoCost() || !canShow) {
|
||||
nameCostLabel.setText(CardDetailUtil.formatCardName(state, canShow));
|
||||
}
|
||||
else {
|
||||
final String manaCost;
|
||||
if (card.isSplitCard() && card.getAlternateState() != null) {
|
||||
manaCost = card.getCurrentState().getManaCost() + " // " + card.getAlternateState().getManaCost();
|
||||
} else {
|
||||
manaCost = state.getManaCost().toString();
|
||||
}
|
||||
this.nameCostLabel.setText(FSkin.encodeSymbols(CardDetailUtil.formatCardName(state) + " - " + manaCost, true));
|
||||
nameCostLabel.setText(FSkin.encodeSymbols(CardDetailUtil.formatCardName(state, canShow) + " - " + manaCost, true));
|
||||
}
|
||||
this.typeLabel.setText(CardDetailUtil.formatCardType(state));
|
||||
|
||||
typeLabel.setText(CardDetailUtil.formatCardType(state, canShow));
|
||||
|
||||
String set = state.getSetCode();
|
||||
this.setInfoLabel.setText(set);
|
||||
CardRarity rarity = state.getRarity();
|
||||
if (!canShow) {
|
||||
set = CardEdition.UNKNOWN.getCode();
|
||||
rarity = CardRarity.Unknown;
|
||||
}
|
||||
setInfoLabel.setText(set);
|
||||
if (null != set && !set.isEmpty()) {
|
||||
CardEdition edition = FModel.getMagicDb().getEditions().get(set);
|
||||
if (null == edition) {
|
||||
setInfoLabel.setToolTipText(state.getRarity().name());
|
||||
}
|
||||
else {
|
||||
setInfoLabel.setToolTipText(String.format("%s (%s)", edition.getName(), state.getRarity().name()));
|
||||
if (canShow) {
|
||||
CardEdition edition = FModel.getMagicDb().getEditions().get(set);
|
||||
if (null == edition) {
|
||||
setInfoLabel.setToolTipText(rarity.name());
|
||||
}
|
||||
else {
|
||||
setInfoLabel.setToolTipText(String.format("%s (%s)", edition.getName(), rarity.name()));
|
||||
}
|
||||
}
|
||||
|
||||
this.setInfoLabel.setOpaque(true);
|
||||
setInfoLabel.setOpaque(true);
|
||||
|
||||
Color backColor;
|
||||
switch(state.getRarity()) {
|
||||
switch (rarity) {
|
||||
case Uncommon:
|
||||
backColor = fromDetailColor(DetailColors.UNCOMMON);
|
||||
break;
|
||||
@@ -231,19 +243,19 @@ public class CardDetailPanel extends SkinnedPanel {
|
||||
}
|
||||
|
||||
Color foreColor = FSkin.getHighContrastColor(backColor);
|
||||
this.setInfoLabel.setBackground(backColor);
|
||||
this.setInfoLabel.setForeground(foreColor);
|
||||
this.setInfoLabel.setBorder(BorderFactory.createLineBorder(foreColor));
|
||||
setInfoLabel.setBackground(backColor);
|
||||
setInfoLabel.setForeground(foreColor);
|
||||
setInfoLabel.setBorder(BorderFactory.createLineBorder(foreColor));
|
||||
}
|
||||
|
||||
this.updateBorder(state);
|
||||
updateBorder(state, canShow);
|
||||
|
||||
this.powerToughnessLabel.setText(CardDetailUtil.formatPowerToughness(state));
|
||||
powerToughnessLabel.setText(CardDetailUtil.formatPowerToughness(state, canShow));
|
||||
|
||||
this.idLabel.setText(CardDetailUtil.formatCardId(state));
|
||||
idLabel.setText(CardDetailUtil.formatCardId(state));
|
||||
|
||||
// fill the card text
|
||||
this.cdArea.setText(FSkin.encodeSymbols(CardDetailUtil.composeCardText(state), true));
|
||||
cdArea.setText(FSkin.encodeSymbols(CardDetailUtil.composeCardText(state, canShow), true));
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
@@ -255,39 +267,39 @@ public class CardDetailPanel extends SkinnedPanel {
|
||||
|
||||
/** @return FLabel */
|
||||
public FLabel getNameCostLabel() {
|
||||
return this.nameCostLabel;
|
||||
return nameCostLabel;
|
||||
}
|
||||
|
||||
/** @return FLabel */
|
||||
public FLabel getTypeLabel() {
|
||||
return this.typeLabel;
|
||||
return typeLabel;
|
||||
}
|
||||
|
||||
/** @return FLabel */
|
||||
public FLabel getPowerToughnessLabel() {
|
||||
return this.powerToughnessLabel;
|
||||
return powerToughnessLabel;
|
||||
}
|
||||
|
||||
/** @return JLabel */
|
||||
public JLabel getSetInfoLabel() {
|
||||
return this.setInfoLabel;
|
||||
return setInfoLabel;
|
||||
}
|
||||
|
||||
/** @return FHtmlViewer */
|
||||
public FHtmlViewer getCDArea() {
|
||||
return this.cdArea;
|
||||
return cdArea;
|
||||
}
|
||||
|
||||
private void updateBorder(final CardStateView card) {
|
||||
private void updateBorder(final CardStateView card, final boolean canShow) {
|
||||
// color info
|
||||
if (card == null) {
|
||||
this.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
|
||||
setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
|
||||
scrArea.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
|
||||
return;
|
||||
}
|
||||
|
||||
Color color = fromDetailColor(CardDetailUtil.getBorderColor(card));
|
||||
this.setBorder(BorderFactory.createLineBorder(color, 2));
|
||||
Color color = fromDetailColor(CardDetailUtil.getBorderColor(card, canShow));
|
||||
setBorder(BorderFactory.createLineBorder(color, 2));
|
||||
scrArea.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, color));
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ public enum VStack implements IVDoc<CStack> {
|
||||
});
|
||||
}
|
||||
|
||||
final DetailColors color = CardDetailUtil.getBorderColor(item.getSourceCard().getCurrentState());
|
||||
final DetailColors color = CardDetailUtil.getBorderColor(item.getSourceCard().getCurrentState(), true);
|
||||
setBackground(new Color(color.r, color.g, color.b));
|
||||
setForeground(FSkin.getHighContrastColor(getBackground()));
|
||||
}
|
||||
|
||||
@@ -293,9 +293,12 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
||||
return;
|
||||
}
|
||||
|
||||
displayIconOverlay(g);
|
||||
drawFoilEffect(g, card, cardXOffset, cardYOffset,
|
||||
cardWidth, cardHeight, Math.round(cardWidth * BLACK_BORDER_SIZE));
|
||||
boolean canShow = MatchUtil.canCardBeShown(card);
|
||||
displayIconOverlay(g, canShow);
|
||||
if (canShow) {
|
||||
drawFoilEffect(g, card, cardXOffset, cardYOffset,
|
||||
cardWidth, cardHeight, Math.round(cardWidth * BLACK_BORDER_SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawFoilEffect(final Graphics g, final CardView card2, final int x, final int y, final int width, final int height, final int borderSize) {
|
||||
@@ -367,8 +370,8 @@ public class CardPanel extends SkinnedPanel implements CardContainer, IDisposabl
|
||||
titleText.setVisible(isVisible);
|
||||
}
|
||||
|
||||
private void displayIconOverlay(final Graphics g) {
|
||||
if (showCardManaCostOverlay() && cardWidth < 200 && MatchUtil.canCardBeShown(card)) {
|
||||
private void displayIconOverlay(final Graphics g, final boolean canShow) {
|
||||
if (canShow && showCardManaCostOverlay() && cardWidth < 200) {
|
||||
final boolean showSplitMana = card.isSplitCard();
|
||||
if (!showSplitMana) {
|
||||
drawManaCost(g, card.getCurrentState().getManaCost(), 0);
|
||||
|
||||
Reference in New Issue
Block a user