Refactor GameLog in new GUI code.

This commit is contained in:
elcnesh
2014-09-03 10:47:51 +00:00
parent b40c999cce
commit 608cae2572
6 changed files with 64 additions and 50 deletions

View File

@@ -516,7 +516,7 @@ public enum FControl implements KeyEventDispatcher {
CDock.SINGLETON_INSTANCE.setModel(game0);
CStack.SINGLETON_INSTANCE.setModel(game0, localPlayer);
CPlayers.SINGLETON_INSTANCE.setModel(game0);
CLog.SINGLETON_INSTANCE.setModel(game0.getGameLog());
CLog.SINGLETON_INSTANCE.setModel(game0);
actuateMatchPreferences();
VAntes.SINGLETON_INSTANCE.setModel(players);

View File

@@ -11,9 +11,11 @@ import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import net.miginfocom.swing.MigLayout;
import org.apache.commons.lang3.StringUtils;
import forge.LobbyPlayer;
import forge.UiCommand;
import forge.game.GameLog;
import forge.game.GameLogEntry;
import forge.game.GameLogEntryType;
import forge.gui.SOverlayUtils;
@@ -105,7 +107,7 @@ public class ViewWinLose implements IWinLoseView<FButton> {
// Assemble game log scroller.
final FTextArea txtLog = new FTextArea();
txtLog.setText(game.getGameLog().getLogText(null).replace("[COMPUTER]", "[AI]"));
txtLog.setText(StringUtils.join(game.getLogEntries(null), "\r\n").replace("[COMPUTER]", "[AI]"));
txtLog.setFont(FSkin.getFont(14));
txtLog.setFocusable(true); // allow highlighting and copying of log
@@ -218,14 +220,12 @@ public class ViewWinLose implements IWinLoseView<FButton> {
}
private void showGameOutcomeSummary() {
GameLog log = game.getGameLog();
for (GameLogEntry o : log.getLogEntriesExact(GameLogEntryType.GAME_OUTCOME))
for (final GameLogEntry o : game.getLogEntriesExact(GameLogEntryType.GAME_OUTCOME))
pnlOutcomes.add(new FLabel.Builder().text(o.message).fontSize(14).build(), "h 20!");
}
private void showPlayerScores() {
GameLog log = game.getGameLog();
for (GameLogEntry o : log.getLogEntriesExact(GameLogEntryType.MATCH_RESULTS)) {
for (final GameLogEntry o : game.getLogEntriesExact(GameLogEntryType.MATCH_RESULTS)) {
lblStats.setText(removePlayerTypeFromLogMessage(o.message));
}
}

View File

@@ -2,9 +2,9 @@ package forge.screens.match.controllers;
import forge.UiCommand;
import forge.FThreads;
import forge.game.GameLog;
import forge.gui.framework.ICDoc;
import forge.screens.match.views.VLog;
import forge.view.IGameView;
import java.util.Observable;
import java.util.Observer;
@@ -19,7 +19,8 @@ public enum CLog implements ICDoc, Observer {
/** */
SINGLETON_INSTANCE;
private GameLog model;
private IGameView model;
/* (non-Javadoc)
* @see forge.gui.framework.ICDoc#getCommandOnSelect()
*/
@@ -45,18 +46,18 @@ public enum CLog implements ICDoc, Observer {
/**
* TODO: Write javadoc for this method.
* @param gameLog
* @param game0
*/
public void setModel(GameLog gameLog) {
model = gameLog;
model.addObserver(this);
public void setModel(final IGameView game0) {
model = game0;
model.addLogObserver(this);
}
/* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/
@Override
public void update(Observable o, Object arg) {
public void update(final Observable o, final Object arg) {
update();
}

View File

@@ -17,9 +17,14 @@
*/
package forge.screens.match.views;
import java.util.List;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import com.google.common.collect.Lists;
import forge.game.GameLog;
import forge.game.GameLogEntry;
import forge.game.GameLogEntryType;
import forge.gui.framework.DragCell;
@@ -32,12 +37,7 @@ import forge.screens.match.GameLogPanel;
import forge.screens.match.controllers.CLog;
import forge.toolbox.FSkin;
import forge.toolbox.FSkin.SkinFont;
import net.miginfocom.swing.MigLayout;
import javax.swing.*;
import java.util.ArrayList;
import java.util.List;
import forge.view.IGameView;
/**
* Assembles Swing components of game log report.
@@ -50,10 +50,10 @@ public enum VLog implements IVDoc<CLog> {
// Keeps a record of log entries currently displayed so we can
// easily identify new entries to be added to the game log.
private List<GameLogEntry> displayedLogEntries = new ArrayList<GameLogEntry>();
private final List<GameLogEntry> displayedLogEntries = Lists.newArrayList();
// Used to determine when a new game has started.
private GameLog gameLogModel = null;
private IGameView gameLogModel = null;
// Fields used with interface IVDoc
private DragCell parentCell;
@@ -122,12 +122,12 @@ public enum VLog implements IVDoc<CLog> {
* <p>
* This is an Observer update method.
* <p>
* @param activeGameLogModel contains list of log entries.
* @param model contains list of log entries.
*/
public void updateConsole(GameLog activeGameLogModel) {
public void updateConsole(final IGameView model) {
if (isGameLogConsoleVisible()) {
resetDisplayIfNewGame(activeGameLogModel);
displayNewGameLogEntries(activeGameLogModel);
resetDisplayIfNewGame(model);
displayNewGameLogEntries(model);
// Important : refreshLayout() needs to be called every update.
refreshLayout();
}
@@ -137,11 +137,11 @@ public enum VLog implements IVDoc<CLog> {
return parentCell.getSelected().equals(this);
}
private void resetDisplayIfNewGame(GameLog activeGameLogModel) {
if (this.gameLogModel != activeGameLogModel) {
private void resetDisplayIfNewGame(final IGameView model) {
if (this.gameLogModel != model) {
gameLog.reset();
this.displayedLogEntries.clear();
this.gameLogModel = activeGameLogModel;
this.gameLogModel = model;
}
}
@@ -164,17 +164,17 @@ public enum VLog implements IVDoc<CLog> {
p.add(gameLog, "w 10:100%, h 100%");
}
private void displayNewGameLogEntries(GameLog activeGameLogModel) {
List<GameLogEntry> newLogEntries = Lists.reverse(getNewGameLogEntries(activeGameLogModel));
private void displayNewGameLogEntries(final IGameView model) {
List<GameLogEntry> newLogEntries = Lists.reverse(getNewGameLogEntries(model));
if (newLogEntries.size() > 0) {
addNewLogEntriesToJPanel(newLogEntries);
}
}
private List<GameLogEntry> getNewGameLogEntries(GameLog activeGameLogModel) {
private List<GameLogEntry> getNewGameLogEntries(final IGameView model) {
String logEntryType = FModel.getPreferences().getPref(FPref.DEV_LOG_ENTRY_TYPE);
GameLogEntryType logVerbosityFilter = GameLogEntryType.valueOf(logEntryType);
List<GameLogEntry> logEntries = activeGameLogModel.getLogEntries(logVerbosityFilter);
List<GameLogEntry> logEntries = model.getLogEntries(logVerbosityFilter);
// Set subtraction - remove all log entries from new list which are already displayed.
logEntries.removeAll(this.displayedLogEntries);
return logEntries;