change manipulateCardList to CardView

This commit is contained in:
Peter F. Patel-Schneider
2019-01-14 21:22:27 -05:00
parent fb80dece04
commit aa7ad578d5
7 changed files with 47 additions and 55 deletions

View File

@@ -285,22 +285,22 @@ public class GuiChoose {
return null; return null;
} }
public static List<Card> manipulateCardList(final CMatchUI gui, final String title, final List<Card> cards, final List<Card> manipulable, public static List<CardView> manipulateCardList(final CMatchUI gui, final String title, final List<CardView> cards, final List<CardView> manipulable,
final boolean toTop, final boolean toBottom, final boolean toAnywhere) { final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
final Callable<List<Card>> callable = new Callable<List<Card>>() { final Callable<List<CardView>> callable = new Callable<List<CardView>>() {
@Override @Override
public List<Card> call() throws Exception { public List<CardView> call() throws Exception {
ListCardArea tempArea = ListCardArea.show(gui,title,cards,manipulable,toTop,toBottom,toAnywhere); ListCardArea tempArea = ListCardArea.show(gui,title,cards,manipulable,toTop,toBottom,toAnywhere);
// tempArea.pack(); // tempArea.pack();
tempArea.show(); tempArea.show();
final List<Card> cardList = tempArea.getCardList(); final List<CardView> cardList = tempArea.getCards();
return cardList; return cardList;
} }
}; };
final FutureTask<List<Card>> ft = new FutureTask<List<Card>>(callable); final FutureTask<List<CardView>> ft = new FutureTask<List<CardView>>(callable);
FThreads.invokeInEdtAndWait(ft); FThreads.invokeInEdtAndWait(ft);
try { try {
List<Card> result = ft.get(); List<CardView> result = ft.get();
return result; return result;
} catch (final Exception e) { // we have waited enough } catch (final Exception e) { // we have waited enough
e.printStackTrace(); e.printStackTrace();

View File

@@ -51,7 +51,6 @@ import forge.deck.Deck;
import forge.deckchooser.FDeckViewer; import forge.deckchooser.FDeckViewer;
import forge.game.GameEntityView; import forge.game.GameEntityView;
import forge.game.GameView; import forge.game.GameView;
import forge.game.card.Card;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.game.combat.CombatView; import forge.game.combat.CombatView;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
@@ -1005,7 +1004,7 @@ public final class CMatchUI
} }
@Override @Override
public List<Card> manipulateCardList(final String title, final List<Card> cards, final List<Card> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { public List<CardView> manipulateCardList(final String title, final List<CardView> cards, final List<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
return GuiChoose.manipulateCardList(this, title, cards, manipulable, toTop, toBottom, toAnywhere); return GuiChoose.manipulateCardList(this, title, cards, manipulable, toTop, toBottom, toAnywhere);
} }

View File

@@ -26,17 +26,9 @@ import java.awt.event.KeyEvent;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
//import javax.swing.ScrollPaneConstants;
import forge.game.card.Card;
import forge.game.card.CardView; import forge.game.card.CardView;
//import forge.game.card.CardCollection;
import forge.screens.match.CMatchUI; import forge.screens.match.CMatchUI;
import forge.view.arcane.util.CardPanelMouseAdapter; import forge.view.arcane.util.CardPanelMouseAdapter;
//import forge.toolbox.FScrollPane;
//import forge.util.collect.FCollectionView;
//import forge.toolbox.MouseTriggerEvent;
//import forge.view.FFrame;
import forge.view.FDialog; import forge.view.FDialog;
import forge.toolbox.FButton; import forge.toolbox.FButton;
@@ -48,8 +40,8 @@ import forge.toolbox.FButton;
// but that would require consirable changes to card panels and elsewhere // but that would require consirable changes to card panels and elsewhere
public class ListCardArea extends FloatingCardArea { public class ListCardArea extends FloatingCardArea {
private static ArrayList<Card> cardList; private static ArrayList<CardView> cardList;
private static ArrayList<Card> moveableCards; private static ArrayList<CardView> moveableCards;
private static ListCardArea storedArea; private static ListCardArea storedArea;
private static FButton doneButton; private static FButton doneButton;
@@ -67,13 +59,13 @@ public class ListCardArea extends FloatingCardArea {
setOpaque(false); setOpaque(false);
} }
public static ListCardArea show(final CMatchUI matchUI, final String title0, final List<Card> cardList0, final List<Card> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) { public static ListCardArea show(final CMatchUI matchUI, final String title0, final List<CardView> cardList0, final List<CardView> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) {
if (storedArea==null) { if (storedArea==null) {
storedArea = new ListCardArea(matchUI); storedArea = new ListCardArea(matchUI);
} }
cardList = new ArrayList<Card>(cardList0); cardList = new ArrayList<CardView>(cardList0);
moveableCards = new ArrayList<Card>(); // make sure moveable cards are in cardlist moveableCards = new ArrayList<CardView>(); // make sure moveable cards are in cardlist
for ( Card card : moveableCards0 ) { for ( CardView card : moveableCards0 ) {
if ( cardList.contains(card) ) { if ( cardList.contains(card) ) {
moveableCards.add(card); moveableCards.add(card);
} }
@@ -89,7 +81,7 @@ public class ListCardArea extends FloatingCardArea {
return storedArea; return storedArea;
} }
public ListCardArea(final CMatchUI matchUI, final String title0, final List<Card> cardList0, final List<Card> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) { public ListCardArea(final CMatchUI matchUI, final String title0, final List<CardView> cardList0, final List<CardView> moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) {
super(matchUI); super(matchUI);
window.add(getScrollPane(),"grow, push"); window.add(getScrollPane(),"grow, push");
// try { Thread.sleep(1000); } catch(InterruptedException ex) { } // try { Thread.sleep(1000); } catch(InterruptedException ex) { }
@@ -100,8 +92,8 @@ public class ListCardArea extends FloatingCardArea {
@Override public void actionPerformed(ActionEvent e) { window.setVisible(false); } @Override public void actionPerformed(ActionEvent e) { window.setVisible(false); }
}); });
window.add(doneButton,BorderLayout.SOUTH); window.add(doneButton,BorderLayout.SOUTH);
cardList = new ArrayList<Card>(cardList0); // this is modified - pfps - is there a better way? cardList = new ArrayList<CardView>(cardList0); // this is modified - pfps - is there a better way?
moveableCards = new ArrayList<Card>(moveableCards0); moveableCards = new ArrayList<CardView>(moveableCards0);
title = title0; title = title0;
toTop = toTop0; toTop = toTop0;
toBottom = toBottom0; toBottom = toBottom0;
@@ -111,15 +103,7 @@ public class ListCardArea extends FloatingCardArea {
storedArea = this; storedArea = this;
} }
protected Iterable<CardView> getCards() { public List<CardView> getCards() {
ArrayList<CardView> result = new ArrayList<CardView>();
for ( Card c : cardList ) {
result.add(c.getView());
}
return result;
}
public List<Card> getCardList() {
return cardList; return cardList;
} }
@@ -185,7 +169,7 @@ public class ListCardArea extends FloatingCardArea {
} }
// is this a valid place to move the card? // is this a valid place to move the card?
private boolean validIndex(final Card card, final int index) { private boolean validIndex(final CardView card, final int index) {
if (toAnywhere) { return true; } if (toAnywhere) { return true; }
int oldIndex = cardList.indexOf(card); int oldIndex = cardList.indexOf(card);
boolean topMove = true; boolean topMove = true;
@@ -201,21 +185,14 @@ public class ListCardArea extends FloatingCardArea {
return false; return false;
} }
protected Card panelToCard(final CardPanel panel) { //pfps there must be a better way
final CardView panelView = panel.getCard();
Card panelCard = null;
for ( Card card : cardList ) { if ( panelView == card.getView() ) { panelCard = card; } }
return panelCard;
}
@Override @Override
protected boolean cardPanelDraggable(final CardPanel panel) { protected boolean cardPanelDraggable(final CardPanel panel) {
return moveableCards.contains(panelToCard(panel)); return moveableCards.contains(panel.getCard());
} }
private void dragEnd(final CardPanel dragPanel) { private void dragEnd(final CardPanel dragPanel) {
// if drag is not allowed, don't move anything // if drag is not allowed, don't move anything
final Card dragCard = panelToCard(dragPanel); final CardView dragCard = dragPanel.getCard();
if (moveableCards.contains(dragCard)) { if (moveableCards.contains(dragCard)) {
//update index of dragged card in hand zone to match new index within hand area //update index of dragged card in hand zone to match new index within hand area
final int index = getCardPanels().indexOf(dragPanel); final int index = getCardPanels().indexOf(dragPanel);
@@ -248,7 +225,7 @@ public class ListCardArea extends FloatingCardArea {
// move to beginning of list if allowable else to beginning of bottom if allowable // move to beginning of list if allowable else to beginning of bottom if allowable
@Override @Override
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) { public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
final Card clickCard = panelToCard(panel); final CardView clickCard = panel.getCard();
if ( moveableCards.contains(clickCard) ) { if ( moveableCards.contains(clickCard) ) {
if ( toTop || toBottom ) { if ( toTop || toBottom ) {
synchronized (cardList) { synchronized (cardList) {
@@ -256,7 +233,7 @@ public class ListCardArea extends FloatingCardArea {
int position; int position;
if ( toTop ) { if ( toTop ) {
position = 0 ; position = 0 ;
} else { // to beginning of bottom } else { // to beginning of bottom: warning, untested
for ( position = cardList.size() ; for ( position = cardList.size() ;
position>0 && moveableCards.contains(cardList.get(position-1)) ; position>0 && moveableCards.contains(cardList.get(position-1)) ;
position-- ); position-- );
@@ -270,8 +247,8 @@ public class ListCardArea extends FloatingCardArea {
} }
@Override @Override
public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) { public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) {
final Card clickCard = panelToCard(panel); final CardView clickCard = panel.getCard();
if (moveableCards.contains(clickCard) && toBottom ) { if (moveableCards.contains(clickCard)) {
if ( toTop || toBottom ) { if ( toTop || toBottom ) {
synchronized (cardList) { synchronized (cardList) {
cardList.remove(clickCard); cardList.remove(clickCard);

View File

@@ -29,7 +29,6 @@ import forge.deck.CardPool;
import forge.deck.FSideboardDialog; import forge.deck.FSideboardDialog;
import forge.game.GameEntityView; import forge.game.GameEntityView;
import forge.game.GameView; import forge.game.GameView;
import forge.game.card.Card;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.DelayedReveal; import forge.game.player.DelayedReveal;
@@ -522,7 +521,7 @@ public class MatchController extends AbstractGuiGame {
} }
@Override @Override
public List<Card> manipulateCardList(final String title, final List<Card> cards, final List<Card> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { public List<CardView> manipulateCardList(final String title, final List<CardView> cards, final List<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
System.err.println("Not implemented yet - should never be called"); System.err.println("Not implemented yet - should never be called");
return null; return null;
} }

View File

@@ -11,7 +11,6 @@ import forge.assets.FSkinProp;
import forge.deck.CardPool; import forge.deck.CardPool;
import forge.game.GameEntityView; import forge.game.GameEntityView;
import forge.game.GameView; import forge.game.GameView;
import forge.game.card.Card;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.DelayedReveal; import forge.game.player.DelayedReveal;
@@ -150,7 +149,7 @@ public interface IGuiGame {
List<GameEntityView> chooseEntitiesForEffect(String title, List<? extends GameEntityView> optionList, int min, int max, DelayedReveal delayedReveal); List<GameEntityView> chooseEntitiesForEffect(String title, List<? extends GameEntityView> optionList, int min, int max, DelayedReveal delayedReveal);
// show a list of cards and allow some of them to be moved around and return new list // show a list of cards and allow some of them to be moved around and return new list
List<Card> manipulateCardList(String title, final List<Card> cards, final List<Card> manipulable, boolean toTop, boolean toBottom, boolean toAnywhere); List<CardView> manipulateCardList(String title, final List<CardView> cards, final List<CardView> manipulable, boolean toTop, boolean toBottom, boolean toAnywhere);
void setCard(CardView card); void setCard(CardView card);
void setPlayerAvatar(LobbyPlayer player, IHasIcon ihi); void setPlayerAvatar(LobbyPlayer player, IHasIcon ihi);

View File

@@ -11,7 +11,6 @@ import forge.assets.FSkinProp;
import forge.deck.CardPool; import forge.deck.CardPool;
import forge.game.GameEntityView; import forge.game.GameEntityView;
import forge.game.GameView; import forge.game.GameView;
import forge.game.card.Card;
import forge.game.card.CardView; import forge.game.card.CardView;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.DelayedReveal; import forge.game.player.DelayedReveal;
@@ -250,7 +249,7 @@ public class NetGuiGame extends AbstractGuiGame {
} }
@Override @Override
public List<Card> manipulateCardList(final String title, final List<Card> cards, final List<Card> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { public List<CardView> manipulateCardList(final String title, final List<CardView> cards, final List<CardView> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
return sendAndWait(ProtocolMethod.manipulateCardList, title, cards, manipulable, toTop, toBottom, toAnywhere); return sendAndWait(ProtocolMethod.manipulateCardList, title, cards, manipulable, toTop, toBottom, toAnywhere);
} }

View File

@@ -737,8 +737,26 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
} }
} }
public List<Card> manipulateCardList(final String title, final List<Card> cards, final List<Card> manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
ArrayList<CardView> cardViews = new ArrayList<CardView>();
for ( Card c : cards ) { cardViews.add(c.getView()); }
ArrayList<CardView> manipulableViews = new ArrayList<CardView>();
for ( Card c : cards ) { manipulableViews.add(c.getView()); }
Iterable<CardView> result = getGui().manipulateCardList(title, cardViews, manipulableViews, toTop, toBottom, toAnywhere);
List<Card> resultCards = new ArrayList<Card>();
for ( CardView cv : result ) {
for ( Card card : cards ) {
if ( cv == card.getView() ) {
resultCards.add(card);
break;
}
}
}
return resultCards;
}
public ImmutablePair<CardCollection, CardCollection> arrangeForMove(final String title, final List<Card> cards, final List<Card> manipulable, final boolean topOK, final boolean bottomOK) { public ImmutablePair<CardCollection, CardCollection> arrangeForMove(final String title, final List<Card> cards, final List<Card> manipulable, final boolean topOK, final boolean bottomOK) {
List<Card> result = getGui().manipulateCardList("Move cards to top or bottom of library", cards, manipulable, topOK, bottomOK, false); List<Card> result = manipulateCardList("Move cards to top or bottom of library", cards, manipulable, topOK, bottomOK, false);
CardCollection toBottom = new CardCollection(); CardCollection toBottom = new CardCollection();
CardCollection toTop = new CardCollection(); CardCollection toTop = new CardCollection();
for (int i = 0; i<cards.size() && manipulable.contains(result.get(i)) ; i++ ) { for (int i = 0; i<cards.size() && manipulable.contains(result.get(i)) ; i++ ) {
@@ -2895,3 +2913,4 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
} }
} }