Prompt when passing priority if mana in your mana pool would be lost

This commit is contained in:
drdev
2014-07-01 05:30:53 +00:00
parent c6aeb45d0f
commit 6b040f9d16
2 changed files with 66 additions and 6 deletions

View File

@@ -17,12 +17,18 @@
*/
package forge.match.input;
import forge.GuiBase;
import forge.game.Game;
import forge.game.card.Card;
import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.match.MatchUtil;
import forge.model.FModel;
import forge.properties.ForgePreferences.FPref;
import forge.util.ITriggerEvent;
import forge.util.ThreadUtil;
import forge.util.gui.SOptionPane;
import java.util.List;
@@ -61,7 +67,12 @@ public class InputPassPriority extends InputSyncronizedBase {
/** {@inheritDoc} */
@Override
protected final void onOk() {
stop();
passPriority(new Runnable() {
@Override
public void run() {
stop();
}
});
}
/** {@inheritDoc} */
@@ -69,11 +80,38 @@ public class InputPassPriority extends InputSyncronizedBase {
protected final void onCancel() {
if (!MatchUtil.undoLastAction()) { //undo if possible
//otherwise end turn
player.getController().autoPassUntil(PhaseType.CLEANUP);
stop();
passPriority(new Runnable() {
@Override
public void run() {
player.getController().autoPassUntil(PhaseType.CLEANUP);
stop();
}
});
}
}
private void passPriority(final Runnable runnable) {
//if gui player has mana floating that will be lost if phase ended right now, prompt before passing priority
Game game = GuiBase.getInterface().getGame();
Player player = game.getPhaseHandler().getPriorityPlayer();
if (player != null && player.getManaPool().willManaBeLostAtEndOfPhase() && player.getLobbyPlayer() == GuiBase.getInterface().getGuiPlayer()) {
ThreadUtil.invokeInGameThread(new Runnable() { //must invoke in game thread so dialog can be shown on mobile game
@Override
public void run() {
String message = "You have mana floating in your mana pool that will be lost if you pass priority now.";
if (FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN)) {
message += " You will take mana burn damage equal to the amount of floating mana.";
}
if (SOptionPane.showOptionDialog(message, "Mana Floating", SOptionPane.WARNING_ICON, new String[]{"OK", "Cancel"}) == 0) {
runnable.run();
}
}
});
return;
}
runnable.run(); //just pass priority immediately if no mana floating that would be lost
}
public SpellAbility getChosenSa() { return chosenSa; }
@Override