From 10234d508f2ad888cda19fa9f0b13856563d2fd4 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 6 Apr 2019 07:32:44 +0400 Subject: [PATCH] * UI: added CTRL/SHIFT/ALT supports for hotkeys (#2042); --- .../mage/client/components/KeyBindButton.java | 240 +++++++++++------- .../mage/client/dialog/PreferencesDialog.form | 111 ++++---- .../mage/client/dialog/PreferencesDialog.java | 152 ++++++----- .../client/remote/CallbackClientImpl.java | 20 +- 4 files changed, 302 insertions(+), 221 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/components/KeyBindButton.java b/Mage.Client/src/main/java/mage/client/components/KeyBindButton.java index be63bbacbe0..1849b44d155 100644 --- a/Mage.Client/src/main/java/mage/client/components/KeyBindButton.java +++ b/Mage.Client/src/main/java/mage/client/components/KeyBindButton.java @@ -1,118 +1,176 @@ package mage.client.components; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; -import java.awt.event.KeyListener; -import javax.swing.JButton; -import javax.swing.JLabel; -import javax.swing.JPopupMenu; import mage.client.dialog.PreferencesDialog; +import javax.swing.*; +import java.awt.event.*; + /** - * - * @author Campbell Suter + * @author Campbell Suter , JayDi85 */ public class KeyBindButton extends JButton implements ActionListener { - private final PreferencesDialog preferences; - private final String key; - private PopupItem item; - private JPopupMenu menu; - private int keyCode; - private String text; + private final PreferencesDialog preferences; + private final String key; + private PopupItem item; + private JPopupMenu menu; + private int keyCode; + private int modifierCode; + private String text; - /** - * For the IDE only, do not use! - */ - public KeyBindButton() { - this(null, null); - } + /** + * For the IDE only, do not use! + */ + public KeyBindButton() { + this(null, null); + } - public KeyBindButton(PreferencesDialog preferences, String key) { - this.preferences = preferences; - this.key = key; - addActionListener(this); - fixText(); - } + public KeyBindButton(PreferencesDialog preferences, String key) { + this.preferences = preferences; + this.key = key; + addActionListener(this); + fixText(); + } - private JPopupMenu getMenu() { - menu = new JPopupMenu(); - menu.add(item = new PopupItem()); - return menu; - } + private JPopupMenu createPopupMenu() { + menu = new JPopupMenu(); + menu.add(item = new PopupItem()); + return menu; + } - private void applyNewKeycode(int code) { - preferences.getKeybindButtons().stream() - .filter(b -> b != KeyBindButton.this) - .filter(b -> { - return b.keyCode == code; + private void applyNewKeycode(int code, int modifier) { + // clear used keys + preferences.getKeybindButtons().stream() + .filter(b -> b != KeyBindButton.this) + .filter(b -> { + return b.keyCode == code && b.modifierCode == modifier; }) - .forEach(b -> b.setKeyCode(0)); + .forEach(b -> { + b.setKeyCode(0); + b.setModifierCode(0); + }); - setKeyCode(code); - menu.setVisible(false); - } + // set new + setKeyCode(code); + setModifierCode(modifier); + menu.setVisible(false); + } - private void fixText() { - if (keyCode == 0) { - text = ""; - } else { - text = KeyEvent.getKeyText(keyCode); - } - repaint(); - } + private void fixText() { + if (keyCode == 0) { + text = ""; + } else { + String codeStr = KeyEvent.getKeyText(keyCode); + String modStr = KeyEvent.getKeyModifiersText(modifierCode); + text = (modStr.isEmpty() ? "" : modStr + " + ") + codeStr; + } + repaint(); + } - public void setKeyCode(int keyCode) { - this.keyCode = keyCode; - switch (keyCode) { - case KeyEvent.VK_ESCAPE: - case KeyEvent.VK_SPACE: - keyCode = 0; - } - fixText(); - setSize(getPreferredSize()); - } + public void setKeyCode(int keyCode) { + this.keyCode = keyCode; + switch (keyCode) { + case KeyEvent.VK_ESCAPE: + case KeyEvent.VK_SPACE: + this.keyCode = 0; + } + fixText(); + //setSize(getPreferredSize()); + } - public int getKeyCode() { - return keyCode; - } + public int getKeyCode() { + return keyCode; + } - @Override - public String getText() { - return text; - } + public void setModifierCode(int modifierCode) { + this.modifierCode = modifierCode; - public String getKey() { - return key; - } + // only single modifier allowed + if (!(modifierCode == InputEvent.ALT_MASK + || modifierCode == InputEvent.CTRL_MASK + || modifierCode == InputEvent.SHIFT_MASK)) { + this.modifierCode = 0; + } + fixText(); + //setSize(getPreferredSize()); + } - @Override - public void actionPerformed(ActionEvent e) { - getMenu().show(this, 0, 0); - item.requestFocusInWindow(); - } + public int getModifierCode() { + return modifierCode; + } - private class PopupItem extends JLabel implements KeyListener { + @Override + public String getText() { + return text; + } - public PopupItem() { - super("Press a key"); - addKeyListener(this); - setFocusable(true); - } + public String getKey() { + return key; + } - @Override - public void keyTyped(KeyEvent e) { - } + @Override + public void actionPerformed(ActionEvent e) { + JPopupMenu m = createPopupMenu(); + m.setPopupSize(this.getWidth(), this.getHeight()); + m.show(this, 0, 0); + item.requestFocusInWindow(); + } - @Override - public void keyPressed(KeyEvent e) { - applyNewKeycode(e.getKeyCode()); - } + private class PopupItem extends JLabel implements KeyListener { - @Override - public void keyReleased(KeyEvent e) { - } + public PopupItem() { + super("Press a key"); + addKeyListener(this); + setFocusable(true); + } - } + @Override + public void keyTyped(KeyEvent e) { + } + + @Override + public void keyPressed(KeyEvent e) { + + // cancel on ESC + if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { + menu.setVisible(false); + return; + } + + // clear on SPACE + if (e.getKeyCode() == KeyEvent.VK_SPACE) { + setKeyCode(0); + setModifierCode(0); + menu.setVisible(false); + return; + } + + // ignore multiple mod keys + switch (e.getModifiers()) { + case KeyEvent.CTRL_MASK: + case KeyEvent.SHIFT_MASK: + case KeyEvent.ALT_MASK: + case 0: + break; + default: + return; + } + + // skip single mod keys without chars + switch (e.getKeyCode()) { + case KeyEvent.VK_CONTROL: + case KeyEvent.VK_SHIFT: + case KeyEvent.VK_ALT: + return; + } + + // all done, can save + applyNewKeycode(e.getKeyCode(), e.getModifiers()); + } + + @Override + public void keyReleased(KeyEvent e) { + } + + } } diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form index 89c02ef8247..f51d3fb355d 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.form @@ -4375,7 +4375,7 @@ - + @@ -5802,7 +5802,7 @@ - + @@ -6033,45 +6033,42 @@ - + - - - - - - - - - - - - - - - - + + - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + @@ -6080,9 +6077,8 @@ - - - + + @@ -6132,16 +6128,17 @@ + + + + + + + + - - - - - - - @@ -6149,37 +6146,37 @@ - + - + - + - + - + - + - + @@ -6248,7 +6245,7 @@ - + @@ -6261,12 +6258,12 @@ - + - + @@ -6280,7 +6277,7 @@ - + @@ -6293,7 +6290,7 @@ - + diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index a3cbdf87105..c869f6e8276 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -35,9 +35,7 @@ import static mage.client.constants.Constants.BATTLEFIELD_FEEDBACK_COLORIZING_MO import static mage.constants.Constants.*; /** - * Preferences dialog. - * - * @author nantuko + * @author nantuko, JayDi85 */ public class PreferencesDialog extends javax.swing.JDialog { @@ -278,6 +276,7 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final String KEY_NEWS_PAGE_COOKIES = "newsPageCookies"; // controls + public static final String KEY_CONTROL_MODIFIER_POSTFIX = "_modifier"; public static final String KEY_CONTROL_TOGGLE_MACRO = "controlToggleMacro"; public static final String KEY_CONTROL_SWITCH_CHAT = "controlSwitchChat"; public static final String KEY_CONTROL_CONFIRM = "controlConfirm"; @@ -1616,7 +1615,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(cbNumberOfDownloadThreads, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 153, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) .add(cbUseDefaultImageFolder)) - .add(0, 308, Short.MAX_VALUE))) + .add(0, 391, Short.MAX_VALUE))) .addContainerGap()) ); panelCardImagesLayout.setVerticalGroup( @@ -2421,7 +2420,7 @@ public class PreferencesDialog extends javax.swing.JDialog { .add(connection_serversLayout.createSequentialGroup() .add(141, 141, 141) .add(jLabel17))) - .addContainerGap(201, Short.MAX_VALUE)) + .addContainerGap(251, Short.MAX_VALUE)) ); connection_serversLayout.setVerticalGroup( connection_serversLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) @@ -2575,19 +2574,19 @@ public class PreferencesDialog extends javax.swing.JDialog { tabsPanel.addTab("Connection", tabConnection); - labelNextTurn.setText("Next Turn"); + labelNextTurn.setText("Next Turn:"); - labelEndStep.setText("End Step"); + labelEndStep.setText("End Step:"); - labelMainStep.setText("Main Step"); + labelMainStep.setText("Main Step:"); - labelYourTurn.setText("Your Turn"); + labelYourTurn.setText("Your Turn:"); - lebelSkip.setText("Skip Stack"); + lebelSkip.setText("Skip Stack:"); - labelPriorEnd.setText("Prior End"); + labelPriorEnd.setText("Prior End:"); - labelCancel.setText("Cancel Skip"); + labelCancel.setText("Cancel Skip:"); keyCancelSkip.setText("keyBindButton1"); @@ -2605,13 +2604,13 @@ public class PreferencesDialog extends javax.swing.JDialog { keySkipStep.setText("keyBindButton1"); - labelSkipStep.setText("Skip Step"); + labelSkipStep.setText("Skip Step:"); keyConfirm.setText("keyBindButton1"); - labelConfirm.setText("Confirm"); + labelConfirm.setText("Confirm:"); - controlsDescriptionLabel.setText("Click on a button and press a key to change a keybind.
Space and ESC are not available, and will set the keybind to nothing.
If you are currently playing a game, the changes will not take effect until you start a new game."); + controlsDescriptionLabel.setText("Click on a button and press a KEY or a combination of CTRL/ALT/SHIF + KEY to change a keybind.\n
\nPress SPACE to clear binging.\n
\nPress ESC to cancel binding.\n
\nNew changes will be applied after new game start."); controlsDescriptionLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP); bttnResetControls.setText("Reset to default"); @@ -2621,11 +2620,11 @@ public class PreferencesDialog extends javax.swing.JDialog { } }); - labelToggleRecordMacro.setText("Record Macro (unsupported)"); + labelToggleRecordMacro.setText("Record Macro (unsupported):"); keyToggleRecordMacro.setText("keyBindButton1"); - labelSwitchChat.setText("Go in/out to chat"); + labelSwitchChat.setText("Go in/out to chat:"); keySwitchChat.setText("keyBindButton1"); @@ -2635,47 +2634,44 @@ public class PreferencesDialog extends javax.swing.JDialog { tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(tabControlsLayout.createSequentialGroup() .addContainerGap() - .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(labelCancel) - .add(labelNextTurn) - .add(labelEndStep) - .add(labelMainStep) - .add(labelYourTurn) - .add(lebelSkip) - .add(labelPriorEnd) - .add(labelSkipStep) - .add(labelConfirm) - .add(labelToggleRecordMacro) - .add(bttnResetControls) - .add(labelSwitchChat)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) + .add(bttnResetControls, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .add(tabControlsLayout.createSequentialGroup() .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(keyConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keyCancelSkip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keyNextTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keySkipStack, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keyYourTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keyMainStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keyPriorEnd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keySkipStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keyEndStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(keyToggleRecordMacro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) - .add(321, 321, 321) - .add(controlsDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 151, Short.MAX_VALUE)) - .add(tabControlsLayout.createSequentialGroup() - .add(keySwitchChat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(0, 0, Short.MAX_VALUE))) + .add(labelCancel) + .add(labelNextTurn) + .add(labelEndStep) + .add(labelMainStep) + .add(labelYourTurn) + .add(lebelSkip) + .add(labelPriorEnd) + .add(labelSkipStep) + .add(labelConfirm) + .add(labelToggleRecordMacro) + .add(labelSwitchChat)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) + .add(keyConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyCancelSkip, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyNextTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keySkipStack, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyYourTurn, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyMainStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyPriorEnd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keySkipStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyEndStep, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keyToggleRecordMacro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) + .add(keySwitchChat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(controlsDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 481, Short.MAX_VALUE) .addContainerGap()) ); tabControlsLayout.setVerticalGroup( tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(tabControlsLayout.createSequentialGroup() .addContainerGap() - .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false) - .add(org.jdesktop.layout.GroupLayout.LEADING, controlsDescriptionLabel) - .add(org.jdesktop.layout.GroupLayout.LEADING, tabControlsLayout.createSequentialGroup() + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false) + .add(tabControlsLayout.createSequentialGroup() .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(labelConfirm) .add(keyConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) @@ -2714,13 +2710,14 @@ public class PreferencesDialog extends javax.swing.JDialog { .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(labelToggleRecordMacro) - .add(keyToggleRecordMacro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(keySwitchChat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .add(labelSwitchChat)) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) - .add(bttnResetControls) + .add(keyToggleRecordMacro, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) + .add(labelSwitchChat) + .add(keySwitchChat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(bttnResetControls)) + .add(controlsDescriptionLabel)) .addContainerGap()) ); @@ -3234,7 +3231,9 @@ public class PreferencesDialog extends javax.swing.JDialog { getKeybindButtons().forEach((bttn) -> { String id = bttn.getKey(); int keyCode = getDefaultControlKey(id); + int modCode = getDefaultControlMofier(id); bttn.setKeyCode(keyCode); + bttn.setModifierCode(modCode); }); }//GEN-LAST:event_bttnResetControlsActionPerformed @@ -3665,8 +3664,11 @@ public class PreferencesDialog extends javax.swing.JDialog { private static void load(Preferences prefs, KeyBindButton button) { String key = button.getKey(); - int prop = prefs.getInt(key, getDefaultControlKey(key)); - button.setKeyCode(prop); + + int code = prefs.getInt(key, getDefaultControlKey(key)); + int mod = prefs.getInt(key + KEY_CONTROL_MODIFIER_POSTFIX, getDefaultControlMofier(key)); + button.setKeyCode(code); + button.setModifierCode(mod); } private static void save(Preferences prefs, JCheckBox checkBox, String propName) { @@ -3708,9 +3710,15 @@ public class PreferencesDialog extends javax.swing.JDialog { private static void save(Preferences prefs, KeyBindButton button) { int code = button.getKeyCode(); + int mod = button.getModifierCode(); + String key = button.getKey(); + prefs.putInt(key, code); updateCache(key, Integer.toString(code)); + + prefs.putInt(key + KEY_CONTROL_MODIFIER_POSTFIX, mod); + updateCache(key + KEY_CONTROL_MODIFIER_POSTFIX, Integer.toString(mod)); } public void reset() { @@ -3743,8 +3751,11 @@ public class PreferencesDialog extends javax.swing.JDialog { } } - public static int getCurrentKeyControlKey(String key) { - return getCachedValue(key, getDefaultControlKey(key)); + private static int getDefaultControlMofier(String key) { + switch (key) { + default: + return 0; + } } private static int getDefaultControlKey(String key) { @@ -3776,14 +3787,29 @@ public class PreferencesDialog extends javax.swing.JDialog { } } + public static int getCurrentControlKey(String key) { + return getCachedValue(key, getDefaultControlKey(key)); + } + + public static int getCurrentControlModifier(String key) { + return getCachedValue(key + KEY_CONTROL_MODIFIER_POSTFIX, getDefaultControlMofier(key)); + } + public static KeyStroke getCachedKeystroke(String key) { int code = getCachedValue(key, getDefaultControlKey(key)); - return KeyStroke.getKeyStroke(code, 0); + int mod = getCachedValue(key + KEY_CONTROL_MODIFIER_POSTFIX, getDefaultControlMofier(key)); + + return KeyStroke.getKeyStroke(code, mod); } public static String getCachedKeyText(String key) { int code = getCachedValue(key, getDefaultControlKey(key)); - return KeyEvent.getKeyText(code); + String codeStr = KeyEvent.getKeyText(code); + + int mod = getCachedValue(key + KEY_CONTROL_MODIFIER_POSTFIX, getDefaultControlMofier(key)); + String modStr = KeyEvent.getKeyModifiersText(mod); + + return (modStr.isEmpty() ? "" : modStr + " + ") + codeStr; } private static void updateCache(String key, String value) { diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index d65825a5606..3f7501c1840 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -404,34 +404,34 @@ public class CallbackClientImpl implements CallbackClient { .append("
Turn mousewheel up (ALT-e) - enlarge image of card the mousepointer hovers over") .append("
Turn mousewheel down (ALT-s) - enlarge original/alternate image of card the mousepointer hovers over") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_CONFIRM))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CONFIRM))) .append(" - Confirm \"Ok\", \"Yes\" or \"Done\" button") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_NEXT_TURN))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_NEXT_TURN))) .append(" - Skip current turn but stop on declare attackers/blockers and something on the stack") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_END_STEP))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_END_STEP))) .append(" - Skip to next end step but stop on declare attackers/blockers and something on the stack") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_SKIP_STEP))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SKIP_STEP))) .append(" - Skip current turn but stop on declare attackers/blockers") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_MAIN_STEP))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_MAIN_STEP))) .append(" - Skip to next main phase but stop on declare attackers/blockers and something on the stack") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_YOUR_TURN))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_YOUR_TURN))) .append(" - Skip everything until your next turn") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_PRIOR_END))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_PRIOR_END))) .append(" - Skip everything until the end step just prior to your turn") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_CANCEL_SKIP))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CANCEL_SKIP))) .append(" - Undo F4/F5/F7/F9/F11") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_SWITCH_CHAT))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SWITCH_CHAT))) .append(" - Switth in/out to chat text field") .append("
") - .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO))) + .append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO))) .append(" - Toggle recording a sequence of actions to repeat. Will not pause if interrupted and can fail if a selected card changes such as when scrying top card to bottom.") .append("
").append(System.getProperty("os.name").contains("Mac OS X") ? "Cmd" : "Ctrl").append(" + click - Hold priority while casting a spell or activating an ability") .append("
").append("Type /FIX message in chat to fix freezed game")