* UI: improved hand request dialog (users can ask your hand once per game, reset it by re-activate button);

This commit is contained in:
Oleg Agafonov 2019-05-28 13:46:29 +04:00
parent a18c3e1d88
commit 9a9b304fd5
8 changed files with 82 additions and 59 deletions

View file

@ -1,42 +1,27 @@
package mage.client.game; package mage.client.game;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.lang.reflect.Field;
import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.MenuSelectionManager;
import javax.swing.event.ChangeListener;
import mage.cards.decks.importer.DeckImporter; import mage.cards.decks.importer.DeckImporter;
import mage.client.MageFrame; import mage.client.MageFrame;
import mage.client.SessionHandler; import mage.client.SessionHandler;
import mage.client.cards.BigCard; import mage.client.cards.BigCard;
import mage.client.dialog.PreferencesDialog; import mage.client.dialog.PreferencesDialog;
import static mage.client.dialog.PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS;
import static mage.client.dialog.PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT;
import static mage.client.dialog.PreferencesDialog.KEY_GAME_MANA_AUTOPAYMENT_ONLY_ONE;
import static mage.client.dialog.PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY;
import mage.client.util.GUISizeHelper; import mage.client.util.GUISizeHelper;
import mage.constants.PlayerAction; import mage.constants.PlayerAction;
import mage.view.PlayerView; import mage.view.PlayerView;
import mage.view.UserRequestMessage; import mage.view.UserRequestMessage;
import javax.swing.*;
import javax.swing.GroupLayout.Alignment;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.*;
import java.lang.reflect.Field;
import java.util.UUID;
import static mage.client.dialog.PreferencesDialog.*;
/** /**
*
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
*/ */
public class PlayAreaPanel extends javax.swing.JPanel { public class PlayAreaPanel extends javax.swing.JPanel {
@ -77,7 +62,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
popupMenu = new JPopupMenu(); popupMenu = new JPopupMenu();
if (options.isPlayer) { if (options.isPlayer) {
addPopupMenuPlayer(player.getUserData().isAllowRequestShowHandCards()); addPopupMenuPlayer(player.getUserData().isAllowRequestHandToAll());
} else { } else {
addPopupMenuWatcher(); addPopupMenuWatcher();
} }
@ -331,12 +316,12 @@ public class PlayAreaPanel extends javax.swing.JPanel {
// Request to see hand cards // Request to see hand cards
menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.REQUEST_PERMISSION_TO_SEE_HAND_CARDS, gameId, playerId)); menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.REQUEST_PERMISSION_TO_SEE_HAND_CARDS, gameId, playerId));
} else { } else {
allowViewHandCardsMenuItem = new JCheckBoxMenuItem("Allow requests to show from other users", allowRequestToShowHandCards); allowViewHandCardsMenuItem = new JCheckBoxMenuItem("Allow hand requests from other users", allowRequestToShowHandCards);
allowViewHandCardsMenuItem.setMnemonic(KeyEvent.VK_A); allowViewHandCardsMenuItem.setMnemonic(KeyEvent.VK_A);
allowViewHandCardsMenuItem.setToolTipText("If activated watchers or other players can request to see your hand cards. If you grant this to a user, it's valid for the complete match."); allowViewHandCardsMenuItem.setToolTipText("Watchers or other players can request your hand cards once per game. Re-activate it to allow new requests.");
handCardsMenu.add(allowViewHandCardsMenuItem); handCardsMenu.add(allowViewHandCardsMenuItem);
// Requests allowed // requests allowed (disable -> enable to reset requested list)
allowViewHandCardsMenuItem.addActionListener(e -> { allowViewHandCardsMenuItem.addActionListener(e -> {
boolean requestsAllowed = ((JCheckBoxMenuItem) e.getSource()).getState(); boolean requestsAllowed = ((JCheckBoxMenuItem) e.getSource()).getState();
PreferencesDialog.setPrefValue(KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, requestsAllowed); PreferencesDialog.setPrefValue(KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, requestsAllowed);
@ -451,13 +436,13 @@ public class PlayAreaPanel extends javax.swing.JPanel {
} }
}); });
popupMenu.addSeparator(); popupMenu.addSeparator();
menuItem = new JMenuItem("<html>View current deck"); menuItem = new JMenuItem("<html>View current deck");
menuItem.setMnemonic(KeyEvent.VK_V); menuItem.setMnemonic(KeyEvent.VK_V);
popupMenu.add(menuItem); popupMenu.add(menuItem);
// View limited deck // View limited deck
menuItem.addActionListener(e -> { menuItem.addActionListener(e -> {
SessionHandler.sendPlayerAction(PlayerAction.VIEW_LIMITED_DECK, gameId, null); SessionHandler.sendPlayerAction(PlayerAction.VIEW_LIMITED_DECK, gameId, null);
@ -522,7 +507,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
this.playerPanel.update(player); this.playerPanel.update(player);
this.battlefieldPanel.update(player.getBattlefield()); this.battlefieldPanel.update(player.getBattlefield());
if (this.allowViewHandCardsMenuItem != null) { if (this.allowViewHandCardsMenuItem != null) {
this.allowViewHandCardsMenuItem.setSelected(player.getUserData().isAllowRequestShowHandCards()); this.allowViewHandCardsMenuItem.setSelected(player.getUserData().isAllowRequestHandToAll());
} }
} }
@ -547,14 +532,14 @@ public class PlayAreaPanel extends javax.swing.JPanel {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
layout.setHorizontalGroup( layout.setHorizontalGroup(
layout.createSequentialGroup() layout.createSequentialGroup()
.addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED) .addPreferredGap(ComponentPlacement.RELATED)
.addComponent(battlefieldPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(battlefieldPanel, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
); );
layout.setVerticalGroup( layout.setVerticalGroup(
layout.createParallelGroup(Alignment.LEADING) layout.createParallelGroup(Alignment.LEADING)
.addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(playerPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(battlefieldPanel, GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE) .addComponent(battlefieldPanel, GroupLayout.DEFAULT_SIZE, 160, Short.MAX_VALUE)
); );
this.setLayout(layout); this.setLayout(layout);
} }

View file

@ -1,9 +1,10 @@
package mage.view; package mage.view;
import java.io.Serializable;
import mage.players.net.UserData; import mage.players.net.UserData;
import mage.players.net.UserSkipPrioritySteps; import mage.players.net.UserSkipPrioritySteps;
import java.io.Serializable;
/** /**
* Transfer object for {@link mage.players.net.UserData} * Transfer object for {@link mage.players.net.UserData}
* *
@ -14,7 +15,6 @@ public class UserDataView implements Serializable {
protected int avatarId; protected int avatarId;
protected int userGroup; protected int userGroup;
protected boolean showAbilityPickerForced; protected boolean showAbilityPickerForced;
protected boolean allowRequestShowHandCards;
protected boolean confirmEmptyManaPool; protected boolean confirmEmptyManaPool;
protected UserSkipPrioritySteps userSkipPrioritySteps; protected UserSkipPrioritySteps userSkipPrioritySteps;
String flagName; String flagName;
@ -29,10 +29,9 @@ public class UserDataView implements Serializable {
} }
public UserDataView(int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards, public UserDataView(int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards,
boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps, String flagName, boolean askMoveToGraveOrder) { boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps, String flagName, boolean askMoveToGraveOrder) {
this.avatarId = avatarId; this.avatarId = avatarId;
this.showAbilityPickerForced = showAbilityPickerForced; this.showAbilityPickerForced = showAbilityPickerForced;
this.allowRequestShowHandCards = allowRequestShowHandCards;
this.userSkipPrioritySteps = userSkipPrioritySteps; this.userSkipPrioritySteps = userSkipPrioritySteps;
this.confirmEmptyManaPool = confirmEmptyManaPool; this.confirmEmptyManaPool = confirmEmptyManaPool;
this.flagName = flagName; this.flagName = flagName;
@ -43,7 +42,6 @@ public class UserDataView implements Serializable {
public UserDataView(UserData userData) { public UserDataView(UserData userData) {
this.avatarId = userData.getAvatarId(); this.avatarId = userData.getAvatarId();
this.userGroup = userData.getGroupId(); this.userGroup = userData.getGroupId();
this.allowRequestShowHandCards = userData.isAllowRequestShowHandCards();
this.showAbilityPickerForced = userData.isShowAbilityPickerForced(); this.showAbilityPickerForced = userData.isShowAbilityPickerForced();
this.userSkipPrioritySteps = userData.getUserSkipPrioritySteps(); this.userSkipPrioritySteps = userData.getUserSkipPrioritySteps();
this.confirmEmptyManaPool = userData.confirmEmptyManaPool(); this.confirmEmptyManaPool = userData.confirmEmptyManaPool();
@ -59,10 +57,6 @@ public class UserDataView implements Serializable {
return showAbilityPickerForced; return showAbilityPickerForced;
} }
public boolean allowRequestShowHandCards() {
return allowRequestShowHandCards;
}
public UserSkipPrioritySteps getUserSkipPrioritySteps() { public UserSkipPrioritySteps getUserSkipPrioritySteps() {
return userSkipPrioritySteps; return userSkipPrioritySteps;
} }

View file

@ -596,7 +596,9 @@ public class GameController implements GameCallback {
if (gameSession != null) { if (gameSession != null) {
UUID requestingPlayerId = getPlayerId(userIdRequester); UUID requestingPlayerId = getPlayerId(userIdRequester);
if (requestingPlayerId == null || !requestingPlayerId.equals(grantingPlayer.getId())) { // don't allow request for your own cards if (requestingPlayerId == null || !requestingPlayerId.equals(grantingPlayer.getId())) { // don't allow request for your own cards
if (grantingPlayer.isRequestToShowHandCardsAllowed()) { if (grantingPlayer.isPlayerAllowedToRequestHand(game.getId(), requestingPlayerId)) {
// one time request per user restrict, enable request will reset users list and allows again
grantingPlayer.addPlayerToRequestedHandList(game.getId(), requestingPlayerId);
gameSession.requestPermissionToSeeHandCards(userIdRequester); gameSession.requestPermissionToSeeHandCards(userIdRequester);
} else { } else {
// player does not allow the request // player does not allow the request

View file

@ -3077,8 +3077,13 @@ public class TestPlayer implements Player {
} }
@Override @Override
public boolean isRequestToShowHandCardsAllowed() { public boolean isPlayerAllowedToRequestHand(UUID gameId, UUID requesterPlayerId) {
return computerPlayer.isRequestToShowHandCardsAllowed(); return computerPlayer.isPlayerAllowedToRequestHand(gameId, requesterPlayerId);
}
@Override
public void addPlayerToRequestedHandList(UUID gameId, UUID requesterPlayerId) {
computerPlayer.addPlayerToRequestedHandList(gameId, requesterPlayerId);
} }
@Override @Override

View file

@ -1242,10 +1242,15 @@ public class PlayerStub implements Player {
} }
@Override @Override
public boolean isRequestToShowHandCardsAllowed() { public boolean isPlayerAllowedToRequestHand(UUID gameId, UUID requesterPlayerId) {
return false; return false;
} }
@Override
public void addPlayerToRequestedHandList(UUID gameId, UUID requesterPlayerId) {
//
}
@Override @Override
public Set<UUID> getUsersAllowedToSeeHandCards() { public Set<UUID> getUsersAllowedToSeeHandCards() {
return null; return null;

View file

@ -855,7 +855,9 @@ public interface Player extends MageItem, Copyable<Player> {
void revokePermissionToSeeHandCards(); void revokePermissionToSeeHandCards();
boolean isRequestToShowHandCardsAllowed(); boolean isPlayerAllowedToRequestHand(UUID gameId, UUID requesterPlayerId);
void addPlayerToRequestedHandList(UUID gameId, UUID requesterPlayerId);
Set<UUID> getUsersAllowedToSeeHandCards(); Set<UUID> getUsersAllowedToSeeHandCards();

View file

@ -2284,6 +2284,7 @@ public abstract class PlayerImpl implements Player, Serializable {
break; break;
case PERMISSION_REQUESTS_ALLOWED_ON: case PERMISSION_REQUESTS_ALLOWED_ON:
userData.setAllowRequestShowHandCards(true); userData.setAllowRequestShowHandCards(true);
userData.resetRequestedHandPlayersList(game.getId()); // users can send request again
break; break;
} }
logger.trace("PASS Priority: " + playerAction.toString()); logger.trace("PASS Priority: " + playerAction.toString());
@ -3969,8 +3970,13 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
@Override @Override
public boolean isRequestToShowHandCardsAllowed() { public boolean isPlayerAllowedToRequestHand(UUID gameId, UUID requesterPlayerId) {
return userData.isAllowRequestShowHandCards(); return userData.isAllowRequestHandToPlayer(gameId, requesterPlayerId);
}
@Override
public void addPlayerToRequestedHandList(UUID gameId, UUID requesterPlayerId) {
userData.addPlayerToRequestedHandList(gameId, requesterPlayerId);
} }
@Override @Override

View file

@ -1,6 +1,7 @@
package mage.players.net; package mage.players.net;
import java.io.Serializable; import java.io.Serializable;
import java.util.*;
/** /**
* User data that is passed during connection to the server. * User data that is passed during connection to the server.
@ -24,6 +25,7 @@ public class UserData implements Serializable {
protected boolean autoOrderTrigger; protected boolean autoOrderTrigger;
protected boolean useFirstManaAbility = false; protected boolean useFirstManaAbility = false;
private String userIdStr; private String userIdStr;
protected Map<UUID, Set<UUID>> requestedHandPlayersList; // game -> players list
protected String matchHistory; protected String matchHistory;
protected int matchQuitRatio; protected int matchQuitRatio;
@ -35,9 +37,9 @@ public class UserData implements Serializable {
private int limitedRating; private int limitedRating;
public UserData(UserGroup userGroup, int avatarId, boolean showAbilityPickerForced, public UserData(UserGroup userGroup, int avatarId, boolean showAbilityPickerForced,
boolean allowRequestShowHandCards, boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps, boolean allowRequestShowHandCards, boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps,
String flagName, boolean askMoveToGraveOrder, boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted, String flagName, boolean askMoveToGraveOrder, boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted,
boolean passPriorityCast, boolean passPriorityActivation, boolean autoOrderTrigger, boolean useFirstManaAbility, String userIdStr) { boolean passPriorityCast, boolean passPriorityActivation, boolean autoOrderTrigger, boolean useFirstManaAbility, String userIdStr) {
this.groupId = userGroup.getGroupId(); this.groupId = userGroup.getGroupId();
this.avatarId = avatarId; this.avatarId = avatarId;
this.showAbilityPickerForced = showAbilityPickerForced; this.showAbilityPickerForced = showAbilityPickerForced;
@ -57,6 +59,7 @@ public class UserData implements Serializable {
this.tourneyHistory = ""; this.tourneyHistory = "";
this.tourneyQuitRatio = 0; this.tourneyQuitRatio = 0;
this.userIdStr = userIdStr; this.userIdStr = userIdStr;
this.requestedHandPlayersList = new HashMap<>();
} }
public void update(UserData userData) { public void update(UserData userData) {
@ -106,14 +109,35 @@ public class UserData implements Serializable {
this.showAbilityPickerForced = showAbilityPickerForced; this.showAbilityPickerForced = showAbilityPickerForced;
} }
public boolean isAllowRequestShowHandCards() { public boolean isAllowRequestHandToAll() {
return allowRequestShowHandCards; return allowRequestShowHandCards;
} }
public boolean isAllowRequestHandToPlayer(UUID gameId, UUID requesterPlayerId) {
// once per game
boolean allowToPlayer = true;
if (requestedHandPlayersList.containsKey(gameId) && requestedHandPlayersList.get(gameId).contains(requesterPlayerId)) {
allowToPlayer = false;
}
return isAllowRequestHandToAll() && allowToPlayer;
}
public void addPlayerToRequestedHandList(UUID gameId, UUID requesterPlayerId) {
if (!requestedHandPlayersList.containsKey(gameId)) {
requestedHandPlayersList.put(gameId, new HashSet<>());
}
Set<UUID> requestedPlayers = requestedHandPlayersList.get(gameId);
requestedPlayers.add(requesterPlayerId);
}
public void setAllowRequestShowHandCards(boolean allowRequestShowHandCards) { public void setAllowRequestShowHandCards(boolean allowRequestShowHandCards) {
this.allowRequestShowHandCards = allowRequestShowHandCards; this.allowRequestShowHandCards = allowRequestShowHandCards;
} }
public void resetRequestedHandPlayersList(UUID gameId) {
this.requestedHandPlayersList.remove(gameId);
}
public UserSkipPrioritySteps getUserSkipPrioritySteps() { public UserSkipPrioritySteps getUserSkipPrioritySteps() {
return userSkipPrioritySteps; return userSkipPrioritySteps;
} }