Commit d3812514 authored by Michael Kamensky's avatar Michael Kamensky

Merge branch 'master' into 'master'

code cleanup for moveable card displays; add movement by clicking to display-based scry

See merge request core-developers/forge!1276
parents f00e759a 3749f2a5
......@@ -285,25 +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 {
ListCardArea tempArea = new ListCardArea(gui,title,cards,manipulable,toTop,toBottom,toAnywhere);
public List<CardView> call() throws Exception {
ListCardArea tempArea = ListCardArea.show(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();
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;
......@@ -101,7 +100,7 @@ import forge.util.ITriggerEvent;
import forge.util.gui.SOptionPane;
import forge.view.FView;
import forge.view.arcane.CardPanel;
import forge.view.arcane.FloatingCardArea;
import forge.view.arcane.FloatingZone;
import forge.match.input.*;
/**
......@@ -401,7 +400,7 @@ public final class CMatchUI
break;
default:
updateZones = true;
FloatingCardArea.refresh(owner, zone);
FloatingZone.refresh(owner, zone);
break;
}
}
......@@ -437,7 +436,7 @@ public final class CMatchUI
break;
case Hand: // controller hand always shown
if (controller != player) {
FloatingCardArea.show(this,player,zone);
FloatingZone.show(this,player,zone);
}
break;
case Library:
......@@ -445,7 +444,7 @@ public final class CMatchUI
case Exile:
case Flashback:
case Command:
FloatingCardArea.show(this,player,zone);
FloatingZone.show(this,player,zone);
break;
default:
break;
......@@ -469,7 +468,7 @@ public final class CMatchUI
case Exile:
case Flashback:
case Command:
FloatingCardArea.hide(this,player,zone);
FloatingZone.hide(this,player,zone);
break;
default:
break;
......@@ -519,7 +518,7 @@ public final class CMatchUI
}
break;
default:
FloatingCardArea.refresh(c.getController(),zone); // in case the card is visible in the zone
FloatingZone.refresh(c.getController(),zone); // in case the card is visible in the zone
break;
}
}
......@@ -559,7 +558,7 @@ public final class CMatchUI
layoutControl.initialize();
layoutControl.update();
}
FloatingCardArea.closeAll();
FloatingZone.closeAll();
}
@Override
......@@ -617,7 +616,7 @@ public final class CMatchUI
case Exile:
case Graveyard:
case Library:
return FloatingCardArea.getCardPanel(this, card);
return FloatingZone.getCardPanel(this, card);
default:
break;
}
......@@ -728,7 +727,7 @@ public final class CMatchUI
@Override
public void finishGame() {
FloatingCardArea.closeAll(); //ensure floating card areas cleared and closed after the game
FloatingZone.closeAll(); //ensure floating card areas cleared and closed after the game
final GameView gameView = getGameView();
if (hasLocalPlayers() || gameView.isMatchOver()) {
new ViewWinLose(gameView, this).show();
......@@ -842,7 +841,7 @@ public final class CMatchUI
} else {
final ZoneType zone = hostCard.getZone();
if (ImmutableList.of(ZoneType.Command, ZoneType.Exile, ZoneType.Graveyard, ZoneType.Library).contains(zone)) {
FloatingCardArea.show(this, hostCard.getController(), zone);
FloatingZone.show(this, hostCard.getController(), zone);
}
menuParent = panel.getParent();
x = triggerEvent.getX();
......@@ -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);
}
......
......@@ -2,7 +2,7 @@ package forge.screens.match;
import forge.game.player.PlayerView;
import forge.game.zone.ZoneType;
import forge.view.arcane.FloatingCardArea;
import forge.view.arcane.FloatingZone;
/**
* Receives click and programmatic requests for viewing data stacks in the
......@@ -27,6 +27,6 @@ public final class ZoneAction implements Runnable {
@Override
public void run() {
FloatingCardArea.showOrHide(matchUI, player, zone);
FloatingZone.showOrHide(matchUI, player, zone);
}
}
\ No newline at end of file
}
/*
* Forge: Play Magic: the Gathering.
* Copyright (C) 2011 Nate
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package forge.view.arcane;
import java.awt.Component;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ScrollPaneConstants;
import forge.assets.FSkinProp;
import forge.game.card.CardView;
import forge.game.player.PlayerView;
import forge.game.zone.ZoneType;
import forge.properties.ForgePreferences.FPref;
import forge.screens.match.CMatchUI;
import forge.toolbox.FScrollPane;
import forge.toolbox.FSkin;
//import forge.util.collect.FCollectionView;
import forge.util.Lang;
import forge.view.FDialog;
public class FloatingZone extends FloatingCardArea {
private static final long serialVersionUID = 1927906492186378596L;
private static final Map<Integer, FloatingZone> floatingAreas = new HashMap<Integer, FloatingZone>();
private static int getKey(final PlayerView player, final ZoneType zone) {
return 40 * player.getId() + zone.hashCode();
}
public static void showOrHide(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
final FloatingZone cardArea = _init(matchUI, player, zone);
cardArea.showOrHideWindow();
}
public static void show(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
final FloatingZone cardArea = _init(matchUI, player, zone);
cardArea.showWindow();
}
public static void hide(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
final FloatingZone cardArea = _init(matchUI, player, zone);
cardArea.hideWindow();
}
private static FloatingZone _init(final CMatchUI matchUI, final PlayerView player, final ZoneType zone) {
final int key = getKey(player, zone);
FloatingZone cardArea = floatingAreas.get(key);
if (cardArea == null || cardArea.getMatchUI() != matchUI) {
cardArea = new FloatingZone(matchUI, player, zone);
floatingAreas.put(key, cardArea);
} else {
cardArea.setPlayer(player); //ensure player is updated if needed
}
return cardArea;
}
public static CardPanel getCardPanel(final CMatchUI matchUI, final CardView card) {
final FloatingZone window = _init(matchUI, card.getController(), card.getZone());
return window.getCardPanel(card.getId());
}
public static void refresh(final PlayerView player, final ZoneType zone) {
FloatingZone cardArea = floatingAreas.get(getKey(player, zone));
if (cardArea != null) {
cardArea.setPlayer(player); //ensure player is updated if needed
cardArea.refresh();
}
//refresh flashback zone when graveyard, library, or exile zones updated
switch (zone) {
case Graveyard:
case Library:
case Exile:
refresh(player, ZoneType.Flashback);
break;
default:
break;
}
}
public static void closeAll() {
for (final FloatingZone cardArea : floatingAreas.values()) {
cardArea.window.setVisible(false);
}
floatingAreas.clear();
}
private final ZoneType zone;
private PlayerView player;
@SuppressWarnings("serial")
private final FDialog window = new FDialog(false, true, "0") {
@Override
public void setLocationRelativeTo(Component c) {
//don't change location this way if dialog has already been shown or location was loaded from preferences
if (hasBeenShown || locLoaded) { return; }
super.setLocationRelativeTo(c);
}
@Override
public void setVisible(boolean b0) {
if (isVisible() == b0) { return; }
if (!b0 && hasBeenShown && locPref != null) {
//update preference before hiding window, as otherwise its location will be 0,0
prefs.setPref(locPref,
getX() + COORD_DELIM + getY() + COORD_DELIM +
getWidth() + COORD_DELIM + getHeight());
//don't call prefs.save(), instead allowing them to be saved when match ends
}
super.setVisible(b0);
if (b0) {
refresh();
hasBeenShown = true;
}
}
};
protected FDialog getWindow() {
return window;
}
protected Iterable<CardView> getCards() {
return player.getCards(zone);
}
private FloatingZone(final CMatchUI matchUI, final PlayerView player0, final ZoneType zone0) {
super(matchUI, new FScrollPane(false, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
window.add(getScrollPane(), "grow, push");
getScrollPane().setViewportView(this);
setOpaque(false);
switch (zone0) {
case Exile:
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_EXILE));
break;
case Graveyard:
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_GRAVEYARD));
break;
case Hand:
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_HAND));
break;
case Library:
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_LIBRARY));
break;
case Flashback:
window.setIconImage(FSkin.getImage(FSkinProp.IMG_ZONE_FLASHBACK));
break;
default:
locPref = null;
break;
}
zone = zone0;
setPlayer(player0);
setVertical(true);
}
private void setPlayer(PlayerView player0) {
if (player == player0) { return; }
player = player0;
title = Lang.getPossessedObject(player0.getName(), zone.name()) + " (%d)";
boolean isAi = player0.isAI();
switch (zone) {
case Exile:
locPref = isAi ? FPref.ZONE_LOC_AI_EXILE : FPref.ZONE_LOC_HUMAN_EXILE;
break;
case Graveyard:
locPref = isAi ? FPref.ZONE_LOC_AI_GRAVEYARD : FPref.ZONE_LOC_HUMAN_GRAVEYARD;
break;
case Hand:
locPref = isAi ? FPref.ZONE_LOC_AI_HAND : FPref.ZONE_LOC_HUMAN_HAND;
break;
case Library:
locPref = isAi ? FPref.ZONE_LOC_AI_LIBRARY : FPref.ZONE_LOC_HUMAN_LIBRARY;
break;
case Flashback:
locPref = isAi ? FPref.ZONE_LOC_AI_FLASHBACK : FPref.ZONE_LOC_HUMAN_FLASHBACK;
break;
default:
locPref = null;
break;
}
}
}
......@@ -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 : manipulable ) { 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
}
}
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