Show Undo in prompt if last action is undoable

Clean up unnecessary items from Game menu
This commit is contained in:
drdev
2014-07-01 04:46:24 +00:00
parent e32f335010
commit b51b67e6f0
9 changed files with 59 additions and 42 deletions

View File

@@ -0,0 +1,31 @@
package forge.match;
import forge.GuiBase;
import forge.game.Game;
import forge.game.player.Player;
import forge.match.input.Input;
import forge.match.input.InputPassPriority;
public class MatchUtil {
public static boolean undoLastAction() {
if (canUndoLastAction() && GuiBase.getInterface().getGame().stack.undo()) {
Input currentInput = GuiBase.getInterface().getInputQueue().getInput();
if (currentInput instanceof InputPassPriority) {
currentInput.showMessageInitial(); //ensure prompt updated if needed
}
return true;
}
return false;
}
public static boolean canUndoLastAction() {
Game game = GuiBase.getInterface().getGame();
if (game.stack.canUndo()) {
Player player = game.getPhaseHandler().getPriorityPlayer();
if (player != null && player.getLobbyPlayer() == GuiBase.getInterface().getGuiPlayer()) {
return true;
}
}
return false;
}
}

View File

@@ -21,6 +21,7 @@ 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.util.ITriggerEvent;
import java.util.List;
@@ -49,7 +50,12 @@ public class InputPassPriority extends InputSyncronizedBase {
public final void showMessage() {
showMessage(getTurnPhasePriorityMessage(player.getGame()));
chosenSa = null;
ButtonUtil.update("OK", "End Turn", true, true, true);
if (MatchUtil.canUndoLastAction()) { //allow undoing with cancel button if can undo last action
ButtonUtil.update("OK", "Undo", true, true, true);
}
else { //otherwise allow ending turn with cancel button
ButtonUtil.update("OK", "End Turn", true, true, true);
}
}
/** {@inheritDoc} */
@@ -61,9 +67,11 @@ public class InputPassPriority extends InputSyncronizedBase {
/** {@inheritDoc} */
@Override
protected final void onCancel() {
//end turn
player.getController().autoPassUntil(PhaseType.CLEANUP);
stop();
if (!MatchUtil.undoLastAction()) { //undo if possible
//otherwise end turn
player.getController().autoPassUntil(PhaseType.CLEANUP);
stop();
}
}
public SpellAbility getChosenSa() { return chosenSa; }