Move ViewWinLose invocation to EDT

This commit is contained in:
Maxmtg
2013-04-06 07:15:23 +00:00
parent 8c0c8633b8
commit 5ef8762b00

View File

@@ -9,6 +9,7 @@ import java.util.Map.Entry;
import forge.Constant.Preferences; import forge.Constant.Preferences;
import forge.FThreads;
import forge.Singletons; import forge.Singletons;
import forge.control.FControl; import forge.control.FControl;
import forge.control.input.InputControl; import forge.control.input.InputControl;
@@ -91,7 +92,7 @@ public class MatchController {
throw new RuntimeException("Game is not over yet."); throw new RuntimeException("Game is not over yet.");
} }
GameOutcome result = new GameOutcome(reason, game.getRegisteredPlayers()); final GameOutcome result = new GameOutcome(reason, game.getRegisteredPlayers());
result.setTurnsPlayed(game.getPhaseHandler().getTurn()); result.setTurnsPlayed(game.getPhaseHandler().getTurn());
gamesPlayed.add(result); gamesPlayed.add(result);
@@ -100,10 +101,10 @@ public class MatchController {
game.getGameLog().add("Final", result.getWinner() + " won", 0); game.getGameLog().add("Final", result.getWinner() + " won", 0);
// add result entries to the game log // add result entries to the game log
LobbyPlayer human = Singletons.getControl().getPlayer().getLobbyPlayer(); final LobbyPlayer human = Singletons.getControl().getPlayer().getLobbyPlayer();
String title = result.isWinner(human) ? "You Win" : "You Lost";
List<String> outcomes = new ArrayList<String>(); final List<String> outcomes = new ArrayList<String>();
for (Entry<LobbyPlayer, PlayerStatistics> p : result) { for (Entry<LobbyPlayer, PlayerStatistics> p : result) {
String whoHas = p.getKey().equals(human) ? "You have" : p.getKey().getName() + " has"; String whoHas = p.getKey().equals(human) ? "You have" : p.getKey().getName() + " has";
String outcome = String.format("%s %s", whoHas, p.getValue().getOutcome().toString()); String outcome = String.format("%s %s", whoHas, p.getValue().getOutcome().toString());
@@ -113,14 +114,17 @@ public class MatchController {
int humanWins = getGamesWonBy(human); int humanWins = getGamesWonBy(human);
int humanLosses = getPlayedGames().size() - humanWins; int humanLosses = getPlayedGames().size() - humanWins;
String statsSummary = "Won: " + humanWins + ", Lost: " + humanLosses; final String statsSummary = "Won: " + humanWins + ", Lost: " + humanLosses;
game.getGameLog().add("Final", statsSummary, 0); game.getGameLog().add("Final", statsSummary, 0);
ViewWinLose v = new ViewWinLose(this); FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() {
v.setTitle(title); String title = result.isWinner(human) ? "You Win" : "You Lost";
v.setOutcomes(outcomes); ViewWinLose v = new ViewWinLose(MatchController.this);
v.setStatsSummary(statsSummary); v.setTitle(title);
v.setOutcomes(outcomes);
v.setStatsSummary(statsSummary);
} });
} }