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); CDock.SINGLETON_INSTANCE.setModel(game0);
CStack.SINGLETON_INSTANCE.setModel(game0, localPlayer); CStack.SINGLETON_INSTANCE.setModel(game0, localPlayer);
CPlayers.SINGLETON_INSTANCE.setModel(game0); CPlayers.SINGLETON_INSTANCE.setModel(game0);
CLog.SINGLETON_INSTANCE.setModel(game0.getGameLog()); CLog.SINGLETON_INSTANCE.setModel(game0);
actuateMatchPreferences(); actuateMatchPreferences();
VAntes.SINGLETON_INSTANCE.setModel(players); VAntes.SINGLETON_INSTANCE.setModel(players);

View File

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

View File

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

View File

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

View File

@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Observer;
import org.apache.commons.lang3.Range; import org.apache.commons.lang3.Range;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -36,7 +37,7 @@ import forge.deck.DeckSection;
import forge.events.UiEventAttackerDeclared; import forge.events.UiEventAttackerDeclared;
import forge.game.Game; import forge.game.Game;
import forge.game.GameEntity; import forge.game.GameEntity;
import forge.game.GameLog; import forge.game.GameLogEntry;
import forge.game.GameLogEntryType; import forge.game.GameLogEntryType;
import forge.game.GameObject; import forge.game.GameObject;
import forge.game.GameOutcome; import forge.game.GameOutcome;
@@ -1175,13 +1176,13 @@ public class PlayerControllerHuman extends PlayerController implements IGameView
} }
} }
@Override @Override
public CardShields chooseRegenerationShield(Card c) { public CardShields chooseRegenerationShield(Card c) {
if (c.getShield().size() < 2) { if (c.getShield().size() < 2) {
return Iterables.getFirst(c.getShield(), null); return Iterables.getFirst(c.getShield(), null);
} }
return SGuiChoose.one("Choose a regeneration shield:", c.getShield()); return SGuiChoose.one("Choose a regeneration shield:", c.getShield());
} }
@Override @Override
public List<PaperCard> chooseCardsYouWonToAddToDeck(List<PaperCard> losses) { public List<PaperCard> chooseCardsYouWonToAddToDeck(List<PaperCard> losses) {
@@ -1361,13 +1362,21 @@ public class PlayerControllerHuman extends PlayerController implements IGameView
} }
} }
/* (non-Javadoc)
* @see forge.view.IGameView#getGameLog()
*/
@Override @Override
public GameLog getGameLog() { public void addLogObserver(final Observer o) {
return game.getGameLog(); game.getGameLog().addObserver(o);
} }
@Override
public List<GameLogEntry> getLogEntries(final GameLogEntryType maxLogLevel) {
return game.getGameLog().getLogEntries(maxLogLevel);
}
@Override
public List<GameLogEntry> getLogEntriesExact(final GameLogEntryType logLevel) {
return game.getGameLog().getLogEntriesExact(logLevel);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.view.IGameView#getGuiRegisteredPlayer(forge.LobbyPlayer) * @see forge.view.IGameView#getGuiRegisteredPlayer(forge.LobbyPlayer)
*/ */

View File

@@ -1,9 +1,11 @@
package forge.view; package forge.view;
import java.util.List; import java.util.List;
import java.util.Observer;
import forge.LobbyPlayer; import forge.LobbyPlayer;
import forge.game.GameLog; import forge.game.GameLogEntry;
import forge.game.GameLogEntryType;
import forge.game.GameOutcome; import forge.game.GameOutcome;
import forge.game.GameType; import forge.game.GameType;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
@@ -41,11 +43,13 @@ public interface IGameView {
public abstract CombatView getCombat(); public abstract CombatView getCombat();
// the following methods should eventually be replaced by methods returning public abstract void addLogObserver(Observer o);
public abstract List<GameLogEntry> getLogEntries(final GameLogEntryType maxLogLevel);
public abstract List<GameLogEntry> getLogEntriesExact(final GameLogEntryType logLevel);
// the following method should eventually be replaced by methods returning
// View classes // View classes
@Deprecated @Deprecated
public abstract GameLog getGameLog();
@Deprecated
public abstract RegisteredPlayer getGuiRegisteredPlayer(LobbyPlayer p); public abstract RegisteredPlayer getGuiRegisteredPlayer(LobbyPlayer p);
public abstract List<PlayerView> getPlayers(); public abstract List<PlayerView> getPlayers();