mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Coverted deck editors and cardshop to JDialog.
This allows them to be modal and gets rid of the setAlwaysOnTop() call. (Which causes all manner of headaches on Linux)
This commit is contained in:
@@ -1,351 +1,354 @@
|
||||
/*
|
||||
* 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.gui.deckeditor;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.elements.CardPanelBase;
|
||||
import forge.gui.deckeditor.elements.DeckAnalysis;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.Predicate;
|
||||
|
||||
/**
|
||||
* The Class DeckEditorBase.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
* @param <TModel> the generic type
|
||||
*/
|
||||
public abstract class DeckEditorBase<T extends InventoryItem, TModel extends DeckBase> extends JFrame {
|
||||
private static final long serialVersionUID = -401223933343539977L;
|
||||
|
||||
/** The filter boxes. */
|
||||
private FilterCheckBoxes filterBoxes;
|
||||
// set this to false when resetting filter from code (like
|
||||
// "clearFiltersPressed"), reset when done.
|
||||
/** The is filters change firing update. */
|
||||
private boolean isFiltersChangeFiringUpdate = true;
|
||||
|
||||
/** The card view. */
|
||||
private CardPanelBase cardView;
|
||||
|
||||
// CardPools and Table data for top and bottom lists
|
||||
/** The top. */
|
||||
private TableView<T> topTableWithCards;
|
||||
|
||||
/** The bottom. */
|
||||
private TableView<T> bottomTableWithCards;
|
||||
|
||||
// top shows available card pool
|
||||
// if constructed, top shows all cards
|
||||
// if sealed, top shows N booster packs
|
||||
// if draft, top shows cards that were chosen
|
||||
/**
|
||||
* Gets the top table model.
|
||||
*
|
||||
* @return the top table model
|
||||
*/
|
||||
public final TableView<T> getTopTableModel() {
|
||||
return this.getTopTableWithCards();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getTop()
|
||||
*/
|
||||
/**
|
||||
* Gets the top.
|
||||
*
|
||||
* @return the top
|
||||
*/
|
||||
public final ItemPoolView<T> getTop() {
|
||||
return this.getTopTableWithCards().getCards();
|
||||
}
|
||||
|
||||
// bottom shows player's choice - be it deck or draft
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getBottom()
|
||||
*/
|
||||
/**
|
||||
* Gets the bottom.
|
||||
*
|
||||
* @return the bottom
|
||||
*/
|
||||
public final ItemPoolView<T> getBottom() {
|
||||
return this.getBottomTableWithCards().getCards();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the controller.
|
||||
*
|
||||
* @return the controller
|
||||
*/
|
||||
public abstract DeckController<TModel> getController();
|
||||
|
||||
// THIS IS HERE FOR OVERLOADING!!!1
|
||||
// or may be return abstract getFilter from derived class + this filter ...
|
||||
// virtual protected member, but later
|
||||
/**
|
||||
* Builds the filter.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
protected abstract Predicate<T> buildFilter();
|
||||
|
||||
/**
|
||||
* Show.
|
||||
*
|
||||
* @param exitCommand the exit command
|
||||
*/
|
||||
public abstract void show(final Command exitCommand);
|
||||
|
||||
/**
|
||||
* Analysis button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
final void analysisButtonActionPerformed(final ActionEvent e) {
|
||||
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(this.getBottomTableWithCards().getCards(),
|
||||
CardPrinted.class);
|
||||
if (deck.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
final DeckEditorBase<T, TModel> g = DeckEditorBase.this;
|
||||
final DeckAnalysis dAnalysis = new DeckAnalysis(g, deck);
|
||||
dAnalysis.setVisible(true);
|
||||
g.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#setItems(forge.item.ItemPoolView,
|
||||
* forge.item.ItemPoolView, forge.game.GameType)
|
||||
*/
|
||||
/**
|
||||
* Update view.
|
||||
*/
|
||||
public abstract void updateView();
|
||||
|
||||
/**
|
||||
* Update display.
|
||||
*/
|
||||
public final void updateDisplay() {
|
||||
this.getTopTableWithCards().setFilter(this.buildFilter());
|
||||
}
|
||||
|
||||
/** The item listener updates display. */
|
||||
private ItemListener itemListenerUpdatesDisplay = new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
|
||||
DeckEditorBase.this.updateDisplay();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is used for a feature: when you start typing card name, the
|
||||
* list gets auto-filtered.
|
||||
*/
|
||||
protected class OnChangeTextUpdateDisplay implements DocumentListener {
|
||||
private void onChange() {
|
||||
if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
|
||||
DeckEditorBase.this.updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* javax.swing.event.DocumentListener#insertUpdate(javax.swing.event
|
||||
* .DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public final void insertUpdate(final DocumentEvent e) {
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* javax.swing.event.DocumentListener#removeUpdate(javax.swing.event
|
||||
* .DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public final void removeUpdate(final DocumentEvent e) {
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* javax.swing.event.DocumentListener#changedUpdate(javax.swing.event
|
||||
* .DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public void changedUpdate(final DocumentEvent e) {
|
||||
} // Happend only on ENTER pressed
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item listener updates display.
|
||||
*
|
||||
* @return the itemListenerUpdatesDisplay
|
||||
*/
|
||||
public ItemListener getItemListenerUpdatesDisplay() {
|
||||
return this.itemListenerUpdatesDisplay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the item listener updates display.
|
||||
*
|
||||
* @param itemListenerUpdatesDisplay
|
||||
* the itemListenerUpdatesDisplay to set
|
||||
*/
|
||||
public void setItemListenerUpdatesDisplay(final ItemListener itemListenerUpdatesDisplay) {
|
||||
this.itemListenerUpdatesDisplay = itemListenerUpdatesDisplay; // TODO:
|
||||
// Add 0
|
||||
// to
|
||||
// parameter's
|
||||
// name.
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is filters change firing update.
|
||||
*
|
||||
* @return the isFiltersChangeFiringUpdate
|
||||
*/
|
||||
public boolean isFiltersChangeFiringUpdate() {
|
||||
return this.isFiltersChangeFiringUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filters change firing update.
|
||||
*
|
||||
* @param isFiltersChangeFiringUpdate
|
||||
* the isFiltersChangeFiringUpdate to set
|
||||
*/
|
||||
public void setFiltersChangeFiringUpdate(final boolean isFiltersChangeFiringUpdate) {
|
||||
this.isFiltersChangeFiringUpdate = isFiltersChangeFiringUpdate; // TODO:
|
||||
// Add 0
|
||||
// to
|
||||
// parameter's
|
||||
// name.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the card view.
|
||||
*
|
||||
* @return the cardView
|
||||
*/
|
||||
public CardPanelBase getCardView() {
|
||||
return this.cardView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the card view.
|
||||
*
|
||||
* @param cardView0
|
||||
* the cardView to set
|
||||
*/
|
||||
protected void setCardView(final CardPanelBase cardView0) {
|
||||
this.cardView = cardView0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter boxes.
|
||||
*
|
||||
* @return the filterBoxes
|
||||
*/
|
||||
public FilterCheckBoxes getFilterBoxes() {
|
||||
return this.filterBoxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filter boxes.
|
||||
*
|
||||
* @param filterBoxes0
|
||||
* the filterBoxes to set
|
||||
*/
|
||||
public void setFilterBoxes(final FilterCheckBoxes filterBoxes0) {
|
||||
this.filterBoxes = filterBoxes0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bottom table with cards.
|
||||
*
|
||||
* @return the bottomTableWithCards
|
||||
*/
|
||||
public TableView<T> getBottomTableWithCards() {
|
||||
return this.bottomTableWithCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bottom table with cards.
|
||||
*
|
||||
* @param bottomTableWithCards0
|
||||
* the bottomTableWithCards to set
|
||||
*/
|
||||
public void setBottomTableWithCards(final TableView<T> bottomTableWithCards0) {
|
||||
this.bottomTableWithCards = bottomTableWithCards0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top table with cards.
|
||||
*
|
||||
* @return the topTableWithCards
|
||||
*/
|
||||
public TableView<T> getTopTableWithCards() {
|
||||
return this.topTableWithCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the top table with cards.
|
||||
*
|
||||
* @param topTableWithCards0
|
||||
* the topTableWithCards to set
|
||||
*/
|
||||
public void setTopTableWithCards(final TableView<T> topTableWithCards0) {
|
||||
this.topTableWithCards = topTableWithCards0;
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.gui.deckeditor;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.DocumentListener;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.elements.CardPanelBase;
|
||||
import forge.gui.deckeditor.elements.DeckAnalysis;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.Predicate;
|
||||
|
||||
/**
|
||||
* The Class DeckEditorBase.
|
||||
*
|
||||
* @param <T> the generic type
|
||||
* @param <TModel> the generic type
|
||||
*/
|
||||
public abstract class DeckEditorBase<T extends InventoryItem, TModel extends DeckBase> extends JDialog {
|
||||
private static final long serialVersionUID = -401223933343539977L;
|
||||
|
||||
/** The filter boxes. */
|
||||
private FilterCheckBoxes filterBoxes;
|
||||
// set this to false when resetting filter from code (like
|
||||
// "clearFiltersPressed"), reset when done.
|
||||
/** The is filters change firing update. */
|
||||
private boolean isFiltersChangeFiringUpdate = true;
|
||||
|
||||
/** The card view. */
|
||||
private CardPanelBase cardView;
|
||||
|
||||
// CardPools and Table data for top and bottom lists
|
||||
/** The top. */
|
||||
private TableView<T> topTableWithCards;
|
||||
|
||||
/** The bottom. */
|
||||
private TableView<T> bottomTableWithCards;
|
||||
|
||||
public DeckEditorBase(JFrame parent) {
|
||||
super(parent, ModalityType.APPLICATION_MODAL);
|
||||
}
|
||||
|
||||
// top shows available card pool
|
||||
// if constructed, top shows all cards
|
||||
// if sealed, top shows N booster packs
|
||||
// if draft, top shows cards that were chosen
|
||||
/**
|
||||
* Gets the top table model.
|
||||
*
|
||||
* @return the top table model
|
||||
*/
|
||||
public final TableView<T> getTopTableModel() {
|
||||
return this.getTopTableWithCards();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getTop()
|
||||
*/
|
||||
/**
|
||||
* Gets the top.
|
||||
*
|
||||
* @return the top
|
||||
*/
|
||||
public final ItemPoolView<T> getTop() {
|
||||
return this.getTopTableWithCards().getCards();
|
||||
}
|
||||
|
||||
// bottom shows player's choice - be it deck or draft
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#getBottom()
|
||||
*/
|
||||
/**
|
||||
* Gets the bottom.
|
||||
*
|
||||
* @return the bottom
|
||||
*/
|
||||
public final ItemPoolView<T> getBottom() {
|
||||
return this.getBottomTableWithCards().getCards();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the controller.
|
||||
*
|
||||
* @return the controller
|
||||
*/
|
||||
public abstract DeckController<TModel> getController();
|
||||
|
||||
// THIS IS HERE FOR OVERLOADING!!!1
|
||||
// or may be return abstract getFilter from derived class + this filter ...
|
||||
// virtual protected member, but later
|
||||
/**
|
||||
* Builds the filter.
|
||||
*
|
||||
* @return the predicate
|
||||
*/
|
||||
protected abstract Predicate<T> buildFilter();
|
||||
|
||||
/**
|
||||
* Show.
|
||||
*
|
||||
* @param exitCommand the exit command
|
||||
*/
|
||||
public abstract void show(final Command exitCommand);
|
||||
|
||||
/**
|
||||
* Analysis button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
final void analysisButtonActionPerformed(final ActionEvent e) {
|
||||
final ItemPoolView<CardPrinted> deck = ItemPool.createFrom(this.getBottomTableWithCards().getCards(),
|
||||
CardPrinted.class);
|
||||
if (deck.isEmpty()) {
|
||||
JOptionPane.showMessageDialog(null, "Cards in deck not found.", "Analysis Deck",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
} else {
|
||||
final DeckEditorBase<T, TModel> g = DeckEditorBase.this;
|
||||
final DeckAnalysis dAnalysis = new DeckAnalysis(g, deck);
|
||||
dAnalysis.setVisible(true);
|
||||
g.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckDisplay#setItems(forge.item.ItemPoolView,
|
||||
* forge.item.ItemPoolView, forge.game.GameType)
|
||||
*/
|
||||
/**
|
||||
* Update view.
|
||||
*/
|
||||
public abstract void updateView();
|
||||
|
||||
/**
|
||||
* Update display.
|
||||
*/
|
||||
public final void updateDisplay() {
|
||||
this.getTopTableWithCards().setFilter(this.buildFilter());
|
||||
}
|
||||
|
||||
/** The item listener updates display. */
|
||||
private ItemListener itemListenerUpdatesDisplay = new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(final ItemEvent e) {
|
||||
if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
|
||||
DeckEditorBase.this.updateDisplay();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is used for a feature: when you start typing card name, the
|
||||
* list gets auto-filtered.
|
||||
*/
|
||||
protected class OnChangeTextUpdateDisplay implements DocumentListener {
|
||||
private void onChange() {
|
||||
if (DeckEditorBase.this.isFiltersChangeFiringUpdate()) {
|
||||
DeckEditorBase.this.updateDisplay();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* javax.swing.event.DocumentListener#insertUpdate(javax.swing.event
|
||||
* .DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public final void insertUpdate(final DocumentEvent e) {
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* javax.swing.event.DocumentListener#removeUpdate(javax.swing.event
|
||||
* .DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public final void removeUpdate(final DocumentEvent e) {
|
||||
this.onChange();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* javax.swing.event.DocumentListener#changedUpdate(javax.swing.event
|
||||
* .DocumentEvent)
|
||||
*/
|
||||
@Override
|
||||
public void changedUpdate(final DocumentEvent e) {
|
||||
} // Happend only on ENTER pressed
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item listener updates display.
|
||||
*
|
||||
* @return the itemListenerUpdatesDisplay
|
||||
*/
|
||||
public ItemListener getItemListenerUpdatesDisplay() {
|
||||
return this.itemListenerUpdatesDisplay;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the item listener updates display.
|
||||
*
|
||||
* @param itemListenerUpdatesDisplay
|
||||
* the itemListenerUpdatesDisplay to set
|
||||
*/
|
||||
public void setItemListenerUpdatesDisplay(final ItemListener itemListenerUpdatesDisplay) {
|
||||
this.itemListenerUpdatesDisplay = itemListenerUpdatesDisplay; // TODO:
|
||||
// Add 0
|
||||
// to
|
||||
// parameter's
|
||||
// name.
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if is filters change firing update.
|
||||
*
|
||||
* @return the isFiltersChangeFiringUpdate
|
||||
*/
|
||||
public boolean isFiltersChangeFiringUpdate() {
|
||||
return this.isFiltersChangeFiringUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filters change firing update.
|
||||
*
|
||||
* @param isFiltersChangeFiringUpdate
|
||||
* the isFiltersChangeFiringUpdate to set
|
||||
*/
|
||||
public void setFiltersChangeFiringUpdate(final boolean isFiltersChangeFiringUpdate) {
|
||||
this.isFiltersChangeFiringUpdate = isFiltersChangeFiringUpdate; // TODO:
|
||||
// Add 0
|
||||
// to
|
||||
// parameter's
|
||||
// name.
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the card view.
|
||||
*
|
||||
* @return the cardView
|
||||
*/
|
||||
public CardPanelBase getCardView() {
|
||||
return this.cardView;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the card view.
|
||||
*
|
||||
* @param cardView0
|
||||
* the cardView to set
|
||||
*/
|
||||
protected void setCardView(final CardPanelBase cardView0) {
|
||||
this.cardView = cardView0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the filter boxes.
|
||||
*
|
||||
* @return the filterBoxes
|
||||
*/
|
||||
public FilterCheckBoxes getFilterBoxes() {
|
||||
return this.filterBoxes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filter boxes.
|
||||
*
|
||||
* @param filterBoxes0
|
||||
* the filterBoxes to set
|
||||
*/
|
||||
public void setFilterBoxes(final FilterCheckBoxes filterBoxes0) {
|
||||
this.filterBoxes = filterBoxes0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the bottom table with cards.
|
||||
*
|
||||
* @return the bottomTableWithCards
|
||||
*/
|
||||
public TableView<T> getBottomTableWithCards() {
|
||||
return this.bottomTableWithCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bottom table with cards.
|
||||
*
|
||||
* @param bottomTableWithCards0
|
||||
* the bottomTableWithCards to set
|
||||
*/
|
||||
public void setBottomTableWithCards(final TableView<T> bottomTableWithCards0) {
|
||||
this.bottomTableWithCards = bottomTableWithCards0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the top table with cards.
|
||||
*
|
||||
* @return the topTableWithCards
|
||||
*/
|
||||
public TableView<T> getTopTableWithCards() {
|
||||
return this.topTableWithCards;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the top table with cards.
|
||||
*
|
||||
* @param topTableWithCards0
|
||||
* the topTableWithCards to set
|
||||
*/
|
||||
public void setTopTableWithCards(final TableView<T> topTableWithCards0) {
|
||||
this.topTableWithCards = topTableWithCards0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.Dialog.ModalityType;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
@@ -30,12 +28,11 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
@@ -52,6 +49,7 @@ import forge.item.InventoryItem;
|
||||
import forge.item.ItemPool;
|
||||
import forge.util.Lambda0;
|
||||
import forge.util.Predicate;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -145,7 +143,6 @@ public final class DeckEditorConstructed extends DeckEditorBase<CardPrinted, Dec
|
||||
this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
|
||||
|
||||
this.setSize(1024, 740);
|
||||
this.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
|
||||
}
|
||||
|
||||
@@ -153,7 +150,8 @@ public final class DeckEditorConstructed extends DeckEditorBase<CardPrinted, Dec
|
||||
* Instantiates a new deck editor common.
|
||||
*
|
||||
*/
|
||||
public DeckEditorConstructed() {
|
||||
public DeckEditorConstructed(JFrame parent) {
|
||||
super(parent);
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Avaliable Cards", true, true, CardPrinted.class));
|
||||
|
||||
@@ -1,419 +1,419 @@
|
||||
/*
|
||||
* 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.gui.deckeditor;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.Font;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.deckeditor.elements.CardPanelHeavy;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.FilterNameTypeSetPanel;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.util.IStorage;
|
||||
import forge.util.Lambda0;
|
||||
import forge.util.Predicate;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $
|
||||
*/
|
||||
public final class DeckEditorLimited extends DeckEditorBase<CardPrinted, DeckGroup> {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code>. */
|
||||
private static final long serialVersionUID = 130339644136746796L;
|
||||
|
||||
private final JButton removeButton = new JButton();
|
||||
private final JButton addButton = new JButton();
|
||||
|
||||
private final JButton analysisButton = new JButton();
|
||||
private final JButton clearFilterButton = new JButton();
|
||||
|
||||
private final JLabel jLabelAnalysisGap = new JLabel("");
|
||||
private FilterNameTypeSetPanel filterNameTypeSet;
|
||||
|
||||
private final DeckController<DeckGroup> controller;
|
||||
|
||||
/**
|
||||
* Show.
|
||||
*
|
||||
* @param exitCommand
|
||||
* the exit command
|
||||
*/
|
||||
@Override
|
||||
public void show(final Command exitCommand) {
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = 5210924838133689758L;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorLimited.this.dispose();
|
||||
if (exitCommand != null) {
|
||||
exitCommand.execute();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final MenuLimited menu = new MenuLimited(this.getController(), exit);
|
||||
|
||||
this.setJMenuBar(menu);
|
||||
|
||||
// do not change this!!!!
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
menu.close();
|
||||
}
|
||||
});
|
||||
|
||||
this.setup();
|
||||
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
} // show(Command)
|
||||
|
||||
private void setup() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 60, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE,
|
||||
PresetColumns.FN_AI_STATUS_GET));
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
this.getBottomTableWithCards().setup(columns, this.getCardView());
|
||||
|
||||
this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
|
||||
|
||||
this.setSize(1024, 740);
|
||||
this.setExtendedState(Frame.MAXIMIZED_BOTH);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck editor common.
|
||||
*
|
||||
* @param deckMap the deck map
|
||||
*/
|
||||
public DeckEditorLimited(final IStorage<DeckGroup> deckMap) {
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Avaliable Cards", true, true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
final Lambda0<DeckGroup> newCreator = new Lambda0<DeckGroup>() {
|
||||
@Override
|
||||
public DeckGroup apply() {
|
||||
return new DeckGroup("");
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<DeckGroup>(deckMap, this, newCreator);
|
||||
}
|
||||
|
||||
private void jbInit() {
|
||||
|
||||
final Font fButtons = new java.awt.Font("Dialog", 0, 13);
|
||||
this.removeButton.setFont(fButtons);
|
||||
this.addButton.setFont(fButtons);
|
||||
this.clearFilterButton.setFont(fButtons);
|
||||
this.analysisButton.setFont(fButtons);
|
||||
|
||||
this.addButton.setText("Add to Deck");
|
||||
this.removeButton.setText("Remove from Deck");
|
||||
this.clearFilterButton.setText("Clear Filter");
|
||||
this.analysisButton.setText("Deck Analysis");
|
||||
|
||||
this.removeButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.removeButtonClicked(e);
|
||||
}
|
||||
});
|
||||
this.addButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.addButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.clearFilterButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.analysisButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.analysisButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
// Type filtering
|
||||
final Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
box.setFont(f);
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
// Color filtering
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
// Do not lower statsLabel any lower, we want this to be visible at 1024
|
||||
// x 768 screen size
|
||||
this.setTitle("Deck Editor");
|
||||
|
||||
final Container content = this.getContentPane();
|
||||
final MigLayout layout = new MigLayout("fill");
|
||||
content.setLayout(layout);
|
||||
|
||||
boolean isFirst = true;
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
String growParameter = "grow";
|
||||
if (isFirst) {
|
||||
growParameter = "cell 0 0, egx checkbox, grow, split 14";
|
||||
isFirst = false;
|
||||
}
|
||||
content.add(box, growParameter);
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
content.add(box, "grow");
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
|
||||
content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow");
|
||||
|
||||
content.add(this.filterNameTypeSet, "cell 0 1, grow");
|
||||
content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, pushy, grow");
|
||||
content.add(this.getTopTableWithCards().getLabel(), "cell 0 4");
|
||||
|
||||
content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5");
|
||||
content.add(this.removeButton, "w 100, h 49, sg button");
|
||||
// Label is used to push the analysis button to the right to separate
|
||||
// analysis button from add/remove card ones
|
||||
content.add(this.jLabelAnalysisGap, "wmin 75, growx");
|
||||
content.add(this.analysisButton, "w 100, h 49, wrap");
|
||||
|
||||
content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow");
|
||||
content.add(this.getBottomTableWithCards().getLabel(), "cell 0 7");
|
||||
|
||||
content.add(this.getCardView(), "cell 1 0 1 8, flowy, grow");
|
||||
|
||||
this.getTopTableWithCards().getTable().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
DeckEditorLimited.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
DeckEditorLimited.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// javax.swing.JRootPane rootPane = this.getRootPane();
|
||||
// rootPane.setDefaultButton(filterButton);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(),
|
||||
this.filterNameTypeSet.buildFilter());
|
||||
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear filter button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void clearFilterButtonActionPerformed(final ActionEvent e) {
|
||||
// disable automatic update triggered by listeners
|
||||
this.setFiltersChangeFiringUpdate(false);
|
||||
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
if (!box.isSelected()) {
|
||||
box.doClick();
|
||||
}
|
||||
}
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
if (!box.isSelected()) {
|
||||
box.doClick();
|
||||
}
|
||||
}
|
||||
|
||||
this.filterNameTypeSet.clearFilters();
|
||||
|
||||
this.setFiltersChangeFiringUpdate(true);
|
||||
|
||||
this.getTopTableWithCards().setFilter(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void addButtonActionPerformed(final ActionEvent e) {
|
||||
this.addCardToDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the card to deck.
|
||||
*/
|
||||
void addCardToDeck() {
|
||||
final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update view
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
|
||||
/*
|
||||
* update model Deck model =
|
||||
* getSelectedDeck(getController().getModel());
|
||||
* model.getMain().add(card); model.getSideboard().remove(card);
|
||||
*/
|
||||
|
||||
this.getController().notifyModelChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
private Deck getSelectedDeck(final DeckGroup model) {
|
||||
return model.getHumanDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the button clicked.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void removeButtonClicked(final ActionEvent e) {
|
||||
final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update view
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
|
||||
/*
|
||||
* update model Deck model =
|
||||
* getSelectedDeck(getController().getModel());
|
||||
* model.getMain().remove(card); model.getSideboard().add(card);
|
||||
*/
|
||||
|
||||
this.getController().notifyModelChanged();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
@Override
|
||||
public DeckController<DeckGroup> getController() {
|
||||
return this.controller;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
Deck toEdit = this.getSelectedDeck(this.controller.getModel());
|
||||
this.getTopTableWithCards().setDeck(toEdit.getSideboard());
|
||||
this.getBottomTableWithCards().setDeck(toEdit.getMain());
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* 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.gui.deckeditor;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.error.ErrorViewer;
|
||||
import forge.gui.deckeditor.elements.CardPanelHeavy;
|
||||
import forge.gui.deckeditor.elements.FilterCheckBoxes;
|
||||
import forge.gui.deckeditor.elements.FilterNameTypeSetPanel;
|
||||
import forge.gui.deckeditor.elements.ManaCostRenderer;
|
||||
import forge.gui.deckeditor.elements.TableColumnInfo;
|
||||
import forge.gui.deckeditor.elements.TableView;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.InventoryItem;
|
||||
import forge.util.IStorage;
|
||||
import forge.util.Lambda0;
|
||||
import forge.util.Predicate;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Gui_DeckEditor class.
|
||||
* </p>
|
||||
*
|
||||
* @author Forge
|
||||
* @version $Id: DeckEditorCommon.java 12850 2011-12-26 14:55:09Z slapshot5 $
|
||||
*/
|
||||
public final class DeckEditorLimited extends DeckEditorBase<CardPrinted, DeckGroup> {
|
||||
/** Constant <code>serialVersionUID=130339644136746796L</code>. */
|
||||
private static final long serialVersionUID = 130339644136746796L;
|
||||
|
||||
private final JButton removeButton = new JButton();
|
||||
private final JButton addButton = new JButton();
|
||||
|
||||
private final JButton analysisButton = new JButton();
|
||||
private final JButton clearFilterButton = new JButton();
|
||||
|
||||
private final JLabel jLabelAnalysisGap = new JLabel("");
|
||||
private FilterNameTypeSetPanel filterNameTypeSet;
|
||||
|
||||
private final DeckController<DeckGroup> controller;
|
||||
|
||||
/**
|
||||
* Show.
|
||||
*
|
||||
* @param exitCommand
|
||||
* the exit command
|
||||
*/
|
||||
@Override
|
||||
public void show(final Command exitCommand) {
|
||||
final Command exit = new Command() {
|
||||
private static final long serialVersionUID = 5210924838133689758L;
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
DeckEditorLimited.this.dispose();
|
||||
if (exitCommand != null) {
|
||||
exitCommand.execute();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
final MenuLimited menu = new MenuLimited(this.getController(), exit);
|
||||
|
||||
this.setJMenuBar(menu);
|
||||
|
||||
// do not change this!!!!
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent ev) {
|
||||
menu.close();
|
||||
}
|
||||
});
|
||||
|
||||
this.setup();
|
||||
|
||||
this.getTopTableWithCards().sort(1, true);
|
||||
this.getBottomTableWithCards().sort(1, true);
|
||||
|
||||
} // show(Command)
|
||||
|
||||
private void setup() {
|
||||
final List<TableColumnInfo<InventoryItem>> columns = new ArrayList<TableColumnInfo<InventoryItem>>();
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Qty", 30, PresetColumns.FN_QTY_COMPARE,
|
||||
PresetColumns.FN_QTY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Name", 175, PresetColumns.FN_NAME_COMPARE,
|
||||
PresetColumns.FN_NAME_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Cost", 75, PresetColumns.FN_COST_COMPARE,
|
||||
PresetColumns.FN_COST_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Color", 60, PresetColumns.FN_COLOR_COMPARE,
|
||||
PresetColumns.FN_COLOR_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Type", 100, PresetColumns.FN_TYPE_COMPARE,
|
||||
PresetColumns.FN_TYPE_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Stats", 60, PresetColumns.FN_STATS_COMPARE,
|
||||
PresetColumns.FN_STATS_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("R", 25, PresetColumns.FN_RARITY_COMPARE,
|
||||
PresetColumns.FN_RARITY_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("Set", 40, PresetColumns.FN_SET_COMPARE,
|
||||
PresetColumns.FN_SET_GET));
|
||||
columns.add(new TableColumnInfo<InventoryItem>("AI", 30, PresetColumns.FN_AI_STATUS_COMPARE,
|
||||
PresetColumns.FN_AI_STATUS_GET));
|
||||
columns.get(2).setCellRenderer(new ManaCostRenderer());
|
||||
|
||||
this.getTopTableWithCards().setup(columns, this.getCardView());
|
||||
this.getBottomTableWithCards().setup(columns, this.getCardView());
|
||||
|
||||
this.filterNameTypeSet.setListeners(new OnChangeTextUpdateDisplay(), this.getItemListenerUpdatesDisplay());
|
||||
|
||||
this.setSize(1024, 740);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new deck editor common.
|
||||
*
|
||||
* @param mainFrame
|
||||
* @param deckMap the deck map
|
||||
*/
|
||||
public DeckEditorLimited(JFrame mainFrame, final IStorage<DeckGroup> deckMap) {
|
||||
super(mainFrame);
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(true));
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Avaliable Cards", true, true, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Deck", true, CardPrinted.class));
|
||||
this.setCardView(new CardPanelHeavy());
|
||||
this.filterNameTypeSet = new FilterNameTypeSetPanel();
|
||||
|
||||
this.jbInit();
|
||||
} catch (final Exception ex) {
|
||||
ErrorViewer.showError(ex);
|
||||
}
|
||||
|
||||
final Lambda0<DeckGroup> newCreator = new Lambda0<DeckGroup>() {
|
||||
@Override
|
||||
public DeckGroup apply() {
|
||||
return new DeckGroup("");
|
||||
}
|
||||
};
|
||||
this.controller = new DeckController<DeckGroup>(deckMap, this, newCreator);
|
||||
}
|
||||
|
||||
private void jbInit() {
|
||||
|
||||
final Font fButtons = new java.awt.Font("Dialog", 0, 13);
|
||||
this.removeButton.setFont(fButtons);
|
||||
this.addButton.setFont(fButtons);
|
||||
this.clearFilterButton.setFont(fButtons);
|
||||
this.analysisButton.setFont(fButtons);
|
||||
|
||||
this.addButton.setText("Add to Deck");
|
||||
this.removeButton.setText("Remove from Deck");
|
||||
this.clearFilterButton.setText("Clear Filter");
|
||||
this.analysisButton.setText("Deck Analysis");
|
||||
|
||||
this.removeButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.removeButtonClicked(e);
|
||||
}
|
||||
});
|
||||
this.addButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.addButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.clearFilterButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.clearFilterButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
this.analysisButton.addActionListener(new java.awt.event.ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(final ActionEvent e) {
|
||||
DeckEditorLimited.this.analysisButtonActionPerformed(e);
|
||||
}
|
||||
});
|
||||
|
||||
// Type filtering
|
||||
final Font f = new Font("Tahoma", Font.PLAIN, 10);
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
box.setFont(f);
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
// Color filtering
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
box.setOpaque(false);
|
||||
}
|
||||
|
||||
// Do not lower statsLabel any lower, we want this to be visible at 1024
|
||||
// x 768 screen size
|
||||
this.setTitle("Deck Editor");
|
||||
|
||||
final Container content = this.getContentPane();
|
||||
final MigLayout layout = new MigLayout("fill");
|
||||
content.setLayout(layout);
|
||||
|
||||
boolean isFirst = true;
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
String growParameter = "grow";
|
||||
if (isFirst) {
|
||||
growParameter = "cell 0 0, egx checkbox, grow, split 14";
|
||||
isFirst = false;
|
||||
}
|
||||
content.add(box, growParameter);
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
content.add(box, "grow");
|
||||
box.addItemListener(this.getItemListenerUpdatesDisplay());
|
||||
}
|
||||
|
||||
content.add(this.clearFilterButton, "wmin 100, hmin 25, wmax 140, hmax 25, grow");
|
||||
|
||||
content.add(this.filterNameTypeSet, "cell 0 1, grow");
|
||||
content.add(this.getTopTableWithCards().getTableDecorated(), "cell 0 2 1 2, pushy, grow");
|
||||
content.add(this.getTopTableWithCards().getLabel(), "cell 0 4");
|
||||
|
||||
content.add(this.addButton, "w 100, h 49, sg button, cell 0 5, split 5");
|
||||
content.add(this.removeButton, "w 100, h 49, sg button");
|
||||
// Label is used to push the analysis button to the right to separate
|
||||
// analysis button from add/remove card ones
|
||||
content.add(this.jLabelAnalysisGap, "wmin 75, growx");
|
||||
content.add(this.analysisButton, "w 100, h 49, wrap");
|
||||
|
||||
content.add(this.getBottomTableWithCards().getTableDecorated(), "cell 0 6, grow");
|
||||
content.add(this.getBottomTableWithCards().getLabel(), "cell 0 7");
|
||||
|
||||
content.add(this.getCardView(), "cell 1 0 1 8, flowy, grow");
|
||||
|
||||
this.getTopTableWithCards().getTable().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
DeckEditorLimited.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.getTopTableWithCards().getTable().addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(final KeyEvent e) {
|
||||
if (e.getKeyChar() == ' ') {
|
||||
DeckEditorLimited.this.addCardToDeck();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// javax.swing.JRootPane rootPane = this.getRootPane();
|
||||
// rootPane.setDefaultButton(filterButton);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#buildFilter()
|
||||
*/
|
||||
@Override
|
||||
protected Predicate<CardPrinted> buildFilter() {
|
||||
final Predicate<CardPrinted> cardFilter = Predicate.and(this.getFilterBoxes().buildFilter(),
|
||||
this.filterNameTypeSet.buildFilter());
|
||||
return Predicate.instanceOf(cardFilter, CardPrinted.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear filter button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void clearFilterButtonActionPerformed(final ActionEvent e) {
|
||||
// disable automatic update triggered by listeners
|
||||
this.setFiltersChangeFiringUpdate(false);
|
||||
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllTypes()) {
|
||||
if (!box.isSelected()) {
|
||||
box.doClick();
|
||||
}
|
||||
}
|
||||
for (final JCheckBox box : this.getFilterBoxes().getAllColors()) {
|
||||
if (!box.isSelected()) {
|
||||
box.doClick();
|
||||
}
|
||||
}
|
||||
|
||||
this.filterNameTypeSet.clearFilters();
|
||||
|
||||
this.setFiltersChangeFiringUpdate(true);
|
||||
|
||||
this.getTopTableWithCards().setFilter(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the button_action performed.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void addButtonActionPerformed(final ActionEvent e) {
|
||||
this.addCardToDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the card to deck.
|
||||
*/
|
||||
void addCardToDeck() {
|
||||
final InventoryItem item = this.getTopTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update view
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().addCard(card);
|
||||
this.getTopTableWithCards().removeCard(card);
|
||||
|
||||
/*
|
||||
* update model Deck model =
|
||||
* getSelectedDeck(getController().getModel());
|
||||
* model.getMain().add(card); model.getSideboard().remove(card);
|
||||
*/
|
||||
|
||||
this.getController().notifyModelChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this method.
|
||||
*
|
||||
* @param model
|
||||
* @return
|
||||
*/
|
||||
private Deck getSelectedDeck(final DeckGroup model) {
|
||||
return model.getHumanDeck();
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the button clicked.
|
||||
*
|
||||
* @param e
|
||||
* the e
|
||||
*/
|
||||
void removeButtonClicked(final ActionEvent e) {
|
||||
final InventoryItem item = this.getBottomTableWithCards().getSelectedCard();
|
||||
if ((item == null) || !(item instanceof CardPrinted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// update view
|
||||
final CardPrinted card = (CardPrinted) item;
|
||||
this.getBottomTableWithCards().removeCard(card);
|
||||
this.getTopTableWithCards().addCard(card);
|
||||
|
||||
/*
|
||||
* update model Deck model =
|
||||
* getSelectedDeck(getController().getModel());
|
||||
* model.getMain().remove(card); model.getSideboard().add(card);
|
||||
*/
|
||||
|
||||
this.getController().notifyModelChanged();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#getController()
|
||||
*/
|
||||
@Override
|
||||
public DeckController<DeckGroup> getController() {
|
||||
return this.controller;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see forge.gui.deckeditor.DeckEditorBase#updateView()
|
||||
*/
|
||||
@Override
|
||||
public void updateView() {
|
||||
Deck toEdit = this.getSelectedDeck(this.controller.getModel());
|
||||
this.getTopTableWithCards().setDeck(toEdit.getSideboard());
|
||||
this.getBottomTableWithCards().setDeck(toEdit.getMain());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
package forge.gui.deckeditor;
|
||||
|
||||
// import java.awt.Font;
|
||||
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
@@ -27,9 +28,9 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JCheckBox;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
@@ -176,11 +177,12 @@ public final class DeckEditorQuest extends DeckEditorBase<CardPrinted, Deck> {
|
||||
/**
|
||||
* Instantiates a new deck editor quest.
|
||||
*
|
||||
* @param parent
|
||||
* @param questData2
|
||||
* the quest data2
|
||||
*/
|
||||
public DeckEditorQuest(final QuestController questData2) {
|
||||
|
||||
public DeckEditorQuest(JFrame parent, final QuestController questData2) {
|
||||
super(parent);
|
||||
this.questData = questData2;
|
||||
try {
|
||||
this.setFilterBoxes(new FilterCheckBoxes(false));
|
||||
|
||||
@@ -30,8 +30,8 @@ import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.WindowConstants;
|
||||
@@ -187,8 +187,8 @@ public class DraftingProcess extends DeckEditorBase<CardPrinted, DeckGroup> {
|
||||
/**
|
||||
* Instantiates a new deck editor draft.
|
||||
*/
|
||||
public DraftingProcess() {
|
||||
|
||||
public DraftingProcess(JFrame parent) {
|
||||
super(parent);
|
||||
try {
|
||||
this.setTopTableWithCards(new TableView<CardPrinted>("Choose one card", false, CardPrinted.class));
|
||||
this.setBottomTableWithCards(new TableView<CardPrinted>("Previously picked cards", true, CardPrinted.class));
|
||||
|
||||
@@ -28,8 +28,8 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
@@ -211,7 +211,8 @@ public final class QuestCardShop extends DeckEditorBase<InventoryItem, DeckBase>
|
||||
* @param qd
|
||||
* a {@link forge.quest.data.QuestData} object.
|
||||
*/
|
||||
public QuestCardShop(final QuestController qd) {
|
||||
public QuestCardShop(JFrame parent, final QuestController qd) {
|
||||
super(parent);
|
||||
this.questData = qd;
|
||||
try {
|
||||
this.setFilterBoxes(null);
|
||||
|
||||
@@ -28,11 +28,10 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JPanel;
|
||||
@@ -45,12 +44,12 @@ import javax.swing.border.BevelBorder;
|
||||
import javax.swing.event.MouseInputAdapter;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.card.CardRules;
|
||||
import forge.card.CardType;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPoolView;
|
||||
import forge.util.MyRandom;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
/**
|
||||
* This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
|
||||
@@ -111,7 +110,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
|
||||
private JSeparator jSeparator1;
|
||||
private JLabel jLabel2;
|
||||
private JButton jButtonOk;
|
||||
private final JFrame jF;
|
||||
private final JDialog parentDialog;
|
||||
|
||||
/** The deck. */
|
||||
private final ItemPoolView<CardPrinted> deck;
|
||||
@@ -126,11 +125,11 @@ public class DeckAnalysis extends javax.swing.JDialog {
|
||||
* @param deckView
|
||||
* the deck view
|
||||
*/
|
||||
public DeckAnalysis(final JFrame g, final ItemPoolView<CardPrinted> deckView) {
|
||||
public DeckAnalysis(final JDialog g, final ItemPoolView<CardPrinted> deckView) {
|
||||
super(g);
|
||||
this.deck = deckView;
|
||||
|
||||
this.jF = g;
|
||||
this.parentDialog = g;
|
||||
this.initGUI();
|
||||
}
|
||||
|
||||
@@ -160,7 +159,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
|
||||
this.addWindowListener(new WindowAdapter() {
|
||||
@Override
|
||||
public void windowClosing(final WindowEvent arg0) {
|
||||
DeckAnalysis.this.jF.setEnabled(true);
|
||||
DeckAnalysis.this.parentDialog.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -475,7 +474,7 @@ public class DeckAnalysis extends javax.swing.JDialog {
|
||||
this.jButtonOk.addMouseListener(new MouseInputAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
DeckAnalysis.this.jF.setEnabled(true);
|
||||
DeckAnalysis.this.parentDialog.setEnabled(true);
|
||||
DeckAnalysis.this.dispose();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,7 +74,8 @@ public enum CSubmenuQuestDecks implements ICSubmenu {
|
||||
VSubmenuQuestDecks.SINGLETON_INSTANCE.getBtnNewDeck().setCommand(new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
final DeckEditorQuest editor = new DeckEditorQuest(AllZone.getQuest());
|
||||
final DeckEditorQuest editor =
|
||||
new DeckEditorQuest(Singletons.getView().getFrame(), AllZone.getQuest());
|
||||
editor.show(cmdDeckExit);
|
||||
OverlayUtils.showOverlay();
|
||||
editor.setVisible(true);
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
package forge.gui.home.quest;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
@@ -16,9 +22,9 @@ import forge.gui.toolbox.FSkin;
|
||||
import forge.gui.toolbox.FTextArea;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import forge.quest.QuestEventChallenge;
|
||||
import forge.quest.QuestController;
|
||||
import forge.quest.QuestEvent;
|
||||
import forge.quest.QuestEventChallenge;
|
||||
import forge.quest.QuestMode;
|
||||
import forge.quest.QuestUtil;
|
||||
import forge.quest.bazaar.QuestItemType;
|
||||
@@ -29,13 +35,6 @@ import forge.quest.data.QuestPreferences.QPref;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
/**
|
||||
* Utilities for the quest submenu, all over the MVC spectrum.
|
||||
* If a piece of code can be reused, it's dumped here.
|
||||
@@ -186,7 +185,7 @@ public class SubmenuQuestUtil {
|
||||
}
|
||||
};
|
||||
|
||||
final QuestCardShop g = new QuestCardShop(AllZone.getQuest());
|
||||
final QuestCardShop g = new QuestCardShop(Singletons.getView().getFrame(), AllZone.getQuest());
|
||||
g.show(exit);
|
||||
g.setVisible(true);
|
||||
}
|
||||
|
||||
@@ -1,263 +1,262 @@
|
||||
package forge.gui.home.sanctioned;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.game.GameNew;
|
||||
import forge.game.GameType;
|
||||
import forge.game.limited.BoosterDraft;
|
||||
import forge.game.limited.CardPoolLimitation;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DraftingProcess;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public enum CSubmenuDraft implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final String[] opponentNames = new String[] {
|
||||
"Abigail", "Ada", "Adeline", "Adriana", "Agatha", "Agnes", "Aileen", "Alba", "Alcyon",
|
||||
"Alethea", "Alice", "Alicia", "Alison", "Amanda", "Amelia", "Amy", "Andrea", "Angelina",
|
||||
"Anita", "Ann", "Annabel", "Anne", "Audrey", "Barbara", "Belinda", "Bernice", "Bertha",
|
||||
"Bonnie", "Brenda", "Bridget", "Bunny", "Carmen", "Carol", "Catherine", "Cheryl",
|
||||
"Christine", "Cinderalla", "Claire", "Clarice", "Claudia", "Constance", "Cora",
|
||||
"Corinne", "Cnythia", "Daisy", "Daphne", "Dawn", "Deborah", "Diana", "Dolly", "Dora",
|
||||
"Doreen", "Doris", "Dorothy", "Eileen", "Elaine", "Elizabeth", "Emily", "Emma", "Ethel",
|
||||
"Evelyn", "Fiona", "Florence", "Frances", "Geraldine", "Gertrude", "Gladys", "Gloria",
|
||||
"Grace", "Greta", "Harriet", "Hazel", "Helen", "Hilda", "Ida", "Ingrid", "Irene",
|
||||
"Isabel", "Jacinta", "Jackie", "Jane", "Janet", "Janice", "Jennifer", "Jessie", "Joan",
|
||||
"Jocelyn", "Josephine", "Joyce", "Judith", "Julia", "Juliana", "Karina", "Kathleen",
|
||||
"Laura", "Lilian", "Lily", "Linda", "Lisa", "Lilita", "Lora", "Lorna", "Lucy", "Lydia",
|
||||
"Mabel", "Madeline", "Maggie", "Maria", "Mariam", "Marilyn", "Mary", "Matilda", "Mavis",
|
||||
"Melanie", "Melinda", "Melody", "Michelle", "Mildred", "Molly", "Mona", "Monica",
|
||||
"Nancy", "Nora", "Norma", "Olga", "Pamela", "Patricia", "Paula", "Pauline", "Pearl",
|
||||
"Peggy", "Penny", "Phoebe", "Phyllis", "Polly", "Priscilla", "Rachel", "Rebecca",
|
||||
"Rita", "Rosa", "Rosalind", "Rose", "Rosemary", "Rowena", "Ruby", "Sally", "Samantha",
|
||||
"Sarah", "Selina", "Sharon", "Sheila", "Shirley", "Sonya", "Stella", "Sue", "Susan",
|
||||
"Sylvia", "Tina", "Tracy", "Ursula", "Valentine", "Valerie", "Vanessa", "Veronica",
|
||||
"Victoria", "Violet", "Vivian", "Wendy", "Winnie", "Yvonne", "Aaron", "Abraham", "Adam",
|
||||
"Adrain", "Alain", "Alan", "Alban", "Albert", "Alec", "Alexander", "Alfonso", "Alfred",
|
||||
"Allan", "Allen", "Alonso", "Aloysius", "Alphonso", "Alvin", "Andrew", "Andy", "Amadeus",
|
||||
"Amselm", "Anthony", "Arnold", "Augusta", "Austin", "Barnaby", "Benedict", "Benjamin",
|
||||
"Bertie", "Bertram", "Bill", "Bob", "Boris", "Brady", "Brian", "Bruce", "Burt", "Byron",
|
||||
"Calvin", "Carl", "Carter", "Casey", "Cecil", "Charles", "Christian", "Christopher",
|
||||
"Clarence", "Clement", "Colin", "Conan", "Dalton", "Damian", "Daniel", "David", "Denis",
|
||||
"Derek", "Desmond", "Dick", "Dominic", "Donald", "Douglas", "Duncan", "Edmund",
|
||||
"Edward", "Ellen", "Elton", "Elvis", "Eric", "Eugene", "Felix", "Francis", "Frank",
|
||||
"Frederick", "Gary", "Geoffrey", "George", "Gerald", "Gerry", "Gordon", "Hamish",
|
||||
"Hardy", "Harold", "Harry", "Henry", "Herbert", "Ignatius", "Jack", "James", "Jeffrey",
|
||||
"Jim", "Joe", "John", "Joseph", "Karl", "Keith", "Kenneth", "Kevin", "Larry", "Lawrence",
|
||||
"Leonard", "Lionel", "Louis", "Lucas", "Malcolm", "Mark", "Martin", "Mathew", "Maurice",
|
||||
"Max", "Melvin", "Michael", "Milton", "Morgan", "Morris", "Murphy", "Neville",
|
||||
"Nicholas", "Noel", "Norman", "Oliver", "Oscar", "Patrick", "Paul", "Perkin", "Peter",
|
||||
"Philip", "Ralph", "Randy", "Raymond", "Richard", "Ricky", "Robert", "Robin", "Rodney",
|
||||
"Roger", "Roland", "Ronald", "Roy", "Sam", "Sebastian", "Simon", "Stanley", "Stephen",
|
||||
"Stuart", "Terence", "Thomas", "Tim", "Tom", "Tony", "Victor", "Vincent", "Wallace",
|
||||
"Walter", "Wilfred", "William", "Winston"
|
||||
};
|
||||
|
||||
private final Command cmdDeckExit = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
update();
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
private final Command cmdDeckSelect = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
final VSubmenuDraft view = VSubmenuDraft.SINGLETON_INSTANCE;
|
||||
|
||||
view.populate();
|
||||
CSubmenuDraft.SINGLETON_INSTANCE.update();
|
||||
|
||||
view.getLstHumanDecks().setExitCommand(cmdDeckExit);
|
||||
view.getLstHumanDecks().setSelectCommand(cmdDeckSelect);
|
||||
|
||||
view.getBtnBuildDeck().addMouseListener(
|
||||
new MouseAdapter() { @Override
|
||||
public void mousePressed(MouseEvent e) { setupDraft(); } });
|
||||
|
||||
view.getBtnStart().addMouseListener(
|
||||
new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startGame();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
view.getBtnDirections().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
view.showDirections();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
view.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_HOVER));
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
view.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().setListData(generateNames());
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().setSelectedIndex(
|
||||
(int) Math.floor(Math.random() * VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().getModel().getSize()));
|
||||
|
||||
List<Deck> human = new ArrayList<Deck>();
|
||||
for (DeckGroup d : Singletons.getModel().getDecks().getDraft()) {
|
||||
human.add(d.getHumanDeck());
|
||||
}
|
||||
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getLstHumanDecks().setDecks(human);
|
||||
|
||||
if (human.size() > 1) {
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void startGame() {
|
||||
final Deck human = VSubmenuDraft.SINGLETON_INSTANCE.getLstHumanDecks().getSelectedDeck();
|
||||
final int aiIndex = VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().getSelectedIndex();
|
||||
|
||||
if (human == null) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"No deck selected for human!\r\n(You may need to build a new deck.)",
|
||||
"No deck", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
else if (human.getMain().countAll() < 40) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"The selected deck doesn't have enough cards to play (minimum 40)."
|
||||
+ "\r\nUse the deck editor to choose the cards you want before starting.",
|
||||
"No deck", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
OverlayUtils.startGameOverlay();
|
||||
OverlayUtils.showOverlay();
|
||||
}
|
||||
});
|
||||
|
||||
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
|
||||
@Override
|
||||
public Object doInBackground() {
|
||||
DeckGroup opponentDecks = Singletons.getModel().getDecks().getDraft().get(human.getName());
|
||||
|
||||
Constant.Runtime.HUMAN_DECK[0] = human;
|
||||
Constant.Runtime.COMPUTER_DECK[0] = opponentDecks.getAiDecks().get(aiIndex); //zero is human deck, so it must be +1
|
||||
|
||||
if (Constant.Runtime.COMPUTER_DECK[0] == null) {
|
||||
throw new IllegalStateException("Draft: Computer deck is null!");
|
||||
}
|
||||
|
||||
Constant.Runtime.setGameType(GameType.Draft);
|
||||
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
/** */
|
||||
private void setupDraft() {
|
||||
OverlayUtils.showOverlay();
|
||||
|
||||
final DraftingProcess draft = new DraftingProcess();
|
||||
|
||||
// Determine what kind of booster draft to run
|
||||
final ArrayList<String> draftTypes = new ArrayList<String>();
|
||||
draftTypes.add("Full Cardpool");
|
||||
draftTypes.add("Block / Set");
|
||||
draftTypes.add("Custom");
|
||||
|
||||
final String prompt = "Choose Draft Format:";
|
||||
final Object o = GuiUtils.chooseOne(prompt, draftTypes.toArray());
|
||||
|
||||
if (o.toString().equals(draftTypes.get(0))) {
|
||||
draft.showGui(new BoosterDraft(CardPoolLimitation.Full));
|
||||
}
|
||||
|
||||
else if (o.toString().equals(draftTypes.get(1))) {
|
||||
draft.showGui(new BoosterDraft(CardPoolLimitation.Block));
|
||||
}
|
||||
|
||||
else if (o.toString().equals(draftTypes.get(2))) {
|
||||
draft.showGui(new BoosterDraft(CardPoolLimitation.Custom));
|
||||
}
|
||||
}
|
||||
|
||||
private String[] generateNames() {
|
||||
// Generate random selection of names for display
|
||||
Random generator = new Random();
|
||||
int i = opponentNames.length;
|
||||
String[] ai = {
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)]
|
||||
};
|
||||
|
||||
return ai;
|
||||
}
|
||||
}
|
||||
package forge.gui.home.sanctioned;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.game.GameNew;
|
||||
import forge.game.GameType;
|
||||
import forge.game.limited.BoosterDraft;
|
||||
import forge.game.limited.CardPoolLimitation;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DraftingProcess;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public enum CSubmenuDraft implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private final String[] opponentNames = new String[] {
|
||||
"Abigail", "Ada", "Adeline", "Adriana", "Agatha", "Agnes", "Aileen", "Alba", "Alcyon",
|
||||
"Alethea", "Alice", "Alicia", "Alison", "Amanda", "Amelia", "Amy", "Andrea", "Angelina",
|
||||
"Anita", "Ann", "Annabel", "Anne", "Audrey", "Barbara", "Belinda", "Bernice", "Bertha",
|
||||
"Bonnie", "Brenda", "Bridget", "Bunny", "Carmen", "Carol", "Catherine", "Cheryl",
|
||||
"Christine", "Cinderalla", "Claire", "Clarice", "Claudia", "Constance", "Cora",
|
||||
"Corinne", "Cnythia", "Daisy", "Daphne", "Dawn", "Deborah", "Diana", "Dolly", "Dora",
|
||||
"Doreen", "Doris", "Dorothy", "Eileen", "Elaine", "Elizabeth", "Emily", "Emma", "Ethel",
|
||||
"Evelyn", "Fiona", "Florence", "Frances", "Geraldine", "Gertrude", "Gladys", "Gloria",
|
||||
"Grace", "Greta", "Harriet", "Hazel", "Helen", "Hilda", "Ida", "Ingrid", "Irene",
|
||||
"Isabel", "Jacinta", "Jackie", "Jane", "Janet", "Janice", "Jennifer", "Jessie", "Joan",
|
||||
"Jocelyn", "Josephine", "Joyce", "Judith", "Julia", "Juliana", "Karina", "Kathleen",
|
||||
"Laura", "Lilian", "Lily", "Linda", "Lisa", "Lilita", "Lora", "Lorna", "Lucy", "Lydia",
|
||||
"Mabel", "Madeline", "Maggie", "Maria", "Mariam", "Marilyn", "Mary", "Matilda", "Mavis",
|
||||
"Melanie", "Melinda", "Melody", "Michelle", "Mildred", "Molly", "Mona", "Monica",
|
||||
"Nancy", "Nora", "Norma", "Olga", "Pamela", "Patricia", "Paula", "Pauline", "Pearl",
|
||||
"Peggy", "Penny", "Phoebe", "Phyllis", "Polly", "Priscilla", "Rachel", "Rebecca",
|
||||
"Rita", "Rosa", "Rosalind", "Rose", "Rosemary", "Rowena", "Ruby", "Sally", "Samantha",
|
||||
"Sarah", "Selina", "Sharon", "Sheila", "Shirley", "Sonya", "Stella", "Sue", "Susan",
|
||||
"Sylvia", "Tina", "Tracy", "Ursula", "Valentine", "Valerie", "Vanessa", "Veronica",
|
||||
"Victoria", "Violet", "Vivian", "Wendy", "Winnie", "Yvonne", "Aaron", "Abraham", "Adam",
|
||||
"Adrain", "Alain", "Alan", "Alban", "Albert", "Alec", "Alexander", "Alfonso", "Alfred",
|
||||
"Allan", "Allen", "Alonso", "Aloysius", "Alphonso", "Alvin", "Andrew", "Andy", "Amadeus",
|
||||
"Amselm", "Anthony", "Arnold", "Augusta", "Austin", "Barnaby", "Benedict", "Benjamin",
|
||||
"Bertie", "Bertram", "Bill", "Bob", "Boris", "Brady", "Brian", "Bruce", "Burt", "Byron",
|
||||
"Calvin", "Carl", "Carter", "Casey", "Cecil", "Charles", "Christian", "Christopher",
|
||||
"Clarence", "Clement", "Colin", "Conan", "Dalton", "Damian", "Daniel", "David", "Denis",
|
||||
"Derek", "Desmond", "Dick", "Dominic", "Donald", "Douglas", "Duncan", "Edmund",
|
||||
"Edward", "Ellen", "Elton", "Elvis", "Eric", "Eugene", "Felix", "Francis", "Frank",
|
||||
"Frederick", "Gary", "Geoffrey", "George", "Gerald", "Gerry", "Gordon", "Hamish",
|
||||
"Hardy", "Harold", "Harry", "Henry", "Herbert", "Ignatius", "Jack", "James", "Jeffrey",
|
||||
"Jim", "Joe", "John", "Joseph", "Karl", "Keith", "Kenneth", "Kevin", "Larry", "Lawrence",
|
||||
"Leonard", "Lionel", "Louis", "Lucas", "Malcolm", "Mark", "Martin", "Mathew", "Maurice",
|
||||
"Max", "Melvin", "Michael", "Milton", "Morgan", "Morris", "Murphy", "Neville",
|
||||
"Nicholas", "Noel", "Norman", "Oliver", "Oscar", "Patrick", "Paul", "Perkin", "Peter",
|
||||
"Philip", "Ralph", "Randy", "Raymond", "Richard", "Ricky", "Robert", "Robin", "Rodney",
|
||||
"Roger", "Roland", "Ronald", "Roy", "Sam", "Sebastian", "Simon", "Stanley", "Stephen",
|
||||
"Stuart", "Terence", "Thomas", "Tim", "Tom", "Tony", "Victor", "Vincent", "Wallace",
|
||||
"Walter", "Wilfred", "William", "Winston"
|
||||
};
|
||||
|
||||
private final Command cmdDeckExit = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
update();
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
private final Command cmdDeckSelect = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
final VSubmenuDraft view = VSubmenuDraft.SINGLETON_INSTANCE;
|
||||
|
||||
view.populate();
|
||||
CSubmenuDraft.SINGLETON_INSTANCE.update();
|
||||
|
||||
view.getLstHumanDecks().setExitCommand(cmdDeckExit);
|
||||
view.getLstHumanDecks().setSelectCommand(cmdDeckSelect);
|
||||
|
||||
view.getBtnBuildDeck().addMouseListener(
|
||||
new MouseAdapter() { @Override
|
||||
public void mousePressed(MouseEvent e) { setupDraft(); } });
|
||||
|
||||
view.getBtnStart().addMouseListener(
|
||||
new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startGame();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
view.getBtnDirections().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
view.showDirections();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
view.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_HOVER));
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
view.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().setListData(generateNames());
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().setSelectedIndex(
|
||||
(int) Math.floor(Math.random() * VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().getModel().getSize()));
|
||||
|
||||
List<Deck> human = new ArrayList<Deck>();
|
||||
for (DeckGroup d : Singletons.getModel().getDecks().getDraft()) {
|
||||
human.add(d.getHumanDeck());
|
||||
}
|
||||
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getLstHumanDecks().setDecks(human);
|
||||
|
||||
if (human.size() > 1) {
|
||||
VSubmenuDraft.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void startGame() {
|
||||
final Deck human = VSubmenuDraft.SINGLETON_INSTANCE.getLstHumanDecks().getSelectedDeck();
|
||||
final int aiIndex = VSubmenuDraft.SINGLETON_INSTANCE.getLstAIDecks().getSelectedIndex();
|
||||
|
||||
if (human == null) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"No deck selected for human!\r\n(You may need to build a new deck.)",
|
||||
"No deck", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
else if (human.getMain().countAll() < 40) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"The selected deck doesn't have enough cards to play (minimum 40)."
|
||||
+ "\r\nUse the deck editor to choose the cards you want before starting.",
|
||||
"No deck", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
OverlayUtils.startGameOverlay();
|
||||
OverlayUtils.showOverlay();
|
||||
}
|
||||
});
|
||||
|
||||
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
|
||||
@Override
|
||||
public Object doInBackground() {
|
||||
DeckGroup opponentDecks = Singletons.getModel().getDecks().getDraft().get(human.getName());
|
||||
|
||||
Constant.Runtime.HUMAN_DECK[0] = human;
|
||||
Constant.Runtime.COMPUTER_DECK[0] = opponentDecks.getAiDecks().get(aiIndex); //zero is human deck, so it must be +1
|
||||
|
||||
if (Constant.Runtime.COMPUTER_DECK[0] == null) {
|
||||
throw new IllegalStateException("Draft: Computer deck is null!");
|
||||
}
|
||||
|
||||
Constant.Runtime.setGameType(GameType.Draft);
|
||||
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
/** */
|
||||
private void setupDraft() {
|
||||
OverlayUtils.showOverlay();
|
||||
|
||||
final DraftingProcess draft = new DraftingProcess(Singletons.getView().getFrame());
|
||||
|
||||
// Determine what kind of booster draft to run
|
||||
final ArrayList<String> draftTypes = new ArrayList<String>();
|
||||
draftTypes.add("Full Cardpool");
|
||||
draftTypes.add("Block / Set");
|
||||
draftTypes.add("Custom");
|
||||
|
||||
final String prompt = "Choose Draft Format:";
|
||||
final Object o = GuiUtils.chooseOne(prompt, draftTypes.toArray());
|
||||
|
||||
if (o.toString().equals(draftTypes.get(0))) {
|
||||
draft.showGui(new BoosterDraft(CardPoolLimitation.Full));
|
||||
}
|
||||
|
||||
else if (o.toString().equals(draftTypes.get(1))) {
|
||||
draft.showGui(new BoosterDraft(CardPoolLimitation.Block));
|
||||
}
|
||||
|
||||
else if (o.toString().equals(draftTypes.get(2))) {
|
||||
draft.showGui(new BoosterDraft(CardPoolLimitation.Custom));
|
||||
}
|
||||
}
|
||||
|
||||
private String[] generateNames() {
|
||||
// Generate random selection of names for display
|
||||
Random generator = new Random();
|
||||
int i = opponentNames.length;
|
||||
String[] ai = {
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)],
|
||||
opponentNames[generator.nextInt(i)]
|
||||
};
|
||||
|
||||
return ai;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,237 +1,235 @@
|
||||
package forge.gui.home.sanctioned;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import net.slightlymagic.braids.util.UtilFunctions;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.game.GameNew;
|
||||
import forge.game.limited.SealedDeck;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DeckEditorBase;
|
||||
import forge.gui.deckeditor.DeckEditorLimited;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public enum CSubmenuSealed implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private Map<String, Deck> aiDecks;
|
||||
|
||||
private final Command cmdExit = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
update();
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
private final Command cmdDeckSelect = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
final VSubmenuSealed view = VSubmenuSealed.SINGLETON_INSTANCE;
|
||||
|
||||
view.populate();
|
||||
CSubmenuSealed.SINGLETON_INSTANCE.update();
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setExitCommand(cmdExit);
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setSelectCommand(cmdDeckSelect);
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnBuildDeck().addMouseListener(
|
||||
new MouseAdapter() { @Override
|
||||
public void mousePressed(final MouseEvent e) { setupSealed(); } });
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnStart().addMouseListener(
|
||||
new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startGame();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnDirections().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.showDirections();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_HOVER));
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
final List<Deck> humanDecks = new ArrayList<Deck>();
|
||||
aiDecks = new HashMap<String, Deck>();
|
||||
|
||||
// Since AI decks are tied directly to the human choice,
|
||||
// they're just mapped in a parallel map and grabbed when the game starts.
|
||||
for (final DeckGroup d : Singletons.getModel().getDecks().getSealed()) {
|
||||
aiDecks.put(d.getName(), d.getAiDecks().get(0));
|
||||
humanDecks.add(d.getHumanDeck());
|
||||
}
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setDecks(humanDecks);
|
||||
}
|
||||
|
||||
private void startGame() {
|
||||
final Deck human = VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().getSelectedDeck();
|
||||
|
||||
if (human == null) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Please build and/or select a deck for yourself.",
|
||||
"No deck", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
OverlayUtils.startGameOverlay();
|
||||
OverlayUtils.showOverlay();
|
||||
}
|
||||
});
|
||||
|
||||
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
|
||||
@Override
|
||||
public Object doInBackground() {
|
||||
Constant.Runtime.HUMAN_DECK[0] = human;
|
||||
Constant.Runtime.COMPUTER_DECK[0] = Singletons.getModel().getDecks().getSealed().get(human.getName()).getAiDecks().get(0);
|
||||
|
||||
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
/** */
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends DeckBase> void setupSealed() {
|
||||
final ArrayList<String> sealedTypes = new ArrayList<String>();
|
||||
sealedTypes.add("Full Cardpool");
|
||||
sealedTypes.add("Block / Set");
|
||||
sealedTypes.add("Custom");
|
||||
|
||||
final String prompt = "Choose Sealed Deck Format:";
|
||||
final Object o = GuiUtils.chooseOne(prompt, sealedTypes.toArray());
|
||||
|
||||
SealedDeck sd = null;
|
||||
|
||||
if (o.toString().equals(sealedTypes.get(0))) {
|
||||
sd = new SealedDeck("Full");
|
||||
}
|
||||
|
||||
else if (o.toString().equals(sealedTypes.get(1))) {
|
||||
sd = new SealedDeck("Block");
|
||||
}
|
||||
|
||||
else if (o.toString().equals(sealedTypes.get(2))) {
|
||||
sd = new SealedDeck("Custom");
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("choice <<" + UtilFunctions.safeToString(o)
|
||||
+ ">> does not equal any of the sealedTypes.");
|
||||
}
|
||||
|
||||
if (sd.getCardpool().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String sDeckName = JOptionPane.showInputDialog(null,
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_MSG),
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_TTL),
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
if (StringUtils.isBlank(sDeckName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// May check for name uniqueness here
|
||||
|
||||
final ItemPool<CardPrinted> sDeck = sd.getCardpool();
|
||||
|
||||
final Deck deck = new Deck(sDeckName);
|
||||
deck.getSideboard().addAll(sDeck);
|
||||
|
||||
for (final String element : Constant.Color.BASIC_LANDS) {
|
||||
deck.getSideboard().add(element, sd.getLandSetCode()[0], 18);
|
||||
}
|
||||
|
||||
final DeckGroup sealed = new DeckGroup(sDeckName);
|
||||
sealed.setHumanDeck(deck);
|
||||
sealed.addAiDeck(sd.buildAIDeck(sDeck.toForgeCardList()));
|
||||
Singletons.getModel().getDecks().getSealed().add(sealed);
|
||||
|
||||
final DeckEditorBase<?, T> editor = (DeckEditorBase<?, T>)
|
||||
new DeckEditorLimited(Singletons.getModel().getDecks().getSealed());
|
||||
|
||||
editor.show(cmdExit);
|
||||
editor.getController().setModel((T) sealed);
|
||||
editor.setAlwaysOnTop(true);
|
||||
editor.setVisible(true);
|
||||
}
|
||||
}
|
||||
package forge.gui.home.sanctioned;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.SwingWorker;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.game.GameNew;
|
||||
import forge.game.limited.SealedDeck;
|
||||
import forge.gui.GuiUtils;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DeckEditorBase;
|
||||
import forge.gui.deckeditor.DeckEditorLimited;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
import forge.gui.toolbox.FSkin;
|
||||
import forge.item.CardPrinted;
|
||||
import forge.item.ItemPool;
|
||||
import forge.properties.ForgeProps;
|
||||
import forge.properties.NewConstants;
|
||||
import net.slightlymagic.braids.util.UtilFunctions;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public enum CSubmenuSealed implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
private Map<String, Deck> aiDecks;
|
||||
|
||||
private final Command cmdExit = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
update();
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
|
||||
private final Command cmdDeckSelect = new Command() {
|
||||
@Override
|
||||
public void execute() {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnStart().setEnabled(true);
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
final VSubmenuSealed view = VSubmenuSealed.SINGLETON_INSTANCE;
|
||||
|
||||
view.populate();
|
||||
CSubmenuSealed.SINGLETON_INSTANCE.update();
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setExitCommand(cmdExit);
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setSelectCommand(cmdDeckSelect);
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnBuildDeck().addMouseListener(
|
||||
new MouseAdapter() { @Override
|
||||
public void mousePressed(final MouseEvent e) { setupSealed(); } });
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnStart().addMouseListener(
|
||||
new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseReleased(final MouseEvent e) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
startGame();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnDirections().addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.showDirections();
|
||||
}
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_HOVER));
|
||||
}
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getBtnDirections().setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() {
|
||||
final List<Deck> humanDecks = new ArrayList<Deck>();
|
||||
aiDecks = new HashMap<String, Deck>();
|
||||
|
||||
// Since AI decks are tied directly to the human choice,
|
||||
// they're just mapped in a parallel map and grabbed when the game starts.
|
||||
for (final DeckGroup d : Singletons.getModel().getDecks().getSealed()) {
|
||||
aiDecks.put(d.getName(), d.getAiDecks().get(0));
|
||||
humanDecks.add(d.getHumanDeck());
|
||||
}
|
||||
|
||||
VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().setDecks(humanDecks);
|
||||
}
|
||||
|
||||
private void startGame() {
|
||||
final Deck human = VSubmenuSealed.SINGLETON_INSTANCE.getLstDecks().getSelectedDeck();
|
||||
|
||||
if (human == null) {
|
||||
JOptionPane.showMessageDialog(null,
|
||||
"Please build and/or select a deck for yourself.",
|
||||
"No deck", JOptionPane.ERROR_MESSAGE);
|
||||
return;
|
||||
}
|
||||
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
OverlayUtils.startGameOverlay();
|
||||
OverlayUtils.showOverlay();
|
||||
}
|
||||
});
|
||||
|
||||
final SwingWorker<Object, Void> worker = new SwingWorker<Object, Void>() {
|
||||
@Override
|
||||
public Object doInBackground() {
|
||||
Constant.Runtime.HUMAN_DECK[0] = human;
|
||||
Constant.Runtime.COMPUTER_DECK[0] = Singletons.getModel().getDecks().getSealed().get(human.getName()).getAiDecks().get(0);
|
||||
|
||||
GameNew.newGame(Constant.Runtime.HUMAN_DECK[0], Constant.Runtime.COMPUTER_DECK[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
OverlayUtils.hideOverlay();
|
||||
}
|
||||
};
|
||||
worker.execute();
|
||||
}
|
||||
|
||||
/** */
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends DeckBase> void setupSealed() {
|
||||
final ArrayList<String> sealedTypes = new ArrayList<String>();
|
||||
sealedTypes.add("Full Cardpool");
|
||||
sealedTypes.add("Block / Set");
|
||||
sealedTypes.add("Custom");
|
||||
|
||||
final String prompt = "Choose Sealed Deck Format:";
|
||||
final Object o = GuiUtils.chooseOne(prompt, sealedTypes.toArray());
|
||||
|
||||
SealedDeck sd = null;
|
||||
|
||||
if (o.toString().equals(sealedTypes.get(0))) {
|
||||
sd = new SealedDeck("Full");
|
||||
}
|
||||
|
||||
else if (o.toString().equals(sealedTypes.get(1))) {
|
||||
sd = new SealedDeck("Block");
|
||||
}
|
||||
|
||||
else if (o.toString().equals(sealedTypes.get(2))) {
|
||||
sd = new SealedDeck("Custom");
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("choice <<" + UtilFunctions.safeToString(o)
|
||||
+ ">> does not equal any of the sealedTypes.");
|
||||
}
|
||||
|
||||
if (sd.getCardpool().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String sDeckName = JOptionPane.showInputDialog(null,
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_MSG),
|
||||
ForgeProps.getLocalized(NewConstants.Lang.OldGuiNewGame.NewGameText.SAVE_SEALED_TTL),
|
||||
JOptionPane.QUESTION_MESSAGE);
|
||||
|
||||
if (StringUtils.isBlank(sDeckName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// May check for name uniqueness here
|
||||
|
||||
final ItemPool<CardPrinted> sDeck = sd.getCardpool();
|
||||
|
||||
final Deck deck = new Deck(sDeckName);
|
||||
deck.getSideboard().addAll(sDeck);
|
||||
|
||||
for (final String element : Constant.Color.BASIC_LANDS) {
|
||||
deck.getSideboard().add(element, sd.getLandSetCode()[0], 18);
|
||||
}
|
||||
|
||||
final DeckGroup sealed = new DeckGroup(sDeckName);
|
||||
sealed.setHumanDeck(deck);
|
||||
sealed.addAiDeck(sd.buildAIDeck(sDeck.toForgeCardList()));
|
||||
Singletons.getModel().getDecks().getSealed().add(sealed);
|
||||
|
||||
final DeckEditorBase<?, T> editor = (DeckEditorBase<?, T>) new DeckEditorLimited(
|
||||
Singletons.getView().getFrame(),
|
||||
Singletons.getModel().getDecks().getSealed());
|
||||
|
||||
editor.show(cmdExit);
|
||||
editor.getController().setModel((T) sealed);
|
||||
editor.setAlwaysOnTop(true);
|
||||
editor.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,52 +1,54 @@
|
||||
package forge.gui.home.utilities;
|
||||
|
||||
import forge.Command;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.DeckEditorBase;
|
||||
import forge.gui.deckeditor.DeckEditorConstructed;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public enum CSubmenuDeckEditor implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
VSubmenuDeckEditor.SINGLETON_INSTANCE.populate();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return new Command() { @Override
|
||||
public void execute() { showDeckEditor(); } };
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() { }
|
||||
|
||||
/**
|
||||
* Shows constructed mode editor.
|
||||
* @param <T> extends DeckBase
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends DeckBase> void showDeckEditor() {
|
||||
DeckEditorBase<?, T> editor = (DeckEditorBase<?, T>) new DeckEditorConstructed();
|
||||
editor.show(null);
|
||||
editor.setVisible(true);
|
||||
}
|
||||
}
|
||||
package forge.gui.home.utilities;
|
||||
|
||||
import forge.Command;
|
||||
import forge.Singletons;
|
||||
import forge.deck.DeckBase;
|
||||
import forge.gui.deckeditor.DeckEditorBase;
|
||||
import forge.gui.deckeditor.DeckEditorConstructed;
|
||||
import forge.gui.home.ICSubmenu;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public enum CSubmenuDeckEditor implements ICSubmenu {
|
||||
/** */
|
||||
SINGLETON_INSTANCE;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void initialize() {
|
||||
VSubmenuDeckEditor.SINGLETON_INSTANCE.populate();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#getCommand()
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
@Override
|
||||
public Command getMenuCommand() {
|
||||
return new Command() { @Override
|
||||
public void execute() { showDeckEditor(); } };
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.control.home.IControlSubmenu#update()
|
||||
*/
|
||||
@Override
|
||||
public void update() { }
|
||||
|
||||
/**
|
||||
* Shows constructed mode editor.
|
||||
* @param <T> extends DeckBase
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
private <T extends DeckBase> void showDeckEditor() {
|
||||
DeckEditorBase<?, T> editor =
|
||||
(DeckEditorBase<?, T>) new DeckEditorConstructed(Singletons.getView().getFrame());
|
||||
editor.show(null);
|
||||
editor.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,492 +1,492 @@
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* 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.gui.toolbox;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.MatteBorder;
|
||||
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.CardCollections;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DeckEditorConstructed;
|
||||
import forge.gui.deckeditor.DeckEditorLimited;
|
||||
import forge.gui.deckeditor.DeckEditorQuest;
|
||||
|
||||
/**
|
||||
* Creates deck list for selected decks for quick deleting, editing, and basic
|
||||
* info.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DeckLister extends JPanel {
|
||||
private final ImageIcon icoDelete;
|
||||
private final ImageIcon icoDeleteOver;
|
||||
private final ImageIcon icoEdit;
|
||||
private final ImageIcon icoEditOver;
|
||||
private RowPanel previousSelect;
|
||||
private RowPanel[] rows;
|
||||
private final GameType gametype;
|
||||
private Command cmdEditorExit, cmdDelete, cmdRowSelect;
|
||||
private final Color clrDefault, clrHover, clrActive, clrBorders;
|
||||
|
||||
/**
|
||||
* Creates deck list for selected decks for quick deleting, editing, and
|
||||
* basic info. "selectable" and "editable" assumed true.
|
||||
*
|
||||
* @param gt0 the gt0
|
||||
* {@link forge.game.GameType}
|
||||
*/
|
||||
public DeckLister(final GameType gt0) {
|
||||
this(gt0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates deck list for selected decks for quick deleting, editing, and
|
||||
* basic info. Set "selectable" and "editable" to show those buttons, or
|
||||
* not.
|
||||
*
|
||||
* @param gt0 the gt0
|
||||
* @param cmd0 the cmd0
|
||||
* {@link forge.game.GameType}
|
||||
* {@link forge.Command}, when exiting deck editor
|
||||
*/
|
||||
public DeckLister(final GameType gt0, final Command cmd0) {
|
||||
super();
|
||||
this.gametype = gt0;
|
||||
this.cmdEditorExit = cmd0;
|
||||
|
||||
this.clrDefault = new Color(0, 0, 0, 0);
|
||||
this.clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER);
|
||||
this.clrActive = FSkin.getColor(FSkin.Colors.CLR_ACTIVE);
|
||||
this.clrBorders = FSkin.getColor(FSkin.Colors.CLR_BORDERS);
|
||||
|
||||
this.setOpaque(false);
|
||||
this.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
||||
|
||||
this.icoDelete = FSkin.getIcon(FSkin.ForgeIcons.ICO_DELETE);
|
||||
this.icoDeleteOver = FSkin.getIcon(FSkin.ForgeIcons.ICO_DELETE_OVER);
|
||||
this.icoEdit = FSkin.getIcon(FSkin.ForgeIcons.ICO_EDIT);
|
||||
this.icoEditOver = FSkin.getIcon(FSkin.ForgeIcons.ICO_EDIT_OVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the decks.
|
||||
*
|
||||
* @param decks0 the new decks
|
||||
* {@link forge.deck.Deck}[]
|
||||
*/
|
||||
public void setDecks(final Iterable<Deck> decks0) {
|
||||
this.removeAll();
|
||||
final List<RowPanel> tempRows = new ArrayList<RowPanel>();
|
||||
|
||||
// Title row
|
||||
// Note: careful with the widths of the rows here;
|
||||
// scroll panes will have difficulty dynamically resizing if 100% width
|
||||
// is set.
|
||||
final JPanel rowTitle = new TitlePanel();
|
||||
rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA));
|
||||
rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
|
||||
|
||||
rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Edit").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Deck Name").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 60%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Main").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Side").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
|
||||
|
||||
RowPanel row;
|
||||
for (final Deck d : decks0) {
|
||||
if (d.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
row = new RowPanel(d);
|
||||
row.add(new DeleteButton(row), "w 10%!, h 20px!, gaptop 5px");
|
||||
row.add(new EditButton(row), "w 10%!, h 20px!, gaptop 5px");
|
||||
row.add(new GenericLabel(d.getName()), "w 60%!, h 20px!, gaptop 5px");
|
||||
row.add(new MainLabel(String.valueOf(d.getMain().countAll())), "w 10%, h 20px!, gaptop 5px");
|
||||
row.add(new GenericLabel(String.valueOf(d.getSideboard().countAll())), "w 10%!, h 20px!, gaptop 5px");
|
||||
this.add(row, "w 98%!, h 30px!, gapleft 1%");
|
||||
tempRows.add(row);
|
||||
}
|
||||
|
||||
this.rows = tempRows.toArray(new RowPanel[0]);
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected deck.
|
||||
*
|
||||
* @return {@link forge.deck.Deck}
|
||||
*/
|
||||
public Deck getSelectedDeck() {
|
||||
Deck selectedDeck = null;
|
||||
for (final RowPanel r : this.rows) {
|
||||
if (r.isSelected()) {
|
||||
selectedDeck = r.getDeck();
|
||||
}
|
||||
}
|
||||
return selectedDeck;
|
||||
}
|
||||
|
||||
/** Prevent panel from repainting the whole screen. */
|
||||
public void repaintOnlyThisPanel() {
|
||||
final Dimension d = DeckLister.this.getSize();
|
||||
this.repaint(0, 0, d.width, d.height);
|
||||
}
|
||||
|
||||
private class DeleteButton extends JButton {
|
||||
public DeleteButton(final RowPanel r0) {
|
||||
super();
|
||||
this.setRolloverEnabled(true);
|
||||
this.setPressedIcon(DeckLister.this.icoDeleteOver);
|
||||
this.setRolloverIcon(DeckLister.this.icoDeleteOver);
|
||||
this.setIcon(DeckLister.this.icoDelete);
|
||||
this.setOpaque(false);
|
||||
this.setContentAreaFilled(false);
|
||||
this.setBorder(null);
|
||||
this.setBorderPainted(false);
|
||||
this.setToolTipText("Delete this deck");
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrHover);
|
||||
r0.setOpaque(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrDefault);
|
||||
r0.setOpaque(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
DeckLister.this.deleteDeck(r0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class EditButton extends JButton {
|
||||
public EditButton(final RowPanel r0) {
|
||||
super();
|
||||
this.setRolloverEnabled(true);
|
||||
this.setPressedIcon(DeckLister.this.icoEditOver);
|
||||
this.setRolloverIcon(DeckLister.this.icoEditOver);
|
||||
this.setIcon(DeckLister.this.icoEdit);
|
||||
this.setOpaque(false);
|
||||
this.setContentAreaFilled(false);
|
||||
this.setBorder(null);
|
||||
this.setBorderPainted(false);
|
||||
this.setToolTipText("Edit this deck");
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrHover);
|
||||
r0.setOpaque(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrDefault);
|
||||
r0.setOpaque(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
DeckLister.this.editDeck(r0.getDeck());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Here only to prevent visual artifact problems from translucent skin
|
||||
// colors.
|
||||
private class TitlePanel extends JPanel {
|
||||
@Override
|
||||
public void paintComponent(final Graphics g) {
|
||||
g.setColor(this.getBackground());
|
||||
g.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
super.paintComponent(g);
|
||||
}
|
||||
}
|
||||
|
||||
private class RowPanel extends JPanel {
|
||||
private boolean selected = false;
|
||||
private final Deck deck;
|
||||
|
||||
public RowPanel(final Deck d0) {
|
||||
super();
|
||||
this.setOpaque(false);
|
||||
this.setBackground(new Color(0, 0, 0, 0));
|
||||
this.setLayout(new MigLayout("insets 0, gap 0"));
|
||||
this.setBorder(new MatteBorder(0, 0, 1, 0, DeckLister.this.clrBorders));
|
||||
this.deck = d0;
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
if (!RowPanel.this.selected) {
|
||||
((RowPanel) e.getSource()).setBackground(DeckLister.this.clrHover);
|
||||
((RowPanel) e.getSource()).setOpaque(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
if (!RowPanel.this.selected) {
|
||||
((RowPanel) e.getSource()).setBackground(DeckLister.this.clrDefault);
|
||||
((RowPanel) e.getSource()).setOpaque(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
DeckLister.this.selectHandler((RowPanel) e.getSource());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setSelected(final boolean b0) {
|
||||
this.selected = b0;
|
||||
this.setOpaque(b0);
|
||||
this.setBackground(b0 ? DeckLister.this.clrActive : DeckLister.this.clrHover);
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
public Deck getDeck() {
|
||||
return this.deck;
|
||||
}
|
||||
}
|
||||
|
||||
private class MainLabel extends JLabel {
|
||||
public MainLabel(final String txt0) {
|
||||
super(txt0);
|
||||
this.setOpaque(true);
|
||||
if (Integer.parseInt(txt0) < 40) {
|
||||
this.setBackground(Color.RED.brighter());
|
||||
} else {
|
||||
this.setBackground(Color.GREEN);
|
||||
}
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
this.setFont(FSkin.getBoldFont(12));
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
private class GenericLabel extends JLabel {
|
||||
public GenericLabel(final String txt0) {
|
||||
super(txt0);
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
this.setFont(FSkin.getBoldFont(12));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected index.
|
||||
*
|
||||
* @return {@link java.lang.Integer}
|
||||
*/
|
||||
public int getSelectedIndex() {
|
||||
for (int i = 0; i < this.rows.length; i++) {
|
||||
if (this.rows[i].isSelected()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a row programatically.
|
||||
*
|
||||
* @param i0
|
||||
*   int
|
||||
* @return boolean Was able to select, or not.
|
||||
*/
|
||||
public boolean setSelectedIndex(final int i0) {
|
||||
if (i0 >= this.rows.length) {
|
||||
return false;
|
||||
}
|
||||
this.selectHandler(this.rows[i0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected deck.
|
||||
*
|
||||
* @param d0   Deck object to select (if exists in list)
|
||||
* @return boolean Found deck, or didn't.
|
||||
*/
|
||||
public boolean setSelectedDeck(final Deck d0) {
|
||||
for (final RowPanel r : this.rows) {
|
||||
if (r.getDeck() == d0) {
|
||||
this.selectHandler(r);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the delete command.
|
||||
*
|
||||
* @param c0   {@link forge.Command} command executed on delete.
|
||||
*/
|
||||
public void setDeleteCommand(final Command c0) {
|
||||
this.cmdDelete = c0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the select command.
|
||||
*
|
||||
* @param c0   {@link forge.Command} command executed on row select.
|
||||
*/
|
||||
public void setSelectCommand(final Command c0) {
|
||||
this.cmdRowSelect = c0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exit command.
|
||||
*
|
||||
* @param c0   {@link forge.Command} command executed on editor exit.
|
||||
*/
|
||||
public void setExitCommand(final Command c0) {
|
||||
this.cmdEditorExit = c0;
|
||||
}
|
||||
|
||||
private void selectHandler(final RowPanel r0) {
|
||||
if (this.previousSelect != null) {
|
||||
this.previousSelect.setSelected(false);
|
||||
}
|
||||
r0.setSelected(true);
|
||||
this.previousSelect = r0;
|
||||
|
||||
if (this.cmdRowSelect != null) {
|
||||
this.cmdRowSelect.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private void editDeck(final Deck d0) {
|
||||
OverlayUtils.showOverlay();
|
||||
|
||||
switch (this.gametype) {
|
||||
case Quest:
|
||||
Constant.Runtime.HUMAN_DECK[0] = d0;
|
||||
final DeckEditorQuest editor = new DeckEditorQuest(AllZone.getQuest());
|
||||
editor.show(this.cmdEditorExit);
|
||||
editor.setVisible(true);
|
||||
editor.setAlwaysOnTop(true);
|
||||
break;
|
||||
case Constructed:
|
||||
final DeckEditorConstructed cEditor = new DeckEditorConstructed();
|
||||
cEditor.show(this.cmdEditorExit);
|
||||
cEditor.getController().load(d0.getName());
|
||||
cEditor.setVisible(true);
|
||||
cEditor.setAlwaysOnTop(true);
|
||||
break;
|
||||
case Sealed:
|
||||
final DeckEditorLimited sEditor = new DeckEditorLimited(Singletons.getModel().getDecks().getSealed());
|
||||
sEditor.show(this.cmdEditorExit);
|
||||
sEditor.getController().load(d0.getName());
|
||||
sEditor.setVisible(true);
|
||||
sEditor.setAlwaysOnTop(true);
|
||||
break;
|
||||
case Draft:
|
||||
final DeckEditorLimited dEditor = new DeckEditorLimited(Singletons.getModel().getDecks().getDraft());
|
||||
dEditor.show(this.cmdEditorExit);
|
||||
dEditor.getController().load(d0.getName());
|
||||
dEditor.setVisible(true);
|
||||
dEditor.setAlwaysOnTop(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDeck(final RowPanel r0) {
|
||||
final Deck d0 = r0.getDeck();
|
||||
|
||||
final int n = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete \"" + d0.getName() + "\" ?",
|
||||
"Delete Deck", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (n == JOptionPane.NO_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CardCollections deckManager = Singletons.getModel().getDecks();
|
||||
|
||||
if (this.gametype.equals(GameType.Draft)) {
|
||||
deckManager.getDraft().delete(d0.getName());
|
||||
} else if (this.gametype.equals(GameType.Sealed)) {
|
||||
deckManager.getSealed().delete(d0.getName());
|
||||
} else if (this.gametype.equals(GameType.Quest)) {
|
||||
AllZone.getQuest().getMyDecks().delete(d0.getName());
|
||||
AllZone.getQuest().save();
|
||||
} else {
|
||||
deckManager.getConstructed().delete(d0.getName());
|
||||
}
|
||||
|
||||
this.remove(r0);
|
||||
this.repaintOnlyThisPanel();
|
||||
this.revalidate();
|
||||
|
||||
if (this.cmdDelete != null) {
|
||||
this.cmdDelete.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Forge: Play Magic: the Gathering.
|
||||
* Copyright (C) 2011 Nate
|
||||
*
|
||||
* 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.gui.toolbox;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingConstants;
|
||||
import javax.swing.border.MatteBorder;
|
||||
|
||||
import forge.AllZone;
|
||||
import forge.Command;
|
||||
import forge.Constant;
|
||||
import forge.Singletons;
|
||||
import forge.deck.CardCollections;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.gui.OverlayUtils;
|
||||
import forge.gui.deckeditor.DeckEditorConstructed;
|
||||
import forge.gui.deckeditor.DeckEditorLimited;
|
||||
import forge.gui.deckeditor.DeckEditorQuest;
|
||||
import net.miginfocom.swing.MigLayout;
|
||||
|
||||
/**
|
||||
* Creates deck list for selected decks for quick deleting, editing, and basic
|
||||
* info.
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DeckLister extends JPanel {
|
||||
private final ImageIcon icoDelete;
|
||||
private final ImageIcon icoDeleteOver;
|
||||
private final ImageIcon icoEdit;
|
||||
private final ImageIcon icoEditOver;
|
||||
private RowPanel previousSelect;
|
||||
private RowPanel[] rows;
|
||||
private final GameType gametype;
|
||||
private Command cmdEditorExit, cmdDelete, cmdRowSelect;
|
||||
private final Color clrDefault, clrHover, clrActive, clrBorders;
|
||||
|
||||
/**
|
||||
* Creates deck list for selected decks for quick deleting, editing, and
|
||||
* basic info. "selectable" and "editable" assumed true.
|
||||
*
|
||||
* @param gt0 the gt0
|
||||
* {@link forge.game.GameType}
|
||||
*/
|
||||
public DeckLister(final GameType gt0) {
|
||||
this(gt0, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates deck list for selected decks for quick deleting, editing, and
|
||||
* basic info. Set "selectable" and "editable" to show those buttons, or
|
||||
* not.
|
||||
*
|
||||
* @param gt0 the gt0
|
||||
* @param cmd0 the cmd0
|
||||
* {@link forge.game.GameType}
|
||||
* {@link forge.Command}, when exiting deck editor
|
||||
*/
|
||||
public DeckLister(final GameType gt0, final Command cmd0) {
|
||||
super();
|
||||
this.gametype = gt0;
|
||||
this.cmdEditorExit = cmd0;
|
||||
|
||||
this.clrDefault = new Color(0, 0, 0, 0);
|
||||
this.clrHover = FSkin.getColor(FSkin.Colors.CLR_HOVER);
|
||||
this.clrActive = FSkin.getColor(FSkin.Colors.CLR_ACTIVE);
|
||||
this.clrBorders = FSkin.getColor(FSkin.Colors.CLR_BORDERS);
|
||||
|
||||
this.setOpaque(false);
|
||||
this.setLayout(new MigLayout("insets 0, gap 0, wrap"));
|
||||
|
||||
this.icoDelete = FSkin.getIcon(FSkin.ForgeIcons.ICO_DELETE);
|
||||
this.icoDeleteOver = FSkin.getIcon(FSkin.ForgeIcons.ICO_DELETE_OVER);
|
||||
this.icoEdit = FSkin.getIcon(FSkin.ForgeIcons.ICO_EDIT);
|
||||
this.icoEditOver = FSkin.getIcon(FSkin.ForgeIcons.ICO_EDIT_OVER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the decks.
|
||||
*
|
||||
* @param decks0 the new decks
|
||||
* {@link forge.deck.Deck}[]
|
||||
*/
|
||||
public void setDecks(final Iterable<Deck> decks0) {
|
||||
this.removeAll();
|
||||
final List<RowPanel> tempRows = new ArrayList<RowPanel>();
|
||||
|
||||
// Title row
|
||||
// Note: careful with the widths of the rows here;
|
||||
// scroll panes will have difficulty dynamically resizing if 100% width
|
||||
// is set.
|
||||
final JPanel rowTitle = new TitlePanel();
|
||||
rowTitle.setBackground(FSkin.getColor(FSkin.Colors.CLR_ZEBRA));
|
||||
rowTitle.setLayout(new MigLayout("insets 0, gap 0"));
|
||||
|
||||
rowTitle.add(new FLabel.Builder().text("Delete").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Edit").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Deck Name").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 60%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Main").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
rowTitle.add(new FLabel.Builder().text("Side").fontAlign(SwingConstants.CENTER).build(),
|
||||
"w 10%!, h 20px!, gaptop 5px");
|
||||
this.add(rowTitle, "w 98%!, h 30px!, gapleft 1%");
|
||||
|
||||
RowPanel row;
|
||||
for (final Deck d : decks0) {
|
||||
if (d.getName() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
row = new RowPanel(d);
|
||||
row.add(new DeleteButton(row), "w 10%!, h 20px!, gaptop 5px");
|
||||
row.add(new EditButton(row), "w 10%!, h 20px!, gaptop 5px");
|
||||
row.add(new GenericLabel(d.getName()), "w 60%!, h 20px!, gaptop 5px");
|
||||
row.add(new MainLabel(String.valueOf(d.getMain().countAll())), "w 10%, h 20px!, gaptop 5px");
|
||||
row.add(new GenericLabel(String.valueOf(d.getSideboard().countAll())), "w 10%!, h 20px!, gaptop 5px");
|
||||
this.add(row, "w 98%!, h 30px!, gapleft 1%");
|
||||
tempRows.add(row);
|
||||
}
|
||||
|
||||
this.rows = tempRows.toArray(new RowPanel[0]);
|
||||
this.revalidate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected deck.
|
||||
*
|
||||
* @return {@link forge.deck.Deck}
|
||||
*/
|
||||
public Deck getSelectedDeck() {
|
||||
Deck selectedDeck = null;
|
||||
for (final RowPanel r : this.rows) {
|
||||
if (r.isSelected()) {
|
||||
selectedDeck = r.getDeck();
|
||||
}
|
||||
}
|
||||
return selectedDeck;
|
||||
}
|
||||
|
||||
/** Prevent panel from repainting the whole screen. */
|
||||
public void repaintOnlyThisPanel() {
|
||||
final Dimension d = DeckLister.this.getSize();
|
||||
this.repaint(0, 0, d.width, d.height);
|
||||
}
|
||||
|
||||
private class DeleteButton extends JButton {
|
||||
public DeleteButton(final RowPanel r0) {
|
||||
super();
|
||||
this.setRolloverEnabled(true);
|
||||
this.setPressedIcon(DeckLister.this.icoDeleteOver);
|
||||
this.setRolloverIcon(DeckLister.this.icoDeleteOver);
|
||||
this.setIcon(DeckLister.this.icoDelete);
|
||||
this.setOpaque(false);
|
||||
this.setContentAreaFilled(false);
|
||||
this.setBorder(null);
|
||||
this.setBorderPainted(false);
|
||||
this.setToolTipText("Delete this deck");
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrHover);
|
||||
r0.setOpaque(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrDefault);
|
||||
r0.setOpaque(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
DeckLister.this.deleteDeck(r0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private class EditButton extends JButton {
|
||||
public EditButton(final RowPanel r0) {
|
||||
super();
|
||||
this.setRolloverEnabled(true);
|
||||
this.setPressedIcon(DeckLister.this.icoEditOver);
|
||||
this.setRolloverIcon(DeckLister.this.icoEditOver);
|
||||
this.setIcon(DeckLister.this.icoEdit);
|
||||
this.setOpaque(false);
|
||||
this.setContentAreaFilled(false);
|
||||
this.setBorder(null);
|
||||
this.setBorderPainted(false);
|
||||
this.setToolTipText("Edit this deck");
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrHover);
|
||||
r0.setOpaque(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
if (!r0.selected) {
|
||||
r0.setBackground(DeckLister.this.clrDefault);
|
||||
r0.setOpaque(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(final MouseEvent e) {
|
||||
DeckLister.this.editDeck(r0.getDeck());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Here only to prevent visual artifact problems from translucent skin
|
||||
// colors.
|
||||
private class TitlePanel extends JPanel {
|
||||
@Override
|
||||
public void paintComponent(final Graphics g) {
|
||||
g.setColor(this.getBackground());
|
||||
g.clearRect(0, 0, this.getWidth(), this.getHeight());
|
||||
g.fillRect(0, 0, this.getWidth(), this.getHeight());
|
||||
super.paintComponent(g);
|
||||
}
|
||||
}
|
||||
|
||||
private class RowPanel extends JPanel {
|
||||
private boolean selected = false;
|
||||
private final Deck deck;
|
||||
|
||||
public RowPanel(final Deck d0) {
|
||||
super();
|
||||
this.setOpaque(false);
|
||||
this.setBackground(new Color(0, 0, 0, 0));
|
||||
this.setLayout(new MigLayout("insets 0, gap 0"));
|
||||
this.setBorder(new MatteBorder(0, 0, 1, 0, DeckLister.this.clrBorders));
|
||||
this.deck = d0;
|
||||
|
||||
this.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(final MouseEvent e) {
|
||||
if (!RowPanel.this.selected) {
|
||||
((RowPanel) e.getSource()).setBackground(DeckLister.this.clrHover);
|
||||
((RowPanel) e.getSource()).setOpaque(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(final MouseEvent e) {
|
||||
if (!RowPanel.this.selected) {
|
||||
((RowPanel) e.getSource()).setBackground(DeckLister.this.clrDefault);
|
||||
((RowPanel) e.getSource()).setOpaque(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
DeckLister.this.selectHandler((RowPanel) e.getSource());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setSelected(final boolean b0) {
|
||||
this.selected = b0;
|
||||
this.setOpaque(b0);
|
||||
this.setBackground(b0 ? DeckLister.this.clrActive : DeckLister.this.clrHover);
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
return this.selected;
|
||||
}
|
||||
|
||||
public Deck getDeck() {
|
||||
return this.deck;
|
||||
}
|
||||
}
|
||||
|
||||
private class MainLabel extends JLabel {
|
||||
public MainLabel(final String txt0) {
|
||||
super(txt0);
|
||||
this.setOpaque(true);
|
||||
if (Integer.parseInt(txt0) < 40) {
|
||||
this.setBackground(Color.RED.brighter());
|
||||
} else {
|
||||
this.setBackground(Color.GREEN);
|
||||
}
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
this.setFont(FSkin.getBoldFont(12));
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
}
|
||||
}
|
||||
|
||||
private class GenericLabel extends JLabel {
|
||||
public GenericLabel(final String txt0) {
|
||||
super(txt0);
|
||||
this.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
this.setForeground(FSkin.getColor(FSkin.Colors.CLR_TEXT));
|
||||
this.setFont(FSkin.getBoldFont(12));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the selected index.
|
||||
*
|
||||
* @return {@link java.lang.Integer}
|
||||
*/
|
||||
public int getSelectedIndex() {
|
||||
for (int i = 0; i < this.rows.length; i++) {
|
||||
if (this.rows[i].isSelected()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a row programatically.
|
||||
*
|
||||
* @param i0
|
||||
*   int
|
||||
* @return boolean Was able to select, or not.
|
||||
*/
|
||||
public boolean setSelectedIndex(final int i0) {
|
||||
if (i0 >= this.rows.length) {
|
||||
return false;
|
||||
}
|
||||
this.selectHandler(this.rows[i0]);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the selected deck.
|
||||
*
|
||||
* @param d0   Deck object to select (if exists in list)
|
||||
* @return boolean Found deck, or didn't.
|
||||
*/
|
||||
public boolean setSelectedDeck(final Deck d0) {
|
||||
for (final RowPanel r : this.rows) {
|
||||
if (r.getDeck() == d0) {
|
||||
this.selectHandler(r);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the delete command.
|
||||
*
|
||||
* @param c0   {@link forge.Command} command executed on delete.
|
||||
*/
|
||||
public void setDeleteCommand(final Command c0) {
|
||||
this.cmdDelete = c0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the select command.
|
||||
*
|
||||
* @param c0   {@link forge.Command} command executed on row select.
|
||||
*/
|
||||
public void setSelectCommand(final Command c0) {
|
||||
this.cmdRowSelect = c0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exit command.
|
||||
*
|
||||
* @param c0   {@link forge.Command} command executed on editor exit.
|
||||
*/
|
||||
public void setExitCommand(final Command c0) {
|
||||
this.cmdEditorExit = c0;
|
||||
}
|
||||
|
||||
private void selectHandler(final RowPanel r0) {
|
||||
if (this.previousSelect != null) {
|
||||
this.previousSelect.setSelected(false);
|
||||
}
|
||||
r0.setSelected(true);
|
||||
this.previousSelect = r0;
|
||||
|
||||
if (this.cmdRowSelect != null) {
|
||||
this.cmdRowSelect.execute();
|
||||
}
|
||||
}
|
||||
|
||||
private void editDeck(final Deck d0) {
|
||||
OverlayUtils.showOverlay();
|
||||
|
||||
JFrame mainFrame = Singletons.getView().getFrame();
|
||||
switch (this.gametype) {
|
||||
case Quest:
|
||||
Constant.Runtime.HUMAN_DECK[0] = d0;
|
||||
final DeckEditorQuest editor = new DeckEditorQuest(mainFrame, AllZone.getQuest());
|
||||
editor.show(this.cmdEditorExit);
|
||||
editor.setVisible(true);
|
||||
break;
|
||||
case Constructed:
|
||||
final DeckEditorConstructed cEditor =
|
||||
new DeckEditorConstructed(mainFrame);
|
||||
cEditor.show(this.cmdEditorExit);
|
||||
cEditor.getController().load(d0.getName());
|
||||
cEditor.setVisible(true);
|
||||
break;
|
||||
case Sealed:
|
||||
final DeckEditorLimited sEditor =
|
||||
new DeckEditorLimited(mainFrame, Singletons.getModel().getDecks().getSealed());
|
||||
sEditor.show(this.cmdEditorExit);
|
||||
sEditor.getController().load(d0.getName());
|
||||
sEditor.setVisible(true);
|
||||
break;
|
||||
case Draft:
|
||||
final DeckEditorLimited dEditor =
|
||||
new DeckEditorLimited(mainFrame, Singletons.getModel().getDecks().getDraft());
|
||||
dEditor.show(this.cmdEditorExit);
|
||||
dEditor.getController().load(d0.getName());
|
||||
dEditor.setVisible(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteDeck(final RowPanel r0) {
|
||||
final Deck d0 = r0.getDeck();
|
||||
|
||||
final int n = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete \"" + d0.getName() + "\" ?",
|
||||
"Delete Deck", JOptionPane.YES_NO_OPTION);
|
||||
|
||||
if (n == JOptionPane.NO_OPTION) {
|
||||
return;
|
||||
}
|
||||
|
||||
final CardCollections deckManager = Singletons.getModel().getDecks();
|
||||
|
||||
if (this.gametype.equals(GameType.Draft)) {
|
||||
deckManager.getDraft().delete(d0.getName());
|
||||
} else if (this.gametype.equals(GameType.Sealed)) {
|
||||
deckManager.getSealed().delete(d0.getName());
|
||||
} else if (this.gametype.equals(GameType.Quest)) {
|
||||
AllZone.getQuest().getMyDecks().delete(d0.getName());
|
||||
AllZone.getQuest().save();
|
||||
} else {
|
||||
deckManager.getConstructed().delete(d0.getName());
|
||||
}
|
||||
|
||||
this.remove(r0);
|
||||
this.repaintOnlyThisPanel();
|
||||
this.revalidate();
|
||||
|
||||
if (this.cmdDelete != null) {
|
||||
this.cmdDelete.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user