Commit 09fc3ae6 authored by Peter Patel-Schneider's avatar Peter Patel-Schneider

add new GUI interface allowing cards to be moved around in a list and use for...

add new GUI interface allowing cards to be moved around in a list and use for arrangeForScry if preference UI_SELECT_FROM_CARD_DISPLAYS is set
parent 69502dd9
......@@ -86,7 +86,7 @@ public class Localizer {
resourceBundle = ResourceBundle.getBundle(languageRegionID, new Locale(splitLocale[0], splitLocale[1]), loader);
} catch (NullPointerException | MissingResourceException e) {
//If the language can't be loaded, default to US English
resourceBundle = ResourceBundle.getBundle("en-GB", new Locale("en", "GB"), loader);
resourceBundle = ResourceBundle.getBundle("en-US", new Locale("en", "US"), loader);
e.printStackTrace();
}
......
......@@ -29,7 +29,7 @@ import forge.item.PaperCard;
import forge.model.FModel;
import forge.screens.match.CMatchUI;
import forge.toolbox.FOptionPane;
import forge.view.arcane.ListCardArea;
public class GuiChoose {
......@@ -285,5 +285,31 @@ public class GuiChoose {
return null;
}
public static List<Card> manipulateCardList(final CMatchUI gui, final String title, final List<Card> cards, final List<Card> manipulable,
final boolean toTop, final boolean toBottom, final boolean toAnywhere) {
final Callable<List<Card>> callable = new Callable<List<Card>>() {
@Override
public List<Card> call() throws Exception {
ListCardArea tempArea = new ListCardArea(gui,title,cards,manipulable,toTop,toBottom,toAnywhere);
// tempArea.pack();
// window? tempArea.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
tempArea.show();
// tempArea.dispose();
//try { Thread.sleep(1000); } catch(InterruptedException ex) { }
final List<Card> cardList = tempArea.getCardList();
return cardList;
}
};
final FutureTask<List<Card>> ft = new FutureTask<List<Card>>(callable);
FThreads.invokeInEdtAndWait(ft);
try {
List<Card> result = ft.get();
return result;
} catch (final Exception e) { // we have waited enough
e.printStackTrace();
}
return null;
}
}
......@@ -51,6 +51,7 @@ 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;
......@@ -1003,6 +1004,11 @@ public final class CMatchUI
return (List<GameEntityView>) order(title,"Selected", min, max, optionList, null, null, false);
}
@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) {
return GuiChoose.manipulateCardList(this, title, cards, manipulable, toTop, toBottom, toAnywhere);
}
@Override
public void setPlayerAvatar(final LobbyPlayer player, final IHasIcon ihi) {
avatarImages.put(player.getName(), ihi.getIconImageKey());
......
......@@ -246,8 +246,8 @@ public class CardArea extends CardPanelContainer implements CardPanelMouseListen
dragPanel.setDisplayEnabled(false);
CardPanel.setDragAnimationPanel(new CardPanel(dragPanel.getMatchUI(), dragPanel.getCard()));
final JFrame frame = (JFrame) SwingUtilities.windowForComponent(this);
final JLayeredPane layeredPane = frame.getLayeredPane();
final RootPaneContainer frame = (RootPaneContainer) SwingUtilities.windowForComponent(this);
final JLayeredPane layeredPane = frame.getLayeredPane();
layeredPane.add(CardPanel.getDragAnimationPanel());
layeredPane.moveToFront(CardPanel.getDragAnimationPanel());
final Point p = SwingUtilities.convertPoint(this, this.mouseDragStartX, this.mouseDragStartY, layeredPane);
......
......@@ -182,6 +182,10 @@ public abstract class CardPanelContainer extends SkinnedPanel {
});
}
protected boolean cardPanelDraggable(final CardPanel panel) {
return true;
}
private MouseMotionListener setupMotionMouseListener() {
final MouseMotionListener mml = new MouseMotionListener() {
@Override
......@@ -207,20 +211,23 @@ public abstract class CardPanelContainer extends SkinnedPanel {
if (panel != mouseDownPanel) {
return;
}
if (intialMouseDragX == -1) {
intialMouseDragX = x;
intialMouseDragY = y;
return;
}
if ((Math.abs(x - intialMouseDragX) < CardPanelContainer.DRAG_SMUDGE)
if (cardPanelDraggable(panel)) { // allow for non-draggable cards
if (intialMouseDragX == -1) {
intialMouseDragX = x;
intialMouseDragY = y;
return;
}
if ((Math.abs(x - intialMouseDragX) < CardPanelContainer.DRAG_SMUDGE)
&& (Math.abs(y - intialMouseDragY) < CardPanelContainer.DRAG_SMUDGE)) {
return;
}
mouseDownPanel = null;
setMouseDragPanel(panel);
mouseDragOffsetX = panel.getX() - intialMouseDragX;
mouseDragOffsetY = panel.getY() - intialMouseDragY;
mouseDragStart(getMouseDragPanel(), evt);
return;
}
mouseDownPanel = null;
setMouseDragPanel(panel);
mouseDragOffsetX = panel.getX() - intialMouseDragX;
mouseDragOffsetY = panel.getY() - intialMouseDragY;
mouseDragStart(getMouseDragPanel(), evt);
}
}
@Override
......@@ -453,4 +460,4 @@ public abstract class CardPanelContainer extends SkinnedPanel {
this.layoutListeners.add(listener);
}
}
\ No newline at end of file
}
......@@ -29,6 +29,7 @@ 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;
......@@ -520,6 +521,11 @@ public class MatchController extends AbstractGuiGame {
return SGuiChoose.order(title, "Selected", min, max, (List<GameEntityView>) optionList, null);
}
@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) {
return null; // pfps not implemented yet
}
@Override
public void setCard(final CardView card) {
// doesn't need to do anything
......
......@@ -11,6 +11,7 @@ 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;
......@@ -147,6 +148,10 @@ public interface IGuiGame {
List<PaperCard> sideboard(CardPool sideboard, CardPool main);
GameEntityView chooseSingleEntityForEffect(String title, List<? extends GameEntityView> optionList, DelayedReveal delayedReveal, boolean isOptional);
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);
void setCard(CardView card);
void setPlayerAvatar(LobbyPlayer player, IHasIcon ihi);
boolean openZones(Collection<ZoneType> zones, Map<PlayerView, Object> players);
......
......@@ -68,6 +68,7 @@ public enum ProtocolMethod {
sideboard (Mode.SERVER, List.class, CardPool.class, CardPool.class),
chooseSingleEntityForEffect(Mode.SERVER, GameEntityView.class, String.class, List.class, DelayedReveal.class, Boolean.TYPE),
chooseEntitiesForEffect(Mode.SERVER, GameEntityView.class, String.class, List.class, Integer.TYPE, Integer.TYPE, DelayedReveal.class),
manipulateCardList (Mode.SERVER, List.class, String.class, List.class, List.class, Boolean.TYPE, Boolean.TYPE, Boolean.TYPE),
setCard (Mode.SERVER, Void.TYPE, CardView.class),
// TODO case "setPlayerAvatar":
openZones (Mode.SERVER, Boolean.TYPE, Collection/*ZoneType*/.class, Map/*PlayerView,Object*/.class),
......
......@@ -11,6 +11,7 @@ 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;
......@@ -248,6 +249,11 @@ public class NetGuiGame extends AbstractGuiGame {
return sendAndWait(ProtocolMethod.chooseEntitiesForEffect, title, optionList, min, max, delayedReveal);
}
@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) {
return sendAndWait(ProtocolMethod.manipulateCardList, title, cards, manipulable, toTop, toBottom, toAnywhere);
}
@Override
public void setCard(final CardView card) {
updateGameView();
......
......@@ -349,8 +349,9 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
private boolean useSelectCardsInput(final FCollectionView<? extends GameEntity> sourceList) {
// if UI_SELECT_FROM_ZONES not set use InputSelect only for battlefield and player hand
// if UI_SELECT_FROM_ZONES set use InputSelect for any zone that can be shown
// if UI_SELECT_FROM_CARD_DISPLAYS not set use InputSelect only for battlefield and player hand
// if UI_SELECT_FROM_CARD_DISPLAYS set use InputSelect for any zone that can be shown
if ( FThreads.isGuiThread() ) { return false; } // also can't use InputSelect from GUI thread (e.g., DevMode Tutor)
for (final GameEntity c : sourceList) {
if (c instanceof Player) {
continue;
......@@ -361,7 +362,7 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
final Zone cz = ((Card) c).getZone();
final boolean useUiPointAtCard =
cz != null &&
FModel.getPreferences().getPrefBoolean(FPref.UI_SELECT_FROM_ZONES) ?
FModel.getPreferences().getPrefBoolean(FPref.UI_SELECT_FROM_CARD_DISPLAYS) ?
(cz.is(ZoneType.Battlefield) || cz.is(ZoneType.Hand) || cz.is(ZoneType.Library) ||
cz.is(ZoneType.Graveyard) || cz.is(ZoneType.Exile) || cz.is(ZoneType.Flashback) || cz.is(ZoneType.Command)) :
(cz.is(ZoneType.Hand) && cz.getPlayer() == player || cz.is(ZoneType.Battlefield));
......@@ -736,31 +737,58 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
}
}
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);
CardCollection toBottom = new CardCollection();
CardCollection toTop = new CardCollection();
for (int i = 0; manipulable.contains(result.get(i)) && i<cards.size(); i++ ) {
toTop.add(result.get(i));
}
if (toTop.size() < cards.size()) { // the top isn't everything
for (int i = result.size()-1; manipulable.contains(result.get(i)); i-- ) {
toBottom.add(result.get(i));
}
}
return ImmutablePair.of(toTop,toBottom);
}
@Override
public ImmutablePair<CardCollection, CardCollection> arrangeForScry(final CardCollection topN) {
CardCollection toBottom = null;
CardCollection toTop = null;
tempShowCards(topN);
if (topN.size() == 1) {
if (willPutCardOnTop(topN.get(0))) {
toTop = topN;
} else {
toBottom = topN;
}
} else {
toBottom = game.getCardList(getGui().many("Select cards to be put on the bottom of your library",
"Cards to put on the bottom", -1, CardView.getCollection(topN), null));
topN.removeAll((Collection<?>) toBottom);
if (topN.isEmpty()) {
toTop = null;
} else if (topN.size() == 1) {
toTop = topN;
} else {
toTop = game.getCardList(getGui().order("Arrange cards to be put on top of your library",
"Top of Library", CardView.getCollection(topN), null));
}
}
if ( FModel.getPreferences().getPrefBoolean(FPref.UI_SELECT_FROM_CARD_DISPLAYS) ) {
ArrayList<Card> cardList = new ArrayList<Card>(); // pfps there must be a better way
for (final Card card : player.getCardsIn(ZoneType.Library)) {
cardList.add(card);
}
ImmutablePair<CardCollection, CardCollection> result =
arrangeForMove("Move cards to top or bottom of library", cardList, topN, true, true);
System.out.print("Arrange "); System.out.println(result);
toTop = result.getLeft();
toBottom = result.getRight();
} else {
if (topN.size() == 1) {
if (willPutCardOnTop(topN.get(0))) {
toTop = topN;
} else {
toBottom = topN;
}
} else {
toBottom = game.getCardList(getGui().many("Select cards to be put on the bottom of your library",
"Cards to put on the bottom", -1, CardView.getCollection(topN), null));
topN.removeAll((Collection<?>) toBottom);
if (topN.isEmpty()) {
toTop = null;
} else if (topN.size() == 1) {
toTop = topN;
} else {
toTop = game.getCardList(getGui().order("Arrange cards to be put on top of your library",
"Top of Library", CardView.getCollection(topN), null));
}
}
}
endTempShowCards();
return ImmutablePair.of(toTop, toBottom);
}
......
......@@ -125,7 +125,7 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
UI_DISABLE_IMAGES_EFFECT_CARDS("false"),
UI_ALLOW_ORDER_GRAVEYARD_WHEN_NEEDED ("Never"),
UI_DEFAULT_FONT_SIZE("12"),
UI_SELECT_FROM_ZONES("true"),
UI_SELECT_FROM_CARD_DISPLAYS("true"),
UI_FOR_TOUCHSCREN("false"),
UI_VIBRATE_ON_LIFE_LOSS("true"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment