Fixed some dialogs for human players that were not shown after a reconnect to a game (e.g choose mulligan, any use Yes/No choice, amount choice, Pile choice).

This commit is contained in:
LevelX2 2015-08-28 14:29:54 +02:00
parent 758f56792e
commit 39e62095e4
3 changed files with 69 additions and 85 deletions

View file

@ -184,13 +184,7 @@ public class HelperPanel extends JPanel {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
if (linkSpecial != null) {
{
// if (evt.getActionCommand().equals("automatic")) {
// showPopupMenu(evt);
// } else {
clickButton(linkSpecial);
// }
}
clickButton(linkSpecial);
}
}
});

View file

@ -11,11 +11,11 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.geom.Area;
import java.awt.geom.GeneralPath;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Arrow extends JPanel {
private static final long serialVersionUID = -4631054277822828303L;
private int startX;
@ -27,21 +27,25 @@ public class Arrow extends JPanel {
private Composite composite;
private Color color = Color.red;
public Arrow () {
public Arrow() {
setOpaque(false);
setOpacity(0.6f);
}
protected void paintComponent (Graphics g) {
protected void paintComponent(Graphics g) {
super.paintComponent(g);
float ex = endX - startX;
float ey = endY - startY;
if (ex == 0 && ey == 0) return;
float length = (float)Math.sqrt(ex * ex + ey * ey);
float bendPercent = (float)Math.asin(ey / length);
if (endX > startX) bendPercent = -bendPercent;
if (ex == 0 && ey == 0) {
return;
}
float length = (float) Math.sqrt(ex * ex + ey * ey);
float bendPercent = (float) Math.asin(ey / length);
if (endX > startX) {
bendPercent = -bendPercent;
}
Area arrow = getArrow(length, bendPercent);
Graphics2D g2d = (Graphics2D)g;
Graphics2D g2d = (Graphics2D) g;
g2d.translate(startX, startY);
g2d.rotate(Math.atan2(ey, ex));
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
@ -52,16 +56,16 @@ public class Arrow extends JPanel {
g2d.draw(arrow);
}
private Area getArrow (float length, float bendPercent) {
private Area getArrow(float length, float bendPercent) {
float p1x = 0, p1y = 0;
float p2x = length, p2y = 0;
float cx = length / 2, cy = length / 8f * bendPercent;
float adjSize, ex, ey, abs_e;
adjSize = (float)(bodyWidth / 2 / Math.sqrt(2));
adjSize = (float) (bodyWidth / 2 / Math.sqrt(2));
ex = p2x - cx;
ey = p2y - cy;
abs_e = (float)Math.sqrt(ex * ex + ey * ey);
abs_e = (float) Math.sqrt(ex * ex + ey * ey);
ex /= abs_e;
ey /= abs_e;
GeneralPath bodyPath = new GeneralPath();
@ -71,10 +75,10 @@ public class Arrow extends JPanel {
bodyPath.quadTo(cx, cy, p2x - (ey + ex) * adjSize, p2y + (ex - ey) * adjSize);
bodyPath.closePath();
adjSize = (float)(headSize / Math.sqrt(2));
adjSize = (float) (headSize / Math.sqrt(2));
ex = p2x - cx;
ey = p2y - cy;
abs_e = (float)Math.sqrt(ex * ex + ey * ey);
abs_e = (float) Math.sqrt(ex * ex + ey * ey);
ex /= abs_e;
ey /= abs_e;
GeneralPath headPath = new GeneralPath();
@ -88,23 +92,23 @@ public class Arrow extends JPanel {
return area;
}
public int getBodyWidth () {
public int getBodyWidth() {
return bodyWidth;
}
public void setBodyWidth (int bodyWidth) {
public void setBodyWidth(int bodyWidth) {
this.bodyWidth = bodyWidth;
}
public float getHeadSize () {
public float getHeadSize() {
return headSize;
}
public void setHeadSize (float headSize) {
public void setHeadSize(float headSize) {
this.headSize = headSize;
}
public void setArrowLocation (int startX, int startY, int endX, int endY) {
public void setArrowLocation(int startX, int startY, int endX, int endY) {
this.startX = startX;
this.startY = startY;
this.endX = endX;
@ -112,7 +116,7 @@ public class Arrow extends JPanel {
repaint();
}
public void setOpacity (float opacity) {
public void setOpacity(float opacity) {
composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity);
}
@ -120,7 +124,7 @@ public class Arrow extends JPanel {
this.color = color;
}
public static void main (String[] args) {
public static void main(String[] args) {
final JFrame frame = new JFrame();
frame.setLayout(new BorderLayout());
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
@ -130,11 +134,13 @@ public class Arrow extends JPanel {
frame.setResizable(false);
frame.setVisible(true);
frame.getContentPane().addMouseMotionListener(new MouseMotionListener() {
public void mouseMoved (MouseEvent e) {
@Override
public void mouseMoved(MouseEvent e) {
arrow.setArrowLocation(320, 240, e.getX(), e.getY());
}
public void mouseDragged (MouseEvent e) {
@Override
public void mouseDragged(MouseEvent e) {
}
});
}

View file

@ -107,7 +107,7 @@ public class HumanPlayer extends PlayerImpl {
protected static FilterBlockingCreature filterBlock = new FilterBlockingCreature();
protected final Choice replacementEffectChoice;
private static final Logger log = Logger.getLogger(HumanPlayer.class);
private static final Logger logger = Logger.getLogger(HumanPlayer.class);
protected HashSet<String> autoSelectReplacementEffects = new HashSet<>();
protected ManaCost currentlyUnpaidMana;
@ -136,52 +136,30 @@ public class HumanPlayer extends PlayerImpl {
protected void waitForResponse(Game game) {
response.clear();
log.debug("Waiting response from player: " + getId());
logger.debug("Waiting response from player: " + getId());
game.resumeTimer(getTurnControlledBy());
synchronized (response) {
try {
response.wait();
log.debug("Got response from player: " + getId());
logger.debug("Got response from player: " + getId());
} catch (InterruptedException ex) {
ex.printStackTrace();
logger.error("Response error for player " + getName() + " gameId: " + game.getId(), ex);
} finally {
game.pauseTimer(getTurnControlledBy());
}
}
}
protected void waitForBooleanResponse(Game game) {
do {
waitForResponse(game);
} while (response.getBoolean() == null && !abort);
}
protected void waitForUUIDResponse(Game game) {
do {
waitForResponse(game);
} while (response.getUUID() == null && !abort);
}
protected void waitForStringResponse(Game game) {
do {
waitForResponse(game);
} while (response.getString() == null && !abort);
}
protected void waitForIntegerResponse(Game game) {
do {
waitForResponse(game);
} while (response.getInteger() == null && !abort);
}
@Override
public boolean chooseMulligan(Game game) {
updateGameStatePriority("chooseMulligan", game);
int nextHandSize = game.mulliganDownTo(playerId);
game.fireAskPlayerEvent(playerId, new MessageToClient("Mulligan "
+ (getHand().size() > nextHandSize ? "down to " : "for free, draw ")
+ nextHandSize + (nextHandSize == 1 ? " card?" : " cards?")), null);
waitForBooleanResponse(game);
do {
game.fireAskPlayerEvent(playerId, new MessageToClient("Mulligan "
+ (getHand().size() > nextHandSize ? "down to " : "for free, draw ")
+ nextHandSize + (nextHandSize == 1 ? " card?" : " cards?")), null);
waitForResponse(game);
} while (response.getBoolean() == null && !abort);
if (!abort) {
return response.getBoolean();
}
@ -202,8 +180,10 @@ public class HumanPlayer extends PlayerImpl {
}
}
updateGameStatePriority("chooseUse", game);
game.fireAskPlayerEvent(playerId, new MessageToClient(message, getRelatedObjectName(source, game)), source);
waitForBooleanResponse(game);
do {
game.fireAskPlayerEvent(playerId, new MessageToClient(message, getRelatedObjectName(source, game)), source);
waitForResponse(game);
} while (response.getBoolean() == null && !abort);
if (!abort) {
return response.getBoolean();
}
@ -262,7 +242,7 @@ public class HumanPlayer extends PlayerImpl {
while (!abort) {
game.fireChooseChoiceEvent(playerId, replacementEffectChoice);
waitForResponse(game);
log.debug("Choose effect: " + response.getString());
logger.debug("Choose effect: " + response.getString());
if (response.getString() != null) {
if (response.getString().startsWith("#")) {
autoSelectReplacementEffects.add(response.getString().substring(1));
@ -809,8 +789,10 @@ public class HumanPlayer extends PlayerImpl {
public int announceXMana(int min, int max, String message, Game game, Ability ability) {
int xValue = 0;
updateGameStatePriority("announceXMana", game);
game.fireGetAmountEvent(playerId, message, min, max);
waitForIntegerResponse(game);
do {
game.fireGetAmountEvent(playerId, message, min, max);
waitForResponse(game);
} while (response.getInteger() == null && !abort);
if (response != null && response.getInteger() != null) {
xValue = response.getInteger();
}
@ -821,8 +803,10 @@ public class HumanPlayer extends PlayerImpl {
public int announceXCost(int min, int max, String message, Game game, Ability ability, VariableCost variableCost) {
int xValue = 0;
updateGameStatePriority("announceXCost", game);
game.fireGetAmountEvent(playerId, message, min, max);
waitForIntegerResponse(game);
do {
game.fireGetAmountEvent(playerId, message, min, max);
waitForResponse(game);
} while (response.getInteger() == null && !abort);
if (response != null && response.getInteger() != null) {
xValue = response.getInteger();
}
@ -1121,8 +1105,10 @@ public class HumanPlayer extends PlayerImpl {
@Override
public int getAmount(int min, int max, String message, Game game) {
updateGameStatePriority("getAmount", game);
game.fireGetAmountEvent(playerId, message, min, max);
waitForIntegerResponse(game);
do {
game.fireGetAmountEvent(playerId, message, min, max);
waitForResponse(game);
} while (response.getInteger() == null && !abort);
if (response != null && response.getInteger() != null) {
return response.getInteger();
} else {
@ -1209,11 +1195,7 @@ public class HumanPlayer extends PlayerImpl {
if (!ability.getSourceId().equals(getCastSourceIdWithAlternateMana()) && ability.getManaCostsToPay().convertedManaCost() > 0) {
return true;
}
if (ability instanceof ManaAbility) {
return true;
}
// if ability has no mana costs you have to pick it from ability picker
return false;
return ability instanceof ManaAbility;
}
return true;
}
@ -1288,8 +1270,10 @@ public class HumanPlayer extends PlayerImpl {
@Override
public boolean choosePile(Outcome outcome, String message, List<? extends Card> pile1, List<? extends Card> pile2, Game game) {
updateGameStatePriority("choosePile", game);
game.fireChoosePileEvent(playerId, message, pile1, pile2);
waitForBooleanResponse(game);
do {
game.fireChoosePileEvent(playerId, message, pile1, pile2);
waitForResponse(game);
} while (response.getBoolean() == null && !abort);
if (!abort) {
return response.getBoolean();
}
@ -1301,7 +1285,7 @@ public class HumanPlayer extends PlayerImpl {
synchronized (response) {
response.setString(responseString);
response.notify();
log.debug("Got response string from player: " + getId());
logger.debug("Got response string from player: " + getId());
}
}
@ -1311,7 +1295,7 @@ public class HumanPlayer extends PlayerImpl {
response.setManaType(manaType);
response.setResponseManaTypePlayerId(manaTypePlayerId);
response.notify();
log.debug("Got response mana type from player: " + getId());
logger.debug("Got response mana type from player: " + getId());
}
}
@ -1320,7 +1304,7 @@ public class HumanPlayer extends PlayerImpl {
synchronized (response) {
response.setUUID(responseUUID);
response.notify();
log.debug("Got response UUID from player: " + getId());
logger.debug("Got response UUID from player: " + getId());
}
}
@ -1329,7 +1313,7 @@ public class HumanPlayer extends PlayerImpl {
synchronized (response) {
response.setBoolean(responseBoolean);
response.notify();
log.debug("Got response boolean from player: " + getId());
logger.debug("Got response boolean from player: " + getId());
}
}
@ -1338,7 +1322,7 @@ public class HumanPlayer extends PlayerImpl {
synchronized (response) {
response.setInteger(responseInteger);
response.notify();
log.debug("Got response integer from player: " + getId());
logger.debug("Got response integer from player: " + getId());
}
}
@ -1347,7 +1331,7 @@ public class HumanPlayer extends PlayerImpl {
abort = true;
synchronized (response) {
response.notify();
log.debug("Got cancel action from player: " + getId());
logger.debug("Got cancel action from player: " + getId());
}
}
@ -1356,7 +1340,7 @@ public class HumanPlayer extends PlayerImpl {
synchronized (response) {
response.setInteger(0);
response.notify();
log.debug("Got skip action from player: " + getId());
logger.debug("Got skip action from player: " + getId());
}
}
@ -1367,7 +1351,7 @@ public class HumanPlayer extends PlayerImpl {
protected void updateGameStatePriority(String methodName, Game game) {
if (game.getState().getPriorityPlayerId() != null) { // don't do it if priority was set to null before (e.g. discard in cleanaup)
log.debug("Setting game priority to " + getId() + " [" + methodName + "]");
logger.debug("Setting game priority to " + getId() + " [" + methodName + "]");
game.getState().setPriorityPlayerId(getId());
}
}