Fix the last problems related to inputs. All errors are fixed, it's time to test!

This commit is contained in:
elcnesh
2014-09-04 10:53:00 +00:00
parent 89b3395cec
commit 2d1f2dc1ae
11 changed files with 93 additions and 38 deletions

View File

@@ -332,7 +332,7 @@ public class GuiDesktop implements IGuiBase {
new Runnable() { new Runnable() {
@Override @Override
public void run() { public void run() {
CPrompt.SINGLETON_INSTANCE.getInputControl().selectAbility(ab); CPrompt.SINGLETON_INSTANCE.selectAbility(ab);
} }
}, enabled); }, enabled);
if (shortcut > 0) { if (shortcut > 0) {

View File

@@ -81,7 +81,6 @@ import forge.screens.match.VMatchUI;
import forge.screens.match.controllers.CDock; import forge.screens.match.controllers.CDock;
import forge.screens.match.controllers.CLog; import forge.screens.match.controllers.CLog;
import forge.screens.match.controllers.CPlayers; import forge.screens.match.controllers.CPlayers;
import forge.screens.match.controllers.CPrompt;
import forge.screens.match.controllers.CStack; import forge.screens.match.controllers.CStack;
import forge.screens.match.views.VAntes; import forge.screens.match.views.VAntes;
import forge.screens.match.views.VDev; import forge.screens.match.views.VDev;
@@ -523,8 +522,6 @@ public enum FControl implements KeyEventDispatcher {
setCurrentScreen(FScreen.MATCH_SCREEN); setCurrentScreen(FScreen.MATCH_SCREEN);
SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc()); SDisplayUtil.showTab(EDocID.REPORT_LOG.getDoc());
CPrompt.SINGLETON_INSTANCE.getInputControl().setGame(game0);
// Listen to DuelOutcome event to show ViewWinLose // Listen to DuelOutcome event to show ViewWinLose
game0.subscribeToEvents(fcVisitor); game0.subscribeToEvents(fcVisitor);

View File

@@ -62,7 +62,7 @@ public enum CDock implements ICDoc {
*/ */
public void endTurn() { public void endTurn() {
game.autoPassUntilEndOfTurn(); game.autoPassUntilEndOfTurn();
if (!CPrompt.SINGLETON_INSTANCE.getInputControl().passPriority()) { if (!CPrompt.SINGLETON_INSTANCE.passPriority()) {
game.autoPassCancel(); game.autoPassCancel();
} }
} }

View File

@@ -53,7 +53,7 @@ public class CField implements ICDoc {
private final MouseListener madAvatar = new MouseAdapter() { private final MouseListener madAvatar = new MouseAdapter() {
@Override @Override
public void mousePressed(final MouseEvent e) { public void mousePressed(final MouseEvent e) {
CPrompt.SINGLETON_INSTANCE.getInputControl().selectPlayer(player, new MouseTriggerEvent(e)); CPrompt.SINGLETON_INSTANCE.selectPlayer(player, new MouseTriggerEvent(e));
} }
}; };
@@ -103,7 +103,7 @@ public class CField implements ICDoc {
return; return;
} }
CPrompt.SINGLETON_INSTANCE.getInputControl().selectCard(c, null); CPrompt.SINGLETON_INSTANCE.selectCard(c, null);
// Temporarily commenting out the below to route, Flashback cards through the InputProxy // Temporarily commenting out the below to route, Flashback cards through the InputProxy
/* /*
final Game game = player.getGame(); final Game game = player.getGame();

View File

@@ -32,10 +32,13 @@ import forge.Singletons;
import forge.UiCommand; import forge.UiCommand;
import forge.gui.framework.ICDoc; import forge.gui.framework.ICDoc;
import forge.gui.framework.SDisplayUtil; import forge.gui.framework.SDisplayUtil;
import forge.match.input.InputProxy;
import forge.screens.match.views.VPrompt; import forge.screens.match.views.VPrompt;
import forge.toolbox.FSkin; import forge.toolbox.FSkin;
import forge.util.ITriggerEvent;
import forge.view.CardView;
import forge.view.IGameView; import forge.view.IGameView;
import forge.view.PlayerView;
import forge.view.SpellAbilityView;
/** /**
* Controls the prompt panel in the match UI. * Controls the prompt panel in the match UI.
@@ -46,20 +49,19 @@ public enum CPrompt implements ICDoc {
/** */ /** */
SINGLETON_INSTANCE; SINGLETON_INSTANCE;
private InputProxy inputControl = new InputProxy();
private Component lastFocusedButton = null; private Component lastFocusedButton = null;
private VPrompt view = VPrompt.SINGLETON_INSTANCE; private final VPrompt view = VPrompt.SINGLETON_INSTANCE;
private final ActionListener actCancel = new ActionListener() { private final ActionListener actCancel = new ActionListener() {
@Override @Override
public void actionPerformed(final ActionEvent evt) { public void actionPerformed(final ActionEvent evt) {
inputControl.selectButtonCancel(); selectButtonCancel();
} }
}; };
private final ActionListener actOK = new ActionListener() { private final ActionListener actOK = new ActionListener() {
@Override @Override
public void actionPerformed(final ActionEvent evt) { public void actionPerformed(final ActionEvent evt) {
inputControl.selectButtonOK(); selectButtonOk();
} }
}; };
@@ -87,13 +89,28 @@ public enum CPrompt implements ICDoc {
_initButton(view.getBtnOK(), actOK); _initButton(view.getBtnOK(), actOK);
} }
/** public void selectButtonOk() {
* Gets the input control. Singletons.getControl().getGameView().selectButtonOk();
* }
* @return GuiInput
*/ public void selectButtonCancel() {
public InputProxy getInputControl() { Singletons.getControl().getGameView().selectButtonCancel();
return this.inputControl; }
public boolean passPriority() {
return Singletons.getControl().getGameView().passPriority();
}
public void selectPlayer(final PlayerView player, final ITriggerEvent triggerEvent) {
Singletons.getControl().getGameView().selectPlayer(player, triggerEvent);
}
public void selectCard(final CardView card, final ITriggerEvent triggerEvent) {
Singletons.getControl().getGameView().selectCard(card, triggerEvent);
}
public void selectAbility(final SpellAbilityView sa) {
Singletons.getControl().getGameView().selectAbility(sa);
} }
/** @param s0   {@link java.lang.String} */ /** @param s0   {@link java.lang.String} */
@@ -117,6 +134,13 @@ public enum CPrompt implements ICDoc {
/* (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
public void update() {
// set focus back to button that last had it
if (null != lastFocusedButton) {
lastFocusedButton.requestFocusInWindow();
}
}
public void updateText() { public void updateText() {
FThreads.assertExecutedByEdt(GuiBase.getInterface(), true); FThreads.assertExecutedByEdt(GuiBase.getInterface(), true);
@@ -125,12 +149,4 @@ public enum CPrompt implements ICDoc {
view.getLblGames().setText(text); view.getLblGames().setText(text);
view.getLblGames().setToolTipText(String.format("%s: Game #%d of %d, turn %d", game.getGameType(), game.getNumPlayedGamesInMatch() + 1, game.getNumGamesInMatch(), game.getTurnNumber())); view.getLblGames().setToolTipText(String.format("%s: Game #%d of %d, turn %d", game.getGameType(), game.getNumPlayedGamesInMatch() + 1, game.getNumGamesInMatch(), game.getTurnNumber()));
} }
@Override
public void update() {
// set focus back to button that last had it
if (null != lastFocusedButton) {
lastFocusedButton.requestFocusInWindow();
}
}
} }

View File

@@ -260,7 +260,7 @@ public enum VStack implements IVDoc<CStack> {
game.setShouldAutoYield(key, !autoYield); game.setShouldAutoYield(key, !autoYield);
if (!autoYield && game.peekStack() == item) { if (!autoYield && game.peekStack() == item) {
//auto-pass priority if ability is on top of stack //auto-pass priority if ability is on top of stack
CPrompt.SINGLETON_INSTANCE.getInputControl().passPriority(); CPrompt.SINGLETON_INSTANCE.passPriority();
} }
} }
}); });
@@ -278,7 +278,7 @@ public enum VStack implements IVDoc<CStack> {
if (game.peekStack() == item && if (game.peekStack() == item &&
Singletons.getControl().getInputQueue().getInput() instanceof InputConfirm) { Singletons.getControl().getInputQueue().getInput() instanceof InputConfirm) {
//auto-yes if ability is on top of stack //auto-yes if ability is on top of stack
CPrompt.SINGLETON_INSTANCE.getInputControl().selectButtonOK(); CPrompt.SINGLETON_INSTANCE.selectButtonOk();
} }
} }
} }
@@ -297,7 +297,7 @@ public enum VStack implements IVDoc<CStack> {
if (game.peekStack() == item && if (game.peekStack() == item &&
Singletons.getControl().getInputQueue().getInput() instanceof InputConfirm) { Singletons.getControl().getInputQueue().getInput() instanceof InputConfirm) {
//auto-no if ability is on top of stack //auto-no if ability is on top of stack
CPrompt.SINGLETON_INSTANCE.getInputControl().selectButtonOK(); CPrompt.SINGLETON_INSTANCE.selectButtonOk();
} }
} }
} }

View File

@@ -62,14 +62,14 @@ public class HandArea extends CardArea {
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) { public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
CPrompt.SINGLETON_INSTANCE.getInputControl().selectCard(panel.getCard(), new MouseTriggerEvent(evt)); CPrompt.SINGLETON_INSTANCE.selectCard(panel.getCard(), new MouseTriggerEvent(evt));
super.mouseLeftClicked(panel, evt); super.mouseLeftClicked(panel, evt);
} }
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) { public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) {
CPrompt.SINGLETON_INSTANCE.getInputControl().selectCard(panel.getCard(), new MouseTriggerEvent(evt)); CPrompt.SINGLETON_INSTANCE.selectCard(panel.getCard(), new MouseTriggerEvent(evt));
super.mouseRightClicked(panel, evt); super.mouseRightClicked(panel, evt);
} }
} }

View File

@@ -571,7 +571,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) { public final void mouseLeftClicked(final CardPanel panel, final MouseEvent evt) {
CPrompt.SINGLETON_INSTANCE.getInputControl().selectCard(panel.getCard(), new MouseTriggerEvent(evt)); CPrompt.SINGLETON_INSTANCE.selectCard(panel.getCard(), new MouseTriggerEvent(evt));
if ((panel.getTappedAngle() != 0) && (panel.getTappedAngle() != CardPanel.TAPPED_ANGLE)) { if ((panel.getTappedAngle() != 0) && (panel.getTappedAngle() != CardPanel.TAPPED_ANGLE)) {
return; return;
} }
@@ -581,7 +581,7 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
/** {@inheritDoc} */ /** {@inheritDoc} */
@Override @Override
public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) { public final void mouseRightClicked(final CardPanel panel, final MouseEvent evt) {
CPrompt.SINGLETON_INSTANCE.getInputControl().selectCard(panel.getCard(), new MouseTriggerEvent(evt)); CPrompt.SINGLETON_INSTANCE.selectCard(panel.getCard(), new MouseTriggerEvent(evt));
super.mouseRightClicked(panel, evt); super.mouseRightClicked(panel, evt);
} }

View File

@@ -78,6 +78,7 @@ import forge.match.input.InputConfirm;
import forge.match.input.InputConfirmMulligan; import forge.match.input.InputConfirmMulligan;
import forge.match.input.InputPassPriority; import forge.match.input.InputPassPriority;
import forge.match.input.InputProliferate; import forge.match.input.InputProliferate;
import forge.match.input.InputProxy;
import forge.match.input.InputSelectCardsForConvoke; import forge.match.input.InputSelectCardsForConvoke;
import forge.match.input.InputSelectCardsFromList; import forge.match.input.InputSelectCardsFromList;
import forge.match.input.InputSelectEntitiesFromList; import forge.match.input.InputSelectEntitiesFromList;
@@ -105,8 +106,10 @@ import forge.view.ViewUtil;
* Handles phase skips for now. * Handles phase skips for now.
*/ */
public class PlayerControllerLocal extends PlayerControllerHuman implements IGameView { public class PlayerControllerLocal extends PlayerControllerHuman implements IGameView {
private final InputProxy inputProxy;
public PlayerControllerLocal(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) { public PlayerControllerLocal(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) {
super(game0, p, lp, gui); super(game0, p, lp, gui);
this.inputProxy = new InputProxy(this);
// aggressively cache a view for each player // aggressively cache a view for each player
for (final Player player : game.getRegisteredPlayers()) { for (final Player player : game.getRegisteredPlayers()) {
getPlayerView(player); getPlayerView(player);
@@ -1406,6 +1409,36 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
return false; return false;
} }
@Override
public void selectButtonOk() {
inputProxy.selectButtonOK();
}
@Override
public void selectButtonCancel() {
inputProxy.selectButtonCancel();
}
@Override
public boolean passPriority() {
return inputProxy.passPriority();
}
@Override
public void selectPlayer(final PlayerView player, final ITriggerEvent triggerEvent) {
inputProxy.selectPlayer(player, triggerEvent);
}
@Override
public void selectCard(final CardView card, final ITriggerEvent triggerEvent) {
inputProxy.selectCard(card, triggerEvent);
}
@Override
public void selectAbility(final SpellAbilityView sa) {
inputProxy.selectAbility(sa);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.view.IGameView#getGuiRegisteredPlayer(forge.LobbyPlayer) * @see forge.view.IGameView#getGuiRegisteredPlayer(forge.LobbyPlayer)
*/ */
@@ -1681,5 +1714,6 @@ public class PlayerControllerLocal extends PlayerControllerHuman implements IGam
@Override @Override
public void devPlaneswalkTo() { public void devPlaneswalkTo() {
DevModeUtil.devModeRiggedPlanarRoll(game, this); DevModeUtil.devModeRiggedPlanarRoll(game, this);
} }
} }

View File

@@ -39,7 +39,6 @@ public class QuestAchievements {
// Difficulty - will store only index from now. // Difficulty - will store only index from now.
private int difficulty; private int difficulty;
@SuppressWarnings("unused")
public QuestAchievements() { //needed for XML serialization public QuestAchievements() { //needed for XML serialization
} }

View File

@@ -10,6 +10,7 @@ import forge.game.GameOutcome;
import forge.game.GameType; import forge.game.GameType;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.RegisteredPlayer; import forge.game.player.RegisteredPlayer;
import forge.util.ITriggerEvent;
public interface IGameView { public interface IGameView {
@@ -45,11 +46,19 @@ public interface IGameView {
public abstract CombatView getCombat(); public abstract CombatView getCombat();
public abstract void addLogObserver(Observer o); public abstract void addLogObserver(Observer o);
public abstract List<GameLogEntry> getLogEntries(final GameLogEntryType maxLogLevel); public abstract List<GameLogEntry> getLogEntries(GameLogEntryType maxLogLevel);
public abstract List<GameLogEntry> getLogEntriesExact(final GameLogEntryType logLevel); public abstract List<GameLogEntry> getLogEntriesExact(GameLogEntryType logLevel);
// Input controls
public abstract boolean tryUndoLastAction(); public abstract boolean tryUndoLastAction();
public abstract void selectButtonOk();
public abstract void selectButtonCancel();
public abstract boolean passPriority();
public abstract void selectPlayer(PlayerView player, ITriggerEvent triggerEvent);
public abstract void selectCard(CardView card, ITriggerEvent triggerEvent);
public abstract void selectAbility(SpellAbilityView sa);
// the following method should eventually be replaced by methods returning // the following method should eventually be replaced by methods returning
// View classes // View classes
@Deprecated @Deprecated