Remove a lot of (now deprecated) GUI code. Removes almost all warnings from the desktop code.

This commit is contained in:
elcnesh
2014-09-03 09:49:50 +00:00
parent af494b13b0
commit b40c999cce
22 changed files with 251 additions and 425 deletions

View File

@@ -17,6 +17,16 @@
*/
package forge;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import javax.imageio.ImageIO;
import org.apache.commons.lang3.StringUtils;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader.InvalidCacheLoadException;
import com.google.common.cache.LoadingCache;
@@ -24,23 +34,12 @@ import com.mortennobel.imagescaling.ResampleOp;
import forge.assets.FSkinProp;
import forge.assets.ImageUtil;
import forge.game.card.Card;
import forge.item.InventoryItem;
import forge.properties.ForgeConstants;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinIcon;
import forge.view.CardView;
import org.apache.commons.lang3.StringUtils;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutionException;
/**
* This class stores ALL card images in a cache with soft values. this means
* that the images may be collected when they are not needed any more, but will
@@ -77,21 +76,6 @@ public class ImageCache {
_missingIconKeys.clear();
}
/**
* retrieve an image from the cache. returns null if the image is not found in the cache
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.
*/
@Deprecated
public static BufferedImage getImage(Card card, int width, int height) {
final String key;
if (!Singletons.getControl().mayShowCard(card) || card.isFaceDown()) {
key = ImageKeys.TOKEN_PREFIX + ImageKeys.MORPH_IMAGE;
} else {
key = card.getImageKey();
}
return scaleImage(key, width, height, true);
}
/**
* retrieve an image from the cache. returns null if the image is not found in the cache
* and cannot be loaded from disk. pass -1 for width and/or height to avoid resizing in that dimension.

View File

@@ -50,7 +50,6 @@ import forge.game.Game;
import forge.game.GameRules;
import forge.game.GameType;
import forge.game.Match;
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.player.RegisteredPlayer;
import forge.gui.GuiDialog;
@@ -370,30 +369,8 @@ public enum FControl implements KeyEventDispatcher {
if (children.length != 0) { children[0].setSize(display.getSize()); }
}
@Deprecated
public Player getCurrentPlayer() {
// try current priority
Player currentPriority = game.getPhaseHandler().getPriorityPlayer();
if (null != currentPriority && currentPriority.getLobbyPlayer() == getGuiPlayer()) {
return currentPriority;
}
// otherwise find just any player, belonging to this lobbyplayer
for (Player p : game.getPlayers()) {
if (p.getLobbyPlayer() == getGuiPlayer()) {
return p;
}
}
return null;
}
@Deprecated
public boolean mayShowCard(Card c) {
return game == null || !gameHasHumanPlayer || c.canBeShownTo(getCurrentPlayer());
}
public boolean mayShowCard(final CardView c) {
return gameView == null || !gameHasHumanPlayer || gameView.mayShowCard(c, getCurrentPlayer());
return gameView == null || !gameHasHumanPlayer || gameView.mayShowCard(c);
}
/**

View File

@@ -1,27 +1,7 @@
package forge.deckchooser;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckSection;
import forge.game.card.Card;
import forge.gui.CardDetailPanel;
import forge.gui.CardPicturePanel;
import forge.item.PaperCard;
import forge.itemmanager.CardManager;
import forge.itemmanager.ItemManagerConfig;
import forge.itemmanager.ItemManagerContainer;
import forge.itemmanager.ItemManagerModel;
import forge.itemmanager.views.*;
import forge.toolbox.FButton;
import forge.toolbox.FOptionPane;
import forge.view.FDialog;
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@@ -29,6 +9,28 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import net.miginfocom.swing.MigLayout;
import forge.deck.CardPool;
import forge.deck.Deck;
import forge.deck.DeckSection;
import forge.gui.CardDetailPanel;
import forge.gui.CardPicturePanel;
import forge.item.IPaperCard;
import forge.item.PaperCard;
import forge.itemmanager.CardManager;
import forge.itemmanager.ItemManagerConfig;
import forge.itemmanager.ItemManagerContainer;
import forge.itemmanager.ItemManagerModel;
import forge.itemmanager.views.ImageView;
import forge.toolbox.FButton;
import forge.toolbox.FOptionPane;
import forge.view.CardView;
import forge.view.FDialog;
@SuppressWarnings("serial")
public class FDeckViewer extends FDialog {
private final Deck deck;
@@ -59,11 +61,11 @@ public class FDeckViewer extends FDialog {
return new ImageView<PaperCard>(this, model0) {
@Override
protected void showHoveredItem(PaperCard item) {
Card card = Card.getCardForUi(item);
final CardView card = CardView.getCardForUi(item);
if (card == null) { return; }
cardDetail.setCard(card);
cardPicture.setCard(card, true);
cardPicture.setCard(card.getState());
}
};
}
@@ -72,14 +74,14 @@ public class FDeckViewer extends FDialog {
this.cardManager.addSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
PaperCard paperCard = cardManager.getSelectedItem();
final IPaperCard paperCard = cardManager.getSelectedItem();
if (paperCard == null) { return; }
Card card = Card.getCardForUi(paperCard);
final CardView card = CardView.getCardForUi(paperCard);
if (card == null) { return; }
cardDetail.setCard(card);
cardPicture.setCard(card, true);
cardPicture.setCard(card.getState());
}
});

View File

@@ -18,19 +18,6 @@
package forge.gui;
import forge.game.card.Card;
import forge.item.PaperCard;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FButton;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import forge.view.FDialog;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
@@ -38,6 +25,21 @@ import java.awt.event.WindowFocusListener;
import java.util.Collections;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.Icon;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.item.PaperCard;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FButton;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import forge.view.CardView;
import forge.view.FDialog;
/**
* A simple class that shows a list of cards in a dialog with preview in its
* right part.
@@ -187,7 +189,7 @@ public class BoxedProductCardListViewer extends FDialog {
// (String) jList.getSelectedValue();
if ((row >= 0) && (row < BoxedProductCardListViewer.this.list.size())) {
final PaperCard cp = BoxedProductCardListViewer.this.list.get(row);
BoxedProductCardListViewer.this.detail.setCard(Card.getCardForUi(cp));
BoxedProductCardListViewer.this.detail.setCard(CardView.getCardForUi(cp));
BoxedProductCardListViewer.this.picture.setCard(cp);
}
}

View File

@@ -18,30 +18,34 @@
package forge.gui;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;
import org.apache.commons.lang3.StringUtils;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardDetailUtil;
import forge.card.CardDetailUtil.DetailColors;
import forge.card.CardEdition;
import forge.game.card.Card;
import forge.game.zone.ZoneType;
import forge.item.IPaperCard;
import forge.item.InventoryItemFromSet;
import forge.model.FModel;
import forge.toolbox.*;
import forge.toolbox.FHtmlViewer;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinnedPanel;
import forge.view.CardView;
import forge.view.CardView.CardStateView;
import forge.view.FDialog;
import org.apache.commons.lang3.StringUtils;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.MouseListener;
/**
* The class CardDetailPanel. Shows the details of a card.
*
@@ -127,7 +131,7 @@ public class CardDetailPanel extends SkinnedPanel {
powerToughnessLabel.setVisible(false);
idLabel.setText("");
cdArea.setText(CardDetailUtil.getItemDescription(item));
this.updateBorder(item instanceof IPaperCard ? Card.getCardForUi((IPaperCard)item) : null, false);
this.updateBorder(item instanceof IPaperCard ? CardView.getCardForUi((IPaperCard)item).getState() : null, false);
String set = item.getEdition();
setInfoLabel.setText(set);
@@ -155,107 +159,8 @@ public class CardDetailPanel extends SkinnedPanel {
});
}
@Deprecated
public final void setCard(Card card) {
this.nameCostLabel.setText("");
this.typeLabel.setVisible(true);
this.typeLabel.setText("");
this.powerToughnessLabel.setVisible(true);
this.powerToughnessLabel.setText("");
this.idLabel.setText("");
this.setInfoLabel.setText("");
this.setInfoLabel.setToolTipText("");
this.setInfoLabel.setOpaque(false);
this.setInfoLabel.setBorder(null);
this.cdArea.setText("");
if (card == null) {
this.updateBorder((Card)null, false);
return;
}
card = card.getCardForUi();
boolean canShowThis = false;
if (card.isFaceDown()) {
if (card.isInZone(ZoneType.Battlefield)) {
this.nameCostLabel.setText("???");
this.typeLabel.setText("Creature");
}
}
else if (Singletons.getControl().mayShowCard(card) || FDialog.isModalOpen()) { //allow showing cards while modal open to account for revealing, picking, and ordering cards
canShowThis = true;
if (card.getManaCost().isNoCost()) {
this.nameCostLabel.setText(card.getName());
}
else {
String manaCost = card.getManaCost().toString();
if ( card.isSplitCard() && card.getCurState() == CardCharacteristicName.Original) {
manaCost = card.getRules().getMainPart().getManaCost().toString() + " // " + card.getRules().getOtherPart().getManaCost().toString();
}
this.nameCostLabel.setText(FSkin.encodeSymbols(card.getName() + " - " + manaCost, true));
}
this.typeLabel.setText(CardDetailUtil.formatCardType(card));
String set = card.getCurSetCode();
this.setInfoLabel.setText(set);
if (null != set && !set.isEmpty()) {
CardEdition edition = FModel.getMagicDb().getEditions().get(set);
if (null == edition) {
setInfoLabel.setToolTipText(card.getRarity().name());
}
else {
setInfoLabel.setToolTipText(String.format("%s (%s)", edition.getName(), card.getRarity().name()));
}
this.setInfoLabel.setOpaque(true);
Color backColor;
switch(card.getRarity()) {
case Uncommon:
backColor = fromDetailColor(DetailColors.UNCOMMON);
break;
case Rare:
backColor = fromDetailColor(DetailColors.RARE);
break;
case MythicRare:
backColor = fromDetailColor(DetailColors.MYTHIC);
break;
case Special: //"Timeshifted" or other Special Rarity Cards
backColor = fromDetailColor(DetailColors.SPECIAL);
break;
default: //case BasicLand: + case Common:
backColor = fromDetailColor(DetailColors.COMMON);
break;
}
Color foreColor = FSkin.getHighContrastColor(backColor);
this.setInfoLabel.setBackground(backColor);
this.setInfoLabel.setForeground(foreColor);
this.setInfoLabel.setBorder(BorderFactory.createLineBorder(foreColor));
}
}
this.updateBorder(card, canShowThis);
this.powerToughnessLabel.setText(CardDetailUtil.formatPowerToughness(card));
this.idLabel.setText(CardDetailUtil.formatCardId(card));
// fill the card text
this.cdArea.setText(FSkin.encodeSymbols(CardDetailUtil.composeCardText(card, canShowThis), true));
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
scrArea.getVerticalScrollBar().setValue(scrArea.getVerticalScrollBar().getMinimum());
}
});
public final void setCard(final CardView card) {
this.setCard(card, false);
}
public final void setCard(final CardView card, final boolean isInAltState) {
@@ -379,20 +284,6 @@ public class CardDetailPanel extends SkinnedPanel {
return this.cdArea;
}
@Deprecated
private void updateBorder(final Card card, final boolean canShow) {
// color info
if (card == null) {
this.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
scrArea.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0));
return;
}
Color color = fromDetailColor(CardDetailUtil.getBorderColor(card, canShow));
this.setBorder(BorderFactory.createLineBorder(color, 2));
scrArea.setBorder(BorderFactory.createMatteBorder(2, 0, 0, 0, color));
}
private void updateBorder(final CardStateView card, final boolean canShow) {
// color info
if (card == null) {

View File

@@ -18,19 +18,6 @@
package forge.gui;
import forge.game.card.Card;
import forge.item.PaperCard;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FButton;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import forge.view.FDialog;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
@@ -38,6 +25,21 @@ import java.awt.event.WindowFocusListener;
import java.util.Collections;
import java.util.List;
import javax.swing.AbstractListModel;
import javax.swing.Icon;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import forge.item.PaperCard;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.toolbox.FButton;
import forge.toolbox.FLabel;
import forge.toolbox.FScrollPane;
import forge.view.CardView;
import forge.view.FDialog;
/**
* A simple class that shows a list of cards in a dialog with preview in its
* right part.
@@ -170,7 +172,7 @@ public class CardListViewer extends FDialog {
// (String) jList.getSelectedValue();
if ((row >= 0) && (row < CardListViewer.this.list.size())) {
final PaperCard cp = CardListViewer.this.list.get(row);
CardListViewer.this.detail.setCard(Card.getCardForUi(cp));
CardListViewer.this.detail.setCard(CardView.getCardForUi(cp));
CardListViewer.this.picture.setCard(cp);
}
}

View File

@@ -48,7 +48,6 @@ public final class CardPicturePanel extends JPanel {
private final FImagePanel panel;
private BufferedImage currentImage;
private boolean mayShowObject;
public CardPicturePanel() {
super(new BorderLayout());
@@ -59,20 +58,17 @@ public final class CardPicturePanel extends JPanel {
public void setCard(final InventoryItem cp) {
this.displayed = cp;
this.mayShowObject = true;
this.setImage();
}
@Deprecated
public void setCard(final Card c, boolean mayShowCard) {
public void setCard(final Card c) {
this.displayed = c;
this.mayShowObject = mayShowCard;
this.setImage();
}
public void setCard(final CardStateView c, final boolean mayShowCard) {
public void setCard(final CardStateView c) {
this.displayed = c;
this.mayShowObject = mayShowCard;
this.setImage();
}
@@ -88,17 +84,8 @@ public final class CardPicturePanel extends JPanel {
if (displayed instanceof InventoryItem) {
final InventoryItem item = (InventoryItem) displayed;
return ImageCache.getOriginalImage(ImageKeys.getImageKey(item, false), true);
}
else if (displayed instanceof Card) {
if (mayShowObject) {
return FImageUtil.getImage((Card)displayed);
}
return ImageCache.getOriginalImage(ImageKeys.TOKEN_PREFIX + ImageKeys.MORPH_IMAGE, true);
} else if (displayed instanceof CardStateView) {
if (mayShowObject) {
return FImageUtil.getImage((CardStateView)displayed);
}
return ImageCache.getOriginalImage(ImageKeys.TOKEN_PREFIX + ImageKeys.MORPH_IMAGE, true);
return FImageUtil.getImage((CardStateView)displayed);
}
return null;
}

View File

@@ -1101,7 +1101,7 @@ public class ImageView<T extends InventoryItem> extends ItemView<T> {
if (paperCard.isFoil()) {
final CardView card = CardView.getCardForUi(paperCard);
if (card.getFoilIndex() == 0) { //if foil finish not yet established, assign a random one
card.card.setRandomFoil();
card.setRandomFoil();
}
CardPanel.drawFoilEffect(g, card, bounds.x, bounds.y, bounds.width, bounds.height, borderSize);
}

View File

@@ -1,19 +1,46 @@
package forge.screens.home.sanctioned;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.Vector;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.ScrollPaneConstants;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import net.miginfocom.swing.MigLayout;
import org.apache.commons.lang3.StringUtils;
import com.google.common.base.Predicate;
import forge.UiCommand;
import forge.Singletons;
import forge.UiCommand;
import forge.assets.FSkinProp;
import forge.deck.DeckProxy;
import forge.deck.DeckSection;
import forge.deck.DeckType;
import forge.game.GameType;
import forge.game.card.Card;
import forge.gui.CardDetailPanel;
import forge.deck.DeckProxy;
import forge.deckchooser.DecksComboBoxEvent;
import forge.deckchooser.FDeckChooser;
import forge.deckchooser.IDecksComboBoxListener;
import forge.game.GameType;
import forge.gui.CardDetailPanel;
import forge.gui.framework.DragCell;
import forge.gui.framework.DragTab;
import forge.gui.framework.EDocID;
@@ -25,25 +52,30 @@ import forge.properties.ForgePreferences.FPref;
import forge.screens.deckeditor.CDeckEditorUI;
import forge.screens.deckeditor.controllers.CEditorCommander;
import forge.screens.deckeditor.controllers.CEditorVariant;
import forge.screens.home.*;
import forge.toolbox.*;
import forge.screens.home.EMenuGroup;
import forge.screens.home.IVSubmenu;
import forge.screens.home.LblHeader;
import forge.screens.home.StartButton;
import forge.screens.home.VHomeUI;
import forge.toolbox.FCheckBox;
import forge.toolbox.FComboBox;
import forge.toolbox.FComboBoxWrapper;
import forge.toolbox.FLabel;
import forge.toolbox.FList;
import forge.toolbox.FMouseAdapter;
import forge.toolbox.FOptionPane;
import forge.toolbox.FPanel;
import forge.toolbox.FRadioButton;
import forge.toolbox.FScrollPane;
import forge.toolbox.FScrollPanel;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinColor;
import forge.toolbox.FSkin.SkinImage;
import forge.toolbox.FTextField;
import forge.util.Lang;
import forge.util.MyRandom;
import forge.util.NameGenerator;
import net.miginfocom.swing.MigLayout;
import org.apache.commons.lang3.StringUtils;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.util.List;
import forge.view.CardView;
/**
* Assembles Swing components of constructed submenu singleton.
@@ -1196,7 +1228,7 @@ public enum VSubmenuConstructed implements IVSubmenu<CSubmenuConstructed> {
if (obj instanceof PaperCard) {
pp.setVanguardButtonText(((PaperCard) obj).getName());
cdp.setCard(Card.getCardForUi((PaperCard) obj));
cdp.setCard(CardView.getCardForUi((PaperCard) obj));
cdp.setVisible(true);
refreshPanels(false, true);
}

View File

@@ -112,7 +112,7 @@ public class QuestWinLoseCardViewer extends FPanel {
// (String) jList.getSelectedValue();
if ((row >= 0) && (row < QuestWinLoseCardViewer.this.list.size())) {
final PaperCard cp = QuestWinLoseCardViewer.this.list.get(row);
QuestWinLoseCardViewer.this.detail.setCard(CardView.getCardForUi(cp), false);
QuestWinLoseCardViewer.this.detail.setCard(CardView.getCardForUi(cp));
QuestWinLoseCardViewer.this.picture.setCard(cp);
}
}

View File

@@ -17,7 +17,6 @@ import forge.toolbox.FOptionPane;
import forge.toolbox.FScrollPane;
import forge.view.FDialog;
import forge.view.IGameView;
import forge.view.PlayerView;
@SuppressWarnings("serial")
public class VAutoYields extends FDialog {
@@ -32,12 +31,12 @@ public class VAutoYields extends FDialog {
private final FCheckBox chkDisableAll;
private final List<String> autoYields;
public VAutoYields(final IGameView game, final PlayerView playerView) {
public VAutoYields(final IGameView game) {
super(true);
setTitle("Auto-Yields");
autoYields = new ArrayList<String>();
for (final String autoYield : playerView.getController().getAutoYields()) {
for (final String autoYield : game.getAutoYields()) {
autoYields.add(autoYield);
}
lstAutoYields = new FList<String>(new AutoYieldsListModel());
@@ -72,7 +71,7 @@ public class VAutoYields extends FDialog {
if (selected != null) {
autoYields.remove(selected);
btnRemove.setEnabled(autoYields.size() > 0);
playerView.getController().setShouldAutoYield(selected, false);
game.setShouldAutoYield(selected, false);
VAutoYields.this.revalidate();
lstAutoYields.repaint();
}

View File

@@ -93,24 +93,23 @@ public enum VMatchUI implements IVTopLevelUI {
}
}
if (Singletons.getControl().getObservedGame().getRules().getGameType().isCommandZoneNeeded()) {
// Add extra players alternatively to existing user/AI field panels.
for (int i = 2; i < lstCommands.size(); i++) {
// If already in layout, no need to add again.
VCommand cmdView = lstCommands.get(i);
if (cmdView.getParentCell() == null) {
lstCommands.get(i % 2).getParentCell().addDoc(cmdView);
}
}
}
else {
//If game goesn't need command zone, remove it from existing field panels
for (int i = 0; i < 2; i++) {
VCommand cmdView = lstCommands.get(i);
if (cmdView.getParentCell() != null) {
cmdView.getParentCell().removeDoc(cmdView);
}
}
if (Singletons.getControl().getGameView().isCommandZoneNeeded()) {
// Add extra players alternatively to existing user/AI field panels.
for (int i = 2; i < lstCommands.size(); i++) {
// If already in layout, no need to add again.
VCommand cmdView = lstCommands.get(i);
if (cmdView.getParentCell() == null) {
lstCommands.get(i % 2).getParentCell().addDoc(cmdView);
}
}
} else {
//If game goesn't need command zone, remove it from existing field panels
for (int i = 0; i < 2; i++) {
VCommand cmdView = lstCommands.get(i);
if (cmdView.getParentCell() != null) {
cmdView.getParentCell().removeDoc(cmdView);
}
}
}
// Add extra hands to existing hand panel.
@@ -206,7 +205,7 @@ public enum VMatchUI implements IVTopLevelUI {
*/
@Override
public boolean onClosing(FScreen screen) {
if (!Singletons.getControl().getObservedGame().isGameOver()) {
if (!Singletons.getControl().getGameView().isGameOver()) {
CMatchUI.SINGLETON_INSTANCE.concede();
return false; //delay hiding tab even if concede successful
}

View File

@@ -17,10 +17,10 @@
*/
package forge.screens.match.controllers;
import forge.UiCommand;
import java.awt.event.MouseEvent;
import forge.Singletons;
import forge.card.CardDetailUtil;
import forge.game.card.Card;
import forge.UiCommand;
import forge.gui.framework.ICDoc;
import forge.item.IPaperCard;
import forge.item.InventoryItem;
@@ -29,8 +29,6 @@ import forge.screens.match.views.VDetail;
import forge.toolbox.FMouseAdapter;
import forge.view.CardView;
import java.awt.event.MouseEvent;
/**
* Controls the card detail area in the match UI.
*
@@ -44,18 +42,10 @@ public enum CDetail implements ICDoc {
/**
* Shows card details and/or picture in sidebar cardview tabber.
*
* @param c &emsp; Card object
* @param c &emsp; {@link CardView} object
*/
@Deprecated
public void showCard(Card c) {
if (c != null) {
c = c.getCardForUi();
}
view.getLblFlipcard().setVisible(c != null && CardDetailUtil.isCardFlippable(c) && Singletons.getControl().mayShowCard(c));
view.getPnlDetail().setCard(c);
if (view.getParentCell() != null) {
view.getParentCell().repaintSelf();
}
public void showCard(final CardView c) {
this.showCard(c, false);
}
public void showCard(final CardView c, final boolean isInAltState) {
@@ -68,15 +58,13 @@ public enum CDetail implements ICDoc {
public void showCard(final InventoryItem item) {
if (item instanceof IPaperCard) {
showCard(Card.getCardForUi((IPaperCard)item));
}
else if (item instanceof InventoryItemFromSet) {
showCard(CardView.getCardForUi((IPaperCard)item));
} else if (item instanceof InventoryItemFromSet) {
view.getLblFlipcard().setVisible(false);
view.getPnlDetail().setItem((InventoryItemFromSet)item);
view.getParentCell().repaintSelf();
}
else {
showCard((Card)null);
} else {
showCard((CardView)null);
}
}

View File

@@ -17,11 +17,13 @@
*/
package forge.screens.match.controllers;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JLabel;
import forge.UiCommand;
import forge.Singletons;
import forge.card.CardCharacteristicName;
import forge.card.CardDetailUtil;
import forge.game.card.Card;
import forge.gui.CardPicturePanel;
import forge.gui.framework.ICDoc;
import forge.item.IPaperCard;
@@ -30,13 +32,6 @@ import forge.screens.match.views.VPicture;
import forge.toolbox.FMouseAdapter;
import forge.toolbox.special.CardZoomer;
import forge.view.CardView;
import forge.view.FDialog;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
/**
* Singleton controller for VPicture.
@@ -58,41 +53,9 @@ public enum CPicture implements ICDoc {
private final JLabel flipIndicator = this.view.getLblFlipcard();
private final CardZoomer zoomer = CardZoomer.SINGLETON_INSTANCE;
@Deprecated
private Card currentCard = null;
@Deprecated
private CardCharacteristicName displayedState = CardCharacteristicName.Original;
private CardView currentView = null;
private boolean isDisplayAlt = false;
private boolean mayShowCurrentCard() {
if (currentCard == null) { return false; }
if (FDialog.isModalOpen()) { return true; } //allow showing cards while modal open to account for revealing, picking, and ordering cards
return Singletons.getControl().mayShowCard(currentCard);
}
/**
* Shows card details and/or picture in sidebar cardview tabber.
*
*/
@Deprecated
public void showCard(Card c, boolean showFlipped) {
if (null == c) {
return;
}
c = c.getCardForUi();
currentCard = c;
displayedState = c.getCurState();
boolean isFlippable = isCurrentCardFlippable();
flipIndicator.setVisible(isFlippable);
picturePanel.setCard(c, mayShowCurrentCard());
if (showFlipped && isFlippable) {
flipCard();
}
}
/**
* Shows card details and/or picture in sidebar cardview tabber.
*
@@ -105,7 +68,7 @@ public enum CPicture implements ICDoc {
currentView = c;
isDisplayAlt = false;
flipIndicator.setVisible(c.hasAltState());
picturePanel.setCard(c.getState(showAlt), mayShowCurrentCard());
picturePanel.setCard(c.getState(showAlt));
if (showAlt && c.hasAltState()) {
flipCard();
}
@@ -117,23 +80,20 @@ public enum CPicture implements ICDoc {
*/
public void showImage(final InventoryItem item) {
if (item instanceof IPaperCard) {
IPaperCard paperCard = ((IPaperCard)item);
Card c = Card.getCardForUi(paperCard);
if (paperCard.isFoil() && c.getFoil() == 0) {
final IPaperCard paperCard = ((IPaperCard)item);
final CardView c = CardView.getCardForUi(paperCard);
if (paperCard.isFoil() && c.getFoilIndex() == 0) {
c.setRandomFoil();
}
showCard(c, false);
} else {
currentCard = null;
currentView = null;
isDisplayAlt = false;
flipIndicator.setVisible(false);
picturePanel.setCard(item);
}
}
public Card getCurrentCard() {
return currentCard;
}
@Override
public UiCommand getCommandOnSelect() {
return null;
@@ -195,7 +155,7 @@ public enum CPicture implements ICDoc {
}
private boolean isCardDisplayed() {
return (currentCard != null);
return (currentView != null);
}
@Override
@@ -205,34 +165,8 @@ public enum CPicture implements ICDoc {
public void flipCard() {
if (currentView.hasAltState()) {
isDisplayAlt = !isDisplayAlt;
picturePanel.setCard(currentView.getState(isDisplayAlt), mayShowCurrentCard());
picturePanel.setCard(currentView.getState(isDisplayAlt));
}
}
/**
* Displays details about the current card state in appropriate GUI panel.
* <p>
* It does this by temporarily setting the {@code CardCharacteristicName} state
* of the card, extracting the details and then setting the card back to its
* original state.
* <p>
* TODO: at the moment setting the state of {@code Card} does not appear to
* trigger any significant functionality but potentially this could cause
* unforeseen consequences. Recommend that a read-only mechanism is implemented
* to get card details for a given {@code CardCharacteristicName} state that does
* not require temporarily setting state of {@code Card} instance.
*/
private void setCardDetailPanel() {
CardCharacteristicName temp = currentCard.getCurState();
currentCard.setState(displayedState);
CDetail.SINGLETON_INSTANCE.showCard(currentCard);
currentCard.setState(temp);
}
@Deprecated
private boolean isCurrentCardFlippable() {
if (!mayShowCurrentCard()) { return false; }
return CardDetailUtil.isCardFlippable(currentCard);
}
}

View File

@@ -29,14 +29,12 @@ import javax.swing.JButton;
import forge.FThreads;
import forge.Singletons;
import forge.UiCommand;
import forge.game.Game;
import forge.game.GameRules;
import forge.game.Match;
import forge.gui.framework.ICDoc;
import forge.gui.framework.SDisplayUtil;
import forge.match.input.InputProxy;
import forge.screens.match.views.VPrompt;
import forge.toolbox.FSkin;
import forge.view.IGameView;
/**
* Controls the prompt panel in the match UI.
@@ -121,12 +119,10 @@ public enum CPrompt implements ICDoc {
public void updateText() {
FThreads.assertExecutedByEdt(true);
final Game game = Singletons.getControl().getObservedGame();
final Match match = game.getMatch();
final GameRules rules = game.getRules();
final String text = String.format("T:%d G:%d/%d [%s]", game.getPhaseHandler().getTurn(), match.getPlayedGames().size() + 1, rules.getGamesPerMatch(), rules.getGameType());
final IGameView game = Singletons.getControl().getGameView();
final String text = String.format("T:%d G:%d/%d [%s]", game.getTurnNumber(), game.getNumPlayedGamesInMatch() + 1, game.getNumGamesInMatch(), game.getGameType());
view.getLblGames().setText(text);
view.getLblGames().setToolTipText(String.format("%s: Game #%d of %d, turn %d", rules.getGameType(), match.getPlayedGames().size() + 1, rules.getGamesPerMatch(), game.getPhaseHandler().getTurn()));
view.getLblGames().setToolTipText(String.format("%s: Game #%d of %d, turn %d", game.getGameType(), game.getNumPlayedGamesInMatch() + 1, game.getNumGamesInMatch(), game.getTurnNumber()));
}
@Override

View File

@@ -199,7 +199,7 @@ public final class GameMenu {
@Override
public void actionPerformed(ActionEvent e) {
final FControl control = Singletons.getControl();
final VAutoYields autoYields = new VAutoYields(control.getGameView(), control.getLocalPlayer());
final VAutoYields autoYields = new VAutoYields(control.getGameView());
autoYields.showAutoYields();
}
};

View File

@@ -158,7 +158,7 @@ public enum VAntes implements IVDoc<CAntes> {
.fontAlign(SwingConstants.CENTER).build(), "w 160px, h 20px");
CardPicturePanel picPanel = new CardPicturePanel();
add(picPanel, "w 160px, h 230px");
picPanel.setCard(c.getState(), true);
picPanel.setCard(c.getState());
}
@Override

View File

@@ -38,7 +38,6 @@ import forge.ImageCache;
import forge.Singletons;
import forge.card.CardDetailUtil;
import forge.card.CardDetailUtil.DetailColors;
import forge.game.player.PlayerController;
import forge.gui.framework.DragCell;
import forge.gui.framework.DragTab;
import forge.gui.framework.EDocID;
@@ -248,7 +247,6 @@ public enum VStack implements IVDoc<CStack> {
private final JCheckBoxMenuItem jmiAlwaysNo;
private IGameView game;
private StackItemView item;
private PlayerController controller;
private Integer triggerID = 0;
@@ -258,8 +256,8 @@ public enum VStack implements IVDoc<CStack> {
@Override
public void actionPerformed(ActionEvent arg0) {
final String key = item.getKey();
final boolean autoYield = controller.shouldAutoYield(key);
controller.setShouldAutoYield(key, !autoYield);
final boolean autoYield = game.shouldAutoYield(key);
game.setShouldAutoYield(key, !autoYield);
if (!autoYield && game.peekStack() == item) {
//auto-pass priority if ability is on top of stack
CPrompt.SINGLETON_INSTANCE.getInputControl().passPriority();
@@ -272,11 +270,11 @@ public enum VStack implements IVDoc<CStack> {
jmiAlwaysYes.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (controller.shouldAlwaysAcceptTrigger(triggerID)) {
controller.setShouldAlwaysAskTrigger(triggerID);
if (game.shouldAlwaysAcceptTrigger(triggerID)) {
game.setShouldAlwaysAskTrigger(triggerID);
}
else {
controller.setShouldAlwaysAcceptTrigger(triggerID);
game.setShouldAlwaysAcceptTrigger(triggerID);
if (game.peekStack() == item &&
Singletons.getControl().getInputQueue().getInput() instanceof InputConfirm) {
//auto-yes if ability is on top of stack
@@ -291,11 +289,11 @@ public enum VStack implements IVDoc<CStack> {
jmiAlwaysNo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
if (controller.shouldAlwaysDeclineTrigger(triggerID)) {
controller.setShouldAlwaysAskTrigger(triggerID);
if (game.shouldAlwaysDeclineTrigger(triggerID)) {
game.setShouldAlwaysAskTrigger(triggerID);
}
else {
controller.setShouldAlwaysDeclineTrigger(triggerID);
game.setShouldAlwaysDeclineTrigger(triggerID);
if (game.peekStack() == item &&
Singletons.getControl().getInputQueue().getInput() instanceof InputConfirm) {
//auto-no if ability is on top of stack
@@ -310,14 +308,13 @@ public enum VStack implements IVDoc<CStack> {
public void setStackInstance(final IGameView game, final StackItemView item, final PlayerView localPlayer) {
this.game = game;
this.item = item;
controller = localPlayer.getController();
triggerID = Integer.valueOf(item.getSourceTrigger());
jmiAutoYield.setSelected(controller.shouldAutoYield(item.getKey()));
jmiAutoYield.setSelected(game.shouldAutoYield(item.getKey()));
if (item.isOptionalTrigger() && item.getActivatingPlayer().equals(localPlayer)) {
jmiAlwaysYes.setSelected(controller.shouldAlwaysAcceptTrigger(triggerID));
jmiAlwaysNo.setSelected(controller.shouldAlwaysDeclineTrigger(triggerID));
jmiAlwaysYes.setSelected(game.shouldAlwaysAcceptTrigger(triggerID));
jmiAlwaysNo.setSelected(game.shouldAlwaysDeclineTrigger(triggerID));
jmiAlwaysYes.setVisible(true);
jmiAlwaysNo.setVisible(true);
}

View File

@@ -93,7 +93,7 @@ public class CardViewer extends JPanel {
// (String) jList.getSelectedValue();
if ((row >= 0) && (row < CardViewer.this.list.size())) {
final PaperCard cp = CardViewer.this.list.get(row);
CardViewer.this.detail.setCard(CardView.getCardForUi(cp), false);
CardViewer.this.detail.setCard(CardView.getCardForUi(cp));
CardViewer.this.picture.setCard(cp);
}
}

View File

@@ -1251,6 +1251,16 @@ public class PlayerControllerHuman extends PlayerController implements IGameView
return this.game.getMatch().getRules().getGameType();
}
@Override
public int getTurnNumber() {
return this.game.getPhaseHandler().getTurn();
}
@Override
public boolean isCommandZoneNeeded() {
return this.game.getMatch().getRules().getGameType().isCommandZoneNeeded();
}
@Override
public boolean isWinner(final LobbyPlayer p) {
return game.getOutcome() == null ? null : game.getOutcome().isWinner(p);
@@ -1279,6 +1289,11 @@ public class PlayerControllerHuman extends PlayerController implements IGameView
return this.game.getMatch().isMatchOver();
}
@Override
public int getNumGamesInMatch() {
return this.game.getMatch().getRules().getGamesPerMatch();
}
@Override
public int getNumPlayedGamesInMatch() {
return this.game.getMatch().getPlayedGames().size();
@@ -1557,8 +1572,8 @@ public class PlayerControllerHuman extends PlayerController implements IGameView
}
@Override
public boolean mayShowCard(final CardView c, final Player viewer) {
return cards.inverse().get(c).canBeShownTo(viewer);
public boolean mayShowCard(final CardView c) {
return cards.inverse().get(c).canBeShownTo(player);
}
@Override

View File

@@ -11,6 +11,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import forge.card.CardEdition;
import forge.card.CardRarity;
import forge.card.ColorSet;
import forge.card.mana.ManaCost;
@@ -190,6 +191,10 @@ public class CardView extends GameEntityView {
this.foilIndex = foilIndex;
}
public void setRandomFoil() {
this.setFoilIndex(CardEdition.getRandomFoil(getSetCode()));
}
/**
* @return the isCloned
*/

View File

@@ -7,7 +7,6 @@ import forge.game.GameLog;
import forge.game.GameOutcome;
import forge.game.GameType;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.player.RegisteredPlayer;
public interface IGameView {
@@ -16,12 +15,17 @@ public interface IGameView {
public abstract GameType getGameType();
// Game-related methods
public abstract int getTurnNumber();
public abstract boolean isCommandZoneNeeded();
public abstract boolean isWinner(LobbyPlayer p);
public abstract LobbyPlayer getWinningPlayer();
public abstract int getWinningTeam();
// Match-related methods
public abstract boolean isFirstGameInMatch();
public abstract boolean isMatchOver();
public abstract int getNumGamesInMatch();
public abstract int getNumPlayedGamesInMatch();
public abstract boolean isMatchWonBy(LobbyPlayer p);
public abstract int getGamesWonBy(LobbyPlayer p);
@@ -53,11 +57,23 @@ public interface IGameView {
public abstract List<StackItemView> getStack();
public abstract StackItemView peekStack();
public abstract boolean mayShowCard(CardView c, Player viewer);
public abstract boolean mayShowCard(CardView c);
// Auto-yield related methods
public abstract Iterable<String> getAutoYields();
public abstract boolean shouldAutoYield(String key);
public abstract void setShouldAutoYield(String key, boolean autoYield);
public abstract boolean getDisableAutoYields();
public abstract void setDisableAutoYields(boolean b);
public abstract boolean shouldAlwaysAcceptTrigger(Integer trigger);
public abstract boolean shouldAlwaysDeclineTrigger(Integer trigger);
public abstract boolean shouldAlwaysAskTrigger(Integer trigger);
public abstract void setShouldAlwaysAcceptTrigger(Integer trigger);
public abstract void setShouldAlwaysDeclineTrigger(Integer trigger);
public abstract void setShouldAlwaysAskTrigger(Integer trigger);
public abstract void autoPassUntilEndOfTurn();
public abstract void autoPassCancel();