FControl in response to player control changes redraws hands panel

This commit is contained in:
Maxmtg
2013-05-27 13:19:00 +00:00
parent b88acfe51f
commit e752136294
4 changed files with 36 additions and 6 deletions

View File

@@ -45,6 +45,7 @@ import forge.game.ai.AiProfileUtil;
import forge.game.event.CardsAntedEvent; import forge.game.event.CardsAntedEvent;
import forge.game.event.DuelFinishedEvent; import forge.game.event.DuelFinishedEvent;
import forge.game.event.Event; import forge.game.event.Event;
import forge.game.event.PlayerControlEvent;
import forge.game.player.LobbyPlayer; import forge.game.player.LobbyPlayer;
import forge.game.player.Player; import forge.game.player.Player;
import forge.gui.GuiDialog; import forge.gui.GuiDialog;
@@ -66,6 +67,7 @@ import forge.gui.match.controllers.CLog;
import forge.gui.match.controllers.CMessage; import forge.gui.match.controllers.CMessage;
import forge.gui.match.controllers.CStack; import forge.gui.match.controllers.CStack;
import forge.gui.match.nonsingleton.VField; import forge.gui.match.nonsingleton.VField;
import forge.gui.match.nonsingleton.VHand;
import forge.gui.match.views.VAntes; import forge.gui.match.views.VAntes;
import forge.gui.toolbox.CardFaceSymbols; import forge.gui.toolbox.CardFaceSymbols;
import forge.gui.toolbox.FSkin; import forge.gui.toolbox.FSkin;
@@ -419,6 +421,14 @@ public enum FControl {
msg.append(kv.getKey().getName()).append(" ante: ").append(kv.getValue()).append(nl); msg.append(kv.getKey().getName()).append(" ante: ").append(kv.getValue()).append(nl);
} }
GuiDialog.message(msg.toString(), "Ante"); GuiDialog.message(msg.toString(), "Ante");
} else if ( ev instanceof PlayerControlEvent ) {
FThreads.invokeInEdtNowOrLater(new Runnable() { @Override public void run() {
CMatchUI.SINGLETON_INSTANCE.initHandViews(getLobby().getGuiPlayer());
VMatchUI.SINGLETON_INSTANCE.populate();
for(VHand h : VMatchUI.SINGLETON_INSTANCE.getHands()) {
h.getLayoutControl().updateHand();
}
} });
} }
} }
} }

View File

@@ -34,6 +34,8 @@ import forge.Singletons;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.LobbyPlayer; import forge.game.player.LobbyPlayer;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.zone.PlayerZone;
import forge.game.zone.ZoneType;
import forge.gui.framework.EDocID; import forge.gui.framework.EDocID;
import forge.gui.match.controllers.CDetail; import forge.gui.match.controllers.CDetail;
import forge.gui.match.controllers.CMessage; import forge.gui.match.controllers.CMessage;
@@ -58,6 +60,7 @@ public enum CMatchUI {
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private List<Player> sortedPlayers; private List<Player> sortedPlayers;
private VMatchUI view;
private ImageIcon getPlayerAvatar(final Player p, final int defaultIndex) { private ImageIcon getPlayerAvatar(final Player p, final int defaultIndex) {
LobbyPlayer lp = p.getLobbyPlayer(); LobbyPlayer lp = p.getLobbyPlayer();
@@ -83,6 +86,8 @@ public enum CMatchUI {
* @param numHandPanels int * @param numHandPanels int
*/ */
public void initMatch(final List<Player> players, LobbyPlayer localPlayer) { public void initMatch(final List<Player> players, LobbyPlayer localPlayer) {
view = VMatchUI.SINGLETON_INSTANCE;
// TODO fix for use with multiplayer // TODO fix for use with multiplayer
final String[] indices = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(","); final String[] indices = Singletons.getModel().getPreferences().getPref(FPref.UI_AVATARS).split(",");
@@ -111,8 +116,8 @@ public enum CMatchUI {
} }
// Replace old instances // Replace old instances
VMatchUI.SINGLETON_INSTANCE.setCommandViews(commands); view.setCommandViews(commands);
VMatchUI.SINGLETON_INSTANCE.setFieldViews(fields); view.setFieldViews(fields);
VPlayers.SINGLETON_INSTANCE.init(players); VPlayers.SINGLETON_INSTANCE.init(players);
@@ -121,9 +126,15 @@ public enum CMatchUI {
public void initHandViews(LobbyPlayer localPlayer) { public void initHandViews(LobbyPlayer localPlayer) {
final List<VHand> hands = new ArrayList<VHand>(); final List<VHand> hands = new ArrayList<VHand>();
final Iterable<VHand> oldHands = view.getHands();
int i = 0; int i = 0;
for (Player p : sortedPlayers) { for (Player p : sortedPlayers) {
PlayerZone hand = p.getZone(ZoneType.Hand);
for(VHand vh : oldHands)
hand.deleteObserver(vh.getLayoutControl());
if (p.getLobbyPlayer() == localPlayer) { if (p.getLobbyPlayer() == localPlayer) {
VHand newHand = new VHand(EDocID.Hands[i], p); VHand newHand = new VHand(EDocID.Hands[i], p);
newHand.getLayoutControl().initialize(); newHand.getLayoutControl().initialize();
@@ -137,7 +148,7 @@ public enum CMatchUI {
newHand.getLayoutControl().initialize(); newHand.getLayoutControl().initialize();
hands.add(newHand); hands.add(newHand);
} }
VMatchUI.SINGLETON_INSTANCE.setHandViews(hands); view.setHandViews(hands);
} }
private List<Player> shiftPlayersPlaceLocalFirst(final List<Player> players, LobbyPlayer localPlayer) { private List<Player> shiftPlayersPlaceLocalFirst(final List<Player> players, LobbyPlayer localPlayer) {
@@ -163,7 +174,7 @@ public enum CMatchUI {
// This method is in the top-level controller because it affects ALL fields // This method is in the top-level controller because it affects ALL fields
// (not just one). // (not just one).
public void resetAllPhaseButtons() { public void resetAllPhaseButtons() {
for (final VField v : VMatchUI.SINGLETON_INSTANCE.getFieldViews()) { for (final VField v : view.getFieldViews()) {
v.resetPhaseButtons(); v.resetPhaseButtons();
} }
} }
@@ -175,7 +186,7 @@ public enum CMatchUI {
public VField getFieldViewFor(Player p) { public VField getFieldViewFor(Player p) {
int idx = getPlayerIndex(p); int idx = getPlayerIndex(p);
return idx < 0 ? null : VMatchUI.SINGLETON_INSTANCE.getFieldViews().get(idx); return idx < 0 ? null :view.getFieldViews().get(idx);
} }
/** /**

View File

@@ -162,4 +162,12 @@ public enum VMatchUI implements IVTopLevelUI {
public void setCommandViews(List<VCommand> lstCommands0) { public void setCommandViews(List<VCommand> lstCommands0) {
this.lstCommands = lstCommands0; this.lstCommands = lstCommands0;
} }
/**
* TODO: Write javadoc for this method.
* @return
*/
public Iterable<VHand> getHands() {
return lstHands;
}
} }

View File

@@ -76,7 +76,8 @@ public class CHand implements ICDoc, Observer {
if (player != null) if (player != null)
player.getZone(ZoneType.Hand).addObserver(this); player.getZone(ZoneType.Hand).addObserver(this);
view.getHandArea().addMouseListener(madCardClick); HandArea area = view.getHandArea();
area.addMouseListener(madCardClick);
} }
/** /**