Support showing prompt for second human player

This commit is contained in:
drdev
2014-09-23 13:38:39 +00:00
parent b7ceefc8c4
commit efefedd445
29 changed files with 260 additions and 172 deletions

1
.gitattributes vendored
View File

@@ -16988,6 +16988,7 @@ forge-gui/src/main/java/forge/match/input/InputBlock.java -text
forge-gui/src/main/java/forge/match/input/InputConfirm.java -text forge-gui/src/main/java/forge/match/input/InputConfirm.java -text
forge-gui/src/main/java/forge/match/input/InputConfirmMulligan.java -text forge-gui/src/main/java/forge/match/input/InputConfirmMulligan.java -text
forge-gui/src/main/java/forge/match/input/InputLockUI.java -text forge-gui/src/main/java/forge/match/input/InputLockUI.java -text
forge-gui/src/main/java/forge/match/input/InputNone.java -text
forge-gui/src/main/java/forge/match/input/InputPassPriority.java -text forge-gui/src/main/java/forge/match/input/InputPassPriority.java -text
forge-gui/src/main/java/forge/match/input/InputPayMana.java -text forge-gui/src/main/java/forge/match/input/InputPayMana.java -text
forge-gui/src/main/java/forge/match/input/InputPayManaOfCostPayment.java -text forge-gui/src/main/java/forge/match/input/InputPayManaOfCostPayment.java -text

View File

@@ -52,7 +52,6 @@ import forge.gui.framework.SLayoutIO;
import forge.interfaces.IButton; import forge.interfaces.IButton;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.match.input.InputQueue;
import forge.model.FModel; import forge.model.FModel;
import forge.screens.deckeditor.CDeckEditorUI; import forge.screens.deckeditor.CDeckEditorUI;
import forge.screens.deckeditor.controllers.CEditorQuestCardShop; import forge.screens.deckeditor.controllers.CEditorQuestCardShop;
@@ -235,12 +234,12 @@ public class GuiDesktop implements IGuiBase {
} }
@Override @Override
public IButton getBtnOK() { public IButton getBtnOK(PlayerView playerView) {
return VMatchUI.SINGLETON_INSTANCE.getBtnOK(); return VMatchUI.SINGLETON_INSTANCE.getBtnOK();
} }
@Override @Override
public IButton getBtnCancel() { public IButton getBtnCancel(PlayerView playerView) {
return VMatchUI.SINGLETON_INSTANCE.getBtnCancel(); return VMatchUI.SINGLETON_INSTANCE.getBtnCancel();
} }
@@ -426,7 +425,7 @@ public class GuiDesktop implements IGuiBase {
} }
@Override @Override
public void showPromptMessage(final String message) { public void showPromptMessage(final PlayerView playerView, final String message) {
CMatchUI.SINGLETON_INSTANCE.showMessage(message); CMatchUI.SINGLETON_INSTANCE.showMessage(message);
} }
@@ -435,11 +434,6 @@ public class GuiDesktop implements IGuiBase {
return CMatchUI.SINGLETON_INSTANCE.stopAtPhase(playerTurn, phase); return CMatchUI.SINGLETON_INSTANCE.stopAtPhase(playerTurn, phase);
} }
@Override
public InputQueue getInputQueue() {
return FControl.instance.getInputQueue();
}
public Object showManaPool(final PlayerView player) { public Object showManaPool(final PlayerView player) {
return null; //not needed since mana pool icons are always visible return null; //not needed since mana pool icons are always visible
} }

View File

@@ -63,6 +63,7 @@ import forge.gui.framework.SLayoutIO;
import forge.gui.framework.SOverflowUtil; import forge.gui.framework.SOverflowUtil;
import forge.gui.framework.SResizingUtil; import forge.gui.framework.SResizingUtil;
import forge.match.input.InputQueue; import forge.match.input.InputQueue;
import forge.match.input.InputSynchronized;
import forge.menus.ForgeMenu; import forge.menus.ForgeMenu;
import forge.model.FModel; import forge.model.FModel;
import forge.player.GamePlayerUtil; import forge.player.GamePlayerUtil;
@@ -407,19 +408,20 @@ public enum FControl implements KeyEventDispatcher {
public Player getCurrentPlayer() { public Player getCurrentPlayer() {
if (game == null) { return null; } if (game == null) { return null; }
// try current priority LobbyPlayer lobbyPlayer = getGuiPlayer();
Player currentPriority = game.getPhaseHandler().getPriorityPlayer(); if (gameViews.size() > 1) {
if (null != currentPriority && currentPriority.getLobbyPlayer() == getGuiPlayer()) { //account for if second human player is currently being prompted
return currentPriority; InputSynchronized activeInput = InputQueue.getActiveInput();
} if (activeInput != null) {
lobbyPlayer = activeInput.getOwner().getLobbyPlayer();
// otherwise find just any player, belonging to this lobbyplayer
for (Player p : game.getPlayers()) {
if (p.getLobbyPlayer() == getGuiPlayer()) {
return p;
} }
} }
for (Player p : game.getPlayers()) {
if (p.getLobbyPlayer() == lobbyPlayer) {
return p;
}
}
return null; return null;
} }
@@ -511,15 +513,16 @@ public enum FControl implements KeyEventDispatcher {
if (p.getController() instanceof PlayerControllerHuman) { if (p.getController() instanceof PlayerControllerHuman) {
final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController(); final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController();
LocalGameView gameView = controller.getGameView(); LocalGameView gameView = controller.getGameView();
game.subscribeToEvents(new FControlGameEventHandler(GuiBase.getInterface(), gameView)); game.subscribeToEvents(new FControlGameEventHandler(gameView));
gameViews.add(gameView); gameViews.add(gameView);
humanCount++; humanCount++;
} }
} }
if (humanCount == 0) { //watch game but do not participate if (humanCount == 0) { //watch game but do not participate
LocalGameView gameView = new WatchLocalGame(game, GuiBase.getInterface()); LocalGameView gameView = new WatchLocalGame(GuiBase.getInterface(), game);
game.subscribeToEvents(new FControlGameEventHandler(GuiBase.getInterface(), gameView)); gameView.setLocalPlayer(sortedPlayers.get(0));
game.subscribeToEvents(new FControlGameEventHandler(gameView));
gameViews.add(gameView); gameViews.add(gameView);
} }
else if (humanCount == sortedPlayers.size()) { else if (humanCount == sortedPlayers.size()) {

View File

@@ -36,7 +36,6 @@ import forge.game.zone.ZoneType;
import forge.interfaces.IButton; import forge.interfaces.IButton;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.match.input.InputQueue;
import forge.properties.ForgeConstants; import forge.properties.ForgeConstants;
import forge.screens.match.FControl; import forge.screens.match.FControl;
import forge.screens.match.views.VPlayerPanel; import forge.screens.match.views.VPlayerPanel;
@@ -238,13 +237,18 @@ public class GuiMobile implements IGuiBase {
} }
@Override @Override
public IButton getBtnOK() { public IButton getBtnOK(PlayerView player) {
return FControl.getView().getActivePrompt().getBtnOk(); return FControl.getView().getPrompt(player).getBtnOk();
} }
@Override @Override
public IButton getBtnCancel() { public IButton getBtnCancel(PlayerView player) {
return FControl.getView().getActivePrompt().getBtnCancel(); return FControl.getView().getPrompt(player).getBtnCancel();
}
@Override
public void showPromptMessage(final PlayerView player, String message) {
FControl.getView().getPrompt(player).setMessage(message);
} }
@Override @Override
@@ -358,21 +362,11 @@ public class GuiMobile implements IGuiBase {
FControl.setHighlighted(player, b); FControl.setHighlighted(player, b);
} }
@Override
public void showPromptMessage(String message) {
FControl.showMessage(message);
}
@Override @Override
public boolean stopAtPhase(final PlayerView playerTurn, final PhaseType phase) { public boolean stopAtPhase(final PlayerView playerTurn, final PhaseType phase) {
return FControl.stopAtPhase(playerTurn, phase); return FControl.stopAtPhase(playerTurn, phase);
} }
@Override
public InputQueue getInputQueue() {
return FControl.getInputQueue();
}
@Override @Override
public Object showManaPool(final PlayerView player) { public Object showManaPool(final PlayerView player) {
VPlayerPanel playerPanel = FControl.getPlayerPanel(player); VPlayerPanel playerPanel = FControl.getPlayerPanel(player);

View File

@@ -48,6 +48,7 @@ import forge.game.trigger.TriggerType;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.match.input.InputPlaybackControl; import forge.match.input.InputPlaybackControl;
import forge.match.input.InputQueue; import forge.match.input.InputQueue;
import forge.match.input.InputSynchronized;
import forge.model.FModel; import forge.model.FModel;
import forge.player.GamePlayerUtil; import forge.player.GamePlayerUtil;
import forge.player.PlayerControllerHuman; import forge.player.PlayerControllerHuman;
@@ -175,15 +176,16 @@ public class FControl {
if (p.getController() instanceof PlayerControllerHuman) { if (p.getController() instanceof PlayerControllerHuman) {
final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController(); final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController();
LocalGameView gameView = controller.getGameView(); LocalGameView gameView = controller.getGameView();
game.subscribeToEvents(new FControlGameEventHandler(GuiBase.getInterface(), gameView)); game.subscribeToEvents(new FControlGameEventHandler(gameView));
gameViews.add(gameView); gameViews.add(gameView);
humanCount++; humanCount++;
} }
} }
if (humanCount == 0) { //watch game but do not participate if (humanCount == 0) { //watch game but do not participate
LocalGameView gameView = new WatchLocalGame(game, GuiBase.getInterface()); LocalGameView gameView = new WatchLocalGame(GuiBase.getInterface(), game);
game.subscribeToEvents(new FControlGameEventHandler(GuiBase.getInterface(), gameView)); gameView.setLocalPlayer(sortedPlayers.get(0));
game.subscribeToEvents(new FControlGameEventHandler(gameView));
gameViews.add(gameView); gameViews.add(gameView);
} }
else if (humanCount == sortedPlayers.size()) { else if (humanCount == sortedPlayers.size()) {
@@ -281,13 +283,6 @@ public class FControl {
} }
} }
public static void showMessage(final String s0) {
view.getActivePrompt().setMessage(s0);
}
public static void showMessage(final PlayerView playerView, final String s0) {
view.getPrompt(playerView).setMessage(s0);
}
public static VPlayerPanel getPlayerPanel(final PlayerView playerView) { public static VPlayerPanel getPlayerPanel(final PlayerView playerView) {
return view.getPlayerPanels().get(playerView); return view.getPlayerPanels().get(playerView);
} }
@@ -314,19 +309,20 @@ public class FControl {
public static Player getCurrentPlayer() { public static Player getCurrentPlayer() {
if (game == null) { return null; } if (game == null) { return null; }
// try current priority LobbyPlayer lobbyPlayer = getGuiPlayer();
Player currentPriority = game.getPhaseHandler().getPriorityPlayer(); if (gameViews.size() > 1) {
if (null != currentPriority && currentPriority.getLobbyPlayer() == getGuiPlayer()) { //account for if second human player is currently being prompted
return currentPriority; InputSynchronized activeInput = InputQueue.getActiveInput();
} if (activeInput != null) {
lobbyPlayer = activeInput.getOwner().getLobbyPlayer();
// otherwise find just any player, belonging to this lobbyplayer
for (Player p : game.getPlayers()) {
if (p.getLobbyPlayer() == getGuiPlayer()) {
return p;
} }
} }
for (Player p : game.getPlayers()) {
if (p.getLobbyPlayer() == lobbyPlayer) {
return p;
}
}
return null; return null;
} }

View File

@@ -49,9 +49,9 @@ import forge.game.player.Player;
import forge.game.zone.PlayerZone; import forge.game.zone.PlayerZone;
import forge.game.zone.Zone; import forge.game.zone.Zone;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.interfaces.IGuiBase;
import forge.match.input.ButtonUtil; import forge.match.input.ButtonUtil;
import forge.match.input.InputBase; import forge.match.input.InputBase;
import forge.match.input.InputNone;
import forge.model.FModel; import forge.model.FModel;
import forge.player.GamePlayerUtil; import forge.player.GamePlayerUtil;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
@@ -64,11 +64,9 @@ import forge.view.PlayerView;
public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> { public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
private final IGuiBase gui;
private final LocalGameView gameView; private final LocalGameView gameView;
public FControlGameEventHandler(final IGuiBase gui, final LocalGameView gameView) { public FControlGameEventHandler(final LocalGameView gameView0) {
this.gui = gui; gameView = gameView0;
this.gameView = gameView;
} }
@Subscribe @Subscribe
@@ -81,11 +79,11 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
public Void visit(final GameEventTurnPhase ev) { public Void visit(final GameEventTurnPhase ev) {
if (phaseUpdPlanned.getAndSet(true)) return null; if (phaseUpdPlanned.getAndSet(true)) return null;
FThreads.invokeInEdtNowOrLater(gui, new Runnable() { FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
@Override @Override
public void run() { public void run() {
phaseUpdPlanned.set(false); phaseUpdPlanned.set(false);
gui.updatePhase(); gameView.getGui().updatePhase();
} }
}); });
return null; return null;
@@ -98,11 +96,11 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override @Override
public Void visit(GameEventPlayerPriority event) { public Void visit(GameEventPlayerPriority event) {
if (combatUpdPlanned.getAndSet(true)) { return null; } if (combatUpdPlanned.getAndSet(true)) { return null; }
FThreads.invokeInEdtNowOrLater(gui, new Runnable() { FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
@Override @Override
public void run() { public void run() {
combatUpdPlanned.set(false); combatUpdPlanned.set(false);
gui.showCombat(gameView.getCombat()); gameView.getGui().showCombat(gameView.getCombat());
} }
}); });
return null; return null;
@@ -118,11 +116,11 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
if (turnUpdPlanned.getAndSet(true)) { return null; } if (turnUpdPlanned.getAndSet(true)) { return null; }
FThreads.invokeInEdtNowOrLater(gui, new Runnable() { FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
@Override @Override
public void run() { public void run() {
turnUpdPlanned.set(false); turnUpdPlanned.set(false);
gui.updateTurn(gameView.getPlayerView(event.turnOwner)); gameView.getGui().updateTurn(gameView.getPlayerView(event.turnOwner));
} }
}); });
return null; return null;
@@ -137,7 +135,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
options.add(fakeCard); options.add(fakeCard);
options.add(gameView.getCardView(kv.getValue())); options.add(gameView.getCardView(kv.getValue()));
} }
SGuiChoose.reveal(gui, "These cards were chosen to ante", options); SGuiChoose.reveal(gameView.getGui(), "These cards were chosen to ante", options);
return null; return null;
} }
@@ -147,10 +145,10 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
return null; return null;
} }
FThreads.invokeInEdtNowOrLater(gui, new Runnable() { FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
@Override @Override
public void run() { public void run() {
gui.updatePlayerControl(); gameView.getGui().updatePlayerControl();
} }
}); });
return null; return null;
@@ -159,25 +157,26 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
private final Runnable unlockGameThreadOnGameOver = new Runnable() { private final Runnable unlockGameThreadOnGameOver = new Runnable() {
@Override @Override
public void run() { public void run() {
gui.getInputQueue().onGameOver(true); // this will unlock any game threads waiting for inputs to complete gameView.getInputQueue().onGameOver(true); // this will unlock any game threads waiting for inputs to complete
} }
}; };
@Override @Override
public Void visit(GameEventGameOutcome ev) { public Void visit(GameEventGameOutcome ev) {
FThreads.invokeInEdtNowOrLater(gui, unlockGameThreadOnGameOver); FThreads.invokeInEdtNowOrLater(gameView.getGui(), unlockGameThreadOnGameOver);
return null; return null;
} }
@Override @Override
public Void visit(GameEventGameFinished ev) { public Void visit(GameEventGameFinished ev) {
FThreads.invokeInEdtNowOrLater(gui, new Runnable() { FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
@Override @Override
public void run() { public void run() {
InputNone inputNone = new InputNone(gameView);
InputBase.cancelAwaitNextInput(); //ensure "Waiting for opponent..." doesn't appear behind WinLo InputBase.cancelAwaitNextInput(); //ensure "Waiting for opponent..." doesn't appear behind WinLo
gui.showPromptMessage(""); //clear prompt behind WinLose overlay gameView.getGui().showPromptMessage(inputNone.getOwner(), ""); //clear prompt behind WinLose overlay
ButtonUtil.update(gui, "", "", false, false, false); ButtonUtil.update(inputNone, "", "", false, false, false);
gui.finishGame(); gameView.getGui().finishGame();
gameView.updateAchievements(); gameView.updateAchievements();
} }
}); });
@@ -189,28 +188,28 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override @Override
public void run() { public void run() {
stackUpdPlanned.set(false); stackUpdPlanned.set(false);
gui.updateStack(); gameView.getGui().updateStack();
} }
}; };
@Override @Override
public Void visit(GameEventSpellAbilityCast event) { public Void visit(GameEventSpellAbilityCast event) {
if (!stackUpdPlanned.getAndSet(true)) { if (!stackUpdPlanned.getAndSet(true)) {
FThreads.invokeInEdtNowOrLater(gui, updStack); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updStack);
} }
return null; return null;
} }
@Override @Override
public Void visit(GameEventSpellResolved event) { public Void visit(GameEventSpellResolved event) {
if (!stackUpdPlanned.getAndSet(true)) { if (!stackUpdPlanned.getAndSet(true)) {
FThreads.invokeInEdtNowOrLater(gui, updStack); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updStack);
} }
return null; return null;
} }
@Override @Override
public Void visit(GameEventSpellRemovedFromStack event) { public Void visit(GameEventSpellRemovedFromStack event) {
if (!stackUpdPlanned.getAndSet(true)) { if (!stackUpdPlanned.getAndSet(true)) {
FThreads.invokeInEdtNowOrLater(gui, updStack); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updStack);
} }
return null; return null;
} }
@@ -220,7 +219,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override @Override
public void run() { public void run() {
synchronized (zonesToUpdate) { synchronized (zonesToUpdate) {
gui.updateZones(zonesToUpdate); gameView.getGui().updateZones(zonesToUpdate);
zonesToUpdate.clear(); zonesToUpdate.clear();
} }
} }
@@ -261,7 +260,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
} }
} }
if (needUpdate) { if (needUpdate) {
FThreads.invokeInEdtNowOrLater(gui, updZones); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updZones);
} }
return null; return null;
} }
@@ -272,7 +271,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
public void run() { public void run() {
synchronized (cardsToUpdate) { synchronized (cardsToUpdate) {
final Iterable<CardView> newCardsToUpdate = gameView.getRefreshedCardViews(cardsToUpdate); final Iterable<CardView> newCardsToUpdate = gameView.getRefreshedCardViews(cardsToUpdate);
gui.updateCards(newCardsToUpdate); gameView.getGui().updateCards(newCardsToUpdate);
cardsToUpdate.clear(); cardsToUpdate.clear();
} }
} }
@@ -339,7 +338,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
} }
} }
if (needUpdate) { if (needUpdate) {
FThreads.invokeInEdtNowOrLater(gui, updCards); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updCards);
} }
return null; return null;
} }
@@ -351,7 +350,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
Iterables.addAll(cardsToUpdate, cc); Iterables.addAll(cardsToUpdate, cc);
} }
if (needUpdate) { if (needUpdate) {
FThreads.invokeInEdtNowOrLater(gui, updCards); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updCards);
} }
return null; return null;
} }
@@ -373,14 +372,14 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override @Override
public Void visit(GameEventCardStatsChanged event) { public Void visit(GameEventCardStatsChanged event) {
final Iterable<CardView> cardViews = gameView.getCardViews(event.cards); final Iterable<CardView> cardViews = gameView.getCardViews(event.cards);
gui.refreshCardDetails(cardViews); gameView.getGui().refreshCardDetails(cardViews);
return updateManyCards(cardViews); return updateManyCards(cardViews);
} }
@Override @Override
public Void visit(GameEventPlayerStatsChanged event) { public Void visit(GameEventPlayerStatsChanged event) {
for (final Player p : event.players) { for (final Player p : event.players) {
gui.refreshCardDetails(gameView.getCardViews(p.getAllCards())); gameView.getGui().refreshCardDetails(gameView.getCardViews(p.getAllCards()));
} }
return null; return null;
} }
@@ -396,7 +395,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
private final Runnable updManaPool = new Runnable() { private final Runnable updManaPool = new Runnable() {
@Override public void run() { @Override public void run() {
synchronized (manaPoolUpdate) { synchronized (manaPoolUpdate) {
gui.updateManaPool(gameView.getPlayerViews(manaPoolUpdate)); gameView.getGui().updateManaPool(gameView.getPlayerViews(manaPoolUpdate));
manaPoolUpdate.clear(); manaPoolUpdate.clear();
} }
} }
@@ -412,7 +411,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
} }
} }
if (invokeUpdate) { if (invokeUpdate) {
FThreads.invokeInEdtNowOrLater(gui, updManaPool); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updManaPool);
} }
return null; return null;
} }
@@ -422,7 +421,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
private final Runnable updLives = new Runnable() { private final Runnable updLives = new Runnable() {
@Override public void run() { @Override public void run() {
synchronized (livesUpdate) { synchronized (livesUpdate) {
gui.updateLives(gameView.getPlayerViews(livesUpdate)); gameView.getGui().updateLives(gameView.getPlayerViews(livesUpdate));
livesUpdate.clear(); livesUpdate.clear();
} }
} }
@@ -437,7 +436,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
} }
} }
if (invokeUpdate) { if (invokeUpdate) {
FThreads.invokeInEdtNowOrLater(gui, updLives); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updLives);
} }
return null; return null;
} }
@@ -452,7 +451,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
} }
} }
if (invokeUpdate) { if (invokeUpdate) {
FThreads.invokeInEdtNowOrLater(gui, updLives); FThreads.invokeInEdtNowOrLater(gameView.getGui(), updLives);
} }
return null; return null;
} }

View File

@@ -102,13 +102,13 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
*/ */
@Override @Override
public Void visit(GameEventGameFinished event) { public Void visit(GameEventGameFinished event) {
gui.getInputQueue().removeInput(inputPlayback); gameView.getInputQueue().removeInput(inputPlayback);
return null; return null;
} }
@Override @Override
public Void visit(GameEventGameStarted event) { public Void visit(GameEventGameStarted event) {
gui.getInputQueue().setInput(inputPlayback); gameView.getInputQueue().setInput(inputPlayback);
return null; return null;
} }

View File

@@ -21,7 +21,6 @@ import forge.game.player.IHasIcon;
import forge.game.player.RegisteredPlayer; import forge.game.player.RegisteredPlayer;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.match.input.InputQueue;
import forge.sound.IAudioClip; import forge.sound.IAudioClip;
import forge.sound.IAudioMusic; import forge.sound.IAudioMusic;
import forge.util.ITriggerEvent; import forge.util.ITriggerEvent;
@@ -59,11 +58,10 @@ public interface IGuiBase {
void showCombat(CombatView combat); void showCombat(CombatView combat);
void setUsedToPay(CardView card, boolean b); void setUsedToPay(CardView card, boolean b);
void setHighlighted(PlayerView player, boolean b); void setHighlighted(PlayerView player, boolean b);
void showPromptMessage(String message); void showPromptMessage(PlayerView playerView, String message);
boolean stopAtPhase(PlayerView playerTurn, PhaseType phase); boolean stopAtPhase(PlayerView playerTurn, PhaseType phase);
InputQueue getInputQueue(); IButton getBtnOK(PlayerView playerView);
IButton getBtnOK(); IButton getBtnCancel(PlayerView playerView);
IButton getBtnCancel();
void focusButton(IButton button); void focusButton(IButton button);
void flashIncorrectAction(); void flashIncorrectAction();
void updatePhase(); void updatePhase();

View File

@@ -19,17 +19,20 @@ package forge.match.input;
import forge.interfaces.IButton; import forge.interfaces.IButton;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.view.PlayerView;
/** /**
* Manages match UI OK/Cancel button enabling and focus * Manages match UI OK/Cancel button enabling and focus
*/ */
public class ButtonUtil { public class ButtonUtil {
public static void update(final IGuiBase gui, boolean okEnabled, boolean cancelEnabled, boolean focusOk) { public static void update(final Input input, boolean okEnabled, boolean cancelEnabled, boolean focusOk) {
update(gui, "OK", "Cancel", okEnabled, cancelEnabled, focusOk); update(input, "OK", "Cancel", okEnabled, cancelEnabled, focusOk);
} }
public static void update(final IGuiBase gui, String okLabel, String cancelLabel, boolean okEnabled, boolean cancelEnabled, boolean focusOk) { public static void update(final Input input, String okLabel, String cancelLabel, boolean okEnabled, boolean cancelEnabled, boolean focusOk) {
IButton btnOk = gui.getBtnOK(); IGuiBase gui = input.getGui();
IButton btnCancel = gui.getBtnCancel(); PlayerView owner = input.getOwner();
IButton btnOk = gui.getBtnOK(owner);
IButton btnCancel = gui.getBtnCancel(owner);
btnOk.setText(okLabel); btnOk.setText(okLabel);
btnCancel.setText(cancelLabel); btnCancel.setText(cancelLabel);

View File

@@ -3,9 +3,15 @@ package forge.match.input;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.interfaces.IGuiBase;
import forge.util.ITriggerEvent; import forge.util.ITriggerEvent;
import forge.view.PlayerView;
public interface Input { public interface Input {
PlayerView getOwner();
IGuiBase getGui();
void showMessageInitial(); void showMessageInitial();
boolean selectCard(Card card, ITriggerEvent triggerEvent); boolean selectCard(Card card, ITriggerEvent triggerEvent);

View File

@@ -100,10 +100,10 @@ public class InputAttack extends InputSyncronizedBase {
private void updatePrompt() { private void updatePrompt() {
if (canCallBackAttackers()) { if (canCallBackAttackers()) {
ButtonUtil.update(getGui(), "OK", "Call Back", true, true, true); ButtonUtil.update(this, "OK", "Call Back", true, true, true);
} }
else { else {
ButtonUtil.update(getGui(), "OK", "Alpha Strike", true, true, true); ButtonUtil.update(this, "OK", "Alpha Strike", true, true, true);
} }
} }

View File

@@ -29,6 +29,8 @@ import forge.game.spellability.SpellAbility;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.player.PlayerControllerHuman; import forge.player.PlayerControllerHuman;
import forge.util.ITriggerEvent; import forge.util.ITriggerEvent;
import forge.view.LocalGameView;
import forge.view.PlayerView;
/** /**
* <p> * <p>
@@ -43,14 +45,20 @@ public abstract class InputBase implements java.io.Serializable, Input {
private static final long serialVersionUID = -6539552513871194081L; private static final long serialVersionUID = -6539552513871194081L;
private final PlayerControllerHuman controller; private final PlayerControllerHuman controller;
public InputBase(final PlayerControllerHuman controller) { public InputBase(final PlayerControllerHuman controller0) {
this.controller = controller; controller = controller0;
} }
public final PlayerControllerHuman getController() { public final PlayerControllerHuman getController() {
return this.controller; return controller;
}
public LocalGameView getGameView() {
return controller.getGameView();
}
public PlayerView getOwner() {
return controller.getPlayerView(controller.getPlayer());
} }
public IGuiBase getGui() { public IGuiBase getGui() {
return getController().getGui(); return controller.getGui();
} }
private boolean finished = false; private boolean finished = false;
@@ -59,7 +67,7 @@ public abstract class InputBase implements java.io.Serializable, Input {
finished = true; finished = true;
if (allowAwaitNextInput()) { if (allowAwaitNextInput()) {
awaitNextInput(getGui()); awaitNextInput(this);
} }
} }
@@ -70,18 +78,18 @@ public abstract class InputBase implements java.io.Serializable, Input {
private static final Timer awaitNextInputTimer = new Timer(); private static final Timer awaitNextInputTimer = new Timer();
private static TimerTask awaitNextInputTask; private static TimerTask awaitNextInputTask;
public static void awaitNextInput(final IGuiBase gui) { public static void awaitNextInput(final Input input) {
//delay updating prompt to await next input briefly so buttons don't flicker disabled then enabled //delay updating prompt to await next input briefly so buttons don't flicker disabled then enabled
awaitNextInputTask = new TimerTask() { awaitNextInputTask = new TimerTask() {
@Override @Override
public void run() { public void run() {
FThreads.invokeInEdtLater(gui, new Runnable() { FThreads.invokeInEdtLater(input.getGui(), new Runnable() {
@Override @Override
public void run() { public void run() {
synchronized (awaitNextInputTimer) { synchronized (awaitNextInputTimer) {
if (awaitNextInputTask != null) { if (awaitNextInputTask != null) {
gui.showPromptMessage("Waiting for opponent..."); input.getGui().showPromptMessage(input.getOwner(), "Waiting for opponent...");
ButtonUtil.update(gui, false, false, false); ButtonUtil.update(input, false, false, false);
awaitNextInputTask = null; awaitNextInputTask = null;
} }
} }
@@ -150,7 +158,7 @@ public abstract class InputBase implements java.io.Serializable, Input {
// to remove need for CMatchUI dependence // to remove need for CMatchUI dependence
protected final void showMessage(final String message) { protected final void showMessage(final String message) {
getGui().showPromptMessage(message); getGui().showPromptMessage(getOwner(), message);
} }
protected final void flashIncorrectAction() { protected final void flashIncorrectAction() {

View File

@@ -74,7 +74,7 @@ public class InputBlock extends InputSyncronizedBase {
@Override @Override
protected final void showMessage() { protected final void showMessage() {
// could add "Reset Blockers" button // could add "Reset Blockers" button
ButtonUtil.update(getGui(), true, false, true); ButtonUtil.update(this, true, false, true);
if (currentAttacker == null) { if (currentAttacker == null) {
showMessage("Select another attacker to declare blockers for."); showMessage("Select another attacker to declare blockers for.");

View File

@@ -56,7 +56,7 @@ public class InputConfirm extends InputSyncronizedBase {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
protected final void showMessage() { protected final void showMessage() {
ButtonUtil.update(getGui(), yesButtonText, noButtonText, true, true, defaultYes); ButtonUtil.update(this, yesButtonText, noButtonText, true, true, defaultYes);
showMessage(message); showMessage(message);
} }

View File

@@ -72,11 +72,11 @@ public class InputConfirmMulligan extends InputSyncronizedBase {
} }
if (isCommander) { if (isCommander) {
ButtonUtil.update(getGui(), "Keep", "Exile", true, false, true); ButtonUtil.update(this, "Keep", "Exile", true, false, true);
sb.append("Will you keep your hand or choose some cards to exile those and draw one less card?"); sb.append("Will you keep your hand or choose some cards to exile those and draw one less card?");
} }
else { else {
ButtonUtil.update(getGui(), "Keep", "Mulligan", true, true, true); ButtonUtil.update(this, "Keep", "Mulligan", true, true, true);
sb.append("Do you want to keep your hand?"); sb.append("Do you want to keep your hand?");
} }
@@ -144,7 +144,7 @@ public class InputConfirmMulligan extends InputSyncronizedBase {
getGui().setUsedToPay(getController().getCardView(c0), true); getGui().setUsedToPay(getController().getCardView(c0), true);
selected.add(c0); selected.add(c0);
} }
ButtonUtil.update(getGui(), "Keep", "Exile", true, !selected.isEmpty(), true); ButtonUtil.update(this, "Keep", "Exile", true, !selected.isEmpty(), true);
} }
return true; return true;
} }

View File

@@ -10,22 +10,31 @@ import forge.game.spellability.SpellAbility;
import forge.interfaces.IGuiBase; import forge.interfaces.IGuiBase;
import forge.util.ITriggerEvent; import forge.util.ITriggerEvent;
import forge.util.ThreadUtil; import forge.util.ThreadUtil;
import forge.view.PlayerView;
public class InputLockUI implements Input { public class InputLockUI implements Input {
private final AtomicInteger iCall = new AtomicInteger(); private final AtomicInteger iCall = new AtomicInteger();
private IGuiBase gui; private IGuiBase gui;
private final InputQueue inputQueue;
private final Game game; private final Game game;
public InputLockUI(final Game game, final InputQueue inputQueue) { public InputLockUI(final Game game0, final InputQueue inputQueue0) {
this.game = game; game = game0;
inputQueue = inputQueue0;
} }
private IGuiBase getGui() { @Override
public PlayerView getOwner() {
return null;
}
@Override
public IGuiBase getGui() {
return gui; return gui;
} }
public void setGui(final IGuiBase gui) { public void setGui(final IGuiBase gui0) {
this.gui = gui; gui = gui0;
} }
public void showMessageInitial() { public void showMessageInitial() {
@@ -56,17 +65,17 @@ public class InputLockUI implements Input {
private final Runnable showMessageFromEdt = new Runnable() { private final Runnable showMessageFromEdt = new Runnable() {
@Override @Override
public void run() { public void run() {
ButtonUtil.update(getGui(), "", "", false, false, false); ButtonUtil.update(InputLockUI.this, "", "", false, false, false);
showMessage("Waiting for actions..."); showMessage("Waiting for actions...");
} }
}; };
protected final boolean isActive() { protected final boolean isActive() {
return getGui().getInputQueue().getInput() == this; return inputQueue.getInput() == this;
} }
protected void showMessage(String message) { protected void showMessage(String message) {
getGui().showPromptMessage(message); getGui().showPromptMessage(getOwner(), message);
} }
@Override @Override

View File

@@ -0,0 +1,54 @@
package forge.match.input;
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility;
import forge.interfaces.IGuiBase;
import forge.util.ITriggerEvent;
import forge.view.LocalGameView;
import forge.view.PlayerView;
public class InputNone implements Input {
private final IGuiBase gui;
private final PlayerView owner;
public InputNone(LocalGameView gameView) {
gui = gameView.getGui();
owner = gameView.getLocalPlayerView();
}
@Override
public IGuiBase getGui() {
return gui;
}
@Override
public PlayerView getOwner() {
return owner;
}
@Override
public void showMessageInitial() {
}
@Override
public boolean selectCard(Card card, ITriggerEvent triggerEvent) {
return false;
}
@Override
public void selectAbility(SpellAbility ab) {
}
@Override
public void selectPlayer(Player player, ITriggerEvent triggerEvent) {
}
@Override
public void selectButtonOK() {
}
@Override
public void selectButtonCancel() {
}
}

View File

@@ -57,10 +57,10 @@ public class InputPassPriority extends InputSyncronizedBase {
showMessage(getTurnPhasePriorityMessage(player.getGame())); showMessage(getTurnPhasePriorityMessage(player.getGame()));
chosenSa = null; chosenSa = null;
if (getController().canUndoLastAction()) { //allow undoing with cancel button if can undo last action if (getController().canUndoLastAction()) { //allow undoing with cancel button if can undo last action
ButtonUtil.update(getGui(), "OK", "Undo", true, true, true); ButtonUtil.update(this, "OK", "Undo", true, true, true);
} }
else { //otherwise allow ending turn with cancel button else { //otherwise allow ending turn with cancel button
ButtonUtil.update(getGui(), "OK", "End Turn", true, true, true); ButtonUtil.update(this, "OK", "End Turn", true, true, true);
} }
} }

View File

@@ -371,10 +371,10 @@ public abstract class InputPayMana extends InputSyncronizedBase {
protected void updateButtons() { protected void updateButtons() {
if (supportAutoPay()) { if (supportAutoPay()) {
ButtonUtil.update(getGui(), "Auto", "Cancel", false, true, false); ButtonUtil.update(this, "Auto", "Cancel", false, true, false);
} }
else { else {
ButtonUtil.update(getGui(), "", "Cancel", false, true, false); ButtonUtil.update(this, "", "Cancel", false, true, false);
} }
} }
@@ -393,7 +393,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
canPayManaCost = proc.getResult(); canPayManaCost = proc.getResult();
} }
if (canPayManaCost) { //enabled Auto button if mana cost can be paid if (canPayManaCost) { //enabled Auto button if mana cost can be paid
ButtonUtil.update(getGui(), "Auto", "Cancel", true, true, true); ButtonUtil.update(this, "Auto", "Cancel", true, true, true);
} }
} }
showMessage(getMessage()); showMessage(getMessage());

View File

@@ -55,10 +55,10 @@ public class InputPlaybackControl extends InputSyncronizedBase implements InputS
private void setPause(boolean pause) { private void setPause(boolean pause) {
isPaused = pause; isPaused = pause;
if (isPaused) { if (isPaused) {
ButtonUtil.update(getGui(), "Resume", "Step", true, true, true); ButtonUtil.update(this, "Resume", "Step", true, true, true);
} }
else { else {
ButtonUtil.update(getGui(), "Pause", isFast ? "1x Speed" : "10x Faster", true, true, true); ButtonUtil.update(this, "Pause", isFast ? "1x Speed" : "10x Faster", true, true, true);
} }
} }

View File

@@ -46,11 +46,11 @@ public class InputProxy implements Observer {
// private static final boolean DEBUG_INPUT = true; // false; // private static final boolean DEBUG_INPUT = true; // false;
public InputProxy(final LocalGameView gameView0) { public InputProxy(final LocalGameView gameView0) {
this.gameView = gameView0; gameView = gameView0;
} }
private IGuiBase getGui() { private IGuiBase getGui() {
return this.gameView.getGui(); return gameView.getGui();
} }
@Override @Override
@@ -61,11 +61,11 @@ public class InputProxy implements Observer {
FThreads.debugGetStackTraceItem(6, true), nextInput == null ? "null" : nextInput.getClass().getSimpleName(), FThreads.debugGetStackTraceItem(6, true), nextInput == null ? "null" : nextInput.getClass().getSimpleName(),
game.getPhaseHandler().debugPrintState(), Singletons.getControl().getInputQueue().printInputStack()); game.getPhaseHandler().debugPrintState(), Singletons.getControl().getInputQueue().printInputStack());
*/ */
this.input.set(nextInput); input.set(nextInput);
Runnable showMessage = new Runnable() { Runnable showMessage = new Runnable() {
@Override public void run() { @Override public void run() {
Input current = getInput(); Input current = getInput();
getGui().getInputQueue().syncPoint(); gameView.getInputQueue().syncPoint();
//System.out.printf("\t%s > showMessage @ %s/%s during %s%n", FThreads.debugGetCurrThreadId(), nextInput.getClass().getSimpleName(), current.getClass().getSimpleName(), game.getPhaseHandler().debugPrintState()); //System.out.printf("\t%s > showMessage @ %s/%s during %s%n", FThreads.debugGetCurrThreadId(), nextInput.getClass().getSimpleName(), current.getClass().getSimpleName(), game.getPhaseHandler().debugPrintState());
current.showMessageInitial(); current.showMessageInitial();
} }
@@ -152,6 +152,6 @@ public class InputProxy implements Observer {
/** @return {@link forge.gui.InputProxy.InputBase} */ /** @return {@link forge.gui.InputProxy.InputBase} */
public Input getInput() { public Input getInput() {
return this.input.get(); return input.get();
} }
} }

View File

@@ -33,6 +33,12 @@ import forge.view.IGameView;
* @version $Id: InputQueue.java 24769 2014-02-09 13:56:04Z Hellfish $ * @version $Id: InputQueue.java 24769 2014-02-09 13:56:04Z Hellfish $
*/ */
public class InputQueue extends Observable { public class InputQueue extends Observable {
private static InputSynchronized activeInput;
public static InputSynchronized getActiveInput() {
return activeInput;
}
private final BlockingDeque<InputSynchronized> inputStack = new LinkedBlockingDeque<InputSynchronized>(); private final BlockingDeque<InputSynchronized> inputStack = new LinkedBlockingDeque<InputSynchronized>();
private final InputLockUI inputLock; private final InputLockUI inputLock;
@@ -56,6 +62,9 @@ public class InputQueue extends Observable {
if (topMostInput != inp) { if (topMostInput != inp) {
throw new RuntimeException("Cannot remove input " + inp.getClass().getSimpleName() + " because it's not on top of stack. Stack = " + inputStack ); throw new RuntimeException("Cannot remove input " + inp.getClass().getSimpleName() + " because it's not on top of stack. Stack = " + inputStack );
} }
if (inp == activeInput) {
activeInput = null;
}
updateObservers(); updateObservers();
} }
@@ -80,6 +89,7 @@ public class InputQueue extends Observable {
} }
public void setInput(final InputSynchronized input) { public void setInput(final InputSynchronized input) {
activeInput = input;
inputStack.push(input); inputStack.push(input);
inputLock.setGui(input.getGui()); inputLock.setGui(input.getGui());
syncPoint(); syncPoint();

View File

@@ -44,7 +44,7 @@ public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyn
@Override @Override
public final void showMessage() { public final void showMessage() {
showMessage(getMessage()); showMessage(getMessage());
ButtonUtil.update(getGui(), hasEnoughTargets(), allowCancel, true); ButtonUtil.update(this, hasEnoughTargets(), allowCancel, true);
} }
@Override @Override

View File

@@ -78,19 +78,19 @@ public final class InputSelectTargets extends InputSyncronizedBase {
if (!tgt.isMinTargetsChosen(sa.getHostCard(), sa) || tgt.isDividedAsYouChoose()) { if (!tgt.isMinTargetsChosen(sa.getHostCard(), sa) || tgt.isDividedAsYouChoose()) {
if (mandatory && tgt.hasCandidates(sa, true)) { if (mandatory && tgt.hasCandidates(sa, true)) {
// Player has to click on a target // Player has to click on a target
ButtonUtil.update(getGui(), false, false, false); ButtonUtil.update(this, false, false, false);
} }
else { else {
ButtonUtil.update(getGui(), false, true, false); ButtonUtil.update(this, false, true, false);
} }
} }
else { else {
if (mandatory && tgt.hasCandidates(sa, true)) { if (mandatory && tgt.hasCandidates(sa, true)) {
// Player has to click on a target or ok // Player has to click on a target or ok
ButtonUtil.update(getGui(), true, false, true); ButtonUtil.update(this, true, false, true);
} }
else { else {
ButtonUtil.update(getGui(), true, true, true); ButtonUtil.update(this, true, true, true);
} }
} }
} }

View File

@@ -30,7 +30,7 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
} }
public void showAndWait() { public void showAndWait() {
getGui().getInputQueue().setInput(this); getGameView().getInputQueue().setInput(this);
awaitLatchRelease(); awaitLatchRelease();
} }
@@ -46,7 +46,7 @@ public abstract class InputSyncronizedBase extends InputBase implements InputSyn
}); });
// thread irrelevant // thread irrelevant
getGui().getInputQueue().removeInput(InputSyncronizedBase.this); getGameView().getInputQueue().removeInput(InputSyncronizedBase.this);
cdlDone.countDown(); cdlDone.countDown();
} }

View File

@@ -18,13 +18,17 @@ public class LobbyPlayerHuman extends LobbyPlayer implements IGameEntitiesFactor
@Override @Override
public PlayerController createControllerFor(Player human) { public PlayerController createControllerFor(Player human) {
return new PlayerControllerHuman(human.getGame(), human, this, gui); PlayerControllerHuman controller = new PlayerControllerHuman(human.getGame(), human, this, gui);
controller.getGameView().setLocalPlayer(human);
return controller;
} }
@Override @Override
public Player createIngamePlayer(Game game, final int id) { public Player createIngamePlayer(Game game, final int id) {
Player player = new Player(GuiDisplayUtil.personalizeHuman(getName()), game, id); Player player = new Player(GuiDisplayUtil.personalizeHuman(getName()), game, id);
player.setFirstController(new PlayerControllerHuman(game, player, this, gui)); PlayerControllerHuman controller = new PlayerControllerHuman(game, player, this, gui);
player.setFirstController(controller);
controller.getGameView().setLocalPlayer(player);
return player; return player;
} }

View File

@@ -89,6 +89,7 @@ import forge.match.input.InputBase;
import forge.match.input.InputBlock; import forge.match.input.InputBlock;
import forge.match.input.InputConfirm; import forge.match.input.InputConfirm;
import forge.match.input.InputConfirmMulligan; import forge.match.input.InputConfirmMulligan;
import forge.match.input.InputNone;
import forge.match.input.InputPassPriority; import forge.match.input.InputPassPriority;
import forge.match.input.InputPayMana; import forge.match.input.InputPayMana;
import forge.match.input.InputProliferate; import forge.match.input.InputProliferate;
@@ -129,7 +130,7 @@ public class PlayerControllerHuman extends PlayerController {
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);
this.gameView = new GameView(game0, gui); this.gameView = new GameView(gui, game0);
// aggressively cache a view for each player (also caches cards) // aggressively cache a view for each player (also caches cards)
for (final Player player : game.getRegisteredPlayers()) { for (final Player player : game.getRegisteredPlayers()) {
@@ -796,9 +797,10 @@ public class PlayerControllerHuman extends PlayerController {
//allow user to cancel auto-pass //allow user to cancel auto-pass
InputBase.cancelAwaitNextInput(); //don't overwrite prompt with awaiting opponent InputBase.cancelAwaitNextInput(); //don't overwrite prompt with awaiting opponent
PhaseType phase = getAutoPassUntilPhase(); PhaseType phase = getAutoPassUntilPhase();
getGui().showPromptMessage("Yielding until " + (phase == PhaseType.CLEANUP ? "end of turn" : phase.nameForUi.toString()) + InputNone inputNone = new InputNone(gameView);
getGui().showPromptMessage(inputNone.getOwner(), "Yielding until " + (phase == PhaseType.CLEANUP ? "end of turn" : phase.nameForUi.toString()) +
".\nYou may cancel this yield to take an action."); ".\nYou may cancel this yield to take an action.");
ButtonUtil.update(getGui(), false, true, false); ButtonUtil.update(inputNone, false, true, false);
} }
} }
@@ -814,9 +816,10 @@ public class PlayerControllerHuman extends PlayerController {
super.autoPassCancel(); super.autoPassCancel();
//prevent prompt getting stuck on yielding message while actually waiting for next input opportunity //prevent prompt getting stuck on yielding message while actually waiting for next input opportunity
getGui().showPromptMessage(""); InputNone inputNone = new InputNone(gameView);
ButtonUtil.update(getGui(), false, false, false); getGui().showPromptMessage(inputNone.getOwner(), "");
InputBase.awaitNextInput(getGui()); ButtonUtil.update(inputNone, false, false, false);
InputBase.awaitNextInput(inputNone);
} }
@Override @Override
@@ -1330,8 +1333,8 @@ public class PlayerControllerHuman extends PlayerController {
* What follows are the View methods. * What follows are the View methods.
*/ */
private class GameView extends LocalGameView { private class GameView extends LocalGameView {
public GameView(Game game0, IGuiBase gui0) { public GameView(IGuiBase gui0, Game game0) {
super(game0, gui0); super(gui0, game0);
} }
@Override @Override
@@ -1363,7 +1366,7 @@ public class PlayerControllerHuman extends PlayerController {
} }
if (game.getStack().undo()) { if (game.getStack().undo()) {
final Input currentInput = getGui().getInputQueue().getInput(); final Input currentInput = inputQueue.getInput();
if (currentInput instanceof InputPassPriority) { if (currentInput instanceof InputPassPriority) {
currentInput.showMessageInitial(); //ensure prompt updated if needed currentInput.showMessageInitial(); //ensure prompt updated if needed
} }
@@ -1384,7 +1387,7 @@ public class PlayerControllerHuman extends PlayerController {
@Override @Override
public void confirm() { public void confirm() {
if (getGui().getInputQueue().getInput() instanceof InputConfirm) { if (inputQueue.getInput() instanceof InputConfirm) {
selectButtonOk(); selectButtonOk();
} }
} }
@@ -1418,7 +1421,7 @@ public class PlayerControllerHuman extends PlayerController {
@Override @Override
public void useMana(final byte mana) { public void useMana(final byte mana) {
final Input input = getGui().getInputQueue().getInput(); final Input input = inputQueue.getInput();
if (input instanceof InputPayMana) { if (input instanceof InputPayMana) {
((InputPayMana) input).useManaFromPool(mana); ((InputPayMana) input).useManaFromPool(mana);
} }
@@ -1587,11 +1590,9 @@ public class PlayerControllerHuman extends PlayerController {
return gameView.getPlayerViews(players); return gameView.getPlayerViews(players);
} }
/** public PlayerView getPlayerView() {
* @param p return gameView.getPlayerView(getPlayer());
* @return }
* @see forge.view.LocalGameView#getPlayerView(forge.game.player.Player)
*/
public PlayerView getPlayerView(Player p) { public PlayerView getPlayerView(Player p) {
return gameView.getPlayerView(p); return gameView.getPlayerView(p);
} }
@@ -2003,7 +2004,7 @@ public class PlayerControllerHuman extends PlayerController {
} }
public void winGame() { public void winGame() {
Input input = getGui().getInputQueue().getInput(); Input input = gameView.getInputQueue().getInput();
if (!(input instanceof InputPassPriority)) { if (!(input instanceof InputPassPriority)) {
SOptionPane.showMessageDialog(getGui(), "You must have priority to use this feature.", "Win Game", SOptionPane.INFORMATION_ICON); SOptionPane.showMessageDialog(getGui(), "You must have priority to use this feature.", "Win Game", SOptionPane.INFORMATION_ICON);
return; return;

View File

@@ -36,8 +36,9 @@ public abstract class LocalGameView implements IGameView {
protected final IGuiBase gui; protected final IGuiBase gui;
protected final InputQueue inputQueue; protected final InputQueue inputQueue;
protected final InputProxy inputProxy; protected final InputProxy inputProxy;
private PlayerView localPlayerView;
public LocalGameView(Game game0, IGuiBase gui0) { public LocalGameView(IGuiBase gui0, Game game0) {
game = game0; game = game0;
gui = gui0; gui = gui0;
inputProxy = new InputProxy(this); inputProxy = new InputProxy(this);
@@ -60,6 +61,14 @@ public abstract class LocalGameView implements IGameView {
return inputProxy; return inputProxy;
} }
public PlayerView getLocalPlayerView() {
return localPlayerView;
}
public void setLocalPlayer(Player localPlayer) {
localPlayerView = getPlayerView(localPlayer);
}
/** Cache of players. */ /** Cache of players. */
private final Cache<Player, PlayerView> players = new Cache<>(); private final Cache<Player, PlayerView> players = new Cache<>();
/** Cache of cards. */ /** Cache of cards. */

View File

@@ -24,8 +24,8 @@ public class WatchLocalGame extends LocalGameView {
* the {@link InputQueue} of the game to enable playback * the {@link InputQueue} of the game to enable playback
* controls, or {@code null} to disallow them. * controls, or {@code null} to disallow them.
*/ */
public WatchLocalGame(Game game0, IGuiBase gui0) { public WatchLocalGame(IGuiBase gui0, Game game0) {
super(game0, gui0); super(gui0, game0);
} }
@Override @Override
@@ -158,5 +158,4 @@ public class WatchLocalGame extends LocalGameView {
public DevModeCheats cheat() { public DevModeCheats cheat() {
return null; return null;
} }
} }