* GUI: added auto-choose for replacement effects (remember answer in dialog + reset answer in popup menu + new option in preferences; #4360, #328, #4219, #6676, #7914);

This commit is contained in:
Oleg Agafonov 2021-08-09 11:25:51 +04:00
parent c081d3fa33
commit c9ab896d24
11 changed files with 311 additions and 77 deletions

View file

@ -324,9 +324,9 @@ public class PickCheckBoxDialog extends MageDialog {
if (item != null) {
if (choice.isKeyChoice()) {
choice.setChoiceByKey(item.getKey());
choice.setChoiceByKey(item.getKey(), false);
} else {
choice.setChoice(item.getKey());
choice.setChoice(item.getKey(), false);
}
return true;
} else {

View file

@ -161,7 +161,8 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="cbSpecial" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="btOK" linkSize="3" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
@ -177,6 +178,7 @@
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btCancel" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="btOK" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="cbSpecial" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -203,6 +205,11 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btCancelActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="cbSpecial">
<Properties>
<Property name="text" type="java.lang.String" value="Remember choose"/>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>

View file

@ -18,10 +18,11 @@ import mage.client.util.gui.MageDialogState;
public class PickChoiceDialog extends MageDialog {
Choice choice;
java.util.List<KeyValueItem> allItems = new ArrayList<>();
DefaultListModel<KeyValueItem> dataModel = new DefaultListModel<>();
final private static String HTML_TEMPLATE = "<html><div style='text-align: center;'>%s</div></html>";
final private static String HTML_HEADERS_TEMPLATE = "<html><div style='text-align: center;'>%s</div></html>";
public void showDialog(Choice choice) {
showDialog(choice, null, null, null);
@ -40,9 +41,13 @@ public class PickChoiceDialog extends MageDialog {
setLabelText(this.labelMessage, choice.getMessage());
setLabelText(this.labelSubMessage, choice.getSubMessage());
btCancel.setEnabled(!choice.isRequired());
// special choice (example: auto-choose answer next time)
cbSpecial.setVisible(choice.isSpecialEnabled());
cbSpecial.setText(choice.getSpecialText());
cbSpecial.setToolTipText(choice.getSpecialHint());
// 2 modes: string or key-values
// sore data in allItems for inremental filtering
// http://logicbig.com/tutorials/core-java-tutorial/swing/list-filter/
@ -199,7 +204,7 @@ public class PickChoiceDialog extends MageDialog {
private void setLabelText(JLabel label, String text) {
if ((text != null) && !text.equals("")) {
label.setText(String.format(HTML_TEMPLATE, text));
label.setText(String.format(HTML_HEADERS_TEMPLATE, text));
label.setVisible(true);
} else {
label.setText("");
@ -247,6 +252,7 @@ public class PickChoiceDialog extends MageDialog {
public boolean setChoice() {
KeyValueItem item = (KeyValueItem) this.listChoices.getSelectedValue();
boolean isSpecial = choice.isSpecialEnabled() && cbSpecial.isSelected();
// auto select one item (after incemental filtering)
if ((item == null) && (this.listChoices.getModel().getSize() == 1)) {
@ -256,12 +262,23 @@ public class PickChoiceDialog extends MageDialog {
if (item != null) {
if (choice.isKeyChoice()) {
choice.setChoiceByKey(item.getKey());
choice.setChoiceByKey(item.getKey(), isSpecial);
} else {
choice.setChoice(item.getKey());
choice.setChoice(item.getKey(), isSpecial);
}
return true;
} else {
// special choice can be empty
if (choice.isSpecialEnabled() && choice.isSpecialCanBeEmpty()) {
if (choice.isKeyChoice()) {
choice.setChoiceByKey(null, isSpecial);
} else {
choice.setChoice(null, isSpecial);
}
return true;
}
// nothing to choose
choice.clearChoice();
return false;
}
@ -311,6 +328,7 @@ public class PickChoiceDialog extends MageDialog {
panelCommands = new javax.swing.JPanel();
btOK = new javax.swing.JButton();
btCancel = new javax.swing.JButton();
cbSpecial = new javax.swing.JCheckBox();
setResizable(true);
@ -386,19 +404,22 @@ public class PickChoiceDialog extends MageDialog {
}
});
cbSpecial.setText("Remember choose");
javax.swing.GroupLayout panelCommandsLayout = new javax.swing.GroupLayout(panelCommands);
panelCommands.setLayout(panelCommandsLayout);
panelCommandsLayout.setHorizontalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelCommandsLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cbSpecial)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btOK)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btCancel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, btCancel, btOK);
panelCommandsLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btCancel, btOK});
panelCommandsLayout.setVerticalGroup(
panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -406,7 +427,8 @@ public class PickChoiceDialog extends MageDialog {
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(panelCommandsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btCancel)
.addComponent(btOK))
.addComponent(btOK)
.addComponent(cbSpecial))
.addContainerGap())
);
@ -460,6 +482,7 @@ public class PickChoiceDialog extends MageDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btCancel;
private javax.swing.JButton btOK;
private javax.swing.JCheckBox cbSpecial;
private javax.swing.JTextField editSearch;
private javax.swing.JLabel labelMessage;
private javax.swing.JLabel labelSearch;

View file

@ -4082,8 +4082,8 @@
<Component id="checkBoxEndTurnOthers" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="phases_stopSettings" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="phases_stopSettings" pref="291" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -4182,7 +4182,7 @@
<Layout class="org.netbeans.modules.form.compat2.layouts.DesignGridLayout">
<Property name="columns" type="int" value="1"/>
<Property name="rows" type="int" value="9"/>
<Property name="rows" type="int" value="10"/>
</Layout>
<SubComponents>
<Component class="javax.swing.JCheckBox" name="cbStopAttack">
@ -4281,8 +4281,8 @@
</Component>
<Component class="javax.swing.JCheckBox" name="cbAutoOrderTrigger">
<Properties>
<Property name="text" type="java.lang.String" value="Set order for your triggers automatically if all have the same text"/>
<Property name="toolTipText" type="java.lang.String" value="&lt;HTML&gt;If activated the order to put on the stack your triggers that trigger at the same time&lt;br/&gt;&#xa;is set automatically if all have the same text."/>
<Property name="text" type="java.lang.String" value="TRIGGERS: auto-choose triggers order for same rule texts (put same triggers to the stack at default order)"/>
<Property name="toolTipText" type="java.lang.String" value="&lt;HTML&gt;If you put same triggers with same texts on the stack then auto-choose their order.&lt;br/&gt;&#xa;You can change that settings anytime at the game."/>
<Property name="actionCommand" type="java.lang.String" value=""/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 25]"/>
@ -4292,6 +4292,19 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbAutoOrderTriggerActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="cbUseSameSettingsForReplacementEffect">
<Properties>
<Property name="text" type="java.lang.String" value="REPLACEMENT EFFECTS: use same auto-choose settings for same cards (choose replacement effects order dialog)"/>
<Property name="toolTipText" type="java.lang.String" value="&lt;HTML&gt;If you setup auto-choose for one object/card then it will be applied for all other objects with same name.&lt;br/&gt;&#xa;You can change that settings anytime at the game."/>
<Property name="actionCommand" type="java.lang.String" value=""/>
<Property name="preferredSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
<Dimension value="[300, 25]"/>
</Property>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="cbUseSameSettingsForReplacementEffectActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>

View file

@ -134,6 +134,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_PASS_PRIORITY_CAST = "passPriorityCast";
public static final String KEY_PASS_PRIORITY_ACTIVATION = "passPriorityActivation";
public static final String KEY_AUTO_ORDER_TRIGGER = "autoOrderTrigger";
public static final String KEY_USE_SAME_SETTINGS_FOR_SAME_REPLACEMENT_EFFECTS = "useSameSettingsForSameReplacementEffects";
public static final String KEY_USE_FIRST_MANA_ABILITY = "useFirstManaAbility";
// mana auto payment
@ -501,6 +502,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
cbPassPriorityCast = new javax.swing.JCheckBox();
cbPassPriorityActivation = new javax.swing.JCheckBox();
cbAutoOrderTrigger = new javax.swing.JCheckBox();
cbUseSameSettingsForReplacementEffect = new javax.swing.JCheckBox();
tabImages = new javax.swing.JPanel();
panelCardImages = new javax.swing.JPanel();
cbUseDefaultImageFolder = new javax.swing.JCheckBox();
@ -1405,7 +1407,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
jLabelEndOfTurn.setText("End of turn:");
phases_stopSettings.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "SKIP settings"));
phases_stopSettings.setLayout(new java.awt.GridLayout(9, 1));
phases_stopSettings.setLayout(new java.awt.GridLayout(10, 1));
cbStopAttack.setSelected(true);
cbStopAttack.setText("STOP skips on declare attackers if attackers are available");
@ -1493,8 +1495,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
});
phases_stopSettings.add(cbPassPriorityActivation);
cbAutoOrderTrigger.setText("Set order for your triggers automatically if all have the same text");
cbAutoOrderTrigger.setToolTipText("<HTML>If activated the order to put on the stack your triggers that trigger at the same time<br/>\nis set automatically if all have the same text.");
cbAutoOrderTrigger.setText("TRIGGERS: auto-choose triggers order for same rule texts (put same triggers to the stack at default order)");
cbAutoOrderTrigger.setToolTipText("<HTML>If you put same triggers with same texts on the stack then auto-choose their order.<br/>\nYou can change that settings anytime at the game.");
cbAutoOrderTrigger.setActionCommand("");
cbAutoOrderTrigger.setPreferredSize(new java.awt.Dimension(300, 25));
cbAutoOrderTrigger.addActionListener(new java.awt.event.ActionListener() {
@ -1504,6 +1506,17 @@ public class PreferencesDialog extends javax.swing.JDialog {
});
phases_stopSettings.add(cbAutoOrderTrigger);
cbUseSameSettingsForReplacementEffect.setText("REPLACEMENT EFFECTS: use same auto-choose settings for same cards (choose replacement effects order dialog)");
cbUseSameSettingsForReplacementEffect.setToolTipText("<HTML>If you setup auto-choose for one object/card then it will be applied for all other objects with same name.<br/>\nYou can change that settings anytime at the game.");
cbUseSameSettingsForReplacementEffect.setActionCommand("");
cbUseSameSettingsForReplacementEffect.setPreferredSize(new java.awt.Dimension(300, 25));
cbUseSameSettingsForReplacementEffect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cbUseSameSettingsForReplacementEffectActionPerformed(evt);
}
});
phases_stopSettings.add(cbUseSameSettingsForReplacementEffect);
org.jdesktop.layout.GroupLayout tabPhasesLayout = new org.jdesktop.layout.GroupLayout(tabPhases);
tabPhases.setLayout(tabPhasesLayout);
tabPhasesLayout.setHorizontalGroup(
@ -1614,8 +1627,8 @@ public class PreferencesDialog extends javax.swing.JDialog {
.add(jLabelEndOfTurn)
.add(checkBoxEndTurnOthers))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(phases_stopSettings, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.add(phases_stopSettings, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE)
.addContainerGap())
);
tabsPanel.addTab("Phases & Priority", tabPhases);
@ -2925,6 +2938,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, dialog.cbPassPriorityCast, KEY_PASS_PRIORITY_CAST, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbPassPriorityActivation, KEY_PASS_PRIORITY_ACTIVATION, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbAutoOrderTrigger, KEY_AUTO_ORDER_TRIGGER, "true", "false", UPDATE_CACHE_POLICY);
save(prefs, dialog.cbUseSameSettingsForReplacementEffect, KEY_USE_SAME_SETTINGS_FOR_SAME_REPLACEMENT_EFFECTS, "true", "false", UPDATE_CACHE_POLICY);
// images
save(prefs, dialog.cbUseDefaultImageFolder, KEY_CARD_IMAGES_USE_DEFAULT, "true", "false", UPDATE_CACHE_POLICY);
@ -3309,6 +3323,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
}//GEN-LAST:event_sliderGUISizeStateChanged
private void cbUseSameSettingsForReplacementEffectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbUseSameSettingsForReplacementEffectActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_cbUseSameSettingsForReplacementEffectActionPerformed
private void showProxySettings() {
Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem();
switch (proxyType) {
@ -3465,7 +3483,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
load(prefs, dialog.cbPassPriorityCast, KEY_PASS_PRIORITY_CAST, "true", "false");
load(prefs, dialog.cbPassPriorityActivation, KEY_PASS_PRIORITY_ACTIVATION, "true", "false");
load(prefs, dialog.cbAutoOrderTrigger, KEY_AUTO_ORDER_TRIGGER, "true", "true");
load(prefs, dialog.cbUseSameSettingsForReplacementEffect, KEY_USE_SAME_SETTINGS_FOR_SAME_REPLACEMENT_EFFECTS, "true", "true");
}
private static void loadGuiSize(Preferences prefs) {
@ -3996,6 +4014,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_CAST, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_ACTIVATION, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_AUTO_ORDER_TRIGGER, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_USE_SAME_SETTINGS_FOR_SAME_REPLACEMENT_EFFECTS, "true").equals("true"),
PreferencesDialog.getCachedValue(PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"),
userStrId
);
@ -4069,6 +4088,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
private javax.swing.JCheckBox cbUseDefaultBattleImage;
private javax.swing.JCheckBox cbUseDefaultImageFolder;
private javax.swing.JCheckBox cbUseRandomBattleImage;
private javax.swing.JCheckBox cbUseSameSettingsForReplacementEffect;
private javax.swing.JLabel chatFontSizeLabel;
private javax.swing.JCheckBox checkBoxBeforeCOthers;
private javax.swing.JCheckBox checkBoxBeforeCYou;

View file

@ -108,7 +108,7 @@ public final class GamePanel extends javax.swing.JPanel {
private boolean initComponents;
private Timer resizeTimer; // can't be final
private final Timer resizeTimer; // can't be final
private enum PopUpMenuType {
TRIGGER_ORDER
@ -128,6 +128,7 @@ public final class GamePanel extends javax.swing.JPanel {
Map<String, Serializable> options;
Set<UUID> targets;
}
private final LastGameData lastGameData = new LastGameData();
@ -1746,18 +1747,22 @@ public final class GamePanel extends javax.swing.JPanel {
// TODO: remember last choices and search incremental for same events?
PickChoiceDialog pickChoice = new PickChoiceDialog();
pickChoice.showDialog(choice, objectId, choiceWindowState);
// special mode adds # to the answer (server side code must process that prefix, see replacementEffectChoice)
String specialPrefix = choice.isChosenSpecial() ? "#" : "";
String valueToSend;
if (choice.isKeyChoice()) {
SessionHandler.sendPlayerString(gameId, choice.getChoiceKey());
/* // old code, auto complete was for auto scripting?
if (pickChoice.isAutoSelect()) {
SessionHandler.sendPlayerString(gameId, '#' + choice.getChoiceKey());
} else {
SessionHandler.sendPlayerString(gameId, choice.getChoiceKey());
}*/
valueToSend = choice.getChoiceKey();
} else {
valueToSend = choice.getChoice();
SessionHandler.sendPlayerString(gameId, choice.getChoice());
}
SessionHandler.sendPlayerString(gameId, valueToSend == null ? null : specialPrefix + valueToSend);
// keep dialog position
choiceWindowState = new MageDialogState(pickChoice);
pickChoice.removeDialog();
}