mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
change manipulateCardList to CardView
This commit is contained in:
@@ -285,22 +285,22 @@ public class GuiChoose {
|
||||
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 Callable<List<Card>> callable = new Callable<List<Card>>() {
|
||||
final Callable<List<CardView>> callable = new Callable<List<CardView>>() {
|
||||
@Override
|
||||
public List<Card> call() throws Exception {
|
||||
public List<CardView> call() throws Exception {
|
||||
ListCardArea tempArea = ListCardArea.show(gui,title,cards,manipulable,toTop,toBottom,toAnywhere);
|
||||
// tempArea.pack();
|
||||
tempArea.show();
|
||||
final List<Card> cardList = tempArea.getCardList();
|
||||
final List<CardView> cardList = tempArea.getCards();
|
||||
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);
|
||||
try {
|
||||
List<Card> result = ft.get();
|
||||
List<CardView> result = ft.get();
|
||||
return result;
|
||||
} catch (final Exception e) { // we have waited enough
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -51,7 +51,6 @@ import forge.deck.Deck;
|
||||
import forge.deckchooser.FDeckViewer;
|
||||
import forge.game.GameEntityView;
|
||||
import forge.game.GameView;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.combat.CombatView;
|
||||
import forge.game.phase.PhaseType;
|
||||
@@ -1005,7 +1004,7 @@ public final class CMatchUI
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,17 +26,9 @@ import java.awt.event.KeyEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//import javax.swing.ScrollPaneConstants;
|
||||
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
//import forge.game.card.CardCollection;
|
||||
import forge.screens.match.CMatchUI;
|
||||
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.toolbox.FButton;
|
||||
@@ -48,8 +40,8 @@ import forge.toolbox.FButton;
|
||||
// but that would require consirable changes to card panels and elsewhere
|
||||
public class ListCardArea extends FloatingCardArea {
|
||||
|
||||
private static ArrayList<Card> cardList;
|
||||
private static ArrayList<Card> moveableCards;
|
||||
private static ArrayList<CardView> cardList;
|
||||
private static ArrayList<CardView> moveableCards;
|
||||
|
||||
private static ListCardArea storedArea;
|
||||
private static FButton doneButton;
|
||||
@@ -67,13 +59,13 @@ public class ListCardArea extends FloatingCardArea {
|
||||
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) {
|
||||
storedArea = new ListCardArea(matchUI);
|
||||
}
|
||||
cardList = new ArrayList<Card>(cardList0);
|
||||
moveableCards = new ArrayList<Card>(); // make sure moveable cards are in cardlist
|
||||
for ( Card card : moveableCards0 ) {
|
||||
cardList = new ArrayList<CardView>(cardList0);
|
||||
moveableCards = new ArrayList<CardView>(); // make sure moveable cards are in cardlist
|
||||
for ( CardView card : moveableCards0 ) {
|
||||
if ( cardList.contains(card) ) {
|
||||
moveableCards.add(card);
|
||||
}
|
||||
@@ -89,7 +81,7 @@ public class ListCardArea extends FloatingCardArea {
|
||||
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);
|
||||
window.add(getScrollPane(),"grow, push");
|
||||
// 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); }
|
||||
});
|
||||
window.add(doneButton,BorderLayout.SOUTH);
|
||||
cardList = new ArrayList<Card>(cardList0); // this is modified - pfps - is there a better way?
|
||||
moveableCards = new ArrayList<Card>(moveableCards0);
|
||||
cardList = new ArrayList<CardView>(cardList0); // this is modified - pfps - is there a better way?
|
||||
moveableCards = new ArrayList<CardView>(moveableCards0);
|
||||
title = title0;
|
||||
toTop = toTop0;
|
||||
toBottom = toBottom0;
|
||||
@@ -111,15 +103,7 @@ public class ListCardArea extends FloatingCardArea {
|
||||
storedArea = this;
|
||||
}
|
||||
|
||||
protected Iterable<CardView> getCards() {
|
||||
ArrayList<CardView> result = new ArrayList<CardView>();
|
||||
for ( Card c : cardList ) {
|
||||
result.add(c.getView());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Card> getCardList() {
|
||||
public List<CardView> getCards() {
|
||||
return cardList;
|
||||
}
|
||||
|
||||
@@ -185,7 +169,7 @@ public class ListCardArea extends FloatingCardArea {
|
||||
}
|
||||
|
||||
// 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; }
|
||||
int oldIndex = cardList.indexOf(card);
|
||||
boolean topMove = true;
|
||||
@@ -201,21 +185,14 @@ public class ListCardArea extends FloatingCardArea {
|
||||
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
|
||||
protected boolean cardPanelDraggable(final CardPanel panel) {
|
||||
return moveableCards.contains(panelToCard(panel));
|
||||
return moveableCards.contains(panel.getCard());
|
||||
}
|
||||
|
||||
private void dragEnd(final CardPanel dragPanel) {
|
||||
// if drag is not allowed, don't move anything
|
||||
final Card dragCard = panelToCard(dragPanel);
|
||||
final CardView dragCard = dragPanel.getCard();
|
||||
if (moveableCards.contains(dragCard)) {
|
||||
//update index of dragged card in hand zone to match new index within hand area
|
||||
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
|
||||
@Override
|
||||
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 ( toTop || toBottom ) {
|
||||
synchronized (cardList) {
|
||||
@@ -256,7 +233,7 @@ public class ListCardArea extends FloatingCardArea {
|
||||
int position;
|
||||
if ( toTop ) {
|
||||
position = 0 ;
|
||||
} else { // to beginning of bottom
|
||||
} else { // to beginning of bottom: warning, untested
|
||||
for ( position = cardList.size() ;
|
||||
position>0 && moveableCards.contains(cardList.get(position-1)) ;
|
||||
position-- );
|
||||
@@ -270,8 +247,8 @@ public class ListCardArea extends FloatingCardArea {
|
||||
}
|
||||
@Override
|
||||
public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) {
|
||||
final Card clickCard = panelToCard(panel);
|
||||
if (moveableCards.contains(clickCard) && toBottom ) {
|
||||
final CardView clickCard = panel.getCard();
|
||||
if (moveableCards.contains(clickCard)) {
|
||||
if ( toTop || toBottom ) {
|
||||
synchronized (cardList) {
|
||||
cardList.remove(clickCard);
|
||||
|
||||
@@ -29,7 +29,6 @@ import forge.deck.CardPool;
|
||||
import forge.deck.FSideboardDialog;
|
||||
import forge.game.GameEntityView;
|
||||
import forge.game.GameView;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.DelayedReveal;
|
||||
@@ -522,7 +521,7 @@ public class MatchController extends AbstractGuiGame {
|
||||
}
|
||||
|
||||
@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");
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import forge.assets.FSkinProp;
|
||||
import forge.deck.CardPool;
|
||||
import forge.game.GameEntityView;
|
||||
import forge.game.GameView;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.phase.PhaseType;
|
||||
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);
|
||||
|
||||
// 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 setPlayerAvatar(LobbyPlayer player, IHasIcon ihi);
|
||||
|
||||
@@ -11,7 +11,6 @@ import forge.assets.FSkinProp;
|
||||
import forge.deck.CardPool;
|
||||
import forge.game.GameEntityView;
|
||||
import forge.game.GameView;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CardView;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.DelayedReveal;
|
||||
@@ -250,7 +249,7 @@ public class NetGuiGame extends AbstractGuiGame {
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
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 toTop = new CardCollection();
|
||||
for (int i = 0; i<cards.size() && manipulable.contains(result.get(i)) ; i++ ) {
|
||||
@@ -2895,3 +2913,4 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user