Allow Human vs Human games in GUI refactoring, plus some minor fixes.

This commit is contained in:
elcnesh
2014-09-12 13:06:54 +00:00
parent c3e9ff7e5b
commit 22374664f7
4 changed files with 74 additions and 5 deletions

View File

@@ -449,6 +449,14 @@ public enum FControl implements KeyEventDispatcher {
this.game = match.createGame(); this.game = match.createGame();
inputQueue = new InputQueue(game); inputQueue = new InputQueue(game);
boolean anyPlayerIsAi = false;
for (final Player p : game.getPlayers()) {
if (p.getLobbyPlayer() instanceof LobbyPlayerAi) {
anyPlayerIsAi = true;
break;
}
}
final LobbyPlayer me = getGuiPlayer(); final LobbyPlayer me = getGuiPlayer();
for (final Player p : game.getPlayers()) { for (final Player p : game.getPlayers()) {
if (p.getLobbyPlayer().equals(me)) { if (p.getLobbyPlayer().equals(me)) {
@@ -459,6 +467,17 @@ public enum FControl implements KeyEventDispatcher {
} }
} }
if (!anyPlayerIsAi) {
// If there are no AI's, allow all players to see all cards (hotseat
// mode).
for (final Player p : game.getPlayers()) {
if (p.getController() instanceof PlayerControllerHuman) {
final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController();
controller.setMayLookAtAllCards(true);
}
}
}
if (this.gameView == null) { if (this.gameView == null) {
// Watch game but do not participate // Watch game but do not participate
final LocalGameView gameView = new LocalGameView(game); final LocalGameView gameView = new LocalGameView(game);

View File

@@ -118,15 +118,15 @@ public class FControl {
} }
public static void startGameInSameMatch() { public static void startGameInSameMatch() {
final Match match = game.getMatch();
endCurrentGame(); endCurrentGame();
startGame(game.getMatch()); startGame(match);
} }
public static void startGameInNewMatch() { public static void startGameInNewMatch() {
endCurrentGame();
final Match match = game.getMatch(); final Match match = game.getMatch();
endCurrentGame();
match.clearGamesPlayed(); match.clearGamesPlayed();
FControl.endCurrentGame();
startGame(match); startGame(match);
} }
@@ -162,9 +162,12 @@ public class FControl {
// Add playback controls to match if needed // Add playback controls to match if needed
gameHasHumanPlayer = false; gameHasHumanPlayer = false;
boolean gameHasAiPlayer = false;
for (Player p : game.getPlayers()) { for (Player p : game.getPlayers()) {
if (p.getController().getLobbyPlayer() == getGuiPlayer()) { if (p.getController().getLobbyPlayer() == getGuiPlayer()) {
gameHasHumanPlayer = true; gameHasHumanPlayer = true;
} else if (p.getLobbyPlayer() instanceof LobbyPlayerAi) {
gameHasAiPlayer = true;
} }
} }
if (!gameHasHumanPlayer) { if (!gameHasHumanPlayer) {
@@ -186,6 +189,17 @@ public class FControl {
}); });
} }
if (!gameHasAiPlayer) {
// If there are no AI's, allow all players to see all cards (hotseat
// mode).
for (final Player p : game.getPlayers()) {
if (p.getController() instanceof PlayerControllerHuman) {
final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController();
controller.setMayLookAtAllCards(true);
}
}
}
Forge.openScreen(view); Forge.openScreen(view);
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game. // It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.

View File

@@ -23,6 +23,11 @@ public class VZoneDisplay extends VCardDisplayArea {
return zoneType; return zoneType;
} }
@Override
public int getCount() {
return player.getNCards(zoneType);
}
@Override @Override
public void update() { public void update() {
FThreads.invokeInEdtNowOrLater(GuiBase.getInterface(), updateRoutine); FThreads.invokeInEdtNowOrLater(GuiBase.getInterface(), updateRoutine);

View File

@@ -113,6 +113,7 @@ public class PlayerControllerHuman extends PlayerController {
* library. * library.
*/ */
private final Set<Card> mayLookAt = Sets.newHashSet(); private final Set<Card> mayLookAt = Sets.newHashSet();
private boolean mayLookAtAllCards = false;
public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) { public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) {
super(game0, p, lp); super(game0, p, lp);
@@ -138,6 +139,24 @@ public class PlayerControllerHuman extends PlayerController {
return gameView; return gameView;
} }
/**
* @return the mayLookAtAllCards
*/
public boolean mayLookAtAllCards() {
return mayLookAtAllCards;
}
/**
* Set this to {@code true} to enable this player to see all cards any other
* player can see.
*
* @param mayLookAtAllCards
* the mayLookAtAllCards to set
*/
public void setMayLookAtAllCards(final boolean mayLookAtAllCards) {
this.mayLookAtAllCards = mayLookAtAllCards;
}
public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) { public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) {
return !getGui().stopAtPhase(gameView.getPlayerView(turn), phase); return !getGui().stopAtPhase(gameView.getPlayerView(turn), phase);
} }
@@ -1379,19 +1398,32 @@ public class PlayerControllerHuman extends PlayerController {
} }
} }
/**
* Check whether a card may be shown. If {@code mayLookAtAllCards} is
* {@code true}, any card may be shown.
*
* @param c a card.
* @return whether the card may be shown.
* @see GameView#mayShowCardNoRedirect(CardView)
*/
@Override @Override
public boolean mayShowCard(final CardView c) { public boolean mayShowCard(final CardView c) {
if (mayLookAtAllCards()) {
return true;
}
final Card card = getCard(c); final Card card = getCard(c);
return card == null || mayLookAt.contains(card) || card.canBeShownTo(player); return card == null || mayLookAt.contains(card) || card.canBeShownTo(player);
} }
@Override @Override
public boolean mayShowCardFace(final CardView c) { public boolean mayShowCardFace(final CardView c) {
if (mayLookAtAllCards()) {
return true;
}
final Card card = getCard(c); final Card card = getCard(c);
return card == null || !c.isFaceDown() || card.canCardFaceBeShownTo(player); return card == null || !c.isFaceDown() || card.canCardFaceBeShownTo(player);
} }
@Override @Override
public boolean getDisableAutoYields() { public boolean getDisableAutoYields() {
return this.getGame().getDisableAutoYields(); return this.getGame().getDisableAutoYields();
@@ -1627,5 +1659,4 @@ public class PlayerControllerHuman extends PlayerController {
return gameView.getSpellAbilities(cards); return gameView.getSpellAbilities(cards);
} }
} }