mirror of
https://github.com/correl/mage.git
synced 2024-12-25 19:25:41 +00:00
Improve keybinding buttons, add information
This commit is contained in:
parent
5ea636126f
commit
b4dc47fbc9
4 changed files with 177 additions and 133 deletions
|
@ -1,44 +1,42 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
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.JToggleButton;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JPopupMenu;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Campbell Suter <znix@znix.xyz>
|
||||
*/
|
||||
public class KeyBindButton extends JToggleButton implements KeyListener {
|
||||
public class KeyBindButton extends JButton implements ActionListener {
|
||||
|
||||
private final JPopupMenu menu;
|
||||
private final PopupItem item;
|
||||
private int keyCode;
|
||||
private String text;
|
||||
|
||||
public KeyBindButton() {
|
||||
menu = new JPopupMenu();
|
||||
menu.add(item = new PopupItem());
|
||||
addActionListener(this);
|
||||
|
||||
fixText();
|
||||
addKeyListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e) {
|
||||
private void applyNewKeycode(int code) {
|
||||
keyCode = code;
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_ESCAPE:
|
||||
case KeyEvent.VK_SPACE:
|
||||
keyCode = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e) {
|
||||
if (!isSelected()) {
|
||||
return;
|
||||
}
|
||||
keyCode = e.getKeyCode();
|
||||
fixText();
|
||||
setSelected(false);
|
||||
menu.setVisible(false);
|
||||
setSize(getPreferredSize());
|
||||
System.out.println("text: " + text);
|
||||
}
|
||||
|
||||
|
@ -65,4 +63,32 @@ public class KeyBindButton extends JToggleButton implements KeyListener {
|
|||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
menu.show(this, 0, 0);
|
||||
item.requestFocusInWindow();
|
||||
}
|
||||
|
||||
private class PopupItem extends JLabel implements KeyListener {
|
||||
|
||||
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) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,3 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package mage.client.components;
|
||||
|
||||
import java.awt.Color;
|
||||
|
|
|
@ -3949,7 +3949,7 @@
|
|||
<Component id="checkBoxEndTurnOthers" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Component id="phases_stopSettings" pref="266" max="32767" attributes="0"/>
|
||||
<Component id="phases_stopSettings" pref="356" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
|
@ -4171,7 +4171,7 @@
|
|||
<Component id="panelCardImages" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="panelBackgroundImages" min="-2" max="-2" attributes="0"/>
|
||||
<EmptySpace pref="53" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="125" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -4230,7 +4230,7 @@
|
|||
</Group>
|
||||
<Component id="cbUseDefaultImageFolder" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="0" pref="231" max="32767" attributes="0"/>
|
||||
<EmptySpace min="0" pref="270" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
|
@ -4744,7 +4744,7 @@
|
|||
<DimensionLayout dim="1">
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Group type="102" alignment="0" attributes="0">
|
||||
<Component id="avatarPane" pref="484" max="32767" attributes="0"/>
|
||||
<Component id="avatarPane" pref="584" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
|
@ -5655,7 +5655,7 @@
|
|||
<Component id="jLabel17" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
<EmptySpace pref="91" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="198" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -5901,17 +5901,19 @@
|
|||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="keyConfirm" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keySkipStep" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keySkipStack" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyYourTurn" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyNextTurn" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyCancelSkip" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyEndStep" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyMainStep" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyPriorEnd" min="-2" max="-2" 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 pref="483" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="controlsDescriptionLabel" pref="498" max="32767" attributes="0"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -5919,6 +5921,8 @@
|
|||
<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="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"/>
|
||||
|
@ -5933,7 +5937,7 @@
|
|||
<Component id="labelNextTurn" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyNextTurn" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
<EmptySpace type="unrelated" min="-2" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="3" attributes="0">
|
||||
<Component id="labelEndStep" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyEndStep" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
|
@ -5963,7 +5967,10 @@
|
|||
<Component id="labelPriorEnd" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="keyPriorEnd" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="263" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<Component id="controlsDescriptionLabel" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace min="-2" pref="263" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -6059,6 +6066,12 @@
|
|||
<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="<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."/>
|
||||
<Property name="verticalAlignment" type="int" value="1"/>
|
||||
</Properties>
|
||||
</Component>
|
||||
</SubComponents>
|
||||
</Container>
|
||||
</SubComponents>
|
||||
|
|
|
@ -571,6 +571,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
labelSkipStep = new javax.swing.JLabel();
|
||||
keyConfirm = new mage.client.components.KeyBindButton();
|
||||
labelConfirm = new javax.swing.JLabel();
|
||||
controlsDescriptionLabel = new javax.swing.JLabel();
|
||||
saveButton = new javax.swing.JButton();
|
||||
exitButton = new javax.swing.JButton();
|
||||
|
||||
|
@ -1435,7 +1436,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.add(jLabelEndOfTurn)
|
||||
.add(checkBoxEndTurnOthers))
|
||||
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
|
||||
.add(phases_stopSettings, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
|
||||
.add(phases_stopSettings, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
|
@ -1514,7 +1515,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, 231, Short.MAX_VALUE)))
|
||||
.add(0, 270, Short.MAX_VALUE)))
|
||||
.addContainerGap())
|
||||
);
|
||||
panelCardImagesLayout.setVerticalGroup(
|
||||
|
@ -1709,7 +1710,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.add(panelCardImages, 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(panelBackgroundImages, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
|
||||
.addContainerGap(53, Short.MAX_VALUE))
|
||||
.addContainerGap(125, Short.MAX_VALUE))
|
||||
);
|
||||
|
||||
tabsPanel.addTab("Images", tabImages);
|
||||
|
@ -2284,7 +2285,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
tabAvatarsLayout.setVerticalGroup(
|
||||
tabAvatarsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
||||
.add(tabAvatarsLayout.createSequentialGroup()
|
||||
.add(avatarPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 484, Short.MAX_VALUE)
|
||||
.add(avatarPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 584, Short.MAX_VALUE)
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
|
@ -2319,7 +2320,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.add(connection_serversLayout.createSequentialGroup()
|
||||
.add(141, 141, 141)
|
||||
.add(jLabel17)))
|
||||
.addContainerGap(91, Short.MAX_VALUE))
|
||||
.addContainerGap(198, Short.MAX_VALUE))
|
||||
);
|
||||
connection_serversLayout.setVerticalGroup(
|
||||
connection_serversLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
|
||||
|
@ -2509,6 +2510,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
|
||||
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.setVerticalAlignment(javax.swing.SwingConstants.TOP);
|
||||
|
||||
org.jdesktop.layout.GroupLayout tabControlsLayout = new org.jdesktop.layout.GroupLayout(tabControls);
|
||||
tabControls.setLayout(tabControlsLayout);
|
||||
tabControlsLayout.setHorizontalGroup(
|
||||
|
@ -2528,20 +2532,24 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
.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(keySkipStep, 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(keyNextTurn, 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(keyEndStep, 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))
|
||||
.addContainerGap(483, Short.MAX_VALUE))
|
||||
.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.BASELINE)
|
||||
.add(labelConfirm)
|
||||
.add(keyConfirm, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
|
||||
|
@ -2576,8 +2584,9 @@ 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))
|
||||
.addContainerGap(263, Short.MAX_VALUE))
|
||||
.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))
|
||||
);
|
||||
|
||||
tabsPanel.addTab("Controls", tabControls);
|
||||
|
@ -3732,6 +3741,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
|||
private javax.swing.JCheckBox checkBoxUpkeepOthers;
|
||||
private javax.swing.JCheckBox checkBoxUpkeepYou;
|
||||
private javax.swing.JPanel connection_servers;
|
||||
private javax.swing.JLabel controlsDescriptionLabel;
|
||||
private javax.swing.JButton exitButton;
|
||||
private javax.swing.JLabel fontSizeLabel;
|
||||
private javax.swing.JPanel guiSizeBasic;
|
||||
|
|
Loading…
Reference in a new issue