Lots of small fixes and cleanup for the GUI refactoring.

This commit is contained in:
elcnesh
2014-09-10 12:08:48 +00:00
parent b608d7e7a3
commit 574e12d2e3
24 changed files with 2435 additions and 2002 deletions

View File

@@ -67,7 +67,6 @@ import forge.model.FModel;
import forge.player.GamePlayerUtil;
import forge.player.LobbyPlayerHuman;
import forge.player.PlayerControllerHuman;
import forge.player.PlayerControllerLocal;
import forge.properties.ForgeConstants;
import forge.properties.ForgePreferences;
import forge.properties.ForgePreferences.FPref;
@@ -95,6 +94,7 @@ import forge.util.NameGenerator;
import forge.view.FFrame;
import forge.view.FView;
import forge.view.IGameView;
import forge.view.LocalGameView;
import forge.view.PlayerView;
/**
@@ -452,12 +452,23 @@ public enum FControl implements KeyEventDispatcher {
final LobbyPlayer me = getGuiPlayer();
for (final Player p : game.getPlayers()) {
if (p.getLobbyPlayer().equals(me)) {
this.gameView = (IGameView) p.getController();
fcVisitor = new FControlGameEventHandler((PlayerControllerHuman) p.getController());
final PlayerControllerHuman controller = (PlayerControllerHuman) p.getController();
this.gameView = controller.getGameView();
this.fcVisitor = new FControlGameEventHandler(GuiBase.getInterface(), controller.getGameView());
break;
}
}
if (this.gameView == null) {
// Watch game but do not participate
final LocalGameView gameView = new LocalGameView(game);
this.gameView = gameView;
this.fcVisitor = new FControlGameEventHandler(GuiBase.getInterface(), gameView);
this.playbackControl = new FControlGamePlayback(GuiBase.getInterface(), gameView);
this.playbackControl.setGame(game);
this.game.subscribeToEvents(playbackControl);
}
attachToGame(this.gameView);
// It's important to run match in a different thread to allow GUI inputs to be invoked from inside game.
@@ -523,20 +534,12 @@ public enum FControl implements KeyEventDispatcher {
// Listen to DuelOutcome event to show ViewWinLose
game0.subscribeToEvents(fcVisitor);
// Add playback controls to match if needed
if (localPlayer == null) {
// Create dummy controller
final PlayerControllerHuman controller =
new PlayerControllerLocal(game, null, humanLobbyPlayer, GuiBase.getInterface());
playbackControl = new FControlGamePlayback(controller);
playbackControl.setGame(game);
game0.subscribeToEvents(playbackControl);
}
// per player observers were set in CMatchUI.SINGLETON_INSTANCE.initMatch
//Set Field shown to current player.
final VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(localPlayer);
SDisplayUtil.showTab(nextField);
if (localPlayer != null) {
final VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(localPlayer);
SDisplayUtil.showTab(nextField);
}
}
/* (non-Javadoc)

View File

@@ -168,7 +168,7 @@ public enum CMatchUI implements ICDoc, IMenuProvider {
int i = 0;
for (final PlayerView p : sortedPlayers) {
if (p.getLobbyPlayer() == localPlayer) {
if (localPlayer == null || p.getLobbyPlayer() == localPlayer) {
VHand newHand = new VHand(EDocID.Hands[i], p);
newHand.getLayoutControl().initialize();
hands.add(newHand);
@@ -176,11 +176,6 @@ public enum CMatchUI implements ICDoc, IMenuProvider {
i++;
}
if (hands.isEmpty()) { // add empty hand for matches without human
VHand newHand = new VHand(EDocID.Hands[0], null);
newHand.getLayoutControl().initialize();
hands.add(newHand);
}
view.setHandViews(hands);
}
@@ -277,7 +272,8 @@ public enum CMatchUI implements ICDoc, IMenuProvider {
*/
public final boolean stopAtPhase(final PlayerView turn, final PhaseType phase) {
VField vf = getFieldViewFor(turn);
PhaseLabel label = vf.getPhaseIndicator().getLabelFor(phase);
PhaseLabel label = vf.getPhaseIndicator()
.getLabelFor(phase);
return label == null || label.getEnabled();
}
@@ -367,7 +363,10 @@ public enum CMatchUI implements ICDoc, IMenuProvider {
} else if (zt == ZoneType.Ante) {
CAntes.SINGLETON_INSTANCE.update();
} else {
getFieldViewFor(owner).getDetailsPanel().updateZones();
final VField vf = getFieldViewFor(owner);
if (vf != null) {
vf.getDetailsPanel().updateZones();
}
}
}
}

View File

@@ -193,7 +193,7 @@ public class VAssignDamage {
DamageTarget dt = new DamageTarget(null, new FLabel.Builder().text("0").fontSize(18).fontAlign(SwingConstants.CENTER).build());
this.damage.put(null, dt);
this.defenders.add(dt);
final CardView fakeCard;
CardView fakeCard = null;
if (defender instanceof CardView)
fakeCard = (CardView)defender;
else if (defender instanceof PlayerView) {
@@ -201,11 +201,10 @@ public class VAssignDamage {
fakeCard.getOriginal().setName(this.defender.toString());
final PlayerView p = (PlayerView)defender;
fakeCard.setOwner(p);
fakeCard.setController(p);
fakeCard.getOriginal().setImageKey(CMatchUI.SINGLETON_INSTANCE.avatarImages.get(p.getLobbyPlayer()));
} else {
fakeCard = new CardView(true);
fakeCard.getOriginal().setName(this.defender.toString());
}
addPanelForDefender(pnlDefenders, fakeCard);
}

View File

@@ -20,6 +20,7 @@ package forge.screens.match.views;
import javax.swing.JPanel;
import net.miginfocom.swing.MigLayout;
import forge.game.zone.ZoneType;
import forge.gui.framework.DragCell;
import forge.gui.framework.DragTab;
import forge.gui.framework.EDocID;
@@ -66,7 +67,7 @@ public class VCommand implements IVDoc<CCommand> {
// TODO player is hard-coded into tabletop...should be dynamic
// (haven't looked into it too deeply). Doublestrike 12-04-12
tabletop = new PlayArea(scroller, id0 == EDocID.COMMAND_0, player);
tabletop = new PlayArea(scroller, id0 == EDocID.COMMAND_0, player, ZoneType.Command);
control = new CCommand(player, this);

View File

@@ -29,6 +29,7 @@ import javax.swing.border.LineBorder;
import net.miginfocom.swing.MigLayout;
import forge.LobbyPlayer;
import forge.game.zone.ZoneType;
import forge.gui.framework.DragCell;
import forge.gui.framework.DragTab;
import forge.gui.framework.EDocID;
@@ -95,7 +96,7 @@ public class VField implements IVDoc<CField> {
// TODO player is hard-coded into tabletop...should be dynamic
// (haven't looked into it too deeply). Doublestrike 12-04-12
tabletop = new PlayArea(scroller, id0 == EDocID.FIELD_1, player);
tabletop = new PlayArea(scroller, id0 == EDocID.FIELD_1, player, ZoneType.Battlefield);
control = new CField(player, this, playerViewer);

View File

@@ -29,6 +29,7 @@ import com.google.common.collect.Lists;
import forge.FThreads;
import forge.GuiBase;
import forge.game.zone.ZoneType;
import forge.screens.match.CMatchUI;
import forge.screens.match.controllers.CPrompt;
import forge.toolbox.FScrollPane;
@@ -78,6 +79,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
private int stackSpacingX, stackSpacingY;
private final PlayerView model;
private final ZoneType zone;
/**
* <p>
@@ -88,11 +90,12 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
* @param mirror
* @param player
*/
public PlayArea(final FScrollPane scrollPane, final boolean mirror, final PlayerView player) {
public PlayArea(final FScrollPane scrollPane, final boolean mirror, final PlayerView player, final ZoneType zone) {
super(scrollPane);
this.setBackground(Color.white);
this.mirror = mirror;
this.model = player;
this.zone = zone;
}
private final CardStackRow collectAllLands() {
@@ -593,13 +596,13 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
*/
public void setupPlayZone() {
FThreads.assertExecutedByEdt(GuiBase.getInterface(), true);
recalculateCardPanels(model);
recalculateCardPanels(model, zone);
}
private void recalculateCardPanels(final PlayerView model) {
private void recalculateCardPanels(final PlayerView model, final ZoneType zone) {
final List<CardView> modelCopy;
synchronized (model) {
modelCopy = Lists.newArrayList(model.getBfCards());
modelCopy = Lists.newArrayList(model.getCards(zone));
}
final List<CardView> oldCards = Lists.newArrayList();