mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 19:58:00 +00:00
Extract base class Input.java
This commit is contained in:
@@ -62,6 +62,7 @@ import forge.card.spellability.Target;
|
||||
import forge.card.trigger.Trigger;
|
||||
import forge.card.trigger.TriggerHandler;
|
||||
import forge.card.trigger.TriggerType;
|
||||
import forge.control.input.Input;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.InputSelectManyCards;
|
||||
import forge.game.GameState;
|
||||
@@ -2304,8 +2305,8 @@ public class CardFactoryUtil {
|
||||
* a {@link java.lang.String} object.
|
||||
* @return a {@link forge.control.input.InputBase} object.
|
||||
*/
|
||||
public static InputBase inputUntapUpToNType(final int n, final String type) {
|
||||
final InputBase untap = new InputBase() {
|
||||
public static Input inputUntapUpToNType(final int n, final String type) {
|
||||
final Input untap = new InputBase() {
|
||||
private static final long serialVersionUID = -2167059918040912025L;
|
||||
|
||||
private final int stop = n;
|
||||
|
||||
23
src/main/java/forge/control/input/Input.java
Normal file
23
src/main/java/forge/control/input/Input.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package forge.control.input;
|
||||
|
||||
import forge.Card;
|
||||
import forge.game.player.Player;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public interface Input {
|
||||
|
||||
// showMessage() is always the first method called
|
||||
void showMessage();
|
||||
|
||||
void selectCard(Card c);
|
||||
|
||||
void selectPlayer(Player player);
|
||||
|
||||
void selectButtonOK();
|
||||
|
||||
void selectButtonCancel();
|
||||
|
||||
}
|
||||
@@ -30,21 +30,21 @@ import forge.gui.match.CMatchUI;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public abstract class InputBase implements java.io.Serializable {
|
||||
public abstract class InputBase implements java.io.Serializable, Input {
|
||||
/** Constant <code>serialVersionUID=-6539552513871194081L</code>. */
|
||||
private static final long serialVersionUID = -6539552513871194081L;
|
||||
|
||||
// showMessage() is always the first method called
|
||||
/**
|
||||
* <p>
|
||||
* showMessage.
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
public abstract void showMessage();
|
||||
|
||||
@Override
|
||||
public void selectCard(final Card c) { }
|
||||
@Override
|
||||
public void selectPlayer(final Player player) { }
|
||||
@Override
|
||||
public void selectButtonOK() { }
|
||||
@Override
|
||||
public void selectButtonCancel() { }
|
||||
|
||||
// to remove need for CMatchUI dependence
|
||||
@@ -52,11 +52,7 @@ public abstract class InputBase implements java.io.Serializable {
|
||||
CMatchUI.SINGLETON_INSTANCE.showMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* stop.
|
||||
* </p>
|
||||
*/
|
||||
// called by input to cleanup.
|
||||
protected final void stop() {
|
||||
// clears a "temp" Input like Input_PayManaCost if there is one
|
||||
Singletons.getModel().getMatch().getInput().resetInput();
|
||||
|
||||
@@ -40,7 +40,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
||||
/** Constant <code>serialVersionUID=3955194449319994301L</code>. */
|
||||
private static final long serialVersionUID = 3955194449319994301L;
|
||||
|
||||
private final Stack<InputBase> inputStack = new Stack<InputBase>();
|
||||
private final Stack<Input> inputStack = new Stack<Input>();
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -50,7 +50,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
||||
* @param in
|
||||
* a {@link forge.control.input.InputBase} object.
|
||||
*/
|
||||
public final void setInput(final InputBase in) {
|
||||
public final void setInput(final Input in) {
|
||||
//System.out.println(in.getClass().getName());
|
||||
this.inputStack.push(in);
|
||||
// System.out.print("Current: " + input + "; Stack = " + inputStack);
|
||||
@@ -67,7 +67,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
||||
* @param bAddToResolving
|
||||
* a boolean.
|
||||
*/
|
||||
public final void setInputInterrupt(final InputBase in) {
|
||||
public final void setInputInterrupt(final Input in) {
|
||||
// Make this
|
||||
this.inputStack.push(in);
|
||||
this.updateObservers();
|
||||
@@ -80,7 +80,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
||||
*
|
||||
* @return a {@link forge.control.input.InputBase} object.
|
||||
*/
|
||||
public final InputBase getInput() {
|
||||
public final Input getInput() {
|
||||
return this.inputStack.peek();
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
||||
*
|
||||
* @return a {@link forge.control.input.InputBase} object.
|
||||
*/
|
||||
public final InputBase getActualInput(GameState game) {
|
||||
public final Input getActualInput(GameState game) {
|
||||
if ( !game.hasMulliganned() )
|
||||
return new InputMulligan();
|
||||
|
||||
@@ -197,7 +197,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
||||
public final void setNewInput(GameState game) {
|
||||
PhaseHandler ph = game.getPhaseHandler();
|
||||
|
||||
final InputBase tmp = getActualInput(game);
|
||||
final Input tmp = getActualInput(game);
|
||||
String message = String.format("%s's %s, priority of %s [%sP] input is %s \t stack:%s", ph.getPlayerTurn(), ph.getPhase(), ph.getPriorityPlayer(), ph.isPlayerPriorityAllowed() ? "+" : "-", tmp == null ? "null" : tmp.getClass().getSimpleName(), inputStack);
|
||||
System.out.println(message);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import forge.Card;
|
||||
import forge.GameEntity;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.Input;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameState;
|
||||
import forge.game.GameType;
|
||||
@@ -32,9 +32,9 @@ public abstract class PlayerController {
|
||||
public PlayerController(GameState game0) {
|
||||
game = game0;
|
||||
}
|
||||
public abstract InputBase getDefaultInput();
|
||||
public abstract InputBase getBlockInput();
|
||||
public abstract InputBase getCleanupInput();
|
||||
public abstract Input getDefaultInput();
|
||||
public abstract Input getBlockInput();
|
||||
public abstract Input getCleanupInput();
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ import forge.Card;
|
||||
import forge.GameEntity;
|
||||
import forge.card.spellability.Spell;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.Input;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameState;
|
||||
import forge.game.GameType;
|
||||
@@ -32,15 +32,15 @@ import forge.gui.GuiChoose;
|
||||
*/
|
||||
public class PlayerControllerAi extends PlayerController {
|
||||
|
||||
private InputBase defaultInput;
|
||||
private InputBase blockInput;
|
||||
private InputBase cleanupInput;
|
||||
private Input defaultInput;
|
||||
private Input blockInput;
|
||||
private Input cleanupInput;
|
||||
|
||||
private final AiController brains;
|
||||
private final AIPlayer player;
|
||||
|
||||
|
||||
public final InputBase getDefaultInput() {
|
||||
public final Input getDefaultInput() {
|
||||
return defaultInput;
|
||||
}
|
||||
|
||||
@@ -70,14 +70,14 @@ public class PlayerControllerAi extends PlayerController {
|
||||
}
|
||||
|
||||
/** Input to use when player has to declare blockers */
|
||||
public InputBase getBlockInput() {
|
||||
public Input getBlockInput() {
|
||||
return blockInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cleanupInput
|
||||
*/
|
||||
public InputBase getCleanupInput() {
|
||||
public Input getCleanupInput() {
|
||||
return cleanupInput;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
|
||||
import forge.Card;
|
||||
import forge.GameEntity;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.Input;
|
||||
import forge.control.input.InputBlock;
|
||||
import forge.control.input.InputCleanup;
|
||||
import forge.control.input.InputPassPriority;
|
||||
@@ -38,12 +38,12 @@ import forge.item.CardPrinted;
|
||||
*/
|
||||
public class PlayerControllerHuman extends PlayerController {
|
||||
|
||||
private final InputBase defaultInput;
|
||||
private final InputBase blockInput;
|
||||
private final InputBase cleanupInput;
|
||||
private final Input defaultInput;
|
||||
private final Input blockInput;
|
||||
private final Input cleanupInput;
|
||||
private final HumanPlayer player;
|
||||
|
||||
public final InputBase getDefaultInput() {
|
||||
public final Input getDefaultInput() {
|
||||
return defaultInput;
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
}
|
||||
|
||||
/** Input to use when player has to declare blockers */
|
||||
public InputBase getBlockInput() {
|
||||
public Input getBlockInput() {
|
||||
return blockInput;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cleanupInput
|
||||
*/
|
||||
public InputBase getCleanupInput() {
|
||||
public Input getCleanupInput() {
|
||||
return cleanupInput;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ import forge.Card;
|
||||
import forge.CardLists;
|
||||
import forge.Singletons;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.Input;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
@@ -57,9 +58,9 @@ public final class PlayerUtil {
|
||||
* @return a {@link forge.control.input.InputBase} object.
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static InputBase inputDiscardNumUnless(final int nCards, final String uType, final SpellAbility sa) {
|
||||
public static Input inputDiscardNumUnless(final int nCards, final String uType, final SpellAbility sa) {
|
||||
final SpellAbility sp = sa;
|
||||
final InputBase target = new InputBase() {
|
||||
final Input target = new InputBase() {
|
||||
private static final long serialVersionUID = 8822292413831640944L;
|
||||
|
||||
private int n = 0;
|
||||
@@ -114,9 +115,9 @@ public final class PlayerUtil {
|
||||
* @return a {@link forge.control.input.InputBase} object.
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static InputBase inputDiscard(final int nCards, final SpellAbility sa) {
|
||||
public static Input inputDiscard(final int nCards, final SpellAbility sa) {
|
||||
final SpellAbility sp = sa;
|
||||
final InputBase target = new InputBase() {
|
||||
final Input target = new InputBase() {
|
||||
private static final long serialVersionUID = -329993322080934435L;
|
||||
|
||||
private int n = 0;
|
||||
@@ -165,7 +166,7 @@ public final class PlayerUtil {
|
||||
* @return a {@link forge.control.input.InputBase} object.
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static InputBase inputSacrificePermanents(final int nCards, final String type) {
|
||||
public static Input inputSacrificePermanents(final int nCards, final String type) {
|
||||
final List<Card> list = CardLists.getType(Singletons.getControl().getPlayer().getCardsIn(ZoneType.Battlefield), type);
|
||||
|
||||
return PlayerUtil.inputSacrificePermanentsFromList(nCards, list, "Select a " + type + " to sacrifice");
|
||||
@@ -185,8 +186,8 @@ public final class PlayerUtil {
|
||||
* @return a {@link forge.control.input.InputBase} object.
|
||||
* @since 1.0.15
|
||||
*/
|
||||
public static InputBase inputSacrificePermanentsFromList(final int nCards, final List<Card> list, final String message) {
|
||||
final InputBase target = new InputBase() {
|
||||
public static Input inputSacrificePermanentsFromList(final int nCards, final List<Card> list, final String message) {
|
||||
final Input target = new InputBase() {
|
||||
private static final long serialVersionUID = 1981791992623774490L;
|
||||
private int n = 0;
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.Observer;
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.Input;
|
||||
import forge.game.player.Player;
|
||||
import forge.view.ButtonUtil;
|
||||
|
||||
@@ -38,7 +38,7 @@ import forge.view.ButtonUtil;
|
||||
public class InputProxy implements Observer {
|
||||
|
||||
/** The input. */
|
||||
private InputBase input;
|
||||
private Input input;
|
||||
private boolean valid = false;
|
||||
|
||||
@Override
|
||||
@@ -56,7 +56,7 @@ public class InputProxy implements Observer {
|
||||
* @param in
|
||||
* a {@link forge.control.input.InputBase} object.
|
||||
*/
|
||||
public final synchronized void setInput(final InputBase in) {
|
||||
public final synchronized void setInput(final Input in) {
|
||||
valid = true;
|
||||
this.input = in;
|
||||
|
||||
@@ -123,7 +123,7 @@ public class InputProxy implements Observer {
|
||||
}
|
||||
|
||||
/** @return {@link forge.gui.InputProxy.InputBase} */
|
||||
public InputBase getInput() {
|
||||
public Input getInput() {
|
||||
return this.input;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ import forge.Singletons;
|
||||
import forge.card.cardfactory.CardFactory;
|
||||
import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.InputBase;
|
||||
import forge.control.input.Input;
|
||||
import forge.control.input.InputAttack;
|
||||
import forge.control.input.InputBlock;
|
||||
import forge.control.input.InputPayManaBase;
|
||||
@@ -388,7 +388,7 @@ public class CField implements ICDoc {
|
||||
// Roujin's bug fix version dated 2-12-2012
|
||||
final Card c = CField.this.view.getTabletop().getHoveredCard(e);
|
||||
|
||||
final InputBase input = CMessage.SINGLETON_INSTANCE.getInputControl().getInput();
|
||||
final Input input = CMessage.SINGLETON_INSTANCE.getInputControl().getInput();
|
||||
|
||||
if (c != null && c.isInZone(ZoneType.Battlefield)) {
|
||||
if (c.isTapped() && (input instanceof InputPayManaSimple || input instanceof InputPayManaExecuteCommands)) {
|
||||
@@ -443,7 +443,7 @@ public class CField implements ICDoc {
|
||||
/** */
|
||||
private void manaAction(String constantColor) {
|
||||
if (CField.this.player == CField.this.playerViewer) {
|
||||
final InputBase in = Singletons.getModel().getMatch().getInput().getInput();
|
||||
final Input in = Singletons.getModel().getMatch().getInput().getInput();
|
||||
if (in instanceof InputPayManaBase) {
|
||||
// Do something
|
||||
((InputPayManaBase) in).selectManaPool(constantColor);
|
||||
|
||||
Reference in New Issue
Block a user