Fix the refactored GUI code so that games can now be played.

This commit is contained in:
elcnesh
2014-09-04 18:08:22 +00:00
parent 2d1f2dc1ae
commit 1f62869b24
49 changed files with 330 additions and 201 deletions

View File

@@ -21,7 +21,8 @@ public class MagicColor {
public static final byte ALL_COLORS = BLACK | BLUE | WHITE | RED | GREEN; public static final byte ALL_COLORS = BLACK | BLUE | WHITE | RED | GREEN;
public static final int NUMBER_OR_COLORS = 5; public static final int NUMBER_OR_COLORS = 5;
public static final byte[] WUBRG = new byte[] { WHITE, BLUE, BLACK, RED, GREEN }; public static final byte[] WUBRG = new byte[] { WHITE, BLUE, BLACK, RED, GREEN };
public static final byte[] WUBRGC = new byte[] { WHITE, BLUE, BLACK, RED, GREEN, COLORLESS };
public static byte fromName(String s) { public static byte fromName(String s) {
if( s == null ) return 0; if( s == null ) return 0;

View File

@@ -92,7 +92,7 @@ final class ImageLoader extends CacheLoader<String, BufferedImage> {
return ImageIO.read(file); return ImageIO.read(file);
} }
catch (IOException ex) { catch (IOException ex) {
BugReporter.reportException(ex, "Could not read image file " + file.getAbsolutePath() + " "); BugReporter.reportException(ex, GuiBase.getInterface(), "Could not read image file " + file.getAbsolutePath() + " ");
break; break;
} }
} }

View File

@@ -19,7 +19,6 @@ package forge;
import forge.control.FControl; import forge.control.FControl;
import forge.model.FModel; import forge.model.FModel;
import forge.properties.ForgeConstants;
import forge.properties.ForgeProfileProperties; import forge.properties.ForgeProfileProperties;
import forge.view.FView; import forge.view.FView;
@@ -48,7 +47,6 @@ public final class Singletons {
initialized = true; initialized = true;
} }
ForgeConstants.init(GuiBase.getInterface());
ForgeProfileProperties.init(GuiBase.getInterface()); ForgeProfileProperties.init(GuiBase.getInterface());
if (withUi) { if (withUi) {

View File

@@ -124,7 +124,7 @@ public enum FControl implements KeyEventDispatcher {
EXIT_FORGE EXIT_FORGE
} }
private final SoundSystem soundSystem = new SoundSystem(GuiBase.getInterface()); private SoundSystem soundSystem;
/** /**
* <p> * <p>
@@ -219,6 +219,8 @@ public enum FControl implements KeyEventDispatcher {
// Preloads skin components (using progress bar). // Preloads skin components (using progress bar).
FSkin.loadFull(true); FSkin.loadFull(true);
this.soundSystem = new SoundSystem(GuiBase.getInterface());
this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts(); this.shortcuts = KeyboardShortcuts.attachKeyboardShortcuts();
this.display = FView.SINGLETON_INSTANCE.getLpnDocument(); this.display = FView.SINGLETON_INSTANCE.getLpnDocument();
@@ -423,7 +425,9 @@ public enum FControl implements KeyEventDispatcher {
inputQueue.onGameOver(false); //release any waiting input, effectively passing priority inputQueue.onGameOver(false); //release any waiting input, effectively passing priority
} }
playbackControl.onGameStopRequested(); if (playbackControl != null) {
playbackControl.onGameStopRequested();
}
} }
private InputQueue inputQueue; private InputQueue inputQueue;
@@ -447,7 +451,9 @@ public enum FControl implements KeyEventDispatcher {
return; //TODO: See if it's possible to run multiple games at once without crashing return; //TODO: See if it's possible to run multiple games at once without crashing
} }
setPlayerName(match.getPlayers()); setPlayerName(match.getPlayers());
final Game game = match.createGame(); this.game = match.createGame();
inputQueue = new InputQueue(game);
final LobbyPlayer me = getGuiPlayer(); final LobbyPlayer me = getGuiPlayer();
for (final Player p : game.getPlayers()) { for (final Player p : game.getPlayers()) {
if (p.getLobbyPlayer().equals(me)) { if (p.getLobbyPlayer().equals(me)) {
@@ -457,7 +463,6 @@ public enum FControl implements KeyEventDispatcher {
} }
} }
inputQueue = new InputQueue(GuiBase.getInterface(), game);
attachToGame(this.gameView); attachToGame(this.gameView);
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game. // It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
@@ -526,7 +531,7 @@ public enum FControl implements KeyEventDispatcher {
game0.subscribeToEvents(fcVisitor); game0.subscribeToEvents(fcVisitor);
// Add playback controls to match if needed // Add playback controls to match if needed
if (localPlayer != null) { if (localPlayer == null) {
// Create dummy controller // Create dummy controller
final PlayerControllerHuman controller = final PlayerControllerHuman controller =
new PlayerControllerLocal(game, null, humanLobbyPlayer, GuiBase.getInterface()); new PlayerControllerLocal(game, null, humanLobbyPlayer, GuiBase.getInterface());

View File

@@ -30,6 +30,7 @@ import forge.toolbox.FButton;
import forge.toolbox.FOptionPane; import forge.toolbox.FOptionPane;
import forge.view.CardView; import forge.view.CardView;
import forge.view.FDialog; import forge.view.FDialog;
import forge.view.ViewUtil;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class FDeckViewer extends FDialog { public class FDeckViewer extends FDialog {
@@ -61,7 +62,7 @@ public class FDeckViewer extends FDialog {
return new ImageView<PaperCard>(this, model0) { return new ImageView<PaperCard>(this, model0) {
@Override @Override
protected void showHoveredItem(PaperCard item) { protected void showHoveredItem(PaperCard item) {
final CardView card = CardView.getCardForUi(item); final CardView card = ViewUtil.getCardForUi(item);
if (card == null) { return; } if (card == null) { return; }
cardDetail.setCard(card); cardDetail.setCard(card);
@@ -77,7 +78,7 @@ public class FDeckViewer extends FDialog {
final IPaperCard paperCard = cardManager.getSelectedItem(); final IPaperCard paperCard = cardManager.getSelectedItem();
if (paperCard == null) { return; } if (paperCard == null) { return; }
final CardView card = CardView.getCardForUi(paperCard); final CardView card = ViewUtil.getCardForUi(paperCard);
if (card == null) { return; } if (card == null) { return; }
cardDetail.setCard(card); cardDetail.setCard(card);

View File

@@ -37,8 +37,8 @@ import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FButton; import forge.toolbox.FButton;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.view.CardView;
import forge.view.FDialog; import forge.view.FDialog;
import forge.view.ViewUtil;
/** /**
* A simple class that shows a list of cards in a dialog with preview in its * A simple class that shows a list of cards in a dialog with preview in its
@@ -189,7 +189,7 @@ public class BoxedProductCardListViewer extends FDialog {
// (String) jList.getSelectedValue(); // (String) jList.getSelectedValue();
if ((row >= 0) && (row < BoxedProductCardListViewer.this.list.size())) { if ((row >= 0) && (row < BoxedProductCardListViewer.this.list.size())) {
final PaperCard cp = BoxedProductCardListViewer.this.list.get(row); final PaperCard cp = BoxedProductCardListViewer.this.list.get(row);
BoxedProductCardListViewer.this.detail.setCard(CardView.getCardForUi(cp)); BoxedProductCardListViewer.this.detail.setCard(ViewUtil.getCardForUi(cp));
BoxedProductCardListViewer.this.picture.setCard(cp); BoxedProductCardListViewer.this.picture.setCard(cp);
} }
} }

View File

@@ -45,6 +45,7 @@ import forge.toolbox.FSkin.SkinnedPanel;
import forge.view.CardView; import forge.view.CardView;
import forge.view.CardView.CardStateView; import forge.view.CardView.CardStateView;
import forge.view.FDialog; import forge.view.FDialog;
import forge.view.ViewUtil;
/** /**
* The class CardDetailPanel. Shows the details of a card. * The class CardDetailPanel. Shows the details of a card.
@@ -131,7 +132,7 @@ public class CardDetailPanel extends SkinnedPanel {
powerToughnessLabel.setVisible(false); powerToughnessLabel.setVisible(false);
idLabel.setText(""); idLabel.setText("");
cdArea.setText(CardDetailUtil.getItemDescription(item)); cdArea.setText(CardDetailUtil.getItemDescription(item));
this.updateBorder(item instanceof IPaperCard ? CardView.getCardForUi((IPaperCard)item).getState() : null, false); this.updateBorder(item instanceof IPaperCard ? ViewUtil.getCardForUi((IPaperCard)item).getState() : null, false);
String set = item.getEdition(); String set = item.getEdition();
setInfoLabel.setText(set); setInfoLabel.setText(set);

View File

@@ -37,8 +37,8 @@ import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FButton; import forge.toolbox.FButton;
import forge.toolbox.FLabel; import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.view.CardView;
import forge.view.FDialog; import forge.view.FDialog;
import forge.view.ViewUtil;
/** /**
* A simple class that shows a list of cards in a dialog with preview in its * A simple class that shows a list of cards in a dialog with preview in its
@@ -172,7 +172,7 @@ public class CardListViewer extends FDialog {
// (String) jList.getSelectedValue(); // (String) jList.getSelectedValue();
if ((row >= 0) && (row < CardListViewer.this.list.size())) { if ((row >= 0) && (row < CardListViewer.this.list.size())) {
final PaperCard cp = CardListViewer.this.list.get(row); final PaperCard cp = CardListViewer.this.list.get(row);
CardListViewer.this.detail.setCard(CardView.getCardForUi(cp)); CardListViewer.this.detail.setCard(ViewUtil.getCardForUi(cp));
CardListViewer.this.picture.setCard(cp); CardListViewer.this.picture.setCard(cp);
} }
} }

View File

@@ -32,6 +32,7 @@ import forge.toolbox.FScrollPane;
import forge.view.CardView; import forge.view.CardView;
import forge.view.FDialog; import forge.view.FDialog;
import forge.view.SpellAbilityView; import forge.view.SpellAbilityView;
import forge.view.ViewUtil;
// An input box for handling the order of choices. // An input box for handling the order of choices.
// Left box has the original choices // Left box has the original choices
@@ -330,7 +331,7 @@ public class DualListBox<T> extends FDialog {
} else if (obj instanceof SpellAbilityView) { } else if (obj instanceof SpellAbilityView) {
card = ((SpellAbilityView) obj).getHostCard(); card = ((SpellAbilityView) obj).getHostCard();
} else if (obj instanceof PaperCard) { } else if (obj instanceof PaperCard) {
card = CardView.getCardForUi((IPaperCard) obj); card = ViewUtil.getCardForUi((IPaperCard) obj);
} }
GuiUtils.clearPanelSelections(); GuiUtils.clearPanelSelections();

View File

@@ -17,6 +17,7 @@
*/ */
package forge.gui; package forge.gui;
import forge.GuiBase;
import forge.UiCommand; import forge.UiCommand;
import forge.assets.FSkinProp; import forge.assets.FSkinProp;
import forge.error.BugReporter; import forge.error.BugReporter;
@@ -513,7 +514,7 @@ public class ImportDialog {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override public void run() { @Override public void run() {
_progressBar.setString("Error"); _progressBar.setString("Error");
BugReporter.reportException(e); BugReporter.reportException(e, GuiBase.getInterface());
} }
}); });
} finally { } finally {
@@ -777,7 +778,7 @@ public class ImportDialog {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override public void run() { @Override public void run() {
// we never interrupt the thread, so this is not expected to happen // we never interrupt the thread, so this is not expected to happen
BugReporter.reportException(e); BugReporter.reportException(e, GuiBase.getInterface());
} }
}); });
} }
@@ -936,7 +937,7 @@ public class ImportDialog {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override public void run() { @Override public void run() {
_progressBar.setString("Error"); _progressBar.setString("Error");
BugReporter.reportException(e); BugReporter.reportException(e, GuiBase.getInterface());
} }
}); });
} }

View File

@@ -20,6 +20,7 @@ import forge.toolbox.FSkin.SkinFont;
import forge.toolbox.FSkin.SkinImage; import forge.toolbox.FSkin.SkinImage;
import forge.toolbox.special.CardZoomer; import forge.toolbox.special.CardZoomer;
import forge.view.CardView; import forge.view.CardView;
import forge.view.ViewUtil;
import forge.view.arcane.CardPanel; import forge.view.arcane.CardPanel;
import javax.swing.*; import javax.swing.*;
@@ -232,7 +233,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
ItemInfo item = getItemAtPoint(e.getPoint()); ItemInfo item = getItemAtPoint(e.getPoint());
if (item != null && item.item instanceof IPaperCard) { if (item != null && item.item instanceof IPaperCard) {
setLockHoveredItem(true); //lock hoveredItem while zoomer open setLockHoveredItem(true); //lock hoveredItem while zoomer open
final CardView card = CardView.getCardForUi((IPaperCard) item.item); final CardView card = ViewUtil.getCardForUi((IPaperCard) item.item);
CardZoomer.SINGLETON_INSTANCE.doMouseButtonZoom(card); CardZoomer.SINGLETON_INSTANCE.doMouseButtonZoom(card);
} }
} }
@@ -1099,7 +1100,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
if (item instanceof IPaperCard) { if (item instanceof IPaperCard) {
IPaperCard paperCard = (IPaperCard)item; IPaperCard paperCard = (IPaperCard)item;
if (paperCard.isFoil()) { if (paperCard.isFoil()) {
final CardView card = CardView.getCardForUi(paperCard); final CardView card = ViewUtil.getCardForUi(paperCard);
if (card.getFoilIndex() == 0) { //if foil finish not yet established, assign a random one if (card.getFoilIndex() == 0) { //if foil finish not yet established, assign a random one
card.setRandomFoil(); card.setRandomFoil();
} }

View File

@@ -7,7 +7,6 @@ import forge.deck.DeckBase;
import forge.deck.io.DeckHtmlSerializer; import forge.deck.io.DeckHtmlSerializer;
import forge.deck.io.DeckSerializer; import forge.deck.io.DeckSerializer;
import forge.deck.io.DeckStorage; import forge.deck.io.DeckStorage;
import forge.error.BugReporter;
import forge.gui.framework.ICDoc; import forge.gui.framework.ICDoc;
import forge.item.InventoryItem; import forge.item.InventoryItem;
import forge.properties.ForgeConstants; import forge.properties.ForgeConstants;
@@ -156,7 +155,7 @@ public enum CCurrentDeck implements ICDoc {
} }
}); });
} catch (final Exception ex) { } catch (final Exception ex) {
BugReporter.reportException(ex); //BugReporter.reportException(ex);
throw new RuntimeException("Error creating new deck. " + ex); throw new RuntimeException("Error creating new deck. " + ex);
} }
} }
@@ -175,7 +174,7 @@ public enum CCurrentDeck implements ICDoc {
.setModel(DeckSerializer.fromFile(file)); .setModel(DeckSerializer.fromFile(file));
} catch (final Exception ex) { } catch (final Exception ex) {
BugReporter.reportException(ex); //BugReporter.reportException(ex);
throw new RuntimeException("Error importing deck." + ex); throw new RuntimeException("Error importing deck." + ex);
} }
} }
@@ -219,7 +218,7 @@ public enum CCurrentDeck implements ICDoc {
DeckSerializer.writeDeck(deck, filename); DeckSerializer.writeDeck(deck, filename);
controller.setModel(DeckSerializer.fromFile(filename)); //reload deck from file so everything is in sync controller.setModel(DeckSerializer.fromFile(filename)); //reload deck from file so everything is in sync
} catch (final Exception ex) { } catch (final Exception ex) {
BugReporter.reportException(ex); //BugReporter.reportException(ex);
throw new RuntimeException("Error exporting deck." + ex); throw new RuntimeException("Error exporting deck." + ex);
} }
} }
@@ -237,7 +236,7 @@ public enum CCurrentDeck implements ICDoc {
((DeckController<Deck>) CDeckEditorUI.SINGLETON_INSTANCE ((DeckController<Deck>) CDeckEditorUI.SINGLETON_INSTANCE
.getCurrentEditorController().getDeckController()).getModel(), filename); .getCurrentEditorController().getDeckController()).getModel(), filename);
} catch (final Exception ex) { } catch (final Exception ex) {
BugReporter.reportException(ex); //BugReporter.reportException(ex);
throw new RuntimeException("Error exporting deck." + ex); throw new RuntimeException("Error exporting deck." + ex);
} }
} }

View File

@@ -75,7 +75,7 @@ import forge.toolbox.FTextField;
import forge.util.Lang; import forge.util.Lang;
import forge.util.MyRandom; import forge.util.MyRandom;
import forge.util.NameGenerator; import forge.util.NameGenerator;
import forge.view.CardView; import forge.view.ViewUtil;
/** /**
* Assembles Swing components of constructed submenu singleton. * Assembles Swing components of constructed submenu singleton.
@@ -1228,7 +1228,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
if (obj instanceof PaperCard) { if (obj instanceof PaperCard) {
pp.setVanguardButtonText(((PaperCard) obj).getName()); pp.setVanguardButtonText(((PaperCard) obj).getName());
cdp.setCard(CardView.getCardForUi((PaperCard) obj)); cdp.setCard(ViewUtil.getCardForUi((PaperCard) obj));
cdp.setVisible(true); cdp.setVisible(true);
refreshPanels(false, true); refreshPanels(false, true);
} }

View File

@@ -35,7 +35,7 @@ import forge.toolbox.FList;
import forge.toolbox.FPanel; import forge.toolbox.FPanel;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.toolbox.FSkin; import forge.toolbox.FSkin;
import forge.view.CardView; import forge.view.ViewUtil;
/** /**
* A simple JPanel that shows three columns: card list, pic, and description.. * A simple JPanel that shows three columns: card list, pic, and description..
@@ -112,7 +112,7 @@ public class QuestWinLoseCardViewer extends FPanel {
// (String) jList.getSelectedValue(); // (String) jList.getSelectedValue();
if ((row >= 0) && (row < QuestWinLoseCardViewer.this.list.size())) { if ((row >= 0) && (row < QuestWinLoseCardViewer.this.list.size())) {
final PaperCard cp = QuestWinLoseCardViewer.this.list.get(row); final PaperCard cp = QuestWinLoseCardViewer.this.list.get(row);
QuestWinLoseCardViewer.this.detail.setCard(CardView.getCardForUi(cp)); QuestWinLoseCardViewer.this.detail.setCard(ViewUtil.getCardForUi(cp));
QuestWinLoseCardViewer.this.picture.setCard(cp); QuestWinLoseCardViewer.this.picture.setCard(cp);
} }
} }

View File

@@ -32,7 +32,7 @@ import java.util.Map;
import javax.swing.JPanel; import javax.swing.JPanel;
import org.testng.collections.Lists; import com.google.common.collect.Lists;
import forge.Singletons; import forge.Singletons;
import forge.gui.framework.FScreen; import forge.gui.framework.FScreen;
@@ -245,6 +245,7 @@ public enum TargetingOverlay {
} }
for (final CardView attackingCard : combat.getAttackers()) { for (final CardView attackingCard : combat.getAttackers()) {
final Iterable<CardView> cards = combat.getBlockers(attackingCard); final Iterable<CardView> cards = combat.getBlockers(attackingCard);
if (cards == null) continue;
for (final CardView blockingCard : cards) { for (final CardView blockingCard : cards) {
if (!attackingCard.equals(c) && !blockingCard.equals(c)) { continue; } if (!attackingCard.equals(c) && !blockingCard.equals(c)) { continue; }
arcsCombat.add(new Point[] { arcsCombat.add(new Point[] {

View File

@@ -198,13 +198,13 @@ public class VAssignDamage {
if (defender instanceof CardView) if (defender instanceof CardView)
fakeCard = (CardView)defender; fakeCard = (CardView)defender;
else if (defender instanceof PlayerView) { else if (defender instanceof PlayerView) {
fakeCard = new CardView(null, -1, true); fakeCard = new CardView(-1, true);
fakeCard.getState().setName(this.defender.toString()); fakeCard.getState().setName(this.defender.toString());
final PlayerView p = (PlayerView)defender; final PlayerView p = (PlayerView)defender;
fakeCard.setOwner(p); fakeCard.setOwner(p);
fakeCard.getState().setImageKey(CMatchUI.SINGLETON_INSTANCE.avatarImages.get(p.getLobbyPlayer())); fakeCard.getState().setImageKey(CMatchUI.SINGLETON_INSTANCE.avatarImages.get(p.getLobbyPlayer()));
} else { } else {
fakeCard = new CardView(null, -2, true); fakeCard = new CardView(-2, true);
fakeCard.getState().setName(this.defender.toString()); fakeCard.getState().setName(this.defender.toString());
} }
addPanelForDefender(pnlDefenders, fakeCard); addPanelForDefender(pnlDefenders, fakeCard);

View File

@@ -3,8 +3,8 @@ package forge.screens.match;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.util.List; import java.util.List;
import com.beust.jcommander.internal.Lists;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.gui.ForgeAction; import forge.gui.ForgeAction;
import forge.gui.GuiChoose; import forge.gui.GuiChoose;

View File

@@ -121,8 +121,12 @@ public enum CCombat implements ICDoc {
} }
} }
for (final CardView blocker : blockers) { if (blockers != null) {
display.append(" < ").append(combatantToString(blocker)).append("\n"); for (final CardView blocker : blockers) {
display.append(" < ")
.append(combatantToString(blocker))
.append("\n");
}
} }
previousBand = isBand; previousBand = isBand;
} }

View File

@@ -28,6 +28,7 @@ import forge.item.InventoryItemFromSet;
import forge.screens.match.views.VDetail; import forge.screens.match.views.VDetail;
import forge.toolbox.FMouseAdapter; import forge.toolbox.FMouseAdapter;
import forge.view.CardView; import forge.view.CardView;
import forge.view.ViewUtil;
/** /**
* Controls the card detail area in the match UI. * Controls the card detail area in the match UI.
@@ -58,7 +59,7 @@ public enum CDetail implements ICDoc {
public void showCard(final InventoryItem item) { public void showCard(final InventoryItem item) {
if (item instanceof IPaperCard) { if (item instanceof IPaperCard) {
showCard(CardView.getCardForUi((IPaperCard)item)); showCard(ViewUtil.getCardForUi((IPaperCard)item));
} else if (item instanceof InventoryItemFromSet) { } else if (item instanceof InventoryItemFromSet) {
view.getLblFlipcard().setVisible(false); view.getLblFlipcard().setVisible(false);
view.getPnlDetail().setItem((InventoryItemFromSet)item); view.getPnlDetail().setItem((InventoryItemFromSet)item);

View File

@@ -27,6 +27,8 @@ import java.util.Observable;
import javax.swing.JLayeredPane; import javax.swing.JLayeredPane;
import javax.swing.SwingUtilities; import javax.swing.SwingUtilities;
import com.google.common.collect.ImmutableList;
import forge.FThreads; import forge.FThreads;
import forge.GuiBase; import forge.GuiBase;
import forge.Singletons; import forge.Singletons;
@@ -105,7 +107,11 @@ public class CHand implements ICDoc {
} }
//update card panels in hand area //update card panels in hand area
final List<CardView> cards = player.getHandCards();
final List<CardView> cards;
synchronized (player) {
cards = ImmutableList.copyOf(player.getHandCards());
}
final List<CardPanel> placeholders = new ArrayList<CardPanel>(); final List<CardPanel> placeholders = new ArrayList<CardPanel>();
final List<CardPanel> cardPanels = new ArrayList<CardPanel>(); final List<CardPanel> cardPanels = new ArrayList<CardPanel>();

View File

@@ -32,6 +32,7 @@ import forge.screens.match.views.VPicture;
import forge.toolbox.FMouseAdapter; import forge.toolbox.FMouseAdapter;
import forge.toolbox.special.CardZoomer; import forge.toolbox.special.CardZoomer;
import forge.view.CardView; import forge.view.CardView;
import forge.view.ViewUtil;
/** /**
* Singleton controller for VPicture. * Singleton controller for VPicture.
@@ -81,7 +82,7 @@ public enum CPicture implements ICDoc {
public void showImage(final InventoryItem item) { public void showImage(final InventoryItem item) {
if (item instanceof IPaperCard) { if (item instanceof IPaperCard) {
final IPaperCard paperCard = ((IPaperCard)item); final IPaperCard paperCard = ((IPaperCard)item);
final CardView c = CardView.getCardForUi(paperCard); final CardView c = ViewUtil.getCardForUi(paperCard);
if (paperCard.isFoil() && c.getFoilIndex() == 0) { if (paperCard.isFoil() && c.getFoilIndex() == 0) {
c.setRandomFoil(); c.setRandomFoil();
} }

View File

@@ -66,7 +66,7 @@ public class VCommand implements IVDoc<CCommand> {
// TODO player is hard-coded into tabletop...should be dynamic // TODO player is hard-coded into tabletop...should be dynamic
// (haven't looked into it too deeply). Doublestrike 12-04-12 // (haven't looked into it too deeply). Doublestrike 12-04-12
tabletop = new PlayArea(scroller, id0 == EDocID.COMMAND_0, player.getCommandCards()); tabletop = new PlayArea(scroller, id0 == EDocID.COMMAND_0, player);
control = new CCommand(player, this); control = new CCommand(player, this);

View File

@@ -95,7 +95,7 @@ public class VField implements IVDoc<CField> {
// TODO player is hard-coded into tabletop...should be dynamic // TODO player is hard-coded into tabletop...should be dynamic
// (haven't looked into it too deeply). Doublestrike 12-04-12 // (haven't looked into it too deeply). Doublestrike 12-04-12
tabletop = new PlayArea(scroller, id0 == EDocID.FIELD_1, player.getBfCards()); tabletop = new PlayArea(scroller, id0 == EDocID.FIELD_1, player);
control = new CField(player, this, playerViewer); control = new CField(player, this, playerViewer);

View File

@@ -24,10 +24,9 @@ import java.util.Map.Entry;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.ScrollPaneConstants; import javax.swing.ScrollPaneConstants;
import com.google.common.collect.Maps;
import net.miginfocom.swing.MigLayout; import net.miginfocom.swing.MigLayout;
import org.testng.collections.Maps;
import forge.gui.framework.DragCell; import forge.gui.framework.DragCell;
import forge.gui.framework.DragTab; import forge.gui.framework.DragTab;
import forge.gui.framework.EDocID; import forge.gui.framework.EDocID;

View File

@@ -30,7 +30,7 @@ import forge.gui.CardDetailPanel;
import forge.gui.CardPicturePanel; import forge.gui.CardPicturePanel;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.toolbox.FScrollPane; import forge.toolbox.FScrollPane;
import forge.view.CardView; import forge.view.ViewUtil;
/** /**
* A simple JPanel that shows three columns: card list, pic, and description.. * A simple JPanel that shows three columns: card list, pic, and description..
@@ -93,7 +93,7 @@ public class CardViewer extends JPanel {
// (String) jList.getSelectedValue(); // (String) jList.getSelectedValue();
if ((row >= 0) && (row < CardViewer.this.list.size())) { if ((row >= 0) && (row < CardViewer.this.list.size())) {
final PaperCard cp = CardViewer.this.list.get(row); final PaperCard cp = CardViewer.this.list.get(row);
CardViewer.this.detail.setCard(CardView.getCardForUi(cp)); CardViewer.this.detail.setCard(ViewUtil.getCardForUi(cp));
CardViewer.this.picture.setCard(cp); CardViewer.this.picture.setCard(cp);
} }
} }

View File

@@ -41,7 +41,7 @@ public final class Main {
GuiBase.setInterface(new GuiDesktop()); GuiBase.setInterface(new GuiDesktop());
//install our error handler //install our error handler
ExceptionHandler.registerErrorHandling(); ExceptionHandler.registerErrorHandling(GuiBase.getInterface());
// Start splash screen first, then data models, then controller. // Start splash screen first, then data models, then controller.
if (args.length == 0) { if (args.length == 0) {

View File

@@ -35,6 +35,7 @@ import forge.toolbox.FScrollPane;
import forge.toolbox.MouseTriggerEvent; import forge.toolbox.MouseTriggerEvent;
import forge.view.CardView; import forge.view.CardView;
import forge.view.CardView.CardStateView; import forge.view.CardView.CardStateView;
import forge.view.PlayerView;
import forge.view.arcane.util.Animation; import forge.view.arcane.util.Animation;
import forge.view.arcane.util.CardPanelMouseListener; import forge.view.arcane.util.CardPanelMouseListener;
@@ -76,7 +77,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
private int extraCardSpacingX, cardSpacingX, cardSpacingY; private int extraCardSpacingX, cardSpacingX, cardSpacingY;
private int stackSpacingX, stackSpacingY; private int stackSpacingX, stackSpacingY;
private final List<CardView> model; private final PlayerView model;
/** /**
* <p> * <p>
@@ -85,13 +86,13 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
* *
* @param scrollPane * @param scrollPane
* @param mirror * @param mirror
* @param list * @param player
*/ */
public PlayArea(final FScrollPane scrollPane, final boolean mirror, final List<CardView> list) { public PlayArea(final FScrollPane scrollPane, final boolean mirror, final PlayerView player) {
super(scrollPane); super(scrollPane);
this.setBackground(Color.white); this.setBackground(Color.white);
this.mirror = mirror; this.mirror = mirror;
this.model = list; this.model = player;
} }
private final CardStackRow collectAllLands() { private final CardStackRow collectAllLands() {
@@ -595,7 +596,12 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
recalculateCardPanels(model); recalculateCardPanels(model);
} }
private void recalculateCardPanels(final List<CardView> model) { private void recalculateCardPanels(final PlayerView model) {
final List<CardView> modelCopy;
synchronized (model) {
modelCopy = Lists.newArrayList(model.getBfCards());
}
final List<CardView> oldCards = Lists.newArrayList(); final List<CardView> oldCards = Lists.newArrayList();
for (final CardPanel cpa : getCardPanels()) { for (final CardPanel cpa : getCardPanels()) {
oldCards.add(cpa.getCard()); oldCards.add(cpa.getCard());
@@ -604,7 +610,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
final List<CardView> toReplace = Lists.newArrayList(); final List<CardView> toReplace = Lists.newArrayList();
// delete all cards that differ in timestamp (they have been blinked) // delete all cards that differ in timestamp (they have been blinked)
for (final CardView c : model) { for (final CardView c : modelCopy) {
for (int i = 0; i < toDelete.size(); i++) { for (int i = 0; i < toDelete.size(); i++) {
final CardView c2 = toDelete.get(i); final CardView c2 = toDelete.get(i);
if (c.getId() == c2.getId()) { if (c.getId() == c2.getId()) {
@@ -624,7 +630,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
} }
} }
final List<CardView> toAdd = new ArrayList<CardView>(model); final List<CardView> toAdd = new ArrayList<CardView>(modelCopy);
toAdd.removeAll(oldCards); toAdd.removeAll(oldCards);
toAdd.addAll(toReplace); toAdd.addAll(toReplace);
@@ -648,7 +654,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
} }
} }
for (final CardView card : model) { for (final CardView card : modelCopy) {
updateCard(card, true); updateCard(card, true);
} }
invalidate(); invalidate();

View File

@@ -45,7 +45,7 @@ public class PanelTest extends JFrame {
this.jbInit(); this.jbInit();
} }
catch (final Exception ex) { catch (final Exception ex) {
BugReporter.reportException(ex); BugReporter.reportException(ex, GuiBase.getInterface());
ex.printStackTrace(); ex.printStackTrace();
} }
} }

View File

@@ -227,7 +227,7 @@ public abstract class GuiDownloadService implements Runnable {
p = new Proxy(TYPES[type], new InetSocketAddress(txtAddress.getText(), Integer.parseInt(txtPort.getText()))); p = new Proxy(TYPES[type], new InetSocketAddress(txtAddress.getText(), Integer.parseInt(txtPort.getText())));
} }
catch (final Exception ex) { catch (final Exception ex) {
BugReporter.reportException(ex, BugReporter.reportException(ex, gui,
"Proxy connection could not be established!\nProxy address: %s\nProxy port: %s", "Proxy connection could not be established!\nProxy address: %s\nProxy port: %s",
txtAddress.getText(), txtPort.getText()); txtAddress.getText(), txtPort.getText());
return; return;

View File

@@ -114,15 +114,15 @@ public class BugReporter {
/** /**
* Alias for reportException(ex, null). * Alias for reportException(ex, null).
*/ */
public static void reportException(final Throwable ex) { public static void reportException(final Throwable ex, final IGuiBase gui) {
reportException(ex, null); reportException(ex, gui, null);
} }
/** /**
* Alias for reportException(ex, String.format(format, args)). * Alias for reportException(ex, String.format(format, args)).
*/ */
public static void reportException(final Throwable ex, final String format, final Object... args) { public static void reportException(final Throwable ex, final IGuiBase gui, final String format, final Object... args) {
reportException(ex, String.format(format, args)); reportException(ex, gui, String.format(format, args));
} }
/** /**

View File

@@ -28,6 +28,7 @@ import java.lang.Thread.UncaughtExceptionHandler;
import com.esotericsoftware.minlog.Log; import com.esotericsoftware.minlog.Log;
import forge.interfaces.IGuiBase;
import forge.properties.ForgeConstants; import forge.properties.ForgeConstants;
import forge.util.MultiplexOutputStream; import forge.util.MultiplexOutputStream;
@@ -46,6 +47,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName()); System.setProperty("sun.awt.exception.handler", ExceptionHandler.class.getName());
} }
private static IGuiBase gui;
private static PrintStream oldSystemOut; private static PrintStream oldSystemOut;
private static PrintStream oldSystemErr; private static PrintStream oldSystemErr;
private static OutputStream logFileStream; private static OutputStream logFileStream;
@@ -54,10 +56,12 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
* Call this at the beginning to make sure that the class is loaded and the * Call this at the beginning to make sure that the class is loaded and the
* static initializer has run. * static initializer has run.
*/ */
public static void registerErrorHandling() { public static void registerErrorHandling(final IGuiBase gui) {
//initialize log file //initialize log file
File logFile = new File(ForgeConstants.LOG_FILE); File logFile = new File(ForgeConstants.LOG_FILE);
ExceptionHandler.gui = gui;
int i = 0; int i = 0;
while (logFile.exists() && !logFile.delete()) { while (logFile.exists() && !logFile.delete()) {
String pathname = logFile.getPath().replaceAll("[0-9]{0,2}.log$", String.valueOf(i++) + ".log"); String pathname = logFile.getPath().replaceAll("[0-9]{0,2}.log$", String.valueOf(i++) + ".log");
@@ -101,7 +105,7 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void uncaughtException(final Thread t, final Throwable ex) { public final void uncaughtException(final Thread t, final Throwable ex) {
BugReporter.reportException(ex); BugReporter.reportException(ex, gui);
} }
/** /**
@@ -112,6 +116,6 @@ public class ExceptionHandler implements UncaughtExceptionHandler {
* a {@link java.lang.Throwable} object. * a {@link java.lang.Throwable} object.
*/ */
public final void handle(final Throwable ex) { public final void handle(final Throwable ex) {
BugReporter.reportException(ex); BugReporter.reportException(ex, gui);
} }
} }

View File

@@ -1,5 +1,18 @@
package forge.gauntlet; package forge.gauntlet;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.lang3.StringUtils;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.MarshallingContext;
@@ -8,19 +21,11 @@ import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import forge.deck.CardPool; import forge.deck.CardPool;
import forge.error.BugReporter;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.model.FModel; import forge.model.FModel;
import forge.properties.ForgeConstants; import forge.properties.ForgeConstants;
import forge.util.IgnoringXStream; import forge.util.IgnoringXStream;
import org.apache.commons.lang3.StringUtils;
import java.io.*;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
public class GauntletIO { public class GauntletIO {
/** Prompt in text field for new (unsaved) built gauntlets. */ /** Prompt in text field for new (unsaved) built gauntlets. */
public static final String TXF_PROMPT = "[New Gauntlet]"; public static final String TXF_PROMPT = "[New Gauntlet]";
@@ -85,7 +90,6 @@ public class GauntletIO {
return data; return data;
} catch (final Exception ex) { } catch (final Exception ex) {
BugReporter.reportException(ex, "Error loading Gauntlet Data");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} finally { } finally {
if (null != zin) { if (null != zin) {
@@ -100,7 +104,6 @@ public class GauntletIO {
final XStream xStream = GauntletIO.getSerializer(false); final XStream xStream = GauntletIO.getSerializer(false);
GauntletIO.savePacked(xStream, gd0); GauntletIO.savePacked(xStream, gd0);
} catch (final Exception ex) { } catch (final Exception ex) {
BugReporter.reportException(ex, "Error saving Gauntlet Data.");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }

View File

@@ -46,10 +46,10 @@ public abstract class InputBase implements java.io.Serializable, Input {
public InputBase(final PlayerControllerHuman controller) { public InputBase(final PlayerControllerHuman controller) {
this.controller = controller; this.controller = controller;
} }
protected final PlayerControllerHuman getController() { public final PlayerControllerHuman getController() {
return this.controller; return this.controller;
} }
protected IGuiBase getGui() { public IGuiBase getGui() {
return getController().getGui(); return getController().getGui();
} }

View File

@@ -14,10 +14,9 @@ import forge.util.ThreadUtil;
public class InputLockUI implements Input { public class InputLockUI implements Input {
private final AtomicInteger iCall = new AtomicInteger(); private final AtomicInteger iCall = new AtomicInteger();
private final IGuiBase gui; private IGuiBase gui;
private final Game game; private final Game game;
public InputLockUI(final IGuiBase gui, final Game game, final InputQueue inputQueue) { public InputLockUI(final Game game, final InputQueue inputQueue) {
this.gui = gui;
this.game = game; this.game = game;
} }
@@ -25,6 +24,10 @@ public class InputLockUI implements Input {
return gui; return gui;
} }
public void setGui(final IGuiBase gui) {
this.gui = gui;
}
public void showMessageInitial() { public void showMessageInitial() {
int ixCall = 1 + iCall.getAndIncrement(); int ixCall = 1 + iCall.getAndIncrement();
ThreadUtil.delay(500, new InputUpdater(ixCall)); ThreadUtil.delay(500, new InputUpdater(ixCall));

View File

@@ -22,7 +22,7 @@ public class InputPlaybackControl extends InputSyncronizedBase implements InputS
control = fControlGamePlayback; control = fControlGamePlayback;
} }
@Override @Override
protected IGuiBase getGui() { public IGuiBase getGui() {
return gui; return gui;
} }

View File

@@ -22,12 +22,12 @@ import java.util.Observer;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import forge.FThreads; import forge.FThreads;
import forge.game.Game;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.player.PlayerControllerHuman; import forge.player.PlayerControllerHuman;
import forge.util.ITriggerEvent; import forge.util.ITriggerEvent;
import forge.util.gui.SOptionPane; import forge.util.gui.SOptionPane;
import forge.view.CardView; import forge.view.CardView;
import forge.view.IGameView;
import forge.view.PlayerView; import forge.view.PlayerView;
import forge.view.SpellAbilityView; import forge.view.SpellAbilityView;
@@ -43,22 +43,18 @@ public class InputProxy implements Observer {
/** The input. */ /** The input. */
private AtomicReference<Input> input = new AtomicReference<Input>(); private AtomicReference<Input> input = new AtomicReference<Input>();
private IGameView game = null; private final Game game;
// private static final boolean DEBUG_INPUT = true; // false; // private static final boolean DEBUG_INPUT = true; // false;
private final PlayerControllerHuman controller; private final PlayerControllerHuman controller;
public InputProxy(final PlayerControllerHuman controller) { public InputProxy(final PlayerControllerHuman controller, final Game game) {
this.controller = controller; this.controller = controller;
this.game = game;
} }
private IGuiBase getGui() { private IGuiBase getGui() {
return controller.getGui(); return this.controller.getGui();
}
public void setGame(IGameView game0) {
game = game0;
getGui().getInputQueue().addObserver(this);
} }
public boolean passPriority() { public boolean passPriority() {
@@ -80,7 +76,6 @@ public class InputProxy implements Observer {
@Override @Override
public final void update(final Observable observable, final Object obj) { public final void update(final Observable observable, final Object obj) {
final Input nextInput = getGui().getInputQueue().getActualInput(game); final Input nextInput = getGui().getInputQueue().getActualInput(game);
/* if(DEBUG_INPUT) /* if(DEBUG_INPUT)
System.out.printf("%s ... \t%s on %s, \tstack = %s%n", System.out.printf("%s ... \t%s on %s, \tstack = %s%n",
FThreads.debugGetStackTraceItem(6, true), nextInput == null ? "null" : nextInput.getClass().getSimpleName(), FThreads.debugGetStackTraceItem(6, true), nextInput == null ? "null" : nextInput.getClass().getSimpleName(),

View File

@@ -22,8 +22,8 @@ import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingDeque;
import forge.game.Game; import forge.game.Game;
import forge.interfaces.IGuiBase; import forge.game.player.Player;
import forge.view.IGameView; import forge.player.PlayerControllerHuman;
/** /**
* <p> * <p>
@@ -37,8 +37,13 @@ public class InputQueue extends Observable {
private final BlockingDeque<InputSynchronized> inputStack = new LinkedBlockingDeque<InputSynchronized>(); private final BlockingDeque<InputSynchronized> inputStack = new LinkedBlockingDeque<InputSynchronized>();
private final InputLockUI inputLock; private final InputLockUI inputLock;
public InputQueue(final IGuiBase gui, final Game game) { public InputQueue(final Game game) {
inputLock = new InputLockUI(gui, game, this); inputLock = new InputLockUI(game, this);
for (final Player p : game.getPlayers()) {
if (p.getController() instanceof PlayerControllerHuman) {
this.addObserver(((PlayerControllerHuman) p.getController()).getInputProxy());
}
}
} }
public final void updateObservers() { public final void updateObservers() {
@@ -66,7 +71,7 @@ public class InputQueue extends Observable {
* *
* @return a {@link forge.gui.input.InputBase} object. * @return a {@link forge.gui.input.InputBase} object.
*/ */
public final Input getActualInput(IGameView game) { public final Input getActualInput(final Game game) {
Input topMost = inputStack.peek(); // incoming input to Control Input topMost = inputStack.peek(); // incoming input to Control
if (topMost != null && !game.isGameOver()) { if (topMost != null && !game.isGameOver()) {
return topMost; return topMost;
@@ -79,8 +84,9 @@ public class InputQueue extends Observable {
return inputStack.toString(); return inputStack.toString();
} }
public void setInput(InputSynchronized input) { public void setInput(final InputSynchronized input) {
this.inputStack.push(input); this.inputStack.push(input);
inputLock.setGui(input.getGui());
syncPoint(); syncPoint();
this.updateObservers(); this.updateObservers();
} }

View File

@@ -1,6 +1,9 @@
package forge.match.input; package forge.match.input;
import forge.interfaces.IGuiBase;
public interface InputSynchronized extends Input { public interface InputSynchronized extends Input {
void awaitLatchRelease(); void awaitLatchRelease();
void relaseLatchWhenGameIsOver(); void relaseLatchWhenGameIsOver();
IGuiBase getGui();
} }

View File

@@ -21,7 +21,7 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
cdlDone.await(); cdlDone.await();
} }
catch (InterruptedException e) { catch (InterruptedException e) {
BugReporter.reportException(e); BugReporter.reportException(e, getGui());
} }
} }

View File

@@ -16,6 +16,7 @@ import forge.game.player.PlayerController;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.game.spellability.SpellAbilityStackInstance; import forge.game.spellability.SpellAbilityStackInstance;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.match.input.InputProxy;
import forge.view.CardView; import forge.view.CardView;
import forge.view.CombatView; import forge.view.CombatView;
import forge.view.GameEntityView; import forge.view.GameEntityView;
@@ -26,16 +27,22 @@ import forge.view.StackItemView;
public abstract class PlayerControllerHuman extends PlayerController { public abstract class PlayerControllerHuman extends PlayerController {
private final IGuiBase gui; private final IGuiBase gui;
private final InputProxy inputProxy;
public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) { public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) {
super(game0, p, lp); super(game0, p, lp);
this.gui = gui; this.gui = gui;
this.inputProxy = new InputProxy(this, game0);
} }
public final IGuiBase getGui() { public final IGuiBase getGui() {
return this.gui; return this.gui;
} }
public final InputProxy getInputProxy() {
return this.inputProxy;
}
public abstract boolean canUndoLastAction(); public abstract boolean canUndoLastAction();
public abstract boolean tryUndoLastAction(); public abstract boolean tryUndoLastAction();

View File

@@ -78,7 +78,6 @@ import forge.match.input.InputConfirm;
import forge.match.input.InputConfirmMulligan; import forge.match.input.InputConfirmMulligan;
import forge.match.input.InputPassPriority; import forge.match.input.InputPassPriority;
import forge.match.input.InputProliferate; import forge.match.input.InputProliferate;
import forge.match.input.InputProxy;
import forge.match.input.InputSelectCardsForConvoke; import forge.match.input.InputSelectCardsForConvoke;
import forge.match.input.InputSelectCardsFromList; import forge.match.input.InputSelectCardsFromList;
import forge.match.input.InputSelectEntitiesFromList; import forge.match.input.InputSelectEntitiesFromList;
@@ -106,18 +105,12 @@ import forge.view.ViewUtil;
* Handles phase skips for now. * Handles phase skips for now.
*/ */
public class PlayerControllerLocal extends PlayerControllerHuman implements IGameView { public class PlayerControllerLocal extends PlayerControllerHuman implements IGameView {
private final InputProxy inputProxy;
public PlayerControllerLocal(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) { public PlayerControllerLocal(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) {
super(game0, p, lp, gui); super(game0, p, lp, gui);
this.inputProxy = new InputProxy(this); // aggressively cache a view for each player (also caches cards)
// aggressively cache a view for each player
for (final Player player : game.getRegisteredPlayers()) { for (final Player player : game.getRegisteredPlayers()) {
getPlayerView(player); getPlayerView(player);
} }
// aggressively cache a view for each card
for (final Card c : game.getCardsInGame()) {
getCardView(c);
}
} }
public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) { public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) {
@@ -1354,6 +1347,9 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
*/ */
@Override @Override
public CombatView getCombat(final Combat c) { public CombatView getCombat(final Combat c) {
if (c == null) {
return null;
}
updateCombatView(c); updateCombatView(c);
return combatView; return combatView;
} }
@@ -1361,9 +1357,10 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
private final void updateCombatView(final Combat combat) { private final void updateCombatView(final Combat combat) {
combatView.reset(); combatView.reset();
for (final AttackingBand b : combat.getAttackingBands()) { for (final AttackingBand b : combat.getAttackingBands()) {
if (b == null) continue;
final GameEntity defender = combat.getDefenderByAttacker(b); final GameEntity defender = combat.getDefenderByAttacker(b);
final List<Card> blockers = b.isBlocked() ? combat.getBlockers(b) : null; final List<Card> blockers = b.isBlocked() == null ? null : combat.getBlockers(b);
combatView.addAttackingBand(getCardViews(b.getAttackers()), getGameEntityView(defender), getCardViews(blockers)); combatView.addAttackingBand(getCardViews(b.getAttackers()), getGameEntityView(defender), blockers == null ? null : getCardViews(blockers));
} }
} }
@@ -1411,32 +1408,32 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
@Override @Override
public void selectButtonOk() { public void selectButtonOk() {
inputProxy.selectButtonOK(); getInputProxy().selectButtonOK();
} }
@Override @Override
public void selectButtonCancel() { public void selectButtonCancel() {
inputProxy.selectButtonCancel(); getInputProxy().selectButtonCancel();
} }
@Override @Override
public boolean passPriority() { public boolean passPriority() {
return inputProxy.passPriority(); return getInputProxy().passPriority();
} }
@Override @Override
public void selectPlayer(final PlayerView player, final ITriggerEvent triggerEvent) { public void selectPlayer(final PlayerView player, final ITriggerEvent triggerEvent) {
inputProxy.selectPlayer(player, triggerEvent); getInputProxy().selectPlayer(player, triggerEvent);
} }
@Override @Override
public void selectCard(final CardView card, final ITriggerEvent triggerEvent) { public void selectCard(final CardView card, final ITriggerEvent triggerEvent) {
inputProxy.selectCard(card, triggerEvent); getInputProxy().selectCard(card, triggerEvent);
} }
@Override @Override
public void selectAbility(final SpellAbilityView sa) { public void selectAbility(final SpellAbilityView sa) {
inputProxy.selectAbility(sa); getInputProxy().selectAbility(sa);
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -1538,12 +1535,16 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
getPlayerView(p, view); getPlayerView(p, view);
} else { } else {
view = new PlayerView(p.getLobbyPlayer(), p.getController()); view = new PlayerView(p.getLobbyPlayer(), p.getController());
getPlayerView(p, view);
players.put(p, view); players.put(p, view);
getPlayerView(p, view);
} }
return view; return view;
} }
private PlayerView getPlayerViewFast(final Player p) {
return players.get(p);
}
@Override @Override
public Player getPlayer(final PlayerView p) { public Player getPlayer(final PlayerView p) {
return players.inverse().get(p); return players.inverse().get(p);
@@ -1565,6 +1566,10 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
view.setGraveCards(getCardViews(p.getCardsIn(ZoneType.Graveyard))); view.setGraveCards(getCardViews(p.getCardsIn(ZoneType.Graveyard)));
view.setHandCards(getCardViews(p.getCardsIn(ZoneType.Hand))); view.setHandCards(getCardViews(p.getCardsIn(ZoneType.Hand)));
view.setLibraryCards(getCardViews(p.getCardsIn(ZoneType.Library))); view.setLibraryCards(getCardViews(p.getCardsIn(ZoneType.Library)));
for (final byte b : MagicColor.WUBRGC) {
view.setMana(b, p.getManaPool().getAmountOfColor(b));
}
} }
public CardView getCardView(final Card c) { public CardView getCardView(final Card c) {
@@ -1578,13 +1583,28 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
view = cards.get(cUi); view = cards.get(cUi);
writeCardToView(cUi, view); writeCardToView(cUi, view);
} else { } else {
view = new CardView(cUi, cUi.getUniqueNumber(), cUi == c); view = new CardView(cUi.getUniqueNumber(), cUi == c);
writeCardToView(cUi, view);
cards.put(cUi, view); cards.put(cUi, view);
writeCardToView(cUi, view);
} }
return view; return view;
} }
private CardView getCardViewFast(final Card c) {
return cards.get(c);
}
private final Function<Card, CardView> FN_GET_CARDVIEW_FAST = new Function<Card, CardView>() {
@Override
public CardView apply(Card input) {
return getCardViewFast(input);
}
};
private Iterable<CardView> getCardViewsFast(final Iterable<Card> cards) {
return Iterables.transform(cards, FN_GET_CARDVIEW_FAST);
}
public Card getCard(final CardView c) { public Card getCard(final CardView c) {
return cards.inverse().get(c); return cards.inverse().get(c);
} }
@@ -1599,29 +1619,30 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
// First, write the values independent of other views. // First, write the values independent of other views.
ViewUtil.writeNonDependentCardViewProperties(c, view); ViewUtil.writeNonDependentCardViewProperties(c, view);
// Next, write the values that depend on other views. // Next, write the values that depend on other views.
view.setOwner(getPlayerView(c.getOwner())); view.setOwner(getPlayerViewFast(c.getOwner()));
view.setController(getPlayerView(c.getController())); view.setController(getPlayerViewFast(c.getController()));
view.setAttacking(game.getCombat() != null && game.getCombat().isAttacking(c)); view.setAttacking(game.getCombat() != null && game.getCombat().isAttacking(c));
view.setBlocking(game.getCombat() != null && game.getCombat().isBlocking(c)); view.setBlocking(game.getCombat() != null && game.getCombat().isBlocking(c));
view.setChosenPlayer(getPlayerView(c.getChosenPlayer())); view.setChosenPlayer(getPlayerViewFast(c.getChosenPlayer()));
view.setEquipping(getCardView(Iterables.getFirst(c.getEquipping(), null))); view.setEquipping(getCardViewFast(Iterables.getFirst(c.getEquipping(), null)));
view.setEquippedBy(getCardViews(c.getEquippedBy())); view.setEquippedBy(getCardViewsFast(c.getEquippedBy()));
view.setEnchantingCard(getCardView(c.getEnchantingCard())); view.setEnchantingCard(getCardViewFast(c.getEnchantingCard()));
view.setEnchantingPlayer(getPlayerView(c.getEnchantingPlayer())); view.setEnchantingPlayer(getPlayerViewFast(c.getEnchantingPlayer()));
view.setEnchantedBy(getCardViews(c.getEnchantedBy())); view.setEnchantedBy(getCardViewsFast(c.getEnchantedBy()));
view.setFortifiedBy(getCardViews(c.getFortifiedBy())); view.setFortifiedBy(getCardViewsFast(c.getFortifiedBy()));
view.setGainControlTargets(getCardViews(c.getGainControlTargets())); view.setGainControlTargets(getCardViewsFast(c.getGainControlTargets()));
view.setCloneOrigin(getCardView(c.getCloneOrigin())); view.setCloneOrigin(getCardViewFast(c.getCloneOrigin()));
view.setImprinted(getCardViews(c.getImprinted())); view.setImprinted(getCardViewsFast(c.getImprinted()));
view.setHauntedBy(getCardViews(c.getHauntedBy())); view.setHauntedBy(getCardViewsFast(c.getHauntedBy()));
view.setHaunting(getCardView(c.getHaunting())); view.setHaunting(getCardViewFast(c.getHaunting()));
view.setMustBlock(c.getMustBlockCards() == null ? Collections.<CardView>emptySet() : getCardViews(c.getMustBlockCards())); view.setMustBlock(c.getMustBlockCards() == null ? Collections.<CardView>emptySet() : getCardViewsFast(c.getMustBlockCards()));
view.setPairedWith(getCardView(c.getPairedWith())); view.setPairedWith(getCardViewFast(c.getPairedWith()));
} }
@Override @Override
public boolean mayShowCard(final CardView c) { public boolean mayShowCard(final CardView c) {
return cards.inverse().get(c).canBeShownTo(player); final Card card = cards.inverse().get(c);
return card == null || card.canBeShownTo(player);
} }
@Override @Override
@@ -1649,6 +1670,7 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
private void writeSpellAbilityToView(final SpellAbility sa, final SpellAbilityView view) { private void writeSpellAbilityToView(final SpellAbility sa, final SpellAbilityView view) {
view.setHostCard(getCardView(sa.getHostCard())); view.setHostCard(getCardView(sa.getHostCard()));
view.setDescription(sa.getDescription());
view.setCanPlay(sa.canPlay()); view.setCanPlay(sa.canPlay());
view.setPromptIfOnlyPossibleAbility(sa.promptIfOnlyPossibleAbility()); view.setPromptIfOnlyPossibleAbility(sa.promptIfOnlyPossibleAbility());
} }

View File

@@ -20,19 +20,18 @@ package forge.properties;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import forge.interfaces.IGuiBase; import org.apache.commons.lang3.StringUtils;
import forge.util.BuildInfo;
public final class ForgeConstants { public final class ForgeConstants {
public static void init(final IGuiBase gui) {
ASSETS_DIR = gui.getAssetsDir();
}
private static String ASSETS_DIR; public static final String ASSETS_DIR = StringUtils.containsIgnoreCase(BuildInfo.getVersionString(), "svn") ?
public static String ASSETS_DIR() { return ASSETS_DIR; } "../forge-gui/" : "";
public static final String PROFILE_FILE = ASSETS_DIR() + "forge.profile.properties"; public static final String PROFILE_FILE = ASSETS_DIR + "forge.profile.properties";
public static final String PROFILE_TEMPLATE_FILE = PROFILE_FILE + ".example"; public static final String PROFILE_TEMPLATE_FILE = PROFILE_FILE + ".example";
public static final String RES_DIR = ASSETS_DIR() + "res/"; public static final String RES_DIR = ASSETS_DIR + "res/";
public static final String LISTS_DIR = RES_DIR + "lists/"; public static final String LISTS_DIR = RES_DIR + "lists/";
public static final String KEYWORD_LIST_FILE = LISTS_DIR + "NonStackingKWList.txt"; public static final String KEYWORD_LIST_FILE = LISTS_DIR + "NonStackingKWList.txt";
public static final String TYPE_LIST_FILE = LISTS_DIR + "TypeLists.txt"; public static final String TYPE_LIST_FILE = LISTS_DIR + "TypeLists.txt";
@@ -46,9 +45,9 @@ public final class ForgeConstants {
public static final String IMAGE_LIST_QUEST_PRECONS_FILE = LISTS_DIR + "precon-images.txt"; public static final String IMAGE_LIST_QUEST_PRECONS_FILE = LISTS_DIR + "precon-images.txt";
public static final String IMAGE_LIST_QUEST_TOURNAMENTPACKS_FILE = LISTS_DIR + "tournamentpack-images.txt"; public static final String IMAGE_LIST_QUEST_TOURNAMENTPACKS_FILE = LISTS_DIR + "tournamentpack-images.txt";
public static final String CHANGES_FILE = ASSETS_DIR() + "CHANGES.txt"; public static final String CHANGES_FILE = ASSETS_DIR + "CHANGES.txt";
public static final String LICENSE_FILE = ASSETS_DIR() + "LICENSE.txt"; public static final String LICENSE_FILE = ASSETS_DIR + "LICENSE.txt";
public static final String README_FILE = ASSETS_DIR() + "README.txt"; public static final String README_FILE = ASSETS_DIR + "README.txt";
public static final String HOWTO_FILE = RES_DIR + "howto.txt"; public static final String HOWTO_FILE = RES_DIR + "howto.txt";
public static final String DRAFT_DIR = RES_DIR + "draft/"; public static final String DRAFT_DIR = RES_DIR + "draft/";

View File

@@ -150,7 +150,7 @@ public class ForgeProfileProperties {
// returns a pair <userDir, cacheDir> // returns a pair <userDir, cacheDir>
private static Pair<String, String> getDefaultDirs() { private static Pair<String, String> getDefaultDirs() {
if (isRunningOnDesktop) { //special case for mobile devices if (isRunningOnDesktop) { //special case for mobile devices
String assetsDir = ForgeConstants.ASSETS_DIR(); String assetsDir = ForgeConstants.ASSETS_DIR;
return Pair.of(assetsDir + "data" + File.separator, assetsDir + "cache" + File.separator); return Pair.of(assetsDir + "data" + File.separator, assetsDir + "cache" + File.separator);
} }

View File

@@ -17,6 +17,35 @@
*/ */
package forge.quest.io; package forge.quest.io;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import com.thoughtworks.xstream.XStream; import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter; import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext; import com.thoughtworks.xstream.converters.MarshallingContext;
@@ -29,39 +58,30 @@ import forge.deck.CardPool;
import forge.deck.Deck; import forge.deck.Deck;
import forge.deck.DeckGroup; import forge.deck.DeckGroup;
import forge.deck.DeckSection; import forge.deck.DeckSection;
import forge.error.BugReporter; import forge.item.BoosterBox;
import forge.item.*; import forge.item.BoosterPack;
import forge.item.FatPack;
import forge.item.InventoryItem;
import forge.item.PaperCard;
import forge.item.PreconDeck;
import forge.item.TournamentPack;
import forge.model.FModel; import forge.model.FModel;
import forge.properties.ForgeConstants; import forge.properties.ForgeConstants;
import forge.quest.QuestController; import forge.quest.QuestController;
import forge.quest.QuestEventDraft; import forge.quest.QuestEventDraft;
import forge.quest.QuestMode; import forge.quest.QuestMode;
import forge.quest.bazaar.QuestItemType; import forge.quest.bazaar.QuestItemType;
import forge.quest.data.*; import forge.quest.data.GameFormatQuest;
import forge.quest.data.QuestAchievements;
import forge.quest.data.QuestAssets;
import forge.quest.data.QuestData;
import forge.quest.data.QuestEventDraftContainer;
import forge.quest.data.QuestItemCondition;
import forge.util.FileUtil; import forge.util.FileUtil;
import forge.util.IgnoringXStream; import forge.util.IgnoringXStream;
import forge.util.ItemPool; import forge.util.ItemPool;
import forge.util.XmlUtil; import forge.util.XmlUtil;
import org.apache.commons.lang3.StringUtils;
import org.w3c.dom.*;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.*;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/** /**
* <p> * <p>
* QuestDataIO class. * QuestDataIO class.
@@ -130,14 +150,15 @@ public class QuestDataIO {
QuestDataIO.updateSaveFile(data, bigXML, xmlSaveFile.getName().replace(".dat", "")); QuestDataIO.updateSaveFile(data, bigXML, xmlSaveFile.getName().replace(".dat", ""));
} }
catch (final Exception e) { catch (final Exception e) {
BugReporter.reportException(e); //BugReporter.reportException(e);
throw new RuntimeException(e);
} }
} }
return data; return data;
} }
catch (final Exception ex) { catch (final Exception ex) {
BugReporter.reportException(ex, "Error loading Quest Data"); //BugReporter.reportException(ex, "Error loading Quest Data");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }
@@ -371,7 +392,7 @@ public class QuestDataIO {
} }
catch (final Exception ex) { catch (final Exception ex) {
BugReporter.reportException(ex, "Error saving Quest Data."); //BugReporter.reportException(ex, "Error saving Quest Data.");
throw new RuntimeException(ex); throw new RuntimeException(ex);
} }
} }

View File

@@ -15,10 +15,8 @@ import forge.card.CardEdition;
import forge.card.CardRarity; import forge.card.CardRarity;
import forge.card.ColorSet; import forge.card.ColorSet;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
import forge.game.card.Card;
import forge.game.card.CounterType; import forge.game.card.CounterType;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.item.IPaperCard;
public class CardView extends GameEntityView { public class CardView extends GameEntityView {
@@ -59,11 +57,7 @@ public class CardView extends GameEntityView {
private Iterable<CardView> mustBlock; private Iterable<CardView> mustBlock;
private CardView pairedWith; private CardView pairedWith;
@Deprecated public CardView(final int id, final boolean isUiDisplayable) {
public final Card card;
public CardView(@Deprecated final Card card, final int id, final boolean isUiDisplayable) {
this.card = card;
this.id = id; this.id = id;
this.isUiDisplayable = isUiDisplayable; this.isUiDisplayable = isUiDisplayable;
this.reset(); this.reset();
@@ -755,7 +749,7 @@ public class CardView extends GameEntityView {
@Override @Override
public final String toString() { public final String toString() {
return this.getState().getName() + " (" + this.getId() + ")"; return this.getState().toString();
} }
public class CardStateView { public class CardStateView {
@@ -791,6 +785,11 @@ public class CardView extends GameEntityView {
this.hasTrample = false; this.hasTrample = false;
} }
@Override
public String toString() {
return this.getName() + " (" + this.getCard().getId() + ")";
}
public CardView getCard() { public CardView getCard() {
return CardView.this; return CardView.this;
} }
@@ -1022,11 +1021,4 @@ public class CardView extends GameEntityView {
return this.type.contains("Planeswalker"); return this.type.contains("Planeswalker");
} }
} }
public static CardView getCardForUi(final IPaperCard pc) {
final Card c = Card.getCardForUi(pc);
final CardView view = new CardView(c, -1, true);
ViewUtil.writeNonDependentCardViewProperties(c, view);
return view;
}
} }

View File

@@ -4,6 +4,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import forge.LobbyPlayer; import forge.LobbyPlayer;
@@ -18,7 +19,14 @@ public class PlayerView extends GameEntityView {
private int life, poisonCounters, maxHandSize, numDrawnThisTurn, preventNextDamage; private int life, poisonCounters, maxHandSize, numDrawnThisTurn, preventNextDamage;
private List<String> keywords; private List<String> keywords;
private String commanderInfo; private String commanderInfo;
private List<CardView> anteCards, bfCards, commandCards, exileCards, flashbackCards, graveCards, handCards, libraryCards; private List<CardView> anteCards = Lists.newArrayList(),
bfCards = Lists.newArrayList(),
commandCards = Lists.newArrayList(),
exileCards = Lists.newArrayList(),
flashbackCards = Lists.newArrayList(),
graveCards = Lists.newArrayList(),
handCards = Lists.newArrayList(),
libraryCards = Lists.newArrayList();
private boolean hasUnlimitedHandSize; private boolean hasUnlimitedHandSize;
private Map<Byte, Integer> mana = Maps.newHashMapWithExpectedSize(MagicColor.NUMBER_OR_COLORS + 1); private Map<Byte, Integer> mana = Maps.newHashMapWithExpectedSize(MagicColor.NUMBER_OR_COLORS + 1);
@@ -160,7 +168,8 @@ public class PlayerView extends GameEntityView {
* @param anteCards the anteCards to set * @param anteCards the anteCards to set
*/ */
public void setAnteCards(final List<CardView> anteCards) { public void setAnteCards(final List<CardView> anteCards) {
this.anteCards = ImmutableList.copyOf(anteCards); this.anteCards.clear();
this.anteCards.addAll(anteCards);
} }
/** /**
@@ -174,7 +183,8 @@ public class PlayerView extends GameEntityView {
* @param bfCards the bfCards to set * @param bfCards the bfCards to set
*/ */
public void setBfCards(final List<CardView> bfCards) { public void setBfCards(final List<CardView> bfCards) {
this.bfCards = ImmutableList.copyOf(bfCards); this.bfCards.clear();
this.bfCards.addAll(bfCards);
} }
/** /**
@@ -188,7 +198,8 @@ public class PlayerView extends GameEntityView {
* @param commandCards the commandCards to set * @param commandCards the commandCards to set
*/ */
public void setCommandCards(List<CardView> commandCards) { public void setCommandCards(List<CardView> commandCards) {
this.commandCards = commandCards; this.commandCards.clear();
this.commandCards.addAll(commandCards);
} }
/** /**
@@ -202,7 +213,8 @@ public class PlayerView extends GameEntityView {
* @param exileCards the exileCards to set * @param exileCards the exileCards to set
*/ */
public void setExileCards(final List<CardView> exileCards) { public void setExileCards(final List<CardView> exileCards) {
this.exileCards = ImmutableList.copyOf(exileCards); this.exileCards.clear();
this.exileCards.addAll(exileCards);
} }
/** /**
@@ -216,7 +228,8 @@ public class PlayerView extends GameEntityView {
* @param flashbackCards the flashbackCards to set * @param flashbackCards the flashbackCards to set
*/ */
public void setFlashbackCards(final List<CardView> flashbackCards) { public void setFlashbackCards(final List<CardView> flashbackCards) {
this.flashbackCards = ImmutableList.copyOf(flashbackCards); this.flashbackCards.clear();
this.flashbackCards.addAll(flashbackCards);
} }
/** /**
@@ -230,7 +243,8 @@ public class PlayerView extends GameEntityView {
* @param graveCards the graveCards to set * @param graveCards the graveCards to set
*/ */
public void setGraveCards(final List<CardView> graveCards) { public void setGraveCards(final List<CardView> graveCards) {
this.graveCards = ImmutableList.copyOf(graveCards); this.graveCards.clear();
this.graveCards.addAll(graveCards);
} }
/** /**
@@ -244,7 +258,8 @@ public class PlayerView extends GameEntityView {
* @param handCards the handCards to set * @param handCards the handCards to set
*/ */
public void setHandCards(final List<CardView> handCards) { public void setHandCards(final List<CardView> handCards) {
this.handCards = ImmutableList.copyOf(handCards); this.handCards.clear();
this.handCards.addAll(handCards);
} }
/** /**
@@ -258,7 +273,8 @@ public class PlayerView extends GameEntityView {
* @param libraryCards the libraryCards to set * @param libraryCards the libraryCards to set
*/ */
public void setLibraryCards(final List<CardView> libraryCards) { public void setLibraryCards(final List<CardView> libraryCards) {
this.libraryCards = ImmutableList.copyOf(libraryCards); this.libraryCards.clear();
this.libraryCards.addAll(libraryCards);
} }
/** /**
@@ -276,10 +292,10 @@ public class PlayerView extends GameEntityView {
} }
public int getMana(final Byte color) { public int getMana(final Byte color) {
return this.mana.get(color).intValue(); return this.mana.containsKey(color) ? this.mana.get(color).intValue() : 0;
} }
private void setMana(final byte color, final int mana) { public void setMana(final byte color, final int mana) {
this.mana.put(Byte.valueOf(color), Integer.valueOf(mana)); this.mana.put(Byte.valueOf(color), Integer.valueOf(mana));
} }
public void setWhiteMana(final int mana) { public void setWhiteMana(final int mana) {

View File

@@ -3,8 +3,14 @@ package forge.view;
public class SpellAbilityView { public class SpellAbilityView {
private CardView hostCard; private CardView hostCard;
private String description;
private boolean canPlay, promptIfOnlyPossibleAbility; private boolean canPlay, promptIfOnlyPossibleAbility;
@Override
public String toString() {
return this.getDescription();
}
/** /**
* @return the hostCard * @return the hostCard
*/ */
@@ -19,6 +25,20 @@ public class SpellAbilityView {
this.hostCard = hostCard; this.hostCard = hostCard;
} }
/**
* @return the description
*/
public String getDescription() {
return description;
}
/**
* @param description the description to set
*/
public void setDescription(String description) {
this.description = description;
}
/** /**
* @return the canPlay * @return the canPlay
*/ */

View File

@@ -47,4 +47,8 @@ public class StackItemView {
return optionalTrigger; return optionalTrigger;
} }
@Override
public String toString() {
return this.getText();
}
} }

View File

@@ -5,6 +5,7 @@ import java.util.Collections;
import forge.card.CardCharacteristicName; import forge.card.CardCharacteristicName;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardCharacteristics; import forge.game.card.CardCharacteristics;
import forge.item.IPaperCard;
import forge.view.CardView.CardStateView; import forge.view.CardView.CardStateView;
public final class ViewUtil { public final class ViewUtil {
@@ -23,7 +24,7 @@ public final class ViewUtil {
*/ */
public static void writeNonDependentCardViewProperties(final Card c, final CardView view) { public static void writeNonDependentCardViewProperties(final Card c, final CardView view) {
final boolean hasAltState = c.isDoubleFaced() || c.isFlipCard() || c.isFaceDown(); final boolean hasAltState = c.isDoubleFaced() || c.isFlipCard() || c.isFaceDown();
view.setZone(c.getZone().getZoneType()); view.setZone(c.getZone() == null ? null : c.getZone().getZoneType());
view.setHasAltState(hasAltState); view.setHasAltState(hasAltState);
view.setFaceDown(c.isFaceDown()); view.setFaceDown(c.isFaceDown());
view.setFoilIndex(c.getFoil()); view.setFoilIndex(c.getFoil());
@@ -87,4 +88,11 @@ public final class ViewUtil {
altView.reset(); altView.reset();
} }
} }
public static CardView getCardForUi(final IPaperCard pc) {
final Card c = Card.getCardForUi(pc);
final CardView view = new CardView(-1, true);
writeNonDependentCardViewProperties(c, view);
return view;
}
} }