mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
renamed PayMana* classes,
pulled some code up from InputSyncronizedBase to InputBase.java mulligan method known as startGame routed selectCard call via InputProxy
This commit is contained in:
3
.gitattributes
vendored
3
.gitattributes
vendored
@@ -14169,12 +14169,11 @@ src/main/java/forge/control/input/InputBlock.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputConfirmMulligan.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputLockUI.java -text
|
||||
src/main/java/forge/control/input/InputPassPriority.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputPayManaBase.java -text
|
||||
src/main/java/forge/control/input/InputPayMana.java -text
|
||||
src/main/java/forge/control/input/InputPayManaExecuteCommands.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputPayManaOfCostPayment.java -text
|
||||
src/main/java/forge/control/input/InputPayManaSimple.java svneol=native#text/plain
|
||||
src/main/java/forge/control/input/InputPayManaX.java -text
|
||||
src/main/java/forge/control/input/InputPayment.java -text
|
||||
src/main/java/forge/control/input/InputPlayOrDraw.java -text
|
||||
src/main/java/forge/control/input/InputProliferate.java -text
|
||||
src/main/java/forge/control/input/InputQueue.java svneol=native#text/plain
|
||||
|
||||
@@ -25,9 +25,9 @@ import forge.card.mana.ManaCost;
|
||||
import forge.card.mana.ManaCostBeingPaid;
|
||||
import forge.card.mana.ManaCostShard;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.InputPayMana;
|
||||
import forge.control.input.InputPayManaOfCostPayment;
|
||||
import forge.control.input.InputPayManaX;
|
||||
import forge.control.input.InputPayment;
|
||||
import forge.game.GameState;
|
||||
import forge.game.ai.ComputerUtilMana;
|
||||
import forge.game.player.Player;
|
||||
@@ -127,9 +127,10 @@ public class CostPartMana extends CostPart {
|
||||
toPay.combineManaCost(mkCost);
|
||||
}
|
||||
|
||||
InputPayMana inpPayment;
|
||||
toPay.applySpellCostChange(ability);
|
||||
if (!toPay.isPaid()) {
|
||||
InputPayment inpPayment = new InputPayManaOfCostPayment(toPay, ability);
|
||||
inpPayment = new InputPayManaOfCostPayment(toPay, ability);
|
||||
Singletons.getControl().getInputQueue().setInputAndWait(inpPayment);
|
||||
if(!inpPayment.isPaid())
|
||||
return false;
|
||||
@@ -140,7 +141,7 @@ public class CostPartMana extends CostPart {
|
||||
if (this.getAmountOfX() > 0) {
|
||||
if( !ability.isAnnouncing("X") && !xWasBilled) {
|
||||
source.setXManaCostPaid(0);
|
||||
InputPayment inpPayment = new InputPayManaX(ability, this.getAmountOfX(), this.canXbe0());
|
||||
inpPayment = new InputPayManaX(ability, this.getAmountOfX(), this.canXbe0());
|
||||
Singletons.getControl().getInputQueue().setInputAndWait(inpPayment);
|
||||
if(!inpPayment.isPaid())
|
||||
return false;
|
||||
|
||||
@@ -10,7 +10,7 @@ import forge.game.player.Player;
|
||||
public interface Input {
|
||||
|
||||
// showMessage() is always the first method called
|
||||
void showMessage(InputQueue iq);
|
||||
void showMessageInitial();
|
||||
|
||||
void selectCard(Card c, boolean isMetaDown);
|
||||
|
||||
|
||||
@@ -35,29 +35,44 @@ import forge.gui.match.views.VMessage;
|
||||
public abstract class InputBase implements java.io.Serializable, Input {
|
||||
/** Constant <code>serialVersionUID=-6539552513871194081L</code>. */
|
||||
private static final long serialVersionUID = -6539552513871194081L;
|
||||
private InputQueue queue;
|
||||
private boolean finished = false;
|
||||
protected final boolean isFinished() { return finished; }
|
||||
protected final void setFinished() { finished = true; }
|
||||
|
||||
// showMessage() is always the first method called
|
||||
@Override
|
||||
public final void showMessage(InputQueue iq) {
|
||||
queue = iq;
|
||||
public final void showMessageInitial() {
|
||||
finished = false;
|
||||
showMessage();
|
||||
}
|
||||
|
||||
protected abstract void showMessage();
|
||||
|
||||
@Override
|
||||
public void selectCard(final Card c, boolean isMetaDown) { }
|
||||
@Override
|
||||
public void selectPlayer(final Player player) { }
|
||||
|
||||
|
||||
@Override
|
||||
public void selectButtonOK() { }
|
||||
public final void selectButtonCancel() {
|
||||
if( isFinished() ) return;
|
||||
onCancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectButtonCancel() { }
|
||||
public final void selectButtonOK() {
|
||||
if( isFinished() ) return;
|
||||
onOk();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void selectCard(Card c, boolean isMetaDown) {
|
||||
if( isFinished() ) return;
|
||||
onCardSelected(c, isMetaDown);
|
||||
}
|
||||
|
||||
protected void onCardSelected(Card c, boolean isRmb) {}
|
||||
protected void onCancel() {}
|
||||
protected void onOk() {}
|
||||
|
||||
// to remove need for CMatchUI dependence
|
||||
protected final void showMessage(String message) {
|
||||
@@ -65,16 +80,10 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
}
|
||||
|
||||
|
||||
protected void afterStop() { }
|
||||
|
||||
protected final void flashIncorrectAction() {
|
||||
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
|
||||
}
|
||||
|
||||
protected InputQueue getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
protected String getTurnPhasePriorityMessage(Player player) {
|
||||
final PhaseHandler ph = player.getGame().getPhaseHandler();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.match.CMatchUI;
|
||||
import forge.view.ButtonUtil;
|
||||
@@ -14,13 +15,11 @@ import forge.view.ButtonUtil;
|
||||
*/
|
||||
public class InputLockUI implements Input {
|
||||
private final AtomicInteger iCall = new AtomicInteger();
|
||||
private final InputQueue iq;
|
||||
|
||||
public InputLockUI(InputQueue inputQueue) {
|
||||
iq = inputQueue;
|
||||
}
|
||||
|
||||
public void showMessage(InputQueue iq) {
|
||||
public void showMessageInitial() {
|
||||
int ixCall = 1 + iCall.getAndIncrement();
|
||||
FThreads.delay(500, new InputUpdater(ixCall));
|
||||
}
|
||||
@@ -55,7 +54,7 @@ public class InputLockUI implements Input {
|
||||
};
|
||||
|
||||
protected final boolean isActive() {
|
||||
return iq.getInput() == this;
|
||||
return Singletons.getControl().getInputQueue().getInput() == this;
|
||||
}
|
||||
|
||||
protected void showMessage(String message) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import forge.view.ButtonUtil;
|
||||
* TODO: Write javadoc for this type.
|
||||
*
|
||||
*/
|
||||
public abstract class InputPayManaBase extends InputSyncronizedBase implements InputPayment {
|
||||
public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
|
||||
private static final long serialVersionUID = -9133423708688480255L;
|
||||
|
||||
@@ -39,7 +39,7 @@ public abstract class InputPayManaBase extends InputSyncronizedBase implements I
|
||||
|
||||
boolean bPaid = false;
|
||||
|
||||
protected InputPayManaBase(SpellAbility saToPayFor) {
|
||||
protected InputPayMana(SpellAbility saToPayFor) {
|
||||
this.player = saToPayFor.getActivatingPlayer();
|
||||
this.game = player.getGame();
|
||||
this.saPaidFor = saToPayFor;
|
||||
@@ -33,7 +33,7 @@ import forge.game.player.Player;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InputPayManaExecuteCommands extends InputPayManaBase {
|
||||
public class InputPayManaExecuteCommands extends InputPayMana {
|
||||
/**
|
||||
* Constant <code>serialVersionUID=3836655722696348713L</code>.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@ import forge.card.mana.ManaCostBeingPaid;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.player.Player;
|
||||
|
||||
public class InputPayManaOfCostPayment extends InputPayManaBase {
|
||||
public class InputPayManaOfCostPayment extends InputPayMana {
|
||||
|
||||
public InputPayManaOfCostPayment(ManaCostBeingPaid cost, SpellAbility spellAbility) {
|
||||
super(spellAbility);
|
||||
|
||||
@@ -28,7 +28,7 @@ import forge.view.ButtonUtil;
|
||||
//pays the cost of a card played from the player's hand
|
||||
//the card is removed from the players hand if the cost is paid
|
||||
//CANNOT be used for ABILITIES
|
||||
public class InputPayManaSimple extends InputPayManaBase {
|
||||
public class InputPayManaSimple extends InputPayMana {
|
||||
// anything that uses this should be converted to Ability_Cost
|
||||
/** Constant <code>serialVersionUID=3467312982164195091L</code>. */
|
||||
private static final long serialVersionUID = 3467312982164195091L;
|
||||
|
||||
@@ -11,7 +11,7 @@ import forge.card.mana.ManaCostBeingPaid;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.view.ButtonUtil;
|
||||
|
||||
public class InputPayManaX extends InputPayManaBase {
|
||||
public class InputPayManaX extends InputPayMana {
|
||||
private static final long serialVersionUID = -6900234444347364050L;
|
||||
private int xPaid = 0;
|
||||
private byte colorsPaid;
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package forge.control.input;
|
||||
|
||||
public interface InputPayment extends InputSynchronized {
|
||||
boolean isPaid();
|
||||
}
|
||||
@@ -126,9 +126,6 @@ public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyn
|
||||
for(T c : selected)
|
||||
if( c instanceof Card)
|
||||
((Card)c).setUsedToPay(false);
|
||||
|
||||
super.afterStop(); // It's ultimatelly important to keep call to super class!
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,17 +2,14 @@ package forge.control.input;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import forge.Card;
|
||||
import forge.FThreads;
|
||||
import forge.Singletons;
|
||||
import forge.error.BugReporter;
|
||||
|
||||
public abstract class InputSyncronizedBase extends InputBase implements InputSynchronized {
|
||||
private static final long serialVersionUID = 8756177361251703052L;
|
||||
|
||||
|
||||
private final CountDownLatch cdlDone;
|
||||
|
||||
|
||||
public InputSyncronizedBase() {
|
||||
cdlDone = new CountDownLatch(1);
|
||||
}
|
||||
@@ -35,30 +32,7 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
|
||||
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() { setFinished(); } });
|
||||
|
||||
// thread irrelevant
|
||||
getQueue().removeInput(InputSyncronizedBase.this);
|
||||
Singletons.getControl().getInputQueue().removeInput(InputSyncronizedBase.this);
|
||||
cdlDone.countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void selectButtonCancel() {
|
||||
if( isFinished() ) return;
|
||||
onCancel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void selectButtonOK() {
|
||||
if( isFinished() ) return;
|
||||
onOk();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void selectCard(Card c, boolean isMetaDown) {
|
||||
if( isFinished() ) return;
|
||||
onCardSelected(c, isMetaDown);
|
||||
}
|
||||
|
||||
protected void onCardSelected(Card c, boolean isRmb) {}
|
||||
protected void onCancel() {}
|
||||
protected void onOk() {}
|
||||
|
||||
}
|
||||
@@ -1479,7 +1479,7 @@ public class GameAction {
|
||||
game.getAction().checkStateEffects();
|
||||
}
|
||||
|
||||
public void mulligan(final Player firstPlayer) {
|
||||
public void startGame(final Player firstPlayer) {
|
||||
performMulligans(firstPlayer, game.getType() == GameType.Commander);
|
||||
game.setAge(GameAge.Play);
|
||||
|
||||
|
||||
@@ -334,9 +334,6 @@ public class GameNew {
|
||||
// ultimate of Karn the Liberated
|
||||
public static void restartGame(final GameState game, final Player startingTurn, Map<Player, List<Card>> playerLibraries) {
|
||||
|
||||
game.setAge(GameAge.Mulligan);
|
||||
game.getAction().mulligan(startingTurn);
|
||||
|
||||
//Card.resetUniqueNumber();
|
||||
// need this code here, otherwise observables fail
|
||||
forge.card.trigger.Trigger.resetIDs();
|
||||
@@ -377,10 +374,14 @@ public class GameNew {
|
||||
PhaseHandler phaseHandler = game.getPhaseHandler();
|
||||
phaseHandler.setPlayerTurn(startingTurn);
|
||||
|
||||
game.setAge(GameAge.Mulligan);
|
||||
// Draw <handsize> cards
|
||||
for (final Player p : game.getPlayers()) {
|
||||
p.drawCards(p.getMaxHandSize());
|
||||
}
|
||||
|
||||
|
||||
game.getAction().startGame(startingTurn);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -125,7 +125,7 @@ public class MatchState {
|
||||
}
|
||||
|
||||
currentGame.setAge(GameAge.Mulligan);
|
||||
currentGame.getAction().mulligan(firstPlayer);
|
||||
currentGame.getAction().startGame(firstPlayer);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,10 +39,9 @@ import forge.card.spellability.Ability;
|
||||
import forge.card.spellability.HumanPlaySpellAbility;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.Target;
|
||||
import forge.control.input.InputPayManaBase;
|
||||
import forge.control.input.InputPayMana;
|
||||
import forge.control.input.InputPayManaExecuteCommands;
|
||||
import forge.control.input.InputPayManaSimple;
|
||||
import forge.control.input.InputPayment;
|
||||
import forge.control.input.InputSelectCards;
|
||||
import forge.control.input.InputSelectCardsFromList;
|
||||
import forge.game.GameActionUtil;
|
||||
@@ -160,7 +159,7 @@ public class HumanPlay {
|
||||
boolean isPaid = manaCost.isPaid();
|
||||
|
||||
if( !isPaid ) {
|
||||
InputPayManaBase inputPay = new InputPayManaSimple(p.getGame(), sa, manaCost);
|
||||
InputPayMana inputPay = new InputPayManaSimple(p.getGame(), sa, manaCost);
|
||||
Singletons.getControl().getInputQueue().setInputAndWait(inputPay);
|
||||
isPaid = inputPay.isPaid();
|
||||
}
|
||||
@@ -454,7 +453,7 @@ public class HumanPlay {
|
||||
if (!(costPart instanceof CostPartMana ))
|
||||
throw new RuntimeException("GameActionUtil.payCostDuringAbilityResolve - The remaining payment type is not Mana.");
|
||||
|
||||
InputPayment toSet = current == null
|
||||
InputPayMana toSet = current == null
|
||||
? new InputPayManaExecuteCommands(p, source + "\r\n", cost.getCostMana().getManaToPay())
|
||||
: new InputPayManaExecuteCommands(p, source + "\r\n" + "Current Card: " + current + "\r\n" , cost.getCostMana().getManaToPay());
|
||||
Singletons.getControl().getInputQueue().setInputAndWait(toSet);
|
||||
|
||||
@@ -51,8 +51,6 @@ public class InputProxy implements Observer {
|
||||
|
||||
@Override
|
||||
public final void update(final Observable observable, final Object obj) {
|
||||
synchronized(this) {} // want to update all changes to memory
|
||||
|
||||
final Input nextInput = Singletons.getControl().getInputQueue().getActualInput(game);
|
||||
|
||||
/* if(DEBUG_INPUT)
|
||||
@@ -65,7 +63,7 @@ public class InputProxy implements Observer {
|
||||
@Override public void run() {
|
||||
Input current = getInput();
|
||||
//System.out.printf("\t%s > showMessage @ %s/%s during %s%n", FThreads.debugGetCurrThreadId(), nextInput.getClass().getSimpleName(), current.getClass().getSimpleName(), game.getPhaseHandler().debugPrintState());
|
||||
current.showMessage(Singletons.getControl().getInputQueue());
|
||||
current.showMessageInitial();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -117,10 +115,10 @@ public class InputProxy implements Observer {
|
||||
* @param zone
|
||||
* a {@link forge.game.zone.PlayerZone} object.
|
||||
*/
|
||||
public final void selectCard(final Card card) {
|
||||
public final void selectCard(final Card card, boolean isRightButton) {
|
||||
Input inp = getInput();
|
||||
if ( null != inp )
|
||||
inp.selectCard(card, false);
|
||||
inp.selectCard(card, isRightButton);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@@ -131,7 +129,7 @@ public class InputProxy implements Observer {
|
||||
}
|
||||
|
||||
/** @return {@link forge.gui.InputProxy.InputBase} */
|
||||
public Input getInput() {
|
||||
private Input getInput() {
|
||||
return this.input.get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ public class CCommand implements ICDoc {
|
||||
|
||||
if (c != null && c.isInZone(ZoneType.Command)) {
|
||||
//TODO: Cast commander/activate avatar/roll planar dice here.
|
||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(c);
|
||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(c, e.isMetaDown());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import forge.Constant.Preferences;
|
||||
import forge.card.cardfactory.CardFactoryUtil;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.control.input.Input;
|
||||
import forge.control.input.InputPayManaBase;
|
||||
import forge.control.input.InputPayMana;
|
||||
import forge.game.GameState;
|
||||
import forge.game.player.HumanPlay;
|
||||
import forge.game.player.LobbyPlayer;
|
||||
@@ -185,29 +185,21 @@ public class CField implements ICDoc {
|
||||
// Roujin's bug fix version dated 2-12-2012
|
||||
final Card c = CField.this.view.getTabletop().getHoveredCard(e);
|
||||
|
||||
final Input input = CMessage.SINGLETON_INSTANCE.getInputControl().getInput();
|
||||
|
||||
if (c == null || !c.isInZone(ZoneType.Battlefield)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Yosei, the Morning Star required cards to be chosen on computer side
|
||||
//earlier it was enforced that cards must be in player zone
|
||||
//this can potentially break some other functionality
|
||||
//(tapping lands works ok but some custom cards may not...)
|
||||
if ( input != null ){
|
||||
input.selectCard(c, e.isMetaDown());
|
||||
}
|
||||
|
||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(c, e.isMetaDown());
|
||||
}
|
||||
|
||||
/** */
|
||||
private void manaAction(byte colorCode) {
|
||||
if (CField.this.player.getLobbyPlayer() == CField.this.viewer) {
|
||||
final Input in = Singletons.getControl().getInputQueue().getInput();
|
||||
if (in instanceof InputPayManaBase) {
|
||||
if (in instanceof InputPayMana) {
|
||||
// Do something
|
||||
((InputPayManaBase) in).selectManaPool(colorCode);
|
||||
((InputPayMana) in).selectManaPool(colorCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class CHand implements ICDoc, Observer {
|
||||
public void mousePressed(final MouseEvent e) {
|
||||
if (e.getButton() != MouseEvent.BUTTON1) { return; }
|
||||
|
||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(cardobj);
|
||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(cardobj, e.isMetaDown());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class CHand implements ICDoc, Observer {
|
||||
}
|
||||
final Card c = view.getHandArea().getHoveredCard(e);
|
||||
if (c != null) {
|
||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(c);
|
||||
CMessage.SINGLETON_INSTANCE.getInputControl().selectCard(c, e.isMetaDown());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user