added SimpleCardView - will reduce the amount of data passed between client and server

This commit is contained in:
BetaSteward 2011-08-22 13:54:55 -04:00
parent 91124ad813
commit aecdbe0778
20 changed files with 273 additions and 74 deletions

View file

@ -41,7 +41,6 @@ import java.util.Map;
import java.util.UUID;
import java.util.Map.Entry;
import mage.cards.CardDimensions;
import mage.cards.MageCard;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
@ -50,9 +49,11 @@ import mage.view.CardsView;
import mage.view.PermanentView;
import mage.view.StackAbilityView;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import mage.client.util.CardsViewUtil;
import mage.sets.Sets;
import mage.view.SimpleCardView;
import mage.view.SimpleCardsView;
/**
*
@ -113,6 +114,10 @@ public class Cards extends javax.swing.JPanel {
}
}
public boolean loadCards(SimpleCardsView cardsView, BigCard bigCard, UUID gameId) {
return loadCards(CardsViewUtil.convertSimple(cardsView), bigCard, gameId);
}
public boolean loadCards(CardsView cardsView, BigCard bigCard, UUID gameId) {
boolean changed = false;

View file

@ -51,6 +51,8 @@ import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.UUID;
import mage.client.util.CardsViewUtil;
import mage.view.SimpleCardsView;
/**
* @author BetaSteward_at_googlemail.com
@ -67,7 +69,11 @@ public class ShowCardsDialog extends MageDialog implements MouseListener {
this.setModal(false);
}
public void loadCards(String name, CardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId, boolean modal) {
public void loadCards(String name, SimpleCardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId, boolean modal) {
loadCards(name, CardsViewUtil.convertSimple(showCards), bigCard, dimension, gameId, modal);
}
public void loadCards(String name, CardsView showCards, BigCard bigCard, CardDimensions dimension, UUID gameId, boolean modal) {
this.reloaded = true;
this.title = name;
cardArea.removeAll();

View file

@ -42,6 +42,7 @@ import javax.swing.Timer;
import mage.client.MageFrame;
import mage.client.constants.Constants.SortBy;
import mage.client.plugins.impl.Plugins;
import mage.client.util.CardsViewUtil;
import mage.remote.Session;
import mage.client.util.Event;
import mage.client.util.Listener;
@ -101,8 +102,8 @@ public class DraftPanel extends javax.swing.JPanel {
}
public void loadBooster(DraftPickView draftPickView) {
draftBooster.loadBooster(draftPickView.getBooster(), bigCard);
draftPicks.loadCards(draftPickView.getPicks(), bigCard, null);
draftBooster.loadBooster(CardsViewUtil.convertSimple(draftPickView.getBooster()), bigCard);
draftPicks.loadCards(CardsViewUtil.convertSimple(draftPickView.getPicks()), bigCard, null);
this.draftBooster.clearCardEventListeners();
this.draftBooster.addCardEventListener(
new Listener<Event> () {
@ -113,7 +114,7 @@ public class DraftPanel extends javax.swing.JPanel {
if (view != null) {
//draftBooster.loadBooster(view.getBooster(), bigCard);
draftBooster.loadBooster(emptyView, bigCard);
draftPicks.loadCards(view.getPicks(), bigCard, null);
draftPicks.loadCards(CardsViewUtil.convertSimple(view.getPicks()), bigCard, null);
Plugins.getInstance().getActionCallback().hidePopup();
setMessage("Waiting for other players");
}

View file

@ -307,7 +307,7 @@ public class GamePanel extends javax.swing.JPanel {
// Get opponents hand cards if available
if (game.getOpponentHands() != null) {
for (Map.Entry<String, CardsView> hand: game.getOpponentHands().entrySet()) {
for (Map.Entry<String, SimpleCardsView> hand: game.getOpponentHands().entrySet()) {
handCards.put(hand.getKey(), hand.getValue());
}
}
@ -577,7 +577,7 @@ public class GamePanel extends javax.swing.JPanel {
jTabbedPane1 = new JTabbedPane();
hand.setCardDimension(getHandCardDimension());
handCards = new HashMap<String, CardsView>();
handCards = new HashMap<String, SimpleCardsView>();
jSplitPane1.setBorder(null);
jSplitPane1.setDividerSize(7);
@ -882,7 +882,7 @@ public class GamePanel extends javax.swing.JPanel {
if (chosenHandKey != null && chosenHandKey.length() > 0) {
this.chosenHandKey = chosenHandKey;
CardsView cards = handCards.get(chosenHandKey);
SimpleCardsView cards = handCards.get(chosenHandKey);
this.hand.loadCards(cards, bigCard, gameId);
hand.setPreferredSize(new java.awt.Dimension((getHandCardDimension().width + 5) * cards.size() + 5, getHandCardDimension().height + 20)); // for scroll
}
@ -983,8 +983,6 @@ public class GamePanel extends javax.swing.JPanel {
private mage.client.chat.ChatPanel gameChatPanel;
private mage.client.game.FeedbackPanel feedbackPanel;
private mage.client.chat.ChatPanel userChatPanel;
private mage.client.cards.Cards hand;
private Map<String, CardsView> handCards;
private javax.swing.JPanel jPanel3;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JLabel lblActivePlayer;
@ -995,7 +993,6 @@ public class GamePanel extends javax.swing.JPanel {
private javax.swing.JPanel pnlBattlefield;
private javax.swing.JPanel pnlGameInfo;
private javax.swing.JPanel pnlReplay;
private mage.client.cards.Cards stack;
private javax.swing.JLabel txtActivePlayer;
private javax.swing.JLabel txtPhase;
private javax.swing.JLabel txtPriority;
@ -1003,6 +1000,10 @@ public class GamePanel extends javax.swing.JPanel {
private javax.swing.JLabel txtTurn;
// End of variables declaration//GEN-END:variables
private mage.client.cards.Cards hand;
private Map<String, SimpleCardsView> handCards;
private mage.client.cards.Cards stack;
private JTabbedPane jTabbedPane1;
private Border emptyBorder = new EmptyBorder(0,0,0,0);
private Color prevBGColor;

View file

@ -0,0 +1,57 @@
/*
* Copyright 2011 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.client.util;
import mage.sets.Sets;
import mage.view.CardView;
import mage.view.CardsView;
import mage.view.SimpleCardView;
import mage.view.SimpleCardsView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class CardsViewUtil {
public static CardsView convertSimple(SimpleCardsView view) {
CardsView cards = new CardsView();
for (SimpleCardView simple: view.values()) {
mage.cards.Card card = Sets.findCard(simple.getExpansionSetCode(), simple.getCardNumber());
if (card != null) {
cards.put(simple.getId(), new CardView(card, simple.getId()));
}
}
return cards;
}
}

View file

@ -34,6 +34,7 @@ import mage.cards.decks.Deck;
import mage.sets.Sets;
import mage.view.CardView;
import mage.view.DeckView;
import mage.view.SimpleCardView;
import org.apache.log4j.Logger;
/**
@ -50,25 +51,25 @@ public class DeckUtil {
public static Deck construct(DeckView view) {
Deck deck = new Deck();
for (CardView cardView : view.getCards().values()) {
for (SimpleCardView cardView : view.getCards().values()) {
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
if (set != null) {
Card card = set.findCard(cardView.getName(), cardView.getCardNumber());
Card card = set.findCard(cardView.getCardNumber());
if (card != null) {
deck.getCards().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: " + cardView.getName() + ", set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
}
for (CardView cardView : view.getSideboard().values()) {
for (SimpleCardView cardView : view.getSideboard().values()) {
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
if (set != null) {
Card card = set.findCard(cardView.getName(), cardView.getCardNumber());
Card card = set.findCard(cardView.getCardNumber());
if (card != null) {
deck.getSideboard().add(card);
} else {
log.fatal("(Deck constructing) Couldn't find card: " + cardView.getName() + ", set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
}
}
}