gui-desktop : Match : add a configurable keyboard shortcut to press OK/yes button from prompt and pop-up.

Allow to quickly pass phases and accept stack events.
Default to 'space bar'
This commit is contained in:
fanch
2024-10-02 20:59:58 +02:00
parent 6a745c721b
commit 12e31f4419
12 changed files with 47 additions and 26 deletions

View File

@@ -113,6 +113,16 @@ public class KeyboardShortcuts {
}
};
/** Press OK Button */
final Action actPressButton = new AbstractAction() {
@Override
public void actionPerformed(final ActionEvent e) {
if (!Singletons.getControl().getCurrentScreen().isMatchScreen()) { return; }
if (matchUI == null) { return; }
matchUI.getGameController().selectButtonOk();
}
};
/** Alpha Strike. */
final Action actAllAttack = new AbstractAction() {
@Override
@@ -215,6 +225,7 @@ public class KeyboardShortcuts {
list.add(new Shortcut(FPref.SHORTCUT_MACRO_RECORD, localizer.getMessage("lblSHORTCUT_MACRO_RECORD"), actMacroRecord, am, im));
list.add(new Shortcut(FPref.SHORTCUT_MACRO_NEXT_ACTION, localizer.getMessage("lblSHORTCUT_MACRO_NEXT_ACTION"), actMacroNextAction, am, im));
list.add(new Shortcut(FPref.SHORTCUT_CARD_ZOOM, localizer.getMessage("lblSHORTCUT_CARD_ZOOM"), actZoomCard, am, im));
list.add(new Shortcut(FPref.SHORTCUT_PRESS_BUTTON, localizer.getMessage("lblSHORTCUT_PRESS_BUTTON"), actPressButton, am, im));
return list;
} // End initMatchShortcuts()

View File

@@ -40,6 +40,8 @@ import com.google.common.base.Function;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import forge.localinstance.properties.ForgePreferences;
import forge.model.FModel;
import forge.toolbox.FList;
import forge.toolbox.FMouseAdapter;
import forge.toolbox.FOptionPane;
@@ -81,6 +83,7 @@ public class ListChooser<T> {
// initialized before; listeners may be added to it
private final FList<T> lstChoices;
private final FOptionPane optionPane;
private final int okShortCut = Integer.parseInt(FModel.getPreferences().getPref(ForgePreferences.FPref.SHORTCUT_PRESS_BUTTON));
public ListChooser(final String title, final int minChoices, final int maxChoices, final Collection<T> list, final Function<T, String> display) {
FThreads.assertExecutedByEdt(true);
@@ -128,7 +131,8 @@ public class ListChooser<T> {
this.lstChoices.addKeyListener(new KeyAdapter() {
@Override public void keyPressed(final KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
int code = e.getKeyCode();
if (KeyEvent.VK_ENTER == code || okShortCut == code) {
ListChooser.this.commit();
}
}

View File

@@ -15,7 +15,9 @@ import javax.swing.text.StyleConstants;
import com.google.common.collect.ImmutableList;
import forge.localinstance.properties.ForgePreferences;
import forge.localinstance.skin.FSkinProp;
import forge.model.FModel;
import forge.toolbox.FSkin.SkinImage;
import forge.util.Localizer;
import forge.view.FDialog;
@@ -81,7 +83,7 @@ public class FOptionPane extends FDialog {
public static int showOptionDialog(final String message, final String title, final SkinImage icon, Component comp, final List<String> options) {
return showOptionDialog(message, title, icon, comp, options, 0);
}
public static int showOptionDialog(final String message, final String title, final SkinImage icon, final List<String> options, final int defaultOption) {
// not fully done loading yet, avoid crash when called by colorCheck for random decks (as each item gets selected after another)
if (FView.SINGLETON_INSTANCE.getSplash() != null) {
@@ -102,7 +104,7 @@ public class FOptionPane extends FDialog {
optionPane.dispose();
return dialogResult;
}
public static String showInputDialog(final String message, final String title) {
return showInputDialog(message, title, null, "", null);
}
@@ -164,6 +166,7 @@ public class FOptionPane extends FDialog {
final int gapBottom = comp == null ? gapAboveButtons : padding;
FLabel centeredLabel = null;
FTextPane centeredPrompt = null;
final int okShortCut = Integer.parseInt(FModel.getPreferences().getPref(ForgePreferences.FPref.SHORTCUT_PRESS_BUTTON));
if (icon != null) {
if (icon.getWidth() < 100) {
@@ -244,27 +247,21 @@ public class FOptionPane extends FDialog {
btn.addKeyListener(new KeyAdapter() { //hook certain keys to move focus between buttons
@Override
public void keyPressed(final KeyEvent e) {
switch (e.getKeyCode()) {
case KeyEvent.VK_LEFT:
if (option > 0) {
buttons[option - 1].requestFocusInWindow();
}
break;
case KeyEvent.VK_RIGHT:
if (option < lastOption) {
buttons[option + 1].requestFocusInWindow();
}
break;
case KeyEvent.VK_HOME:
if (option > 0) {
buttons[0].requestFocusInWindow();
}
break;
case KeyEvent.VK_END:
if (option < lastOption) {
buttons[lastOption].requestFocusInWindow();
}
break;
int code = e.getKeyCode();
if(okShortCut == code) {
btn.doClick();
}
else if(KeyEvent.VK_LEFT == code && option > 0){
buttons[option - 1].requestFocusInWindow();
}
else if( KeyEvent.VK_RIGHT == code && option < lastOption){
buttons[option + 1].requestFocusInWindow();
}
else if(KeyEvent.VK_HOME == code && option > 0) {
buttons[0].requestFocusInWindow();
}
else if(KeyEvent.VK_END == code && option < lastOption) {
buttons[lastOption].requestFocusInWindow();
}
}
});
@@ -275,7 +272,7 @@ public class FOptionPane extends FDialog {
x += dx;
}
if (centeredLabel != null) {
if (null != centeredPrompt) {
centeredLabel.setPreferredSize(new Dimension(width - 2 * padding, centeredLabel.getMinimumSize().height));
centeredPrompt.setPreferredSize(new Dimension(width - 2 * padding, centeredPrompt.getPreferredSize().height));
}

View File

@@ -418,6 +418,7 @@ lblSHORTCUT_AUTOYIELD_ALWAYS_NO=Duel: Auto-Bestätigen von Fähigkeiten auf dem
lblSHORTCUT_MACRO_RECORD=Duell: Aktion-Abfolge-Makro aufnehmen
lblSHORTCUT_MACRO_NEXT_ACTION=Duel: führe nächste Aktion im gespeicherten Makro aus
lblSHORTCUT_CARD_ZOOM=Duell: Zoome ausgewählte Karte
lblSHORTCUT_PRESS_BUTTON=Duell: Dr<44>cken Sie die OK/Ja-Taste
#VSubmenuDraft.java
lblBoosterDraft=Booster-Draft
lblHeaderBoosterDraft=Format: Booster-Draft

View File

@@ -420,6 +420,7 @@ lblSHORTCUT_AUTOYIELD_ALWAYS_NO=Match: auto-yield ability on stack (Always No)
lblSHORTCUT_MACRO_RECORD=Match: record a macro sequence of actions
lblSHORTCUT_MACRO_NEXT_ACTION=Match: execute next action in a recorded macro
lblSHORTCUT_CARD_ZOOM=Match: zoom the currently selected card
lblSHORTCUT_PRESS_BUTTON=Match: Press OK/Yes button
#VSubmenuDraft.java
lblBoosterDraft=Booster Draft
lblHeaderBoosterDraft=Sanctioned Format: Booster Draft

View File

@@ -418,6 +418,7 @@ lblSHORTCUT_SHOWTARGETING=Partida: alternar la orientación visual de superposic
lblSHORTCUT_AUTOYIELD_ALWAYS_YES=Partida: ceder automáticamente en cada habilidad de la pila (Siempre Sí)
lblSHORTCUT_AUTOYIELD_ALWAYS_NO=Partida: ceder automáticamente en cada habilidad de la pila (Siempre No)
lblSHORTCUT_MACRO_RECORD=Partida: Grabar una macro de secuencia de acciones
lblSHORTCUT_PRESS_BUTTON=Partida: Presione el bot<6F>n Aceptar/S<>
lblSHORTCUT_MACRO_NEXT_ACTION=Partida: Ejecutar siguiente acción en una macro grabada
lblSHORTCUT_CARD_ZOOM=Partida: hacer zoom en la carta seleccionada
#VSubmenuDraft.java

View File

@@ -416,6 +416,7 @@ lblSHORTCUT_SHOWTARGETING=Correspondance : basculer la superposition visuelle du
lblSHORTCUT_AUTOYIELD_ALWAYS_YES=Match : capacité de rendement automatique sur la pile (toujours oui)
lblSHORTCUT_AUTOYIELD_ALWAYS_NO=Match : capacité de rendement automatique sur la pile (toujours non)
lblSHORTCUT_MACRO_RECORD=Match : enregistrer une macro séquence d''actions
lblSHORTCUT_PRESS_BUTTON=Match: appuyez sur le bouton OK/Oui
lblSHORTCUT_MACRO_NEXT_ACTION=Match : exécuter l''action suivante dans une macro enregistrée
lblSHORTCUT_CARD_ZOOM=Match : zoomer la carte actuellement sélectionnée
#VSubmenuDraft.java

View File

@@ -415,6 +415,7 @@ lblSHORTCUT_SHOWTARGETING=Incontro: attiva / disattiva gli indicatori dei bersag
lblSHORTCUT_AUTOYIELD_ALWAYS_YES=Incontro: consenso automatico in pila: sempre Sì
lblSHORTCUT_AUTOYIELD_ALWAYS_NO=Incontro: consenso automatico in pila: sempre No
lblSHORTCUT_MACRO_RECORD=Incontro: registra una macro (sequenza di azioni)
lblSHORTCUT_PRESS_BUTTON=Incontro: premere il pulsante OK/S<>
lblSHORTCUT_MACRO_NEXT_ACTION=Incontro: esegue l''azione successiva in una macro registrata
lblSHORTCUT_CARD_ZOOM=Incontro: ingrandisce la carta attualmente selezionata
#VSubmenuDraft.java

View File

@@ -416,6 +416,7 @@ lblSHORTCUT_SHOWTARGETING=ビジュアルオーバーレイのターゲットを
lblSHORTCUT_AUTOYIELD_ALWAYS_YES=スタック解決時、優先権の自動放棄(常にはい)
lblSHORTCUT_AUTOYIELD_ALWAYS_NO=スタック解決時、優先権の自動放棄(常にいいえ)
lblSHORTCUT_MACRO_RECORD=アクションのマクロシーケンスを記録します
lblSHORTCUT_PRESS_BUTTON=はいボタンを押してください
lblSHORTCUT_MACRO_NEXT_ACTION=記録されたマクロで次のアクションを実行します
lblSHORTCUT_CARD_ZOOM=現在選択されているカードをズームします
#VSubmenuDraft.java

View File

@@ -428,6 +428,7 @@ lblSHORTCUT_SHOWTARGETING=Partida\: mudar a indicação visual do alvo
lblSHORTCUT_AUTOYIELD_ALWAYS_YES=Partida\: resolver automático a pilha (Sempre Sim)
lblSHORTCUT_AUTOYIELD_ALWAYS_NO=Partida\: resolver automático a pilha (Sempre Não)
lblSHORTCUT_MACRO_RECORD=Partida\: grave uma sequência macro das ações
lblSHORTCUT_PRESS_BUTTON=Partida\: pressione o bot<6F>o OK/Sim
lblSHORTCUT_MACRO_NEXT_ACTION=Partida\: execute a próxima ação em uma macro gravada
lblSHORTCUT_CARD_ZOOM=Partida\: amplie a carta selecionada atual
#VSubmenuDraft.java

View File

@@ -420,6 +420,7 @@ lblSHORTCUT_AUTOYIELD_ALWAYS_NO=匹配:自动让过堆叠中的异能(所有
lblSHORTCUT_MACRO_RECORD=匹配:记录操作宏的动作序列
lblSHORTCUT_MACRO_NEXT_ACTION=匹配:在录制的宏中执行下一个操作
lblSHORTCUT_CARD_ZOOM=匹配:缩放当前选定的图片
lblSHORTCUT_PRESS_BUTTON=按“是”按钮
#VSubmenuDraft.java
lblBoosterDraft=轮抓
lblHeaderBoosterDraft=游戏模式:轮抓

View File

@@ -283,7 +283,8 @@ public class ForgePreferences extends PreferencesStore<ForgePreferences.FPref> {
SHORTCUT_AUTOYIELD_ALWAYS_NO ("78"),
SHORTCUT_MACRO_RECORD ("16 82"),
SHORTCUT_MACRO_NEXT_ACTION ("16 50"),
SHORTCUT_CARD_ZOOM("90");
SHORTCUT_CARD_ZOOM("90"),
SHORTCUT_PRESS_BUTTON("32");
private final String strDefaultVal;