mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
Refactor code to prevent duplication of match code
This commit is contained in:
@@ -49,9 +49,9 @@ import forge.game.player.Player;
|
||||
import forge.game.zone.PlayerZone;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.match.input.ButtonUtil;
|
||||
import forge.match.input.InputBase;
|
||||
import forge.match.input.InputNone;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
@@ -83,7 +83,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
@Override
|
||||
public void run() {
|
||||
phaseUpdPlanned.set(false);
|
||||
gameView.getGui().updatePhase();
|
||||
MatchUtil.getController().updatePhase();
|
||||
}
|
||||
});
|
||||
return null;
|
||||
@@ -100,7 +100,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
@Override
|
||||
public void run() {
|
||||
combatUpdPlanned.set(false);
|
||||
gameView.getGui().showCombat(gameView.getCombat());
|
||||
MatchUtil.getController().showCombat(gameView.getCombat());
|
||||
}
|
||||
});
|
||||
return null;
|
||||
@@ -120,7 +120,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
@Override
|
||||
public void run() {
|
||||
turnUpdPlanned.set(false);
|
||||
gameView.getGui().updateTurn(gameView.getPlayerView(event.turnOwner));
|
||||
MatchUtil.getController().updateTurn(gameView.getPlayerView(event.turnOwner));
|
||||
}
|
||||
});
|
||||
return null;
|
||||
@@ -148,7 +148,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
gameView.getGui().updatePlayerControl();
|
||||
MatchUtil.getController().updatePlayerControl();
|
||||
}
|
||||
});
|
||||
return null;
|
||||
@@ -172,11 +172,11 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
FThreads.invokeInEdtNowOrLater(gameView.getGui(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
InputNone inputNone = new InputNone(gameView);
|
||||
PlayerView localPlayer = gameView.getLocalPlayerView();
|
||||
InputBase.cancelAwaitNextInput(); //ensure "Waiting for opponent..." doesn't appear behind WinLo
|
||||
gameView.getGui().showPromptMessage(inputNone.getOwner(), ""); //clear prompt behind WinLose overlay
|
||||
ButtonUtil.update(inputNone, "", "", false, false, false);
|
||||
gameView.getGui().finishGame();
|
||||
MatchUtil.getController().showPromptMessage(localPlayer, ""); //clear prompt behind WinLose overlay
|
||||
ButtonUtil.update(localPlayer, "", "", false, false, false);
|
||||
MatchUtil.getController().finishGame();
|
||||
gameView.updateAchievements();
|
||||
}
|
||||
});
|
||||
@@ -188,7 +188,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
@Override
|
||||
public void run() {
|
||||
stackUpdPlanned.set(false);
|
||||
gameView.getGui().updateStack();
|
||||
MatchUtil.getController().updateStack();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -219,7 +219,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
@Override
|
||||
public void run() {
|
||||
synchronized (zonesToUpdate) {
|
||||
gameView.getGui().updateZones(zonesToUpdate);
|
||||
MatchUtil.getController().updateZones(zonesToUpdate);
|
||||
zonesToUpdate.clear();
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
public void run() {
|
||||
synchronized (cardsToUpdate) {
|
||||
final Iterable<CardView> newCardsToUpdate = gameView.getRefreshedCardViews(cardsToUpdate);
|
||||
gameView.getGui().updateCards(newCardsToUpdate);
|
||||
MatchUtil.updateCards(newCardsToUpdate);
|
||||
cardsToUpdate.clear();
|
||||
}
|
||||
}
|
||||
@@ -372,14 +372,14 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
@Override
|
||||
public Void visit(GameEventCardStatsChanged event) {
|
||||
final Iterable<CardView> cardViews = gameView.getCardViews(event.cards);
|
||||
gameView.getGui().refreshCardDetails(cardViews);
|
||||
MatchUtil.getController().refreshCardDetails(cardViews);
|
||||
return updateManyCards(cardViews);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(GameEventPlayerStatsChanged event) {
|
||||
for (final Player p : event.players) {
|
||||
gameView.getGui().refreshCardDetails(gameView.getCardViews(p.getAllCards()));
|
||||
MatchUtil.getController().refreshCardDetails(gameView.getCardViews(p.getAllCards()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -395,7 +395,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
private final Runnable updManaPool = new Runnable() {
|
||||
@Override public void run() {
|
||||
synchronized (manaPoolUpdate) {
|
||||
gameView.getGui().updateManaPool(gameView.getPlayerViews(manaPoolUpdate));
|
||||
MatchUtil.getController().updateManaPool(gameView.getPlayerViews(manaPoolUpdate));
|
||||
manaPoolUpdate.clear();
|
||||
}
|
||||
}
|
||||
@@ -421,7 +421,7 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
|
||||
private final Runnable updLives = new Runnable() {
|
||||
@Override public void run() {
|
||||
synchronized (livesUpdate) {
|
||||
gameView.getGui().updateLives(gameView.getPlayerViews(livesUpdate));
|
||||
MatchUtil.getController().updateLives(gameView.getPlayerViews(livesUpdate));
|
||||
livesUpdate.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import forge.game.event.GameEventSpellResolved;
|
||||
import forge.game.event.GameEventTurnPhase;
|
||||
import forge.game.event.IGameEventVisitor;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.match.input.InputPlaybackControl;
|
||||
import forge.view.LocalGameView;
|
||||
|
||||
@@ -76,7 +77,7 @@ public class FControlGamePlayback extends IGameEventVisitor.Base<Void> {
|
||||
*/
|
||||
@Override
|
||||
public Void visit(GameEventTurnPhase ev) {
|
||||
boolean isUiToStop = gui.stopAtPhase(
|
||||
boolean isUiToStop = MatchUtil.getController().stopAtPhase(
|
||||
gameView.getPlayerView(ev.playerTurn), ev.phase);
|
||||
|
||||
switch(ev.phase) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.interfaces.IButton;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.interfaces.IWinLoseView;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.view.IGameView;
|
||||
@@ -19,12 +19,10 @@ import forge.view.IGameView;
|
||||
public abstract class GauntletWinLoseController {
|
||||
private final IGameView lastGame;
|
||||
private final IWinLoseView<? extends IButton> view;
|
||||
private final IGuiBase gui;
|
||||
|
||||
public GauntletWinLoseController(IWinLoseView<? extends IButton> view0, final IGameView game0, final IGuiBase gui) {
|
||||
public GauntletWinLoseController(IWinLoseView<? extends IButton> view0, final IGameView game0) {
|
||||
view = view0;
|
||||
lastGame = game0;
|
||||
this.gui = gui;
|
||||
}
|
||||
|
||||
public void showOutcome() {
|
||||
@@ -121,9 +119,9 @@ public abstract class GauntletWinLoseController {
|
||||
|
||||
view.hide();
|
||||
saveOptions();
|
||||
gui.endCurrentGame();
|
||||
MatchUtil.endCurrentGame();
|
||||
|
||||
gui.startMatch(GameType.Gauntlet, players);
|
||||
MatchUtil.startMatch(GameType.Gauntlet, players);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -3,32 +3,17 @@ package forge.interfaces;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
|
||||
import forge.LobbyPlayer;
|
||||
import forge.assets.FSkinProp;
|
||||
import forge.assets.ISkinImage;
|
||||
import forge.deck.CardPool;
|
||||
import forge.events.UiEvent;
|
||||
import forge.game.GameType;
|
||||
import forge.game.Match;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.IHasIcon;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.item.PaperCard;
|
||||
import forge.sound.IAudioClip;
|
||||
import forge.sound.IAudioMusic;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.view.CardView;
|
||||
import forge.view.CombatView;
|
||||
import forge.view.GameEntityView;
|
||||
import forge.view.PlayerView;
|
||||
import forge.view.SpellAbilityView;
|
||||
|
||||
public interface IGuiBase {
|
||||
boolean isRunningOnDesktop();
|
||||
@@ -53,40 +38,7 @@ public interface IGuiBase {
|
||||
File getSaveFile(File defaultFile);
|
||||
void showCardList(final String title, final String message, final List<PaperCard> list);
|
||||
boolean showBoxedProduct(final String title, final String message, final List<PaperCard> list);
|
||||
void fireEvent(UiEvent e);
|
||||
void setCard(CardView card);
|
||||
void showCombat(CombatView combat);
|
||||
void setUsedToPay(CardView card, boolean b);
|
||||
void setHighlighted(PlayerView player, boolean b);
|
||||
void showPromptMessage(PlayerView playerView, String message);
|
||||
boolean stopAtPhase(PlayerView playerTurn, PhaseType phase);
|
||||
IButton getBtnOK(PlayerView playerView);
|
||||
IButton getBtnCancel(PlayerView playerView);
|
||||
void focusButton(IButton button);
|
||||
void flashIncorrectAction();
|
||||
void updatePhase();
|
||||
void updateTurn(PlayerView player);
|
||||
void updatePlayerControl();
|
||||
void enableOverlay();
|
||||
void disableOverlay();
|
||||
void finishGame();
|
||||
Object showManaPool(PlayerView player);
|
||||
void hideManaPool(PlayerView player, Object zoneToRestore);
|
||||
boolean openZones(Collection<ZoneType> zones, Map<PlayerView, Object> players);
|
||||
void restoreOldZones(Map<PlayerView, Object> playersToRestoreZonesFor);
|
||||
void updateStack();
|
||||
void updateZones(List<Pair<PlayerView, ZoneType>> zonesToUpdate);
|
||||
void updateCards(Iterable<CardView> cardsToUpdate);
|
||||
void refreshCardDetails(Iterable<CardView> cards);
|
||||
void updateManaPool(List<PlayerView> manaPoolUpdate);
|
||||
void updateLives(List<PlayerView> livesUpdate);
|
||||
void endCurrentGame();
|
||||
void startMatch(GameType gauntletType, List<RegisteredPlayer> starter);
|
||||
void setPanelSelection(CardView hostCard);
|
||||
Map<CardView, Integer> getDamageToAssign(CardView attacker, List<CardView> blockers,
|
||||
int damageDealt, GameEntityView defender, boolean overrideOrder);
|
||||
int getAbilityToPlay(List<SpellAbilityView> abilities, ITriggerEvent triggerEvent);
|
||||
void hear(LobbyPlayer player, String message);
|
||||
int getAvatarCount();
|
||||
void copyToClipboard(String text);
|
||||
void browseToUrl(String url) throws Exception;
|
||||
@@ -94,8 +46,6 @@ public interface IGuiBase {
|
||||
IAudioMusic createAudioMusic(String filename);
|
||||
void startAltSoundSystem(String filename, boolean isSynchronized);
|
||||
void clearImageCache();
|
||||
void startGame(Match match);
|
||||
void continueMatch(Match match);
|
||||
void showSpellShop();
|
||||
void showBazaar();
|
||||
void setPlayerAvatar(LobbyPlayer player, IHasIcon ihi);
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.List;
|
||||
import forge.deck.Deck;
|
||||
import forge.game.GameType;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.util.Aggregates;
|
||||
@@ -38,8 +38,6 @@ import forge.util.Aggregates;
|
||||
* @since 1.2.xx
|
||||
*/
|
||||
public class GauntletMini {
|
||||
|
||||
private final IGuiBase gui;
|
||||
private int rounds;
|
||||
private Deck humanDeck;
|
||||
private int currentRound;
|
||||
@@ -49,8 +47,7 @@ public class GauntletMini {
|
||||
private GameType gauntletType;
|
||||
private List<RegisteredPlayer> aiOpponents = new ArrayList<RegisteredPlayer>();
|
||||
|
||||
public GauntletMini(IGuiBase gui) {
|
||||
this.gui = gui;
|
||||
public GauntletMini() {
|
||||
}
|
||||
|
||||
// private final String humanName;
|
||||
@@ -86,7 +83,7 @@ public class GauntletMini {
|
||||
}
|
||||
|
||||
currentRound++;
|
||||
gui.endCurrentGame();
|
||||
MatchUtil.endCurrentGame();
|
||||
startRound();
|
||||
}
|
||||
|
||||
@@ -143,7 +140,7 @@ public class GauntletMini {
|
||||
starter.add(new RegisteredPlayer(humanDeck).setPlayer(GamePlayerUtil.getGuiPlayer()));
|
||||
starter.add(aiOpponents.get(currentRound - 1).setPlayer(GamePlayerUtil.createAiPlayer()));
|
||||
|
||||
gui.startMatch(gauntletType, starter);
|
||||
MatchUtil.startMatch(gauntletType, starter);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -17,7 +17,7 @@ public abstract class LimitedWinLoseController {
|
||||
public LimitedWinLoseController(IWinLoseView<? extends IButton> view0, final IGameView game0, final IGuiBase gui) {
|
||||
view = view0;
|
||||
lastGame = game0;
|
||||
gauntlet = FModel.getGauntletMini(gui);
|
||||
gauntlet = FModel.getGauntletMini();
|
||||
wonMatch = lastGame.isMatchWonBy(GamePlayerUtil.getGuiPlayer());
|
||||
}
|
||||
|
||||
|
||||
54
forge-gui/src/main/java/forge/match/IMatchController.java
Normal file
54
forge-gui/src/main/java/forge/match/IMatchController.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package forge.match;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import forge.LobbyPlayer;
|
||||
import forge.game.Match;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.interfaces.IButton;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.view.CardView;
|
||||
import forge.view.CombatView;
|
||||
import forge.view.GameEntityView;
|
||||
import forge.view.PlayerView;
|
||||
import forge.view.SpellAbilityView;
|
||||
|
||||
public interface IMatchController {
|
||||
void startNewMatch(Match match);
|
||||
boolean resetForNewGame();
|
||||
void openView(List<Player> sortedPlayers, int humanCount);
|
||||
void afterGameEnd();
|
||||
void showCombat(CombatView combat);
|
||||
void showPromptMessage(PlayerView playerView, String message);
|
||||
boolean stopAtPhase(PlayerView playerTurn, PhaseType phase);
|
||||
IButton getBtnOK(PlayerView playerView);
|
||||
IButton getBtnCancel(PlayerView playerView);
|
||||
void focusButton(IButton button);
|
||||
void flashIncorrectAction();
|
||||
void updatePhase();
|
||||
void updateTurn(PlayerView player);
|
||||
void updatePlayerControl();
|
||||
void enableOverlay();
|
||||
void disableOverlay();
|
||||
void finishGame();
|
||||
Object showManaPool(PlayerView player);
|
||||
void hideManaPool(PlayerView player, Object zoneToRestore);
|
||||
boolean openZones(Collection<ZoneType> zones, Map<PlayerView, Object> players);
|
||||
void restoreOldZones(Map<PlayerView, Object> playersToRestoreZonesFor);
|
||||
void updateStack();
|
||||
void updateZones(List<Pair<PlayerView, ZoneType>> zonesToUpdate);
|
||||
void updateSingleCard(CardView card);
|
||||
void refreshCardDetails(Iterable<CardView> cards);
|
||||
void updateManaPool(List<PlayerView> manaPoolUpdate);
|
||||
void updateLives(List<PlayerView> livesUpdate);
|
||||
void setPanelSelection(CardView hostCard);
|
||||
void hear(LobbyPlayer player, String message);
|
||||
int getAbilityToPlay(List<SpellAbilityView> abilities, ITriggerEvent triggerEvent);
|
||||
Map<CardView, Integer> assignDamage(CardView attacker, List<CardView> blockers, int damage, GameEntityView defender, boolean overrideOrder);
|
||||
}
|
||||
596
forge-gui/src/main/java/forge/match/MatchUtil.java
Normal file
596
forge-gui/src/main/java/forge/match/MatchUtil.java
Normal file
@@ -0,0 +1,596 @@
|
||||
package forge.match;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.LobbyPlayer;
|
||||
import forge.ai.LobbyPlayerAi;
|
||||
import forge.card.CardCharacteristicName;
|
||||
import forge.control.FControlGameEventHandler;
|
||||
import forge.control.FControlGamePlayback;
|
||||
import forge.events.IUiEventVisitor;
|
||||
import forge.events.UiEvent;
|
||||
import forge.events.UiEventAttackerDeclared;
|
||||
import forge.events.UiEventBlockerAssigned;
|
||||
import forge.game.Game;
|
||||
import forge.game.GameRules;
|
||||
import forge.game.GameType;
|
||||
import forge.game.Match;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.game.trigger.TriggerType;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.match.input.InputPlaybackControl;
|
||||
import forge.match.input.InputQueue;
|
||||
import forge.match.input.InputSynchronized;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.player.LobbyPlayerHuman;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.properties.ForgePreferences;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
import forge.quest.QuestController;
|
||||
import forge.sound.MusicPlaylist;
|
||||
import forge.sound.SoundSystem;
|
||||
import forge.util.GuiDisplayUtil;
|
||||
import forge.util.NameGenerator;
|
||||
import forge.util.gui.SOptionPane;
|
||||
import forge.view.CardView;
|
||||
import forge.view.GameEntityView;
|
||||
import forge.view.LocalGameView;
|
||||
import forge.view.PlayerView;
|
||||
import forge.view.WatchLocalGame;
|
||||
|
||||
public class MatchUtil {
|
||||
private static IMatchController controller;
|
||||
private static Game game;
|
||||
private static List<LocalGameView> gameViews = new ArrayList<LocalGameView>();
|
||||
private static final EventBus uiEvents;
|
||||
private static FControlGamePlayback playbackControl;
|
||||
private static final MatchUiEventVisitor visitor = new MatchUiEventVisitor();
|
||||
|
||||
static {
|
||||
uiEvents = new EventBus("ui events");
|
||||
uiEvents.register(SoundSystem.instance);
|
||||
uiEvents.register(visitor);
|
||||
}
|
||||
|
||||
public static IMatchController getController() {
|
||||
return controller;
|
||||
}
|
||||
public static void setController(IMatchController controller0) {
|
||||
controller = controller0;
|
||||
}
|
||||
|
||||
public static void startMatch(GameType gameType, List<RegisteredPlayer> players) {
|
||||
startMatch(gameType, null, players);
|
||||
}
|
||||
public static void startMatch(GameType gameType, Set<GameType> appliedVariants, List<RegisteredPlayer> players) {
|
||||
boolean useRandomFoil = FModel.getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL);
|
||||
for (RegisteredPlayer rp : players) {
|
||||
rp.setRandomFoil(useRandomFoil);
|
||||
}
|
||||
|
||||
GameRules rules = new GameRules(gameType);
|
||||
if (appliedVariants != null && !appliedVariants.isEmpty()) {
|
||||
rules.setAppliedVariants(appliedVariants);
|
||||
}
|
||||
rules.setPlayForAnte(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE));
|
||||
rules.setMatchAnteRarity(FModel.getPreferences().getPrefBoolean(FPref.UI_ANTE_MATCH_RARITY));
|
||||
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||
rules.canCloneUseTargetsImage = FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
|
||||
|
||||
controller.startNewMatch(new Match(rules, players));
|
||||
}
|
||||
|
||||
public static void continueMatch() {
|
||||
final Match match = game.getMatch();
|
||||
endCurrentGame();
|
||||
startGame(match);
|
||||
}
|
||||
|
||||
public static void restartMatch() {
|
||||
final Match match = game.getMatch();
|
||||
endCurrentGame();
|
||||
match.clearGamesPlayed();
|
||||
startGame(match);
|
||||
}
|
||||
|
||||
public static void startGame(final Match match) {
|
||||
if (!controller.resetForNewGame()) { return; }
|
||||
|
||||
//prompt user for player one name if needed
|
||||
final ForgePreferences prefs = FModel.getPreferences();
|
||||
if (StringUtils.isBlank(prefs.getPref(FPref.PLAYER_NAME))) {
|
||||
boolean isPlayerOneHuman = match.getPlayers().get(0).getPlayer() instanceof LobbyPlayerHuman;
|
||||
boolean isPlayerTwoComputer = match.getPlayers().get(1).getPlayer() instanceof LobbyPlayerAi;
|
||||
if (isPlayerOneHuman && isPlayerTwoComputer) {
|
||||
GamePlayerUtil.setPlayerName(GuiBase.getInterface());
|
||||
}
|
||||
}
|
||||
|
||||
SoundSystem.instance.setBackgroundMusic(MusicPlaylist.MATCH);
|
||||
|
||||
game = match.createGame();
|
||||
|
||||
if (game.getRules().getGameType() == GameType.Quest) {
|
||||
QuestController qc = FModel.getQuest();
|
||||
// Reset new list when the Match round starts, not when each game starts
|
||||
if (game.getMatch().getPlayedGames().isEmpty()) {
|
||||
qc.getCards().resetNewList();
|
||||
}
|
||||
game.subscribeToEvents(qc); // this one listens to player's mulligans ATM
|
||||
}
|
||||
|
||||
game.subscribeToEvents(SoundSystem.instance);
|
||||
|
||||
final String[] indices = prefs.getPref(FPref.UI_AVATARS).split(",");
|
||||
|
||||
// Instantiate all required field slots (user at 0)
|
||||
final List<Player> sortedPlayers = new ArrayList<Player>(game.getRegisteredPlayers());
|
||||
Collections.sort(sortedPlayers, new Comparator<Player>() {
|
||||
@Override
|
||||
public int compare(Player p1, Player p2) {
|
||||
int v1 = p1.getController() instanceof PlayerControllerHuman ? 0 : 1;
|
||||
int v2 = p2.getController() instanceof PlayerControllerHuman ? 0 : 1;
|
||||
return Integer.compare(v1, v2);
|
||||
}
|
||||
});
|
||||
|
||||
gameViews.clear();
|
||||
|
||||
int i = 0;
|
||||
int avatarIndex = 0;
|
||||
int humanCount = 0;
|
||||
for (Player p : sortedPlayers) {
|
||||
if (i < indices.length) {
|
||||
avatarIndex = Integer.parseInt(indices[i]);
|
||||
i++;
|
||||
}
|
||||
p.getLobbyPlayer().setAvatarIndex(avatarIndex);
|
||||
|
||||
if (p.getController() instanceof PlayerControllerHuman) {
|
||||
final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController();
|
||||
LocalGameView gameView = controller.getGameView();
|
||||
game.subscribeToEvents(new FControlGameEventHandler(gameView));
|
||||
gameViews.add(gameView);
|
||||
humanCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (humanCount == 0) { //watch game but do not participate
|
||||
LocalGameView gameView = new WatchLocalGame(GuiBase.getInterface(), game);
|
||||
gameView.setLocalPlayer(sortedPlayers.get(0));
|
||||
game.subscribeToEvents(new FControlGameEventHandler(gameView));
|
||||
gameViews.add(gameView);
|
||||
}
|
||||
else if (humanCount == sortedPlayers.size()) {
|
||||
//if there are no AI's, allow all players to see all cards (hotseat mode).
|
||||
for (Player p : sortedPlayers) {
|
||||
((PlayerControllerHuman) p.getController()).setMayLookAtAllCards(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (humanCount == 0) {
|
||||
playbackControl = new FControlGamePlayback(GuiBase.getInterface(), getGameView());
|
||||
playbackControl.setGame(game);
|
||||
game.subscribeToEvents(playbackControl);
|
||||
}
|
||||
|
||||
controller.openView(sortedPlayers, humanCount);
|
||||
|
||||
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
|
||||
// Game is set on pause while gui player takes decisions
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
match.startGame(game);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Game getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public static LocalGameView getGameView() {
|
||||
return getGameView(getCurrentPlayer());
|
||||
}
|
||||
public static LocalGameView getGameView(Player player) {
|
||||
switch (gameViews.size()) {
|
||||
case 1:
|
||||
return gameViews.get(0);
|
||||
case 0:
|
||||
return null;
|
||||
default:
|
||||
if (player != null && player.getController() instanceof PlayerControllerHuman) {
|
||||
return ((PlayerControllerHuman)player.getController()).getGameView();
|
||||
}
|
||||
return gameViews.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static InputQueue getInputQueue() {
|
||||
LocalGameView gameView = getGameView();
|
||||
if (gameView != null) {
|
||||
return gameView.getInputQueue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void endCurrentTurn() {
|
||||
getGameView().passPriorityUntilEndOfTurn();
|
||||
}
|
||||
|
||||
public static Player getCurrentPlayer() {
|
||||
if (game == null) { return null; }
|
||||
|
||||
LobbyPlayer lobbyPlayer = getGuiPlayer();
|
||||
if (gameViews.size() > 1) {
|
||||
//account for if second human player is currently being prompted
|
||||
InputSynchronized activeInput = InputQueue.getActiveInput();
|
||||
if (activeInput != null) {
|
||||
lobbyPlayer = activeInput.getOwner().getLobbyPlayer();
|
||||
}
|
||||
}
|
||||
|
||||
for (Player p : game.getPlayers()) {
|
||||
if (p.getLobbyPlayer() == lobbyPlayer) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void alphaStrike() {
|
||||
getGameView().alphaStrike();
|
||||
}
|
||||
|
||||
public static Map<CardView, Integer> getDamageToAssign(final CardView attacker, final List<CardView> blockers, final int damage, final GameEntityView defender, final boolean overrideOrder) {
|
||||
if (damage <= 0) {
|
||||
return new HashMap<CardView, Integer>();
|
||||
}
|
||||
|
||||
// If the first blocker can absorb all of the damage, don't show the Assign Damage dialog
|
||||
CardView firstBlocker = blockers.get(0);
|
||||
if (!overrideOrder && !attacker.getOriginal().hasDeathtouch() && firstBlocker.getLethalDamage() >= damage) {
|
||||
Map<CardView, Integer> res = new HashMap<CardView, Integer>();
|
||||
res.put(firstBlocker, damage);
|
||||
return res;
|
||||
}
|
||||
|
||||
return controller.assignDamage(attacker, blockers, damage, defender, overrideOrder);
|
||||
}
|
||||
|
||||
private static Set<PlayerView> highlightedPlayers = new HashSet<PlayerView>();
|
||||
public static void setHighlighted(PlayerView pv, boolean b) {
|
||||
if (b) {
|
||||
highlightedPlayers.add(pv);
|
||||
}
|
||||
else {
|
||||
highlightedPlayers.remove(pv);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isHighlighted(PlayerView player) {
|
||||
return highlightedPlayers.contains(player);
|
||||
}
|
||||
|
||||
private static Set<CardView> highlightedCards = new HashSet<CardView>();
|
||||
// used to highlight cards in UI
|
||||
public static void setUsedToPay(CardView card, boolean value) {
|
||||
boolean hasChanged = value ? highlightedCards.add(card) : highlightedCards.remove(card);
|
||||
if (hasChanged) { // since we are in UI thread, may redraw the card right now
|
||||
controller.updateSingleCard(card);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isUsedToPay(CardView card) {
|
||||
return highlightedCards.contains(card);
|
||||
}
|
||||
|
||||
public static void updateCards(Iterable<CardView> cardsToUpdate) {
|
||||
for (CardView c : cardsToUpdate) {
|
||||
controller.updateSingleCard(c);
|
||||
}
|
||||
}
|
||||
|
||||
/** Concede game, bring up WinLose UI. */
|
||||
public static void concede() {
|
||||
String userPrompt =
|
||||
"This will end the current game and you will not be able to resume.\n\n" +
|
||||
"Concede anyway?";
|
||||
if (SOptionPane.showConfirmDialog(GuiBase.getInterface(), userPrompt, "Concede Game?", "Concede", "Cancel")) {
|
||||
stopGame();
|
||||
}
|
||||
}
|
||||
|
||||
public static void stopGame() {
|
||||
List<Player> pp = new ArrayList<Player>();
|
||||
for (Player p : game.getPlayers()) {
|
||||
if (p.getOriginalLobbyPlayer() == getGuiPlayer()) {
|
||||
pp.add(p);
|
||||
}
|
||||
}
|
||||
boolean hasHuman = !pp.isEmpty();
|
||||
|
||||
if (pp.isEmpty()) {
|
||||
pp.addAll(game.getPlayers()); // no human? then all players surrender!
|
||||
}
|
||||
|
||||
for (Player p: pp) {
|
||||
p.concede();
|
||||
}
|
||||
|
||||
Player priorityPlayer = game.getPhaseHandler().getPriorityPlayer();
|
||||
boolean humanHasPriority = priorityPlayer == null || priorityPlayer.getLobbyPlayer() == getGuiPlayer();
|
||||
|
||||
if (hasHuman && humanHasPriority) {
|
||||
game.getAction().checkGameOverCondition();
|
||||
}
|
||||
else {
|
||||
game.isGameOver(); // this is synchronized method - it's used to make Game-0 thread see changes made here
|
||||
getInputQueue().onGameOver(false); //release any waiting input, effectively passing priority
|
||||
}
|
||||
|
||||
if (playbackControl != null) {
|
||||
playbackControl.onGameStopRequested();
|
||||
}
|
||||
}
|
||||
|
||||
public static void endCurrentGame() {
|
||||
if (game == null) { return; }
|
||||
|
||||
game = null;
|
||||
controller.afterGameEnd();
|
||||
}
|
||||
|
||||
public static void pause() {
|
||||
SoundSystem.instance.pause();
|
||||
//pause playback if needed
|
||||
InputQueue inputQueue = getInputQueue();
|
||||
if (inputQueue != null && inputQueue.getInput() instanceof InputPlaybackControl) {
|
||||
((InputPlaybackControl)inputQueue.getInput()).pause();
|
||||
}
|
||||
}
|
||||
|
||||
public static void resume() {
|
||||
SoundSystem.instance.resume();
|
||||
}
|
||||
|
||||
private final static boolean LOG_UIEVENTS = false;
|
||||
|
||||
// UI-related events should arrive here
|
||||
public static void fireEvent(UiEvent uiEvent) {
|
||||
if (LOG_UIEVENTS) {
|
||||
//System.out.println("UI: " + uiEvent.toString() + " \t\t " + FThreads.debugGetStackTraceItem(4, true));
|
||||
}
|
||||
uiEvents.post(uiEvent);
|
||||
}
|
||||
|
||||
public static void setupGameState(String filename) {
|
||||
int humanLife = -1;
|
||||
int aiLife = -1;
|
||||
|
||||
final Map<ZoneType, String> humanCardTexts = new EnumMap<ZoneType, String>(ZoneType.class);
|
||||
final Map<ZoneType, String> aiCardTexts = new EnumMap<ZoneType, String>(ZoneType.class);
|
||||
|
||||
String tChangePlayer = "NONE";
|
||||
String tChangePhase = "NONE";
|
||||
|
||||
try {
|
||||
final FileInputStream fstream = new FileInputStream(filename);
|
||||
final DataInputStream in = new DataInputStream(fstream);
|
||||
final BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
String temp = "";
|
||||
|
||||
while ((temp = br.readLine()) != null) {
|
||||
final String[] tempData = temp.split("=");
|
||||
if (tempData.length < 2 || temp.charAt(0) == '#') {
|
||||
continue;
|
||||
}
|
||||
|
||||
final String categoryName = tempData[0].toLowerCase();
|
||||
final String categoryValue = tempData[1];
|
||||
|
||||
switch (categoryName) {
|
||||
case "humanlife":
|
||||
humanLife = Integer.parseInt(categoryValue);
|
||||
break;
|
||||
case "ailife":
|
||||
aiLife = Integer.parseInt(categoryValue);
|
||||
break;
|
||||
case "activeplayer":
|
||||
tChangePlayer = categoryValue.trim().toLowerCase();
|
||||
break;
|
||||
case "activephase":
|
||||
tChangePhase = categoryValue;
|
||||
break;
|
||||
case "humancardsinplay":
|
||||
humanCardTexts.put(ZoneType.Battlefield, categoryValue);
|
||||
break;
|
||||
case "aicardsinplay":
|
||||
aiCardTexts.put(ZoneType.Battlefield, categoryValue);
|
||||
break;
|
||||
case "humancardsinhand":
|
||||
humanCardTexts.put(ZoneType.Hand, categoryValue);
|
||||
break;
|
||||
case "aicardsinhand":
|
||||
aiCardTexts.put(ZoneType.Hand, categoryValue);
|
||||
break;
|
||||
case "humancardsingraveyard":
|
||||
humanCardTexts.put(ZoneType.Graveyard, categoryValue);
|
||||
break;
|
||||
case "aicardsingraveyard":
|
||||
aiCardTexts.put(ZoneType.Graveyard, categoryValue);
|
||||
break;
|
||||
case "humancardsinlibrary":
|
||||
humanCardTexts.put(ZoneType.Library, categoryValue);
|
||||
break;
|
||||
case "aicardsinlibrary":
|
||||
aiCardTexts.put(ZoneType.Library, categoryValue);
|
||||
break;
|
||||
case "humancardsinexile":
|
||||
humanCardTexts.put(ZoneType.Exile, categoryValue);
|
||||
break;
|
||||
case "aicardsinexile":
|
||||
aiCardTexts.put(ZoneType.Exile, categoryValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
catch (final FileNotFoundException fnfe) {
|
||||
SOptionPane.showErrorDialog(GuiBase.getInterface(), "File not found: " + filename);
|
||||
}
|
||||
catch (final Exception e) {
|
||||
SOptionPane.showErrorDialog(GuiBase.getInterface(), "Error loading battle setup file!");
|
||||
return;
|
||||
}
|
||||
|
||||
setupGameState(humanLife, aiLife, humanCardTexts, aiCardTexts, tChangePlayer, tChangePhase);
|
||||
}
|
||||
|
||||
public static void setupGameState(final int humanLife, final int aiLife, final Map<ZoneType, String> humanCardTexts,
|
||||
final Map<ZoneType, String> aiCardTexts, final String tChangePlayer, final String tChangePhase) {
|
||||
|
||||
game.getAction().invoke(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final Player human = game.getPlayers().get(0);
|
||||
final Player ai = game.getPlayers().get(1);
|
||||
|
||||
Player newPlayerTurn = tChangePlayer.equals("human") ? newPlayerTurn = human : tChangePlayer.equals("ai") ? newPlayerTurn = ai : null;
|
||||
PhaseType newPhase = tChangePhase.trim().equalsIgnoreCase("none") ? null : PhaseType.smartValueOf(tChangePhase);
|
||||
|
||||
game.getPhaseHandler().devModeSet(newPhase, newPlayerTurn);
|
||||
|
||||
game.getTriggerHandler().suppressMode(TriggerType.ChangesZone);
|
||||
|
||||
setupPlayerState(humanLife, humanCardTexts, human);
|
||||
setupPlayerState(aiLife, aiCardTexts, ai);
|
||||
|
||||
game.getTriggerHandler().clearSuppression(TriggerType.ChangesZone);
|
||||
|
||||
game.getAction().checkStaticAbilities(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setupPlayerState(int life, Map<ZoneType, String> cardTexts, final Player p) {
|
||||
Map<ZoneType, List<Card>> humanCards = new EnumMap<ZoneType, List<Card>>(ZoneType.class);
|
||||
for (Entry<ZoneType, String> kv : cardTexts.entrySet()) {
|
||||
humanCards.put(kv.getKey(), processCardsForZone(kv.getValue().split(";"), p));
|
||||
}
|
||||
|
||||
if (life > 0) {
|
||||
p.setLife(life, null);
|
||||
}
|
||||
|
||||
for (Entry<ZoneType, List<Card>> kv : humanCards.entrySet()) {
|
||||
if (kv.getKey() == ZoneType.Battlefield) {
|
||||
for (final Card c : kv.getValue()) {
|
||||
p.getZone(ZoneType.Hand).add(c);
|
||||
p.getGame().getAction().moveToPlay(c);
|
||||
c.setSickness(false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
p.getZone(kv.getKey()).setCards(kv.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static List<Card> processCardsForZone(final String[] data, final Player player) {
|
||||
final List<Card> cl = new ArrayList<Card>();
|
||||
for (final String element : data) {
|
||||
final String[] cardinfo = element.trim().split("\\|");
|
||||
|
||||
final Card c = Card.fromPaperCard(FModel.getMagicDb().getCommonCards().getCard(cardinfo[0]), player);
|
||||
|
||||
boolean hasSetCurSet = false;
|
||||
for (final String info : cardinfo) {
|
||||
if (info.startsWith("Set:")) {
|
||||
c.setCurSetCode(info.substring(info.indexOf(':') + 1));
|
||||
hasSetCurSet = true;
|
||||
}
|
||||
else if (info.equalsIgnoreCase("Tapped:True")) {
|
||||
c.tap();
|
||||
}
|
||||
else if (info.startsWith("Counters:")) {
|
||||
final String[] counterStrings = info.substring(info.indexOf(':') + 1).split(",");
|
||||
for (final String counter : counterStrings) {
|
||||
c.addCounter(CounterType.valueOf(counter), 1, true);
|
||||
}
|
||||
}
|
||||
else if (info.equalsIgnoreCase("SummonSick:True")) {
|
||||
c.setSickness(true);
|
||||
}
|
||||
else if (info.equalsIgnoreCase("FaceDown:True")) {
|
||||
c.setState(CardCharacteristicName.FaceDown);
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasSetCurSet) {
|
||||
c.setCurSetCode(c.getMostRecentSet());
|
||||
}
|
||||
|
||||
cl.add(c);
|
||||
}
|
||||
return cl;
|
||||
}
|
||||
|
||||
/** Returns a random name from the supplied list. */
|
||||
public static String getRandomName() {
|
||||
String playerName = GuiDisplayUtil.getPlayerName();
|
||||
String aiName = NameGenerator.getRandomName("Any", "Generic", playerName);
|
||||
return aiName;
|
||||
}
|
||||
|
||||
public final static LobbyPlayer getGuiPlayer() {
|
||||
return GamePlayerUtil.getGuiPlayer();
|
||||
}
|
||||
|
||||
private static class MatchUiEventVisitor implements IUiEventVisitor<Void> {
|
||||
@Override
|
||||
public Void visit(UiEventBlockerAssigned event) {
|
||||
controller.updateSingleCard(event.blocker);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visit(UiEventAttackerDeclared event) {
|
||||
controller.updateSingleCard(event.attacker);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void receiveEvent(UiEvent evt) {
|
||||
evt.visit(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,31 +18,29 @@
|
||||
package forge.match.input;
|
||||
|
||||
import forge.interfaces.IButton;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.view.PlayerView;
|
||||
|
||||
/**
|
||||
* Manages match UI OK/Cancel button enabling and focus
|
||||
*/
|
||||
public class ButtonUtil {
|
||||
public static void update(final Input input, boolean okEnabled, boolean cancelEnabled, boolean focusOk) {
|
||||
update(input, "OK", "Cancel", okEnabled, cancelEnabled, focusOk);
|
||||
public static void update(PlayerView owner, boolean okEnabled, boolean cancelEnabled, boolean focusOk) {
|
||||
update(owner, "OK", "Cancel", okEnabled, cancelEnabled, focusOk);
|
||||
}
|
||||
public static void update(final Input input, String okLabel, String cancelLabel, boolean okEnabled, boolean cancelEnabled, boolean focusOk) {
|
||||
IGuiBase gui = input.getGui();
|
||||
PlayerView owner = input.getOwner();
|
||||
IButton btnOk = gui.getBtnOK(owner);
|
||||
IButton btnCancel = gui.getBtnCancel(owner);
|
||||
public static void update(PlayerView owner, String okLabel, String cancelLabel, boolean okEnabled, boolean cancelEnabled, boolean focusOk) {
|
||||
IButton btnOk = MatchUtil.getController().getBtnOK(owner);
|
||||
IButton btnCancel = MatchUtil.getController().getBtnCancel(owner);
|
||||
|
||||
btnOk.setText(okLabel);
|
||||
btnCancel.setText(cancelLabel);
|
||||
btnOk.setEnabled(okEnabled);
|
||||
btnCancel.setEnabled(cancelEnabled);
|
||||
if (okEnabled && focusOk) {
|
||||
gui.focusButton(btnOk);
|
||||
MatchUtil.getController().focusButton(btnOk);
|
||||
}
|
||||
else if (cancelEnabled) {
|
||||
gui.focusButton(btnCancel);
|
||||
MatchUtil.getController().focusButton(btnCancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.view.CardView;
|
||||
@@ -81,7 +82,7 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
List<Pair<Card, GameEntity>> mandatoryAttackers = CombatUtil.getMandatoryAttackers(playerAttacks, combat, defenders);
|
||||
for (Pair<Card, GameEntity> attacker : mandatoryAttackers) {
|
||||
combat.addAttacker(attacker.getLeft(), attacker.getRight());
|
||||
getGui().fireEvent(new UiEventAttackerDeclared(
|
||||
MatchUtil.fireEvent(new UiEventAttackerDeclared(
|
||||
getController().getCardView(attacker.getLeft()),
|
||||
getController().getGameEntityView(attacker.getRight())));
|
||||
}
|
||||
@@ -100,10 +101,10 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
|
||||
private void updatePrompt() {
|
||||
if (canCallBackAttackers()) {
|
||||
ButtonUtil.update(this, "OK", "Call Back", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "OK", "Call Back", true, true, true);
|
||||
}
|
||||
else {
|
||||
ButtonUtil.update(this, "OK", "Alpha Strike", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "OK", "Alpha Strike", true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +152,7 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
}
|
||||
}
|
||||
}
|
||||
getGui().updateCards(refreshCards);
|
||||
MatchUtil.updateCards(refreshCards);
|
||||
updateMessage();
|
||||
}
|
||||
|
||||
@@ -238,7 +239,7 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
combat.addAttacker(card, currentDefender, activeBand);
|
||||
activateBand(activeBand);
|
||||
|
||||
getGui().fireEvent(new UiEventAttackerDeclared(
|
||||
MatchUtil.fireEvent(new UiEventAttackerDeclared(
|
||||
getController().getCardView(card),
|
||||
getController().getGameEntityView(currentDefender)));
|
||||
}
|
||||
@@ -253,11 +254,11 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
if (canUndeclareAttacker(card)) {
|
||||
// TODO Is there no way to attacks each turn cards to attack Planeswalkers?
|
||||
combat.removeFromCombat(card);
|
||||
getGui().setUsedToPay(getController().getCardView(card), false);
|
||||
MatchUtil.setUsedToPay(getController().getCardView(card), false);
|
||||
// When removing an attacker clear the attacking band
|
||||
activateBand(null);
|
||||
|
||||
getGui().fireEvent(new UiEventAttackerDeclared(
|
||||
MatchUtil.fireEvent(new UiEventAttackerDeclared(
|
||||
getController().getCardView(card), null));
|
||||
return true;
|
||||
}
|
||||
@@ -268,10 +269,10 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
currentDefender = def;
|
||||
for (final GameEntity ge : defenders) {
|
||||
if (ge instanceof Card) {
|
||||
getGui().setUsedToPay(getController().getCardView((Card) ge), ge == def);
|
||||
MatchUtil.setUsedToPay(getController().getCardView((Card) ge), ge == def);
|
||||
}
|
||||
else if (ge instanceof Player) {
|
||||
getGui().setHighlighted(getController().getPlayerView((Player) ge), ge == def);
|
||||
MatchUtil.setHighlighted(getController().getPlayerView((Player) ge), ge == def);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,14 +282,14 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
private final void activateBand(final AttackingBand band) {
|
||||
if (activeBand != null) {
|
||||
for (final Card card : activeBand.getAttackers()) {
|
||||
getGui().setUsedToPay(getController().getCardView(card), false);
|
||||
MatchUtil.setUsedToPay(getController().getCardView(card), false);
|
||||
}
|
||||
}
|
||||
activeBand = band;
|
||||
|
||||
if (activeBand != null) {
|
||||
for (final Card card : activeBand.getAttackers()) {
|
||||
getGui().setUsedToPay(getController().getCardView(card), true);
|
||||
MatchUtil.setUsedToPay(getController().getCardView(card), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,6 +313,6 @@ public class InputAttack extends InputSyncronizedBase {
|
||||
showMessage(message);
|
||||
|
||||
updatePrompt();
|
||||
getGui().showCombat(getController().getCombat(combat)); // redraw sword icons
|
||||
MatchUtil.getController().showCombat(getController().getCombat(combat)); // redraw sword icons
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import forge.game.phase.PhaseHandler;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.view.LocalGameView;
|
||||
@@ -110,9 +111,9 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
}
|
||||
|
||||
private static void updatePromptForAwait(final LocalGameView gameView) {
|
||||
InputNone inputNone = new InputNone(gameView);
|
||||
inputNone.getGui().showPromptMessage(inputNone.getOwner(), "Waiting for opponent...");
|
||||
ButtonUtil.update(inputNone, false, false, false);
|
||||
PlayerView playerView = gameView.getLocalPlayerView();
|
||||
MatchUtil.getController().showPromptMessage(playerView, "Waiting for opponent...");
|
||||
ButtonUtil.update(playerView, false, false, false);
|
||||
}
|
||||
|
||||
public static void cancelAwaitNextInput() {
|
||||
@@ -173,11 +174,11 @@ public abstract class InputBase implements java.io.Serializable, Input {
|
||||
|
||||
// to remove need for CMatchUI dependence
|
||||
protected final void showMessage(final String message) {
|
||||
getGui().showPromptMessage(getOwner(), message);
|
||||
MatchUtil.getController().showPromptMessage(getOwner(), message);
|
||||
}
|
||||
|
||||
protected final void flashIncorrectAction() {
|
||||
getGui().flashIncorrectAction();
|
||||
MatchUtil.getController().flashIncorrectAction();
|
||||
}
|
||||
|
||||
protected String getTurnPhasePriorityMessage(final Game game) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.util.ThreadUtil;
|
||||
@@ -74,7 +75,7 @@ public class InputBlock extends InputSyncronizedBase {
|
||||
@Override
|
||||
protected final void showMessage() {
|
||||
// could add "Reset Blockers" button
|
||||
ButtonUtil.update(this, true, false, true);
|
||||
ButtonUtil.update(getOwner(), true, false, true);
|
||||
|
||||
if (currentAttacker == null) {
|
||||
showMessage("Select another attacker to declare blockers for.");
|
||||
@@ -85,7 +86,7 @@ public class InputBlock extends InputSyncronizedBase {
|
||||
showMessage(message);
|
||||
}
|
||||
|
||||
getGui().showCombat(getController().getCombat(combat));
|
||||
MatchUtil.getController().showCombat(getController().getCombat(combat));
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
@@ -114,7 +115,7 @@ public class InputBlock extends InputSyncronizedBase {
|
||||
boolean isCorrectAction = false;
|
||||
if (triggerEvent != null && triggerEvent.getButton() == 3 && card.getController() == defender) {
|
||||
combat.removeFromCombat(card);
|
||||
getGui().fireEvent(new UiEventBlockerAssigned(
|
||||
MatchUtil.fireEvent(new UiEventBlockerAssigned(
|
||||
getController().getCardView(card), (CardView) null));
|
||||
isCorrectAction = true;
|
||||
}
|
||||
@@ -130,7 +131,7 @@ public class InputBlock extends InputSyncronizedBase {
|
||||
if (combat.isBlocking(card, currentAttacker)) {
|
||||
//if creature already blocking current attacker, remove blocker from combat
|
||||
combat.removeBlockAssignment(currentAttacker, card);
|
||||
getGui().fireEvent(new UiEventBlockerAssigned(
|
||||
MatchUtil.fireEvent(new UiEventBlockerAssigned(
|
||||
getController().getCardView(card), (CardView) null));
|
||||
isCorrectAction = true;
|
||||
}
|
||||
@@ -138,7 +139,7 @@ public class InputBlock extends InputSyncronizedBase {
|
||||
isCorrectAction = CombatUtil.canBlock(currentAttacker, card, combat);
|
||||
if (isCorrectAction) {
|
||||
combat.addBlocker(currentAttacker, card);
|
||||
getGui().fireEvent(new UiEventBlockerAssigned(
|
||||
MatchUtil.fireEvent(new UiEventBlockerAssigned(
|
||||
getController().getCardView(card),
|
||||
getController().getCardView(currentAttacker)));
|
||||
}
|
||||
@@ -157,7 +158,7 @@ public class InputBlock extends InputSyncronizedBase {
|
||||
private void setCurrentAttacker(final Card card) {
|
||||
currentAttacker = card;
|
||||
for (final Card c : combat.getAttackers()) {
|
||||
getGui().setUsedToPay(getController().getCardView(c), card == c);
|
||||
MatchUtil.setUsedToPay(getController().getCardView(c), card == c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class InputConfirm extends InputSyncronizedBase {
|
||||
/** {@inheritDoc} */
|
||||
@Override
|
||||
protected final void showMessage() {
|
||||
ButtonUtil.update(this, yesButtonText, noButtonText, true, true, defaultYes);
|
||||
ButtonUtil.update(getOwner(), yesButtonText, noButtonText, true, true, defaultYes);
|
||||
showMessage(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import forge.game.Game;
|
||||
import forge.game.card.Card;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.util.Lang;
|
||||
@@ -72,11 +73,11 @@ public class InputConfirmMulligan extends InputSyncronizedBase {
|
||||
}
|
||||
|
||||
if (isCommander) {
|
||||
ButtonUtil.update(this, "Keep", "Exile", true, false, true);
|
||||
ButtonUtil.update(getOwner(), "Keep", "Exile", true, false, true);
|
||||
sb.append("Will you keep your hand or choose some cards to exile those and draw one less card?");
|
||||
}
|
||||
else {
|
||||
ButtonUtil.update(this, "Keep", "Mulligan", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "Keep", "Mulligan", true, true, true);
|
||||
sb.append("Do you want to keep your hand?");
|
||||
}
|
||||
|
||||
@@ -101,7 +102,7 @@ public class InputConfirmMulligan extends InputSyncronizedBase {
|
||||
if (isCommander) {
|
||||
// Clear the "selected" icon after clicking the done button
|
||||
for (final Card c : this.selected) {
|
||||
getGui().setUsedToPay(getController().getCardView(c), false);
|
||||
MatchUtil.setUsedToPay(getController().getCardView(c), false);
|
||||
}
|
||||
}
|
||||
stop();
|
||||
@@ -137,14 +138,14 @@ public class InputConfirmMulligan extends InputSyncronizedBase {
|
||||
|
||||
if (isCommander) { // allow to choose cards for partial paris
|
||||
if (selected.contains(c0)) {
|
||||
getGui().setUsedToPay(getController().getCardView(c0), false);
|
||||
MatchUtil.setUsedToPay(getController().getCardView(c0), false);
|
||||
selected.remove(c0);
|
||||
}
|
||||
else {
|
||||
getGui().setUsedToPay(getController().getCardView(c0), true);
|
||||
MatchUtil.setUsedToPay(getController().getCardView(c0), true);
|
||||
selected.add(c0);
|
||||
}
|
||||
ButtonUtil.update(this, "Keep", "Exile", true, !selected.isEmpty(), true);
|
||||
ButtonUtil.update(getOwner(), "Keep", "Exile", true, !selected.isEmpty(), true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import forge.game.card.Card;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.util.ThreadUtil;
|
||||
import forge.view.PlayerView;
|
||||
@@ -65,7 +66,7 @@ public class InputLockUI implements Input {
|
||||
private final Runnable showMessageFromEdt = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ButtonUtil.update(InputLockUI.this, "", "", false, false, false);
|
||||
ButtonUtil.update(InputLockUI.this.getOwner(), "", "", false, false, false);
|
||||
showMessage("Waiting for actions...");
|
||||
}
|
||||
};
|
||||
@@ -75,7 +76,7 @@ public class InputLockUI implements Input {
|
||||
}
|
||||
|
||||
protected void showMessage(String message) {
|
||||
getGui().showPromptMessage(getOwner(), message);
|
||||
MatchUtil.getController().showPromptMessage(getOwner(), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
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() {
|
||||
}
|
||||
}
|
||||
@@ -57,10 +57,10 @@ public class InputPassPriority extends InputSyncronizedBase {
|
||||
showMessage(getTurnPhasePriorityMessage(player.getGame()));
|
||||
chosenSa = null;
|
||||
if (getController().canUndoLastAction()) { //allow undoing with cancel button if can undo last action
|
||||
ButtonUtil.update(this, "OK", "Undo", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "OK", "Undo", true, true, true);
|
||||
}
|
||||
else { //otherwise allow ending turn with cancel button
|
||||
ButtonUtil.update(this, "OK", "End Turn", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "OK", "End Turn", true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import forge.game.player.Player;
|
||||
import forge.game.replacement.ReplacementEffect;
|
||||
import forge.game.spellability.AbilityManaPart;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.player.HumanPlay;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.util.Evaluator;
|
||||
@@ -53,13 +54,13 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
|
||||
//if player is floating mana, show mana pool to make it easier to use that mana
|
||||
wasFloatingMana = !player.getManaPool().isEmpty();
|
||||
zoneToRestore = wasFloatingMana ? getGui().showManaPool(getController().getPlayerView(player)) : null;
|
||||
zoneToRestore = wasFloatingMana ? MatchUtil.getController().showManaPool(getController().getPlayerView(player)) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
if (wasFloatingMana) { //hide mana pool if it was shown due to floating mana
|
||||
getGui().hideManaPool(getController().getPlayerView(player), zoneToRestore);
|
||||
MatchUtil.getController().hideManaPool(getController().getPlayerView(player), zoneToRestore);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -371,10 +372,10 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
|
||||
protected void updateButtons() {
|
||||
if (supportAutoPay()) {
|
||||
ButtonUtil.update(this, "Auto", "Cancel", false, true, false);
|
||||
ButtonUtil.update(getOwner(), "Auto", "Cancel", false, true, false);
|
||||
}
|
||||
else {
|
||||
ButtonUtil.update(this, "", "Cancel", false, true, false);
|
||||
ButtonUtil.update(getOwner(), "", "Cancel", false, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -393,7 +394,7 @@ public abstract class InputPayMana extends InputSyncronizedBase {
|
||||
canPayManaCost = proc.getResult();
|
||||
}
|
||||
if (canPayManaCost) { //enabled Auto button if mana cost can be paid
|
||||
ButtonUtil.update(this, "Auto", "Cancel", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "Auto", "Cancel", true, true, true);
|
||||
}
|
||||
}
|
||||
showMessage(getMessage());
|
||||
|
||||
@@ -55,10 +55,10 @@ public class InputPlaybackControl extends InputSyncronizedBase implements InputS
|
||||
private void setPause(boolean pause) {
|
||||
isPaused = pause;
|
||||
if (isPaused) {
|
||||
ButtonUtil.update(this, "Resume", "Step", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "Resume", "Step", true, true, true);
|
||||
}
|
||||
else {
|
||||
ButtonUtil.update(this, "Pause", isFast ? "1x Speed" : "10x Faster", true, true, true);
|
||||
ButtonUtil.update(getOwner(), "Pause", isFast ? "1x Speed" : "10x Faster", true, true, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.google.common.collect.Iterables;
|
||||
|
||||
import forge.game.GameEntity;
|
||||
import forge.game.card.Card;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
|
||||
public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyncronizedBase {
|
||||
@@ -44,7 +45,7 @@ public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyn
|
||||
@Override
|
||||
public final void showMessage() {
|
||||
showMessage(getMessage());
|
||||
ButtonUtil.update(this, hasEnoughTargets(), allowCancel, true);
|
||||
ButtonUtil.update(getOwner(), hasEnoughTargets(), allowCancel, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -74,14 +75,14 @@ public abstract class InputSelectManyBase<T extends GameEntity> extends InputSyn
|
||||
|
||||
protected void onSelectStateChanged(final GameEntity c, final boolean newState) {
|
||||
if (c instanceof Card) {
|
||||
getGui().setUsedToPay(getController().getCardView((Card) c), newState); // UI supports card highlighting though this abstraction-breaking mechanism
|
||||
MatchUtil.setUsedToPay(getController().getCardView((Card) c), newState); // UI supports card highlighting though this abstraction-breaking mechanism
|
||||
}
|
||||
}
|
||||
|
||||
private void resetUsedToPay() {
|
||||
for (final GameEntity c : getSelected()) {
|
||||
if (c instanceof Card) {
|
||||
getGui().setUsedToPay(getController().getCardView((Card) c), false);
|
||||
MatchUtil.setUsedToPay(getController().getCardView((Card) c), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import forge.game.card.Card;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.spellability.SpellAbility;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.player.PlayerControllerHuman;
|
||||
import forge.util.ITriggerEvent;
|
||||
import forge.util.gui.SGuiChoose;
|
||||
@@ -78,19 +79,19 @@ public final class InputSelectTargets extends InputSyncronizedBase {
|
||||
if (!tgt.isMinTargetsChosen(sa.getHostCard(), sa) || tgt.isDividedAsYouChoose()) {
|
||||
if (mandatory && tgt.hasCandidates(sa, true)) {
|
||||
// Player has to click on a target
|
||||
ButtonUtil.update(this, false, false, false);
|
||||
ButtonUtil.update(getOwner(), false, false, false);
|
||||
}
|
||||
else {
|
||||
ButtonUtil.update(this, false, true, false);
|
||||
ButtonUtil.update(getOwner(), false, true, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (mandatory && tgt.hasCandidates(sa, true)) {
|
||||
// Player has to click on a target or ok
|
||||
ButtonUtil.update(this, true, false, true);
|
||||
ButtonUtil.update(getOwner(), true, false, true);
|
||||
}
|
||||
else {
|
||||
ButtonUtil.update(this, true, true, true);
|
||||
ButtonUtil.update(getOwner(), true, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -238,7 +239,7 @@ public final class InputSelectTargets extends InputSyncronizedBase {
|
||||
private void addTarget(final GameEntity ge) {
|
||||
sa.getTargets().add(ge);
|
||||
if (ge instanceof Card) {
|
||||
getGui().setUsedToPay(getController().getCardView((Card) ge), true);
|
||||
MatchUtil.setUsedToPay(getController().getCardView((Card) ge), true);
|
||||
lastTarget = (Card) ge;
|
||||
}
|
||||
final Integer val = targetDepth.get(ge);
|
||||
@@ -255,7 +256,7 @@ public final class InputSelectTargets extends InputSyncronizedBase {
|
||||
private void done() {
|
||||
for (final GameEntity c : targetDepth.keySet()) {
|
||||
if (c instanceof Card) {
|
||||
getGui().setUsedToPay(getController().getCardView((Card) c), false);
|
||||
MatchUtil.setUsedToPay(getController().getCardView((Card) c), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -300,9 +300,9 @@ public class FModel {
|
||||
gauntletData = data0;
|
||||
}
|
||||
|
||||
public static GauntletMini getGauntletMini(final IGuiBase gui) {
|
||||
public static GauntletMini getGauntletMini() {
|
||||
if (gauntlet == null) {
|
||||
gauntlet = new GauntletMini(gui);
|
||||
gauntlet = new GauntletMini();
|
||||
}
|
||||
return gauntlet;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import forge.game.player.IGameEntitiesFactory;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.player.PlayerController;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.util.GuiDisplayUtil;
|
||||
|
||||
public class LobbyPlayerHuman extends LobbyPlayer implements IGameEntitiesFactory {
|
||||
@@ -33,7 +34,7 @@ public class LobbyPlayerHuman extends LobbyPlayer implements IGameEntitiesFactor
|
||||
}
|
||||
|
||||
public void hear(LobbyPlayer player, String message) {
|
||||
gui.hear(player, message);
|
||||
MatchUtil.getController().hear(player, message);
|
||||
}
|
||||
|
||||
public IGuiBase getGui() {
|
||||
|
||||
@@ -82,6 +82,7 @@ import forge.game.zone.ZoneType;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.PaperCard;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.match.input.ButtonUtil;
|
||||
import forge.match.input.Input;
|
||||
import forge.match.input.InputAttack;
|
||||
@@ -89,7 +90,6 @@ import forge.match.input.InputBase;
|
||||
import forge.match.input.InputBlock;
|
||||
import forge.match.input.InputConfirm;
|
||||
import forge.match.input.InputConfirmMulligan;
|
||||
import forge.match.input.InputNone;
|
||||
import forge.match.input.InputPassPriority;
|
||||
import forge.match.input.InputPayMana;
|
||||
import forge.match.input.InputProliferate;
|
||||
@@ -169,14 +169,14 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
}
|
||||
|
||||
public boolean isUiSetToSkipPhase(final Player turn, final PhaseType phase) {
|
||||
return !getGui().stopAtPhase(gameView.getPlayerView(turn), phase);
|
||||
return !MatchUtil.getController().stopAtPhase(gameView.getPlayerView(turn), phase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses GUI to learn which spell the player (human in our case) would like to play
|
||||
*/
|
||||
public SpellAbility getAbilityToPlay(final List<SpellAbility> abilities, final ITriggerEvent triggerEvent) {
|
||||
final int choice = getGui().getAbilityToPlay(gameView.getSpellAbilityViews(abilities), triggerEvent);
|
||||
final int choice = MatchUtil.getController().getAbilityToPlay(gameView.getSpellAbilityViews(abilities), triggerEvent);
|
||||
return gameView.getSpellAbility(choice);
|
||||
}
|
||||
|
||||
@@ -258,7 +258,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if ((attacker.hasKeyword("Trample") && defender != null) || (blockers.size() > 1)) {
|
||||
final CardView vAttacker = gameView.getCardView(attacker);
|
||||
final GameEntityView vDefender = gameView.getGameEntityView(defender);
|
||||
final Map<CardView, Integer> result = getGui().getDamageToAssign(vAttacker, vBlockers, damageDealt, vDefender, overrideOrder);
|
||||
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());
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (max <= 0) {
|
||||
return new ArrayList<Card>();
|
||||
}
|
||||
|
||||
|
||||
StringBuilder builder = new StringBuilder("Select ");
|
||||
if (min == 0) {
|
||||
builder.append("up to ");
|
||||
@@ -325,10 +325,10 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
if (max == 1) {
|
||||
Card singleChosen = chooseSingleEntityForEffect(sourceList, sa, title, isOptional);
|
||||
return singleChosen == null ? Lists.<Card>newArrayList() : Lists.newArrayList(singleChosen);
|
||||
}
|
||||
}
|
||||
|
||||
MatchUtil.getController().setPanelSelection(gameView.getCardView(sa.getHostCard()));
|
||||
|
||||
getGui().setPanelSelection(gameView.getCardView(sa.getHostCard()));
|
||||
|
||||
// try to use InputSelectCardsFromList when possible
|
||||
boolean cardsAreInMyHandOrBattlefield = true;
|
||||
for (Card c : sourceList) {
|
||||
@@ -496,7 +496,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
@Override
|
||||
public List<Card> orderBlockers(final Card attacker, final List<Card> blockers) {
|
||||
final CardView vAttacker = gameView.getCardView(attacker);
|
||||
getGui().setPanelSelection(vAttacker);
|
||||
MatchUtil.getController().setPanelSelection(vAttacker);
|
||||
final List<CardView> choices = SGuiChoose.order(getGui(), "Choose Damage Order for " + vAttacker, "Damaged First", gameView.getCardViews(blockers), vAttacker);
|
||||
return gameView.getCards(choices);
|
||||
}
|
||||
@@ -504,7 +504,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
@Override
|
||||
public List<Card> orderBlocker(final Card attacker, final Card blocker, final List<Card> oldBlockers) {
|
||||
final CardView vAttacker = gameView.getCardView(attacker);
|
||||
getGui().setPanelSelection(vAttacker);
|
||||
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));
|
||||
return gameView.getCards(choices);
|
||||
}
|
||||
@@ -512,7 +512,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
@Override
|
||||
public List<Card> orderAttackers(final Card blocker, final List<Card> attackers) {
|
||||
final CardView vBlocker = gameView.getCardView(blocker);
|
||||
getGui().setPanelSelection(vBlocker);
|
||||
MatchUtil.getController().setPanelSelection(vBlocker);
|
||||
final List<CardView> choices = SGuiChoose.order(getGui(), "Choose Damage Order for " + vBlocker, "Damaged First", gameView.getCardViews(attackers), vBlocker);
|
||||
return gameView.getCards(choices);
|
||||
}
|
||||
@@ -733,9 +733,9 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
Iterables.removeAll(types, invalidTypes);
|
||||
}
|
||||
if (isOptional) {
|
||||
return SGuiChoose.oneOrNone(getGui(), "Choose a " + kindOfType.toLowerCase() + " type", types);
|
||||
return SGuiChoose.oneOrNone(getGui(), "Choose a " + kindOfType.toLowerCase() + " type", types);
|
||||
}
|
||||
return SGuiChoose.one(getGui(), "Choose a " + kindOfType.toLowerCase() + " type", types);
|
||||
return SGuiChoose.one(getGui(), "Choose a " + kindOfType.toLowerCase() + " type", types);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -767,7 +767,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());
|
||||
getGui().fireEvent(new UiEventAttackerDeclared(gameView.getCardView(attacker.getLeft()), gameView.getGameEntityView(attacker.getRight())));
|
||||
MatchUtil.fireEvent(new UiEventAttackerDeclared(gameView.getCardView(attacker.getLeft()), gameView.getGameEntityView(attacker.getRight())));
|
||||
}
|
||||
try {
|
||||
Thread.sleep(FControlGamePlayback.combatDelay);
|
||||
@@ -797,10 +797,10 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
//allow user to cancel auto-pass
|
||||
InputBase.cancelAwaitNextInput(); //don't overwrite prompt with awaiting opponent
|
||||
PhaseType phase = getAutoPassUntilPhase();
|
||||
InputNone inputNone = new InputNone(gameView);
|
||||
getGui().showPromptMessage(inputNone.getOwner(), "Yielding until " + (phase == PhaseType.CLEANUP ? "end of turn" : phase.nameForUi.toString()) +
|
||||
PlayerView playerView = gameView.getLocalPlayerView();
|
||||
MatchUtil.getController().showPromptMessage(playerView, "Yielding until " + (phase == PhaseType.CLEANUP ? "end of turn" : phase.nameForUi.toString()) +
|
||||
".\nYou may cancel this yield to take an action.");
|
||||
ButtonUtil.update(inputNone, false, true, false);
|
||||
ButtonUtil.update(playerView, false, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,9 +816,9 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
super.autoPassCancel();
|
||||
|
||||
//prevent prompt getting stuck on yielding message while actually waiting for next input opportunity
|
||||
InputNone inputNone = new InputNone(gameView);
|
||||
getGui().showPromptMessage(inputNone.getOwner(), "");
|
||||
ButtonUtil.update(inputNone, false, false, false);
|
||||
PlayerView playerView = gameView.getLocalPlayerView();
|
||||
MatchUtil.getController().showPromptMessage(playerView, "");
|
||||
ButtonUtil.update(playerView, false, false, false);
|
||||
InputBase.awaitNextInput(gameView);
|
||||
}
|
||||
|
||||
@@ -1163,9 +1163,9 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
@Override
|
||||
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers, HashMap<String, Object> runParams) {
|
||||
if (possibleReplacers.size() == 1) {
|
||||
return possibleReplacers.get(0);
|
||||
return possibleReplacers.get(0);
|
||||
}
|
||||
return SGuiChoose.one(getGui(), prompt, possibleReplacers);
|
||||
return SGuiChoose.one(getGui(), prompt, possibleReplacers);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1327,8 +1327,8 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
|
||||
public boolean isGuiPlayer() {
|
||||
return lobbyPlayer == GamePlayerUtil.getGuiPlayer();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* What follows are the View methods.
|
||||
*/
|
||||
@@ -1720,7 +1720,7 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
public void setViewAllCards(final boolean canViewAll) {
|
||||
mayLookAtAllCards = canViewAll;
|
||||
for (final Player p : game.getPlayers()) {
|
||||
getGui().updateCards(getCardViews(p.getAllCards()));
|
||||
MatchUtil.updateCards(getCardViews(p.getAllCards()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import forge.game.spellability.SpellAbilityStackInstance;
|
||||
import forge.game.spellability.TargetRestrictions;
|
||||
import forge.game.zone.Zone;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.match.input.InputSelectTargets;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.gui.SGuiChoose;
|
||||
@@ -138,12 +139,12 @@ public class TargetSelection {
|
||||
for (Card card : validTargets) {
|
||||
playersWithValidTargets.put(controller.getPlayerView(card.getController()), null);
|
||||
}
|
||||
if (controller.getGui().openZones(zone, playersWithValidTargets)) {
|
||||
if (MatchUtil.getController().openZones(zone, playersWithValidTargets)) {
|
||||
InputSelectTargets inp = new InputSelectTargets(controller, validTargets, ability, mandatory);
|
||||
inp.showAndWait();
|
||||
choiceResult = !inp.hasCancelled();
|
||||
bTargetingDone = inp.hasPressedOk();
|
||||
controller.getGui().restoreOldZones(playersWithValidTargets);
|
||||
MatchUtil.getController().restoreOldZones(playersWithValidTargets);
|
||||
}
|
||||
else {
|
||||
// for every other case an all-purpose GuiChoose
|
||||
|
||||
@@ -3,7 +3,6 @@ package forge.quest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import forge.FThreads;
|
||||
import forge.deck.Deck;
|
||||
import forge.deck.DeckGroup;
|
||||
import forge.deck.DeckSection;
|
||||
@@ -13,6 +12,7 @@ import forge.game.GameType;
|
||||
import forge.game.Match;
|
||||
import forge.game.player.RegisteredPlayer;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
@@ -29,7 +29,12 @@ public class QuestDraftUtils {
|
||||
if (lastGame.getMatch().isMatchOver()) {
|
||||
matchInProgress = false;
|
||||
}
|
||||
gui.continueMatch(matchInProgress ? lastGame.getMatch() : null);
|
||||
if (matchInProgress) {
|
||||
MatchUtil.continueMatch();
|
||||
}
|
||||
else {
|
||||
MatchUtil.endCurrentGame();
|
||||
}
|
||||
}
|
||||
|
||||
public static void completeDraft(DeckGroup finishedDraft) {
|
||||
@@ -184,15 +189,15 @@ public class QuestDraftUtils {
|
||||
if (matchInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
gui.enableOverlay();
|
||||
|
||||
|
||||
MatchUtil.getController().enableOverlay();
|
||||
|
||||
DraftMatchup nextMatch = matchups.remove(0);
|
||||
|
||||
matchInProgress = true;
|
||||
|
||||
if (!nextMatch.hasHumanPlayer) {
|
||||
gui.disableOverlay();
|
||||
MatchUtil.getController().disableOverlay();
|
||||
waitForUserInput = false;
|
||||
aiMatchInProgress = true;
|
||||
}
|
||||
@@ -207,14 +212,8 @@ public class QuestDraftUtils {
|
||||
rules.setGamesPerMatch(3);
|
||||
rules.setManaBurn(FModel.getPreferences().getPrefBoolean(FPref.UI_MANABURN));
|
||||
rules.canCloneUseTargetsImage = FModel.getPreferences().getPrefBoolean(FPref.UI_CLONE_MODE_SOURCE);
|
||||
|
||||
final Match match = new Match(rules, nextMatch.matchStarter);
|
||||
FThreads.invokeInEdtLater(gui, new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
gui.startGame(match);
|
||||
}
|
||||
});
|
||||
|
||||
MatchUtil.getController().startNewMatch(new Match(rules, nextMatch.matchStarter));
|
||||
}
|
||||
|
||||
public static void continueMatches(final IGuiBase gui) {
|
||||
|
||||
@@ -38,6 +38,7 @@ import forge.interfaces.IButton;
|
||||
import forge.interfaces.IGuiBase;
|
||||
import forge.item.IPaperCard;
|
||||
import forge.item.PaperToken;
|
||||
import forge.match.MatchUtil;
|
||||
import forge.model.FModel;
|
||||
import forge.player.GamePlayerUtil;
|
||||
import forge.properties.ForgePreferences.FPref;
|
||||
@@ -589,7 +590,7 @@ public class QuestUtil {
|
||||
FThreads.invokeInEdtNowOrLater(gui, new Runnable(){
|
||||
@Override
|
||||
public void run() {
|
||||
gui.startGame(mc);
|
||||
MatchUtil.startGame(mc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.Map;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import forge.GuiBase;
|
||||
import forge.events.UiEvent;
|
||||
import forge.game.event.GameEvent;
|
||||
import forge.interfaces.IGuiBase;
|
||||
@@ -19,6 +20,8 @@ import forge.properties.ForgePreferences.FPref;
|
||||
*
|
||||
*/
|
||||
public class SoundSystem {
|
||||
public static final SoundSystem instance = new SoundSystem(GuiBase.getInterface());
|
||||
|
||||
public static final int DELAY = 30;
|
||||
|
||||
private static final IAudioClip emptySound = new NoSoundClip();
|
||||
@@ -28,7 +31,7 @@ public class SoundSystem {
|
||||
private final IGuiBase gui;
|
||||
private final EventVisualizer visualizer;
|
||||
|
||||
public SoundSystem(final IGuiBase gui) {
|
||||
private SoundSystem(final IGuiBase gui) {
|
||||
this.gui = gui;
|
||||
this.visualizer = new EventVisualizer(GamePlayerUtil.getGuiPlayer());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user