From 43bdab86363bf4747c64b5ddfcd5a1a3c68b8f72 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Mon, 16 Aug 2021 02:00:35 +0400 Subject: [PATCH] * GUI: added yes/no auto-answers for state base actions dialogs (example: commander change zone); --- .../java/mage/client/game/FeedbackPanel.java | 1 + .../java/mage/client/game/HelperPanel.java | 97 +++++++++++++------ .../java/mage/client/game/PlayAreaPanel.java | 14 +-- .../src/mage/player/human/HumanPlayer.java | 24 +++-- 4 files changed, 89 insertions(+), 47 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java b/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java index 3fc47ef18c3..5a2274d636d 100644 --- a/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/FeedbackPanel.java @@ -86,6 +86,7 @@ public class FeedbackPanel extends javax.swing.JPanel { case QUESTION: setButtonState("Yes", "No", mode); if (options != null && options.containsKey(ORIGINAL_ID)) { + // allows yes/no auto-answers for ability related this.helper.setOriginalId((UUID) options.get(ORIGINAL_ID)); } break; diff --git a/Mage.Client/src/main/java/mage/client/game/HelperPanel.java b/Mage.Client/src/main/java/mage/client/game/HelperPanel.java index 0f3a7e57a49..32d284a74df 100644 --- a/Mage.Client/src/main/java/mage/client/game/HelperPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/HelperPanel.java @@ -53,9 +53,13 @@ public class HelperPanel extends JPanel { private static final String CMD_AUTO_ANSWER_NAME_NO = "cmdAutoAnswerNameNo"; private static final String CMD_AUTO_ANSWER_RESET_ALL = "cmdAutoAnswerResetAll"; - // popup menu for set automatic answers + // popup menu for keep auto-answer in yes/no dialogs private JPopupMenu popupMenuAskYes; + private JMenuItem popupItemYesAsText; + private JMenuItem popupItemYesAsTextAndAbility; private JPopupMenu popupMenuAskNo; + private JMenuItem popupItemNoAsText; + private JMenuItem popupItemNoAsTextAndAbility; // originalId of feedback causing ability private UUID originalId; @@ -244,8 +248,8 @@ public class HelperPanel extends JPanel { } private void checkPopupMenu(MouseEvent e) { - if (e.isPopupTrigger() - && originalId != null) { // only Yes/No requests from abilities can be automated + if (e.isPopupTrigger()) { + // allows any yes/no dialogs JButton source = (JButton) e.getSource(); if (source.getActionCommand().startsWith(QUESTION.toString())) { showPopupMenu(e.getComponent(), source.getActionCommand()); @@ -268,16 +272,26 @@ public class HelperPanel extends JPanel { if (!txtLeft.isEmpty()) { this.btnLeft.setText(txtLeft); if (mode != null) { - this.btnLeft.setActionCommand(mode.toString() + txtLeft); + this.btnLeft.setActionCommand(mode + txtLeft); } } + this.btnRight.setVisible(rightVisible); if (!txtRight.isEmpty()) { this.btnRight.setText(txtRight); if (mode != null) { - this.btnRight.setActionCommand(mode.toString() + txtRight); + this.btnRight.setActionCommand(mode + txtRight); } } + + // auto-answer hints + String buttonTooltip = null; + if (mode == QUESTION) { + buttonTooltip = "Right click on button to make auto-answer."; + } + this.btnLeft.setToolTipText(buttonTooltip); + this.btnRight.setToolTipText(buttonTooltip); + autoSizeButtonsAndFeedbackState(); } @@ -310,7 +324,7 @@ public class HelperPanel extends JPanel { public void setGameNeedFeedback(boolean need, TurnPhase gameTurnPhase) { this.gameNeedFeedback = need; this.gameTurnPhase = gameTurnPhase; - + if (this.gameNeedFeedback) { // start notification sound timer this.needFeedbackTimer.restart(); @@ -465,37 +479,42 @@ public class HelperPanel extends JPanel { popupMenuAskNo = new JPopupMenu(); // String tooltipText = ""; - JMenuItem menuItem; - menuItem = new JMenuItem("Always Yes for the same text and ability"); - menuItem.setActionCommand(CMD_AUTO_ANSWER_ID_YES); - menuItem.addActionListener(actionListener); - menuItem.setToolTipText("If the same question from the same ability would
be asked again, it's automatically answered with Yes."); - popupMenuAskYes.add(menuItem); + popupItemYesAsTextAndAbility = new JMenuItem("Auto-answer YES for the same TEXT and ABILITY"); + popupItemYesAsTextAndAbility.setActionCommand(CMD_AUTO_ANSWER_ID_YES); + popupItemYesAsTextAndAbility.addActionListener(actionListener); + popupItemYesAsTextAndAbility.setToolTipText("If the same question from the same ability would
be asked again, it's automatically answered with Yes.
You can reset it by battlefield right click menu."); + popupMenuAskYes.add(popupItemYesAsTextAndAbility); - menuItem = new JMenuItem("Always No for the same text and ability"); - menuItem.setActionCommand(CMD_AUTO_ANSWER_ID_NO); - menuItem.setToolTipText("If the same question from the same ability would
be asked again, it's automatically answered with No."); - menuItem.addActionListener(actionListener); - popupMenuAskNo.add(menuItem); + popupItemNoAsTextAndAbility = new JMenuItem("Auto-answer NO for the same TEXT and ABILITY"); + popupItemNoAsTextAndAbility.setActionCommand(CMD_AUTO_ANSWER_ID_NO); + popupItemNoAsTextAndAbility.setToolTipText("If the same question from the same ability would
" + + "be asked again, it's automatically answered with No.
" + + "You can reset it by battlefield right click menu."); + popupItemNoAsTextAndAbility.addActionListener(actionListener); + popupMenuAskNo.add(popupItemNoAsTextAndAbility); - menuItem = new JMenuItem("Always Yes for the same text"); - menuItem.setActionCommand(CMD_AUTO_ANSWER_NAME_YES); - menuItem.setToolTipText("If the same question would be asked again (regardless from which source),
it's automatically answered with Yes."); - menuItem.addActionListener(actionListener); - popupMenuAskYes.add(menuItem); + popupItemYesAsText = new JMenuItem("Auto-answer YES for the same TEXT"); + popupItemYesAsText.setActionCommand(CMD_AUTO_ANSWER_NAME_YES); + popupItemYesAsText.setToolTipText("If the same question would be asked again (regardless from which source),
" + + "it's automatically answered with Yes.
" + + "You can reset it by battlefield right click menu."); + popupItemYesAsText.addActionListener(actionListener); + popupMenuAskYes.add(popupItemYesAsText); - menuItem = new JMenuItem("Always No for the same text"); - menuItem.setActionCommand(CMD_AUTO_ANSWER_NAME_NO); - menuItem.setToolTipText("If the same question would be asked again (regardless from which source),
it's automatically answered with No."); - menuItem.addActionListener(actionListener); - popupMenuAskNo.add(menuItem); + popupItemNoAsText = new JMenuItem("Auto-answer NO for the same TEXT"); + popupItemNoAsText.setActionCommand(CMD_AUTO_ANSWER_NAME_NO); + popupItemNoAsText.setToolTipText("If the same question would be asked again (regardless from which source),
" + + "it's automatically answered with No.
" + + "You can reset it by battlefield right click menu."); + popupItemNoAsText.addActionListener(actionListener); + popupMenuAskNo.add(popupItemNoAsText); - menuItem = new JMenuItem("Delete all automatic Yes/No settings"); + JMenuItem menuItem = new JMenuItem("Reset all YER/NO auto-answers"); menuItem.setActionCommand(CMD_AUTO_ANSWER_RESET_ALL); menuItem.addActionListener(actionListener); popupMenuAskYes.add(menuItem); - menuItem = new JMenuItem("Delete all automatic Yes/No settings"); + menuItem = new JMenuItem("Reset all YER/NO auto-answers"); menuItem.setActionCommand(CMD_AUTO_ANSWER_RESET_ALL); menuItem.addActionListener(actionListener); popupMenuAskNo.add(menuItem); @@ -528,13 +547,29 @@ public class HelperPanel extends JPanel { } private void showPopupMenu(Component callingComponent, String actionCommand) { - // Get the location of the point 'on the screen' + // keep auto-answer for yes/no + + // two modes: + // - remember text for all (example: commander zone change); + // - remember text + ability for source only (example: any optional ability) + + // yes + popupItemYesAsText.setEnabled(true); + popupItemYesAsTextAndAbility.setEnabled(originalId != null); + popupItemYesAsText.setEnabled(true); + popupItemYesAsTextAndAbility.setEnabled(originalId != null); + // no + popupItemNoAsText.setEnabled(true); + popupItemNoAsTextAndAbility.setEnabled(originalId != null); + popupItemNoAsText.setEnabled(true); + popupItemNoAsTextAndAbility.setEnabled(originalId != null); + Point p = callingComponent.getLocationOnScreen(); // Show the JPopupMenu via program // Parameter desc // ---------------- // this - represents current frame - // 0,0 is the co ordinate where the popup + // 0,0 is the coordinate where the popup // is shown JPopupMenu menu; if (actionCommand.endsWith("Yes")) { 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 fbde9c3a336..3e4f0df69dd 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayAreaPanel.java @@ -283,29 +283,29 @@ public class PlayAreaPanel extends javax.swing.JPanel { SessionHandler.sendPlayerAction(useFirstManaAbility ? PlayerAction.USE_FIRST_MANA_ABILITY_ON : PlayerAction.USE_FIRST_MANA_ABILITY_OFF, gameId, null); }); - JMenu automaticConfirmsMenu = new JMenu("Automatic confirms"); + JMenu automaticConfirmsMenu = new JMenu("Auto-answers"); automaticConfirmsMenu.setMnemonic(KeyEvent.VK_U); popupMenu.add(automaticConfirmsMenu); - menuItem = new JMenuItem("Replacement effects - reset auto select"); + menuItem = new JMenuItem("Replacement effects - reset all auto-answers"); menuItem.setMnemonic(KeyEvent.VK_R); menuItem.setToolTipText("Reset all effects that were added to the list of auto select replacement effects this game."); automaticConfirmsMenu.add(menuItem); // Reset the replacement effcts that were auto selected for the game menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.RESET_AUTO_SELECT_REPLACEMENT_EFFECTS, gameId, null)); - menuItem = new JMenuItem("Triggered abilities - reset auto stack order"); + menuItem = new JMenuItem("Triggered abilities - reset all auto-answers for stack order"); menuItem.setMnemonic(KeyEvent.VK_T); - menuItem.setToolTipText("Deletes all triggered ability order settings you added during the game."); + menuItem.setToolTipText("Reset all triggered ability order settings you added during the game."); automaticConfirmsMenu.add(menuItem); // Reset the replacement effcts that were auto selected for the game menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.TRIGGER_AUTO_ORDER_RESET_ALL, gameId, null)); - menuItem = new JMenuItem("Use requests - reset automatic answers"); + menuItem = new JMenuItem("Yes/no requests - reset all auto-answers"); menuItem.setMnemonic(KeyEvent.VK_T); - menuItem.setToolTipText("Deletes all defined automatic answers for Yes/No usage requests."); + menuItem.setToolTipText("Reset all defined automatic answers for Yes/No usage requests (with two buttons)."); automaticConfirmsMenu.add(menuItem); - // Reset the replacement effcts that were auto selected for the game + // Reset the replacement and yes/no dialogs that were auto selected for the game menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL, gameId, null)); JMenu handCardsMenu = new JMenu("Cards on hand"); diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 5eced2ccbb4..ba1cfdc9c76 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -82,6 +82,7 @@ public class HumanPlayer extends PlayerImpl { protected Set triggerAutoOrderNameFirst = new HashSet<>(); protected Set triggerAutoOrderNameLast = new HashSet<>(); + // auto-answer protected Map requestAutoAnswerId = new HashMap<>(); protected Map requestAutoAnswerText = new HashMap<>(); @@ -296,18 +297,23 @@ public class HumanPlayer extends PlayerImpl { if (falseText != null) { options.put("UI.right.btn.text", falseText); } + if (source != null) { + //options.put(Constants.Option.ORIGINAL_ID, "") + } + // auto-answer + Boolean answer = null; if (source != null) { - Boolean answer = requestAutoAnswerId.get(source.getOriginalId() + "#" + message); - if (answer != null) { - return answer; - } else { - answer = requestAutoAnswerText.get(message); - if (answer != null) { - return answer; - } - } + // ability + text + answer = requestAutoAnswerId.get(source.getOriginalId() + "#" + message); + } + if (answer == null) { + // text + answer = requestAutoAnswerText.get(message); + } + if (answer != null) { + return answer; } while (canRespond()) {