mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Allow Human vs Human games in GUI refactoring, plus some minor fixes.
This commit is contained in:
@@ -449,6 +449,14 @@ public enum FControl implements KeyEventDispatcher {
|
||||
this.game = match.createGame();
|
||||
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();
|
||||
for (final Player p : game.getPlayers()) {
|
||||
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) {
|
||||
// Watch game but do not participate
|
||||
final LocalGameView gameView = new LocalGameView(game);
|
||||
|
||||
@@ -118,15 +118,15 @@ public class FControl {
|
||||
}
|
||||
|
||||
public static void startGameInSameMatch() {
|
||||
final Match match = game.getMatch();
|
||||
endCurrentGame();
|
||||
startGame(game.getMatch());
|
||||
startGame(match);
|
||||
}
|
||||
|
||||
public static void startGameInNewMatch() {
|
||||
endCurrentGame();
|
||||
final Match match = game.getMatch();
|
||||
endCurrentGame();
|
||||
match.clearGamesPlayed();
|
||||
FControl.endCurrentGame();
|
||||
startGame(match);
|
||||
}
|
||||
|
||||
@@ -162,9 +162,12 @@ public class FControl {
|
||||
|
||||
// Add playback controls to match if needed
|
||||
gameHasHumanPlayer = false;
|
||||
boolean gameHasAiPlayer = false;
|
||||
for (Player p : game.getPlayers()) {
|
||||
if (p.getController().getLobbyPlayer() == getGuiPlayer()) {
|
||||
gameHasHumanPlayer = true;
|
||||
} else if (p.getLobbyPlayer() instanceof LobbyPlayerAi) {
|
||||
gameHasAiPlayer = true;
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
|
||||
|
||||
@@ -23,6 +23,11 @@ public class VZoneDisplay extends VCardDisplayArea {
|
||||
return zoneType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return player.getNCards(zoneType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
FThreads.invokeInEdtNowOrLater(GuiBase.getInterface(), updateRoutine);
|
||||
|
||||
@@ -113,6 +113,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
* library.
|
||||
*/
|
||||
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) {
|
||||
super(game0, p, lp);
|
||||
@@ -138,6 +139,24 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
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) {
|
||||
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
|
||||
public boolean mayShowCard(final CardView c) {
|
||||
if (mayLookAtAllCards()) {
|
||||
return true;
|
||||
}
|
||||
final Card card = getCard(c);
|
||||
return card == null || mayLookAt.contains(card) || card.canBeShownTo(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mayShowCardFace(final CardView c) {
|
||||
if (mayLookAtAllCards()) {
|
||||
return true;
|
||||
}
|
||||
final Card card = getCard(c);
|
||||
return card == null || !c.isFaceDown() || card.canCardFaceBeShownTo(player);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean getDisableAutoYields() {
|
||||
return this.getGame().getDisableAutoYields();
|
||||
@@ -1626,6 +1658,5 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
List<SpellAbilityView> cards) {
|
||||
return gameView.getSpellAbilities(cards);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user