mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
* GuiChoose.getOrderChoice is properly parameterized now
This commit is contained in:
@@ -767,7 +767,7 @@ public final class AbilityFactoryClash {
|
|||||||
|
|
||||||
// first, separate the cards into piles
|
// first, separate the cards into piles
|
||||||
if (separator.isHuman()) {
|
if (separator.isHuman()) {
|
||||||
final List<Object> firstPile = GuiChoose.getOrderChoices("Place into two piles", "Pile 1", -1, pool.toArray(), null, card);
|
final List<Card> firstPile = GuiChoose.getOrderChoices("Place into two piles", "Pile 1", -1, pool, null, card);
|
||||||
for (final Object o : firstPile) {
|
for (final Object o : firstPile) {
|
||||||
pile1.add((Card)o);
|
pile1.add((Card)o);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2050,7 +2050,7 @@ public final class AbilityFactoryReveal {
|
|||||||
topCards.add(lib.get(j));
|
topCards.add(lib.get(j));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Object> orderedCards = GuiChoose.getOrderChoices("Select order to Rearrange", "Top of Library", 0, topCards.toArray(), null, src);
|
List<Card> orderedCards = GuiChoose.getOrderChoices("Select order to Rearrange", "Top of Library", 0, topCards, null, src);
|
||||||
for (int i = maxCards - 1; i >= 0; i--) {
|
for (int i = maxCards - 1; i >= 0; i--) {
|
||||||
Card next = (Card) orderedCards.get(i);
|
Card next = (Card) orderedCards.get(i);
|
||||||
Singletons.getModel().getGameAction().moveToLibrary(next, 0);
|
Singletons.getModel().getGameAction().moveToLibrary(next, 0);
|
||||||
@@ -2414,7 +2414,7 @@ public final class AbilityFactoryReveal {
|
|||||||
final int validamount = Math.min(valid.size(), max);
|
final int validamount = Math.min(valid.size(), max);
|
||||||
|
|
||||||
if (anyNumber && player.isHuman() && validamount > 0) {
|
if (anyNumber && player.isHuman() && validamount > 0) {
|
||||||
final List<Object> selection = GuiChoose.getOrderChoices("Choose Which Cards to Reveal", "Revealed", -1, valid.toArray(), null, null);
|
final List<Card> selection = GuiChoose.getOrderChoices("Choose Which Cards to Reveal", "Revealed", -1, valid, null, null);
|
||||||
for (final Object o : selection) {
|
for (final Object o : selection) {
|
||||||
if (o != null && o instanceof Card) {
|
if (o != null && o instanceof Card) {
|
||||||
chosen.add((Card) o);
|
chosen.add((Card) o);
|
||||||
|
|||||||
@@ -4847,7 +4847,7 @@ public class CardFactoryUtil {
|
|||||||
card.clearDevoured();
|
card.clearDevoured();
|
||||||
if (card.getController().isHuman()) {
|
if (card.getController().isHuman()) {
|
||||||
if (creats.size() > 0) {
|
if (creats.size() > 0) {
|
||||||
final List<Object> selection = GuiChoose.getOrderChoices("Devour", "Devouring", -1, creats.toArray(), null, card);
|
final List<Card> selection = GuiChoose.getOrderChoices("Devour", "Devouring", -1, creats, null, card);
|
||||||
numCreatures[0] = selection.size();
|
numCreatures[0] = selection.size();
|
||||||
|
|
||||||
for (Object o : selection) {
|
for (Object o : selection) {
|
||||||
|
|||||||
@@ -440,7 +440,7 @@ public class CombatUtil {
|
|||||||
|
|
||||||
List<Card> orderedBlockers = null;
|
List<Card> orderedBlockers = null;
|
||||||
if (player.isHuman()) {
|
if (player.isHuman()) {
|
||||||
List<Object> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, blockers.toArray(), null, attacker);
|
List<Card> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, blockers, null, attacker);
|
||||||
|
|
||||||
orderedBlockers = new ArrayList<Card>();
|
orderedBlockers = new ArrayList<Card>();
|
||||||
for(Object o : ordered) {
|
for(Object o : ordered) {
|
||||||
@@ -468,7 +468,7 @@ public class CombatUtil {
|
|||||||
|
|
||||||
List<Card> orderedAttacker = null;
|
List<Card> orderedAttacker = null;
|
||||||
if (player.isHuman()) {
|
if (player.isHuman()) {
|
||||||
List<Object> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, attackers.toArray(), null, blocker);
|
List<Card> ordered = GuiChoose.getOrderChoices("Choose Blocking Order", "Damaged First", 0, attackers, null, blocker);
|
||||||
|
|
||||||
orderedAttacker = new ArrayList<Card>();
|
orderedAttacker = new ArrayList<Card>();
|
||||||
for(Object o : ordered) {
|
for(Object o : ordered) {
|
||||||
|
|||||||
@@ -1355,7 +1355,7 @@ public class MagicStack extends MyObservable {
|
|||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Otherwise, gave a dual list form to create instead of needing to do it one at a time
|
// Otherwise, gave a dual list form to create instead of needing to do it one at a time
|
||||||
List<Object> orderedSAs = GuiChoose.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", 0, activePlayerSAs.toArray(), null, null);
|
List<SpellAbility> orderedSAs = GuiChoose.getOrderChoices("Select order for Simultaneous Spell Abilities", "Resolve first", 0, activePlayerSAs, null, null);
|
||||||
int size = orderedSAs.size();
|
int size = orderedSAs.size();
|
||||||
for(int i = size-1; i >= 0; i--){
|
for(int i = size-1; i >= 0; i--){
|
||||||
SpellAbility next = (SpellAbility)orderedSAs.get(i);
|
SpellAbility next = (SpellAbility)orderedSAs.get(i);
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ import java.awt.Dimension;
|
|||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.util.ArrayList;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
@@ -35,14 +34,14 @@ import forge.gui.match.CMatchUI;
|
|||||||
// Single ok button, disabled until left box is empty
|
// Single ok button, disabled until left box is empty
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class DualListBox extends JPanel {
|
public class DualListBox<T> extends JPanel {
|
||||||
private JList sourceList;
|
private JList sourceList;
|
||||||
|
|
||||||
private UnsortedListModel sourceListModel;
|
private UnsortedListModel<T> sourceListModel;
|
||||||
|
|
||||||
private JList destList;
|
private JList destList;
|
||||||
|
|
||||||
private UnsortedListModel destListModel;
|
private UnsortedListModel<T> destListModel;
|
||||||
|
|
||||||
private JButton addButton;
|
private JButton addButton;
|
||||||
private JButton addAllButton;
|
private JButton addAllButton;
|
||||||
@@ -59,7 +58,7 @@ public class DualListBox extends JPanel {
|
|||||||
|
|
||||||
private Card refCard = null;
|
private Card refCard = null;
|
||||||
|
|
||||||
public DualListBox(int remainingObjects, String label, Object[] sourceElements, Object[] destElements,
|
public DualListBox(int remainingObjects, String label, List<T> sourceElements, List<T> destElements,
|
||||||
Card referenceCard) {
|
Card referenceCard) {
|
||||||
this.remainingObjects = remainingObjects;
|
this.remainingObjects = remainingObjects;
|
||||||
this.refCard = referenceCard;
|
this.refCard = referenceCard;
|
||||||
@@ -91,31 +90,32 @@ public class DualListBox extends JPanel {
|
|||||||
addSourceElements(newValue);
|
addSourceElements(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addDestinationElements(List<T> newValue) {
|
||||||
|
fillListModel(destListModel, newValue);
|
||||||
|
}
|
||||||
|
|
||||||
public void addDestinationElements(ListModel newValue) {
|
public void addDestinationElements(ListModel newValue) {
|
||||||
fillListModel(destListModel, newValue);
|
fillListModel(destListModel, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillListModel(UnsortedListModel model, ListModel newValues) {
|
@SuppressWarnings("unchecked") // Java 7 has type parameterized ListModel
|
||||||
|
private void fillListModel(UnsortedListModel<T> model, ListModel newValues) {
|
||||||
int size = newValues.getSize();
|
int size = newValues.getSize();
|
||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
model.add(newValues.getElementAt(i));
|
model.add((T)newValues.getElementAt(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSourceElements(Object[] newValue) {
|
public void addSourceElements(List<T> newValue) {
|
||||||
fillListModel(sourceListModel, newValue);
|
fillListModel(sourceListModel, newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSourceElements(Object[] newValue) {
|
public void setSourceElements(List<T> newValue) {
|
||||||
clearSourceListModel();
|
clearSourceListModel();
|
||||||
addSourceElements(newValue);
|
addSourceElements(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addDestinationElements(Object[] newValue) {
|
private void fillListModel(UnsortedListModel<T> model, List<T> newValues) {
|
||||||
fillListModel(destListModel, newValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fillListModel(UnsortedListModel model, Object[] newValues) {
|
|
||||||
model.addAll(newValues);
|
model.addAll(newValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ public class DualListBox extends JPanel {
|
|||||||
destList.getSelectionModel().clearSelection();
|
destList.getSelectionModel().clearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Object> getOrderedList() {
|
public List<T> getOrderedList() {
|
||||||
this.setVisible(false);
|
this.setVisible(false);
|
||||||
return destListModel.model;
|
return destListModel.model;
|
||||||
}
|
}
|
||||||
@@ -162,7 +162,7 @@ public class DualListBox extends JPanel {
|
|||||||
private void initScreen() {
|
private void initScreen() {
|
||||||
setPreferredSize(new Dimension(650, 300));
|
setPreferredSize(new Dimension(650, 300));
|
||||||
setLayout(new GridLayout(0, 3));
|
setLayout(new GridLayout(0, 3));
|
||||||
sourceListModel = new UnsortedListModel();
|
sourceListModel = new UnsortedListModel<T>();
|
||||||
sourceList = new JList(sourceListModel);
|
sourceList = new JList(sourceListModel);
|
||||||
|
|
||||||
// Dual List control buttons
|
// Dual List control buttons
|
||||||
@@ -182,7 +182,7 @@ public class DualListBox extends JPanel {
|
|||||||
autoButton = new JButton("Auto");
|
autoButton = new JButton("Auto");
|
||||||
autoButton.addActionListener(new AutoListener());
|
autoButton.addActionListener(new AutoListener());
|
||||||
|
|
||||||
destListModel = new UnsortedListModel();
|
destListModel = new UnsortedListModel<T>();
|
||||||
destList = new JList(destListModel);
|
destList = new JList(destListModel);
|
||||||
|
|
||||||
JPanel leftPanel = new JPanel(new BorderLayout());
|
JPanel leftPanel = new JPanel(new BorderLayout());
|
||||||
@@ -217,7 +217,8 @@ public class DualListBox extends JPanel {
|
|||||||
private class AddListener implements ActionListener {
|
private class AddListener implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Object[] selected = sourceList.getSelectedValues();
|
@SuppressWarnings("unchecked")
|
||||||
|
List<T> selected = (List<T>) Arrays.asList(sourceList.getSelectedValues());
|
||||||
addDestinationElements(selected);
|
addDestinationElements(selected);
|
||||||
clearSourceSelected();
|
clearSourceSelected();
|
||||||
sourceList.validate();
|
sourceList.validate();
|
||||||
@@ -226,16 +227,7 @@ public class DualListBox extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addAll() {
|
private void addAll() {
|
||||||
Iterator<Object> itr = sourceListModel.iterator();
|
addDestinationElements(sourceListModel);
|
||||||
|
|
||||||
ArrayList<Object> objects = new ArrayList<Object>();
|
|
||||||
|
|
||||||
while (itr.hasNext()) {
|
|
||||||
Object obj = itr.next();
|
|
||||||
objects.add(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
addDestinationElements(objects.toArray());
|
|
||||||
clearSourceListModel();
|
clearSourceListModel();
|
||||||
setButtonState();
|
setButtonState();
|
||||||
}
|
}
|
||||||
@@ -251,7 +243,8 @@ public class DualListBox extends JPanel {
|
|||||||
private class RemoveListener implements ActionListener {
|
private class RemoveListener implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Object[] selected = destList.getSelectedValues();
|
@SuppressWarnings("unchecked")
|
||||||
|
List<T> selected = (List<T>) Arrays.asList(destList.getSelectedValues());
|
||||||
addSourceElements(selected);
|
addSourceElements(selected);
|
||||||
clearDestinationSelected();
|
clearDestinationSelected();
|
||||||
setButtonState();
|
setButtonState();
|
||||||
@@ -261,16 +254,7 @@ public class DualListBox extends JPanel {
|
|||||||
private class RemoveAllListener implements ActionListener {
|
private class RemoveAllListener implements ActionListener {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
Iterator<Object> itr = destListModel.iterator();
|
addSourceElements(destListModel);
|
||||||
|
|
||||||
ArrayList<Object> objects = new ArrayList<Object>();
|
|
||||||
|
|
||||||
while (itr.hasNext()) {
|
|
||||||
Object obj = itr.next();
|
|
||||||
objects.add(obj);
|
|
||||||
}
|
|
||||||
|
|
||||||
addSourceElements(objects.toArray());
|
|
||||||
clearDestinationListModel();
|
clearDestinationListModel();
|
||||||
setButtonState();
|
setButtonState();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ public class GuiAssignDamageFrame extends JFrame {
|
|||||||
private final JPanel buttonPanel = new JPanel();
|
private final JPanel buttonPanel = new JPanel();
|
||||||
private final BoxLayout buttonLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
|
private final BoxLayout buttonLayout = new BoxLayout(buttonPanel, BoxLayout.X_AXIS);
|
||||||
|
|
||||||
private UnsortedListModel recipientsListModel = new UnsortedListModel();
|
private UnsortedListModel<GameEntity> recipientsListModel = new UnsortedListModel<GameEntity>();
|
||||||
private final JList recipientsList = new JList(recipientsListModel);
|
private final JList recipientsList = new JList(recipientsListModel);
|
||||||
|
|
||||||
private final JButton oneDamageButton = new JButton("Assign 1");
|
private final JButton oneDamageButton = new JButton("Assign 1");
|
||||||
|
|||||||
@@ -194,11 +194,11 @@ public class GuiChoose {
|
|||||||
return c.getSelectedValues();
|
return c.getSelectedValues();
|
||||||
} // getChoice()
|
} // getChoice()
|
||||||
|
|
||||||
public static List<Object> getOrderChoices(final String title, final String top, int remainingObjects,
|
public static <T> List<T> getOrderChoices(final String title, final String top, int remainingObjects,
|
||||||
final Object[] sourceChoices, Object[] destChoices, Card referenceCard) {
|
final List<T> sourceChoices, List<T> destChoices, Card referenceCard) {
|
||||||
// An input box for handling the order of choices.
|
// An input box for handling the order of choices.
|
||||||
final JFrame frame = new JFrame();
|
final JFrame frame = new JFrame();
|
||||||
DualListBox dual = new DualListBox(remainingObjects, top, sourceChoices, destChoices, referenceCard);
|
DualListBox<T> dual = new DualListBox<T>(remainingObjects, top, sourceChoices, destChoices, referenceCard);
|
||||||
|
|
||||||
frame.setLayout(new BorderLayout());
|
frame.setLayout(new BorderLayout());
|
||||||
frame.setSize(dual.getPreferredSize());
|
frame.setSize(dual.getPreferredSize());
|
||||||
@@ -218,7 +218,7 @@ public class GuiChoose {
|
|||||||
}
|
}
|
||||||
dialog.setVisible(true);
|
dialog.setVisible(true);
|
||||||
|
|
||||||
List<Object> objects = dual.getOrderedList();
|
List<T> objects = dual.getOrderedList();
|
||||||
dialog.dispose();
|
dialog.dispose();
|
||||||
return objects;
|
return objects;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package forge.gui;
|
package forge.gui;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
@@ -8,12 +7,13 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.swing.AbstractListModel;
|
import javax.swing.AbstractListModel;
|
||||||
|
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class UnsortedListModel extends AbstractListModel {
|
class UnsortedListModel<T> extends AbstractListModel { // Java 7 has a generic version. In 6 we have to cast types
|
||||||
List<Object> model;
|
List<T> model;
|
||||||
|
|
||||||
public UnsortedListModel() {
|
public UnsortedListModel() {
|
||||||
model = new LinkedList<Object>();
|
model = new LinkedList<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -26,18 +26,24 @@ class UnsortedListModel extends AbstractListModel {
|
|||||||
return model.get(index);
|
return model.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add(Object element) {
|
public void add(T element) {
|
||||||
if (model.add(element)) {
|
if (model.add(element)) {
|
||||||
fireContentsChanged(this, 0, getSize());
|
fireContentsChanged(this, 0, getSize());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addAll(Object elements[]) {
|
public void addAll(T[] elements) {
|
||||||
Collection<Object> c = Arrays.asList(elements);
|
for(T e : elements)
|
||||||
model.addAll(c);
|
model.add(e);
|
||||||
fireContentsChanged(this, 0, getSize());
|
fireContentsChanged(this, 0, getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addAll(Collection<T> elements) {
|
||||||
|
model.addAll(elements);
|
||||||
|
fireContentsChanged(this, 0, getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
model.clear();
|
model.clear();
|
||||||
fireContentsChanged(this, 0, getSize());
|
fireContentsChanged(this, 0, getSize());
|
||||||
@@ -47,7 +53,7 @@ class UnsortedListModel extends AbstractListModel {
|
|||||||
return model.contains(element);
|
return model.contains(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Iterator<Object> iterator() {
|
public Iterator<T> iterator() {
|
||||||
return model.iterator();
|
return model.iterator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ public enum CPicture implements ICDoc {
|
|||||||
/** */
|
/** */
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
private InventoryItem item = null;
|
|
||||||
private Card currentCard = null;
|
private Card currentCard = null;
|
||||||
private boolean flipped = false;
|
private boolean flipped = false;
|
||||||
|
|
||||||
@@ -46,14 +45,12 @@ public enum CPicture implements ICDoc {
|
|||||||
*   Card object
|
*   Card object
|
||||||
*/
|
*/
|
||||||
public void showCard(final Card c) {
|
public void showCard(final Card c) {
|
||||||
this.item = null;
|
|
||||||
this.currentCard = c;
|
this.currentCard = c;
|
||||||
VPicture.SINGLETON_INSTANCE.getLblFlipcard().setVisible(c != null && c.isDoubleFaced() ? true : false);
|
VPicture.SINGLETON_INSTANCE.getLblFlipcard().setVisible(c != null && c.isDoubleFaced() ? true : false);
|
||||||
VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(c);
|
VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showCard(final InventoryItem item) {
|
public void showCard(final InventoryItem item) {
|
||||||
this.item = item;
|
|
||||||
this.currentCard = null;
|
this.currentCard = null;
|
||||||
VPicture.SINGLETON_INSTANCE.getLblFlipcard().setVisible(false);
|
VPicture.SINGLETON_INSTANCE.getLblFlipcard().setVisible(false);
|
||||||
VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(item);
|
VPicture.SINGLETON_INSTANCE.getPnlPicture().setCard(item);
|
||||||
|
|||||||
Reference in New Issue
Block a user