Some more minor fixes for GUI refactoring (restores full playback control).

This commit is contained in:
elcnesh
2014-09-14 06:15:11 +00:00
parent 295423050b
commit a31e273147
6 changed files with 50 additions and 52 deletions

View File

@@ -30,9 +30,9 @@ import forge.control.FControl;
import forge.deck.CardPool; import forge.deck.CardPool;
import forge.error.BugReportDialog; import forge.error.BugReportDialog;
import forge.events.UiEvent; import forge.events.UiEvent;
import forge.game.GameObject;
import forge.game.GameType; import forge.game.GameType;
import forge.game.Match; import forge.game.Match;
import forge.game.card.Card;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.IHasIcon; import forge.game.player.IHasIcon;
import forge.game.player.RegisteredPlayer; import forge.game.player.RegisteredPlayer;
@@ -153,8 +153,8 @@ public class GuiDesktop implements IGuiBase {
@Override @Override
public <T> T showInputDialog(String message, String title, FSkinProp icon, T initialInput, T[] inputOptions) { public <T> T showInputDialog(String message, String title, FSkinProp icon, T initialInput, T[] inputOptions) {
if (initialInput instanceof Card || (inputOptions != null && inputOptions.length > 0 && inputOptions[0] instanceof Card)) { if (initialInput instanceof GameObject || (inputOptions != null && inputOptions.length > 0 && inputOptions[0] instanceof GameObject)) {
System.err.println("Warning: Cards passed to GUI! Printing stack trace."); System.err.println("Warning: GameObject passed to GUI! Printing stack trace.");
Thread.dumpStack(); Thread.dumpStack();
} }
return FOptionPane.showInputDialog(message, title, icon == null ? null : FSkin.getImage(icon), initialInput, inputOptions); return FOptionPane.showInputDialog(message, title, icon == null ? null : FSkin.getImage(icon), initialInput, inputOptions);
@@ -162,8 +162,8 @@ public class GuiDesktop implements IGuiBase {
@Override @Override
public <T> List<T> getChoices(final String message, final int min, final int max, final Collection<T> choices, final T selected, final Function<T, String> display) { public <T> List<T> getChoices(final String message, final int min, final int max, final Collection<T> choices, final T selected, final Function<T, String> display) {
if ((choices != null && !choices.isEmpty() && choices.iterator().next() instanceof Card) || selected instanceof Card) { if ((choices != null && !choices.isEmpty() && choices.iterator().next() instanceof GameObject) || selected instanceof GameObject) {
System.err.println("Warning: Cards passed to GUI! Printing stack trace."); System.err.println("Warning: GameObject passed to GUI! Printing stack trace.");
Thread.dumpStack(); Thread.dumpStack();
} }
return GuiChoose.getChoices(message, min, max, choices, selected, display); return GuiChoose.getChoices(message, min, max, choices, selected, display);
@@ -172,9 +172,9 @@ public class GuiDesktop implements IGuiBase {
@Override @Override
public <T> List<T> order(final String title, final String top, final int remainingObjectsMin, final int remainingObjectsMax, public <T> List<T> order(final String title, final String top, final int remainingObjectsMin, final int remainingObjectsMax,
final List<T> sourceChoices, final List<T> destChoices, final CardView referenceCard, final boolean sideboardingMode) { final List<T> sourceChoices, final List<T> destChoices, final CardView referenceCard, final boolean sideboardingMode) {
if ((sourceChoices != null && !sourceChoices.isEmpty() && sourceChoices.iterator().next() instanceof Card) if ((sourceChoices != null && !sourceChoices.isEmpty() && sourceChoices.iterator().next() instanceof GameObject)
|| (destChoices != null && !destChoices.isEmpty() && destChoices.iterator().next() instanceof Card)) { || (destChoices != null && !destChoices.isEmpty() && destChoices.iterator().next() instanceof GameObject)) {
System.err.println("Warning: Cards passed to GUI! Printing stack trace."); System.err.println("Warning: GameObject passed to GUI! Printing stack trace.");
Thread.dumpStack(); Thread.dumpStack();
} }
return GuiChoose.order(title, top, remainingObjectsMin, remainingObjectsMax, sourceChoices, destChoices, referenceCard, sideboardingMode); return GuiChoose.order(title, top, remainingObjectsMin, remainingObjectsMax, sourceChoices, destChoices, referenceCard, sideboardingMode);

View File

@@ -511,7 +511,7 @@ public enum FControl implements KeyEventDispatcher {
} }
private FControlGameEventHandler fcVisitor; private FControlGameEventHandler fcVisitor;
private FControlGamePlayback playbackControl;// = new FControlGamePlayback(); private FControlGamePlayback playbackControl;
private void attachToGame(final IGameView game0) { private void attachToGame(final IGameView game0) {
if (game0.getGameType().equals(GameType.Quest)) { if (game0.getGameType().equals(GameType.Quest)) {
QuestController qc = FModel.getQuest(); QuestController qc = FModel.getQuest();
@@ -696,22 +696,7 @@ public enum FControl implements KeyEventDispatcher {
final ForgePreferences prefs = FModel.getPreferences(); final ForgePreferences prefs = FModel.getPreferences();
final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews(); final List<VField> fieldViews = VMatchUI.SINGLETON_INSTANCE.getFieldViews();
// AI field is at index [0] // Human field is at index [0]
PhaseIndicator fvAi = fieldViews.get(1).getPhaseIndicator();
fvAi.getLblUpkeep().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_UPKEEP));
fvAi.getLblDraw().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_DRAW));
fvAi.getLblMain1().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_MAIN1));
fvAi.getLblBeginCombat().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_BEGINCOMBAT));
fvAi.getLblDeclareAttackers().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_DECLAREATTACKERS));
fvAi.getLblDeclareBlockers().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_DECLAREBLOCKERS));
fvAi.getLblFirstStrike().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_FIRSTSTRIKE));
fvAi.getLblCombatDamage().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_COMBATDAMAGE));
fvAi.getLblEndCombat().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_ENDCOMBAT));
fvAi.getLblMain2().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_MAIN2));
fvAi.getLblEndTurn().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_EOT));
fvAi.getLblCleanup().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_CLEANUP));
// Human field is at index [1]
PhaseIndicator fvHuman = fieldViews.get(0).getPhaseIndicator(); PhaseIndicator fvHuman = fieldViews.get(0).getPhaseIndicator();
fvHuman.getLblUpkeep().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_UPKEEP)); fvHuman.getLblUpkeep().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_UPKEEP));
fvHuman.getLblDraw().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_DRAW)); fvHuman.getLblDraw().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_DRAW));
@@ -726,6 +711,23 @@ public enum FControl implements KeyEventDispatcher {
fvHuman.getLblEndTurn().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_EOT)); fvHuman.getLblEndTurn().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_EOT));
fvHuman.getLblCleanup().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_CLEANUP)); fvHuman.getLblCleanup().setEnabled(prefs.getPrefBoolean(FPref.PHASE_HUMAN_CLEANUP));
// AI field is at index [1], ...
for (int i = 1; i < fieldViews.size(); i++) {
PhaseIndicator fvAi = fieldViews.get(i).getPhaseIndicator();
fvAi.getLblUpkeep().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_UPKEEP));
fvAi.getLblDraw().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_DRAW));
fvAi.getLblMain1().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_MAIN1));
fvAi.getLblBeginCombat().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_BEGINCOMBAT));
fvAi.getLblDeclareAttackers().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_DECLAREATTACKERS));
fvAi.getLblDeclareBlockers().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_DECLAREBLOCKERS));
fvAi.getLblFirstStrike().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_FIRSTSTRIKE));
fvAi.getLblCombatDamage().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_COMBATDAMAGE));
fvAi.getLblEndCombat().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_ENDCOMBAT));
fvAi.getLblMain2().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_MAIN2));
fvAi.getLblEndTurn().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_EOT));
fvAi.getLblCleanup().setEnabled(prefs.getPrefBoolean(FPref.PHASE_AI_CLEANUP));
}
//Singletons.getView().getViewMatch().setLayoutParams(prefs.getPref(FPref.UI_LAYOUT_PARAMS)); //Singletons.getView().getViewMatch().setLayoutParams(prefs.getPref(FPref.UI_LAYOUT_PARAMS));
} }

View File

@@ -1,6 +1,5 @@
package forge.control; package forge.control;
import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
@@ -11,6 +10,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
@@ -129,12 +129,12 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override @Override
public Void visit(GameEventAnteCardsSelected ev) { public Void visit(GameEventAnteCardsSelected ev) {
final List<Card> options = new ArrayList<Card>(); final List<CardView> options = Lists.newArrayList();
for (final Entry<Player, Card> kv : ev.cards.entries()) { for (final Entry<Player, Card> kv : ev.cards.entries()) {
final Card fakeCard = new Card(-1); //use fake card so real cards appear with proper formatting final CardView fakeCard = new CardView(true); //use fake card so real cards appear with proper formatting
fakeCard.setName(" -- From " + Lang.getPossesive(kv.getKey().getName()) + " deck --"); fakeCard.getOriginal().setName(" -- From " + Lang.getPossesive(kv.getKey().getName()) + " deck --");
options.add(fakeCard); options.add(fakeCard);
options.add(kv.getValue()); options.add(gameView.getCardView(kv.getValue()));
} }
SGuiChoose.reveal(gui, "These cards were chosen to ante", options); SGuiChoose.reveal(gui, "These cards were chosen to ante", options);
return null; return null;

View File

@@ -20,7 +20,9 @@ public class InputPlaybackControl extends InputSyncronizedBase implements InputS
this.gui = gui; this.gui = gui;
this.game = game; this.game = game;
control = fControlGamePlayback; control = fControlGamePlayback;
setPause(false);
} }
@Override @Override
public IGuiBase getGui() { public IGuiBase getGui() {
return gui; return gui;

View File

@@ -1640,16 +1640,7 @@ public class PlayerControllerHuman extends PlayerController {
* @return * @return
* @see forge.view.LocalGameView#getCardViews(java.util.List) * @see forge.view.LocalGameView#getCardViews(java.util.List)
*/ */
public final List<CardView> getCardViews(List<Card> cards) { public final List<CardView> getCardViews(final Iterable<Card> cards) {
return gameView.getCardViews(cards);
}
/**
* @param cards
* @return
* @see forge.view.LocalGameView#getCardViews(java.lang.Iterable)
*/
public final List<CardView> getCardViews(Iterable<Card> cards) {
return gameView.getCardViews(cards); return gameView.getCardViews(cards);
} }

View File

@@ -44,6 +44,8 @@ import forge.properties.ForgeConstants;
import forge.util.gui.SGuiChoose; import forge.util.gui.SGuiChoose;
import forge.util.gui.SGuiDialog; import forge.util.gui.SGuiDialog;
import forge.util.gui.SOptionPane; import forge.util.gui.SOptionPane;
import forge.view.CardView;
import forge.view.PlayerView;
public final class DevModeUtil { public final class DevModeUtil {
@@ -247,7 +249,8 @@ public final class DevModeUtil {
} }
final List<Card> lib = pPriority.getCardsIn(ZoneType.Library); final List<Card> lib = pPriority.getCardsIn(ZoneType.Library);
final Card card = SGuiChoose.oneOrNone(controller.getGui(), "Choose a card", lib); final CardView cardView = SGuiChoose.oneOrNone(controller.getGui(), "Choose a card", controller.getCardViews(lib));
final Card card = controller.getCard(cardView);
if (card == null) { return; } if (card == null) { return; }
game.getAction().invoke(new Runnable() { game.getAction().invoke(new Runnable() {
@@ -266,7 +269,9 @@ public final class DevModeUtil {
* @since 1.0.15 * @since 1.0.15
*/ */
public static void devModeAddCounter(final Game game, final PlayerControllerHuman controller) { public static void devModeAddCounter(final Game game, final PlayerControllerHuman controller) {
final Card card = SGuiChoose.oneOrNone(controller.getGui(), "Add counters to which card?", game.getCardsIn(ZoneType.Battlefield)); final List<Card> cards = game.getCardsIn(ZoneType.Battlefield);
final CardView cardView = SGuiChoose.oneOrNone(controller.getGui(), "Add counters to which card?", controller.getCardViews(cards));
final Card card = controller.getCard(cardView);
if (card == null) { return; } if (card == null) { return; }
final CounterType counter = SGuiChoose.oneOrNone(controller.getGui(), "Which type of counter?", CounterType.values()); final CounterType counter = SGuiChoose.oneOrNone(controller.getGui(), "Which type of counter?", CounterType.values());
@@ -335,7 +340,8 @@ public final class DevModeUtil {
*/ */
public static void devModeSetLife(final Game game, final PlayerControllerHuman controller) { public static void devModeSetLife(final Game game, final PlayerControllerHuman controller) {
final List<Player> players = game.getPlayers(); final List<Player> players = game.getPlayers();
final Player player = SGuiChoose.oneOrNone(controller.getGui(), "Set life for which player?", players); final PlayerView playerView = SGuiChoose.oneOrNone(controller.getGui(), "Set life for which player?", controller.getPlayerViews(players));
final Player player = controller.getPlayer(playerView);
if (player == null) { return; } if (player == null) { return; }
final Integer life = SGuiChoose.getInteger(controller.getGui(), "Set life to what?", 0); final Integer life = SGuiChoose.getInteger(controller.getGui(), "Set life to what?", 0);
@@ -380,7 +386,8 @@ public final class DevModeUtil {
*/ */
public static void devModeCardToHand(final Game game, final PlayerControllerHuman controller) { public static void devModeCardToHand(final Game game, final PlayerControllerHuman controller) {
final List<Player> players = game.getPlayers(); final List<Player> players = game.getPlayers();
final Player p = SGuiChoose.oneOrNone(controller.getGui(), "Put card in hand for which player?", players); final PlayerView pView = SGuiChoose.oneOrNone(controller.getGui(), "Put card in hand for which player?", controller.getPlayerViews(players));
final Player p = controller.getPlayer(pView);
if (null == p) { if (null == p) {
return; return;
} }
@@ -401,7 +408,8 @@ public final class DevModeUtil {
public static void devModeCardToBattlefield(final Game game, final PlayerControllerHuman controller) { public static void devModeCardToBattlefield(final Game game, final PlayerControllerHuman controller) {
final List<Player> players = game.getPlayers(); final List<Player> players = game.getPlayers();
final Player p = SGuiChoose.oneOrNone(controller.getGui(), "Put card in play for which player?", players); final PlayerView pView = SGuiChoose.oneOrNone(controller.getGui(), "Put card in play for which player?", controller.getPlayerViews(players));
final Player p = controller.getPlayer(pView);
if (null == p) { if (null == p) {
return; return;
} }
@@ -444,7 +452,8 @@ public final class DevModeUtil {
public static void devModeRiggedPlanarRoll(final Game game, final PlayerControllerHuman controller) { public static void devModeRiggedPlanarRoll(final Game game, final PlayerControllerHuman controller) {
final List<Player> players = game.getPlayers(); final List<Player> players = game.getPlayers();
final Player player = SGuiChoose.oneOrNone(controller.getGui(), "Which player should roll?", players); final PlayerView playerView = SGuiChoose.oneOrNone(controller.getGui(), "Which player should roll?", controller.getPlayerViews(players));
final Player player = controller.getPlayer(playerView);
if (player == null) { return; } if (player == null) { return; }
final PlanarDice res = SGuiChoose.oneOrNone(controller.getGui(), "Choose result", PlanarDice.values()); final PlanarDice res = SGuiChoose.oneOrNone(controller.getGui(), "Choose result", PlanarDice.values());
@@ -452,12 +461,6 @@ public final class DevModeUtil {
System.out.println("Rigging planar dice roll: " + res.toString()); System.out.println("Rigging planar dice roll: " + res.toString());
//DBG
//System.out.println("ActivePlanes: " + getGame().getActivePlanes());
//System.out.println("CommandPlanes: " + getGame().getCardsIn(ZoneType.Command));
game.getAction().invoke(new Runnable() { game.getAction().invoke(new Runnable() {
@Override @Override
public void run() { public void run() {