Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 62 additions & 8 deletions forge-gui-desktop/src/main/java/forge/deckchooser/FDeckViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@
import java.util.SortedMap;
import java.util.TreeMap;

import forge.toolbox.FMouseAdapter;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinnedLabel;
import forge.localinstance.skin.FSkinProp;
import java.awt.event.MouseEvent;

@SuppressWarnings("serial")
public class FDeckViewer extends FDialog {
private final Deck deck;
Expand All @@ -39,10 +45,14 @@ public class FDeckViewer extends FDialog {

private final CardDetailPanel cardDetail = new CardDetailPanel();
private final CardPicturePanel cardPicture = new CardPicturePanel();
private final SkinnedLabel lblFlipcard = new SkinnedLabel();
private final FButton btnCopyToClipboard = new FButton(Localizer.getInstance().getMessage("btnCopyToClipboard"));
private final FButton btnChangeSection = new FButton(Localizer.getInstance().getMessage("lblChangeSection"));
private final FButton btnClose = new FButton(Localizer.getInstance().getMessage("lblClose"));

private CardView currentCard = null;
private boolean isDisplayAlt = false;

public static void show(final Deck deck) {
if (deck == null) { return; }

Expand All @@ -63,8 +73,9 @@ protected void showHoveredItem(PaperCard item) {
final CardView card = CardView.getCardForUi(item);
if (card == null) { return; }

cardDetail.setCard(card);
cardPicture.setCard(card.getCurrentState());
currentCard = card;
isDisplayAlt = false;
updateCardDisplay();
}
};
}
Expand All @@ -77,8 +88,9 @@ protected void showHoveredItem(PaperCard item) {
final CardView card = CardView.getCardForUi(paperCard);
if (card == null) { return; }

cardDetail.setCard(card);
cardPicture.setCard(card.getCurrentState());
currentCard = card;
isDisplayAlt = false;
updateCardDisplay();
});

for (Entry<DeckSection, CardPool> entry : deck) {
Expand All @@ -87,6 +99,9 @@ protected void showHoveredItem(PaperCard item) {
this.currentSection = DeckSection.Main;
updateCaption();

this.lblFlipcard.setIcon(FSkin.getIcon(FSkinProp.ICO_FLIPCARD));
this.lblFlipcard.setVisible(false);

this.btnCopyToClipboard.setFocusable(false);
this.btnCopyToClipboard.addActionListener(arg0 -> FDeckViewer.this.copyToClipboard());
this.btnChangeSection.setFocusable(false);
Expand All @@ -101,25 +116,30 @@ protected void showHoveredItem(PaperCard item) {

final int width;
final int height;
if(FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_SMALL_DECK_VIEWER)){
if (FModel.getPreferences().getPrefBoolean(ForgePreferences.FPref.UI_SMALL_DECK_VIEWER)) {
width = 800;
height = 600;
}
else {
GraphicsDevice gd = this.getGraphicsConfiguration().getDevice();
width = (int)(gd.getDisplayMode().getWidth() * 0.7);
height = (int)(gd.getDisplayMode().getHeight() * 0.8);
width = (int) (gd.getDisplayMode().getWidth() * 0.7);
height = (int) (gd.getDisplayMode().getHeight() * 0.8);
}

this.setPreferredSize(new Dimension(width, height));
this.setSize(width, height);

this.cardPicture.setOpaque(false);

JPanel pictureContainer = new JPanel(new MigLayout("insets 0, gap 0, align center center"));
pictureContainer.setOpaque(false);
pictureContainer.add(lblFlipcard, "pos (50% - 40px) (50% - 60px)");
pictureContainer.add(this.cardPicture, "w 100%, h 100%");

JPanel cardPanel = new JPanel(new MigLayout("insets 0, gap 0, wrap"));
cardPanel.setOpaque(false);
cardPanel.add(this.cardDetail, "w 225px, h 240px, gapbottom 10px");
cardPanel.add(this.cardPicture, "w 225px, h 350px, gapbottom 10px");
cardPanel.add(pictureContainer, "w 225px, h 350px, gapbottom 10px");

JPanel buttonPanel = new JPanel(new MigLayout("insets 0, gap 0"));
buttonPanel.setOpaque(false);
Expand All @@ -133,6 +153,40 @@ protected void showHoveredItem(PaperCard item) {

this.cardManager.setup(ItemManagerConfig.DECK_VIEWER);
this.setDefaultFocus(this.cardManager.getCurrentView().getComponent());

FMouseAdapter mouseListener = new FMouseAdapter() {
@Override
public void onLeftClick(MouseEvent e) {
toggleFlip();
}
};
this.cardPicture.addMouseListener(mouseListener);
this.cardDetail.addMouseListener(mouseListener);
this.lblFlipcard.addMouseListener(mouseListener);
}

private void toggleFlip() {
if (currentCard != null && (currentCard.isFlipCard() || currentCard.hasAlternateState())) {
isDisplayAlt = !isDisplayAlt;
updateCardDisplay();
}
}

private void updateCardDisplay() {
if (currentCard == null)
return;

boolean mayFlip = currentCard.isFlipCard() || currentCard.hasAlternateState();
CardView.CardStateView state = currentCard.getState(isDisplayAlt);

boolean displayFlipped = currentCard.isFlipped();
if (currentCard.isFlipCard() && isDisplayAlt) {
displayFlipped = !displayFlipped;
}

lblFlipcard.setVisible(mayFlip);
cardDetail.setCard(currentCard, true, isDisplayAlt);
cardPicture.setCard(state, true, displayFlipped);
}

private void changeSection() {
Expand Down