Create Add Basic Lands dialog for desktop app

This commit is contained in:
drdev
2015-09-27 01:06:48 +00:00
parent fc73105532
commit 2abc509f46
14 changed files with 552 additions and 36 deletions

View File

@@ -0,0 +1,409 @@
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Forge Team
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.screens.deckeditor;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.text.NumberFormat;
import java.util.Map.Entry;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import com.google.common.collect.ImmutableList;
import forge.ImageCache;
import forge.StaticData;
import forge.UiCommand;
import forge.assets.FSkinProp;
import forge.card.CardEdition;
import forge.card.CardRules;
import forge.card.mana.ManaCostShard;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.item.PaperCard;
import forge.model.FModel;
import forge.toolbox.FComboBox;
import forge.toolbox.FComboBoxPanel;
import forge.toolbox.FHtmlViewer;
import forge.toolbox.FLabel;
import forge.toolbox.FOptionPane;
import forge.toolbox.FSkin;
import forge.toolbox.FTextField;
import forge.toolbox.FSkin.SkinnedPanel;
import forge.util.ItemPool;
import forge.view.arcane.CardPanel;
@SuppressWarnings("serial")
public class AddBasicLandsDialog {
private static final int WIDTH = 800;
private static final int HEIGHT = 375;
private static final int ADD_BTN_SIZE = 30;
private static final int LAND_PANEL_PADDING = 3;
private final FComboBoxPanel<CardEdition> cbLandSet = new FComboBoxPanel<CardEdition>("Land Set:", FlowLayout.CENTER, StaticData.instance().getEditions());
private final MainPanel panel = new MainPanel();
private final LandPanel pnlPlains = new LandPanel("Plains");
private final LandPanel pnlIsland = new LandPanel("Island");
private final LandPanel pnlSwamp = new LandPanel("Swamp");
private final LandPanel pnlMountain = new LandPanel("Mountain");
private final LandPanel pnlForest = new LandPanel("Forest");
private final FHtmlViewer lblDeckInfo = new FHtmlViewer();
private final Deck deck;
private FOptionPane optionPane;
private int nonLandCount, oldLandCount;
private CardEdition landSet;
public AddBasicLandsDialog(Deck deck0) {
this(deck0, null, null);
}
public AddBasicLandsDialog(Deck deck0, CardEdition defaultLandSet) {
this(deck0, defaultLandSet, null);
}
public AddBasicLandsDialog(Deck deck0, CardEdition defaultLandSet, ItemPool<PaperCard> restrictedCatalog0) {
deck = deck0;
if (defaultLandSet == null) {
defaultLandSet = StaticData.instance().getEditions().get("ZEN");
}
panel.setMinimumSize(new Dimension(WIDTH, HEIGHT));
panel.add(cbLandSet);
panel.add(pnlPlains);
panel.add(pnlIsland);
panel.add(pnlSwamp);
panel.add(pnlMountain);
panel.add(pnlForest);
panel.add(lblDeckInfo);
lblDeckInfo.setAlignmentX(0.5f);
lblDeckInfo.setFont(FSkin.getFont(12));
cbLandSet.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
landSet = cbLandSet.getSelectedItem();
pnlPlains.refreshArtChoices();
pnlIsland.refreshArtChoices();
pnlSwamp.refreshArtChoices();
pnlMountain.refreshArtChoices();
pnlForest.refreshArtChoices();
}
});
cbLandSet.setSelectedItem(defaultLandSet);
//initialize land counts based on current deck contents
int halfCountW = 0; //track half shard count for each color to add to symbol count only if a full symbol is also found
int halfCountU = 0;
int halfCountB = 0;
int halfCountR = 0;
int halfCountG = 0;
for (Entry<PaperCard, Integer> entry : deck.getMain()) {
CardRules cardRules = entry.getKey().getRules();
int count = entry.getValue();
if (cardRules.getType().isLand()) {
oldLandCount += count;
}
else {
nonLandCount += count;
for (ManaCostShard shard : cardRules.getManaCost()) {
boolean isMonoColor = shard.isMonoColor();
if (shard.isWhite()) {
if (isMonoColor) {
pnlPlains.symbolCount += count;
continue;
}
halfCountW += count;
}
if (shard.isBlue()) {
if (isMonoColor) {
pnlIsland.symbolCount += count;
continue;
}
halfCountU += count;
}
if (shard.isBlack()) {
if (isMonoColor) {
pnlSwamp.symbolCount += count;
continue;
}
halfCountB += count;
}
if (shard.isRed()) {
if (isMonoColor) {
pnlMountain.symbolCount += count;
continue;
}
halfCountR += count;
}
if (shard.isGreen()) {
if (isMonoColor) {
pnlForest.symbolCount += count;
continue;
}
halfCountG += count;
}
}
}
//only account for half shards if full shards exist for a given color
if (pnlPlains.symbolCount > 0 && halfCountW > 0) {
pnlPlains.symbolCount += halfCountW * 0.5;
}
if (pnlIsland.symbolCount > 0 && halfCountU > 0) {
pnlIsland.symbolCount += halfCountU * 0.5;
}
if (pnlSwamp.symbolCount > 0 && halfCountB > 0) {
pnlSwamp.symbolCount += halfCountB * 0.5;
}
if (pnlMountain.symbolCount > 0 && halfCountR > 0) {
pnlMountain.symbolCount += halfCountR * 0.5;
}
if (pnlForest.symbolCount > 0 && halfCountG > 0) {
pnlForest.symbolCount += halfCountG * 0.5;
}
}
updateDeckInfoLabel();
}
public CardPool show() {
optionPane = new FOptionPane(null, "Add Basic Lands", null, panel, ImmutableList.of("OK", "Cancel"), 0);
panel.revalidate();
panel.repaint();
optionPane.setVisible(true);
int result = optionPane.getResult();
optionPane.dispose();
if (result == 0) {
CardPool landsToAdd = new CardPool();
pnlPlains.addToCardPool(landsToAdd);
pnlIsland.addToCardPool(landsToAdd);
pnlSwamp.addToCardPool(landsToAdd);
pnlMountain.addToCardPool(landsToAdd);
pnlForest.addToCardPool(landsToAdd);
return landsToAdd;
}
return null;
}
private void updateDeckInfoLabel() {
NumberFormat integer = NumberFormat.getIntegerInstance();
NumberFormat percent = NumberFormat.getPercentInstance();
int newLandCount = pnlPlains.count + pnlIsland.count + pnlSwamp.count + pnlMountain.count + pnlForest.count;
double totalSymbolCount = pnlPlains.symbolCount + pnlIsland.symbolCount + pnlSwamp.symbolCount + pnlMountain.symbolCount + pnlForest.symbolCount;
int newTotalCount = nonLandCount + oldLandCount + newLandCount;
lblDeckInfo.setText(FSkin.encodeSymbols(
nonLandCount + " non-lands + " +
oldLandCount + " lands + " +
newLandCount + " added lands = " +
newTotalCount + " cards\n" +
"{W} " + integer.format(pnlPlains.symbolCount) + " (" + percent.format(pnlPlains.symbolCount / totalSymbolCount) + ") | " +
"{U} " + integer.format(pnlIsland.symbolCount) + " (" + percent.format(pnlIsland.symbolCount / totalSymbolCount) + ") | " +
"{B} " + integer.format(pnlSwamp.symbolCount) + " (" + percent.format(pnlSwamp.symbolCount / totalSymbolCount) + ") | " +
"{R} " + integer.format(pnlMountain.symbolCount) + " (" + percent.format(pnlMountain.symbolCount / totalSymbolCount) + ") | " +
"{G} " + integer.format(pnlForest.symbolCount) + " (" + percent.format(pnlForest.symbolCount / totalSymbolCount) + ")", true));
}
private class MainPanel extends SkinnedPanel {
private MainPanel() {
super(null);
setOpaque(false);
}
@Override
public void doLayout() {
int padding = 10;
int x = padding;
int y = padding;
int w = getWidth() - 2 * padding;
//layout land set combo box
int comboBoxHeight = FTextField.HEIGHT;
cbLandSet.setBounds(x, y, w, comboBoxHeight);
//layout card panel scroller
y += comboBoxHeight + padding;
int panelExtraHeight = pnlPlains.cbLandArt.getHeight() + ADD_BTN_SIZE + 2 * LAND_PANEL_PADDING;
int panelWidth = (getWidth() - 6 * padding) / 5;
int panelHeight = Math.round((float)panelWidth * CardPanel.ASPECT_RATIO) + panelExtraHeight;
pnlPlains.setBounds(x, y, panelWidth, panelHeight);
x += panelWidth + padding;
pnlIsland.setBounds(x, y, panelWidth, panelHeight);
x += panelWidth + padding;
pnlSwamp.setBounds(x, y, panelWidth, panelHeight);
x += panelWidth + padding;
pnlMountain.setBounds(x, y, panelWidth, panelHeight);
x += panelWidth + padding;
pnlForest.setBounds(x, y, panelWidth, panelHeight);
//layout info label
x = padding;
y += panelHeight + padding;
lblDeckInfo.setBounds(x, y, w, getHeight() - y - padding);
}
}
private class LandPanel extends SkinnedPanel {
private final LandCardPanel cardPanel;
private final FLabel lblCount, btnSubtract, btnAdd;
private final FComboBox<String> cbLandArt;
private final String cardName;
private PaperCard card;
private int count, maxCount;
private double symbolCount;
private LandPanel(String cardName0) {
super(null);
setOpaque(false);
cardName = cardName0;
cardPanel = new LandCardPanel();
cbLandArt = new FComboBox<String>();
cbLandArt.setFont(cbLandSet.getFont());
cbLandArt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent arg0) {
int artIndex = cbLandArt.getSelectedIndex();
if (artIndex < 0) { return; }
card = generateCard(artIndex); //generate card for display
}
});
lblCount = new FLabel.Builder().text("0").fontSize(18).fontAlign(SwingConstants.CENTER).build();
btnSubtract = new FLabel.ButtonBuilder().icon(FSkin.getIcon(FSkinProp.ICO_MINUS)).cmdClick(new UiCommand() {
@Override
public void run() {
if (count > 0) {
count--;
lblCount.setText(String.valueOf(count));
updateDeckInfoLabel();
}
}
}).build();
btnAdd = new FLabel.ButtonBuilder().icon(FSkin.getIcon(FSkinProp.ICO_PLUS)).cmdClick(new UiCommand() {
@Override
public void run() {
if (maxCount == 0 || count < maxCount) {
count++;
lblCount.setText(String.valueOf(count));
updateDeckInfoLabel();
}
}
}).build();
add(cardPanel);
add(cbLandArt);
add(lblCount);
add(btnSubtract);
add(btnAdd);
}
private void addToCardPool(CardPool pool) {
if (count == 0) { return; }
int artIndex = cbLandArt.getSelectedIndex();
if (artIndex < 0) { return; }
if (artIndex > 0 && card != null) {
pool.add(card, count); //simplify things if art index specified
}
else {
for (int i = 0; i < count; i++) {
pool.add(generateCard(artIndex));
}
}
}
private PaperCard generateCard(int artIndex) {
PaperCard c = FModel.getMagicDb().getCommonCards().getCard(cardName, landSet.getCode(), artIndex);
if (c == null) {
//if can't find land for this set, fall back to Zendikar lands
c = FModel.getMagicDb().getCommonCards().getCard(cardName, "ZEN");
}
return c;
}
private void refreshArtChoices() {
cbLandArt.removeAllItems();
if (landSet == null) { return; }
int artChoiceCount = FModel.getMagicDb().getCommonCards().getArtCount(cardName, landSet.getCode());
cbLandArt.addItem("Assorted Art");
for (int i = 1; i <= artChoiceCount; i++) {
cbLandArt.addItem("Card Art " + i);
}
}
@Override
public void doLayout() {
int width = getWidth();
int height = getHeight();
int y = height - ADD_BTN_SIZE;
int buttonWidth = ADD_BTN_SIZE;
int labelWidth = width - 2 * ADD_BTN_SIZE;
int minLabelWidth = lblCount.getSkin().getFont().measureTextWidth(JOptionPane.getRootFrame().getGraphics(), "0") + 2 * lblCount.getInsets().left;
if (labelWidth < minLabelWidth) { //ensure count label has enough room for display a single digit count at normal font size
labelWidth = minLabelWidth;
buttonWidth = (width - labelWidth) / 2;
}
btnSubtract.setBounds(0, y, buttonWidth, ADD_BTN_SIZE);
lblCount.setBounds(buttonWidth, y, labelWidth, ADD_BTN_SIZE);
btnAdd.setBounds(width - buttonWidth, y, buttonWidth, ADD_BTN_SIZE);
y -= FTextField.HEIGHT + LAND_PANEL_PADDING;
cbLandArt.setBounds(0, y, width, FTextField.HEIGHT);
int cardPanelHeight = y - LAND_PANEL_PADDING;
int cardPanelWidth = Math.round((float)cardPanelHeight / CardPanel.ASPECT_RATIO);
cardPanel.setBounds((width - cardPanelWidth) / 2, 0, cardPanelWidth, cardPanelHeight);
}
private class LandCardPanel extends SkinnedPanel {
private LandCardPanel() {
super(null);
setOpaque(false);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
if (card == null) { return; }
final Graphics2D g2d = (Graphics2D) g;
final BufferedImage img = ImageCache.getImage(card, getWidth(), getHeight());
if (img != null) {
g2d.drawImage(img, null, 0, 0);
}
}
}
}
}

View File

@@ -299,11 +299,6 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
CDeckEditorUI.SINGLETON_INSTANCE.removeSelectedCards(false, 4);
}
});
btnAddBasicLands.setCommand(new UiCommand() {
@Override public void run() {
}
});
itemManager.getPnlButtons().add(btnRemove, "w 30%!, h 30px!, gapx 5");
itemManager.getPnlButtons().add(btnRemove4, "w 30%!, h 30px!, gapx 5");
itemManager.getPnlButtons().add(btnAddBasicLands, "w 30%!, h 30px!, gapx 5");
@@ -374,6 +369,7 @@ public abstract class ACEditorBase<TItem extends InventoryItem, TModel extends D
protected void resetUI() {
getBtnAdd4().setVisible(true);
getBtnRemove4().setVisible(true);
getBtnAddBasicLands().setVisible(true);
VCurrentDeck.SINGLETON_INSTANCE.getBtnSave().setVisible(true);
VCurrentDeck.SINGLETON_INSTANCE.getBtnSaveAs().setVisible(true);

View File

@@ -65,6 +65,7 @@ public final class CEditorCommander extends ACEditorBase<PaperCard, Deck> {
* This is the least restrictive mode;
* all cards are available.
*/
@SuppressWarnings("serial")
public CEditorCommander(final CDetailPicture cDetailPicture) {
super(FScreen.DECK_EDITOR_COMMANDER, cDetailPicture);
allSections.add(DeckSection.Main);
@@ -89,6 +90,13 @@ public final class CEditorCommander extends ACEditorBase<PaperCard, Deck> {
}
};
this.controller = new DeckController<Deck>(FModel.getDecks().getCommander(), this, newCreator);
getBtnAddBasicLands().setCommand(new UiCommand() {
@Override
public void run() {
CEditorConstructed.addBasicLands(CEditorCommander.this, null);
}
});
}
//=========== Overridden from ACEditorBase

View File

@@ -22,6 +22,7 @@ import com.google.common.base.Supplier;
import forge.UiCommand;
import forge.card.CardRulesPredicates;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckSection;
import forge.gui.framework.FScreen;
@@ -30,6 +31,7 @@ import forge.itemmanager.CardManager;
import forge.itemmanager.ItemManagerConfig;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.screens.deckeditor.AddBasicLandsDialog;
import forge.screens.deckeditor.SEditorIO;
import forge.screens.match.controllers.CDetailPicture;
import forge.util.ItemPool;
@@ -59,6 +61,7 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
* This is the least restrictive mode;
* all cards are available.
*/
@SuppressWarnings("serial")
public CEditorConstructed(final CDetailPicture cDetailPicture) {
super(FScreen.DECK_EDITOR_CONSTRUCTED, cDetailPicture);
@@ -91,6 +94,13 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
};
this.controller = new DeckController<Deck>(FModel.getDecks().getConstructed(), this, newCreator);
getBtnAddBasicLands().setCommand(new UiCommand() {
@Override
public void run() {
CEditorConstructed.addBasicLands(CEditorConstructed.this, null);
}
});
}
//=========== Overridden from ACEditorBase
@@ -321,6 +331,17 @@ public final class CEditorConstructed extends ACEditorBase<PaperCard, Deck> {
this.controller.updateCaptions();
}
public static void addBasicLands(ACEditorBase<PaperCard, Deck> editor, ItemPool<PaperCard> restrictedCatalog) {
Deck deck = editor.getDeckController().getModel();
if (deck == null) { return; }
AddBasicLandsDialog dialog = new AddBasicLandsDialog(deck, null, restrictedCatalog);
CardPool landsToAdd = dialog.show();
if (landsToAdd != null) {
editor.onAddItems(landsToAdd, false);
}
}
/* (non-Javadoc)
* @see forge.gui.deckeditor.ACEditorBase#show(forge.Command)
*/

View File

@@ -19,6 +19,10 @@ package forge.screens.deckeditor.controllers;
import com.google.common.base.Supplier;
import forge.StaticData;
import forge.UiCommand;
import forge.card.CardEdition;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckGroup;
import forge.deck.DeckSection;
@@ -27,6 +31,7 @@ import forge.gui.framework.FScreen;
import forge.item.PaperCard;
import forge.itemmanager.CardManager;
import forge.itemmanager.ItemManagerConfig;
import forge.screens.deckeditor.AddBasicLandsDialog;
import forge.screens.deckeditor.SEditorIO;
import forge.screens.deckeditor.views.VAllDecks;
import forge.screens.deckeditor.views.VCurrentDeck;
@@ -34,6 +39,7 @@ import forge.screens.deckeditor.views.VDeckgen;
import forge.screens.home.sanctioned.CSubmenuDraft;
import forge.screens.home.sanctioned.CSubmenuSealed;
import forge.screens.match.controllers.CDetailPicture;
import forge.util.ItemPool;
import forge.util.storage.IStorage;
import java.util.Map.Entry;
@@ -59,6 +65,7 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
*
* @param deckMap0 &emsp; {@link forge.deck.DeckGroup}<{@link forge.util.storage.IStorage}>
*/
@SuppressWarnings("serial")
public CEditorLimited(final IStorage<DeckGroup> deckMap0, final FScreen screen0, final CDetailPicture cDetailPicture) {
super(screen0, cDetailPicture);
@@ -80,6 +87,13 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
}
};
this.controller = new DeckController<DeckGroup>(deckMap0, this, newCreator);
getBtnAddBasicLands().setCommand(new UiCommand() {
@Override
public void run() {
CEditorLimited.addBasicLands(CEditorLimited.this, null);
}
});
}
/**
@@ -155,6 +169,18 @@ public final class CEditorLimited extends ACEditorBase<PaperCard, DeckGroup> {
return this.controller;
}
public static void addBasicLands(ACEditorBase<PaperCard, DeckGroup> editor, ItemPool<PaperCard> restrictedCatalog) {
Deck deck = editor.getDeckController().getModel().getHumanDeck();
if (deck == null) { return; }
CardEdition defaultLandSet = StaticData.instance().getEditions().getEarliestEditionWithAllCards(deck.getAllCardsInASinglePool());
AddBasicLandsDialog dialog = new AddBasicLandsDialog(deck, defaultLandSet, restrictedCatalog);
CardPool landsToAdd = dialog.show();
if (landsToAdd != null) {
editor.onAddItems(landsToAdd, false);
}
}
/* (non-Javadoc)
* @see forge.gui.deckeditor.ACEditorBase#show(forge.Command)
*/

View File

@@ -90,6 +90,7 @@ public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
*
* @param questData0 &emsp; {@link forge.quest.QuestController}
*/
@SuppressWarnings("serial")
public CEditorQuest(final QuestController questData0, final CDetailPicture cDetailPicture) {
super(FScreen.DECK_EDITOR_QUEST, cDetailPicture);
@@ -117,6 +118,13 @@ public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
};
this.controller = new DeckController<Deck>(questData0.getMyDecks(), this, newCreator);
getBtnAddBasicLands().setCommand(new UiCommand() {
@Override
public void run() {
CEditorConstructed.addBasicLands(CEditorQuest.this, questData.getCards().getCardpool());
}
});
}
// fills number of decks using each card
@@ -292,5 +300,4 @@ public final class CEditorQuest extends ACEditorBase<PaperCard, Deck> {
allDecksParent.addDoc(VAllDecks.SINGLETON_INSTANCE);
}
}
}

View File

@@ -235,6 +235,8 @@ public final class CEditorQuestCardShop extends ACEditorBase<InventoryItem, Deck
CDRemLabel = this.getBtnRemove().getText();
this.getBtnRemove().setText("Sell Card");
this.getBtnAddBasicLands().setVisible(false);
VProbabilities.SINGLETON_INSTANCE.getTabLabel().setVisible(false);
prevRem4Label = this.getBtnRemove4().getText();

View File

@@ -26,6 +26,7 @@ import java.util.Map.Entry;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import forge.UiCommand;
import forge.deck.Deck;
import forge.deck.DeckGroup;
import forge.deck.DeckSection;
@@ -90,6 +91,7 @@ public final class CEditorQuestLimited extends ACEditorBase<PaperCard, DeckGroup
*
* @param questData0 &emsp; {@link forge.quest.QuestController}
*/
@SuppressWarnings("serial")
public CEditorQuestLimited(final QuestController questData0, final CDetailPicture cDetailPicture) {
super(FScreen.DECK_EDITOR_QUEST_TOURNAMENT, cDetailPicture);
@@ -120,6 +122,12 @@ public final class CEditorQuestLimited extends ACEditorBase<PaperCard, DeckGroup
controller.getView().getDeckManager().setup(ItemManagerConfig.DRAFT_POOL);
controller.setModel(questData0.getDraftDecks().get(QuestEventDraft.DECK_NAME));
getBtnAddBasicLands().setCommand(new UiCommand() {
@Override
public void run() {
CEditorLimited.addBasicLands(CEditorQuestLimited.this, questData.getCards().getCardpool());
}
});
}
// fills number of decks using each card
@@ -221,7 +229,6 @@ public final class CEditorQuestLimited extends ACEditorBase<PaperCard, DeckGroup
@Override
public void update() {
this.getCatalogManager().setup(getScreen() == FScreen.DECK_EDITOR_DRAFT ? ItemManagerConfig.DRAFT_POOL : ItemManagerConfig.SEALED_POOL);
this.getDeckManager().setup(ItemManagerConfig.DECK_EDITOR);

View File

@@ -21,6 +21,7 @@ import com.google.common.base.Predicate;
import com.google.common.base.Supplier;
import com.google.common.collect.Iterables;
import forge.UiCommand;
import forge.deck.Deck;
import forge.deck.DeckSection;
import forge.gui.framework.DragCell;
@@ -61,6 +62,7 @@ public final class CEditorVariant extends ACEditorBase<PaperCard, Deck> {
* This is the least restrictive mode;
* all cards are available.
*/
@SuppressWarnings("serial")
public CEditorVariant(final IStorage<Deck> folder, final Predicate<PaperCard> poolCondition, final DeckSection deckSection0, final FScreen screen0, final CDetailPicture cDetailPicture) {
super(screen0, cDetailPicture);
@@ -82,6 +84,13 @@ public final class CEditorVariant extends ACEditorBase<PaperCard, Deck> {
}
};
this.controller = new DeckController<Deck>(folder, this, newCreator);
getBtnAddBasicLands().setCommand(new UiCommand() {
@Override
public void run() {
CEditorConstructed.addBasicLands(CEditorVariant.this, null);
}
});
}
//=========== Overridden from ACEditorBase

View File

@@ -74,6 +74,7 @@ public class CEditorWinstonProcess extends ACEditorBase<PaperCard, DeckGroup> {
/**
* Updates the deck editor UI as necessary draft selection mode.
*/
@SuppressWarnings("serial")
public CEditorWinstonProcess(final CDetailPicture cDetailPicture) {
super(FScreen.DRAFTING_PROCESS, cDetailPicture);
@@ -90,6 +91,13 @@ public class CEditorWinstonProcess extends ACEditorBase<PaperCard, DeckGroup> {
this.setCatalogManager(catalogManager);
this.setDeckManager(deckManager);
getBtnAddBasicLands().setCommand(new UiCommand() {
@Override
public void run() {
CEditorLimited.addBasicLands(CEditorWinstonProcess.this, null);
}
});
}
/**

View File

@@ -1,11 +1,14 @@
package forge.toolbox;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
import com.google.common.collect.ImmutableList;
import forge.toolbox.FSkin.SkinnedLabel;
/**
@@ -25,25 +28,40 @@ public class FComboBoxPanel<E> extends JPanel {
private String comboBoxCaption = "";
private FComboBox<E> comboBox = null;
private int flowLayout;
public FComboBoxPanel(final String comboBoxCaption) {
public FComboBoxPanel(final String comboBoxCaption0) {
this(comboBoxCaption0, FlowLayout.LEFT);
}
public FComboBoxPanel(final String comboBoxCaption0, int flowLayout0) {
super();
this.comboBoxCaption = comboBoxCaption;
comboBoxCaption = comboBoxCaption0;
flowLayout = flowLayout0;
applyLayoutAndSkin();
allPanels.add(this);
}
public void setComboBox(final FComboBox<E> comboBox, final E selectedItem) {
public FComboBoxPanel(final String comboBoxCaption0, Iterable<E> items) {
this(comboBoxCaption0, FlowLayout.LEFT, items);
}
public FComboBoxPanel(final String comboBoxCaption0, int flowLayout0, Iterable<E> items) {
this(comboBoxCaption0, flowLayout0);
List<E> list = ImmutableList.copyOf(items);
setComboBox(new FComboBox<E>(list), list.get(0));
}
public void setComboBox(final FComboBox<E> comboBox0, final E selectedItem) {
removeExistingComboBox();
this.comboBox = comboBox;
this.comboBox.setSelectedItem(selectedItem);
comboBox = comboBox0;
comboBox.setSelectedItem(selectedItem);
setComboBoxLayout();
}
private void removeExistingComboBox() {
if (this.comboBox != null) {
this.remove(this.comboBox);
this.comboBox = null;
if (comboBox != null) {
remove(comboBox);
comboBox = null;
}
}
@@ -54,42 +72,46 @@ public class FComboBoxPanel<E> extends JPanel {
}
private void setPanelLayout() {
final FlowLayout panelLayout = new FlowLayout(FlowLayout.LEFT);
final FlowLayout panelLayout = new FlowLayout(flowLayout);
panelLayout.setVgap(0);
this.setLayout(panelLayout);
this.setOpaque(false);
setLayout(panelLayout);
setOpaque(false);
}
private void setLabelLayout() {
if (this.comboBoxCaption != null && !this.comboBoxCaption.isEmpty()) {
final SkinnedLabel comboLabel = new SkinnedLabel(this.comboBoxCaption);
if (comboBoxCaption != null && !comboBoxCaption.isEmpty()) {
final SkinnedLabel comboLabel = new SkinnedLabel(comboBoxCaption);
comboLabel.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
comboLabel.setFont(FSkin.getBoldFont(12));
this.add(comboLabel);
add(comboLabel);
}
}
private void setComboBoxLayout() {
if (this.comboBox != null) {
this.comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
this.comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
this.comboBox.setFont(FSkin.getFont(12));
this.comboBox.setEditable(false);
this.comboBox.setFocusable(true);
this.comboBox.setOpaque(true);
this.add(this.comboBox);
if (comboBox != null) {
comboBox.setBackground(FSkin.getColor(FSkin.Colors.CLR_THEME2));
comboBox.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
comboBox.setFont(FSkin.getFont(12));
comboBox.setEditable(false);
comboBox.setFocusable(true);
comboBox.setOpaque(true);
add(comboBox);
}
}
public void setSelectedItem(final Object item) {
this.comboBox.setSelectedItem(item);
public void addActionListener(final ActionListener l) {
comboBox.addActionListener(l);
}
public Object getSelectedItem() {
return this.comboBox.getSelectedItem();
public void setSelectedItem(final Object item) {
comboBox.setSelectedItem(item);
}
public E getSelectedItem() {
return comboBox.getSelectedItem();
}
private void refreshSkin() {
this.comboBox = FComboBoxWrapper.refreshComboBoxSkin(this.comboBox);
comboBox = FComboBoxWrapper.refreshComboBoxSkin(comboBox);
}
}