removed references to match controller via singletons where in non-ui classes (UI may safely use singletons.fcontrol)

This commit is contained in:
Maxmtg
2013-05-08 21:12:35 +00:00
parent cd02a01180
commit 13e89a6abf
7 changed files with 38 additions and 33 deletions

View File

@@ -49,7 +49,7 @@ public class RestartGameEffect extends SpellAbilityEffect {
playerLibraries.put(p, newLibrary); playerLibraries.put(p, newLibrary);
} }
GameNew.restartGame(Singletons.getControl().getMatch(), game, sa.getActivatingPlayer(), playerLibraries); GameNew.restartGame(game.getMatch(), game, sa.getActivatingPlayer(), playerLibraries);
} }
/* (non-Javadoc) /* (non-Javadoc)

View File

@@ -24,8 +24,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.zone.ZoneType;
import forge.gui.InputProxy;
import forge.gui.framework.EDocID; import forge.gui.framework.EDocID;
import forge.gui.framework.SDisplayUtil; import forge.gui.framework.SDisplayUtil;
import forge.gui.match.CMatchUI; import forge.gui.match.CMatchUI;
@@ -186,23 +184,23 @@ public class MatchController {
CStack.SINGLETON_INSTANCE.setModel(currentGame.getStack()); CStack.SINGLETON_INSTANCE.setModel(currentGame.getStack());
CLog.SINGLETON_INSTANCE.setModel(currentGame.getGameLog()); CLog.SINGLETON_INSTANCE.setModel(currentGame.getGameLog());
CCombat.SINGLETON_INSTANCE.setModel(currentGame); CCombat.SINGLETON_INSTANCE.setModel(currentGame);
CMessage.SINGLETON_INSTANCE.setModel(match);
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 inputProxy = CMessage.SINGLETON_INSTANCE.getInputControl(); CMessage.SINGLETON_INSTANCE.getInputControl().setMatch(match);
inputProxy.setMatch(match);
// models shall notify controllers of changes // 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(inputProxy);
currentGame.getGameLog().addObserver(CLog.SINGLETON_INSTANCE); currentGame.getGameLog().addObserver(CLog.SINGLETON_INSTANCE);
// some observers were set in CMatchUI.initMatch // some observers were set in CMatchUI.initMatch
// black magic still // black magic still
match.getInput().addObserver(inputProxy);
VAntes.SINGLETON_INSTANCE.setModel(currentGame.getRegisteredPlayers()); VAntes.SINGLETON_INSTANCE.setModel(currentGame.getRegisteredPlayers());
@@ -211,7 +209,6 @@ public class MatchController {
} }
// per player observers were set in CMatchUI.SINGLETON_INSTANCE.initMatch // per player observers were set in CMatchUI.SINGLETON_INSTANCE.initMatch
CMessage.SINGLETON_INSTANCE.updateGameInfo(match);
} }
/** /**

View File

@@ -246,6 +246,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
switch(this.getPhase()) { switch(this.getPhase()) {
case UNTAP: case UNTAP:
//SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc()); //SDisplayUtil.showTab(EDocID.REPORT_STACK.getDoc());
updateObservers();
PhaseUtil.handleUntap(game); PhaseUtil.handleUntap(game);
break; break;

View File

@@ -26,7 +26,6 @@ import com.google.common.base.Predicate;
import forge.Card; import forge.Card;
import forge.CardLists; import forge.CardLists;
import forge.CardPredicates.Presets; import forge.CardPredicates.Presets;
import forge.Singletons;
import forge.card.cost.Cost; import forge.card.cost.Cost;
import forge.card.mana.ManaCost; import forge.card.mana.ManaCost;
import forge.card.spellability.Ability; import forge.card.spellability.Ability;
@@ -41,7 +40,6 @@ import forge.game.player.AIPlayer;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
import forge.gui.match.CMatchUI; import forge.gui.match.CMatchUI;
import forge.gui.match.controllers.CMessage;
import forge.gui.match.nonsingleton.VField.PhaseLabel; import forge.gui.match.nonsingleton.VField.PhaseLabel;
/** /**
@@ -86,8 +84,6 @@ public class PhaseUtil {
final PhaseHandler ph = game.getPhaseHandler(); final PhaseHandler ph = game.getPhaseHandler();
final Player turn = ph.getPlayerTurn(); final Player turn = ph.getPlayerTurn();
CMessage.SINGLETON_INSTANCE.updateGameInfo(Singletons.getControl().getMatch());
game.getCombat().reset(turn); game.getCombat().reset(turn);
// Tokens starting game in play should suffer from Sum. Sickness // Tokens starting game in play should suffer from Sum. Sickness

View File

@@ -45,8 +45,11 @@ public class InputProxy implements Observer {
private static final boolean INPUT_DEBUG = false; private static final boolean INPUT_DEBUG = false;
public void setMatch(MatchController matchController) { public void setMatch(MatchController match0) {
match = matchController; match = match0;
match.getCurrentGame().getStack().addObserver(this);
match.getCurrentGame().getPhaseHandler().addObserver(this);
match.getInput().addObserver(this);
} }
@Override @Override

View File

@@ -23,6 +23,8 @@ import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter; import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JButton; import javax.swing.JButton;
@@ -38,7 +40,7 @@ import forge.gui.match.views.VMessage;
* *
* <br><br><i>(C at beginning of class name denotes a control class.)</i> * <br><br><i>(C at beginning of class name denotes a control class.)</i>
*/ */
public enum CMessage implements ICDoc { public enum CMessage implements ICDoc, Observer {
/** */ /** */
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
@@ -67,6 +69,7 @@ public enum CMessage implements ICDoc {
} }
} }
}; };
private MatchController match;
private void _initButton(JButton button, ActionListener onClick) { private void _initButton(JButton button, ActionListener onClick) {
// remove to ensure listeners don't accumulate over many initializations // remove to ensure listeners don't accumulate over many initializations
@@ -96,17 +99,6 @@ public enum CMessage implements ICDoc {
VMessage.SINGLETON_INSTANCE.getTarMessage().setText(s0); VMessage.SINGLETON_INSTANCE.getTarMessage().setText(s0);
} }
/** Updates counter label in message area.
* @param match
* @param gameState */
public void updateGameInfo(MatchController match) {
VMessage.SINGLETON_INSTANCE.getLblGames().setText(
match.getGameType().toString() + ": Game #"
+ (match.getPlayedGames().size() + 1)
+ " of " + match.getGamesPerMatch()
+ ", turn " + match.getCurrentGame().getPhaseHandler().getTurn());
}
/** Flashes animation on input panel if play is currently waiting on input. */ /** Flashes animation on input panel if play is currently waiting on input. */
public void remind() { public void remind() {
SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE); SDisplayUtil.remind(VMessage.SINGLETON_INSTANCE);
@@ -120,6 +112,18 @@ public enum CMessage implements ICDoc {
return null; return null;
} }
/* (non-Javadoc)
* @see java.util.Observer#update(java.util.Observable, java.lang.Object)
*/
@Override
public void update(Observable o, Object arg) {
VMessage.SINGLETON_INSTANCE.getLblGames().setText(
match.getGameType().toString() + ": Game #"
+ (match.getPlayedGames().size() + 1)
+ " of " + match.getGamesPerMatch()
+ ", turn " + match.getCurrentGame().getPhaseHandler().getTurn());
}
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.gui.framework.ICDoc#update() * @see forge.gui.framework.ICDoc#update()
*/ */
@@ -130,4 +134,14 @@ public enum CMessage implements ICDoc {
lastFocusedButton.requestFocusInWindow(); lastFocusedButton.requestFocusInWindow();
} }
} }
/**
* TODO: Write javadoc for this method.
* @param match
*/
public void setModel(MatchController match0) {
match = match0;
match.getCurrentGame().getPhaseHandler().addObserver(this);
update(null, null);
}
} }

View File

@@ -18,7 +18,6 @@
package forge.gui.match.views; package forge.gui.match.views;
import java.awt.Dimension; import java.awt.Dimension;
import java.util.Iterator;
import java.util.Observable; import java.util.Observable;
import java.util.Observer; import java.util.Observer;
import java.util.SortedSet; import java.util.SortedSet;
@@ -172,11 +171,6 @@ public enum VAntes implements IVDoc<CAntes>, Observer {
picPanel.setCard(c0); picPanel.setCard(c0);
} }
/** @return {@link forge.Card} */
public Card getCard() {
return card;
}
@Override @Override
public int compareTo(AntePanel o) { public int compareTo(AntePanel o) {
return o.card.getUniqueNumber() - card.getUniqueNumber(); return o.card.getUniqueNumber() - card.getUniqueNumber();