Merge pull request #2489 from ZNixian/master

Improve keybinds
This commit is contained in:
LevelX2 2016-10-21 12:57:56 +02:00 committed by GitHub
commit 34b8f7add9
3 changed files with 259 additions and 149 deletions

View file

@ -7,6 +7,7 @@ import java.awt.event.KeyListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPopupMenu;
import mage.client.dialog.PreferencesDialog;
/**
*
@ -14,80 +15,102 @@ import javax.swing.JPopupMenu;
*/
public class KeyBindButton extends JButton implements ActionListener {
private final JPopupMenu menu;
private final PopupItem item;
private int keyCode;
private String text;
private final PreferencesDialog preferences;
private final String key;
private PopupItem item;
private JPopupMenu menu;
private int keyCode;
private String text;
public KeyBindButton() {
menu = new JPopupMenu();
menu.add(item = new PopupItem());
addActionListener(this);
/**
* For the IDE only, do not use!
*/
public KeyBindButton() {
this(null, null);
}
fixText();
}
public KeyBindButton(PreferencesDialog preferences, String key) {
this.preferences = preferences;
this.key = key;
addActionListener(this);
fixText();
}
private void applyNewKeycode(int code) {
keyCode = code;
switch (keyCode) {
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_SPACE:
keyCode = 0;
}
fixText();
menu.setVisible(false);
setSize(getPreferredSize());
}
private JPopupMenu getMenu() {
menu = new JPopupMenu();
menu.add(item = new PopupItem());
return menu;
}
private void fixText() {
if (keyCode == 0) {
text = "<None>";
} else {
text = KeyEvent.getKeyText(keyCode);
}
repaint();
}
private void applyNewKeycode(int code) {
preferences.getKeybindButtons().stream()
.filter(b -> b != KeyBindButton.this)
.filter(b -> b.getKeyCode() == code)
.forEach(b -> b.setKeyCode(0));
public void setKeyCode(int keyCode) {
this.keyCode = keyCode;
fixText();
}
setKeyCode(code);
menu.setVisible(false);
}
public int getKeyCode() {
return keyCode;
}
private void fixText() {
if (keyCode == 0) {
text = "<None>";
} else {
text = KeyEvent.getKeyText(keyCode);
}
repaint();
}
@Override
public String getText() {
return text;
}
public void setKeyCode(int keyCode) {
this.keyCode = keyCode;
switch (keyCode) {
case KeyEvent.VK_ESCAPE:
case KeyEvent.VK_SPACE:
keyCode = 0;
}
fixText();
setSize(getPreferredSize());
}
@Override
public void actionPerformed(ActionEvent e) {
menu.show(this, 0, 0);
item.requestFocusInWindow();
}
public int getKeyCode() {
return keyCode;
}
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) {
getMenu().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) {
applyNewKeycode(e.getKeyCode());
}
@Override
public void keyReleased(KeyEvent e) {
}
}
}

View file

@ -5886,33 +5886,41 @@
<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"/>
<Group type="102" attributes="0">
<Component id="bttnResetControls" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" 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"/>
</Group>
<EmptySpace type="unrelated" max="-2" 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"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="controlsDescriptionLabel" pref="498" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace type="unrelated" max="-2" 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"/>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="controlsDescriptionLabel" pref="498" max="32767" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
@ -5921,8 +5929,9 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" max="-2" attributes="0">
<Group type="102" 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="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"/>
@ -5968,9 +5977,10 @@
<Component id="keyPriorEnd" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="controlsDescriptionLabel" max="32767" attributes="0"/>
</Group>
<EmptySpace min="-2" pref="263" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="bttnResetControls" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -6015,41 +6025,65 @@
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_CANCEL_SKIP)"/>
</AuxValues>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyNextTurn">
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_NEXT_TURN)"/>
</AuxValues>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyMainStep">
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_MAIN_STEP)"/>
</AuxValues>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyEndStep">
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_END_STEP)"/>
</AuxValues>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyYourTurn">
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_YOUR_TURN)"/>
</AuxValues>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keySkipStack">
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_SKIP_STACK)"/>
</AuxValues>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keyPriorEnd">
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_PRIOR_END)"/>
</AuxValues>
</Component>
<Component class="mage.client.components.KeyBindButton" name="keySkipStep">
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_SKIP_STEP)"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="labelSkipStep">
<Properties>
@ -6060,6 +6094,9 @@
<Properties>
<Property name="text" type="java.lang.String" value="keyBindButton1"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_CreateCodeCustom" type="java.lang.String" value="new KeyBindButton(this, KEY_CONTROL_CONFIRM)"/>
</AuxValues>
</Component>
<Component class="javax.swing.JLabel" name="labelConfirm">
<Properties>
@ -6072,6 +6109,14 @@
<Property name="verticalAlignment" type="int" value="1"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="bttnResetControls">
<Properties>
<Property name="text" type="java.lang.String" value="Reset to default"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="bttnResetControlsActionPerformed"/>
</Events>
</Component>
</SubComponents>
</Container>
</SubComponents>

View file

@ -42,7 +42,9 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
@ -560,18 +562,19 @@ public class PreferencesDialog extends javax.swing.JDialog {
lebelSkip = new javax.swing.JLabel();
labelPriorEnd = new javax.swing.JLabel();
labelCancel = new javax.swing.JLabel();
keyCancelSkip = new mage.client.components.KeyBindButton();
keyNextTurn = new mage.client.components.KeyBindButton();
keyMainStep = new mage.client.components.KeyBindButton();
keyEndStep = new mage.client.components.KeyBindButton();
keyYourTurn = new mage.client.components.KeyBindButton();
keySkipStack = new mage.client.components.KeyBindButton();
keyPriorEnd = new mage.client.components.KeyBindButton();
keySkipStep = new mage.client.components.KeyBindButton();
keyCancelSkip = new KeyBindButton(this, KEY_CONTROL_CANCEL_SKIP);
keyNextTurn = new KeyBindButton(this, KEY_CONTROL_NEXT_TURN);
keyMainStep = new KeyBindButton(this, KEY_CONTROL_MAIN_STEP);
keyEndStep = new KeyBindButton(this, KEY_CONTROL_END_STEP);
keyYourTurn = new KeyBindButton(this, KEY_CONTROL_YOUR_TURN);
keySkipStack = new KeyBindButton(this, KEY_CONTROL_SKIP_STACK);
keyPriorEnd = new KeyBindButton(this, KEY_CONTROL_PRIOR_END);
keySkipStep = new KeyBindButton(this, KEY_CONTROL_SKIP_STEP);
labelSkipStep = new javax.swing.JLabel();
keyConfirm = new mage.client.components.KeyBindButton();
keyConfirm = new KeyBindButton(this, KEY_CONTROL_CONFIRM);
labelConfirm = new javax.swing.JLabel();
controlsDescriptionLabel = new javax.swing.JLabel();
bttnResetControls = new javax.swing.JButton();
saveButton = new javax.swing.JButton();
exitButton = new javax.swing.JButton();
@ -2513,6 +2516,13 @@ public class PreferencesDialog extends javax.swing.JDialog {
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.setVerticalAlignment(javax.swing.SwingConstants.TOP);
bttnResetControls.setText("Reset to default");
bttnResetControls.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
bttnResetControlsActionPerformed(evt);
}
});
org.jdesktop.layout.GroupLayout tabControlsLayout = new org.jdesktop.layout.GroupLayout(tabControls);
tabControls.setLayout(tabControlsLayout);
tabControlsLayout.setHorizontalGroup(
@ -2520,36 +2530,42 @@ public class PreferencesDialog extends javax.swing.JDialog {
.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))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.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))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(controlsDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE)
.add(tabControlsLayout.createSequentialGroup()
.add(bttnResetControls)
.add(0, 0, Short.MAX_VALUE))
.add(tabControlsLayout.createSequentialGroup()
.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))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.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))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(controlsDescriptionLabel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 498, Short.MAX_VALUE)))
.addContainerGap())
);
tabControlsLayout.setVerticalGroup(
tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(tabControlsLayout.createSequentialGroup()
.addContainerGap()
.add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
.add(tabControlsLayout.createSequentialGroup()
.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.BASELINE)
.add(labelConfirm)
.add(keyConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
@ -2584,9 +2600,10 @@ public class PreferencesDialog extends javax.swing.JDialog {
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
.add(tabControlsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(labelPriorEnd)
.add(keyPriorEnd, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(controlsDescriptionLabel))
.add(263, 263, 263))
.add(keyPriorEnd, 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)
.addContainerGap())
);
tabsPanel.addTab("Controls", tabControls);
@ -2780,15 +2797,15 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, dialog.txtURLServerList, KEY_CONNECTION_URL_SERVER_LIST);
// controls
save(prefs, dialog.keyConfirm, KEY_CONTROL_CONFIRM);
save(prefs, dialog.keyCancelSkip, KEY_CONTROL_CANCEL_SKIP);
save(prefs, dialog.keyNextTurn, KEY_CONTROL_NEXT_TURN);
save(prefs, dialog.keyEndStep, KEY_CONTROL_END_STEP);
save(prefs, dialog.keySkipStep, KEY_CONTROL_SKIP_STEP);
save(prefs, dialog.keyMainStep, KEY_CONTROL_MAIN_STEP);
save(prefs, dialog.keyYourTurn, KEY_CONTROL_YOUR_TURN);
save(prefs, dialog.keySkipStack, KEY_CONTROL_SKIP_STACK);
save(prefs, dialog.keyPriorEnd, KEY_CONTROL_PRIOR_END);
save(prefs, dialog.keyConfirm);
save(prefs, dialog.keyCancelSkip);
save(prefs, dialog.keyNextTurn);
save(prefs, dialog.keyEndStep);
save(prefs, dialog.keySkipStep);
save(prefs, dialog.keyMainStep);
save(prefs, dialog.keyYourTurn);
save(prefs, dialog.keySkipStack);
save(prefs, dialog.keyPriorEnd);
// Avatar
if (selectedAvatarId < MIN_AVATAR_ID || selectedAvatarId > MAX_AVATAR_ID) {
@ -3079,6 +3096,14 @@ public class PreferencesDialog extends javax.swing.JDialog {
// TODO add your handling code here:
}//GEN-LAST:event_cbCardRenderHideSetSymbolActionPerformed
private void bttnResetControlsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bttnResetControlsActionPerformed
getKeybindButtons().stream().forEach((bttn) -> {
String id = bttn.getKey();
int keyCode = getDefaultControlKey(id);
bttn.setKeyCode(keyCode);
});
}//GEN-LAST:event_bttnResetControlsActionPerformed
private void showProxySettings() {
Connection.ProxyType proxyType = (Connection.ProxyType) cbProxyType.getSelectedItem();
switch (proxyType) {
@ -3327,15 +3352,15 @@ public class PreferencesDialog extends javax.swing.JDialog {
}
private static void loadControlSettings(Preferences prefs) {
load(prefs, dialog.keyConfirm, KEY_CONTROL_CONFIRM);
load(prefs, dialog.keyCancelSkip, KEY_CONTROL_CANCEL_SKIP);
load(prefs, dialog.keyNextTurn, KEY_CONTROL_NEXT_TURN);
load(prefs, dialog.keyEndStep, KEY_CONTROL_END_STEP);
load(prefs, dialog.keySkipStep, KEY_CONTROL_SKIP_STEP);
load(prefs, dialog.keyMainStep, KEY_CONTROL_MAIN_STEP);
load(prefs, dialog.keyYourTurn, KEY_CONTROL_YOUR_TURN);
load(prefs, dialog.keySkipStack, KEY_CONTROL_SKIP_STACK);
load(prefs, dialog.keyPriorEnd, KEY_CONTROL_PRIOR_END);
load(prefs, dialog.keyConfirm);
load(prefs, dialog.keyCancelSkip);
load(prefs, dialog.keyNextTurn);
load(prefs, dialog.keyEndStep);
load(prefs, dialog.keySkipStep);
load(prefs, dialog.keyMainStep);
load(prefs, dialog.keyYourTurn);
load(prefs, dialog.keySkipStack);
load(prefs, dialog.keyPriorEnd);
}
private static void loadSelectedAvatar(Preferences prefs) {
@ -3462,8 +3487,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
load(prefs, checkBox, propName, PHASE_ON);
}
private static void load(Preferences prefs, KeyBindButton button, String propName) {
int prop = prefs.getInt(propName, getDefaultControlKey(propName));
private static void load(Preferences prefs, KeyBindButton button) {
String key = button.getKey();
int prop = prefs.getInt(key, getDefaultControlKey(key));
button.setKeyCode(prop);
}
@ -3504,10 +3530,11 @@ public class PreferencesDialog extends javax.swing.JDialog {
updateCache(propName, comboBox.getSelectedItem().toString().trim());
}
private static void save(Preferences prefs, KeyBindButton button, String propName) {
private static void save(Preferences prefs, KeyBindButton button) {
int code = button.getKeyCode();
prefs.putInt(propName, code);
updateCache(propName, Integer.toString(code));
String key = button.getKey();
prefs.putInt(key, code);
updateCache(key, Integer.toString(code));
}
public void reset() {
@ -3688,6 +3715,20 @@ public class PreferencesDialog extends javax.swing.JDialog {
);
}
public List<KeyBindButton> getKeybindButtons() {
return Arrays.asList(
keyCancelSkip,
keyConfirm,
keyEndStep,
keyMainStep,
keyNextTurn,
keyPriorEnd,
keySkipStack,
keySkipStep,
keyYourTurn
);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JScrollPane avatarPane;
private javax.swing.JPanel avatarPanel;
@ -3695,6 +3736,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
private javax.swing.JButton btnBrowseBackgroundImage;
private javax.swing.JButton btnBrowseBattlefieldImage;
private javax.swing.JButton btnBrowseImageLocation;
private javax.swing.JButton bttnResetControls;
private javax.swing.JCheckBox cbAllowRequestToShowHandCards;
private javax.swing.JCheckBox cbAskMoveToGraveOrder;
private javax.swing.JCheckBox cbAutoOrderTrigger;