diff --git a/Mage.Client/src/main/java/mage/client/game/GamePanel.java b/Mage.Client/src/main/java/mage/client/game/GamePanel.java index 22f47f766e..e8a1de52a1 100644 --- a/Mage.Client/src/main/java/mage/client/game/GamePanel.java +++ b/Mage.Client/src/main/java/mage/client/game/GamePanel.java @@ -62,6 +62,7 @@ import java.util.*; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; + /** * * @author BetaSteward_at_googlemail.com, nantuko8 @@ -351,7 +352,7 @@ public final class GamePanel extends javax.swing.JPanel { } } PlayerView player = game.getPlayers().get(playerSeat); - PlayAreaPanel sessionPlayer = new PlayAreaPanel(player, bigCard, gameId, true, game.getPriorityTime()); + PlayAreaPanel sessionPlayer = new PlayAreaPanel(player, bigCard, gameId, true, game.getPriorityTime(), game.isPlayer(), this); players.put(player.getPlayerId(), sessionPlayer); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; @@ -383,7 +384,7 @@ public final class GamePanel extends javax.swing.JPanel { col = numColumns - 1; } player = game.getPlayers().get(playerNum); - PlayAreaPanel playerPanel = new PlayAreaPanel(player, bigCard, gameId, false, game.getPriorityTime()); + PlayAreaPanel playerPanel = new PlayAreaPanel(player, bigCard, gameId, false, game.getPriorityTime(), game.isPlayer(), this); players.put(player.getPlayerId(), playerPanel); c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; @@ -1249,6 +1250,14 @@ public final class GamePanel extends javax.swing.JPanel { return gameChatPanel.getText(); } + public Session getSession() { + return session; + } + + public FeedbackPanel getFeedbackPanel() { + return feedbackPanel; + } + private mage.client.components.ability.AbilityPicker abilityPicker; private mage.client.cards.BigCard bigCard; private javax.swing.JButton btnConcede; @@ -1296,7 +1305,6 @@ public final class GamePanel extends javax.swing.JPanel { private boolean imagePanelState; } - class ReplayTask extends SwingWorker> { private Session session; diff --git a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java index f3660f4308..34f9d0de2f 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java @@ -52,20 +52,26 @@ public class PlayAreaPanel extends javax.swing.JPanel { private UUID gameId; private boolean smallMode = false; private boolean playingMode = true; + private GamePanel gamePanel; public static final int PANEL_HEIGHT = 242; public static final int PANEL_HEIGHT_SMALL = 190; /** Creates new form PlayAreaPanel */ - public PlayAreaPanel() { + public PlayAreaPanel(boolean isPlayer) { initComponents(); setOpaque(false); battlefieldPanel.setOpaque(false); - addPopupMenu(); + if (isPlayer) { + addPopupMenu(); + } else { + addPopupMenuWatcher(); + } } - public PlayAreaPanel(PlayerView player, BigCard bigCard, UUID gameId, boolean me, int priorityTime) { - this(); + public PlayAreaPanel(PlayerView player, BigCard bigCard, UUID gameId, boolean me, int priorityTime, boolean isPlayer, GamePanel gamePanel) { + this(isPlayer); + this.gamePanel = gamePanel; init(player, bigCard, gameId, priorityTime); update(player); } @@ -76,6 +82,57 @@ public class PlayAreaPanel extends javax.swing.JPanel { Pmenu = new JPopupMenu(); + menuItem = new JMenuItem("F2 - Confirm"); + Pmenu.add(menuItem); + + // Confirm (F2) + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (gamePanel.getFeedbackPanel() != null) { + gamePanel.getFeedbackPanel().pressOKYesOrDone(); + } + } + }); + + + menuItem = new JMenuItem("F3 - Cancel previous F4/F9 skip action"); + Pmenu.add(menuItem); + + // Cancel (F3) + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + gamePanel.getSession().restorePriority(gameId); + } + }); + + Pmenu.addSeparator(); + + menuItem = new JMenuItem("F4 - Skip phases until next turn (stop on stack/attack/block)"); + Pmenu.add(menuItem); + + // Skip to next turn (F4) + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + gamePanel.getSession().passTurnPriority(gameId);; + } + }); + + menuItem = new JMenuItem("F9 - Skip everything until own next turn (stop on attack/block)"); + Pmenu.add(menuItem); + + // Skip to next own turn (F9) + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + gamePanel.getSession().passPriorityUntilNextYourTurn(gameId); + } + }); + + Pmenu.addSeparator(); + menuItem = new JMenuItem("Concede game"); Pmenu.add(menuItem); @@ -89,22 +146,56 @@ public class PlayAreaPanel extends javax.swing.JPanel { } }); - menuItem = new JMenuItem("Quit match"); + Pmenu.addSeparator(); + + menuItem = new JMenuItem("Concede complete match"); Pmenu.add(menuItem); // Quit match menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to quit the match?", "Confirm quit match", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to concede the complete match?", "Confirm concede match", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { MageFrame.getSession().quitMatch(gameId); } } }); - menuItem = new JMenuItem("Cancel"); +// Pmenu.addSeparator(); +// +// menuItem = new JMenuItem("Cancel"); +// Pmenu.add(menuItem); + + battlefieldPanel.getMainPanel().addMouseListener(new MouseAdapter() { + @Override + public void mouseReleased(MouseEvent Me) { + if (Me.isPopupTrigger() && playingMode) { + Pmenu.show(Me.getComponent(), Me.getX(), Me.getY()); + } + } + }); + } + + private void addPopupMenuWatcher() { + final JPopupMenu Pmenu; + JMenuItem menuItem; + + Pmenu = new JPopupMenu(); + + menuItem = new JMenuItem("Stop watching"); Pmenu.add(menuItem); + // Stop watching + menuItem.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to stop watching the game?", "Confirm stop watching game", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + gamePanel.getSession().stopWatching(gameId); + gamePanel.hideGame(); + } + } + }); + battlefieldPanel.getMainPanel().addMouseListener(new MouseAdapter() { @Override public void mouseReleased(MouseEvent Me) { diff --git a/Mage.Common/src/mage/view/GameView.java b/Mage.Common/src/mage/view/GameView.java index 642b566478..a27b849e3c 100644 --- a/Mage.Common/src/mage/view/GameView.java +++ b/Mage.Common/src/mage/view/GameView.java @@ -64,7 +64,6 @@ public class GameView implements Serializable { private SimpleCardsView hand; private Map opponentHands; private CardsView stack = new CardsView(); - //private List stackOrder = new ArrayList(); private List exiles = new ArrayList(); private List revealed = new ArrayList(); private List lookedAt = new ArrayList(); @@ -76,10 +75,12 @@ public class GameView implements Serializable { private String priorityPlayerName = ""; private int turn; private boolean special = false; + private boolean isPlayer; - public GameView(GameState state, Game game) { - priorityTime = game.getPriorityTime(); + public GameView(GameState state, Game game, boolean isPlayer) { + this.isPlayer = isPlayer; + this.priorityTime = game.getPriorityTime(); for (Player player: state.getPlayers().values()) { players.add(new PlayerView(player, state, game)); } @@ -275,4 +276,8 @@ public class GameView implements Serializable { return activePlayerId; } + public boolean isPlayer() { + return isPlayer; + } + } diff --git a/Mage.Server/src/main/java/mage/server/game/ReplaySession.java b/Mage.Server/src/main/java/mage/server/game/ReplaySession.java index 678722a16b..1138d482f6 100644 --- a/Mage.Server/src/main/java/mage/server/game/ReplaySession.java +++ b/Mage.Server/src/main/java/mage/server/game/ReplaySession.java @@ -56,7 +56,7 @@ public class ReplaySession implements GameCallback { replay.start(); User user = UserManager.getInstance().getUser(userId); if (user != null) { - user.fireCallback(new ClientCallback("replayInit", replay.getGame().getId(), new GameView(replay.next(), replay.getGame()))); + user.fireCallback(new ClientCallback("replayInit", replay.getGame().getId(), new GameView(replay.next(), replay.getGame(), false))); } } @@ -94,7 +94,7 @@ public class ReplaySession implements GameCallback { else { User user = UserManager.getInstance().getUser(userId); if (user != null) { - user.fireCallback(new ClientCallback("replayUpdate", replay.getGame().getId(), new GameView(state, game))); + user.fireCallback(new ClientCallback("replayUpdate", replay.getGame().getId(), new GameView(state, game, false))); } } }