draft stuff

This commit is contained in:
BetaSteward 2011-01-08 23:54:32 -05:00
parent 2e13136101
commit 03e3be90d6
34 changed files with 1238 additions and 743 deletions

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,29 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
<AuxValue name="designerSize" type="java.awt.Dimension" value="-84,-19,0,5,115,114,0,18,106,97,118,97,46,97,119,116,46,68,105,109,101,110,115,105,111,110,65,-114,-39,-41,-84,95,68,20,2,0,2,73,0,6,104,101,105,103,104,116,73,0,5,119,105,100,116,104,120,112,0,0,1,44,0,0,1,-112"/>
</AuxValues>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="400" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="300" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Form>

View file

@ -0,0 +1,126 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/*
* DraftGrid.java
*
* Created on 7-Jan-2011, 6:23:39 PM
*/
package mage.client.cards;
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.UUID;
import mage.cards.MageCard;
import mage.client.MageFrame;
import mage.client.plugins.impl.Plugins;
import mage.client.util.Config;
import mage.view.CardView;
import mage.view.CardsView;
import mage.client.util.Event;
import mage.client.util.Listener;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DraftGrid extends javax.swing.JPanel implements MouseListener {
protected CardEventSource cardEventSource = new CardEventSource();
protected BigCard bigCard;
/** Creates new form DraftGrid */
public DraftGrid() {
initComponents();
}
public void loadBooster(CardsView booster, BigCard bigCard) {
this.bigCard = bigCard;
this.removeAll();
int numColumns = 5;
int curColumn = 0;
int curRow = 0;
Rectangle rectangle = new Rectangle(Config.dimensions.frameWidth, Config.dimensions.frameHeight);
for (CardView card: booster.values()) {
MageCard cardImg = Plugins.getInstance().getMageCard(card, bigCard, Config.dimensions, null);
cardImg.addMouseListener(this);
add(cardImg);
cardImg.update(card);
rectangle.setLocation(curColumn * Config.dimensions.frameWidth, curRow * Config.dimensions.frameHeight);
cardImg.setBounds(rectangle);
cardImg.setCardBounds(rectangle.x, rectangle.y, Config.dimensions.frameWidth, Config.dimensions.frameHeight);
curColumn++;
if (curColumn == numColumns) {
curColumn = 0;
curRow++;
}
}
}
public void addCardEventListener(Listener<Event> listener) {
cardEventSource.addListener(listener);
}
public void clearCardEventListeners() {
cardEventSource.clearListeners();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2 && !e.isConsumed()) {
e.consume();
Object obj = e.getSource();
if (obj instanceof MageCard) {
this.cardEventSource.doubleClick(((MageCard)obj).getOriginal().getId(), "double-click");
}
}
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
}

View file

@ -34,6 +34,7 @@
package mage.client.draft;
import java.util.UUID;
import mage.client.MagePane;
/**
@ -47,6 +48,10 @@ public class DraftPane extends MagePane {
initComponents();
}
public void showDraft(UUID draftId) {
this.draftPanel1.showDraft(draftId);
}
/** 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

@ -1,6 +1,10 @@
<?xml version="1.1" encoding="UTF-8" ?>
<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
<NonVisualComponents>
<Component class="javax.swing.JSeparator" name="jSeparator1">
</Component>
</NonVisualComponents>
<AuxValues>
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/>
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
@ -18,13 +22,22 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="465" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Component id="draftBooster" max="32767" attributes="0"/>
<Component id="draftPicks" alignment="0" pref="570" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
<Component id="draftPicks" pref="123" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="0" max="-2" attributes="0"/>
<Component id="draftBooster" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
@ -47,7 +60,7 @@
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace pref="85" max="32767" attributes="0"/>
<EmptySpace pref="186" max="32767" attributes="0"/>
<Component id="bigCard" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
@ -58,5 +71,38 @@
</Component>
</SubComponents>
</Container>
<Container class="mage.client.cards.DraftGrid" name="draftBooster">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
</Properties>
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="568" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="432" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
</Layout>
</Container>
<Container class="mage.client.cards.CardGrid" name="draftPicks">
<Properties>
<Property name="border" type="javax.swing.border.Border" editor="org.netbeans.modules.form.editors2.BorderEditor">
<Border info="org.netbeans.modules.form.compat2.border.LineBorderInfo">
<LineBorder/>
</Border>
</Property>
</Properties>
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JLayeredPaneSupportLayout"/>
</Container>
</SubComponents>
</Form>

View file

@ -35,8 +35,11 @@
package mage.client.draft;
import java.util.UUID;
import mage.client.cards.BigCard;
import mage.view.CardsView;
import mage.client.MageFrame;
import mage.client.remote.Session;
import mage.client.util.Event;
import mage.client.util.Listener;
import mage.view.DraftPickView;
/**
*
@ -44,14 +47,41 @@ import mage.view.CardsView;
*/
public class DraftPanel extends javax.swing.JPanel {
private UUID draftId;
private Session session;
/** Creates new form DraftPanel */
public DraftPanel() {
initComponents();
}
public void loadBooster(CardsView cards, UUID draftId) {
public synchronized void showDraft(UUID draftId) {
this.draftId = draftId;
session = MageFrame.getSession();
session.setDraft(this);
if (!session.joinDraft(draftId))
hideDraft();
}
public void loadBooster(DraftPickView draftPickView) {
draftBooster.loadBooster(draftPickView.getBooster(), bigCard);
draftPicks.loadCards(draftPickView.getPicks(), bigCard, null);
this.draftBooster.clearCardEventListeners();
this.draftBooster.addCardEventListener(
new Listener<Event> () {
@Override
public void event(Event event) {
if (event.getEventName().equals("double-click")) {
session.sendCardPick(draftId, (UUID)event.getSource());
}
}
}
);
}
public void hideDraft() {
this.setVisible(false);
}
/** This method is called from within the constructor to
@ -63,8 +93,11 @@ public class DraftPanel extends javax.swing.JPanel {
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jSeparator1 = new javax.swing.JSeparator();
jPanel1 = new javax.swing.JPanel();
bigCard = new mage.client.cards.BigCard();
draftBooster = new mage.client.cards.DraftGrid();
draftPicks = new mage.client.cards.CardGrid();
jPanel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
@ -77,28 +110,53 @@ public class DraftPanel extends javax.swing.JPanel {
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(85, Short.MAX_VALUE)
.addContainerGap(186, Short.MAX_VALUE)
.addComponent(bigCard, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
draftBooster.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
javax.swing.GroupLayout draftBoosterLayout = new javax.swing.GroupLayout(draftBooster);
draftBooster.setLayout(draftBoosterLayout);
draftBoosterLayout.setHorizontalGroup(
draftBoosterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 568, Short.MAX_VALUE)
);
draftBoosterLayout.setVerticalGroup(
draftBoosterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 432, Short.MAX_VALUE)
);
draftPicks.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(465, Short.MAX_VALUE))
.addGap(0, 0, 0)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(draftBooster, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(draftPicks, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 570, Short.MAX_VALUE)))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(draftPicks, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
.addGap(0, 0, 0)
.addComponent(draftBooster, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private mage.client.cards.BigCard bigCard;
private mage.client.cards.DraftGrid draftBooster;
private mage.client.cards.CardGrid draftPicks;
private javax.swing.JPanel jPanel1;
private javax.swing.JSeparator jSeparator1;
// End of variables declaration//GEN-END:variables
}

View file

@ -83,7 +83,7 @@ public class Client implements CallbackClient {
}
else if(callback.getMethod().equals("startDraft")) {
TableClientMessage message = (TableClientMessage) callback.getData();
//TODO: add code to start draft
draftStarted(message.getGameId(), message.getPlayerId());
}
else if (callback.getMethod().equals("replayGame")) {
replayGame();
@ -166,9 +166,13 @@ public class Client implements CallbackClient {
TableClientMessage message = (TableClientMessage) callback.getData();
sideboard(message.getDeck(), message.getTableId());
}
else if (callback.getMethod().equals("construct")) {
TableClientMessage message = (TableClientMessage) callback.getData();
construct(message.getDeck(), message.getTableId());
}
else if (callback.getMethod().equals("draftPick")) {
DraftClientMessage message = (DraftClientMessage) callback.getData();
session.getDraft().loadBooster(message.getDraftPickView());
}
else if (callback.getMethod().equals("draftInform")) {
if (callback.getMessageId() > messageId) {
@ -179,7 +183,7 @@ public class Client implements CallbackClient {
}
}
else if (callback.getMethod().equals("draftInit")) {
session.ack("draftInit");
}
messageId = callback.getMessageId();
}
@ -206,6 +210,16 @@ public class Client implements CallbackClient {
}
}
protected void draftStarted(UUID draftId, UUID playerId) {
try {
frame.showDraft(draftId);
logger.info("Draft " + draftId + " started for player " + playerId);
}
catch (Exception ex) {
handleException(ex);
}
}
protected void watchGame(UUID gameId) {
try {
frame.watchGame(gameId);
@ -230,6 +244,10 @@ public class Client implements CallbackClient {
frame.showDeckEditor(DeckEditorMode.Sideboard, deck, tableId);
}
protected void construct(Deck deck, UUID tableId) {
frame.showDeckEditor(DeckEditorMode.Limited, deck, tableId);
}
private void handleException(Exception ex) {
logger.log(Level.SEVERE, "Client error\n", ex);
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Unrecoverable client error. Disconnecting", "Error", JOptionPane.ERROR_MESSAGE);

View file

@ -44,6 +44,7 @@ import mage.cards.decks.DeckCardLists;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
import mage.client.components.MageUI;
import mage.client.draft.DraftPanel;
import mage.client.game.GamePanel;
import mage.client.util.Config;
import mage.game.GameException;
@ -73,6 +74,7 @@ public class Session {
private ServerState serverState;
private Map<UUID, ChatPanel> chats = new HashMap<UUID, ChatPanel>();
private GamePanel game;
private DraftPanel draft;
private CallbackClientDaemon callbackDaemon;
private MageUI ui = new MageUI();
@ -170,6 +172,14 @@ public class Session {
game = gamePanel;
}
public DraftPanel getDraft() {
return draft;
}
public void setDraft(DraftPanel draftPanel) {
draft = draftPanel;
}
public UUID getMainRoomId() {
try {
return server.getMainRoomId();
@ -337,7 +347,7 @@ public class Session {
public boolean sendCardPick(UUID draftId, UUID cardId) {
try {
server.sendPlayerUUID(draftId, sessionId, cardId);
server.sendCardPick(draftId, sessionId, cardId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
@ -397,6 +407,18 @@ public class Session {
return false;
}
public boolean joinDraft(UUID draftId) {
try {
server.joinDraft(draftId, sessionId);
return true;
} catch (RemoteException ex) {
handleRemoteException(ex);
} catch (MageException ex) {
handleMageException(ex);
}
return false;
}
public boolean watchGame(UUID gameId) {
try {
server.watchGame(gameId, sessionId);

View file

@ -321,6 +321,7 @@ public class TablesPanel extends javax.swing.JPanel implements Observer {
private void btnNewDraftActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewDraftActionPerformed
DraftOptions options = new DraftOptions("testDraft");
options.setDraftType("8 Player Booster");
options.getPlayerTypes().add("Human");
options.getPlayerTypes().add("Computer - default");
options.getPlayerTypes().add("Computer - default");