mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
Show Undo in prompt if last action is undoable
Clean up unnecessary items from Game menu
This commit is contained in:
31
forge-gui/src/main/java/forge/match/MatchUtil.java
Normal file
31
forge-gui/src/main/java/forge/match/MatchUtil.java
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user