* GUI: added yes/no auto-answers for state base actions dialogs (example: commander change zone);

This commit is contained in:
Oleg Agafonov 2021-08-16 02:00:35 +04:00
parent 9a0474d196
commit 43bdab8636
4 changed files with 89 additions and 47 deletions

View file

@ -86,6 +86,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
case QUESTION: case QUESTION:
setButtonState("Yes", "No", mode); setButtonState("Yes", "No", mode);
if (options != null && options.containsKey(ORIGINAL_ID)) { if (options != null && options.containsKey(ORIGINAL_ID)) {
// allows yes/no auto-answers for ability related
this.helper.setOriginalId((UUID) options.get(ORIGINAL_ID)); this.helper.setOriginalId((UUID) options.get(ORIGINAL_ID));
} }
break; break;

View file

@ -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_NAME_NO = "cmdAutoAnswerNameNo";
private static final String CMD_AUTO_ANSWER_RESET_ALL = "cmdAutoAnswerResetAll"; 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 JPopupMenu popupMenuAskYes;
private JMenuItem popupItemYesAsText;
private JMenuItem popupItemYesAsTextAndAbility;
private JPopupMenu popupMenuAskNo; private JPopupMenu popupMenuAskNo;
private JMenuItem popupItemNoAsText;
private JMenuItem popupItemNoAsTextAndAbility;
// originalId of feedback causing ability // originalId of feedback causing ability
private UUID originalId; private UUID originalId;
@ -244,8 +248,8 @@ public class HelperPanel extends JPanel {
} }
private void checkPopupMenu(MouseEvent e) { private void checkPopupMenu(MouseEvent e) {
if (e.isPopupTrigger() if (e.isPopupTrigger()) {
&& originalId != null) { // only Yes/No requests from abilities can be automated // allows any yes/no dialogs
JButton source = (JButton) e.getSource(); JButton source = (JButton) e.getSource();
if (source.getActionCommand().startsWith(QUESTION.toString())) { if (source.getActionCommand().startsWith(QUESTION.toString())) {
showPopupMenu(e.getComponent(), source.getActionCommand()); showPopupMenu(e.getComponent(), source.getActionCommand());
@ -268,16 +272,26 @@ public class HelperPanel extends JPanel {
if (!txtLeft.isEmpty()) { if (!txtLeft.isEmpty()) {
this.btnLeft.setText(txtLeft); this.btnLeft.setText(txtLeft);
if (mode != null) { if (mode != null) {
this.btnLeft.setActionCommand(mode.toString() + txtLeft); this.btnLeft.setActionCommand(mode + txtLeft);
} }
} }
this.btnRight.setVisible(rightVisible); this.btnRight.setVisible(rightVisible);
if (!txtRight.isEmpty()) { if (!txtRight.isEmpty()) {
this.btnRight.setText(txtRight); this.btnRight.setText(txtRight);
if (mode != null) { 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(); autoSizeButtonsAndFeedbackState();
} }
@ -310,7 +324,7 @@ public class HelperPanel extends JPanel {
public void setGameNeedFeedback(boolean need, TurnPhase gameTurnPhase) { public void setGameNeedFeedback(boolean need, TurnPhase gameTurnPhase) {
this.gameNeedFeedback = need; this.gameNeedFeedback = need;
this.gameTurnPhase = gameTurnPhase; this.gameTurnPhase = gameTurnPhase;
if (this.gameNeedFeedback) { if (this.gameNeedFeedback) {
// start notification sound timer // start notification sound timer
this.needFeedbackTimer.restart(); this.needFeedbackTimer.restart();
@ -465,37 +479,42 @@ public class HelperPanel extends JPanel {
popupMenuAskNo = new JPopupMenu(); popupMenuAskNo = new JPopupMenu();
// String tooltipText = ""; // String tooltipText = "";
JMenuItem menuItem; popupItemYesAsTextAndAbility = new JMenuItem("Auto-answer YES for the same TEXT and ABILITY");
menuItem = new JMenuItem("Always Yes for the same text and ability"); popupItemYesAsTextAndAbility.setActionCommand(CMD_AUTO_ANSWER_ID_YES);
menuItem.setActionCommand(CMD_AUTO_ANSWER_ID_YES); popupItemYesAsTextAndAbility.addActionListener(actionListener);
menuItem.addActionListener(actionListener); popupItemYesAsTextAndAbility.setToolTipText("<HTML>If the same question from the same ability would<br/>be asked again, it's automatically answered with <b>Yes</b>.<br/>You can reset it by battlefield right click menu.");
menuItem.setToolTipText("<HTML>If the same question from the same ability would<br/>be asked again, it's automatically answered with <b>Yes</b>."); popupMenuAskYes.add(popupItemYesAsTextAndAbility);
popupMenuAskYes.add(menuItem);
menuItem = new JMenuItem("Always No for the same text and ability"); popupItemNoAsTextAndAbility = new JMenuItem("Auto-answer NO for the same TEXT and ABILITY");
menuItem.setActionCommand(CMD_AUTO_ANSWER_ID_NO); popupItemNoAsTextAndAbility.setActionCommand(CMD_AUTO_ANSWER_ID_NO);
menuItem.setToolTipText("<HTML>If the same question from the same ability would<br/>be asked again, it's automatically answered with <b>No</b>."); popupItemNoAsTextAndAbility.setToolTipText("<HTML>If the same question from the same ability would<br/>"
menuItem.addActionListener(actionListener); + "be asked again, it's automatically answered with <b>No</b>.<br/>"
popupMenuAskNo.add(menuItem); + "You can reset it by battlefield right click menu.");
popupItemNoAsTextAndAbility.addActionListener(actionListener);
popupMenuAskNo.add(popupItemNoAsTextAndAbility);
menuItem = new JMenuItem("Always Yes for the same text"); popupItemYesAsText = new JMenuItem("Auto-answer YES for the same TEXT");
menuItem.setActionCommand(CMD_AUTO_ANSWER_NAME_YES); popupItemYesAsText.setActionCommand(CMD_AUTO_ANSWER_NAME_YES);
menuItem.setToolTipText("<HTML>If the same question would be asked again (regardless from which source),<br/> it's automatically answered with <b>Yes</b>."); popupItemYesAsText.setToolTipText("<HTML>If the same question would be asked again (regardless from which source),<br/>"
menuItem.addActionListener(actionListener); + "it's automatically answered with <b>Yes</b>.<br/>"
popupMenuAskYes.add(menuItem); + "You can reset it by battlefield right click menu.");
popupItemYesAsText.addActionListener(actionListener);
popupMenuAskYes.add(popupItemYesAsText);
menuItem = new JMenuItem("Always No for the same text"); popupItemNoAsText = new JMenuItem("Auto-answer NO for the same TEXT");
menuItem.setActionCommand(CMD_AUTO_ANSWER_NAME_NO); popupItemNoAsText.setActionCommand(CMD_AUTO_ANSWER_NAME_NO);
menuItem.setToolTipText("<HTML>If the same question would be asked again (regardless from which source),<br/> it's automatically answered with <b>No</b>."); popupItemNoAsText.setToolTipText("<HTML>If the same question would be asked again (regardless from which source),<br/>"
menuItem.addActionListener(actionListener); + "it's automatically answered with <b>No</b>.<br/>"
popupMenuAskNo.add(menuItem); + "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.setActionCommand(CMD_AUTO_ANSWER_RESET_ALL);
menuItem.addActionListener(actionListener); menuItem.addActionListener(actionListener);
popupMenuAskYes.add(menuItem); 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.setActionCommand(CMD_AUTO_ANSWER_RESET_ALL);
menuItem.addActionListener(actionListener); menuItem.addActionListener(actionListener);
popupMenuAskNo.add(menuItem); popupMenuAskNo.add(menuItem);
@ -528,13 +547,29 @@ public class HelperPanel extends JPanel {
} }
private void showPopupMenu(Component callingComponent, String actionCommand) { 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(); Point p = callingComponent.getLocationOnScreen();
// Show the JPopupMenu via program // Show the JPopupMenu via program
// Parameter desc // Parameter desc
// ---------------- // ----------------
// this - represents current frame // this - represents current frame
// 0,0 is the co ordinate where the popup // 0,0 is the coordinate where the popup
// is shown // is shown
JPopupMenu menu; JPopupMenu menu;
if (actionCommand.endsWith("Yes")) { if (actionCommand.endsWith("Yes")) {

View file

@ -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); 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); automaticConfirmsMenu.setMnemonic(KeyEvent.VK_U);
popupMenu.add(automaticConfirmsMenu); 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.setMnemonic(KeyEvent.VK_R);
menuItem.setToolTipText("Reset all effects that were added to the list of auto select replacement effects this game."); menuItem.setToolTipText("Reset all effects that were added to the list of auto select replacement effects this game.");
automaticConfirmsMenu.add(menuItem); automaticConfirmsMenu.add(menuItem);
// Reset the replacement effcts that were auto selected for the game // 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.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.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); automaticConfirmsMenu.add(menuItem);
// Reset the replacement effcts that were auto selected for the game // 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.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.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); 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)); menuItem.addActionListener(e -> SessionHandler.sendPlayerAction(PlayerAction.REQUEST_AUTO_ANSWER_RESET_ALL, gameId, null));
JMenu handCardsMenu = new JMenu("Cards on hand"); JMenu handCardsMenu = new JMenu("Cards on hand");

View file

@ -82,6 +82,7 @@ public class HumanPlayer extends PlayerImpl {
protected Set<String> triggerAutoOrderNameFirst = new HashSet<>(); protected Set<String> triggerAutoOrderNameFirst = new HashSet<>();
protected Set<String> triggerAutoOrderNameLast = new HashSet<>(); protected Set<String> triggerAutoOrderNameLast = new HashSet<>();
// auto-answer
protected Map<String, Boolean> requestAutoAnswerId = new HashMap<>(); protected Map<String, Boolean> requestAutoAnswerId = new HashMap<>();
protected Map<String, Boolean> requestAutoAnswerText = new HashMap<>(); protected Map<String, Boolean> requestAutoAnswerText = new HashMap<>();
@ -296,18 +297,23 @@ public class HumanPlayer extends PlayerImpl {
if (falseText != null) { if (falseText != null) {
options.put("UI.right.btn.text", falseText); options.put("UI.right.btn.text", falseText);
} }
if (source != null) {
//options.put(Constants.Option.ORIGINAL_ID, "")
}
// auto-answer // auto-answer
Boolean answer = null;
if (source != null) { if (source != null) {
Boolean answer = requestAutoAnswerId.get(source.getOriginalId() + "#" + message); // ability + text
if (answer != null) { answer = requestAutoAnswerId.get(source.getOriginalId() + "#" + message);
return answer; }
} else { if (answer == null) {
answer = requestAutoAnswerText.get(message); // text
if (answer != null) { answer = requestAutoAnswerText.get(message);
return answer; }
} if (answer != null) {
} return answer;
} }
while (canRespond()) { while (canRespond()) {