updates to VStack are never empty

This commit is contained in:
Maxmtg
2013-04-23 18:38:23 +00:00
parent 45a9f0985a
commit f5ac535af3
4 changed files with 47 additions and 39 deletions

View File

@@ -23,7 +23,6 @@ import forge.game.player.LobbyPlayer;
import forge.game.player.LobbyPlayerHuman; import forge.game.player.LobbyPlayerHuman;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.player.PlayerStatistics; import forge.game.player.PlayerStatistics;
import forge.game.player.PlayerType;
import forge.gui.InputProxy; import forge.gui.InputProxy;
import forge.gui.framework.EDocID; import forge.gui.framework.EDocID;
import forge.gui.framework.SDisplayUtil; import forge.gui.framework.SDisplayUtil;
@@ -38,7 +37,6 @@ import forge.gui.match.controllers.CStack;
import forge.gui.match.nonsingleton.VField; import forge.gui.match.nonsingleton.VField;
import forge.gui.match.views.VAntes; import forge.gui.match.views.VAntes;
import forge.properties.ForgePreferences.FPref; import forge.properties.ForgePreferences.FPref;
import forge.util.Aggregates;
/** /**
* TODO: Write javadoc for this type. * TODO: Write javadoc for this type.
@@ -163,31 +161,44 @@ public class MatchController {
} }
try { try {
HumanPlayer localHuman = (HumanPlayer) Aggregates.firstFieldEquals(currentGame.getPlayers(), Player.Accessors.FN_GET_TYPE, PlayerType.HUMAN);
HumanPlayer localHuman = null;
for(Player p : currentGame.getPlayers()) {
if ( p.getLobbyPlayer() != FControl.SINGLETON_INSTANCE.getLobby().getGuiPlayer())
continue;
localHuman = (HumanPlayer) p;
break;
}
if (null == localHuman)
throw new IllegalStateException("Cannot start a game without a human yet!");
FControl.SINGLETON_INSTANCE.setPlayer(localHuman); FControl.SINGLETON_INSTANCE.setPlayer(localHuman);
// The UI controls should use these game data as models
CMatchUI.SINGLETON_INSTANCE.initMatch(currentGame.getRegisteredPlayers(), localHuman); CMatchUI.SINGLETON_INSTANCE.initMatch(currentGame.getRegisteredPlayers(), localHuman);
CDock.SINGLETON_INSTANCE.onGameStarts(currentGame, localHuman); CDock.SINGLETON_INSTANCE.onGameStarts(currentGame, localHuman);
CStack.SINGLETON_INSTANCE.setModel(currentGame.getStack());
CLog.SINGLETON_INSTANCE.init(currentGame.getGameLog()); CLog.SINGLETON_INSTANCE.setModel(currentGame.getGameLog());
currentGame.getGameLog().addObserver(CLog.SINGLETON_INSTANCE);
CCombat.SINGLETON_INSTANCE.setModel(currentGame); CCombat.SINGLETON_INSTANCE.setModel(currentGame);
Singletons.getModel().getPreferences().actuateMatchPreferences(); Singletons.getModel().getPreferences().actuateMatchPreferences();
Singletons.getControl().changeState(FControl.Screens.MATCH_SCREEN); Singletons.getControl().changeState(FControl.Screens.MATCH_SCREEN);
SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc()); SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc());
InputProxy inputControl = CMessage.SINGLETON_INSTANCE.getInputControl(); // black magic still
inputControl.setMatch(this); InputProxy inputProxy = CMessage.SINGLETON_INSTANCE.getInputControl();
input.addObserver(inputControl); inputProxy.setMatch(this);
currentGame.getStack().addObserver(inputControl); input.addObserver(inputProxy);
// models shall notify controllers of changes
currentGame.getStack().addObserver(inputProxy);
currentGame.getStack().addObserver(CStack.SINGLETON_INSTANCE); currentGame.getStack().addObserver(CStack.SINGLETON_INSTANCE);
currentGame.getPhaseHandler().addObserver(inputControl); currentGame.getPhaseHandler().addObserver(inputProxy);
currentGame.getGameLog().addObserver(CLog.SINGLETON_INSTANCE);
// some observers are set in CMatchUI.initMatch // some observers are set in CMatchUI.initMatch
final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed; final boolean canRandomFoil = Singletons.getModel().getPreferences().getPrefBoolean(FPref.UI_RANDOM_FOIL) && gameType == GameType.Constructed;
GameNew.newGame(this, startConditions, currentGame, canRandomFoil); GameNew.newGame(this, startConditions, currentGame, canRandomFoil);

View File

@@ -47,7 +47,7 @@ public enum CLog implements ICDoc, Observer {
* TODO: Write javadoc for this method. * TODO: Write javadoc for this method.
* @param gameLog * @param gameLog
*/ */
public void init(GameLog gameLog) { public void setModel(GameLog gameLog) {
model = gameLog; model = gameLog;
} }

View File

@@ -21,6 +21,8 @@ public enum CStack implements ICDoc, Observer {
/** */ /** */
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private MagicStack model;
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.gui.framework.ICDoc#getCommandOnSelect() * @see forge.gui.framework.ICDoc#getCommandOnSelect()
*/ */
@@ -36,25 +38,17 @@ public enum CStack implements ICDoc, Observer {
public void initialize() { public void initialize() {
} }
/* (non-Javadoc) private final Runnable upd = new Runnable() { @Override public void run() {
* @see forge.gui.framework.ICDoc#update() SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc());
*/
public void update(MagicStack model) {
VStack.SINGLETON_INSTANCE.updateStack(model); VStack.SINGLETON_INSTANCE.updateStack(model);
} } };
/* (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(final Observable arg0, Object arg1) { public void update(final Observable arg0, Object arg1) {
if ( arg0 instanceof MagicStack ) update();
{
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() {
SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc());
update((MagicStack)arg0);
} });
}
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -62,7 +56,9 @@ public enum CStack implements ICDoc, Observer {
*/ */
@Override @Override
public void update() { public void update() {
// won't update without a model! FThreads.invokeInEdtNowOrLater(upd);
} }
public void setModel(MagicStack model) { this.model = model; }
} }

View File

@@ -86,13 +86,7 @@ public class CField implements ICDoc {
public void mousePressed(final MouseEvent e) { cardclickAction(e); } }; public void mousePressed(final MouseEvent e) { cardclickAction(e); } };
// Hand, Graveyard, Library, Flashback, Exile zones, attached to hand.
private final Observer observerZones = new Observer() {
@Override
public void update(final Observable a, final Object b) {
FThreads.invokeInEdtNowOrLater(updateZonesRunnable);
}
};
private final Runnable updateZonesRunnable = new Runnable() { @Override public void run() { CField.this.view.updateZones(CField.this.player); } }; private final Runnable updateZonesRunnable = new Runnable() { @Override public void run() { CField.this.view.updateZones(CField.this.player); } };
private final Runnable updateDetailsRunnable = new Runnable() { @Override public void run() { CField.this.view.updateDetails(CField.this.player); } }; private final Runnable updateDetailsRunnable = new Runnable() { @Override public void run() { CField.this.view.updateDetails(CField.this.player); } };
@@ -103,6 +97,13 @@ public class CField implements ICDoc {
FThreads.invokeInEdtNowOrLater(updateDetailsRunnable); FThreads.invokeInEdtNowOrLater(updateDetailsRunnable);
} }
}; };
// Hand, Graveyard, Library, Flashback, Exile zones, attached to hand.
private final Observer observerZones = new Observer() {
@Override
public void update(final Observable a, final Object b) {
FThreads.invokeInEdtNowOrLater(updateZonesRunnable);
}
};
// Card play area, attached to battlefield zone. // Card play area, attached to battlefield zone.
private final Observer observerPlay = new Observer() { private final Observer observerPlay = new Observer() {