* Draft - Added possibility to hide (and show again) cards from the picked cards area.

This commit is contained in:
LevelX2 2014-11-22 18:19:59 +01:00
parent 4622973639
commit bf3fa37e5d
6 changed files with 217 additions and 31 deletions

View file

@ -28,6 +28,7 @@
package mage.client.cards;
import java.awt.Component;
import mage.client.util.Event;
import mage.client.util.EventDispatcher;
import mage.client.util.EventSource;
@ -69,6 +70,11 @@ public class CardEventSource implements EventSource<Event>, Serializable {
dispatcher.fireEvent(new Event(null, message));
}
public void showPopupMenuEvent(SimpleCardView card, Component component, int x, int y, String message) {
dispatcher.fireEvent(new Event(card, message, x, y, component));
}
@Override
public void clearListeners() {
dispatcher.clearListeners();

View file

@ -48,7 +48,7 @@
<Group type="102" alignment="0" attributes="0">
<Component id="panelControl" min="-2" pref="25" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="-2" attributes="0"/>
<Component id="panelCardArea" pref="266" max="32767" attributes="0"/>
<Component id="panelCardArea" pref="330" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -92,7 +92,7 @@
<Component id="jToggleListView" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="jToggleCardView" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="55" max="32767" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -127,7 +127,7 @@
<Property name="text" type="java.lang.String" value="999"/>
<Property name="toolTipText" type="java.lang.String" value="Number of all cards in this area."/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
<Color id="Standardcursor"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="inheritsPopupMenu" type="boolean" value="false"/>
@ -145,7 +145,7 @@
<Property name="toolTipText" type="java.lang.String" value="Number of lands."/>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
<Color id="Standardcursor"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="inheritsPopupMenu" type="boolean" value="false"/>
@ -163,7 +163,7 @@
<Property name="toolTipText" type="java.lang.String" value="Number of creatures."/>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
<Color id="Standardcursor"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="inheritsPopupMenu" type="boolean" value="false"/>
@ -181,7 +181,7 @@
<Property name="toolTipText" type="java.lang.String" value="Number of sorceries."/>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
<Color id="Standardcursor"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="inheritsPopupMenu" type="boolean" value="false"/>
@ -199,7 +199,7 @@
<Property name="toolTipText" type="java.lang.String" value="Number of instants."/>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
<Color id="Standardcursor"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="inheritsPopupMenu" type="boolean" value="false"/>
@ -217,7 +217,7 @@
<Property name="toolTipText" type="java.lang.String" value="Number of enchantments."/>
<Property name="verticalAlignment" type="int" value="1"/>
<Property name="cursor" type="java.awt.Cursor" editor="org.netbeans.modules.form.editors2.CursorEditor">
<Color id="Default Cursor"/>
<Color id="Standardcursor"/>
</Property>
<Property name="focusable" type="boolean" value="false"/>
<Property name="inheritsPopupMenu" type="boolean" value="false"/>

View file

@ -78,6 +78,7 @@ import mage.client.util.gui.TableSpinnerEditor;
import mage.constants.CardType;
import mage.view.CardView;
import mage.view.CardsView;
import mage.view.SimpleCardView;
import org.mage.card.arcane.CardPanel;
/**
@ -114,6 +115,11 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
mainModel.removeTableModelListener(mainTable);
mainModel.clear();
}
if(cardArea != null) {
for(MouseListener ml: cardArea.getMouseListeners()) {
cardArea.removeMouseListener(ml);
}
}
if(mainTable != null) {
for(MouseListener ml: mainTable.getMouseListeners()) {
mainTable.removeMouseListener(ml);
@ -175,6 +181,9 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
cbSortBy.setEnabled(true);
chkPiles.setEnabled(true);
}
cardArea.addMouseListener(this);
mainTable.setOpaque(false);
mainTable.addMouseListener(new MouseAdapter() {
@Override
@ -621,7 +630,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
.addComponent(jToggleListView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jToggleCardView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 55, Short.MAX_VALUE))
.addGap(0, 0, Short.MAX_VALUE))
);
panelControlLayout.setVerticalGroup(
panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -661,7 +670,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
.addGroup(layout.createSequentialGroup()
.addComponent(panelControl, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, 0)
.addComponent(panelCardArea, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE))
.addComponent(panelCardArea, javax.swing.GroupLayout.DEFAULT_SIZE, 330, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
@ -716,29 +725,51 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
@Override
public void mousePressed(MouseEvent e) {
if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume();
if (e.getClickCount() >= 1 && !e.isConsumed()) {
Object obj = e.getSource();
if (obj instanceof Card) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card)obj).getOriginal(), "alt-double-click");
}
else {
cardEventSource.doubleClick(((Card)obj).getOriginal(), "double-click");
}
} else if (obj instanceof MageCard) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((MageCard)obj).getOriginal(), "alt-double-click");
}
else {
cardEventSource.doubleClick(((MageCard)obj).getOriginal(), "double-click");
if (e.getClickCount() == 2) {
e.consume();
if (obj instanceof Card) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card)obj).getOriginal(), "alt-double-click");
}
else {
cardEventSource.doubleClick(((Card)obj).getOriginal(), "double-click");
}
} else if (obj instanceof MageCard) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((MageCard)obj).getOriginal(), "alt-double-click");
}
else {
cardEventSource.doubleClick(((MageCard)obj).getOriginal(), "double-click");
}
}
}
if (obj instanceof MageCard) {
checkMenu(e, ((MageCard)obj).getOriginal());
} else {
checkMenu(e, null);
}
}
}
@Override
public void mouseReleased(MouseEvent e) {
if (!e.isConsumed()) {
Object obj = e.getSource();
if (obj instanceof MageCard) {
checkMenu(e, ((MageCard)obj).getOriginal());
} else {
checkMenu(e, null);
}
}
}
private void checkMenu(MouseEvent Me, SimpleCardView card){
if (Me.isPopupTrigger()) {
Me.consume();
cardEventSource.showPopupMenuEvent(card, Me.getComponent(), Me.getX(), Me.getY(), "show-popup-menu");
}
}
@Override

View file

@ -39,10 +39,19 @@ import java.awt.Dimension;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.KeyStroke;
import javax.swing.Timer;
import mage.client.MageFrame;
import mage.client.components.tray.MageTray;
@ -59,6 +68,7 @@ import mage.view.CardsView;
import mage.view.DraftPickView;
import mage.view.DraftView;
import mage.view.SimpleCardView;
import mage.view.SimpleCardsView;
/**
*
@ -70,7 +80,19 @@ public class DraftPanel extends javax.swing.JPanel {
private Session session;
private Timer countdown;
private int timeout;
private boolean picked;
// popup menu area picked cards
private final JPopupMenu popupMenuPickedArea;
// popup menu for a card
private final JPopupMenu popupMenuCardPanel;
// cards hidden in the picked cards area
private final Set<UUID> cardsHidden = new HashSet<>();
// all cards picked
protected SimpleCardsView pickedCards;
// all cards picked
protected SimpleCardsView pickedCardsShown = new SimpleCardsView();
// id of card with popup menu
protected UUID cardIdPopupMenu;
private static final CardsView emptyView = new CardsView();
@ -81,6 +103,15 @@ public class DraftPanel extends javax.swing.JPanel {
draftBooster.setOpaque(false);
draftPicks.setSortSetting(SortSettingDraft.getInstance());
draftPicks.setOpaque(false);
popupMenuPickedArea = new JPopupMenu();
addPopupMenuPickArea();
this.add(popupMenuPickedArea);
popupMenuCardPanel = new JPopupMenu();
addPopupMenuCardPanel();
this.add(popupMenuCardPanel);
draftLeftPane.setOpaque(false);
countdown = new Timer(1000,
@ -209,8 +240,29 @@ public class DraftPanel extends javax.swing.JPanel {
}
public void loadBooster(DraftPickView draftPickView) {
// upper area that shows the picks
loadCardsToPickedCardsArea(draftPickView.getPicks());
this.draftPicks.clearCardEventListeners();
this.draftPicks.addCardEventListener(new Listener<Event> () {
@Override
public void event(Event event) {
if (event.getEventName().equals("show-popup-menu")) {
if (event.getSource() != null) {
// Popup Menu Card
cardIdPopupMenu = ((SimpleCardView)event.getSource()).getId();
popupMenuCardPanel.show(event.getComponent(), event.getxPos(), event.getyPos());
} else {
// Popup Menu area
popupMenuPickedArea.show(event.getComponent(), event.getxPos(), event.getyPos());
}
}
}
}
);
// lower area that shows the booster
draftBooster.loadBooster(CardsViewUtil.convertSimple(draftPickView.getBooster()), bigCard);
draftPicks.loadCards(CardsViewUtil.convertSimple(draftPickView.getPicks()), bigCard, null);
this.draftBooster.clearCardEventListeners();
this.draftBooster.addCardEventListener(
new Listener<Event> () {
@ -220,8 +272,8 @@ public class DraftPanel extends javax.swing.JPanel {
SimpleCardView source = (SimpleCardView) event.getSource();
DraftPickView view = session.sendCardPick(draftId, source.getId());
if (view != null) {
draftBooster.loadBooster(emptyView, bigCard);
draftPicks.loadCards(CardsViewUtil.convertSimple(view.getPicks()), bigCard, null);
loadCardsToPickedCardsArea(view.getPicks());
draftBooster.loadBooster(emptyView, bigCard);
Plugins.getInstance().getActionCallback().hidePopup();
setMessage("Waiting for other players");
}
@ -245,7 +297,17 @@ public class DraftPanel extends javax.swing.JPanel {
countdown.start();
}
}
private void loadCardsToPickedCardsArea(SimpleCardsView pickedCards) {
this.pickedCards = pickedCards;
for (Map.Entry<UUID,SimpleCardView> entry: pickedCards.entrySet()) {
if (!cardsHidden.contains(entry.getKey())) {
pickedCardsShown.put(entry.getKey(), entry.getValue());
}
}
draftPicks.loadCards(CardsViewUtil.convertSimple(pickedCardsShown), bigCard, null);
}
private void setTimeout(int s){
int minute = s/60;
int second = s - (minute*60);
@ -280,6 +342,64 @@ public class DraftPanel extends javax.swing.JPanel {
this.lblMessage.setText(message);
}
private void addPopupMenuPickArea() {
int c = JComponent.WHEN_IN_FOCUSED_WINDOW;
KeyStroke ks9 = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
this.getInputMap(c).put(ks9, "F9_PRESS");
this.getActionMap().put("F9_PRESS", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
showAgainAllHiddenCards();
}
});
JMenuItem menuItem;
menuItem = new JMenuItem("F9 - Show all hidden cards");
popupMenuPickedArea.add(menuItem);
// Confirm (F9)
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
showAgainAllHiddenCards();
}
});
// popupMenuPickedArea.addSeparator();
}
private void addPopupMenuCardPanel() {
JMenuItem menuItem;
menuItem = new JMenuItem("Hide this card");
popupMenuCardPanel.add(menuItem);
// Hide Card
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// Add the card to the hidden cards
cardsHidden.add(cardIdPopupMenu);
pickedCardsShown.remove(cardIdPopupMenu);
draftPicks.loadCards(CardsViewUtil.convertSimple(pickedCardsShown), bigCard, null);
}
});
// popupMenuCardPanel.addSeparator();
}
private void showAgainAllHiddenCards() {
// show again all hidden cards
cardsHidden.clear();
draftPicks.loadCards(CardsViewUtil.convertSimple(pickedCards), bigCard, null);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is

View file

@ -28,6 +28,7 @@
package mage.client.util;
import java.awt.Component;
import java.io.Serializable;
/**
@ -36,8 +37,11 @@ import java.io.Serializable;
*/
public class Event implements Serializable {
private final Object source;
private final Component component;
private final String eventName;
private final int number;
private final int xPos;
private final int yPos;
public Event(Object source, String eventName) {
this(source, eventName, 0);
@ -47,6 +51,18 @@ public class Event implements Serializable {
this.source = source;
this.eventName = eventName;
this.number = number;
this.xPos = 0;
this.yPos = 0;
this.component = null;
}
public Event(Object source, String eventName, int xPos, int yPos, Component component) {
this.source = source;
this.eventName = eventName;
this.number =0;
this.xPos = xPos;
this.yPos = yPos;
this.component = component;
}
public Object getSource() {
@ -60,5 +76,17 @@ public class Event implements Serializable {
public int getNumber() {
return number;
}
public int getxPos() {
return xPos;
}
public int getyPos() {
return yPos;
}
public Component getComponent() {
return component;
}
}

View file

@ -35,10 +35,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
/**
*
* @author BetaSteward_at_googlemail.com
* @param <E>
*/
public abstract class EventDispatcher<E extends Event> implements Serializable {
private List<Listener<E>> listeners = new CopyOnWriteArrayList<Listener<E>>();
private final List<Listener<E>> listeners = new CopyOnWriteArrayList<>();
public void addListener(Listener<E> listener) {
if (!listeners.contains(listener)) {