forked from External/mage
* Added possibility to allow other players to see hand cards of player.
This commit is contained in:
parent
d0e1107a3e
commit
7e145d2cfd
33 changed files with 1093 additions and 190 deletions
|
|
@ -152,7 +152,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
private boolean initialized = false;
|
||||
private int lastUpdatedTurn;
|
||||
private boolean menuNameSet = false;
|
||||
|
||||
private boolean handCardsOfOpponentAvailable = false;
|
||||
|
||||
private Map<String, Card> loadedCards = new HashMap<>();
|
||||
|
||||
|
|
@ -388,17 +388,18 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
this.feedbackPanel.init(gameId);
|
||||
this.feedbackPanel.clear();
|
||||
|
||||
|
||||
this.btnConcede.setVisible(false);
|
||||
this.btnStopWatching.setVisible(true);
|
||||
this.btnSwitchHands.setVisible(false);
|
||||
this.chosenHandKey = "";
|
||||
this.btnCancelSkip.setVisible(false);
|
||||
|
||||
this.btnSkipToNextTurn.setVisible(false);
|
||||
this.btnSkipToEndTurn.setVisible(false);
|
||||
this.btnSkipToNextMain.setVisible(false);
|
||||
this.btnSkipStack.setVisible(false);
|
||||
this.btnSkipToYourTurn.setVisible(false);
|
||||
|
||||
this.btnSkipToYourTurn.setVisible(false);
|
||||
|
||||
this.pnlReplay.setVisible(false);
|
||||
this.gameChatPanel.clear();
|
||||
|
|
@ -530,45 +531,59 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
}
|
||||
|
||||
public synchronized void updateGame(GameView game, Map<String, Serializable> options) {
|
||||
if (playerId == null || game.getHand() == null) {
|
||||
if (playerId == null && game.getWatchedHands() == null) {
|
||||
this.handContainer.setVisible(false);
|
||||
} else {
|
||||
this.handContainer.setVisible(true);
|
||||
handCards.clear();
|
||||
handCards.put(YOUR_HAND, game.getHand());
|
||||
|
||||
// Mark playable
|
||||
if (game.getCanPlayInHand() != null) {
|
||||
for (CardView card : handCards.get(YOUR_HAND).values()) {
|
||||
if (game.getCanPlayInHand().contains(card.getId())) {
|
||||
card.setPlayable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get opponents hand cards if available
|
||||
if (game.getOpponentHands() != null) {
|
||||
for (Map.Entry<String, SimpleCardsView> hand: game.getOpponentHands().entrySet()) {
|
||||
if (game.getWatchedHands() != null) {
|
||||
for (Map.Entry<String, SimpleCardsView> hand: game.getWatchedHands().entrySet()) {
|
||||
handCards.put(hand.getKey(), CardsViewUtil.convertSimple(hand.getValue(), loadedCards));
|
||||
}
|
||||
}
|
||||
|
||||
if (!handCards.containsKey(chosenHandKey)) {
|
||||
chosenHandKey = YOUR_HAND;
|
||||
if (playerId != null) {
|
||||
handCards.put(YOUR_HAND, game.getHand());
|
||||
// Mark playable
|
||||
if (game.getCanPlayInHand() != null) {
|
||||
for (CardView card : handCards.get(YOUR_HAND).values()) {
|
||||
if (game.getCanPlayInHand().contains(card.getId())) {
|
||||
card.setPlayable(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Get opponents hand cards if available (only possible for players)
|
||||
if (game.getOpponentHands() != null) {
|
||||
for (Map.Entry<String, SimpleCardsView> hand: game.getOpponentHands().entrySet()) {
|
||||
handCards.put(hand.getKey(), CardsViewUtil.convertSimple(hand.getValue(), loadedCards));
|
||||
}
|
||||
}
|
||||
if (!handCards.containsKey(chosenHandKey)) {
|
||||
chosenHandKey = YOUR_HAND;
|
||||
}
|
||||
} else if (chosenHandKey.isEmpty() && handCards.size() > 0) {
|
||||
chosenHandKey = handCards.keySet().iterator().next();
|
||||
}
|
||||
if (chosenHandKey != null && handCards.containsKey(chosenHandKey)) {
|
||||
handContainer.loadCards(handCards.get(chosenHandKey), bigCard, gameId);
|
||||
}
|
||||
handContainer.loadCards(handCards.get(chosenHandKey), bigCard, gameId);
|
||||
|
||||
hideAll();
|
||||
|
||||
// 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\" button to switch between cards in different hands.");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "You lost control on other player's turn.");
|
||||
|
||||
if (playerId != null) {
|
||||
// set visible only if we have any other hand visible than ours
|
||||
btnSwitchHands.setVisible(handCards.size() > 1);
|
||||
boolean change = (handCardsOfOpponentAvailable != (game.getOpponentHands() != null));
|
||||
if (change) {
|
||||
handCardsOfOpponentAvailable = !handCardsOfOpponentAvailable;
|
||||
if (handCardsOfOpponentAvailable) {
|
||||
JOptionPane.showMessageDialog(null, "You control other player's turn. \nUse \"Switch Hand\" button to switch between cards in different hands.");
|
||||
} else {
|
||||
JOptionPane.showMessageDialog(null, "You lost control on other player's turn.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
btnSwitchHands.setVisible(!handCards.isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1280,7 +1295,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnStopWatching.setBorder(new EmptyBorder(0,0,0,0));
|
||||
btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.getInstance().getStopWatchButtonImage()));
|
||||
btnStopWatching.setFocusable(false);
|
||||
btnSwitchHands.setToolTipText("Stop watching this game.");
|
||||
btnStopWatching.setToolTipText("Stop watching this game.");
|
||||
btnStopWatching.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
|
|
@ -1620,42 +1635,42 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
|
||||
private void btnConcedeActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
if (modalQuestion("Are you sure you want to concede?", "Confirm concede") == JOptionPane.YES_OPTION) {
|
||||
session.sendPlayerAction(PlayerAction.CONCEDE, gameId);
|
||||
session.sendPlayerAction(PlayerAction.CONCEDE, gameId, null);
|
||||
}
|
||||
}
|
||||
|
||||
private void btnEndTurnActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId);
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null);
|
||||
AudioManager.playOnSkipButton();
|
||||
updateSkipButtons(true, false, false, false, false);
|
||||
}
|
||||
|
||||
private void btnUntilEndOfTurnActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_TURN_END_STEP, gameId);
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_TURN_END_STEP, gameId, null);
|
||||
AudioManager.playOnSkipButton();
|
||||
updateSkipButtons(false, true, false, false, false);
|
||||
}
|
||||
|
||||
private void btnUntilNextMainPhaseActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE, gameId);
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_MAIN_PHASE, gameId, null);
|
||||
AudioManager.playOnSkipButton();
|
||||
updateSkipButtons(false, false, true, false, false);
|
||||
}
|
||||
|
||||
private void btnPassPriorityUntilNextYourTurnActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId);
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_MY_NEXT_TURN, gameId, null);
|
||||
AudioManager.playOnSkipButton();
|
||||
updateSkipButtons(false, false, false, true, false);
|
||||
}
|
||||
|
||||
private void btnPassPriorityUntilStackResolvedActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_STACK_RESOLVED, gameId);
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_STACK_RESOLVED, gameId, null);
|
||||
AudioManager.playOnSkipButton();
|
||||
updateSkipButtons(false, false, false, false, true);
|
||||
}
|
||||
|
||||
private void restorePriorityActionPerformed(java.awt.event.ActionEvent evt) {
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId);
|
||||
session.sendPlayerAction(PlayerAction.PASS_PRIORITY_CANCEL_ALL_ACTIONS, gameId, null);
|
||||
AudioManager.playOnSkipButtonCancel();
|
||||
updateSkipButtons(false, false, false, false, false);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue