forked from External/mage
draft improves: add protection timer (2 sec) to avoid double pick (#11188)
This commit is contained in:
parent
35710efa60
commit
a58cac2fd5
2 changed files with 56 additions and 13 deletions
|
|
@ -19,7 +19,6 @@
|
|||
import javax.swing.Timer;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.dnd.DragSourceEvent;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
|
@ -42,6 +41,20 @@
|
|||
private Timer countdown;
|
||||
private int timeout;
|
||||
|
||||
/**
|
||||
* ms delay between booster showing up and pick being allowed.
|
||||
*/
|
||||
private static final int protectionTime = 2000;
|
||||
/**
|
||||
* Timer starting at booster being displayed, to protect from early pick due to clicking
|
||||
* a little too much on the last pick.
|
||||
*/
|
||||
private Timer protectionTimer;
|
||||
/**
|
||||
* Number of the latest card pick for which the protection timer has been set.
|
||||
*/
|
||||
private int protectionPickNo = 0;
|
||||
|
||||
// popup menu area picked cards
|
||||
private final JPopupMenu popupMenuPickedArea;
|
||||
// popup menu for a card
|
||||
|
|
@ -108,6 +121,10 @@
|
|||
}
|
||||
}
|
||||
);
|
||||
|
||||
protectionTimer = new Timer(protectionTime, e -> {
|
||||
protectionTimer.stop();
|
||||
});
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
|
|
@ -120,6 +137,13 @@
|
|||
countdown.removeActionListener(al);
|
||||
}
|
||||
}
|
||||
|
||||
if (protectionTimer != null) {
|
||||
protectionTimer.stop();
|
||||
for (ActionListener al : protectionTimer.getActionListeners()) {
|
||||
protectionTimer.removeActionListener(al);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeGUISize() {
|
||||
|
|
@ -311,7 +335,13 @@
|
|||
}
|
||||
|
||||
if (!draftBooster.isEmptyGrid()) {
|
||||
SessionHandler.setBoosterLoaded(draftId); // confirm to the server that the booster has been successfully loaded, otherwise the server will re-send the booster
|
||||
SessionHandler.setBoosterLoaded(draftId); // confirm to the server that the booster has been successfully loaded, otherwise the server will re-send the booster
|
||||
|
||||
if(pickNo != protectionPickNo && !protectionTimer.isRunning()) {
|
||||
// Restart the protection timer.
|
||||
protectionPickNo = pickNo;
|
||||
protectionTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -345,6 +375,10 @@
|
|||
}
|
||||
}
|
||||
|
||||
public boolean isAllowedToPick() {
|
||||
return !protectionTimer.isRunning();
|
||||
}
|
||||
|
||||
public void hideDraft() {
|
||||
Component c = this.getParent();
|
||||
while (c != null && !(c instanceof DraftPane)) {
|
||||
|
|
@ -525,7 +559,7 @@
|
|||
lblPlayer15 = new javax.swing.JLabel();
|
||||
lblPlayer16 = new javax.swing.JLabel();
|
||||
draftPicks = new mage.client.cards.CardsList();
|
||||
draftBooster = new mage.client.cards.DraftGrid();
|
||||
draftBooster = new mage.client.cards.DraftGrid(this);
|
||||
|
||||
draftLeftPane.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
||||
draftLeftPane.setFocusable(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue