mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Merge pull request #5626 from hitch17/more-forgiving-button-presses
Simulate JButton behavior while still preserving check for BUTTON1
This commit is contained in:
commit
1ad6dc9976
3 changed files with 93 additions and 89 deletions
|
@ -15,6 +15,8 @@ public class KeyboundButton extends JButton {
|
|||
private final String text;
|
||||
private static final Font keyFont = new Font(Font.SANS_SERIF, Font.BOLD, 13);
|
||||
|
||||
private boolean tinting = false;
|
||||
|
||||
public KeyboundButton(String key) {
|
||||
text = PreferencesDialog.getCachedKeyText(key);
|
||||
}
|
||||
|
@ -25,7 +27,11 @@ public class KeyboundButton extends JButton {
|
|||
Graphics sg = g.create();
|
||||
try {
|
||||
ui.update(sg, this);
|
||||
sg.setColor(Color.white);
|
||||
if (tinting) {
|
||||
sg.setColor(new Color(0, 0, 0, 32));
|
||||
sg.fillRoundRect(2, 2, getWidth() - 4 , getHeight() - 4, 6, 6);
|
||||
}
|
||||
sg.setColor(tinting ? Color.lightGray : Color.white);
|
||||
sg.setFont(keyFont);
|
||||
|
||||
int textWidth = sg.getFontMetrics(keyFont).stringWidth(text);
|
||||
|
@ -37,4 +43,10 @@ public class KeyboundButton extends JButton {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setTint(boolean tinting) {
|
||||
this.tinting = tinting;
|
||||
repaint();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
package mage.client.game;
|
||||
|
||||
import mage.client.components.KeyboundButton;
|
||||
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public class FirstButtonMousePressedAction extends MouseAdapter {
|
||||
|
||||
private final Consumer<MouseEvent> callback;
|
||||
private boolean pressed = false;
|
||||
private boolean inside = false;
|
||||
|
||||
public FirstButtonMousePressedAction(Consumer<MouseEvent> callback) {
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
pressed = true;
|
||||
if (e.getSource() instanceof KeyboundButton) {
|
||||
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||
button.setTint(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
pressed = false;
|
||||
if (e.getSource() instanceof KeyboundButton) {
|
||||
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||
button.setTint(false);
|
||||
}
|
||||
if (e.getButton() == MouseEvent.BUTTON1 && inside) {
|
||||
callback.accept(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseEntered(MouseEvent e) {
|
||||
inside = true;
|
||||
if (pressed && e.getSource() instanceof KeyboundButton) {
|
||||
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||
button.setTint(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseExited(MouseEvent e) {
|
||||
inside = false;
|
||||
if (e.getSource() instanceof KeyboundButton) {
|
||||
KeyboundButton button = (KeyboundButton) e.getSource();
|
||||
button.setTint(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1464,14 +1464,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnToggleMacro.setToolTipText("Toggle Record Macro ("
|
||||
+ getCachedKeyText(KEY_CONTROL_TOGGLE_MACRO) + ").");
|
||||
btnToggleMacro.setFocusable(false);
|
||||
btnToggleMacro.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnToggleMacroActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnToggleMacro.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnToggleMacroActionPerformed(null)));
|
||||
|
||||
KeyStroke kst = getCachedKeystroke(KEY_CONTROL_TOGGLE_MACRO);
|
||||
this.getInputMap(c).put(kst, "F8_PRESS");
|
||||
|
@ -1497,14 +1491,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnCancelSkip.setToolTipText("Cancel all skip actions ("
|
||||
+ getCachedKeyText(KEY_CONTROL_CANCEL_SKIP) + ").");
|
||||
btnCancelSkip.setFocusable(false);
|
||||
btnCancelSkip.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
restorePriorityActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnCancelSkip.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
restorePriorityActionPerformed(null)));
|
||||
|
||||
btnSkipToNextTurn.setContentAreaFilled(false);
|
||||
btnSkipToNextTurn.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||
|
@ -1512,14 +1500,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnSkipToNextTurn.setToolTipText("Skip to next turn ("
|
||||
+ getCachedKeyText(KEY_CONTROL_NEXT_TURN) + ").");
|
||||
btnSkipToNextTurn.setFocusable(false);
|
||||
btnSkipToNextTurn.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnEndTurnActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnSkipToNextTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnEndTurnActionPerformed(null)));
|
||||
|
||||
KeyStroke ks = getCachedKeystroke(KEY_CONTROL_NEXT_TURN);
|
||||
this.getInputMap(c).put(ks, "F4_PRESS");
|
||||
|
@ -1536,14 +1518,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnSkipToEndTurn.setToolTipText("Skip to (opponents/next) end of turn step ("
|
||||
+ getCachedKeyText(KEY_CONTROL_END_STEP) + ") - adjust using preferences.");
|
||||
btnSkipToEndTurn.setFocusable(false);
|
||||
btnSkipToEndTurn.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnUntilEndOfTurnActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnSkipToEndTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnUntilEndOfTurnActionPerformed(null)));
|
||||
|
||||
ks = getCachedKeystroke(KEY_CONTROL_END_STEP);
|
||||
this.getInputMap(c).put(ks, "F5_PRESS");
|
||||
|
@ -1569,14 +1545,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnSkipToNextMain.setToolTipText("Skip to (your) next main phase ("
|
||||
+ getCachedKeyText(KEY_CONTROL_MAIN_STEP) + ") - adjust using preferences.");
|
||||
btnSkipToNextMain.setFocusable(false);
|
||||
btnSkipToNextMain.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnUntilNextMainPhaseActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnSkipToNextMain.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnUntilNextMainPhaseActionPerformed(null)));
|
||||
|
||||
ks = getCachedKeystroke(KEY_CONTROL_MAIN_STEP);
|
||||
this.getInputMap(c).put(ks, "F7_PRESS");
|
||||
|
@ -1593,14 +1563,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnSkipToYourTurn.setToolTipText("Skip to your next turn ("
|
||||
+ getCachedKeyText(KEY_CONTROL_YOUR_TURN) + ").");
|
||||
btnSkipToYourTurn.setFocusable(false);
|
||||
btnSkipToYourTurn.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnPassPriorityUntilNextYourTurnActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnSkipToYourTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnPassPriorityUntilNextYourTurnActionPerformed(null)));
|
||||
|
||||
KeyStroke ks9 = getCachedKeystroke(KEY_CONTROL_YOUR_TURN);
|
||||
this.getInputMap(c).put(ks9, "F9_PRESS");
|
||||
|
@ -1617,14 +1581,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnSkipToEndStepBeforeYourTurn.setToolTipText("Skip to the end step before your turn ("
|
||||
+ getCachedKeyText(KEY_CONTROL_PRIOR_END) + ") - adjust using preferences.");
|
||||
btnSkipToEndStepBeforeYourTurn.setFocusable(false);
|
||||
btnSkipToEndStepBeforeYourTurn.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnSkipToEndStepBeforeYourTurnActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnSkipToEndStepBeforeYourTurn.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnSkipToEndStepBeforeYourTurnActionPerformed(null)));
|
||||
|
||||
KeyStroke ks11 = getCachedKeystroke(KEY_CONTROL_PRIOR_END);
|
||||
this.getInputMap(c).put(ks11, "F11_PRESS");
|
||||
|
@ -1641,14 +1599,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnSkipStack.setToolTipText("Skip until stack is resolved ("
|
||||
+ getCachedKeyText(KEY_CONTROL_SKIP_STACK) + ").");
|
||||
btnSkipStack.setFocusable(false);
|
||||
btnSkipStack.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnPassPriorityUntilStackResolvedActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnSkipStack.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnPassPriorityUntilStackResolvedActionPerformed(null)));
|
||||
|
||||
ks = getCachedKeystroke(KEY_CONTROL_SKIP_STACK);
|
||||
this.getInputMap(c).put(ks, "F10_PRESS");
|
||||
|
@ -1664,14 +1616,8 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnConcede.setIcon(new ImageIcon(ImageManagerImpl.instance.getConcedeButtonImage()));
|
||||
btnConcede.setToolTipText("Concede the current game.");
|
||||
btnConcede.setFocusable(false);
|
||||
btnConcede.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnConcedeActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnConcede.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnConcedeActionPerformed(null)));
|
||||
|
||||
KeyStroke ks2 = getCachedKeystroke(KEY_CONTROL_CONFIRM);
|
||||
this.getInputMap(c).put(ks2, "F2_PRESS");
|
||||
|
@ -1772,28 +1718,16 @@ public final class GamePanel extends javax.swing.JPanel {
|
|||
btnSwitchHands.setIcon(new ImageIcon(ImageManagerImpl.instance.getSwitchHandsButtonImage()));
|
||||
btnSwitchHands.setFocusable(false);
|
||||
btnSwitchHands.setToolTipText("Switch between your hand cards and hand cards of controlled players.");
|
||||
btnSwitchHands.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnSwitchHandActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnSwitchHands.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnSwitchHandActionPerformed(null)));
|
||||
|
||||
btnStopWatching.setContentAreaFilled(false);
|
||||
btnStopWatching.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
btnStopWatching.setIcon(new ImageIcon(ImageManagerImpl.instance.getStopWatchButtonImage()));
|
||||
btnStopWatching.setFocusable(false);
|
||||
btnStopWatching.setToolTipText("Stop watching this game.");
|
||||
btnStopWatching.addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent evt) {
|
||||
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||
btnStopWatchingActionPerformed(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
btnStopWatching.addMouseListener(new FirstButtonMousePressedAction(e ->
|
||||
btnStopWatchingActionPerformed(null)));
|
||||
|
||||
stackObjects.setBackgroundColor(new Color(0, 0, 0, 40));
|
||||
|
||||
|
|
Loading…
Reference in a new issue