mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 20:58:03 +00:00
Prevent showing menu if no ability can be played
This commit is contained in:
@@ -82,7 +82,7 @@ public abstract class Ability extends SpellAbility {
|
|||||||
public static final Ability PLAY_LAND_SURROGATE = new Ability(null, (Cost)null){
|
public static final Ability PLAY_LAND_SURROGATE = new Ability(null, (Cost)null){
|
||||||
@Override
|
@Override
|
||||||
public boolean canPlay() {
|
public boolean canPlay() {
|
||||||
return true; //if this ability is added anywhere, it can be assummed that land can be played
|
return true; //if this ability is added anywhere, it can be assumed that land can be played
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void resolve() {
|
public void resolve() {
|
||||||
|
|||||||
@@ -113,9 +113,15 @@ public class PlayerControllerHuman extends PlayerController {
|
|||||||
|
|
||||||
//show menu if mouse was trigger for ability
|
//show menu if mouse was trigger for ability
|
||||||
final JPopupMenu menu = new JPopupMenu("Abilities");
|
final JPopupMenu menu = new JPopupMenu("Abilities");
|
||||||
|
|
||||||
|
boolean enabled;
|
||||||
|
boolean hasEnabled = false;
|
||||||
int shortcut = KeyEvent.VK_1; //use number keys as shortcuts for abilities 1-9
|
int shortcut = KeyEvent.VK_1; //use number keys as shortcuts for abilities 1-9
|
||||||
for (final SpellAbility ab : abilities) {
|
for (final SpellAbility ab : abilities) {
|
||||||
|
enabled = ab.canPlay();
|
||||||
|
if (enabled) {
|
||||||
|
hasEnabled = true;
|
||||||
|
}
|
||||||
GuiUtils.addMenuItem(menu, ab.toString(),
|
GuiUtils.addMenuItem(menu, ab.toString(),
|
||||||
shortcut > 0 ? KeyStroke.getKeyStroke(shortcut, 0) : null,
|
shortcut > 0 ? KeyStroke.getKeyStroke(shortcut, 0) : null,
|
||||||
new Runnable() {
|
new Runnable() {
|
||||||
@@ -123,13 +129,15 @@ public class PlayerControllerHuman extends PlayerController {
|
|||||||
public void run() {
|
public void run() {
|
||||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectAbility(ab);
|
CMessage.SINGLETON_INSTANCE.getInputControl().selectAbility(ab);
|
||||||
}
|
}
|
||||||
}, ab.canPlay());
|
}, enabled);
|
||||||
shortcut++;
|
shortcut++;
|
||||||
if (shortcut > KeyEvent.VK_9) {
|
if (shortcut > KeyEvent.VK_9) {
|
||||||
shortcut = 0; //stop adding shortcuts after 9
|
shortcut = 0; //stop adding shortcuts after 9
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
menu.show(triggerEvent.getComponent(), triggerEvent.getX(), triggerEvent.getY());
|
if (hasEnabled) { //only show menu if at least one ability can be played
|
||||||
|
menu.show(triggerEvent.getComponent(), triggerEvent.getX(), triggerEvent.getY());
|
||||||
|
}
|
||||||
|
|
||||||
return null; //delay ability until choice made
|
return null; //delay ability until choice made
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user