mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Add a button on the deck editor to change your cards to the oldest versions.
This commit is contained in:
parent
55a8e34f7a
commit
75bc19d4a7
2 changed files with 78 additions and 0 deletions
|
@ -562,6 +562,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
JButton selectByButton;
|
JButton selectByButton;
|
||||||
JButton analyseButton;
|
JButton analyseButton;
|
||||||
JButton blingButton;
|
JButton blingButton;
|
||||||
|
JButton oldVersionButton;
|
||||||
|
|
||||||
// Popup for toolbar
|
// Popup for toolbar
|
||||||
final JPopupMenu filterPopup;
|
final JPopupMenu filterPopup;
|
||||||
|
@ -716,6 +717,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
selectByButton = new JButton("Select By");
|
selectByButton = new JButton("Select By");
|
||||||
analyseButton = new JButton("M"); // "Mana" button
|
analyseButton = new JButton("M"); // "Mana" button
|
||||||
blingButton = new JButton("B"); // "Bling" button
|
blingButton = new JButton("B"); // "Bling" button
|
||||||
|
oldVersionButton = new JButton("O"); // "Old version" button
|
||||||
|
|
||||||
// Name and count label
|
// Name and count label
|
||||||
deckNameAndCountLabel = new JLabel();
|
deckNameAndCountLabel = new JLabel();
|
||||||
|
@ -740,6 +742,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
toolbarInner.add(visibilityButton);
|
toolbarInner.add(visibilityButton);
|
||||||
toolbarInner.add(analyseButton);
|
toolbarInner.add(analyseButton);
|
||||||
toolbarInner.add(blingButton);
|
toolbarInner.add(blingButton);
|
||||||
|
toolbarInner.add(oldVersionButton);
|
||||||
toolbar.add(toolbarInner, BorderLayout.WEST);
|
toolbar.add(toolbarInner, BorderLayout.WEST);
|
||||||
JPanel sliderPanel = new JPanel(new GridBagLayout());
|
JPanel sliderPanel = new JPanel(new GridBagLayout());
|
||||||
sliderPanel.setOpaque(false);
|
sliderPanel.setOpaque(false);
|
||||||
|
@ -982,6 +985,11 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
|
|
||||||
blingButton.addActionListener(evt -> blingDeck());
|
blingButton.addActionListener(evt -> blingDeck());
|
||||||
|
|
||||||
|
// Old version button - Switch cards to the oldest non-promo printing. In case of multiples in a set, take the lowest card number.
|
||||||
|
oldVersionButton.setToolTipText("Switch cards to the oldest non-promo printing");
|
||||||
|
|
||||||
|
oldVersionButton.addActionListener(evt -> oldVersionDeck());
|
||||||
|
|
||||||
// Filter popup
|
// Filter popup
|
||||||
filterPopup = new JPopupMenu();
|
filterPopup = new JPopupMenu();
|
||||||
filterPopup.setPreferredSize(new Dimension(300, 300));
|
filterPopup.setPreferredSize(new Dimension(300, 300));
|
||||||
|
@ -1567,6 +1575,44 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void oldVersionDeck() {
|
||||||
|
if (this.mode != Constants.DeckEditorMode.FREE_BUILDING) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (JOptionPane.showConfirmDialog(null, "Are you sure you want to switch your card versions to the oldest ones?", "WARNING",
|
||||||
|
JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<List<List<CardView>>> newCardGrid = new ArrayList<>();
|
||||||
|
for (List<List<CardView>> gridRow : cardGrid) {
|
||||||
|
List<List<CardView>> newGridRow = new ArrayList<>();
|
||||||
|
for (List<CardView> stack : gridRow) {
|
||||||
|
List<CardView> newStack = new ArrayList<>();
|
||||||
|
for (CardView card : stack) {
|
||||||
|
CardInfo oldestCardInfo = CardRepository.instance.findOldestNonPromoVersionCard(card.getName());
|
||||||
|
if (oldestCardInfo != null) {
|
||||||
|
CardView oldestCardView = new CardView(oldestCardInfo.getMockCard());
|
||||||
|
this.removeCardView(card);
|
||||||
|
eventSource.fireEvent(card, ClientEventType.REMOVE_SPECIFIC_CARD);
|
||||||
|
this.addCardView(oldestCardView, false);
|
||||||
|
eventSource.fireEvent(oldestCardView, ClientEventType.ADD_SPECIFIC_CARD);
|
||||||
|
newStack.add(oldestCardView);
|
||||||
|
} else {
|
||||||
|
newStack.add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
newGridRow.add(newStack);
|
||||||
|
}
|
||||||
|
newCardGrid.add(newGridRow);
|
||||||
|
}
|
||||||
|
cardGrid = newCardGrid;
|
||||||
|
layoutGrid();
|
||||||
|
cardScroll.revalidate();
|
||||||
|
repaint();
|
||||||
|
}
|
||||||
|
|
||||||
// Update the contents of the card grid
|
// Update the contents of the card grid
|
||||||
public void setCards(CardsView cardsView, DeckCardLayout layout, BigCard bigCard) {
|
public void setCards(CardsView cardsView, DeckCardLayout layout, BigCard bigCard) {
|
||||||
if (bigCard != null) {
|
if (bigCard != null) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ import com.j256.ormlite.support.DatabaseConnection;
|
||||||
import com.j256.ormlite.table.TableUtils;
|
import com.j256.ormlite.table.TableUtils;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
|
import mage.constants.SetType;
|
||||||
import mage.constants.SuperType;
|
import mage.constants.SuperType;
|
||||||
import mage.game.events.Listener;
|
import mage.game.events.Listener;
|
||||||
import mage.util.RandomUtil;
|
import mage.util.RandomUtil;
|
||||||
|
@ -485,6 +486,37 @@ public enum CardRepository {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CardInfo findOldestNonPromoVersionCard(String name) {
|
||||||
|
List<CardInfo> allVersions = this.findCards(name);
|
||||||
|
if (!allVersions.isEmpty()) {
|
||||||
|
allVersions.sort(new OldestNonPromoComparator());
|
||||||
|
return allVersions.get(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class OldestNonPromoComparator implements Comparator<CardInfo> {
|
||||||
|
@Override
|
||||||
|
public int compare(CardInfo a, CardInfo b) {
|
||||||
|
ExpansionInfo aSet = ExpansionRepository.instance.getSetByCode(a.getSetCode());
|
||||||
|
ExpansionInfo bSet = ExpansionRepository.instance.getSetByCode(b.getSetCode());
|
||||||
|
if (aSet.getType() == SetType.PROMOTIONAL && bSet.getType() != SetType.PROMOTIONAL) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (bSet.getType() == SetType.PROMOTIONAL && aSet.getType() != SetType.PROMOTIONAL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (aSet.getReleaseDate().after(bSet.getReleaseDate())) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if (aSet.getReleaseDate().before(bSet.getReleaseDate())) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return Integer.compare(a.getCardNumberAsInt(), b.getCardNumberAsInt());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public long getContentVersionFromDB() {
|
public long getContentVersionFromDB() {
|
||||||
try {
|
try {
|
||||||
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
ConnectionSource connectionSource = new JdbcConnectionSource(JDBC_URL);
|
||||||
|
|
Loading…
Reference in a new issue