Possibility to view other player's hands in UI.

This commit is contained in:
magenoxx 2011-08-04 21:51:00 +04:00
parent 752569874d
commit f3334c6e92
3 changed files with 94 additions and 9 deletions

View file

@ -34,6 +34,7 @@
package mage.client.game;
import com.sun.corba.se.spi.presentation.rmi.IDLNameTranslator;
import mage.Constants;
import mage.client.MageFrame;
import mage.client.cards.Cards;
@ -48,6 +49,7 @@ import mage.remote.Session;
import mage.view.*;
import org.apache.log4j.Logger;
import javax.net.ssl.HandshakeCompletedEvent;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
@ -69,6 +71,7 @@ import java.util.prefs.Preferences;
public class GamePanel extends javax.swing.JPanel {
private final static Logger logger = Logger.getLogger(GamePanel.class);
static final String YOUR_HAND = "Your hand";
private Map<UUID, PlayAreaPanel> players = new HashMap<UUID, PlayAreaPanel>();
private Map<UUID, ExileZoneDialog> exiles = new HashMap<UUID, ExileZoneDialog>();
@ -80,6 +83,7 @@ public class GamePanel extends javax.swing.JPanel {
private CombatDialog combat;
private PickNumberDialog pickNumber;
private JLayeredPane jLayeredPane;
private String chosenHandKey = "You";
private static final int HAND_CARD_WIDTH = 75;
private static final Dimension handCardDimension = new Dimension(HAND_CARD_WIDTH, (int)(HAND_CARD_WIDTH * 3.5f / 2.5f));
@ -174,6 +178,7 @@ public class GamePanel extends javax.swing.JPanel {
this.feedbackPanel.clear();
this.abilityPicker.init(session, gameId);
this.btnConcede.setVisible(true);
this.btnSwitchHands.setVisible(false);
this.pnlReplay.setVisible(false);
this.btnStopWatching.setVisible(false);
this.gameChatPanel.clear();
@ -190,6 +195,7 @@ public class GamePanel extends javax.swing.JPanel {
this.feedbackPanel.init(gameId);
this.feedbackPanel.clear();
this.btnConcede.setVisible(false);
this.btnSwitchHands.setVisible(false);
this.btnStopWatching.setVisible(true);
this.pnlReplay.setVisible(false);
this.gameChatPanel.clear();
@ -205,6 +211,7 @@ public class GamePanel extends javax.swing.JPanel {
MageFrame.addGame(gameId, this);
this.feedbackPanel.clear();
this.btnConcede.setVisible(false);
this.btnSwitchHands.setVisible(false);
this.btnStopWatching.setVisible(false);
this.pnlReplay.setVisible(true);
this.gameChatPanel.clear();
@ -298,9 +305,33 @@ public class GamePanel extends javax.swing.JPanel {
if (playerId == null || game.getHand() == null) {
this.hand.setVisible(false);
} else {
this.hand.loadCards(game.getHand(), bigCard, gameId);
int count = game.getHand().size();
hand.setPreferredSize(new java.awt.Dimension((getHandCardDimension().width + 5) * count + 5, getHandCardDimension().height + 20)); // for scroll
handCards.clear();
handCards.put(YOUR_HAND, game.getHand());
// Get opponents hand cards if available
if (game.getOpponentHands() != null) {
for (Map.Entry<String, CardsView> hand: game.getOpponentHands().entrySet()) {
handCards.put(hand.getKey(), hand.getValue());
}
}
if (!handCards.containsKey(chosenHandKey)) {
chosenHandKey = YOUR_HAND;
}
this.hand.loadCards(handCards.get(chosenHandKey), bigCard, gameId);
hand.setPreferredSize(new java.awt.Dimension((getHandCardDimension().width + 5) * game.getHand().size() + 5, getHandCardDimension().height + 20)); // for scroll
// set visible only if we have any other hand visible than ours
boolean previous = btnSwitchHands.isVisible();
boolean visible = handCards.size() > 1;
if (previous != visible) {
btnSwitchHands.setVisible(visible);
if (visible) {
JOptionPane.showMessageDialog(null, "You control other player's turn. \nUse \"Switch Hand\" on the bottom to switch between cards in different hands.");
} else {
JOptionPane.showMessageDialog(null, "You lost control on other player's turn.");
}
}
}
if (game.getPhase() != null)
this.txtPhase.setText(game.getPhase().toString());
@ -525,6 +556,7 @@ public class GamePanel extends javax.swing.JPanel {
lblPriority = new javax.swing.JLabel();
feedbackPanel = new mage.client.game.FeedbackPanel();
btnConcede = new javax.swing.JButton();
btnSwitchHands = new javax.swing.JButton();
btnStopWatching = new javax.swing.JButton();
bigCard = new mage.client.cards.BigCard();
stack = new mage.client.cards.Cards();
@ -544,6 +576,7 @@ public class GamePanel extends javax.swing.JPanel {
jTabbedPane1 = new JTabbedPane();
hand.setCardDimension(getHandCardDimension());
handCards = new HashMap<String, CardsView>();
jSplitPane1.setBorder(null);
jSplitPane1.setDividerSize(7);
@ -603,6 +636,15 @@ public class GamePanel extends javax.swing.JPanel {
}
});
btnSwitchHands.setText("Switch Hands");
btnSwitchHands.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
btnSwitchHandActionPerformed(null);
}
});
btnSwitchHands.setBorder(BorderFactory.createLineBorder(Color.red));
btnStopWatching.setText("Stop Watching");
btnStopWatching.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -676,6 +718,8 @@ public class GamePanel extends javax.swing.JPanel {
.addGap(10, 10, 10)
.addComponent(btnConcede)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnSwitchHands)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnStopWatching)
.addContainerGap(62, Short.MAX_VALUE))
.addComponent(bigCard, javax.swing.GroupLayout.DEFAULT_SIZE, 256, Short.MAX_VALUE)
@ -721,6 +765,7 @@ public class GamePanel extends javax.swing.JPanel {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(pnlGameInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnConcede)
.addComponent(btnSwitchHands)
.addComponent(btnStopWatching)))
);
@ -823,6 +868,25 @@ public class GamePanel extends javax.swing.JPanel {
}
}//GEN-LAST:event_btnConcedeActionPerformed
private void btnSwitchHandActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConcedeActionPerformed
String[] choices = handCards.keySet().toArray(new String[0]);
String chosenHandKey = (String) JOptionPane.showInputDialog(
this,
"Choose hand to display:", "Switch between hands",
JOptionPane.PLAIN_MESSAGE,
null,
choices,
YOUR_HAND);
if (chosenHandKey != null && chosenHandKey.length() > 0) {
chosenHandKey = chosenHandKey;
CardsView cards = handCards.get(chosenHandKey);
this.hand.loadCards(cards, bigCard, gameId);
hand.setPreferredSize(new java.awt.Dimension((getHandCardDimension().width + 5) * cards.size() + 5, getHandCardDimension().height + 20)); // for scroll
}
}
private void btnStopWatchingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopWatchingActionPerformed
if (modalQuestion("Are you sure you want to stop watching?", "Stop watching") == JOptionPane.YES_OPTION) {
session.stopWatching(gameId);
@ -910,6 +974,7 @@ public class GamePanel extends javax.swing.JPanel {
private mage.client.components.ability.AbilityPicker abilityPicker;
private mage.client.cards.BigCard bigCard;
private javax.swing.JButton btnConcede;
private javax.swing.JButton btnSwitchHands;
private javax.swing.JButton btnNextPlay;
private javax.swing.JButton btnPreviousPlay;
private javax.swing.JButton btnStopReplay;
@ -918,6 +983,7 @@ public class GamePanel extends javax.swing.JPanel {
private mage.client.game.FeedbackPanel feedbackPanel;
private mage.client.chat.ChatPanel userChatPanel;
private mage.client.cards.Cards hand;
private Map<String, CardsView> handCards;
private javax.swing.JPanel jPanel3;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JLabel lblActivePlayer;

View file

@ -31,6 +31,7 @@ package mage.view;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.MageObject;
@ -56,6 +57,7 @@ public class GameView implements Serializable {
private List<PlayerView> players = new ArrayList<PlayerView>();
private CardsView hand;
private Map<String, CardsView> opponentHands;
private CardsView stack = new CardsView();
private List<ExileView> exiles = new ArrayList<ExileView>();
private List<RevealedView> revealed = new ArrayList<RevealedView>();
@ -124,6 +126,14 @@ public class GameView implements Serializable {
this.hand = hand;
}
public Map<String, CardsView> getOpponentHands() {
return opponentHands;
}
public void setOpponentHands(Map<String, CardsView> opponentHands) {
this.opponentHands = opponentHands;
}
public TurnPhase getPhase() {
return phase;
}

View file

@ -29,18 +29,15 @@
package mage.server.game;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import mage.cards.Cards;
import mage.game.Game;
import mage.interfaces.callback.ClientCallback;
import mage.players.Player;
import mage.server.User;
import mage.server.UserManager;
import mage.server.util.ConfigSettings;
@ -197,8 +194,20 @@ public class GameSession extends GameWatcher {
@Override
public GameView getGameView() {
Player player = game.getPlayer(playerId);
GameView gameView = new GameView(game.getState(), game);
gameView.setHand(new CardsView(game.getPlayer(playerId).getHand().getCards(game)));
gameView.setHand(new CardsView(player.getHand().getCards(game)));
if (player.getPlayersUnderYourControl().size() > 0) {
Map<String, CardsView> handCards = new HashMap<String, CardsView>();
for (UUID playerId : player.getPlayersUnderYourControl()) {
Player opponent = game.getPlayer(playerId);
handCards.put(player.getName(), new CardsView(opponent.getHand().getCards(game)));
}
gameView.setOpponentHands(handCards);
}
//TODO: should player be able to look at all these cards?
List<LookedAtView> list = new ArrayList<LookedAtView>();
for (Entry<String, Cards> entry : game.getState().getLookedAt(playerId).entrySet()) {