mirror of
https://github.com/correl/mage.git
synced 2024-11-24 19:19:56 +00:00
Initial working product. Doesn't handle skipping stack.
This commit is contained in:
parent
486d05589b
commit
028d7ed1f8
5 changed files with 127 additions and 1 deletions
|
@ -299,6 +299,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
public static final String KEY_CONNECTION_URL_SERVER_LIST = "connectionURLServerList";
|
public static final String KEY_CONNECTION_URL_SERVER_LIST = "connectionURLServerList";
|
||||||
|
|
||||||
// controls
|
// controls
|
||||||
|
public static final String KEY_CONTROL_TOGGLE_MACRO = "controlToggleMacro";
|
||||||
public static final String KEY_CONTROL_CONFIRM = "controlConfirm";
|
public static final String KEY_CONTROL_CONFIRM = "controlConfirm";
|
||||||
public static final String KEY_CONTROL_CANCEL_SKIP = "controlCancelSkip";
|
public static final String KEY_CONTROL_CANCEL_SKIP = "controlCancelSkip";
|
||||||
public static final String KEY_CONTROL_NEXT_TURN = "controlNextTurn";
|
public static final String KEY_CONTROL_NEXT_TURN = "controlNextTurn";
|
||||||
|
|
|
@ -489,6 +489,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
this.btnStopWatching.setVisible(false);
|
this.btnStopWatching.setVisible(false);
|
||||||
this.btnSwitchHands.setVisible(false);
|
this.btnSwitchHands.setVisible(false);
|
||||||
this.btnCancelSkip.setVisible(true);
|
this.btnCancelSkip.setVisible(true);
|
||||||
|
this.btnToggleMacro.setVisible(true);
|
||||||
|
|
||||||
this.btnSkipToNextTurn.setVisible(true);
|
this.btnSkipToNextTurn.setVisible(true);
|
||||||
this.btnSkipToEndTurn.setVisible(true);
|
this.btnSkipToEndTurn.setVisible(true);
|
||||||
|
@ -522,6 +523,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
this.btnSwitchHands.setVisible(false);
|
this.btnSwitchHands.setVisible(false);
|
||||||
this.chosenHandKey = "";
|
this.chosenHandKey = "";
|
||||||
this.btnCancelSkip.setVisible(false);
|
this.btnCancelSkip.setVisible(false);
|
||||||
|
this.btnToggleMacro.setVisible(false);
|
||||||
|
|
||||||
this.btnSkipToNextTurn.setVisible(false);
|
this.btnSkipToNextTurn.setVisible(false);
|
||||||
this.btnSkipToEndTurn.setVisible(false);
|
this.btnSkipToEndTurn.setVisible(false);
|
||||||
|
@ -1346,6 +1348,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
txtHoldPriority.setToolTipText("Holding priority after the next spell cast or ability activation");
|
txtHoldPriority.setToolTipText("Holding priority after the next spell cast or ability activation");
|
||||||
txtHoldPriority.setVisible(false);
|
txtHoldPriority.setVisible(false);
|
||||||
|
|
||||||
|
btnToggleMacro = new KeyboundButton(KEY_CONTROL_TOGGLE_MACRO);
|
||||||
btnCancelSkip = new KeyboundButton(KEY_CONTROL_CANCEL_SKIP); // F3
|
btnCancelSkip = new KeyboundButton(KEY_CONTROL_CANCEL_SKIP); // F3
|
||||||
btnSkipToNextTurn = new KeyboundButton(KEY_CONTROL_NEXT_TURN); // F4
|
btnSkipToNextTurn = new KeyboundButton(KEY_CONTROL_NEXT_TURN); // F4
|
||||||
btnSkipToEndTurn = new KeyboundButton(KEY_CONTROL_END_STEP); // F5
|
btnSkipToEndTurn = new KeyboundButton(KEY_CONTROL_END_STEP); // F5
|
||||||
|
@ -1437,6 +1440,30 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
|
||||||
|
|
||||||
|
|
||||||
|
btnToggleMacro.setContentAreaFilled(false);
|
||||||
|
btnToggleMacro.setBorder(new EmptyBorder(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE));
|
||||||
|
btnToggleMacro.setIcon(new ImageIcon(ImageManagerImpl.instance.getSkipNextTurnButtonImage()));
|
||||||
|
btnToggleMacro.setToolTipText("Toggle Record Macro (F8).");
|
||||||
|
btnToggleMacro.setFocusable(false);
|
||||||
|
btnToggleMacro.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent evt) {
|
||||||
|
if (evt.getButton() == MouseEvent.BUTTON1) {
|
||||||
|
btnToggleMacroActionPerformed(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
KeyStroke kst = KeyStroke.getKeyStroke(KeyEvent.VK_F8, 0);
|
||||||
|
this.getInputMap(c).put(kst, "F8_PRESS");
|
||||||
|
this.getActionMap().put("F8_PRESS", new AbstractAction() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent actionEvent) {
|
||||||
|
btnToggleMacroActionPerformed(actionEvent);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
KeyStroke ks3 = getCachedKeystroke(KEY_CONTROL_CANCEL_SKIP);
|
KeyStroke ks3 = getCachedKeystroke(KEY_CONTROL_CANCEL_SKIP);
|
||||||
this.getInputMap(c).put(ks3, "F3_PRESS");
|
this.getInputMap(c).put(ks3, "F3_PRESS");
|
||||||
this.getActionMap().put("F3_PRESS", new AbstractAction() {
|
this.getActionMap().put("F3_PRESS", new AbstractAction() {
|
||||||
|
@ -1809,6 +1836,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
.addComponent(btnSkipToEndStepBeforeYourTurn)
|
.addComponent(btnSkipToEndStepBeforeYourTurn)
|
||||||
)
|
)
|
||||||
.addGroup(gl_pnlShortCuts.createSequentialGroup()
|
.addGroup(gl_pnlShortCuts.createSequentialGroup()
|
||||||
|
.addComponent(btnToggleMacro)
|
||||||
.addComponent(txtHoldPriority)
|
.addComponent(txtHoldPriority)
|
||||||
.addComponent(txtSpellsCast)
|
.addComponent(txtSpellsCast)
|
||||||
.addComponent(btnSwitchHands)
|
.addComponent(btnSwitchHands)
|
||||||
|
@ -1843,6 +1871,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
.addComponent(btnSkipToEndStepBeforeYourTurn)
|
.addComponent(btnSkipToEndStepBeforeYourTurn)
|
||||||
)
|
)
|
||||||
.addGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
.addGroup(gl_pnlShortCuts.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||||
|
.addComponent(btnToggleMacro)
|
||||||
.addComponent(txtHoldPriority)
|
.addComponent(txtHoldPriority)
|
||||||
.addComponent(txtSpellsCast)
|
.addComponent(txtSpellsCast)
|
||||||
.addComponent(btnSwitchHands)
|
.addComponent(btnSwitchHands)
|
||||||
|
@ -1989,6 +2018,9 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
for (MouseListener ml : this.getMouseListeners()) {
|
for (MouseListener ml : this.getMouseListeners()) {
|
||||||
this.removeMouseListener(ml);
|
this.removeMouseListener(ml);
|
||||||
}
|
}
|
||||||
|
for (MouseListener ml : this.btnToggleMacro.getMouseListeners()) {
|
||||||
|
this.btnToggleMacro.removeMouseListener(ml);
|
||||||
|
}
|
||||||
for (MouseListener ml : this.btnCancelSkip.getMouseListeners()) {
|
for (MouseListener ml : this.btnCancelSkip.getMouseListeners()) {
|
||||||
this.btnCancelSkip.removeMouseListener(ml);
|
this.btnCancelSkip.removeMouseListener(ml);
|
||||||
}
|
}
|
||||||
|
@ -2071,6 +2103,12 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
MageFrame.getInstance().showUserRequestDialog(message);
|
MageFrame.getInstance().showUserRequestDialog(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void btnToggleMacroActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
SessionHandler.sendPlayerAction(PlayerAction.TOGGLE_RECORD_MACRO, gameId, null);
|
||||||
|
AudioManager.playOnSkipButton();
|
||||||
|
updateSkipButtons(false, false, false, false, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
private void btnEndTurnActionPerformed(java.awt.event.ActionEvent evt) {
|
private void btnEndTurnActionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null);
|
SessionHandler.sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_NEXT_TURN, gameId, null);
|
||||||
AudioManager.playOnSkipButton();
|
AudioManager.playOnSkipButton();
|
||||||
|
@ -2360,6 +2398,7 @@ public final class GamePanel extends javax.swing.JPanel {
|
||||||
private mage.client.cards.BigCard bigCard;
|
private mage.client.cards.BigCard bigCard;
|
||||||
|
|
||||||
// private JPanel cancelSkipPanel;
|
// private JPanel cancelSkipPanel;
|
||||||
|
private KeyboundButton btnToggleMacro;
|
||||||
private KeyboundButton btnCancelSkip;
|
private KeyboundButton btnCancelSkip;
|
||||||
private KeyboundButton btnSkipToNextTurn; // F4
|
private KeyboundButton btnSkipToNextTurn; // F4
|
||||||
private KeyboundButton btnSkipToEndTurn; // F5
|
private KeyboundButton btnSkipToEndTurn; // F5
|
||||||
|
|
|
@ -103,6 +103,12 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
protected boolean holdingPriority;
|
protected boolean holdingPriority;
|
||||||
|
|
||||||
|
protected Queue<PlayerResponse> actionQueue = new LinkedList<>();
|
||||||
|
protected Queue<PlayerResponse> actionQueueSaved = new LinkedList<>();
|
||||||
|
protected int actionIterations = 0;
|
||||||
|
protected boolean recordingMacro = false;
|
||||||
|
|
||||||
|
|
||||||
public HumanPlayer(String name, RangeOfInfluence range, int skill) {
|
public HumanPlayer(String name, RangeOfInfluence range, int skill) {
|
||||||
super(name, range);
|
super(name, range);
|
||||||
replacementEffectChoice = new ChoiceImpl(true);
|
replacementEffectChoice = new ChoiceImpl(true);
|
||||||
|
@ -117,7 +123,31 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
this.replacementEffectChoice = player.replacementEffectChoice;
|
this.replacementEffectChoice = player.replacementEffectChoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean pullResponseFromQueue(Game game) {
|
||||||
|
if (actionQueue.isEmpty() && actionIterations > 0 && !actionQueueSaved.isEmpty()) {
|
||||||
|
actionQueue = new LinkedList(actionQueueSaved);
|
||||||
|
actionIterations--;
|
||||||
|
}
|
||||||
|
PlayerResponse action = actionQueue.poll();
|
||||||
|
if (action != null) {
|
||||||
|
logger.info("Popping an action " + action);
|
||||||
|
synchronized (response) {
|
||||||
|
if (action.getString() != null && action.getString().equals("resolveStack")) {
|
||||||
|
logger.info("Skipping stack");
|
||||||
|
sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_STACK_RESOLVED, game, null);
|
||||||
|
response.clear();
|
||||||
|
} else {
|
||||||
|
response.copy(action);
|
||||||
|
}
|
||||||
|
response.notifyAll();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected void waitForResponse(Game game) {
|
protected void waitForResponse(Game game) {
|
||||||
|
if(pullResponseFromQueue(game)) return;
|
||||||
response.clear();
|
response.clear();
|
||||||
logger.debug("Waiting response from player: " + getId());
|
logger.debug("Waiting response from player: " + getId());
|
||||||
game.resumeTimer(getTurnControlledBy());
|
game.resumeTimer(getTurnControlledBy());
|
||||||
|
@ -131,6 +161,10 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
game.pauseTimer(getTurnControlledBy());
|
game.pauseTimer(getTurnControlledBy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (recordingMacro) {
|
||||||
|
logger.info("Adding an action " + response);
|
||||||
|
actionQueueSaved.add(new PlayerResponse(response));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -679,6 +713,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
holdingPriority = false;
|
holdingPriority = false;
|
||||||
game.firePriorityEvent(playerId);
|
game.firePriorityEvent(playerId);
|
||||||
waitForResponse(game);
|
waitForResponse(game);
|
||||||
|
logger.info("Human Priority got response: " + response);
|
||||||
if (game.executingRollback()) {
|
if (game.executingRollback()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1523,6 +1558,28 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
case UNHOLD_PRIORITY:
|
case UNHOLD_PRIORITY:
|
||||||
holdingPriority = false;
|
holdingPriority = false;
|
||||||
break;
|
break;
|
||||||
|
case TOGGLE_RECORD_MACRO:
|
||||||
|
if(recordingMacro) {
|
||||||
|
logger.info("Finished Recording Macro");
|
||||||
|
recordingMacro = false;
|
||||||
|
// TODO: Figure out how to make dialog
|
||||||
|
actionIterations = 3;
|
||||||
|
pullResponseFromQueue(game);
|
||||||
|
} else {
|
||||||
|
logger.info("Starting Recording Macro");
|
||||||
|
resetPlayerPassedActions();
|
||||||
|
recordingMacro = true;
|
||||||
|
actionIterations = 0;
|
||||||
|
actionQueueSaved.clear();
|
||||||
|
actionQueue.clear();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case PASS_PRIORITY_UNTIL_STACK_RESOLVED:
|
||||||
|
if (recordingMacro) {
|
||||||
|
PlayerResponse tResponse = new PlayerResponse();
|
||||||
|
tResponse.setString("resolveStack");
|
||||||
|
actionQueueSaved.add(tResponse);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
super.sendPlayerAction(playerAction, game, data);
|
super.sendPlayerAction(playerAction, game, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,34 @@ public class PlayerResponse implements Serializable {
|
||||||
private ManaType responseManaType;
|
private ManaType responseManaType;
|
||||||
private UUID responseManaTypePlayerId;
|
private UUID responseManaTypePlayerId;
|
||||||
|
|
||||||
|
public PlayerResponse() {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
String res = new String();
|
||||||
|
res += responseString + ",";
|
||||||
|
res += responseUUID + ",";
|
||||||
|
res += responseBoolean + ",";
|
||||||
|
res += responseInteger + ",";
|
||||||
|
res += responseManaType + ",";
|
||||||
|
res += responseManaTypePlayerId;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PlayerResponse(PlayerResponse other) {
|
||||||
|
copy(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void copy(PlayerResponse other) {
|
||||||
|
responseString = other.responseString;
|
||||||
|
responseUUID = other.responseUUID;
|
||||||
|
responseBoolean = other.responseBoolean;
|
||||||
|
responseInteger = other.responseInteger;
|
||||||
|
responseManaType = other.responseManaType;
|
||||||
|
responseManaTypePlayerId = other.responseManaTypePlayerId;
|
||||||
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
responseString = null;
|
responseString = null;
|
||||||
responseUUID = null;
|
responseUUID = null;
|
||||||
|
|
|
@ -84,5 +84,6 @@ public enum PlayerAction {
|
||||||
CLIENT_REPLAY_ACTION,
|
CLIENT_REPLAY_ACTION,
|
||||||
HOLD_PRIORITY,
|
HOLD_PRIORITY,
|
||||||
UNHOLD_PRIORITY,
|
UNHOLD_PRIORITY,
|
||||||
VIEW_LIMITED_DECK
|
VIEW_LIMITED_DECK,
|
||||||
|
TOGGLE_RECORD_MACRO
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue