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
|
|
@ -1,15 +1,16 @@
|
|||
package mage.client.cards;
|
||||
|
||||
import mage.cards.CardDimensions;
|
||||
import mage.abilities.icon.CardIconRenderSettings;
|
||||
import mage.cards.CardDimensions;
|
||||
import mage.cards.MageCard;
|
||||
import mage.client.dialog.PreferencesDialog;
|
||||
import mage.client.draft.DraftPanel;
|
||||
import mage.client.plugins.impl.Plugins;
|
||||
import mage.client.util.comparators.CardViewRarityComparator;
|
||||
import mage.client.util.ClientEventType;
|
||||
import mage.client.util.Event;
|
||||
import mage.client.util.Listener;
|
||||
import mage.client.util.audio.AudioManager;
|
||||
import mage.client.util.comparators.CardViewRarityComparator;
|
||||
import mage.constants.Constants;
|
||||
import mage.view.CardView;
|
||||
import mage.view.CardsView;
|
||||
|
|
@ -28,6 +29,8 @@ public class DraftGrid extends javax.swing.JPanel implements CardEventProducer {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(DraftGrid.class);
|
||||
|
||||
private final DraftPanel parentPanel;
|
||||
|
||||
protected final CardEventSource cardEventSource = new CardEventSource();
|
||||
protected BigCard bigCard;
|
||||
protected MageCard markedCard;
|
||||
|
|
@ -36,22 +39,28 @@ public class DraftGrid extends javax.swing.JPanel implements CardEventProducer {
|
|||
/**
|
||||
* Creates new form DraftGrid
|
||||
*/
|
||||
public DraftGrid() {
|
||||
public DraftGrid(DraftPanel panel) {
|
||||
initComponents();
|
||||
parentPanel = panel;
|
||||
markedCard = null;
|
||||
emptyGrid = true;
|
||||
|
||||
// ENABLE picks and other actions
|
||||
cardEventSource.addListener(new Listener<Event>() {
|
||||
@Override
|
||||
public void event(Event event) {
|
||||
if (event.getEventType() == ClientEventType.CARD_DOUBLE_CLICK) {
|
||||
cardEventSource.addListener(event -> {
|
||||
if (event.getEventType() == ClientEventType.CARD_DOUBLE_CLICK
|
||||
|| event.getEventType() == ClientEventType.CARD_CLICK) {
|
||||
// There is a protection against picking too early in DraftPanel logic.
|
||||
// So, when double clicking early, we do mark the card as selected like
|
||||
// a single click would.
|
||||
|
||||
CardView card = (CardView) event.getSource();
|
||||
if(event.getEventType() == ClientEventType.CARD_DOUBLE_CLICK
|
||||
&& parentPanel.isAllowedToPick()
|
||||
) {
|
||||
cardEventSource.fireEvent(card, ClientEventType.DRAFT_PICK_CARD);
|
||||
hidePopup();
|
||||
AudioManager.playOnDraftSelect();
|
||||
} else if (event.getEventType() == ClientEventType.CARD_CLICK) {
|
||||
CardView card = (CardView) event.getSource();
|
||||
} else {
|
||||
MageCard cardPanel = (MageCard) event.getComponent();
|
||||
if (markedCard != null) {
|
||||
markedCard.setSelected(false);
|
||||
|
|
|
|||
|
|
@ -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() {
|
||||
|
|
@ -312,6 +336,12 @@
|
|||
|
||||
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
|
||||
|
||||
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