From aa7ad578d5e09be5f9bc1a3e186e1b2e0137b77d Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Mon, 14 Jan 2019 21:22:27 -0500 Subject: [PATCH] change manipulateCardList to CardView --- .../src/main/java/forge/gui/GuiChoose.java | 12 ++-- .../java/forge/screens/match/CMatchUI.java | 3 +- .../java/forge/view/arcane/ListCardArea.java | 57 ++++++------------- .../forge/screens/match/MatchController.java | 3 +- .../main/java/forge/interfaces/IGuiGame.java | 3 +- .../java/forge/net/server/NetGuiGame.java | 3 +- .../forge/player/PlayerControllerHuman.java | 21 ++++++- 7 files changed, 47 insertions(+), 55 deletions(-) diff --git a/forge-gui-desktop/src/main/java/forge/gui/GuiChoose.java b/forge-gui-desktop/src/main/java/forge/gui/GuiChoose.java index bcd7430e96c..d9c2f9782a5 100644 --- a/forge-gui-desktop/src/main/java/forge/gui/GuiChoose.java +++ b/forge-gui-desktop/src/main/java/forge/gui/GuiChoose.java @@ -285,22 +285,22 @@ public class GuiChoose { return null; } - public static List manipulateCardList(final CMatchUI gui, final String title, final List cards, final List manipulable, + public static List manipulateCardList(final CMatchUI gui, final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { - final Callable> callable = new Callable>() { + final Callable> callable = new Callable>() { @Override - public List call() throws Exception { + public List call() throws Exception { ListCardArea tempArea = ListCardArea.show(gui,title,cards,manipulable,toTop,toBottom,toAnywhere); // tempArea.pack(); tempArea.show(); - final List cardList = tempArea.getCardList(); + final List cardList = tempArea.getCards(); return cardList; } }; - final FutureTask> ft = new FutureTask>(callable); + final FutureTask> ft = new FutureTask>(callable); FThreads.invokeInEdtAndWait(ft); try { - List result = ft.get(); + List result = ft.get(); return result; } catch (final Exception e) { // we have waited enough e.printStackTrace(); diff --git a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java index 6e6ae367caa..400303463c0 100644 --- a/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java +++ b/forge-gui-desktop/src/main/java/forge/screens/match/CMatchUI.java @@ -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 manipulateCardList(final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { + public List manipulateCardList(final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { return GuiChoose.manipulateCardList(this, title, cards, manipulable, toTop, toBottom, toAnywhere); } diff --git a/forge-gui-desktop/src/main/java/forge/view/arcane/ListCardArea.java b/forge-gui-desktop/src/main/java/forge/view/arcane/ListCardArea.java index ac1f3bda04a..23f7e4b81f5 100644 --- a/forge-gui-desktop/src/main/java/forge/view/arcane/ListCardArea.java +++ b/forge-gui-desktop/src/main/java/forge/view/arcane/ListCardArea.java @@ -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 cardList; - private static ArrayList moveableCards; + private static ArrayList cardList; + private static ArrayList 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 cardList0, final List moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) { + public static ListCardArea show(final CMatchUI matchUI, final String title0, final List cardList0, final List moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) { if (storedArea==null) { storedArea = new ListCardArea(matchUI); } - cardList = new ArrayList(cardList0); - moveableCards = new ArrayList(); // make sure moveable cards are in cardlist - for ( Card card : moveableCards0 ) { + cardList = new ArrayList(cardList0); + moveableCards = new ArrayList(); // 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 cardList0, final List moveableCards0, final boolean toTop0, final boolean toBottom0, final boolean toAnywhere0) { + public ListCardArea(final CMatchUI matchUI, final String title0, final List cardList0, final List 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(cardList0); // this is modified - pfps - is there a better way? - moveableCards = new ArrayList(moveableCards0); + cardList = new ArrayList(cardList0); // this is modified - pfps - is there a better way? + moveableCards = new ArrayList(moveableCards0); title = title0; toTop = toTop0; toBottom = toBottom0; @@ -111,15 +103,7 @@ public class ListCardArea extends FloatingCardArea { storedArea = this; } - protected Iterable getCards() { - ArrayList result = new ArrayList(); - for ( Card c : cardList ) { - result.add(c.getView()); - } - return result; - } - - public List getCardList() { + public List 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); diff --git a/forge-gui-mobile/src/forge/screens/match/MatchController.java b/forge-gui-mobile/src/forge/screens/match/MatchController.java index 789fa67d32c..68445b75feb 100644 --- a/forge-gui-mobile/src/forge/screens/match/MatchController.java +++ b/forge-gui-mobile/src/forge/screens/match/MatchController.java @@ -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 manipulateCardList(final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { + public List manipulateCardList(final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { System.err.println("Not implemented yet - should never be called"); return null; } diff --git a/forge-gui/src/main/java/forge/interfaces/IGuiGame.java b/forge-gui/src/main/java/forge/interfaces/IGuiGame.java index 5e60457fb8d..b36cce98e73 100644 --- a/forge-gui/src/main/java/forge/interfaces/IGuiGame.java +++ b/forge-gui/src/main/java/forge/interfaces/IGuiGame.java @@ -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 chooseEntitiesForEffect(String title, List 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 manipulateCardList(String title, final List cards, final List manipulable, boolean toTop, boolean toBottom, boolean toAnywhere); + List manipulateCardList(String title, final List cards, final List manipulable, boolean toTop, boolean toBottom, boolean toAnywhere); void setCard(CardView card); void setPlayerAvatar(LobbyPlayer player, IHasIcon ihi); diff --git a/forge-gui/src/main/java/forge/net/server/NetGuiGame.java b/forge-gui/src/main/java/forge/net/server/NetGuiGame.java index 069f3302d4c..c99368a4e07 100644 --- a/forge-gui/src/main/java/forge/net/server/NetGuiGame.java +++ b/forge-gui/src/main/java/forge/net/server/NetGuiGame.java @@ -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 manipulateCardList(final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { + public List manipulateCardList(final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { return sendAndWait(ProtocolMethod.manipulateCardList, title, cards, manipulable, toTop, toBottom, toAnywhere); } diff --git a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java index 28ace52e11a..8f2b7fff928 100644 --- a/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java +++ b/forge-gui/src/main/java/forge/player/PlayerControllerHuman.java @@ -737,8 +737,26 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont } } + public List manipulateCardList(final String title, final List cards, final List manipulable, final boolean toTop, final boolean toBottom, final boolean toAnywhere) { + ArrayList cardViews = new ArrayList(); + for ( Card c : cards ) { cardViews.add(c.getView()); } + ArrayList manipulableViews = new ArrayList(); + for ( Card c : cards ) { manipulableViews.add(c.getView()); } + Iterable result = getGui().manipulateCardList(title, cardViews, manipulableViews, toTop, toBottom, toAnywhere); + List resultCards = new ArrayList(); + for ( CardView cv : result ) { + for ( Card card : cards ) { + if ( cv == card.getView() ) { + resultCards.add(card); + break; + } + } + } + return resultCards; + } + public ImmutablePair arrangeForMove(final String title, final List cards, final List manipulable, final boolean topOK, final boolean bottomOK) { - List result = getGui().manipulateCardList("Move cards to top or bottom of library", cards, manipulable, topOK, bottomOK, false); + List 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