From ce60a9d75b544ada9e950d984b361609313c7657 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 18 Jan 2020 08:02:31 +0400 Subject: [PATCH] * UI: choose ability to play improves (see 8add25fa1218a1269940388e3ad4b3a326ee882f) --- .../client/components/ability/AbilityPicker.java | 8 ++++++++ .../src/main/java/mage/view/AbilityPickerView.java | 13 +++++++++---- .../src/mage/player/human/HumanPlayer.java | 7 ++++++- .../main/java/mage/server/game/GameController.java | 6 +++--- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java b/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java index 3faf0f12f5..c430311c6a 100644 --- a/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java +++ b/Mage.Client/src/main/java/mage/client/components/ability/AbilityPicker.java @@ -494,6 +494,14 @@ public class AbilityPicker extends JXPanel implements MouseWheelListener { break; } } + + // old cancel style (just close dialog) + for (Object obj : choices) { + AbilityPickerAction action = (AbilityPickerAction) obj; + if (action.id == null) { + cancel(); + } + } } private void tryChoiceOption(int choiceNumber) { diff --git a/Mage.Common/src/main/java/mage/view/AbilityPickerView.java b/Mage.Common/src/main/java/mage/view/AbilityPickerView.java index 1f4575c199..8ea265aee0 100644 --- a/Mage.Common/src/main/java/mage/view/AbilityPickerView.java +++ b/Mage.Common/src/main/java/mage/view/AbilityPickerView.java @@ -18,17 +18,22 @@ public class AbilityPickerView implements Serializable { private Map choices = new LinkedHashMap<>(); private String message = null; - public AbilityPickerView(String objectName, List abilities) { + public AbilityPickerView(String objectName, List abilities, String message) { + this.message = message; + + int num = 0; for (Ability ability : abilities) { + num++; + String rule; if (objectName == null) { - choices.put(ability.getId(), ability.getRule(true)); + rule = ability.getRule(true); } else { - String rule = ability.getRule(objectName); + rule = ability.getRule(objectName); if (rule.isEmpty()) { rule = ability.toString(); } - choices.put(ability.getId(), rule); } + choices.put(ability.getId(), num + ". " + rule); } } diff --git a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java index 236e2ada06..52b6571375 100644 --- a/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.Human/src/mage/player/human/HumanPlayer.java @@ -1923,10 +1923,15 @@ public class HumanPlayer extends PlayerImpl { } } + String message = "Choose spell or ability to play"; + if (object != null) { + message = message + "
" + object.getLogName(); + } + // TODO: add canRespond cycle? prepareForResponse(game); if (!isExecutingMacro()) { - game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(abilities.values())); + game.fireGetChoiceEvent(playerId, message, object, new ArrayList<>(abilities.values())); } waitForResponse(game); diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index 70795de716..282978615b 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -201,7 +201,7 @@ public class GameController implements GameCallback { if (event.getChoices() != null && !event.getChoices().isEmpty()) { objectName = event.getChoices().iterator().next(); } - chooseAbility(event.getPlayerId(), objectName, event.getAbilities()); + chooseAbility(event.getPlayerId(), objectName, event.getAbilities(), event.getMessage()); break; case CHOOSE_PILE: choosePile(event.getPlayerId(), event.getMessage(), event.getPile1(), event.getPile2()); @@ -761,8 +761,8 @@ public class GameController implements GameCallback { } - private synchronized void chooseAbility(UUID playerId, final String objectName, final List choices) throws MageException { - perform(playerId, playerId1 -> getGameSession(playerId1).chooseAbility(new AbilityPickerView(objectName, choices))); + private synchronized void chooseAbility(UUID playerId, final String objectName, final List choices, String message) throws MageException { + perform(playerId, playerId1 -> getGameSession(playerId1).chooseAbility(new AbilityPickerView(objectName, choices, message))); } private synchronized void choosePile(UUID playerId, final String message, final List pile1, final List pile2) throws MageException {