change client messages to enum rather than string

This commit is contained in:
igoudt 2017-10-03 15:18:31 +02:00
parent a110b54d91
commit 9cbc2b7ea2
14 changed files with 233 additions and 331 deletions

View file

@ -27,20 +27,9 @@
*/
package mage.client.cards;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import java.util.UUID;
import javax.swing.JLayeredPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import mage.cards.MageCard;
import mage.client.plugins.impl.Plugins;
import mage.client.util.ClientEventType;
import mage.client.util.Event;
import mage.client.util.GUISizeHelper;
import mage.client.util.Listener;
@ -50,6 +39,13 @@ import mage.view.CardsView;
import mage.view.SimpleCardView;
import org.mage.card.arcane.CardPanel;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;
import java.util.UUID;
public class CardArea extends JPanel implements MouseListener {
protected final CardEventSource cardEventSource = new CardEventSource();
@ -240,15 +236,15 @@ public class CardArea extends JPanel implements MouseListener {
e.consume();
if (obj instanceof Card) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card) obj).getOriginal(), "alt-double-click");
cardEventSource.fireEvent(((Card) obj).getOriginal(), ClientEventType.ALT_DOUBLE_CLICK);
} else {
cardEventSource.doubleClick(((Card) obj).getOriginal(), "double-click");
cardEventSource.fireEvent(((Card) obj).getOriginal(), ClientEventType.DOUBLE_CLICK);
}
} else if (obj instanceof MageCard) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((MageCard) obj).getOriginal(), "alt-double-click");
cardEventSource.fireEvent(((MageCard) obj).getOriginal(), ClientEventType.ALT_DOUBLE_CLICK);
} else {
cardEventSource.doubleClick(((MageCard) obj).getOriginal(), "double-click");
cardEventSource.fireEvent(((MageCard) obj).getOriginal(),ClientEventType.DOUBLE_CLICK);
}
}
}
@ -270,14 +266,14 @@ public class CardArea extends JPanel implements MouseListener {
checkMenu(e, null);
}
} else {
cardEventSource.actionConsumedEvent("action-consumed");
cardEventSource.fireEvent(ClientEventType.ACTION_CONSUMED);
}
}
private void checkMenu(MouseEvent Me, SimpleCardView card) {
if (Me.isPopupTrigger()) {
Me.consume();
cardEventSource.showPopupMenuEvent(card, Me.getComponent(), Me.getX(), Me.getY(), "show-popup-menu");
cardEventSource.fireEvent(card, Me.getComponent(), Me.getX(), Me.getY(), ClientEventType.SHOW_POP_UP_MENU);
}
}

View file

@ -27,14 +27,13 @@
*/
package mage.client.cards;
import java.awt.Component;
import java.io.Serializable;
import mage.client.util.*;
import mage.client.util.Event;
import mage.client.util.EventDispatcher;
import mage.client.util.EventSource;
import mage.client.util.Listener;
import mage.view.SimpleCardView;
import java.awt.*;
import java.io.Serializable;
/**
*
* @author BetaSteward_at_googlemail.com
@ -49,42 +48,22 @@ public class CardEventSource implements EventSource<Event>, Serializable {
dispatcher.addListener(listener);
}
public void setNumber(SimpleCardView card, String message, int number) {
dispatcher.fireEvent(new Event(card, message, number));
public void fireEvent(SimpleCardView card, ClientEventType eventType, int number){
dispatcher.fireEvent(new Event(card, eventType, number));
}
public void removeSpecificCard(SimpleCardView card, String message) {
dispatcher.fireEvent(new Event(card, message));
public void fireEvent(ClientEventType eventType){
dispatcher.fireEvent(new Event(null, eventType));
}
public void addSpecificCard(SimpleCardView card, String message) {
dispatcher.fireEvent(new Event(card, message));
public void fireEvent(SimpleCardView card, ClientEventType eventType){
dispatcher.fireEvent(new Event(card, eventType));
}
public void doubleClick(SimpleCardView card, String message) {
dispatcher.fireEvent(new Event(card, message));
}
public void altDoubleClick(SimpleCardView card, String message) {
dispatcher.fireEvent(new Event(card, message));
}
public void removeFromMainEvent(String message) {
dispatcher.fireEvent(new Event(null, message));
}
public void removeFromSideboardEvent(String message) {
dispatcher.fireEvent(new Event(null, message));
}
public void showPopupMenuEvent(SimpleCardView card, Component component, int x, int y, String message) {
public void fireEvent(SimpleCardView card, Component component, int x, int y, ClientEventType message) {
dispatcher.fireEvent(new Event(card, message, x, y, component));
}
public void actionConsumedEvent(String message) {
dispatcher.fireEvent(new Event(null, message));
}
@Override
public void clearListeners() {
dispatcher.clearListeners();

View file

@ -33,22 +33,10 @@
*/
package mage.client.cards;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import mage.cards.MageCard;
import mage.client.deckeditor.SortSetting;
import mage.client.plugins.impl.Plugins;
import mage.client.util.ClientEventType;
import mage.client.util.Event;
import mage.client.util.GUISizeHelper;
import mage.client.util.Listener;
@ -57,6 +45,13 @@ import mage.view.CardView;
import mage.view.CardsView;
import org.mage.card.arcane.CardPanel;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
/**
*
* @author BetaSteward_at_googlemail.com
@ -321,15 +316,15 @@ public class CardGrid extends javax.swing.JLayeredPane implements MouseListener,
Object obj = e.getSource();
if (obj instanceof Card) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card) obj).getOriginal(), "alt-double-click");
cardEventSource.fireEvent(((Card) obj).getOriginal(), ClientEventType.ALT_DOUBLE_CLICK);
} else {
cardEventSource.doubleClick(((Card) obj).getOriginal(), "double-click");
cardEventSource.fireEvent(((Card) obj).getOriginal(), ClientEventType.DOUBLE_CLICK);
}
} else if (obj instanceof MageCard) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((MageCard) obj).getOriginal(), "alt-double-click");
cardEventSource.fireEvent(((MageCard) obj).getOriginal(), ClientEventType.ALT_DOUBLE_CLICK);
} else {
cardEventSource.doubleClick(((MageCard) obj).getOriginal(), "double-click");
cardEventSource.fireEvent(((MageCard) obj).getOriginal(), ClientEventType.DOUBLE_CLICK);
}
}
}

View file

@ -62,7 +62,6 @@ import java.util.*;
import java.util.List;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CardsList extends javax.swing.JPanel implements MouseListener, ICardGrid {
@ -475,9 +474,9 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
setMinimumSize(new java.awt.Dimension(30, 30));
setPreferredSize((!Beans.isDesignTime())?
(GUISizeHelper.editorCardDimension)
:(new Dimension(600, 600)));
setPreferredSize((!Beans.isDesignTime()) ?
(GUISizeHelper.editorCardDimension)
: (new Dimension(600, 600)));
setRequestFocusEnabled(false);
panelControl.setMaximumSize(new java.awt.Dimension(32767, 23));
@ -522,7 +521,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
chkPiles.setMargin(new java.awt.Insets(3, 2, 2, 2));
chkPiles.addActionListener(evt -> chkPilesActionPerformed(evt));
cbSortBy.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "SortBy" }));
cbSortBy.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"SortBy"}));
cbSortBy.setToolTipText("Sort the cards if card view is active.");
cbSortBy.setMaximumSize(new java.awt.Dimension(120, 20));
cbSortBy.setMinimumSize(new java.awt.Dimension(120, 20));
@ -553,36 +552,36 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
javax.swing.GroupLayout panelControlLayout = new javax.swing.GroupLayout(panelControl);
panelControl.setLayout(panelControlLayout);
panelControlLayout.setHorizontalGroup(
panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelControlLayout.createSequentialGroup()
.addComponent(lblCount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblLandCount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblCreatureCount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkPiles)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.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)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelControlLayout.createSequentialGroup()
.addComponent(lblCount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblLandCount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblCreatureCount)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(chkPiles)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.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)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
panelControlLayout.setVerticalGroup(
panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelControlLayout.createSequentialGroup()
.addGroup(panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblCount)
.addComponent(lblLandCount)
.addComponent(lblCreatureCount)
.addComponent(chkPiles))
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jToggleListView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jToggleCardView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, 0))
panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelControlLayout.createSequentialGroup()
.addGroup(panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(panelControlLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblCount)
.addComponent(lblLandCount)
.addComponent(lblCreatureCount)
.addComponent(chkPiles))
.addComponent(cbSortBy, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jToggleListView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jToggleCardView, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 0, 0))
);
jToggleListView.getAccessibleContext().setAccessibleDescription("Switch between image and table view.");
@ -593,16 +592,16 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panelControl, javax.swing.GroupLayout.PREFERRED_SIZE, 467, Short.MAX_VALUE)
.addComponent(panelCardArea)
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(panelControl, javax.swing.GroupLayout.PREFERRED_SIZE, 467, Short.MAX_VALUE)
.addComponent(panelCardArea)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(panelControl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(2, 2, 2)
.addComponent(panelCardArea, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE))
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(panelControl, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(2, 2, 2)
.addComponent(panelCardArea, javax.swing.GroupLayout.DEFAULT_SIZE, 179, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
@ -660,15 +659,15 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
e.consume();
if (obj instanceof Card) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((Card) obj).getOriginal(), "alt-double-click");
cardEventSource.fireEvent(((Card) obj).getOriginal(), ClientEventType.ALT_DOUBLE_CLICK);
} else {
cardEventSource.doubleClick(((Card) obj).getOriginal(), "double-click");
cardEventSource.fireEvent(((Card) obj).getOriginal(), ClientEventType.DOUBLE_CLICK);
}
} else if (obj instanceof MageCard) {
if (e.isAltDown()) {
cardEventSource.altDoubleClick(((MageCard) obj).getOriginal(), "alt-double-click");
cardEventSource.fireEvent(((MageCard) obj).getOriginal(), ClientEventType.ALT_DOUBLE_CLICK);
} else {
cardEventSource.doubleClick(((MageCard) obj).getOriginal(), "double-click");
cardEventSource.fireEvent(((MageCard) obj).getOriginal(), ClientEventType.DOUBLE_CLICK);
}
}
}
@ -695,7 +694,7 @@ public class CardsList extends javax.swing.JPanel implements MouseListener, ICar
private void checkMenu(MouseEvent Me, SimpleCardView card) {
if (Me.isPopupTrigger()) {
Me.consume();
cardEventSource.showPopupMenuEvent(card, Me.getComponent(), Me.getX(), Me.getY(), "show-popup-menu");
cardEventSource.fireEvent(card, Me.getComponent(), Me.getX(), Me.getY(), ClientEventType.SHOW_POP_UP_MENU);
}
}

View file

@ -34,17 +34,11 @@
package mage.client.cards;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.client.plugins.impl.Plugins;
import mage.client.util.CardViewRarityComparator;
import mage.client.util.ClientEventType;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.client.util.audio.AudioManager;
@ -53,6 +47,12 @@ import mage.view.CardView;
import mage.view.CardsView;
import org.apache.log4j.Logger;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author BetaSteward_at_googlemail.com
@ -186,7 +186,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
if (e.getButton() == MouseEvent.BUTTON1) {
Object obj = e.getSource();
if (obj instanceof MageCard) {
this.cardEventSource.doubleClick(((MageCard)obj).getOriginal(), "pick-a-card");
this.cardEventSource.fireEvent(((MageCard)obj).getOriginal(), ClientEventType.PICK_A_CARD);
this.hidePopup();
AudioManager.playOnDraftSelect();
}
@ -203,7 +203,7 @@ public class DraftGrid extends javax.swing.JPanel implements MouseListener {
if (this.markedCard != null) {
markedCard.setSelected(false);
}
this.cardEventSource.doubleClick(((MageCard)obj).getOriginal(), "mark-a-card");
this.cardEventSource.fireEvent(((MageCard)obj).getOriginal(), ClientEventType.MARK_A_CARD);
markedCard = ((MageCard)obj);
markedCard.setSelected(true);
repaint();

View file

@ -70,7 +70,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
if (card.isSelected()) {
stack.set(i, null);
removeCardView(card);
eventSource.removeSpecificCard(card, "remove-specific-card");
eventSource.fireEvent(card, ClientEventType.REMOVE_SPECIFIC_CARD);
}
}
}
@ -326,7 +326,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
for (CardView card : cards) {
card.setSelected(true);
addCardView(card, false);
eventSource.addSpecificCard(card, "add-specific-card");
eventSource.fireEvent(card, ClientEventType.ADD_SPECIFIC_CARD);
}
layoutGrid();
cardContent.repaint();
@ -381,7 +381,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
for (int i = 0; i < stack.size(); ++i) {
CardView card = stack.get(i);
if (card.isSelected()) {
eventSource.removeSpecificCard(card, "remove-specific-card");
eventSource.fireEvent(card, ClientEventType.REMOVE_SPECIFIC_CARD);
stack.set(i, null);
removeCardView(card);
}
@ -1497,7 +1497,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
if (acard.getName().equals(card.getName())) {
CardView pimpedCard = new CardView(acard);
addCardView(pimpedCard, false);
eventSource.addSpecificCard(pimpedCard, "add-specific-card");
eventSource.fireEvent(pimpedCard, ClientEventType.ADD_SPECIFIC_CARD);
pimpedCards.put(pimpedCard, 1);
didModify = true;
}
@ -1748,9 +1748,9 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
if (e.getClickCount() == 1) {
cardClicked(card, e);
} else if (e.isAltDown()) {
eventSource.altDoubleClick(card, "alt-double-click");
eventSource.fireEvent(card, ClientEventType.ALT_DOUBLE_CLICK);
} else {
eventSource.doubleClick(card, "double-click");
eventSource.fireEvent(card, ClientEventType.DOUBLE_CLICK);
}
}
}
@ -1776,7 +1776,7 @@ public class DragCardGrid extends JPanel implements DragCardSource, DragCardTarg
if (duplicated) {
sortIntoGrid(card);
eventSource.addSpecificCard(card, "add-specific-card");
eventSource.fireEvent(card, ClientEventType.ADD_SPECIFIC_CARD);
// Update layout
layoutGrid();
// Update draw