mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
* UI: improved hand request dialog (users can ask your hand once per game, reset it by re-activate button);
This commit is contained in:
parent
a18c3e1d88
commit
9a9b304fd5
8 changed files with 82 additions and 59 deletions
|
@ -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);
|
||||||
|
@ -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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -32,7 +32,6 @@ public class UserDataView implements Serializable {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue