mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
Prevent stuff getting out of sync
This commit is contained in:
@@ -616,7 +616,7 @@ public enum CMatchUI implements ICDoc, IMenuProvider, IMatchController {
|
||||
public void openView(List<Player> sortedPlayers) {
|
||||
List<PlayerView> sortedPlayerViews = new ArrayList<PlayerView>();
|
||||
for (Player p : sortedPlayers) {
|
||||
sortedPlayerViews.add(MatchUtil.getGameView().getPlayerView(p));
|
||||
sortedPlayerViews.add(MatchUtil.getGameView().getPlayerView(p, false));
|
||||
}
|
||||
CMatchUI.SINGLETON_INSTANCE.initMatch(sortedPlayerViews, MatchUtil.getHumanCount() != 1);
|
||||
|
||||
|
||||
@@ -181,7 +181,7 @@ public enum VStack implements IVDoc<CStack> {
|
||||
public StackInstanceTextArea(final LocalGameView gameView, final StackItemView item) {
|
||||
sourceCard = item.getSource();
|
||||
|
||||
final PlayerView localPlayer = gameView.getPlayerView(MatchUtil.getCurrentPlayer());
|
||||
final PlayerView localPlayer = gameView.getPlayerView(MatchUtil.getCurrentPlayer(), false);
|
||||
final String txt = (item.isOptionalTrigger() && item.getActivatingPlayer().equals(localPlayer)
|
||||
? "(OPTIONAL) " : "") + item.getText();
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ public class MatchController implements IMatchController {
|
||||
boolean noHumans = MatchUtil.getHumanCount() == 0;
|
||||
List<VPlayerPanel> playerPanels = new ArrayList<VPlayerPanel>();
|
||||
for (Player p : sortedPlayers) {
|
||||
playerPanels.add(new VPlayerPanel(MatchUtil.getGameView(p).getPlayerView(p), noHumans || p.getController() instanceof PlayerControllerHuman));
|
||||
playerPanels.add(new VPlayerPanel(MatchUtil.getGameView(p).getPlayerView(p, false), noHumans || p.getController() instanceof PlayerControllerHuman));
|
||||
}
|
||||
view = new MatchScreen(playerPanels);
|
||||
|
||||
|
||||
@@ -256,7 +256,7 @@ public class VStack extends FDropDown {
|
||||
@Override
|
||||
protected void buildMenu() {
|
||||
final LocalGameView gameView = MatchUtil.getGameView();
|
||||
final PlayerView playerView = gameView.getPlayerView(player);
|
||||
final PlayerView playerView = gameView.getPlayerView(player, false);
|
||||
final String key = stackInstance.getKey();
|
||||
final boolean autoYield = gameView.shouldAutoYield(key);
|
||||
addItem(new FCheckBoxMenuItem("Auto-Yield", autoYield,
|
||||
|
||||
@@ -79,6 +79,12 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
|
||||
public FControlGameEventHandler(final LocalGameView gameView0) {
|
||||
gameView = gameView0;
|
||||
|
||||
// aggressively cache a view for each player (also caches cards)
|
||||
for (Player player : gameView.getGame().getRegisteredPlayers()) {
|
||||
gameView.getPlayerView(player, true);
|
||||
}
|
||||
|
||||
processEventsTimer = GuiBase.getInterface().createGuiTimer(processEvents, BASE_TIMER_INTERVAL);
|
||||
processEventsTimer.start(); //start event processing loop
|
||||
}
|
||||
@@ -90,26 +96,25 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
if (eventReceived) {
|
||||
eventReceived = false;
|
||||
|
||||
gameView.startUpdate();
|
||||
IMatchController controller = MatchUtil.getController();
|
||||
if (!cardsUpdate.isEmpty()) {
|
||||
MatchUtil.updateCards(gameView.getCardViews(cardsUpdate));
|
||||
MatchUtil.updateCards(gameView.getCardViews(cardsUpdate, true));
|
||||
cardsUpdate.clear();
|
||||
}
|
||||
if (!cardsRefreshDetails.isEmpty()) {
|
||||
controller.refreshCardDetails(gameView.getCardViews(cardsRefreshDetails));
|
||||
controller.refreshCardDetails(gameView.getCardViews(cardsRefreshDetails, true));
|
||||
cardsRefreshDetails.clear();
|
||||
}
|
||||
if (!livesUpdate.isEmpty()) {
|
||||
controller.updateLives(gameView.getPlayerViews(livesUpdate));
|
||||
controller.updateLives(gameView.getPlayerViews(livesUpdate, true));
|
||||
livesUpdate.clear();
|
||||
}
|
||||
if (!manaPoolUpdate.isEmpty()) {
|
||||
controller.updateManaPool(gameView.getPlayerViews(manaPoolUpdate));
|
||||
controller.updateManaPool(gameView.getPlayerViews(manaPoolUpdate, true));
|
||||
manaPoolUpdate.clear();
|
||||
}
|
||||
if (!zonesUpdate.isEmpty()) {
|
||||
List<PlayerView> players = gameView.getPlayers();
|
||||
List<PlayerView> players = gameView.getPlayers(true);
|
||||
ArrayList<Pair<PlayerView, ZoneType>> zones = new ArrayList<Pair<PlayerView, ZoneType>>();
|
||||
for (String z : zonesUpdate) {
|
||||
int idx = z.indexOf(PLAYER_ZONE_DELIM);
|
||||
@@ -119,7 +124,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
zonesUpdate.clear();
|
||||
}
|
||||
if (turnUpdate != null) {
|
||||
controller.updateTurn(gameView.getPlayerView(turnUpdate));
|
||||
controller.updateTurn(gameView.getPlayerView(turnUpdate, true));
|
||||
turnUpdate = null;
|
||||
}
|
||||
if (needPhaseUpdate) {
|
||||
@@ -153,7 +158,6 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
gameView.updateAchievements();
|
||||
processEventsTimer.stop();
|
||||
}
|
||||
gameView.endUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -197,7 +201,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
final CardView fakeCard = new CardView(-1); //use fake card so real cards appear with proper formatting
|
||||
fakeCard.getOriginal().setName(" -- From " + Lang.getPossesive(kv.getKey().getName()) + " deck --");
|
||||
options.add(fakeCard);
|
||||
options.add(gameView.getCardView(kv.getValue()));
|
||||
options.add(gameView.getCardView(kv.getValue(), true));
|
||||
}
|
||||
SGuiChoose.reveal(gameView.getGui(), "These cards were chosen to ante", options);
|
||||
return null;
|
||||
|
||||
@@ -78,7 +78,7 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
||||
@Override
|
||||
public Void visit(GameEventTurnPhase ev) {
|
||||
boolean isUiToStop = MatchUtil.getController().stopAtPhase(
|
||||
gameView.getPlayerView(ev.playerTurn), ev.phase);
|
||||
gameView.getPlayerView(ev.playerTurn, true), ev.phase);
|
||||
|
||||
switch(ev.phase) {
|
||||
case COMBAT_END:
|
||||
@@ -124,7 +124,7 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
||||
FThreads.invokeInEdtNowOrLater(gui, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gui.setCard(gameView.getCardView(event.spell.getHostCard()));
|
||||
gui.setCard(gameView.getCardView(event.spell.getHostCard(), true));
|
||||
}
|
||||
});
|
||||
pauseForEvent(resolveDelay);
|
||||
@@ -139,7 +139,7 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
||||
FThreads.invokeInEdtNowOrLater(gui, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gui.setCard(gameView.getCardView(event.sa.getHostCard()));
|
||||
gui.setCard(gameView.getCardView(event.sa.getHostCard(), true));
|
||||
}
|
||||
});
|
||||
pauseForEvent(castDelay);
|
||||
|
||||
@@ -213,7 +213,7 @@ public class MatchUtil {
|
||||
|
||||
//ensure opponents set properly
|
||||
for (PlayerView pv : gameViews.get(0).getPlayers()) {
|
||||
pv.setOpponents(gameViews.get(0).getPlayerViews(players.getKey(pv.getId()).getOpponents()));
|
||||
pv.setOpponents(gameViews.get(0).getPlayerViews(players.getKey(pv.getId()).getOpponents(), false));
|
||||
}
|
||||
|
||||
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
|
||||
|
||||
@@ -942,14 +942,15 @@ public class HumanCostDecision extends CostDecisionMakerBase {
|
||||
inp.setMessage("Remove %d " + cost.counter.getName() + " counters from " + cost.getDescriptiveType());
|
||||
inp.setCancelAllowed(true);
|
||||
inp.showAndWait();
|
||||
if(inp.hasCancelled())
|
||||
if (inp.hasCancelled()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Have to hack here: remove all counters minus one, without firing any triggers,
|
||||
// triggers will fire when last is removed by executePayment.
|
||||
// They don't care how many were removed anyway
|
||||
// int sum = 0;
|
||||
for(Card crd : inp.getSelected()) {
|
||||
for (Card crd : inp.getSelected()) {
|
||||
int removed = inp.getTimesSelected(crd);
|
||||
// sum += removed;
|
||||
if(removed < 2) continue;
|
||||
@@ -961,9 +962,11 @@ public class HumanCostDecision extends CostDecisionMakerBase {
|
||||
|
||||
// Rift Elemental only - always removes 1 counter, so there will be no code for N counters.
|
||||
List<CardView> suspended = Lists.newArrayList();
|
||||
for (final Card crd : validCards)
|
||||
if (crd.getCounters( cost.counter) > 0)
|
||||
for (final Card crd : validCards) {
|
||||
if (crd.getCounters(cost.counter) > 0) {
|
||||
suspended.add(controller.getCardView(crd));
|
||||
}
|
||||
}
|
||||
|
||||
final CardView view = SGuiChoose.oneOrNone(getGui(), "Remove counter(s) from a card in " + cost.zone, suspended);
|
||||
final Card card = controller.getCard(view);
|
||||
|
||||
@@ -127,11 +127,6 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
super(game0, p, lp);
|
||||
if (p.getController() == null || p.getLobbyPlayer() == lp) {
|
||||
gameView = new GameView(gui, game0);
|
||||
|
||||
// aggressively cache a view for each player (also caches cards)
|
||||
for (final Player player : game.getRegisteredPlayers()) {
|
||||
gameView.getPlayerView(player);
|
||||
}
|
||||
}
|
||||
else { //handle the case of one player controlling another
|
||||
for (Player p0 : game.getPlayers()) {
|
||||
@@ -195,7 +190,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
}
|
||||
|
||||
public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) {
|
||||
return !MatchUtil.getController().stopAtPhase(gameView.getPlayerView(turn), phase);
|
||||
return !MatchUtil.getController().stopAtPhase(getPlayerView(turn), phase);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -280,10 +275,10 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (defender != null && assignDamageAsIfNotBlocked(attacker)) {
|
||||
map.put(null, damageDealt);
|
||||
} else {
|
||||
final List<CardView> vBlockers = gameView.getCardViews(blockers);
|
||||
final List<CardView> vBlockers = getCardViews(blockers);
|
||||
if ((attacker.hasKeyword("Trample") && defender != null) || (blockers.size() > 1)) {
|
||||
final CardView vAttacker = gameView.getCardView(attacker);
|
||||
final GameEntityView vDefender = gameView.getGameEntityView(defender);
|
||||
final CardView vAttacker = getCardView(attacker);
|
||||
final GameEntityView vDefender = getGameEntityView(defender);
|
||||
final Map<CardView, Integer> result = MatchUtil.getDamageToAssign(vAttacker, vBlockers, damageDealt, vDefender, overrideOrder);
|
||||
for (final Entry<CardView, Integer> e : result.entrySet()) {
|
||||
map.put(gameView.getCard(e.getKey()), e.getValue());
|
||||
@@ -298,7 +293,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
private final boolean assignDamageAsIfNotBlocked(final Card attacker) {
|
||||
return attacker.hasKeyword("CARDNAME assigns its combat damage as though it weren't blocked.")
|
||||
|| (attacker.hasKeyword("You may have CARDNAME assign its combat damage as though it weren't blocked.")
|
||||
&& SGuiDialog.confirm(getGui(), gameView.getCardView(attacker), "Do you want to assign its combat damage as though it weren't blocked?"));
|
||||
&& SGuiDialog.confirm(getGui(), getCardView(attacker), "Do you want to assign its combat damage as though it weren't blocked?"));
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -354,7 +349,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
return singleChosen == null ? Lists.<Card>newArrayList() : Lists.newArrayList(singleChosen);
|
||||
}
|
||||
|
||||
MatchUtil.getController().setPanelSelection(gameView.getCardView(sa.getHostCard()));
|
||||
MatchUtil.getController().setPanelSelection(getCardView(sa.getHostCard()));
|
||||
|
||||
// try to use InputSelectCardsFromList when possible
|
||||
boolean cardsAreInMyHandOrBattlefield = true;
|
||||
@@ -376,7 +371,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
}
|
||||
|
||||
tempShowCards(sourceList);
|
||||
final List<CardView> choices = SGuiChoose.many(getGui(), title, "Chosen Cards", min, max, gameView.getCardViews(sourceList), gameView.getCardView(sa.getHostCard()));
|
||||
final List<CardView> choices = SGuiChoose.many(getGui(), title, "Chosen Cards", min, max, getCardViews(sourceList), getCardView(sa.getHostCard()));
|
||||
endTempShowCards();
|
||||
|
||||
return getCards(choices);
|
||||
@@ -421,7 +416,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
tempShowCard((Card) t);
|
||||
}
|
||||
}
|
||||
final GameEntityView result = isOptional ? SGuiChoose.oneOrNone(getGui(), title, gameView.getGameEntityViews((Iterable<GameEntity>) options)) : SGuiChoose.one(getGui(), title, gameView.getGameEntityViews((Iterable<GameEntity>) options));
|
||||
final GameEntityView result = isOptional ? SGuiChoose.oneOrNone(getGui(), title, gameView.getGameEntityViews((Iterable<GameEntity>) options, false)) : SGuiChoose.one(getGui(), title, gameView.getGameEntityViews((Iterable<GameEntity>) options, false));
|
||||
endTempShowCards();
|
||||
return (T) gameView.getGameEntity(result);
|
||||
}
|
||||
@@ -456,18 +451,18 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
*/
|
||||
@Override
|
||||
public boolean confirmAction(SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||
return SGuiDialog.confirm(getGui(), gameView.getCardView(sa.getHostCard()), message);
|
||||
return SGuiDialog.confirm(getGui(), getCardView(sa.getHostCard()), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean confirmBidAction(SpellAbility sa, PlayerActionConfirmMode bidlife,
|
||||
String string, int bid, Player winner) {
|
||||
return SGuiDialog.confirm(getGui(), gameView.getCardView(sa.getHostCard()), string + " Highest Bidder " + winner);
|
||||
return SGuiDialog.confirm(getGui(), getCardView(sa.getHostCard()), string + " Highest Bidder " + winner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean confirmStaticApplication(Card hostCard, GameEntity affected, String logic, String message) {
|
||||
return SGuiDialog.confirm(getGui(), gameView.getCardView(hostCard), message);
|
||||
return SGuiDialog.confirm(getGui(), getCardView(hostCard), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -525,25 +520,25 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
|
||||
@Override
|
||||
public List<Card> orderBlockers(final Card attacker, final List<Card> blockers) {
|
||||
final CardView vAttacker = gameView.getCardView(attacker);
|
||||
final CardView vAttacker = getCardView(attacker);
|
||||
MatchUtil.getController().setPanelSelection(vAttacker);
|
||||
final List<CardView> choices = SGuiChoose.order(getGui(), "Choose Damage Order for " + vAttacker, "Damaged First", gameView.getCardViews(blockers), vAttacker);
|
||||
final List<CardView> choices = SGuiChoose.order(getGui(), "Choose Damage Order for " + vAttacker, "Damaged First", getCardViews(blockers), vAttacker);
|
||||
return gameView.getCards(choices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Card> orderBlocker(final Card attacker, final Card blocker, final List<Card> oldBlockers) {
|
||||
final CardView vAttacker = gameView.getCardView(attacker);
|
||||
final CardView vAttacker = getCardView(attacker);
|
||||
MatchUtil.getController().setPanelSelection(vAttacker);
|
||||
final List<CardView> choices = SGuiChoose.insertInList(getGui(), "Choose blocker after which to place " + vAttacker + " in damage order; cancel to place it first", gameView.getCardView(blocker), gameView.getCardViews(oldBlockers));
|
||||
final List<CardView> choices = SGuiChoose.insertInList(getGui(), "Choose blocker after which to place " + vAttacker + " in damage order; cancel to place it first", getCardView(blocker), getCardViews(oldBlockers));
|
||||
return gameView.getCards(choices);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Card> orderAttackers(final Card blocker, final List<Card> attackers) {
|
||||
final CardView vBlocker = gameView.getCardView(blocker);
|
||||
final CardView vBlocker = getCardView(blocker);
|
||||
MatchUtil.getController().setPanelSelection(vBlocker);
|
||||
final List<CardView> choices = SGuiChoose.order(getGui(), "Choose Damage Order for " + vBlocker, "Damaged First", gameView.getCardViews(attackers), vBlocker);
|
||||
final List<CardView> choices = SGuiChoose.order(getGui(), "Choose Damage Order for " + vBlocker, "Damaged First", getCardViews(attackers), vBlocker);
|
||||
return gameView.getCards(choices);
|
||||
}
|
||||
|
||||
@@ -561,7 +556,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
String fm = formatMessage(message, owner);
|
||||
if (!cards.isEmpty()) {
|
||||
tempShowCards(cards);
|
||||
SGuiChoose.reveal(getGui(), fm, gameView.getCardViews(cards));
|
||||
SGuiChoose.reveal(getGui(), fm, getCardViews(cards));
|
||||
endTempShowCards();
|
||||
}
|
||||
else {
|
||||
@@ -585,7 +580,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
}
|
||||
}
|
||||
else {
|
||||
final List<CardView> toBottomViews = SGuiChoose.many(getGui(), "Select cards to be put on the bottom of your library", "Cards to put on the bottom", -1, gameView.getCardViews(topN), null);
|
||||
final List<CardView> toBottomViews = SGuiChoose.many(getGui(), "Select cards to be put on the bottom of your library", "Cards to put on the bottom", -1, getCardViews(topN), null);
|
||||
toBottom = gameView.getCards(toBottomViews);
|
||||
topN.removeAll(toBottom);
|
||||
if (topN.isEmpty()) {
|
||||
@@ -595,7 +590,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
toTop = topN;
|
||||
}
|
||||
else {
|
||||
final List<CardView> toTopViews = SGuiChoose.order(getGui(), "Arrange cards to be put on top of your library", "Cards arranged", gameView.getCardViews(topN), null);
|
||||
final List<CardView> toTopViews = SGuiChoose.order(getGui(), "Arrange cards to be put on top of your library", "Cards arranged", getCardViews(topN), null);
|
||||
toTop = gameView.getCards(toTopViews);
|
||||
}
|
||||
}
|
||||
@@ -607,7 +602,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
public boolean willPutCardOnTop(final Card c) {
|
||||
final PaperCard pc = FModel.getMagicDb().getCommonCards().getCard(c.getName());
|
||||
final Card c1 = (pc != null ? Card.fromPaperCard(pc, null) : c);
|
||||
final CardView view = gameView.getCardView(c1);
|
||||
final CardView view = getCardView(c1);
|
||||
return SGuiDialog.confirm(getGui(), view, "Put " + view + " on the top or bottom of your library?", new String[]{"Top", "Bottom"});
|
||||
}
|
||||
|
||||
@@ -648,7 +643,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (p != player) {
|
||||
tempShowCards(valid);
|
||||
final List<CardView> choices = SGuiChoose.many(getGui(), "Choose " + min + " card" + (min != 1 ? "s" : "") + " to discard",
|
||||
"Discarded", min, min, gameView.getCardViews(valid), null);
|
||||
"Discarded", min, min, getCardViews(valid), null);
|
||||
endTempShowCards();
|
||||
return getCards(choices);
|
||||
}
|
||||
@@ -661,7 +656,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
|
||||
@Override
|
||||
public void playMiracle(final SpellAbility miracle, final Card card) {
|
||||
final CardView view = gameView.getCardView(card);
|
||||
final CardView view = getCardView(card);
|
||||
if (SGuiDialog.confirm(getGui(), view, view + " - Drawn. Play for Miracle Cost?")) {
|
||||
HumanPlay.playSpellAbility(this, player, miracle);
|
||||
}
|
||||
@@ -680,7 +675,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
System.out.println("Delve for " + chosenAmount);
|
||||
|
||||
for (int i = 0; i < chosenAmount; i++) {
|
||||
final CardView nowChosen = SGuiChoose.oneOrNone(getGui(), "Exile which card?", gameView.getCardViews(grave));
|
||||
final CardView nowChosen = SGuiChoose.oneOrNone(getGui(), "Exile which card?", getCardViews(grave));
|
||||
|
||||
if (nowChosen == null) {
|
||||
// User canceled,abort delving.
|
||||
@@ -778,7 +773,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
*/
|
||||
@Override
|
||||
public boolean confirmReplacementEffect(ReplacementEffect replacementEffect, SpellAbility effectSA, String question) {
|
||||
return SGuiDialog.confirm(getGui(), gameView.getCardView(replacementEffect.getHostCard()), question);
|
||||
return SGuiDialog.confirm(getGui(), getCardView(replacementEffect.getHostCard()), question);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -797,7 +792,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
//ensure they're declared and then delay slightly so user can see as much
|
||||
for (Pair<Card, GameEntity> attacker : mandatoryAttackers) {
|
||||
combat.addAttacker(attacker.getLeft(), attacker.getRight());
|
||||
MatchUtil.fireEvent(new UiEventAttackerDeclared(gameView.getCardView(attacker.getLeft()), gameView.getGameEntityView(attacker.getRight())));
|
||||
MatchUtil.fireEvent(new UiEventAttackerDeclared(getCardView(attacker.getLeft()), getGameEntityView(attacker.getRight())));
|
||||
}
|
||||
try {
|
||||
Thread.sleep(FControlGamePlayback.combatDelay);
|
||||
@@ -961,7 +956,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (srcCards.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
final List<CardView> chosen = SGuiChoose.many(getGui(), "Choose cards to activate from opening hand and their order", "Activate first", -1, gameView.getCardViews(srcCards), null);
|
||||
final List<CardView> chosen = SGuiChoose.many(getGui(), "Choose cards to activate from opening hand and their order", "Activate first", -1, getCardViews(srcCards), null);
|
||||
for (final CardView view : chosen) {
|
||||
final Card c = getCard(view);
|
||||
for (SpellAbility sa : usableFromOpeningHand) {
|
||||
@@ -991,7 +986,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
case PlayOrDraw: labels = new String[]{"Play", "Draw"}; break;
|
||||
default: labels = kindOfChoice.toString().split("Or");
|
||||
}
|
||||
return SGuiDialog.confirm(getGui(), gameView.getCardView(sa.getHostCard()), question, defaultVal == null || defaultVal.booleanValue(), labels);
|
||||
return SGuiDialog.confirm(getGui(), getCardView(sa.getHostCard()), question, defaultVal == null || defaultVal.booleanValue(), labels);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1163,7 +1158,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (colorNames.length > 2) {
|
||||
return MagicColor.fromName(SGuiChoose.one(getGui(), message, colorNames));
|
||||
}
|
||||
int idxChosen = SGuiDialog.confirm(getGui(), gameView.getCardView(c), message, colorNames) ? 0 : 1;
|
||||
int idxChosen = SGuiDialog.confirm(getGui(), getCardView(c), message, colorNames) ? 0 : 1;
|
||||
return MagicColor.fromName(colorNames[idxChosen]);
|
||||
}
|
||||
|
||||
@@ -1262,7 +1257,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
final String p1Str = String.format("Pile 1 (%s cards)", pile1.size());
|
||||
final String p2Str = String.format("Pile 2 (%s cards)", pile2.size());
|
||||
final String[] possibleValues = { p1Str , p2Str };
|
||||
return SGuiDialog.confirm(getGui(), gameView.getCardView(sa.getHostCard()), "Choose a Pile", possibleValues);
|
||||
return SGuiDialog.confirm(getGui(), getCardView(sa.getHostCard()), "Choose a Pile", possibleValues);
|
||||
}
|
||||
|
||||
tempShowCards(pile1);
|
||||
@@ -1598,7 +1593,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
* @see forge.view.LocalGameView#getGameEntityView(forge.game.GameEntity)
|
||||
*/
|
||||
public final GameEntityView getGameEntityView(GameEntity e) {
|
||||
return gameView.getGameEntityView(e);
|
||||
return gameView.getGameEntityView(e, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1607,14 +1602,14 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
* @see forge.view.LocalGameView#getPlayerViews(java.lang.Iterable)
|
||||
*/
|
||||
public final List<PlayerView> getPlayerViews(Iterable<Player> players) {
|
||||
return gameView.getPlayerViews(players);
|
||||
return gameView.getPlayerViews(players, false);
|
||||
}
|
||||
|
||||
public PlayerView getPlayerView() {
|
||||
return gameView.getPlayerView(getPlayer());
|
||||
return gameView.getPlayerView(getPlayer(), false);
|
||||
}
|
||||
public PlayerView getPlayerView(Player p) {
|
||||
return gameView.getPlayerView(p);
|
||||
return gameView.getPlayerView(p, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1632,7 +1627,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
* @see forge.view.LocalGameView#getCardView(forge.game.card.Card)
|
||||
*/
|
||||
public CardView getCardView(Card c) {
|
||||
return gameView.getCardView(c);
|
||||
return gameView.getCardView(c, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1641,7 +1636,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
* @see forge.view.LocalGameView#getCardViews(java.util.List)
|
||||
*/
|
||||
public final List<CardView> getCardViews(final Iterable<Card> cards) {
|
||||
return gameView.getCardViews(cards);
|
||||
return gameView.getCardViews(cards, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1740,7 +1735,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
public void setViewAllCards(final boolean canViewAll) {
|
||||
mayLookAtAllCards = canViewAll;
|
||||
for (final Player p : game.getPlayers()) {
|
||||
MatchUtil.updateCards(getCardViews(p.getAllCards()));
|
||||
MatchUtil.updateCards(gameView.getCardViews(p.getAllCards(), true));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package forge.view;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Observer;
|
||||
@@ -67,7 +68,7 @@ public abstract class LocalGameView implements IGameView {
|
||||
}
|
||||
|
||||
public void setLocalPlayer(Player localPlayer) {
|
||||
localPlayerView = getPlayerView(localPlayer);
|
||||
localPlayerView = getPlayerView(localPlayer, false);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -203,10 +204,10 @@ public abstract class LocalGameView implements IGameView {
|
||||
final List<Card> blockers = combat.getBlockers(b);
|
||||
final boolean isBlocked = b.isBlocked() == Boolean.TRUE;
|
||||
combatView.addAttackingBand(
|
||||
getCardViews(b.getAttackers()),
|
||||
getGameEntityView(defender),
|
||||
blockers == null || !isBlocked ? null : getCardViews(blockers),
|
||||
blockers == null ? null : getCardViews(blockers));
|
||||
getCardViews(b.getAttackers(), false),
|
||||
getGameEntityView(defender, false),
|
||||
blockers == null || !isBlocked ? null : getCardViews(blockers, false),
|
||||
blockers == null ? null : getCardViews(blockers, false));
|
||||
}
|
||||
}
|
||||
MatchUtil.cachedCombatView = combatView;
|
||||
@@ -241,12 +242,15 @@ public abstract class LocalGameView implements IGameView {
|
||||
*/
|
||||
@Override
|
||||
public List<PlayerView> getPlayers() {
|
||||
return getPlayerViews(game.getRegisteredPlayers());
|
||||
return getPlayerViews(game.getRegisteredPlayers(), false);
|
||||
}
|
||||
public List<PlayerView> getPlayers(boolean forceUpdate) {
|
||||
return getPlayerViews(game.getRegisteredPlayers(), forceUpdate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PlayerView getPlayerTurn() {
|
||||
return getPlayerView(game.getPhaseHandler().getPlayerTurn());
|
||||
return getPlayerView(game.getPhaseHandler().getPlayerTurn(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -309,44 +313,40 @@ public abstract class LocalGameView implements IGameView {
|
||||
return MatchUtil.stackItems.getKey(view.getId());
|
||||
}
|
||||
|
||||
public final GameEntityView getGameEntityView(final GameEntity e) {
|
||||
public final GameEntityView getGameEntityView(final GameEntity e, final boolean forceUpdate) {
|
||||
if (e instanceof Card) {
|
||||
return getCardView((Card)e);
|
||||
} else if (e instanceof Player) {
|
||||
return getPlayerView((Player)e);
|
||||
return getCardView((Card)e, forceUpdate);
|
||||
}
|
||||
if (e instanceof Player) {
|
||||
return getPlayerView((Player)e, forceUpdate);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final Function<GameEntity, GameEntityView> FN_GET_GAME_ENTITY_VIEW = new Function<GameEntity, GameEntityView>() {
|
||||
@Override
|
||||
public GameEntityView apply(GameEntity input) {
|
||||
return getGameEntityView(input);
|
||||
public final List<GameEntityView> getGameEntityViews(final Iterable<GameEntity> entities, final boolean forceUpdate) {
|
||||
List<GameEntityView> views = new ArrayList<GameEntityView>();
|
||||
for (GameEntity e : entities) {
|
||||
views.add(getGameEntityView(e, forceUpdate));
|
||||
}
|
||||
};
|
||||
|
||||
public final List<GameEntityView> getGameEntityViews(final Iterable<GameEntity> entities) {
|
||||
return ViewUtil.transformIfNotNull(entities, FN_GET_GAME_ENTITY_VIEW);
|
||||
return views;
|
||||
}
|
||||
|
||||
public final GameEntity getGameEntity(final GameEntityView view) {
|
||||
if (view instanceof CardView) {
|
||||
return getCard((CardView) view);
|
||||
} else if (view instanceof PlayerView) {
|
||||
}
|
||||
if (view instanceof PlayerView) {
|
||||
return getPlayer((PlayerView) view);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final Function<Player, PlayerView> FN_GET_PLAYER_VIEW = new Function<Player, PlayerView>() {
|
||||
@Override
|
||||
public PlayerView apply(final Player input) {
|
||||
return getPlayerView(input);
|
||||
public final List<PlayerView> getPlayerViews(final Iterable<Player> players, final boolean forceUpdate) {
|
||||
List<PlayerView> views = new ArrayList<PlayerView>();
|
||||
for (Player p : players) {
|
||||
views.add(getPlayerView(p, forceUpdate));
|
||||
}
|
||||
};
|
||||
|
||||
public final List<PlayerView> getPlayerViews(final Iterable<Player> players) {
|
||||
return ViewUtil.transformIfNotNull(players, FN_GET_PLAYER_VIEW);
|
||||
return views;
|
||||
}
|
||||
|
||||
public Player getPlayer(final PlayerView p) {
|
||||
@@ -356,7 +356,7 @@ public abstract class LocalGameView implements IGameView {
|
||||
return MatchUtil.players.getKey(p.getId());
|
||||
}
|
||||
|
||||
public PlayerView getPlayerView(final Player p) {
|
||||
public PlayerView getPlayerView(final Player p, final boolean forceUpdate) {
|
||||
if (p == null) {
|
||||
return null;
|
||||
}
|
||||
@@ -364,18 +364,16 @@ public abstract class LocalGameView implements IGameView {
|
||||
PlayerView view = MatchUtil.players.get(p.getId());
|
||||
if (view == null) {
|
||||
view = new PlayerView(p.getLobbyPlayer(), p.getId());
|
||||
writePlayerToView(p, view);
|
||||
writePlayerToView(p, view, forceUpdate);
|
||||
MatchUtil.players.put(p, view);
|
||||
}
|
||||
else if (updateViewOnAccess) {
|
||||
updateViewOnAccess = false; //set to false temporarily to prevent stack overflow
|
||||
writePlayerToView(p, view);
|
||||
updateViewOnAccess = true;
|
||||
else if (forceUpdate) {
|
||||
writePlayerToView(p, view, true);
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
private void writePlayerToView(final Player p, final PlayerView view) {
|
||||
private void writePlayerToView(final Player p, final PlayerView view, final boolean forceUpdate) {
|
||||
view.setCommanderInfo(CardFactoryUtil.getCommanderInfo(p).trim().replace("\r\n", "; "));
|
||||
view.setKeywords(p.getKeywords());
|
||||
view.setLife(p.getLife());
|
||||
@@ -384,16 +382,16 @@ public abstract class LocalGameView implements IGameView {
|
||||
view.setPoisonCounters(p.getPoisonCounters());
|
||||
view.setPreventNextDamage(p.getPreventNextDamageTotalShields());
|
||||
view.setHasUnlimitedHandSize(p.isUnlimitedHandSize());
|
||||
view.setAnteCards(getCardViews(p.getCardsIn(ZoneType.Ante)));
|
||||
view.setBfCards(getCardViews(p.getCardsIn(ZoneType.Battlefield, false)));
|
||||
view.setCommandCards(getCardViews(p.getCardsIn(ZoneType.Command)));
|
||||
view.setExileCards(getCardViews(p.getCardsIn(ZoneType.Exile)));
|
||||
view.setFlashbackCards(getCardViews(p.getCardsActivableInExternalZones(false)));
|
||||
view.setGraveCards(getCardViews(p.getCardsIn(ZoneType.Graveyard)));
|
||||
view.setAnteCards(getCardViews(p.getCardsIn(ZoneType.Ante), forceUpdate));
|
||||
view.setBfCards(getCardViews(p.getCardsIn(ZoneType.Battlefield, false), forceUpdate));
|
||||
view.setCommandCards(getCardViews(p.getCardsIn(ZoneType.Command), forceUpdate));
|
||||
view.setExileCards(getCardViews(p.getCardsIn(ZoneType.Exile), forceUpdate));
|
||||
view.setFlashbackCards(getCardViews(p.getCardsActivableInExternalZones(false), forceUpdate));
|
||||
view.setGraveCards(getCardViews(p.getCardsIn(ZoneType.Graveyard), forceUpdate));
|
||||
final List<Card> handCards = p.getCardsIn(ZoneType.Hand),
|
||||
libraryCards = p.getCardsIn(ZoneType.Library);
|
||||
view.setHandCards(getCardViews(handCards));
|
||||
view.setLibraryCards(getCardViews(libraryCards));
|
||||
view.setHandCards(getCardViews(handCards, forceUpdate));
|
||||
view.setLibraryCards(getCardViews(libraryCards, forceUpdate));
|
||||
view.setnHandCards(handCards.size());
|
||||
view.setnLibraryCards(libraryCards.size());
|
||||
|
||||
@@ -402,15 +400,7 @@ public abstract class LocalGameView implements IGameView {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean updateViewOnAccess;
|
||||
public void startUpdate() {
|
||||
updateViewOnAccess = true; //allow accessed card views and player views to be updated
|
||||
}
|
||||
public void endUpdate() {
|
||||
updateViewOnAccess = false;
|
||||
}
|
||||
|
||||
public CardView getCardView(final Card c) {
|
||||
public CardView getCardView(final Card c, final boolean forceUpdate) {
|
||||
if (c == null || c != c.getCardForUi()) {
|
||||
return null;
|
||||
}
|
||||
@@ -421,10 +411,8 @@ public abstract class LocalGameView implements IGameView {
|
||||
writeCardToView(c, view, MatchUtil.getGameView());
|
||||
MatchUtil.cards.put(c, view);
|
||||
}
|
||||
else if (updateViewOnAccess) {
|
||||
updateViewOnAccess = false; //set to false temporarily to prevent stack overflow
|
||||
else if (forceUpdate) {
|
||||
writeCardToView(c, view, MatchUtil.getGameView());
|
||||
updateViewOnAccess = true;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
@@ -432,19 +420,16 @@ public abstract class LocalGameView implements IGameView {
|
||||
public void updateAllCards() {
|
||||
LocalGameView gameView = MatchUtil.getGameView();
|
||||
for (Card c : MatchUtil.cards.getKeys()) {
|
||||
writeCardToView(c, getCardView(c), gameView);
|
||||
writeCardToView(c, getCardView(c, false), gameView);
|
||||
}
|
||||
}
|
||||
|
||||
private final Function<Card, CardView> FN_GET_CARD_VIEW = new Function<Card, CardView>() {
|
||||
@Override
|
||||
public CardView apply(final Card input) {
|
||||
return getCardView(input);
|
||||
public final List<CardView> getCardViews(final Iterable<Card> cards, final boolean forceUpdate) {
|
||||
List<CardView> cardViews = new ArrayList<CardView>();
|
||||
for (Card c : cards) {
|
||||
cardViews.add(getCardView(c, forceUpdate));
|
||||
}
|
||||
};
|
||||
|
||||
public final List<CardView> getCardViews(final Iterable<Card> cards) {
|
||||
return ViewUtil.transformIfNotNull(cards, FN_GET_CARD_VIEW);
|
||||
return cardViews;
|
||||
}
|
||||
|
||||
public Card getCard(final CardView c) {
|
||||
@@ -474,24 +459,24 @@ public abstract class LocalGameView implements IGameView {
|
||||
if (!mayShowCard) { return; }
|
||||
|
||||
final Combat combat = game.getCombat();
|
||||
view.setOwner(getPlayerView(c.getOwner()));
|
||||
view.setController(getPlayerView(c.getController()));
|
||||
view.setOwner(getPlayerView(c.getOwner(), false));
|
||||
view.setController(getPlayerView(c.getController(), false));
|
||||
view.setAttacking(combat != null && combat.isAttacking(c));
|
||||
view.setBlocking(combat != null && combat.isBlocking(c));
|
||||
view.setChosenPlayer(getPlayerView(c.getChosenPlayer()));
|
||||
view.setEquipping(getCardView(Iterables.getFirst(c.getEquipping(), null)));
|
||||
view.setEquippedBy(getCardViews(c.getEquippedBy()));
|
||||
view.setEnchantingCard(getCardView(c.getEnchantingCard()));
|
||||
view.setEnchantingPlayer(getPlayerView(c.getEnchantingPlayer()));
|
||||
view.setEnchantedBy(getCardViews(c.getEnchantedBy()));
|
||||
view.setFortifiedBy(getCardViews(c.getFortifiedBy()));
|
||||
view.setGainControlTargets(getCardViews(c.getGainControlTargets()));
|
||||
view.setCloneOrigin(getCardView(c.getCloneOrigin()));
|
||||
view.setImprinted(getCardViews(c.getImprinted()));
|
||||
view.setHauntedBy(getCardViews(c.getHauntedBy()));
|
||||
view.setHaunting(getCardView(c.getHaunting()));
|
||||
view.setMustBlock(c.getMustBlockCards() == null ? Collections.<CardView>emptySet() : getCardViews(c.getMustBlockCards()));
|
||||
view.setPairedWith(getCardView(c.getPairedWith()));
|
||||
view.setChosenPlayer(getPlayerView(c.getChosenPlayer(), false));
|
||||
view.setEquipping(getCardView(Iterables.getFirst(c.getEquipping(), null), false));
|
||||
view.setEquippedBy(getCardViews(c.getEquippedBy(), false));
|
||||
view.setEnchantingCard(getCardView(c.getEnchantingCard(), false));
|
||||
view.setEnchantingPlayer(getPlayerView(c.getEnchantingPlayer(), false));
|
||||
view.setEnchantedBy(getCardViews(c.getEnchantedBy(), false));
|
||||
view.setFortifiedBy(getCardViews(c.getFortifiedBy(), false));
|
||||
view.setGainControlTargets(getCardViews(c.getGainControlTargets(), false));
|
||||
view.setCloneOrigin(getCardView(c.getCloneOrigin(), false));
|
||||
view.setImprinted(getCardViews(c.getImprinted(), false));
|
||||
view.setHauntedBy(getCardViews(c.getHauntedBy(), false));
|
||||
view.setHaunting(getCardView(c.getHaunting(), false));
|
||||
view.setMustBlock(c.getMustBlockCards() == null ? Collections.<CardView>emptySet() : getCardViews(c.getMustBlockCards(), false));
|
||||
view.setPairedWith(getCardView(c.getPairedWith(), false));
|
||||
}
|
||||
|
||||
public SpellAbilityView getSpellAbilityView(final SpellAbility sa) {
|
||||
@@ -544,7 +529,7 @@ public abstract class LocalGameView implements IGameView {
|
||||
}
|
||||
|
||||
private void writeSpellAbilityToView(final SpellAbility sa, final SpellAbilityView view) {
|
||||
view.setHostCard(getCardView(sa.getHostCard()));
|
||||
view.setHostCard(getCardView(sa.getHostCard(), false));
|
||||
view.setDescription(sa.toUnsuppressedString());
|
||||
view.setCanPlay(sa.canPlay());
|
||||
view.setPromptIfOnlyPossibleAbility(sa.promptIfOnlyPossibleAbility());
|
||||
|
||||
@@ -30,10 +30,10 @@ public class StackItemView implements IIdentifiable {
|
||||
key = si.getSpellAbility().toUnsuppressedString();
|
||||
sourceTrigger = si.getSpellAbility().getSourceTrigger();
|
||||
text = si.getStackDescription();
|
||||
source = gameView.getCardView(si.getSourceCard());
|
||||
activatingPlayer = gameView.getPlayerView(si.getActivator());
|
||||
targetCards = gameView.getCardViews(si.getTargetChoices().getTargetCards());
|
||||
targetPlayers = gameView.getPlayerViews(si.getTargetChoices().getTargetPlayers());
|
||||
source = gameView.getCardView(si.getSourceCard(), false);
|
||||
activatingPlayer = gameView.getPlayerView(si.getActivator(), false);
|
||||
targetCards = gameView.getCardViews(si.getTargetChoices().getTargetCards(), false);
|
||||
targetPlayers = gameView.getPlayerViews(si.getTargetChoices().getTargetPlayers(), false);
|
||||
ability = si.isAbility();
|
||||
optionalTrigger = si.isOptionalTrigger();
|
||||
subInstance = si.getSubInstance() == null ? null : new StackItemView(si.getSubInstance(), gameView);
|
||||
|
||||
Reference in New Issue
Block a user