Added options to gameclient target message.

This commit is contained in:
magenoxx 2011-01-27 18:27:41 +03:00
parent 23c5bf9db0
commit a1b2127962
16 changed files with 96 additions and 44 deletions

View file

@ -623,6 +623,7 @@ public class MageFrame extends javax.swing.JFrame {
private void btnGamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGamesActionPerformed
this.tablesPane.setVisible(true);
this.tablesPane.toFront();
this.tablesPane.showTables();
}//GEN-LAST:event_btnGamesActionPerformed

View file

@ -41,6 +41,8 @@ import java.awt.EventQueue;
import java.awt.MenuComponent;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.io.Serializable;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
import javax.swing.SwingUtilities;
@ -76,7 +78,7 @@ public class FeedbackPanel extends javax.swing.JPanel {
session = MageFrame.getSession();
}
public void getFeedback(FeedbackMode mode, String message, boolean modal, boolean special) {
public void getFeedback(FeedbackMode mode, String message, boolean modal, boolean special, Map<String, Serializable> options) {
this.lblMessage.setText(message);
this.selected = false;
this.mode = mode;
@ -115,6 +117,14 @@ public class FeedbackPanel extends javax.swing.JPanel {
startModal();
}
private void handleOptions(Map<String, Serializable> options) {
if (options != null) {
if (options.containsKey("UI.right.btn.text")) {
this.btnRight.setText((String)options.get("UI.right.btn.text"));
}
}
}
public void doClick() {
this.btnRight.doClick();
}

View file

@ -37,6 +37,7 @@ package mage.client.game;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@ -356,12 +357,12 @@ public class GamePanel extends javax.swing.JPanel {
public void ask(String question, GameView gameView) {
updateGame(gameView);
this.feedbackPanel.getFeedback(FeedbackMode.QUESTION, question, true, false);
this.feedbackPanel.getFeedback(FeedbackMode.QUESTION, question, true, false, null);
}
public void pickTarget(String message, CardsView cardView, GameView gameView, Set<UUID> targets, boolean required) {
public void pickTarget(String message, CardsView cardView, GameView gameView, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
updateGame(gameView);
this.feedbackPanel.getFeedback(required?FeedbackMode.INFORM:FeedbackMode.CANCEL, message, false, gameView.getSpecial());
this.feedbackPanel.getFeedback(required?FeedbackMode.INFORM:FeedbackMode.CANCEL, message, false, gameView.getSpecial(), options);
if (cardView != null && cardView.size() > 0) {
showCards(message, cardView, required);
}
@ -369,7 +370,7 @@ public class GamePanel extends javax.swing.JPanel {
public void inform(String information, GameView gameView) {
updateGame(gameView);
this.feedbackPanel.getFeedback(FeedbackMode.INFORM, information, false, gameView.getSpecial());
this.feedbackPanel.getFeedback(FeedbackMode.INFORM, information, false, gameView.getSpecial(), null);
}
public void modalMessage(String message) {
@ -386,7 +387,7 @@ public class GamePanel extends javax.swing.JPanel {
public void select(String message, GameView gameView) {
updateGame(gameView);
this.feedbackPanel.getFeedback(FeedbackMode.SELECT, message, false, gameView.getSpecial());
this.feedbackPanel.getFeedback(FeedbackMode.SELECT, message, false, gameView.getSpecial(), null);
if (PhaseManager.getInstance().isSkip(gameView, message)) {
this.feedbackPanel.doClick();
}
@ -394,12 +395,12 @@ public class GamePanel extends javax.swing.JPanel {
public void playMana(String message, GameView gameView) {
updateGame(gameView);
this.feedbackPanel.getFeedback(FeedbackMode.CANCEL, message, false, gameView.getSpecial());
this.feedbackPanel.getFeedback(FeedbackMode.CANCEL, message, false, gameView.getSpecial(), null);
}
public void playXMana(String message, GameView gameView) {
updateGame(gameView);
this.feedbackPanel.getFeedback(FeedbackMode.CONFIRM, message, false, gameView.getSpecial());
this.feedbackPanel.getFeedback(FeedbackMode.CONFIRM, message, false, gameView.getSpecial(), null);
}
public void replayMessage(String message) {

View file

@ -122,7 +122,7 @@ public class Client implements CallbackClient {
}
else if (callback.getMethod().equals("gameTarget")) {
GameClientMessage message = (GameClientMessage) callback.getData();
session.getGame().pickTarget(message.getMessage(), message.getCardsView(), message.getGameView(), message.getTargets(), message.isFlag());
session.getGame().pickTarget(message.getMessage(), message.getCardsView(), message.getGameView(), message.getTargets(), message.isFlag(), message.getOptions());
}
else if (callback.getMethod().equals("gameSelect")) {
GameClientMessage message = (GameClientMessage) callback.getData();

View file

@ -75,6 +75,7 @@ public class TablesPane extends MagePane {
tablesPanel.showTables(roomId);
this.repaint();
}
}
public void hideTables() {

View file

@ -29,6 +29,7 @@
package mage.view;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
@ -48,6 +49,7 @@ public class GameClientMessage implements Serializable {
private Set<UUID> targets;
private int min;
private int max;
private Map<String, Serializable> options;
public GameClientMessage(GameView gameView) {
this.gameView = gameView;
@ -58,7 +60,7 @@ public class GameClientMessage implements Serializable {
this.message = message;
}
public GameClientMessage(GameView gameView, String question, CardsView cardView, Set<UUID> targets, boolean required) {
private GameClientMessage(GameView gameView, String question, CardsView cardView, Set<UUID> targets, boolean required) {
this.gameView = gameView;
this.message = question;
this.cardsView = cardView;
@ -66,6 +68,11 @@ public class GameClientMessage implements Serializable {
this.flag = required;
}
public GameClientMessage(GameView gameView, String question, CardsView cardView, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
this(gameView, question, cardView, targets, required);
this.options = options;
}
public GameClientMessage(String[] choices, String message) {
this.strings = choices;
this.message = message;
@ -118,4 +125,7 @@ public class GameClientMessage implements Serializable {
return max;
}
public Map<String, Serializable> getOptions() {
return options;
}
}

View file

@ -30,6 +30,7 @@ package mage.player.ai;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
import java.util.logging.Level;
@ -138,6 +139,11 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
@Override
public boolean choose(Outcome outcome, Target target, Game game) {
return choose(outcome, target, game, null);
}
@Override
public boolean choose(Outcome outcome, Target target, Game game, Map<String, Serializable> options) {
if (logger.isLoggable(Level.FINE))
logger.fine("chooseTarget: " + outcome.toString() + ":" + target.toString());
UUID opponentId = game.getOpponents(playerId).iterator().next();

View file

@ -28,6 +28,7 @@
package mage.player.human;
import java.io.Serializable;
import java.util.List;
import mage.abilities.TriggeredAbilities;
import mage.abilities.TriggeredAbility;
@ -182,8 +183,13 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
@Override
public boolean choose(Outcome outcome, Target target, Game game) {
return choose(outcome, target, game, null);
}
@Override
public boolean choose(Outcome outcome, Target target, Game game, Map<String, Serializable> options) {
while (!abort) {
game.fireSelectTargetEvent(playerId, target.getMessage(), target.possibleTargets(null, playerId, game), target.isRequired());
game.fireSelectTargetEvent(playerId, target.getMessage(), target.possibleTargets(null, playerId, game), target.isRequired(), options);
waitForResponse();
if (response.getUUID() != null) {
if (target instanceof TargetPermanent) {
@ -206,7 +212,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
@Override
public boolean chooseTarget(Outcome outcome, Target target, Ability source, Game game) {
while (!abort) {
game.fireSelectTargetEvent(playerId, target.getMessage(), target.possibleTargets(source==null?null:source.getId(), playerId, game), target.isRequired());
game.fireSelectTargetEvent(playerId, target.getMessage(), target.possibleTargets(source==null?null:source.getId(), playerId, game), target.isRequired(), null);
waitForResponse();
if (response.getUUID() != null) {
if (target instanceof TargetPermanent) {
@ -263,7 +269,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
@Override
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
while (!abort) {
game.fireSelectTargetEvent(playerId, target.getMessage() + "\n Amount remaining:" + target.getAmountRemaining(), target.possibleTargets(source==null?null:source.getId(), playerId, game), target.isRequired());
game.fireSelectTargetEvent(playerId, target.getMessage() + "\n Amount remaining:" + target.getAmountRemaining(), target.possibleTargets(source==null?null:source.getId(), playerId, game), target.isRequired(), null);
waitForResponse();
if (response.getUUID() != null) {
if (target.canTarget(response.getUUID(), source, game)) {
@ -434,7 +440,7 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
protected void selectCombatGroup(UUID blockerId, Game game) {
TargetAttackingCreature target = new TargetAttackingCreature();
game.fireSelectTargetEvent(playerId, "Select attacker to block", target.possibleTargets(null, playerId, game), target.isRequired());
game.fireSelectTargetEvent(playerId, "Select attacker to block", target.possibleTargets(null, playerId, game), target.isRequired(), null);
waitForResponse();
if (response.getBoolean() != null) {
return;

View file

@ -29,11 +29,8 @@
package mage.server.game;
import java.io.File;
import java.util.Collection;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import java.util.UUID;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
@ -126,10 +123,10 @@ public class GameController implements GameCallback {
ask(event.getPlayerId(), event.getMessage());
break;
case PICK_TARGET:
target(event.getPlayerId(), event.getMessage(), event.getCards(), event.getTargets(), event.isRequired());
target(event.getPlayerId(), event.getMessage(), event.getCards(), event.getTargets(), event.isRequired(), event.getOptions());
break;
case PICK_ABILITY:
target(event.getPlayerId(), event.getMessage(), event.getAbilities(), event.isRequired());
target(event.getPlayerId(), event.getMessage(), event.getAbilities(), event.isRequired(), event.getOptions());
break;
case SELECT:
select(event.getPlayerId(), event.getMessage());
@ -332,19 +329,19 @@ public class GameController implements GameCallback {
informOthers(playerId);
}
private synchronized void target(UUID playerId, String question, Cards cards, Set<UUID> targets, boolean required) {
private synchronized void target(UUID playerId, String question, Cards cards, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
if (gameSessions.containsKey(playerId)) {
if (cards != null)
gameSessions.get(playerId).target(question, new CardsView(cards.getCards(game)), targets, required, getGameView(playerId));
gameSessions.get(playerId).target(question, new CardsView(cards.getCards(game)), targets, required, getGameView(playerId), options);
else
gameSessions.get(playerId).target(question, new CardsView(), targets, required, getGameView(playerId));
gameSessions.get(playerId).target(question, new CardsView(), targets, required, getGameView(playerId), options);
}
informOthers(playerId);
}
private synchronized void target(UUID playerId, String question, Collection<? extends Ability> abilities, boolean required) {
private synchronized void target(UUID playerId, String question, Collection<? extends Ability> abilities, boolean required, Map<String, Serializable> options) {
if (gameSessions.containsKey(playerId))
gameSessions.get(playerId).target(question, new CardsView(abilities, game), null, required, getGameView(playerId));
gameSessions.get(playerId).target(question, new CardsView(abilities, game), null, required, getGameView(playerId), options);
informOthers(playerId);
}

View file

@ -28,6 +28,8 @@
package mage.server.game;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
@ -71,12 +73,12 @@ public class GameSession extends GameWatcher {
}
}
public void target(final String question, final CardsView cardView, final Set<UUID> targets, final boolean required, final GameView gameView) {
public void target(final String question, final CardsView cardView, final Set<UUID> targets, final boolean required, final GameView gameView, final Map<String, Serializable> options) {
if (!killed) {
setupTimeout();
Session session = SessionManager.getInstance().getSession(sessionId);
if (session != null)
session.fireCallback(new ClientCallback("gameTarget", new GameClientMessage(gameView, question, cardView, targets, required)));
session.fireCallback(new ClientCallback("gameTarget", new GameClientMessage(gameView, question, cardView, targets, required, options)));
}
}

View file

@ -39,9 +39,8 @@ import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetPermanentOrPlayerWithCounter;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.io.Serializable;
import java.util.*;
/**
* @author nantuko
@ -65,8 +64,10 @@ public class ProliferateEffect extends OneShotEffect<ProliferateEffect> {
//had, if thats the case this ability should fizzle.
if (target.canChoose(controller.getId(), game)) {
boolean abilityApplied = false;
Map<String, Serializable> options = new HashMap<String, Serializable>();
options.put("UI.right.btn.text", "Done");
while (target.canChoose(controller.getId(), game)) {
if (!controller.choose(Outcome.Benefit, target, game)) {
if (!controller.choose(Outcome.Benefit, target, game, options)) {
break;
}
}

View file

@ -34,6 +34,7 @@ import mage.game.stack.SpellStack;
import mage.MageObject;
import java.io.Serializable;
import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.Constants.MultiplayerAttackOption;
@ -115,7 +116,7 @@ public interface Game extends MageItem, Serializable {
public void addPlayerQueryEventListener(Listener<PlayerQueryEvent> listener);
public void fireAskPlayerEvent(UUID playerId, String message);
public void fireChooseEvent(UUID playerId, Choice choice);
public void fireSelectTargetEvent(UUID playerId, String message, Set<UUID> targets, boolean required);
public void fireSelectTargetEvent(UUID playerId, String message, Set<UUID> targets, boolean required, Map<String, Serializable> options);
public void fireSelectTargetEvent(UUID playerId, String message, Cards cards, boolean required);
public void fireSelectTargetEvent(UUID playerId, String message, TriggeredAbilities abilities, boolean required);
// public void fireRevealCardsEvent(String message, Cards cards);

View file

@ -759,8 +759,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
}
@Override
public void fireSelectTargetEvent(UUID playerId, String message, Set<UUID> targets, boolean required) {
playerQueryEventSource.target(playerId, message, targets, required);
public void fireSelectTargetEvent(UUID playerId, String message, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
playerQueryEventSource.target(playerId, message, targets, required, options);
}
@Override

View file

@ -29,11 +29,8 @@
package mage.game.events;
import java.io.Serializable;
import java.util.Collection;
import java.util.EventObject;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.TriggeredAbilities;
@ -61,6 +58,12 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
private boolean required;
private int min;
private int max;
private Map<String, Serializable> options;
private PlayerQueryEvent(UUID playerId, String message, Collection<? extends Ability> abilities, Set<String> choices, Set<UUID> targets, Cards cards, QueryType queryType, int min, int max, boolean required, Map<String, Serializable> options) {
this(playerId, message, abilities, choices, targets, cards, queryType, min, max, required);
this.options = options;
}
private PlayerQueryEvent(UUID playerId, String message, Collection<? extends Ability> abilities, Set<String> choices, Set<UUID> targets, Cards cards, QueryType queryType, int min, int max, boolean required) {
super(playerId);
@ -100,6 +103,10 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
return new PlayerQueryEvent(playerId, message, null, null, targets, null, QueryType.PICK_TARGET, 0, 0, required);
}
public static PlayerQueryEvent targetEvent(UUID playerId, String message, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
return new PlayerQueryEvent(playerId, message, null, null, targets, null, QueryType.PICK_TARGET, 0, 0, required, options);
}
public static PlayerQueryEvent targetEvent(UUID playerId, String message, Cards cards, boolean required) {
return new PlayerQueryEvent(playerId, message, null, null, null, cards, QueryType.PICK_TARGET, 0, 0, required);
}
@ -175,4 +182,8 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
public int getMax() {
return max;
}
public Map<String, Serializable> getOptions() {
return options;
}
}

View file

@ -29,10 +29,8 @@
package mage.game.events;
import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;
import mage.abilities.ActivatedAbility;
import mage.abilities.TriggeredAbilities;
import mage.cards.Card;
@ -67,6 +65,10 @@ public class PlayerQueryEventSource implements EventSource<PlayerQueryEvent>, Se
dispatcher.fireEvent(PlayerQueryEvent.targetEvent(playerId, message, targets, required));
}
public void target(UUID playerId, String message, Set<UUID> targets, boolean required, Map<String, Serializable> options) {
dispatcher.fireEvent(PlayerQueryEvent.targetEvent(playerId, message, targets, required, options));
}
public void target(UUID playerId, String message, Cards cards, boolean required) {
dispatcher.fireEvent(PlayerQueryEvent.targetEvent(playerId, message, cards, required));
}

View file

@ -28,7 +28,9 @@
package mage.players;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.Constants.Outcome;
@ -135,6 +137,7 @@ public interface Player extends MageItem, Copyable<Player> {
public abstract void priority(Game game);
public abstract boolean choose(Outcome outcome, Target target, Game game);
public abstract boolean choose(Outcome outcome, Target target, Game game, Map<String, Serializable> options);
public abstract boolean choose(Cards cards, TargetCard target, Game game);
public abstract boolean chooseTarget(Outcome outcome, Target target, Ability source, Game game);
public abstract boolean chooseTarget(Cards cards, TargetCard target, Ability source, Game game);