mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Changing new input setup. A special thread will set up new input to actual state. This will eliminate the longest stack traces
This commit is contained in:
2
.gitattributes
vendored
2
.gitattributes
vendored
@@ -14220,9 +14220,9 @@ src/main/java/forge/gui/GuiChoose.java -text
|
|||||||
src/main/java/forge/gui/GuiDialog.java -text
|
src/main/java/forge/gui/GuiDialog.java -text
|
||||||
src/main/java/forge/gui/GuiDisplayUtil.java svneol=native#text/plain
|
src/main/java/forge/gui/GuiDisplayUtil.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/GuiImportPicture.java svneol=native#text/plain
|
src/main/java/forge/gui/GuiImportPicture.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/GuiInput.java svneol=native#text/plain
|
|
||||||
src/main/java/forge/gui/GuiProgressBarWindow.java svneol=native#text/plain
|
src/main/java/forge/gui/GuiProgressBarWindow.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/GuiUtils.java svneol=native#text/plain
|
src/main/java/forge/gui/GuiUtils.java svneol=native#text/plain
|
||||||
|
src/main/java/forge/gui/InputProxy.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/ListChooser.java svneol=native#text/plain
|
src/main/java/forge/gui/ListChooser.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/MultiLineLabel.java svneol=native#text/plain
|
src/main/java/forge/gui/MultiLineLabel.java svneol=native#text/plain
|
||||||
src/main/java/forge/gui/MultiLineLabelUI.java svneol=native#text/plain
|
src/main/java/forge/gui/MultiLineLabelUI.java svneol=native#text/plain
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ public class RestartGameEffect extends SpellAbilityEffect {
|
|||||||
playerLibraries.put(p, newLibrary);
|
playerLibraries.put(p, newLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameNew.restartGame(game, sa.getActivatingPlayer(), playerLibraries);
|
GameNew.restartGame(Singletons.getModel().getMatch(), game, sa.getActivatingPlayer(), playerLibraries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import forge.game.phase.PhaseType;
|
|||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.player.PlayerController;
|
import forge.game.player.PlayerController;
|
||||||
import forge.game.zone.MagicStack;
|
import forge.game.zone.MagicStack;
|
||||||
|
import forge.gui.match.controllers.CMessage;
|
||||||
import forge.util.MyObservable;
|
import forge.util.MyObservable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,7 +66,7 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
*/
|
*/
|
||||||
public final void setInput(final Input in) {
|
public final void setInput(final Input in) {
|
||||||
boolean isInputEmpty = this.input == null || this.input instanceof InputPassPriority;
|
boolean isInputEmpty = this.input == null || this.input instanceof InputPassPriority;
|
||||||
System.out.println(in.getClass().getName());
|
//System.out.println(in.getClass().getName());
|
||||||
if (!this.game.getStack().isResolving() && isInputEmpty) {
|
if (!this.game.getStack().isResolving() && isInputEmpty) {
|
||||||
this.input = in;
|
this.input = in;
|
||||||
} else {
|
} else {
|
||||||
@@ -134,12 +135,9 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
* @param update
|
* @param update
|
||||||
* a boolean.
|
* a boolean.
|
||||||
*/
|
*/
|
||||||
public final void resetInput() { resetInput(true); }
|
public final void resetInput() {
|
||||||
public final void resetInput(final boolean update) {
|
|
||||||
this.input = null;
|
this.input = null;
|
||||||
if (update) {
|
this.updateObservers();
|
||||||
this.updateObservers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -244,4 +242,19 @@ public class InputControl extends MyObservable implements java.io.Serializable {
|
|||||||
return pc.getDefaultInput();
|
return pc.getDefaultInput();
|
||||||
} // getInput()
|
} // getInput()
|
||||||
|
|
||||||
|
public final void setNewInput(GameState game) {
|
||||||
|
PhaseHandler ph = game.getPhaseHandler();
|
||||||
|
|
||||||
|
final Input tmp = getActualInput();
|
||||||
|
//String message = String.format("%s's %s, priority of %s [%sP] input is %s", ph.getPlayerTurn(), ph.getPhase(), ph.getPriorityPlayer(), ph.isPlayerPriorityAllowed() ? "+" : "-", tmp == null ? "null" : tmp.getClass().getSimpleName());
|
||||||
|
//System.out.println(message);
|
||||||
|
if (tmp != null) {
|
||||||
|
//System.out.println(ph.getPlayerTurn() + "'s " + ph.getPhase() + ", priority of " + ph.getPriorityPlayer() + " @ input is " + tmp.getClass().getName() );
|
||||||
|
CMessage.SINGLETON_INSTANCE.getInputControl().setInput(tmp);
|
||||||
|
} else if (!ph.isPlayerPriorityAllowed()) {
|
||||||
|
// System.out.println("cannot have priority, forced to pass");
|
||||||
|
ph.getPriorityPlayer().getController().passPriority();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // InputControl
|
} // InputControl
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ import java.util.Set;
|
|||||||
|
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.base.Predicates;
|
import com.google.common.base.Predicates;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
@@ -25,11 +23,13 @@ import forge.CardUtil;
|
|||||||
import forge.Singletons;
|
import forge.Singletons;
|
||||||
import forge.card.trigger.TriggerHandler;
|
import forge.card.trigger.TriggerHandler;
|
||||||
import forge.card.trigger.TriggerType;
|
import forge.card.trigger.TriggerType;
|
||||||
|
import forge.control.input.Input;
|
||||||
import forge.control.input.InputControl;
|
import forge.control.input.InputControl;
|
||||||
import forge.control.input.InputMulligan;
|
import forge.control.input.InputMulligan;
|
||||||
import forge.deck.Deck;
|
import forge.deck.Deck;
|
||||||
import forge.deck.CardPool;
|
import forge.deck.CardPool;
|
||||||
import forge.deck.DeckSection;
|
import forge.deck.DeckSection;
|
||||||
|
import forge.error.BugReporter;
|
||||||
import forge.game.event.FlipCoinEvent;
|
import forge.game.event.FlipCoinEvent;
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
@@ -38,9 +38,11 @@ import forge.game.player.LobbyPlayer;
|
|||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.zone.PlayerZone;
|
import forge.game.zone.PlayerZone;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
|
import forge.gui.match.controllers.CMessage;
|
||||||
import forge.gui.match.views.VAntes;
|
import forge.gui.match.views.VAntes;
|
||||||
import forge.item.CardPrinted;
|
import forge.item.CardPrinted;
|
||||||
import forge.item.IPaperCard;
|
import forge.item.IPaperCard;
|
||||||
|
import forge.properties.ForgePreferences;
|
||||||
import forge.properties.ForgePreferences.FPref;
|
import forge.properties.ForgePreferences.FPref;
|
||||||
import forge.util.Aggregates;
|
import forge.util.Aggregates;
|
||||||
import forge.util.MyRandom;
|
import forge.util.MyRandom;
|
||||||
@@ -51,6 +53,45 @@ import forge.util.MyRandom;
|
|||||||
*/
|
*/
|
||||||
public class GameNew {
|
public class GameNew {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for this type.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static final class GameInputUpdatesThread extends Thread {
|
||||||
|
private final MatchController match;
|
||||||
|
private final GameState game;
|
||||||
|
private boolean wasChangedRecently;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO: Write javadoc for Constructor.
|
||||||
|
* @param match
|
||||||
|
* @param game
|
||||||
|
*/
|
||||||
|
public GameInputUpdatesThread(MatchController match, GameState game) {
|
||||||
|
this.match = match;
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(){
|
||||||
|
while(!game.isGameOver()) {
|
||||||
|
boolean needsNewInput = CMessage.SINGLETON_INSTANCE.getInputControl().isValid() == false;
|
||||||
|
if ( needsNewInput ) {
|
||||||
|
match.getInput().setNewInput(game);
|
||||||
|
wasChangedRecently = true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(wasChangedRecently ? 2 : 40);
|
||||||
|
wasChangedRecently = false;
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
BugReporter.reportException(e);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final ForgePreferences preferences = Singletons.getModel().getPreferences();
|
||||||
|
|
||||||
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool secion, boolean canRandomFoil, Random generator) {
|
private static void preparePlayerLibrary(Player player, final ZoneType zoneType, CardPool secion, boolean canRandomFoil, Random generator) {
|
||||||
PlayerZone library = player.getZone(zoneType);
|
PlayerZone library = player.getZone(zoneType);
|
||||||
for (final Entry<CardPrinted, Integer> stackOfCards : secion) {
|
for (final Entry<CardPrinted, Integer> stackOfCards : secion) {
|
||||||
@@ -60,7 +101,7 @@ public class GameNew {
|
|||||||
final Card card = cardPrinted.toForgeCard(player);
|
final Card card = cardPrinted.toForgeCard(player);
|
||||||
|
|
||||||
// apply random pictures for cards
|
// apply random pictures for cards
|
||||||
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_CARD_ART)) {
|
if (preferences.getPrefBoolean(FPref.UI_RANDOM_CARD_ART)) {
|
||||||
final int cntVariants = cardPrinted.getRules().getEditionInfo(cardPrinted.getEdition()).getCopiesCount();
|
final int cntVariants = cardPrinted.getRules().getEditionInfo(cardPrinted.getEdition()).getCopiesCount();
|
||||||
if (cntVariants > 1) {
|
if (cntVariants > 1) {
|
||||||
card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1);
|
card.setRandomPicture(generator.nextInt(cntVariants - 1) + 1);
|
||||||
@@ -86,8 +127,8 @@ public class GameNew {
|
|||||||
* TODO: Accept something like match state as parameter. Match should be aware of players,
|
* TODO: Accept something like match state as parameter. Match should be aware of players,
|
||||||
* their decks and other special starting conditions.
|
* their decks and other special starting conditions.
|
||||||
*/
|
*/
|
||||||
public static void newGame(final Map<Player, PlayerStartConditions> playersConditions, final GameState game, final boolean canRandomFoil) {
|
public static void newGame(final MatchController match, final Map<Player, PlayerStartConditions> playersConditions, final GameState game, final boolean canRandomFoil) {
|
||||||
Singletons.getModel().getMatch().getInput().clearInput();
|
match.getInput().clearInput();
|
||||||
|
|
||||||
Card.resetUniqueNumber();
|
Card.resetUniqueNumber();
|
||||||
// need this code here, otherwise observables fail
|
// need this code here, otherwise observables fail
|
||||||
@@ -97,7 +138,7 @@ public class GameNew {
|
|||||||
trigHandler.clearDelayedTrigger();
|
trigHandler.clearDelayedTrigger();
|
||||||
|
|
||||||
// friendliness
|
// friendliness
|
||||||
boolean useAnte = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE);
|
boolean useAnte = preferences.getPrefBoolean(FPref.UI_ANTE);
|
||||||
final Set<CardPrinted> rAICards = new HashSet<CardPrinted>();
|
final Set<CardPrinted> rAICards = new HashSet<CardPrinted>();
|
||||||
|
|
||||||
Map<Player, Set<CardPrinted>> removedAnteCards = new HashMap<Player, Set<CardPrinted>>();
|
Map<Player, Set<CardPrinted>> removedAnteCards = new HashMap<Player, Set<CardPrinted>>();
|
||||||
@@ -112,8 +153,8 @@ public class GameNew {
|
|||||||
|
|
||||||
initVariantsZones(player, psc);
|
initVariantsZones(player, psc);
|
||||||
|
|
||||||
GameType gameType = Singletons.getModel().getMatch().getGameType();
|
GameType gameType = match.getGameType();
|
||||||
boolean isFirstGame = Singletons.getModel().getMatch().getPlayedGames().isEmpty();
|
boolean isFirstGame = match.getPlayedGames().isEmpty();
|
||||||
boolean hasSideboard = psc.getOriginalDeck().has(DeckSection.Sideboard);
|
boolean hasSideboard = psc.getOriginalDeck().has(DeckSection.Sideboard);
|
||||||
boolean canSideBoard = !isFirstGame && gameType.isSideboardingAllowed() && hasSideboard;
|
boolean canSideBoard = !isFirstGame && gameType.isSideboardingAllowed() && hasSideboard;
|
||||||
|
|
||||||
@@ -132,7 +173,7 @@ public class GameNew {
|
|||||||
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.get(DeckSection.Sideboard), canRandomFoil, generator);
|
preparePlayerLibrary(player, ZoneType.Sideboard, myDeck.get(DeckSection.Sideboard), canRandomFoil, generator);
|
||||||
|
|
||||||
// Shuffling
|
// Shuffling
|
||||||
if (player instanceof AIPlayer && Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_SMOOTH_LAND)) {
|
if (player instanceof AIPlayer && preferences.getPrefBoolean(FPref.UI_SMOOTH_LAND)) {
|
||||||
// AI may do this instead of shuffling its deck
|
// AI may do this instead of shuffling its deck
|
||||||
final Iterable<Card> c1 = GameNew.smoothComputerManaCurve(player.getCardsIn(ZoneType.Library));
|
final Iterable<Card> c1 = GameNew.smoothComputerManaCurve(player.getCardsIn(ZoneType.Library));
|
||||||
player.getZone(ZoneType.Library).setCards(c1);
|
player.getZone(ZoneType.Library).setCards(c1);
|
||||||
@@ -174,7 +215,7 @@ public class GameNew {
|
|||||||
JOptionPane.showMessageDialog(null, ante.toString(), "", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, ante.toString(), "", JOptionPane.INFORMATION_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameNew.actuateGame(game, false);
|
GameNew.actuateGame(match, game, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void initVariantsZones(final Player player, final PlayerStartConditions psc) {
|
private static void initVariantsZones(final Player player, final PlayerStartConditions psc) {
|
||||||
@@ -243,8 +284,7 @@ public class GameNew {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ultimate of Karn the Liberated
|
// ultimate of Karn the Liberated
|
||||||
public static void restartGame(final GameState game, final Player startingTurn, Map<Player, List<Card>> playerLibraries) {
|
public static void restartGame(final MatchController match, final GameState game, final Player startingTurn, Map<Player, List<Card>> playerLibraries) {
|
||||||
MatchController match = Singletons.getModel().getMatch();
|
|
||||||
|
|
||||||
Map<LobbyPlayer, PlayerStartConditions> players = match.getPlayers();
|
Map<LobbyPlayer, PlayerStartConditions> players = match.getPlayers();
|
||||||
Map<Player, PlayerStartConditions> playersConditions = new HashMap<Player, PlayerStartConditions>();
|
Map<Player, PlayerStartConditions> playersConditions = new HashMap<Player, PlayerStartConditions>();
|
||||||
@@ -291,7 +331,7 @@ public class GameNew {
|
|||||||
PhaseHandler phaseHandler = game.getPhaseHandler();
|
PhaseHandler phaseHandler = game.getPhaseHandler();
|
||||||
phaseHandler.setPlayerTurn(startingTurn);
|
phaseHandler.setPlayerTurn(startingTurn);
|
||||||
|
|
||||||
GameNew.actuateGame(game, true);
|
GameNew.actuateGame(match, game, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,10 +342,10 @@ public class GameNew {
|
|||||||
* newGame, then when all is ready, call this function.
|
* newGame, then when all is ready, call this function.
|
||||||
* @param isRestartedGame Whether the actuated game is the first start or a restart
|
* @param isRestartedGame Whether the actuated game is the first start or a restart
|
||||||
*/
|
*/
|
||||||
private static void actuateGame(final GameState game, boolean isRestartedGame) {
|
private static void actuateGame(final MatchController match, final GameState game, boolean isRestartedGame) {
|
||||||
if (!isRestartedGame) {
|
if (!isRestartedGame) {
|
||||||
// Deciding which cards go to ante
|
// Deciding which cards go to ante
|
||||||
if (Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_ANTE)) {
|
if (preferences.getPrefBoolean(FPref.UI_ANTE)) {
|
||||||
final String nl = System.getProperty("line.separator");
|
final String nl = System.getProperty("line.separator");
|
||||||
final StringBuilder msg = new StringBuilder();
|
final StringBuilder msg = new StringBuilder();
|
||||||
for (final Player p : game.getPlayers()) {
|
for (final Player p : game.getPlayers()) {
|
||||||
@@ -324,15 +364,24 @@ public class GameNew {
|
|||||||
JOptionPane.showMessageDialog(null, msg, "Ante", JOptionPane.INFORMATION_MESSAGE);
|
JOptionPane.showMessageDialog(null, msg, "Ante", JOptionPane.INFORMATION_MESSAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameOutcome lastGameOutcome = Singletons.getModel().getMatch().getLastGameOutcome();
|
GameOutcome lastGameOutcome = match.getLastGameOutcome();
|
||||||
// Only cut/coin toss if it's the first game of the match
|
// Only cut/coin toss if it's the first game of the match
|
||||||
if (lastGameOutcome == null) {
|
Player goesFirst;
|
||||||
GameNew.seeWhoPlaysFirstDice();
|
Player humanPlayer = Singletons.getControl().getPlayer();
|
||||||
|
boolean isFirstGame = lastGameOutcome == null;
|
||||||
|
if (isFirstGame) {
|
||||||
|
goesFirst = GameNew.seeWhoPlaysFirstDice(game);
|
||||||
} else {
|
} else {
|
||||||
Player human = Singletons.getControl().getPlayer();
|
|
||||||
Player goesFirst = lastGameOutcome.isWinner(human.getLobbyPlayer()) ? human.getOpponent() : human;
|
goesFirst = lastGameOutcome.isWinner(humanPlayer.getLobbyPlayer()) ? humanPlayer.getOpponent() : humanPlayer;
|
||||||
setPlayersFirstTurn(goesFirst, false);
|
|
||||||
}
|
}
|
||||||
|
String message = goesFirst + ( isFirstGame ? " has won the coin toss." : " lost the last game.");
|
||||||
|
boolean willPlay = goesFirst.getController().getWillPlayOnFirstTurn(message);
|
||||||
|
if ( goesFirst != humanPlayer ) {
|
||||||
|
JOptionPane.showMessageDialog(null, message + "\nComputer Going First", "You are drawing", JOptionPane.INFORMATION_MESSAGE);
|
||||||
|
}
|
||||||
|
goesFirst = willPlay ? goesFirst : goesFirst.getOpponent();
|
||||||
|
game.getPhaseHandler().setPlayerTurn(goesFirst);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw <handsize> cards
|
// Draw <handsize> cards
|
||||||
@@ -340,9 +389,20 @@ public class GameNew {
|
|||||||
p.drawCards(p.getMaxHandSize());
|
p.drawCards(p.getMaxHandSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
game.getPhaseHandler().setPhaseState(PhaseType.MULLIGAN);
|
game.getPhaseHandler().setPhaseState(PhaseType.MULLIGAN);
|
||||||
InputControl control = Singletons.getModel().getMatch().getInput();
|
|
||||||
control.setInput(new InputMulligan());
|
InputControl control = match.getInput();
|
||||||
|
Input tmp = new InputMulligan();
|
||||||
|
control.setInput(tmp);
|
||||||
|
|
||||||
|
|
||||||
|
Thread thGame = new GameInputUpdatesThread(match, game);
|
||||||
|
|
||||||
|
match.getInput().getInput().showMessage();
|
||||||
|
thGame.setName("Game input updater");
|
||||||
|
thGame.start();
|
||||||
} // newGame()
|
} // newGame()
|
||||||
|
|
||||||
private static String buildFourColumnList(String firstLine, Iterable<CardPrinted> cAnteRemoved) {
|
private static String buildFourColumnList(String firstLine, Iterable<CardPrinted> cAnteRemoved) {
|
||||||
@@ -418,49 +478,14 @@ public class GameNew {
|
|||||||
* <p>
|
* <p>
|
||||||
* seeWhoPlaysFirstCoinToss.
|
* seeWhoPlaysFirstCoinToss.
|
||||||
* </p>
|
* </p>
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
private static void seeWhoPlaysFirstDice() {
|
private static Player seeWhoPlaysFirstDice(final GameState game) {
|
||||||
int playerDie = 0;
|
|
||||||
int computerDie = 0;
|
|
||||||
|
|
||||||
while (playerDie == computerDie) {
|
|
||||||
playerDie = MyRandom.getRandom().nextInt(20);
|
|
||||||
computerDie = MyRandom.getRandom().nextInt(20);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Play the Flip Coin sound
|
// Play the Flip Coin sound
|
||||||
Singletons.getModel().getGame().getEvents().post(new FlipCoinEvent());
|
game.getEvents().post(new FlipCoinEvent());
|
||||||
|
|
||||||
List<Player> allPlayers = Singletons.getModel().getGame().getPlayers();
|
List<Player> allPlayers = game.getPlayers();
|
||||||
setPlayersFirstTurn(allPlayers.get(MyRandom.getRandom().nextInt(allPlayers.size())), true);
|
return allPlayers.get(MyRandom.getRandom().nextInt(allPlayers.size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setPlayersFirstTurn(Player goesFirst, boolean firstGame) {
|
|
||||||
StringBuilder sb = new StringBuilder(goesFirst.toString());
|
|
||||||
if (firstGame) {
|
|
||||||
sb.append(" has won the coin toss.");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sb.append(" lost the last game.");
|
|
||||||
}
|
|
||||||
if (goesFirst.isHuman()) {
|
|
||||||
if (!humanPlayOrDraw(sb.toString())) {
|
|
||||||
goesFirst = goesFirst.getOpponent();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sb.append("\nComputer Going First");
|
|
||||||
JOptionPane.showMessageDialog(null, sb.toString(), "Play or Draw?", JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
}
|
|
||||||
Singletons.getModel().getGame().getPhaseHandler().setPlayerTurn(goesFirst);
|
|
||||||
} // seeWhoPlaysFirstDice()
|
|
||||||
|
|
||||||
private static boolean humanPlayOrDraw(String message) {
|
|
||||||
final String[] possibleValues = { "Play", "Draw" };
|
|
||||||
|
|
||||||
final Object playDraw = JOptionPane.showOptionDialog(null, message + "\n\nWould you like to play or draw?",
|
|
||||||
"Play or Draw?", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null,
|
|
||||||
possibleValues, possibleValues[0]);
|
|
||||||
|
|
||||||
return !playDraw.equals(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import forge.game.player.Player;
|
|||||||
import forge.game.player.PlayerStatistics;
|
import forge.game.player.PlayerStatistics;
|
||||||
import forge.game.player.PlayerType;
|
import forge.game.player.PlayerType;
|
||||||
import forge.game.zone.ZoneType;
|
import forge.game.zone.ZoneType;
|
||||||
import forge.gui.GuiInput;
|
import forge.gui.InputProxy;
|
||||||
import forge.gui.framework.EDocID;
|
import forge.gui.framework.EDocID;
|
||||||
import forge.gui.framework.SDisplayUtil;
|
import forge.gui.framework.SDisplayUtil;
|
||||||
import forge.gui.match.CMatchUI;
|
import forge.gui.match.CMatchUI;
|
||||||
@@ -149,8 +149,7 @@ public class MatchController {
|
|||||||
Singletons.getControl().changeState(FControl.Screens.MATCH_SCREEN);
|
Singletons.getControl().changeState(FControl.Screens.MATCH_SCREEN);
|
||||||
SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc());
|
SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc());
|
||||||
|
|
||||||
// set all observers
|
InputProxy inputControl = CMessage.SINGLETON_INSTANCE.getInputControl();
|
||||||
GuiInput inputControl = CMessage.SINGLETON_INSTANCE.getInputControl();
|
|
||||||
input.addObserver(inputControl);
|
input.addObserver(inputControl);
|
||||||
currentGame.getStack().addObserver(inputControl);
|
currentGame.getStack().addObserver(inputControl);
|
||||||
currentGame.getPhaseHandler().addObserver(inputControl);
|
currentGame.getPhaseHandler().addObserver(inputControl);
|
||||||
@@ -159,7 +158,7 @@ public class MatchController {
|
|||||||
// some observers are set in CMatchUI.initMatch
|
// some observers are set in CMatchUI.initMatch
|
||||||
|
|
||||||
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
|
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
|
||||||
GameNew.newGame(startConditions, currentGame, canRandomFoil);
|
GameNew.newGame(this, startConditions, currentGame, canRandomFoil);
|
||||||
|
|
||||||
// TODO restore this functionality!!!
|
// TODO restore this functionality!!!
|
||||||
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE);
|
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE);
|
||||||
|
|||||||
@@ -21,9 +21,7 @@ import java.util.Observable;
|
|||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
import forge.Card;
|
import forge.Card;
|
||||||
import forge.Singletons;
|
|
||||||
import forge.control.input.Input;
|
import forge.control.input.Input;
|
||||||
import forge.game.phase.PhaseHandler;
|
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.zone.PlayerZone;
|
import forge.game.zone.PlayerZone;
|
||||||
import forge.util.MyObservable;
|
import forge.util.MyObservable;
|
||||||
@@ -36,28 +34,16 @@ import forge.util.MyObservable;
|
|||||||
* @author Forge
|
* @author Forge
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class GuiInput extends MyObservable implements Observer {
|
public class InputProxy extends MyObservable implements Observer {
|
||||||
|
|
||||||
/** The input. */
|
/** The input. */
|
||||||
private Input input;
|
private Input input;
|
||||||
|
private volatile boolean valid = false;
|
||||||
|
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
|
||||||
@Override
|
@Override
|
||||||
public final void update(final Observable observable, final Object obj) {
|
public final void update(final Observable observable, final Object obj) {
|
||||||
PhaseHandler ph = Singletons.getModel().getGame().getPhaseHandler();
|
valid = false;
|
||||||
|
|
||||||
final Input tmp = Singletons.getModel().getMatch().getInput().getActualInput();
|
|
||||||
// System.out.println(ph.getPlayerTurn() + "'s " + ph.getPhase() + ", priority of " + ph.getPriorityPlayer() + " @ actual input is " + ( tmp == null ? "null" : tmp.getClass().getName()) + "; MHP = " + ph.mayPlayerHavePriority() );
|
|
||||||
if (tmp != null) {
|
|
||||||
// System.out.println(ph.getPlayerTurn() + "'s " + ph.getPhase() + ", priority of " + ph.getPriorityPlayer() + " @ input is " + tmp.getClass().getName() );
|
|
||||||
this.setInput(tmp);
|
|
||||||
} else if (!ph.isPlayerPriorityAllowed()) {
|
|
||||||
//System.out.println("cannot have priority, forced to pass");
|
|
||||||
ph.passPriority();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* Setter for the field <code>input</code>.
|
* Setter for the field <code>input</code>.
|
||||||
@@ -66,9 +52,10 @@ public class GuiInput extends MyObservable implements Observer {
|
|||||||
* @param in
|
* @param in
|
||||||
* a {@link forge.control.input.Input} object.
|
* a {@link forge.control.input.Input} object.
|
||||||
*/
|
*/
|
||||||
private void setInput(final Input in) {
|
public void setInput(final Input in) {
|
||||||
|
valid = true;
|
||||||
this.input = in;
|
this.input = in;
|
||||||
this.input.showMessage();
|
this.input.showMessage(); // this call may invalidate the input by the time it returns
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -121,10 +108,13 @@ public class GuiInput extends MyObservable implements Observer {
|
|||||||
return this.getInput().toString();
|
return this.getInput().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return {@link forge.gui.GuiInput.Input} */
|
/** @return {@link forge.gui.InputProxy.Input} */
|
||||||
public Input getInput() {
|
public Input getInput() {
|
||||||
return this.input;
|
return this.input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
return valid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -28,7 +28,7 @@ import javax.swing.JButton;
|
|||||||
|
|
||||||
import forge.Command;
|
import forge.Command;
|
||||||
import forge.game.MatchController;
|
import forge.game.MatchController;
|
||||||
import forge.gui.GuiInput;
|
import forge.gui.InputProxy;
|
||||||
import forge.gui.framework.ICDoc;
|
import forge.gui.framework.ICDoc;
|
||||||
import forge.gui.framework.SDisplayUtil;
|
import forge.gui.framework.SDisplayUtil;
|
||||||
import forge.gui.match.views.VMessage;
|
import forge.gui.match.views.VMessage;
|
||||||
@@ -42,7 +42,7 @@ public enum CMessage implements ICDoc {
|
|||||||
/** */
|
/** */
|
||||||
SINGLETON_INSTANCE;
|
SINGLETON_INSTANCE;
|
||||||
|
|
||||||
private GuiInput inputControl = new GuiInput();
|
private InputProxy inputControl = new InputProxy();
|
||||||
private Component lastFocusedButton = null;
|
private Component lastFocusedButton = null;
|
||||||
|
|
||||||
private final ActionListener actCancel = new ActionListener() {
|
private final ActionListener actCancel = new ActionListener() {
|
||||||
@@ -87,7 +87,7 @@ public enum CMessage implements ICDoc {
|
|||||||
*
|
*
|
||||||
* @return GuiInput
|
* @return GuiInput
|
||||||
*/
|
*/
|
||||||
public GuiInput getInputControl() {
|
public InputProxy getInputControl() {
|
||||||
return this.inputControl;
|
return this.inputControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user