* UI: added CTRL/SHIFT/ALT supports for hotkeys (#2042);

This commit is contained in:
Oleg Agafonov 2019-04-06 07:32:44 +04:00
parent b18428f68f
commit 10234d508f
4 changed files with 302 additions and 221 deletions

View file

@ -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 <znix@znix.xyz>
* @author Campbell Suter <znix@znix.xyz>, 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 = "<None>";
} else {
text = KeyEvent.getKeyText(keyCode);
}
repaint();
}
private void fixText() {
if (keyCode == 0) {
text = "<none>";
} 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) {
}
}
}

View file

@ -4375,7 +4375,7 @@
</Group>
<Component id="cbUseDefaultImageFolder" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="308" max="32767" attributes="0"/>
<EmptySpace min="0" pref="391" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
@ -5802,7 +5802,7 @@
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace pref="201" max="32767" attributes="0"/>
<EmptySpace pref="251" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -6033,45 +6033,42 @@
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="labelCancel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelNextTurn" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelEndStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelMainStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelYourTurn" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lebelSkip" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelPriorEnd" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelSkipStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelConfirm" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelToggleRecordMacro" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="bttnResetControls" min="-2" max="-2" attributes="0"/>
<Component id="labelSwitchChat" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Component id="bttnResetControls" max="32767" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="keyConfirm" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keyCancelSkip" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keyNextTurn" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keySkipStack" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keyYourTurn" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keyMainStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keyPriorEnd" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keySkipStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keyEndStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="keyToggleRecordMacro" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelCancel" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelNextTurn" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelEndStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelMainStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelYourTurn" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="lebelSkip" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelPriorEnd" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelSkipStep" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelConfirm" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelToggleRecordMacro" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelSwitchChat" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="keyConfirm" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keyCancelSkip" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keyNextTurn" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keySkipStack" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keyYourTurn" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keyMainStep" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keyPriorEnd" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keySkipStep" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keyEndStep" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keyToggleRecordMacro" alignment="0" min="-2" pref="100" max="-2" attributes="0"/>
<Component id="keySwitchChat" min="-2" pref="100" max="-2" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="321" max="-2" attributes="0"/>
<Component id="controlsDescriptionLabel" pref="151" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Component id="keySwitchChat" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="controlsDescriptionLabel" pref="481" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -6080,9 +6077,8 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Component id="controlsDescriptionLabel" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" attributes="0">
<Group type="103" groupAlignment="3" attributes="0">
<Component id="labelConfirm" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="keyConfirm" alignment="3" min="-2" max="-2" attributes="0"/>
@ -6132,16 +6128,17 @@
<Component id="labelToggleRecordMacro" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="keyToggleRecordMacro" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="labelSwitchChat" alignment="3" min="-2" max="-2" attributes="0"/>
<Component id="keySwitchChat" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
<Component id="bttnResetControls" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="controlsDescriptionLabel" max="32767" attributes="0"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="keySwitchChat" alignment="0" min="-2" max="-2" attributes="0"/>
<Component id="labelSwitchChat" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="bttnResetControls" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -6149,37 +6146,37 @@
<SubComponents>
<Component class="javax.swing.JLabel" name="labelNextTurn">
<Properties>
<Property name="text" type="java.lang.String" value="Next Turn"/>
<Property name="text" type="java.lang.String" value="Next Turn:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelEndStep">
<Properties>
<Property name="text" type="java.lang.String" value="End Step"/>
<Property name="text" type="java.lang.String" value="End Step:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelMainStep">
<Properties>
<Property name="text" type="java.lang.String" value="Main Step"/>
<Property name="text" type="java.lang.String" value="Main Step:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelYourTurn">
<Properties>
<Property name="text" type="java.lang.String" value="Your Turn"/>
<Property name="text" type="java.lang.String" value="Your Turn:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="lebelSkip">
<Properties>
<Property name="text" type="java.lang.String" value="Skip Stack"/>
<Property name="text" type="java.lang.String" value="Skip Stack:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelPriorEnd">
<Properties>
<Property name="text" type="java.lang.String" value="Prior End"/>
<Property name="text" type="java.lang.String" value="Prior End:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="labelCancel">
<Properties>
<Property name="text" type="java.lang.String" value="Cancel Skip"/>
<Property name="text" type="java.lang.String" value="Cancel Skip:"/>
</Properties>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyCancelSkip">
@ -6248,7 +6245,7 @@
</Component>
<Component class="javax.swing.JLabel" name="labelSkipStep">
<Properties>
<Property name="text" type="java.lang.String" value="Skip Step"/>
<Property name="text" type="java.lang.String" value="Skip Step:"/>
</Properties>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyConfirm">
@ -6261,12 +6258,12 @@
</Component>
<Component class="javax.swing.JLabel" name="labelConfirm">
<Properties>
<Property name="text" type="java.lang.String" value="Confirm"/>
<Property name="text" type="java.lang.String" value="Confirm:"/>
</Properties>
</Component>
<Component class="javax.swing.JLabel" name="controlsDescriptionLabel">
<Properties>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Click on a button and press a key to change a keybind.&lt;br&gt;Space and ESC are not available, and will set the keybind to nothing.&lt;br&gt;If you are currently playing a game, the changes will not take effect until you start a new game."/>
<Property name="text" type="java.lang.String" value="&lt;html&gt;Click on a button and press a KEY or a combination of CTRL/ALT/SHIF + KEY to change a keybind.&#xa;&lt;br&gt;&#xa;Press SPACE to clear binging.&#xa;&lt;br&gt;&#xa;Press ESC to cancel binding.&#xa;&lt;br&gt;&#xa;New changes will be applied after new game start."/>
<Property name="verticalAlignment" type="int" value="1"/>
</Properties>
</Component>
@ -6280,7 +6277,7 @@
</Component>
<Component class="javax.swing.JLabel" name="labelToggleRecordMacro">
<Properties>
<Property name="text" type="java.lang.String" value="Record Macro (unsupported)"/>
<Property name="text" type="java.lang.String" value="Record Macro (unsupported):"/>
</Properties>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyToggleRecordMacro">
@ -6293,7 +6290,7 @@
</Component>
<Component class="javax.swing.JLabel" name="labelSwitchChat">
<Properties>
<Property name="text" type="java.lang.String" value="Go in/out to chat"/>
<Property name="text" type="java.lang.String" value="Go in/out to chat:"/>
</Properties>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keySwitchChat">

View file

@ -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("<html>Click on a button and press a key to change a keybind.<br>Space and ESC are not available, and will set the keybind to nothing.<br>If you are currently playing a game, the changes will not take effect until you start a new game.");
controlsDescriptionLabel.setText("<html>Click on a button and press a KEY or a combination of CTRL/ALT/SHIF + KEY to change a keybind.\n<br>\nPress SPACE to clear binging.\n<br>\nPress ESC to cancel binding.\n<br>\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) {

View file

@ -404,34 +404,34 @@ public class CallbackClientImpl implements CallbackClient {
.append("<br/>Turn mousewheel up (ALT-e) - enlarge image of card the mousepointer hovers over")
.append("<br/>Turn mousewheel down (ALT-s) - enlarge original/alternate image of card the mousepointer hovers over")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_CONFIRM)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CONFIRM)))
.append("</b> - Confirm \"Ok\", \"Yes\" or \"Done\" button")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_NEXT_TURN)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_NEXT_TURN)))
.append("</b> - Skip current turn but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_END_STEP)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_END_STEP)))
.append("</b> - Skip to next end step but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_SKIP_STEP)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SKIP_STEP)))
.append("</b> - Skip current turn but stop on declare attackers/blockers")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_MAIN_STEP)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_MAIN_STEP)))
.append("</b> - Skip to next main phase but stop on declare attackers/blockers and something on the stack")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_YOUR_TURN)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_YOUR_TURN)))
.append("</b> - Skip everything until your next turn")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_PRIOR_END)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_PRIOR_END)))
.append("</b> - Skip everything until the end step just prior to your turn")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_CANCEL_SKIP)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_CANCEL_SKIP)))
.append("</b> - Undo F4/F5/F7/F9/F11")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_SWITCH_CHAT)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_SWITCH_CHAT)))
.append("</b> - Switth in/out to chat text field")
.append("<br/><b>")
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentKeyControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO)))
.append(KeyEvent.getKeyText(PreferencesDialog.getCurrentControlKey(PreferencesDialog.KEY_CONTROL_TOGGLE_MACRO)))
.append("</b> - 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("<br/><b>").append(System.getProperty("os.name").contains("Mac OS X") ? "Cmd" : "Ctrl").append(" + click</b> - Hold priority while casting a spell or activating an ability")
.append("<br/>").append("Type <b>/FIX</b> message in chat to fix freezed game")