Prevent showing menu if no ability can be played

This commit is contained in:
drdev
2013-11-11 02:36:44 +00:00
parent 812d4ca519
commit bdb1243409
2 changed files with 12 additions and 4 deletions

View File

@@ -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() {

View File

@@ -114,8 +114,14 @@ 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
} }
} }
if (hasEnabled) { //only show menu if at least one ability can be played
menu.show(triggerEvent.getComponent(), triggerEvent.getX(), triggerEvent.getY()); menu.show(triggerEvent.getComponent(), triggerEvent.getX(), triggerEvent.getY());
}
return null; //delay ability until choice made return null; //delay ability until choice made
} }