* 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:
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;

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_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("<HTML>If the same question from the same ability would<br/>be asked again, it's automatically answered with <b>Yes</b>.");
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("<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.");
popupMenuAskYes.add(popupItemYesAsTextAndAbility);
menuItem = new JMenuItem("Always No for the same text and ability");
menuItem.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>.");
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("<HTML>If the same question from the same ability would<br/>"
+ "be asked again, it's automatically answered with <b>No</b>.<br/>"
+ "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("<HTML>If the same question would be asked again (regardless from which source),<br/> it's automatically answered with <b>Yes</b>.");
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("<HTML>If the same question would be asked again (regardless from which source),<br/>"
+ "it's automatically answered with <b>Yes</b>.<br/>"
+ "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("<HTML>If the same question would be asked again (regardless from which source),<br/> it's automatically answered with <b>No</b>.");
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("<HTML>If the same question would be asked again (regardless from which source),<br/>"
+ "it's automatically answered with <b>No</b>.<br/>"
+ "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")) {

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);
});
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");