mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Improve MouseWheel support in play choice popup
This commit is contained in:
@@ -12,6 +12,7 @@ import java.awt.Point;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.awt.event.MouseWheelListener;
|
||||
|
||||
@@ -334,7 +335,7 @@ public class MenuScroller {
|
||||
*
|
||||
* @return the number of items to display at a time
|
||||
*/
|
||||
public int getscrollCount() {
|
||||
public int getScrollCount() {
|
||||
return scrollCount;
|
||||
}
|
||||
|
||||
@@ -603,10 +604,20 @@ public class MenuScroller {
|
||||
}
|
||||
|
||||
private class MouseScrollListener implements MouseWheelListener {
|
||||
public void mouseWheelMoved(MouseWheelEvent mwe){
|
||||
firstIndex += mwe.getWheelRotation();
|
||||
refreshMenu();
|
||||
public void mouseWheelMoved(MouseWheelEvent mwe) {
|
||||
int rot = mwe.getWheelRotation();
|
||||
if (rot == 0) {
|
||||
return;
|
||||
}
|
||||
// anything to scroll? otherwise select items directly
|
||||
if (menu.getComponentCount() <= scrollCount + topFixedCount + bottomFixedCount) {
|
||||
setMenuSelectedIndex(menu, Math.abs(rot), rot < 0);
|
||||
return;
|
||||
}
|
||||
|
||||
firstIndex += rot;
|
||||
mwe.consume();
|
||||
refreshMenu();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -631,4 +642,14 @@ public class MenuScroller {
|
||||
|
||||
return scrollCount;
|
||||
}
|
||||
|
||||
public static void setMenuSelectedIndex(final JPopupMenu menu, final int index, boolean scrollUp) {
|
||||
SwingUtilities.invokeLater(new Runnable() { //use invoke later to ensure first enabled item selected by default
|
||||
public void run() {
|
||||
for (int i = 0; i < index; i++) {
|
||||
menu.dispatchEvent(new KeyEvent(menu, KeyEvent.KEY_PRESSED, 0, 0, scrollUp ? KeyEvent.VK_UP : KeyEvent.VK_DOWN, KeyEvent.CHAR_UNDEFINED));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.KeyStroke;
|
||||
import javax.swing.SwingUtilities;
|
||||
import javax.swing.event.PopupMenuEvent;
|
||||
import javax.swing.event.PopupMenuListener;
|
||||
|
||||
@@ -918,9 +917,6 @@ public final class CMatchUI
|
||||
|
||||
//show menu if mouse was trigger for ability
|
||||
final JPopupMenu menu = new JPopupMenu(Localizer.getInstance().getMessage("lblAbilities"));
|
||||
//add scroll area when too big
|
||||
// TODO: do we need a user setting for the scrollCount?
|
||||
MenuScroller.setScrollerFor(menu, 8, 125, 3, 1);
|
||||
|
||||
boolean enabled;
|
||||
int firstEnabled = -1;
|
||||
@@ -949,6 +945,10 @@ public final class CMatchUI
|
||||
}
|
||||
|
||||
if (firstEnabled >= 0) { //only show menu if at least one ability can be played
|
||||
//add scroll area when too big
|
||||
// TODO: do we need a user setting for the scrollCount?
|
||||
MenuScroller.setScrollerFor(menu, 8, 125, 3, 1);
|
||||
|
||||
final CardPanel panel = findCardPanel(hostCard);
|
||||
final Component menuParent;
|
||||
final int x, y;
|
||||
@@ -983,14 +983,8 @@ public final class CMatchUI
|
||||
menu.show(menuParent, x, y);
|
||||
openAbilityMenu = menu;
|
||||
|
||||
final int _firstEnabled = firstEnabled;
|
||||
SwingUtilities.invokeLater(new Runnable() { //use invoke later to ensure first enabled ability selected by default
|
||||
@Override public final void run() {
|
||||
for (int i = 0; i <= _firstEnabled; i++) {
|
||||
menu.dispatchEvent(new KeyEvent(menu, KeyEvent.KEY_PRESSED, 0, 0, KeyEvent.VK_DOWN, KeyEvent.CHAR_UNDEFINED));
|
||||
}
|
||||
}
|
||||
});
|
||||
// TODO seems 1 would now always lead to the first enabled one?
|
||||
MenuScroller.setMenuSelectedIndex(menu, firstEnabled, false);
|
||||
}
|
||||
|
||||
return null; //delay ability until choice made
|
||||
|
||||
Reference in New Issue
Block a user