add option to browse card images using card flow screen from explorer.

master
lodici 2017-07-17 17:32:26 +01:00
parent 3a0274521a
commit 1c11b93fdf
8 changed files with 115 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 712 B

View File

@ -9,6 +9,7 @@ public enum MagicIcon {
// ../ui/... icons.
//
ALERT("ui/alert-16.png"),
CARDFLOW("ui/cardflow-32.png"),
CHECKBOX_OFF("ui/checkbox-16.png"),
CHECKBOX_ON("ui/checkbox-selected-16.png"),
ARROWDOWN("ui/w_arrowdown.png"),

View File

@ -23,6 +23,7 @@ import magic.ui.screen.about.AboutScreen;
import magic.ui.screen.card.explorer.ExplorerScreen;
import magic.ui.screen.card.script.CardScriptScreen;
import magic.ui.screen.cardflow.CardFlowScreen;
import magic.ui.screen.cardflow.ICardFlowListener;
import magic.ui.screen.cardflow.ICardFlowProvider;
import magic.ui.screen.deck.DeckScreen;
import magic.ui.screen.deck.editor.DeckEditorScreen;
@ -361,6 +362,10 @@ public final class ScreenController {
showScreen(() -> new CardFlowScreen(provider, screenTitle));
}
public static void showCardFlowScreen(ICardFlowProvider provider, ICardFlowListener listener, String screenTitle) {
showScreen(() -> new CardFlowScreen(provider, listener, screenTitle));
}
public static boolean isDeckScreenShowing() {
return !screens.isEmpty() && screens.peek() instanceof DeckScreen;
}

View File

@ -5,6 +5,7 @@ import java.awt.Container;
import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
@ -12,6 +13,7 @@ import javax.swing.SwingUtilities;
import magic.model.MagicCardDefinition;
import magic.model.MagicRandom;
import magic.ui.ICardFilterPanelListener;
import magic.ui.MagicImages;
import magic.ui.ScreenController;
import magic.ui.widget.card.filter.CardFilterPanel;
import magic.ui.widget.cards.table.CardTablePanelB;
@ -130,6 +132,22 @@ public class ExplorerContentPanel extends JPanel
cardPoolTable.setStyle();
}
BufferedImage getCardImage(int index) {
return MagicImages.getCardImage(cardPoolTable.getCard(index));
}
int getCardsCount() {
return filterPanel.getTotalCardCount();
}
void setCardAt(int index) {
cardPoolTable.selectCardAt(index);
}
int getSelectedCardIndex() {
return cardPoolTable.getSelectedCardIndex();
}
private class CardPoolMouseListener extends MouseAdapter {
@Override
public void mouseReleased(MouseEvent e) {

View File

@ -1,17 +1,27 @@
package magic.ui.screen.card.explorer;
import java.awt.Color;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.SwingUtilities;
import magic.data.MagicIcon;
import magic.data.MagicSetDefinitions;
import magic.translate.MText;
import magic.ui.MagicLogs;
import magic.ui.MagicSound;
import magic.ui.ScreenController;
import magic.ui.WikiPage;
import magic.ui.helpers.ImageHelper;
import magic.ui.screen.HeaderFooterScreen;
import magic.ui.screen.MScreen;
import magic.ui.screen.cardflow.ICardFlowListener;
import magic.ui.screen.cardflow.ICardFlowProvider;
import magic.ui.screen.widget.PlainMenuButton;
import magic.ui.widget.cards.table.CardsTableStyle;
@SuppressWarnings("serial")
public class ExplorerScreen extends HeaderFooterScreen {
public class ExplorerScreen extends HeaderFooterScreen
implements ICardFlowProvider, ICardFlowListener {
// translatable strings
private static final String _S1 = "Card Explorer";
@ -19,6 +29,12 @@ public class ExplorerScreen extends HeaderFooterScreen {
private static final String _S4 = "View the script and groovy files for the selected card.<br>(or double-click row)";
private static final String _S5 = "Lucky Dip";
private static final String _S6 = "Selects a random card from the list of cards displayed.";
private static final String _S7 = "Card flow screen";
private static final String _S8 = "Browse through the card images starting at the selected card.";
private static final ImageIcon CARDFLOW_ICON = ImageHelper.getRecoloredIcon(
MagicIcon.CARDFLOW, Color.BLACK, Color.WHITE
);
private ExplorerContentPanel contentPanel;
private ExplorerHeaderPanel headerPanel;
@ -49,15 +65,27 @@ public class ExplorerScreen extends HeaderFooterScreen {
}
private void setFooterButtons() {
addToFooter(PlainMenuButton.build(this::doShowScriptScreen,
MagicIcon.EDIT, MText.get(_S3), MText.get(_S4)
),
PlainMenuButton.build(this::doSelectRandomCard,
MagicIcon.RANDOM, MText.get(_S5), MText.get(_S6)
)
addToFooter(
PlainMenuButton.build(this::doShowScriptScreen,
MagicIcon.EDIT, MText.get(_S3), MText.get(_S4)
),
PlainMenuButton.build(this::doSelectRandomCard,
MagicIcon.RANDOM, MText.get(_S5), MText.get(_S6)
),
PlainMenuButton.build(this::doShowCardFlowScreen,
CARDFLOW_ICON, MText.get(_S7), MText.get(_S8)
)
);
}
private void doShowCardFlowScreen() {
if (contentPanel.getCardsCount() > 0) {
ScreenController.showCardFlowScreen(this, this, MText.get(_S1));
} else {
MagicSound.BEEP.play();
}
}
private void doShowScriptScreen() {
contentPanel.showCardScriptScreen();
}
@ -89,4 +117,29 @@ public class ExplorerScreen extends HeaderFooterScreen {
CardsTableStyle.setStyle(dialPosition);
contentPanel.setCardsTableStyle();
}
@Override
public BufferedImage getImage(int index) {
return contentPanel.getCardImage(index);
}
@Override
public int getImagesCount() {
return contentPanel.getCardsCount();
}
@Override
public int getStartImageIndex() {
return contentPanel.getSelectedCardIndex();
}
@Override
public void setNewActiveImage(int index) {
SwingUtilities.invokeLater(() -> contentPanel.setCardAt(index));
}
@Override
public void cardFlowClicked() {
// not supported
}
}

View File

@ -431,7 +431,9 @@ class CardFlowPanel extends JPanel implements TimelineCallback {
}
public void addListener(ICardFlowListener aListener) {
listeners.add(aListener);
if (aListener != null) {
listeners.add(aListener);
}
}
public int getImagesCount() {

View File

@ -33,10 +33,22 @@ public class CardFlowScreen extends HeaderFooterScreen
private final OptionsPanel optionsPanel;
private final ScreenSettings settings = new ScreenSettings();
private final FlashTextOverlay flashOverlay = new FlashTextOverlay();
private final ICardFlowListener listener;
public CardFlowScreen(ICardFlowProvider provider, ICardFlowListener listener, String screenTitle) {
super(screenTitle);
this.provider = provider;
this.listener = listener;
optionsPanel = new OptionsPanel(this, settings);
cardFlowPanel = new CardFlowPanel(provider, settings);
layeredPane = new CardFlowLayeredPane(cardFlowPanel, flashOverlay);
initialize();
}
public CardFlowScreen(ICardFlowProvider provider, String screenTitle) {
super(screenTitle);
this.provider = provider;
this.listener = null;
optionsPanel = new OptionsPanel(this, settings);
cardFlowPanel = new CardFlowPanel(provider, settings);
layeredPane = new CardFlowLayeredPane(cardFlowPanel, flashOverlay);
@ -46,6 +58,7 @@ public class CardFlowScreen extends HeaderFooterScreen
public CardFlowScreen() {
super("Cardflow Test Screen");
this.provider = this;
this.listener = null;
optionsPanel = new OptionsPanel(this, settings);
cardFlowPanel = new CardFlowPanel(this, settings);
layeredPane = new CardFlowLayeredPane(cardFlowPanel, flashOverlay);
@ -55,6 +68,7 @@ public class CardFlowScreen extends HeaderFooterScreen
private void initialize() {
cardFlowPanel.addListener(this);
cardFlowPanel.addListener(listener);
cardFlowPanel.setBackground(BACKGROUND_COLOR);
setMainContent(layeredPane);

View File

@ -121,4 +121,18 @@ public class CardTablePanelB extends CardsTablePanel
tableModel.showCardCount(b);
}
public MagicCardDefinition getCard(int index) {
return tableModel.getCardDef(index);
}
public void selectCardAt(int index) {
table.setRowSelectionInterval(index, index);
scrollRowToViewportCenter(index);
}
public int getSelectedCardIndex() {
int row = table.getSelectedRow();
return row == -1 ? 0 : row;
}
}