diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index f141f9908d..100fcf6572 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -1,674 +1,697 @@ -/* -* Copyright 2010 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. -*/ - -/* - * MageFrame.java - * - * Created on 15-Dec-2009, 9:11:37 PM - */ - -package mage.client; - -import mage.cards.Card; -import mage.cards.decks.Deck; -import mage.client.cards.CardsStorage; -import mage.client.components.MageComponents; -import mage.client.components.MageJDesktop; -import mage.client.components.MageRoundPane; -import mage.client.components.arcane.ManaSymbols; -import mage.client.constants.Constants.DeckEditorMode; -import mage.client.deckeditor.collection.viewer.CollectionViewerPane; -import mage.client.dialog.*; -import mage.client.plugins.impl.Plugins; -import mage.client.remote.Session; -import mage.client.util.EDTExceptionHandler; -import mage.client.util.gui.ArrowBuilder; -import mage.components.ImagePanel; -import mage.util.Logging; - -import javax.imageio.ImageIO; -import javax.swing.*; -import javax.swing.JToolBar.Separator; -import java.awt.*; -import java.awt.event.ComponentAdapter; -import java.awt.event.ComponentEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.image.BufferedImage; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.UUID; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.prefs.Preferences; - -/** - * @author BetaSteward_at_googlemail.com - */ -public class MageFrame extends javax.swing.JFrame { - - private final static Logger logger = Logging.getLogger(MageFrame.class.getName()); - - private static Session session; - private ConnectDialog connectDialog; - private static CombatDialog combat; - private static PickNumberDialog pickNumber; - private static Preferences prefs = Preferences.userNodeForPackage(MageFrame.class); - private JLabel title; - private Rectangle titleRectangle; - - /** - * @return the session - */ - public static Session getSession() { - return session; - } - - public static JDesktopPane getDesktop() { - return desktopPane; - } - - public static Preferences getPreferences() { - return prefs; - } - - /** - * Creates new form MageFrame - */ - public MageFrame() { - - setTitle("Mage, version 0.5.1"); - - EDTExceptionHandler.registerExceptionHandler(); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - exitApp(); - } - }); - - try { - UIManager.put("desktop", new Color(0, 0, 0, 0)); - UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); - //MageSynthStyleFactory f = new MageSynthStyleFactory(SynthLookAndFeel.getStyleFactory()); - //SynthLookAndFeel.setStyleFactory(f); - } catch (Exception ex) { - logger.log(Level.SEVERE, null, ex); - } - - Plugins.getInstance().loadPlugins(); - ManaSymbols.loadImages(); - - initComponents(); - setSize(1024, 768); - this.setExtendedState(JFrame.MAXIMIZED_BOTH); - - session = new Session(this); - connectDialog = new ConnectDialog(); - combat = new CombatDialog(); - pickNumber = new PickNumberDialog(); - desktopPane.add(connectDialog, JLayeredPane.POPUP_LAYER); - desktopPane.add(combat, JLayeredPane.POPUP_LAYER); - combat.hideDialog(); - desktopPane.add(pickNumber, JLayeredPane.POPUP_LAYER); - session.getUI().addComponent(MageComponents.DESKTOP_PANE, desktopPane); - - addTooltipContainer(); - setBackground(); - addMageLabel(); - setAppIcon(); - - desktopPane.add(ArrowBuilder.getArrowsPanel(), JLayeredPane.DRAG_LAYER); - - desktopPane.addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - int width = ((JComponent) e.getSource()).getWidth(); - int height = ((JComponent) e.getSource()).getHeight(); - backgroundPane.setSize(width, height); - JPanel arrowsPanel = ArrowBuilder.getArrowsPanelRef(); - if (arrowsPanel != null) arrowsPanel.setSize(width, height); - if (title != null) { - //title.setBorder(BorderFactory.createLineBorder(Color.red)); - title.setBounds((int) (width - titleRectangle.getWidth()) / 2, (int) (height - titleRectangle.getHeight()) / 2, titleRectangle.width, titleRectangle.height); - } - } - }); - - //TODO: move to plugin impl - if (Plugins.getInstance().isCardPluginLoaded()) { - Separator separator = new javax.swing.JToolBar.Separator(); - mageToolbar.add(separator); - - JButton btnDownloadSymbols = new JButton("Symbols"); - btnDownloadSymbols.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnDownloadSymbols.setFocusable(false); - btnDownloadSymbols.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnDownloadSymbols.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnDownloadSymbols.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnSymbolsActionPerformed(evt); - } - }); - mageToolbar.add(btnDownloadSymbols); - - separator = new javax.swing.JToolBar.Separator(); - mageToolbar.add(separator); - - JButton btnDownload = new JButton("Images"); - btnDownload.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnDownload.setFocusable(false); - btnDownload.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnDownload.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnDownload.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnImagesActionPerformed(evt); - } - }); - mageToolbar.add(btnDownload); - } - - if (Plugins.getInstance().isCounterPluginLoaded()) { - int i = Plugins.getInstance().getGamesPlayed(); - JLabel label = new JLabel(" Games played: " + String.valueOf(i)); - desktopPane.add(label, JLayeredPane.DEFAULT_LAYER + 1); - label.setVisible(true); - label.setForeground(Color.white); - label.setBounds(0, 0, 180, 30); - } - - session.getUI().addButton(MageComponents.TABLES_MENU_BUTTON, btnGames); - - SwingUtilities.invokeLater(new Runnable() { - public void run() { - if (autoConnect()) - enableButtons(); - else - disableButtons(); - } - }); - } - - private void addTooltipContainer() { - final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane(); - cardInfoPane.setSize(320, 201); - cardInfoPane.setLocation(40, 40); - cardInfoPane.setBackground(new Color(0, 0, 0, 0)); - - MageRoundPane popupContainer = new MageRoundPane(); - popupContainer.setLayout(null); - - popupContainer.add(cardInfoPane); - popupContainer.setVisible(false); - popupContainer.setBounds(0, 0, 320 + 80, 201 + 80); - - desktopPane.add(popupContainer, JLayeredPane.POPUP_LAYER); - - session.getUI().addComponent(MageComponents.CARD_INFO_PANE, cardInfoPane); - session.getUI().addComponent(MageComponents.POPUP_CONTAINER, popupContainer); - } - - private void setBackground() { - String filename = "/background.jpg"; - try { - if (Plugins.getInstance().isThemePluginLoaded()) { - Map ui = new HashMap(); - backgroundPane = (ImagePanel) Plugins.getInstance().updateTablePanel(ui); - } else { - InputStream is = this.getClass().getResourceAsStream(filename); - BufferedImage background = ImageIO.read(is); - backgroundPane = new ImagePanel(background, ImagePanel.SCALED); - } - backgroundPane.setSize(1024, 768); - desktopPane.add(backgroundPane, JLayeredPane.DEFAULT_LAYER); - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void addMageLabel() { - String filename = "/label-mage.png"; - try { - InputStream is = this.getClass().getResourceAsStream(filename); - - float ratio = 1179.0f / 678.0f; - titleRectangle = new Rectangle(640, (int) (640 / ratio)); - if (is != null) { - BufferedImage image = ImageIO.read(is); - //ImageIcon resized = new ImageIcon(image.getScaledInstance(titleRectangle.width, titleRectangle.height, java.awt.Image.SCALE_SMOOTH)); - title = new JLabel(); - title.setIcon(new ImageIcon(image)); - backgroundPane.setLayout(null); - backgroundPane.add(title); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void setAppIcon() { - String filename = "/icon-mage.png"; - try { - InputStream is = this.getClass().getResourceAsStream(filename); - - if (is != null) { - BufferedImage image = ImageIO.read(is); - setIconImage(image); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - - private void btnImagesActionPerformed(java.awt.event.ActionEvent evt) { - Plugins.getInstance().downloadImage(new HashSet(CardsStorage.getAllCards())); - } - - private void btnSymbolsActionPerformed(java.awt.event.ActionEvent evt) { - if (JOptionPane.showConfirmDialog(null, "Do you want to download mana symbols?") == JOptionPane.OK_OPTION) { - Plugins.getInstance().downloadSymbols(); - } - } - - public void showGame(UUID gameId, UUID playerId) { - this.tablesPane.hideTables(); - this.tablesPane.setVisible(false); - this.gamePane.setVisible(true); - this.gamePane.showGame(gameId, playerId); - } - - public void watchGame(UUID gameId) { - this.tablesPane.hideTables(); - this.tablesPane.setVisible(false); - this.gamePane.setVisible(true); - this.gamePane.watchGame(gameId); - } - - public void replayGame() { - this.tablesPane.hideTables(); - this.tablesPane.setVisible(false); - this.gamePane.setVisible(true); - this.gamePane.replayGame(); - } - - public static boolean connect(String userName, String serverName, int port) { - return session.connect(userName, serverName, port); - } - - public boolean autoConnect() { - boolean autoConnect = Boolean.parseBoolean(prefs.get("autoConnect", "false")); - if (autoConnect) { - String userName = prefs.get("userName", ""); - String server = prefs.get("serverAddress", ""); - int port = Integer.parseInt(prefs.get("serverPort", "")); - try { - setCursor(new Cursor(Cursor.WAIT_CURSOR)); - if (MageFrame.connect(userName, server, port)) { - return true; - } else { - JOptionPane.showMessageDialog(rootPane, "Unable to connect to server"); - } - } finally { - setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - } - } - return false; - } - - /** - * 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") - // //GEN-BEGIN:initComponents - private void initComponents() { - - desktopPane = new MageJDesktop(); - tablesPane = new mage.client.table.TablesPane(); - gamePane = new mage.client.game.GamePane(); - deckEditorPane = new mage.client.deckeditor.DeckEditorPane(); - collectionViewerPane = new CollectionViewerPane(); - mageToolbar = new javax.swing.JToolBar(); - btnConnect = new javax.swing.JButton(); - jSeparator5 = new javax.swing.JToolBar.Separator(); - btnGames = new javax.swing.JButton(); - jSeparator4 = new javax.swing.JToolBar.Separator(); - btnDeckEditor = new javax.swing.JButton(); - jSeparator3 = new javax.swing.JToolBar.Separator(); - btnPreferences = new javax.swing.JButton(); - jSeparator2 = new javax.swing.JToolBar.Separator(); - btnAbout = new javax.swing.JButton(); - jSeparator1 = new javax.swing.JToolBar.Separator(); - btnExit = new javax.swing.JButton(); - lblStatus = new javax.swing.JLabel(); - jSeparator6 = new javax.swing.JToolBar.Separator(); - btnCollectionViewer = new JButton(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - //setMinimumSize(new java.awt.Dimension(1024, 768)); - - tablesPane.setBounds(20, 10, 560, 440); - desktopPane.add(tablesPane, javax.swing.JLayeredPane.DEFAULT_LAYER); - try { - tablesPane.setMaximum(true); - } catch (java.beans.PropertyVetoException e1) { - e1.printStackTrace(); - } - gamePane.setBounds(20, 30, -1, -1); - desktopPane.add(gamePane, javax.swing.JLayeredPane.DEFAULT_LAYER); - try { - gamePane.setMaximum(true); - } catch (java.beans.PropertyVetoException e1) { - e1.printStackTrace(); - } - deckEditorPane.setBounds(140, 50, -1, -1); - desktopPane.add(deckEditorPane, javax.swing.JLayeredPane.DEFAULT_LAYER); - try { - deckEditorPane.setMaximum(true); - } catch (java.beans.PropertyVetoException e1) { - e1.printStackTrace(); - } - collectionViewerPane.setBounds(140, 50, -1, -1); - desktopPane.add(collectionViewerPane, javax.swing.JLayeredPane.DEFAULT_LAYER); - try { - collectionViewerPane.setMaximum(true); - } catch (java.beans.PropertyVetoException e1) { - e1.printStackTrace(); - } - - mageToolbar.setFloatable(false); - mageToolbar.setRollover(true); - - btnConnect.setText("Connect"); - btnConnect.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnConnect.setFocusable(false); - btnConnect.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnConnect.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnConnect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnConnectActionPerformed(evt); - } - }); - mageToolbar.add(btnConnect); - mageToolbar.add(jSeparator4); - - btnGames.setText("Tables"); - btnGames.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnGames.setFocusable(false); - btnGames.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnGames.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnGames.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnGamesActionPerformed(evt); - } - }); - mageToolbar.add(btnGames); - mageToolbar.add(jSeparator3); - - btnDeckEditor.setText("Deck Editor"); - btnDeckEditor.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnDeckEditor.setFocusable(false); - btnDeckEditor.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnDeckEditor.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnDeckEditor.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnDeckEditorActionPerformed(evt); - } - }); - mageToolbar.add(btnDeckEditor); - mageToolbar.add(jSeparator2); - - btnCollectionViewer.setText("Collection Viewer"); - btnCollectionViewer.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnCollectionViewer.setFocusable(false); - btnCollectionViewer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnCollectionViewer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnCollectionViewer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnCollectionViewerActionPerformed(evt); - } - }); - mageToolbar.add(btnCollectionViewer); - mageToolbar.add(jSeparator6); - - btnPreferences.setText("Preferences"); - btnPreferences.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnPreferences.setFocusable(false); - btnPreferences.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnPreferences.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnPreferences.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnPreferencesActionPerformed(evt); - } - }); - mageToolbar.add(btnPreferences); - mageToolbar.add(jSeparator5); - - btnAbout.setText("About"); - btnAbout.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnAbout.setFocusable(false); - btnAbout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnAbout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnAbout.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnAboutActionPerformed(evt); - } - }); - mageToolbar.add(btnAbout); - mageToolbar.add(jSeparator1); - - btnExit.setText("Exit"); - btnExit.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); - btnExit.setFocusable(false); - btnExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - btnExit.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - btnExitActionPerformed(evt); - } - }); - mageToolbar.add(btnExit); - - lblStatus.setText("Not connected "); - mageToolbar.add(Box.createHorizontalGlue()); - mageToolbar.add(lblStatus); - - javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); - getContentPane().setLayout(layout); - layout.setHorizontalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1144, Short.MAX_VALUE) - .addComponent(mageToolbar, javax.swing.GroupLayout.DEFAULT_SIZE, 1144, Short.MAX_VALUE) - ); - layout.setVerticalGroup( - layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(layout.createSequentialGroup() - .addComponent(mageToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) - .addGap(0, 0, 0) - .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 880, Short.MAX_VALUE)) - ); - - pack(); - }// //GEN-END:initComponents - - private void btnDeckEditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeckEditorActionPerformed - this.gamePane.setVisible(false); - this.tablesPane.setVisible(false); - this.collectionViewerPane.setVisible(false); - showDeckEditor(DeckEditorMode.Constructed, null, null); - }//GEN-LAST:event_btnDeckEditorActionPerformed - - private void btnCollectionViewerActionPerformed(java.awt.event.ActionEvent evt) { - this.gamePane.setVisible(false); - this.tablesPane.setVisible(false); - this.deckEditorPane.setVisible(false); - showCollectionViewer(); - } - - private void btnPreferencesActionPerformed(java.awt.event.ActionEvent evt) { - PhasesDialog.main(new String[]{}); - } - - private void btnGamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGamesActionPerformed - this.gamePane.setVisible(false); - this.deckEditorPane.setVisible(false); - this.collectionViewerPane.setVisible(false); - this.tablesPane.setVisible(true); - this.tablesPane.showTables(); - }//GEN-LAST:event_btnGamesActionPerformed - - private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed - exitApp(); - }//GEN-LAST:event_btnExitActionPerformed - - private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed - if (session.isConnected()) { - if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { - session.disconnect(); - } - } else { - connectDialog.showDialog(); - } - }//GEN-LAST:event_btnConnectActionPerformed - - private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed - AboutDialog aboutDialog = new AboutDialog(); - desktopPane.add(aboutDialog); - aboutDialog.showDialog(); - }//GEN-LAST:event_btnAboutActionPerformed - - public void exitApp() { - session.disconnect(); - Plugins.getInstance().shutdown(); - dispose(); - System.exit(0); - } - - public void enableButtons() { - btnConnect.setEnabled(true); - btnConnect.setText("Disconnect"); - btnGames.setEnabled(true); - btnDeckEditor.setEnabled(true); - } - - public void disableButtons() { - btnConnect.setEnabled(true); - btnConnect.setText("Connect"); - btnGames.setEnabled(false); - btnDeckEditor.setEnabled(true); - this.tablesPane.setVisible(false); - this.gamePane.setVisible(false); - this.deckEditorPane.setVisible(false); - this.collectionViewerPane.setVisible(false); - } - - public void showDeckEditor(DeckEditorMode mode, Deck deck, UUID tableId) { - this.deckEditorPane.setVisible(true); - this.deckEditorPane.show(mode, deck, tableId); - } - - public void showCollectionViewer() { - this.collectionViewerPane.setVisible(true); - } - - public static CombatDialog getCombatDialog() { - return combat; - } - - public static PickNumberDialog getPickNumberDialog() { - return pickNumber; - } - - static void renderSplashFrame(Graphics2D g) { - g.setComposite(AlphaComposite.Clear); - g.fillRect(120, 140, 200, 40); - g.setPaintMode(); - g.setColor(Color.white); - g.drawString("Version 0.5.1", 560, 460); - } - - /** - * @param args the command line arguments - */ - public static void main(String args[]) { - final SplashScreen splash = SplashScreen.getSplashScreen(); - if (splash != null) { - Graphics2D g = splash.createGraphics(); - if (g != null) { - renderSplashFrame(g); - } - splash.update(); - } - - Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { - public void uncaughtException(Thread t, Throwable e) { - logger.log(Level.SEVERE, null, e); - } - }); - SwingUtilities.invokeLater(new Runnable() { - public void run() { - new MageFrame().setVisible(true); - } - }); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JButton btnAbout; - private javax.swing.JButton btnConnect; - private javax.swing.JButton btnDeckEditor; - private javax.swing.JButton btnCollectionViewer; - private javax.swing.JButton btnPreferences; - private javax.swing.JButton btnExit; - private javax.swing.JButton btnGames; - private mage.client.deckeditor.DeckEditorPane deckEditorPane; - private CollectionViewerPane collectionViewerPane; - private static MageJDesktop desktopPane; - private mage.client.game.GamePane gamePane; - private javax.swing.JToolBar.Separator jSeparator1; - private javax.swing.JToolBar.Separator jSeparator2; - private javax.swing.JToolBar.Separator jSeparator3; - private javax.swing.JToolBar.Separator jSeparator4; - private javax.swing.JToolBar.Separator jSeparator5; - private javax.swing.JToolBar.Separator jSeparator6; - private javax.swing.JLabel lblStatus; - private javax.swing.JToolBar mageToolbar; - private mage.client.table.TablesPane tablesPane; - // End of variables declaration//GEN-END:variables - - private static final long serialVersionUID = -9104885239063142218L; - private ImagePanel backgroundPane; - - public void setStatusText(String status) { - this.lblStatus.setText(status); - } -} +/* +* Copyright 2010 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. +*/ + +/* + * MageFrame.java + * + * Created on 15-Dec-2009, 9:11:37 PM + */ + +package mage.client; + +import mage.cards.Card; +import mage.cards.decks.Deck; +import mage.client.cards.CardsStorage; +import mage.client.components.MageComponents; +import mage.client.components.MageJDesktop; +import mage.client.components.MageRoundPane; +import mage.client.components.arcane.ManaSymbols; +import mage.client.constants.Constants.DeckEditorMode; +import mage.client.deckeditor.collection.viewer.CollectionViewerPane; +import mage.client.dialog.*; +import mage.client.plugins.impl.Plugins; +import mage.client.remote.Session; +import mage.client.util.EDTExceptionHandler; +import mage.client.util.gui.ArrowBuilder; +import mage.components.ImagePanel; +import mage.util.Logging; + +import javax.imageio.ImageIO; +import javax.swing.*; +import javax.swing.JToolBar.Separator; +import java.awt.*; +import java.awt.event.ComponentAdapter; +import java.awt.event.ComponentEvent; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.prefs.Preferences; +import mage.client.draft.DraftPane; + +/** + * @author BetaSteward_at_googlemail.com + */ +public class MageFrame extends javax.swing.JFrame { + + private final static Logger logger = Logging.getLogger(MageFrame.class.getName()); + + private static Session session; + private ConnectDialog connectDialog; + private static CombatDialog combat; + private static PickNumberDialog pickNumber; + private static Preferences prefs = Preferences.userNodeForPackage(MageFrame.class); + private JLabel title; + private Rectangle titleRectangle; + + /** + * @return the session + */ + public static Session getSession() { + return session; + } + + public static JDesktopPane getDesktop() { + return desktopPane; + } + + public static Preferences getPreferences() { + return prefs; + } + + /** + * Creates new form MageFrame + */ + public MageFrame() { + + setTitle("Mage, version 0.5.1"); + + EDTExceptionHandler.registerExceptionHandler(); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + exitApp(); + } + }); + + try { + UIManager.put("desktop", new Color(0, 0, 0, 0)); + UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); + //MageSynthStyleFactory f = new MageSynthStyleFactory(SynthLookAndFeel.getStyleFactory()); + //SynthLookAndFeel.setStyleFactory(f); + } catch (Exception ex) { + logger.log(Level.SEVERE, null, ex); + } + + Plugins.getInstance().loadPlugins(); + ManaSymbols.loadImages(); + + initComponents(); + setSize(1024, 768); + this.setExtendedState(JFrame.MAXIMIZED_BOTH); + + session = new Session(this); + connectDialog = new ConnectDialog(); + combat = new CombatDialog(); + pickNumber = new PickNumberDialog(); + desktopPane.add(connectDialog, JLayeredPane.POPUP_LAYER); + desktopPane.add(combat, JLayeredPane.POPUP_LAYER); + combat.hideDialog(); + desktopPane.add(pickNumber, JLayeredPane.POPUP_LAYER); + session.getUI().addComponent(MageComponents.DESKTOP_PANE, desktopPane); + + draftPane = new DraftPane(); + desktopPane.add(draftPane, javax.swing.JLayeredPane.DEFAULT_LAYER); + try { + draftPane.setMaximum(true); + } catch (java.beans.PropertyVetoException e1) { + e1.printStackTrace(); + } + + addTooltipContainer(); + setBackground(); + addMageLabel(); + setAppIcon(); + + desktopPane.add(ArrowBuilder.getArrowsPanel(), JLayeredPane.DRAG_LAYER); + + desktopPane.addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + int width = ((JComponent) e.getSource()).getWidth(); + int height = ((JComponent) e.getSource()).getHeight(); + backgroundPane.setSize(width, height); + JPanel arrowsPanel = ArrowBuilder.getArrowsPanelRef(); + if (arrowsPanel != null) arrowsPanel.setSize(width, height); + if (title != null) { + //title.setBorder(BorderFactory.createLineBorder(Color.red)); + title.setBounds((int) (width - titleRectangle.getWidth()) / 2, (int) (height - titleRectangle.getHeight()) / 2, titleRectangle.width, titleRectangle.height); + } + } + }); + + //TODO: move to plugin impl + if (Plugins.getInstance().isCardPluginLoaded()) { + Separator separator = new javax.swing.JToolBar.Separator(); + mageToolbar.add(separator); + + JButton btnDownloadSymbols = new JButton("Symbols"); + btnDownloadSymbols.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnDownloadSymbols.setFocusable(false); + btnDownloadSymbols.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnDownloadSymbols.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnDownloadSymbols.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnSymbolsActionPerformed(evt); + } + }); + mageToolbar.add(btnDownloadSymbols); + + separator = new javax.swing.JToolBar.Separator(); + mageToolbar.add(separator); + + JButton btnDownload = new JButton("Images"); + btnDownload.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnDownload.setFocusable(false); + btnDownload.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnDownload.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnDownload.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnImagesActionPerformed(evt); + } + }); + mageToolbar.add(btnDownload); + } + + if (Plugins.getInstance().isCounterPluginLoaded()) { + int i = Plugins.getInstance().getGamesPlayed(); + JLabel label = new JLabel(" Games played: " + String.valueOf(i)); + desktopPane.add(label, JLayeredPane.DEFAULT_LAYER + 1); + label.setVisible(true); + label.setForeground(Color.white); + label.setBounds(0, 0, 180, 30); + } + + session.getUI().addButton(MageComponents.TABLES_MENU_BUTTON, btnGames); + + SwingUtilities.invokeLater(new Runnable() { + public void run() { + if (autoConnect()) + enableButtons(); + else + disableButtons(); + } + }); + } + + private void addTooltipContainer() { + final JEditorPane cardInfoPane = (JEditorPane) Plugins.getInstance().getCardInfoPane(); + cardInfoPane.setSize(320, 201); + cardInfoPane.setLocation(40, 40); + cardInfoPane.setBackground(new Color(0, 0, 0, 0)); + + MageRoundPane popupContainer = new MageRoundPane(); + popupContainer.setLayout(null); + + popupContainer.add(cardInfoPane); + popupContainer.setVisible(false); + popupContainer.setBounds(0, 0, 320 + 80, 201 + 80); + + desktopPane.add(popupContainer, JLayeredPane.POPUP_LAYER); + + session.getUI().addComponent(MageComponents.CARD_INFO_PANE, cardInfoPane); + session.getUI().addComponent(MageComponents.POPUP_CONTAINER, popupContainer); + } + + private void setBackground() { + String filename = "/background.jpg"; + try { + if (Plugins.getInstance().isThemePluginLoaded()) { + Map ui = new HashMap(); + backgroundPane = (ImagePanel) Plugins.getInstance().updateTablePanel(ui); + } else { + InputStream is = this.getClass().getResourceAsStream(filename); + BufferedImage background = ImageIO.read(is); + backgroundPane = new ImagePanel(background, ImagePanel.SCALED); + } + backgroundPane.setSize(1024, 768); + desktopPane.add(backgroundPane, JLayeredPane.DEFAULT_LAYER); + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void addMageLabel() { + String filename = "/label-mage.png"; + try { + InputStream is = this.getClass().getResourceAsStream(filename); + + float ratio = 1179.0f / 678.0f; + titleRectangle = new Rectangle(640, (int) (640 / ratio)); + if (is != null) { + BufferedImage image = ImageIO.read(is); + //ImageIcon resized = new ImageIcon(image.getScaledInstance(titleRectangle.width, titleRectangle.height, java.awt.Image.SCALE_SMOOTH)); + title = new JLabel(); + title.setIcon(new ImageIcon(image)); + backgroundPane.setLayout(null); + backgroundPane.add(title); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void setAppIcon() { + String filename = "/icon-mage.png"; + try { + InputStream is = this.getClass().getResourceAsStream(filename); + + if (is != null) { + BufferedImage image = ImageIO.read(is); + setIconImage(image); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void btnImagesActionPerformed(java.awt.event.ActionEvent evt) { + Plugins.getInstance().downloadImage(new HashSet(CardsStorage.getAllCards())); + } + + private void btnSymbolsActionPerformed(java.awt.event.ActionEvent evt) { + if (JOptionPane.showConfirmDialog(null, "Do you want to download mana symbols?") == JOptionPane.OK_OPTION) { + Plugins.getInstance().downloadSymbols(); + } + } + + public void showGame(UUID gameId, UUID playerId) { + this.tablesPane.hideTables(); + this.tablesPane.setVisible(false); + this.draftPane.setVisible(false); + this.gamePane.setVisible(true); + this.gamePane.showGame(gameId, playerId); + } + + public void watchGame(UUID gameId) { + this.tablesPane.hideTables(); + this.tablesPane.setVisible(false); + this.draftPane.setVisible(false); + this.gamePane.setVisible(true); + this.gamePane.watchGame(gameId); + } + + public void replayGame() { + this.tablesPane.hideTables(); + this.tablesPane.setVisible(false); + this.draftPane.setVisible(false); + this.gamePane.setVisible(true); + this.gamePane.replayGame(); + } + + public void showDraft(UUID draftId) { + this.tablesPane.hideTables(); + this.tablesPane.setVisible(false); + this.gamePane.setVisible(false); + this.draftPane.setVisible(true); + this.draftPane.showDraft(draftId); + } + + public static boolean connect(String userName, String serverName, int port) { + return session.connect(userName, serverName, port); + } + + public boolean autoConnect() { + boolean autoConnect = Boolean.parseBoolean(prefs.get("autoConnect", "false")); + if (autoConnect) { + String userName = prefs.get("userName", ""); + String server = prefs.get("serverAddress", ""); + int port = Integer.parseInt(prefs.get("serverPort", "")); + try { + setCursor(new Cursor(Cursor.WAIT_CURSOR)); + if (MageFrame.connect(userName, server, port)) { + return true; + } else { + JOptionPane.showMessageDialog(rootPane, "Unable to connect to server"); + } + } finally { + setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + } + } + return false; + } + + /** + * 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") + // //GEN-BEGIN:initComponents + private void initComponents() { + + desktopPane = new MageJDesktop(); + tablesPane = new mage.client.table.TablesPane(); + gamePane = new mage.client.game.GamePane(); + deckEditorPane = new mage.client.deckeditor.DeckEditorPane(); + collectionViewerPane = new CollectionViewerPane(); + mageToolbar = new javax.swing.JToolBar(); + btnConnect = new javax.swing.JButton(); + jSeparator5 = new javax.swing.JToolBar.Separator(); + btnGames = new javax.swing.JButton(); + jSeparator4 = new javax.swing.JToolBar.Separator(); + btnDeckEditor = new javax.swing.JButton(); + jSeparator3 = new javax.swing.JToolBar.Separator(); + btnPreferences = new javax.swing.JButton(); + jSeparator2 = new javax.swing.JToolBar.Separator(); + btnAbout = new javax.swing.JButton(); + jSeparator1 = new javax.swing.JToolBar.Separator(); + btnExit = new javax.swing.JButton(); + lblStatus = new javax.swing.JLabel(); + jSeparator6 = new javax.swing.JToolBar.Separator(); + btnCollectionViewer = new JButton(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + //setMinimumSize(new java.awt.Dimension(1024, 768)); + + tablesPane.setBounds(20, 10, 560, 440); + desktopPane.add(tablesPane, javax.swing.JLayeredPane.DEFAULT_LAYER); + try { + tablesPane.setMaximum(true); + } catch (java.beans.PropertyVetoException e1) { + e1.printStackTrace(); + } + gamePane.setBounds(20, 30, -1, -1); + desktopPane.add(gamePane, javax.swing.JLayeredPane.DEFAULT_LAYER); + try { + gamePane.setMaximum(true); + } catch (java.beans.PropertyVetoException e1) { + e1.printStackTrace(); + } + deckEditorPane.setBounds(140, 50, -1, -1); + desktopPane.add(deckEditorPane, javax.swing.JLayeredPane.DEFAULT_LAYER); + try { + deckEditorPane.setMaximum(true); + } catch (java.beans.PropertyVetoException e1) { + e1.printStackTrace(); + } + collectionViewerPane.setBounds(140, 50, -1, -1); + desktopPane.add(collectionViewerPane, javax.swing.JLayeredPane.DEFAULT_LAYER); + try { + collectionViewerPane.setMaximum(true); + } catch (java.beans.PropertyVetoException e1) { + e1.printStackTrace(); + } + + mageToolbar.setFloatable(false); + mageToolbar.setRollover(true); + + btnConnect.setText("Connect"); + btnConnect.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnConnect.setFocusable(false); + btnConnect.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnConnect.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnConnect.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnConnectActionPerformed(evt); + } + }); + mageToolbar.add(btnConnect); + mageToolbar.add(jSeparator4); + + btnGames.setText("Tables"); + btnGames.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnGames.setFocusable(false); + btnGames.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnGames.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnGames.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnGamesActionPerformed(evt); + } + }); + mageToolbar.add(btnGames); + mageToolbar.add(jSeparator3); + + btnDeckEditor.setText("Deck Editor"); + btnDeckEditor.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnDeckEditor.setFocusable(false); + btnDeckEditor.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnDeckEditor.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnDeckEditor.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnDeckEditorActionPerformed(evt); + } + }); + mageToolbar.add(btnDeckEditor); + mageToolbar.add(jSeparator2); + + btnCollectionViewer.setText("Collection Viewer"); + btnCollectionViewer.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnCollectionViewer.setFocusable(false); + btnCollectionViewer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnCollectionViewer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnCollectionViewer.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnCollectionViewerActionPerformed(evt); + } + }); + mageToolbar.add(btnCollectionViewer); + mageToolbar.add(jSeparator6); + + btnPreferences.setText("Preferences"); + btnPreferences.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnPreferences.setFocusable(false); + btnPreferences.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnPreferences.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnPreferences.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnPreferencesActionPerformed(evt); + } + }); + mageToolbar.add(btnPreferences); + mageToolbar.add(jSeparator5); + + btnAbout.setText("About"); + btnAbout.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnAbout.setFocusable(false); + btnAbout.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnAbout.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnAbout.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnAboutActionPerformed(evt); + } + }); + mageToolbar.add(btnAbout); + mageToolbar.add(jSeparator1); + + btnExit.setText("Exit"); + btnExit.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1)); + btnExit.setFocusable(false); + btnExit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); + btnExit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); + btnExit.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + btnExitActionPerformed(evt); + } + }); + mageToolbar.add(btnExit); + + lblStatus.setText("Not connected "); + mageToolbar.add(Box.createHorizontalGlue()); + mageToolbar.add(lblStatus); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 1144, Short.MAX_VALUE) + .addComponent(mageToolbar, javax.swing.GroupLayout.DEFAULT_SIZE, 1144, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addComponent(mageToolbar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 0, 0) + .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 880, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void btnDeckEditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeckEditorActionPerformed + this.gamePane.setVisible(false); + this.tablesPane.setVisible(false); + this.draftPane.setVisible(false); + this.collectionViewerPane.setVisible(false); + showDeckEditor(DeckEditorMode.Constructed, null, null); + }//GEN-LAST:event_btnDeckEditorActionPerformed + + private void btnCollectionViewerActionPerformed(java.awt.event.ActionEvent evt) { + this.gamePane.setVisible(false); + this.tablesPane.setVisible(false); + this.deckEditorPane.setVisible(false); + showCollectionViewer(); + } + + private void btnPreferencesActionPerformed(java.awt.event.ActionEvent evt) { + PhasesDialog.main(new String[]{}); + } + + private void btnGamesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGamesActionPerformed + this.gamePane.setVisible(false); + this.deckEditorPane.setVisible(false); + this.collectionViewerPane.setVisible(false); + this.tablesPane.setVisible(true); + this.tablesPane.showTables(); + }//GEN-LAST:event_btnGamesActionPerformed + + private void btnExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExitActionPerformed + exitApp(); + }//GEN-LAST:event_btnExitActionPerformed + + private void btnConnectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConnectActionPerformed + if (session.isConnected()) { + if (JOptionPane.showConfirmDialog(this, "Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { + session.disconnect(); + } + } else { + connectDialog.showDialog(); + } + }//GEN-LAST:event_btnConnectActionPerformed + + private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed + AboutDialog aboutDialog = new AboutDialog(); + desktopPane.add(aboutDialog); + aboutDialog.showDialog(); + }//GEN-LAST:event_btnAboutActionPerformed + + public void exitApp() { + session.disconnect(); + Plugins.getInstance().shutdown(); + dispose(); + System.exit(0); + } + + public void enableButtons() { + btnConnect.setEnabled(true); + btnConnect.setText("Disconnect"); + btnGames.setEnabled(true); + btnDeckEditor.setEnabled(true); + } + + public void disableButtons() { + btnConnect.setEnabled(true); + btnConnect.setText("Connect"); + btnGames.setEnabled(false); + btnDeckEditor.setEnabled(true); + this.tablesPane.setVisible(false); + this.gamePane.setVisible(false); + this.deckEditorPane.setVisible(false); + this.draftPane.setVisible(false); + this.collectionViewerPane.setVisible(false); + } + + public void showDeckEditor(DeckEditorMode mode, Deck deck, UUID tableId) { + this.deckEditorPane.setVisible(true); + this.deckEditorPane.show(mode, deck, tableId); + } + + public void showCollectionViewer() { + this.collectionViewerPane.setVisible(true); + } + + public static CombatDialog getCombatDialog() { + return combat; + } + + public static PickNumberDialog getPickNumberDialog() { + return pickNumber; + } + + static void renderSplashFrame(Graphics2D g) { + g.setComposite(AlphaComposite.Clear); + g.fillRect(120, 140, 200, 40); + g.setPaintMode(); + g.setColor(Color.white); + g.drawString("Version 0.5.1", 560, 460); + } + + /** + * @param args the command line arguments + */ + public static void main(String args[]) { + final SplashScreen splash = SplashScreen.getSplashScreen(); + if (splash != null) { + Graphics2D g = splash.createGraphics(); + if (g != null) { + renderSplashFrame(g); + } + splash.update(); + } + + Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { + public void uncaughtException(Thread t, Throwable e) { + logger.log(Level.SEVERE, null, e); + } + }); + SwingUtilities.invokeLater(new Runnable() { + public void run() { + new MageFrame().setVisible(true); + } + }); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JButton btnAbout; + private javax.swing.JButton btnConnect; + private javax.swing.JButton btnDeckEditor; + private javax.swing.JButton btnCollectionViewer; + private javax.swing.JButton btnPreferences; + private javax.swing.JButton btnExit; + private javax.swing.JButton btnGames; + private mage.client.deckeditor.DeckEditorPane deckEditorPane; + private CollectionViewerPane collectionViewerPane; + private static MageJDesktop desktopPane; + private mage.client.game.GamePane gamePane; + private javax.swing.JToolBar.Separator jSeparator1; + private javax.swing.JToolBar.Separator jSeparator2; + private javax.swing.JToolBar.Separator jSeparator3; + private javax.swing.JToolBar.Separator jSeparator4; + private javax.swing.JToolBar.Separator jSeparator5; + private javax.swing.JToolBar.Separator jSeparator6; + private javax.swing.JLabel lblStatus; + private javax.swing.JToolBar mageToolbar; + private mage.client.table.TablesPane tablesPane; + // End of variables declaration//GEN-END:variables + + private static final long serialVersionUID = -9104885239063142218L; + private ImagePanel backgroundPane; + private DraftPane draftPane; + + public void setStatusText(String status) { + this.lblStatus.setText(status); + } +} diff --git a/Mage.Client/src/main/java/mage/client/cards/DraftGrid.form b/Mage.Client/src/main/java/mage/client/cards/DraftGrid.form new file mode 100644 index 0000000000..797927e8af --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/cards/DraftGrid.form @@ -0,0 +1,29 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Mage.Client/src/main/java/mage/client/cards/DraftGrid.java b/Mage.Client/src/main/java/mage/client/cards/DraftGrid.java new file mode 100644 index 0000000000..41022d9d3a --- /dev/null +++ b/Mage.Client/src/main/java/mage/client/cards/DraftGrid.java @@ -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 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") + // //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) + ); + }// //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 + +} diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPane.java b/Mage.Client/src/main/java/mage/client/draft/DraftPane.java index 6e99b46672..528d413f7e 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPane.java +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPane.java @@ -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 diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.form b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.form index 2df044075c..f61cee7816 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.form +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.form @@ -1,6 +1,10 @@
+ + + + @@ -18,13 +22,22 @@ - + + + + + + + + + + @@ -47,7 +60,7 @@ - + @@ -58,5 +71,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java index 1d5e92ebce..189b3ba36f 100644 --- a/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java +++ b/Mage.Client/src/main/java/mage/client/draft/DraftPanel.java @@ -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 () { + @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 { // //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)) ); }// //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 } diff --git a/Mage.Client/src/main/java/mage/client/remote/Client.java b/Mage.Client/src/main/java/mage/client/remote/Client.java index 3633b4de0c..88ffa2bf7f 100644 --- a/Mage.Client/src/main/java/mage/client/remote/Client.java +++ b/Mage.Client/src/main/java/mage/client/remote/Client.java @@ -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); diff --git a/Mage.Client/src/main/java/mage/client/remote/Session.java b/Mage.Client/src/main/java/mage/client/remote/Session.java index 3c1e3a207f..641a16dbfb 100644 --- a/Mage.Client/src/main/java/mage/client/remote/Session.java +++ b/Mage.Client/src/main/java/mage/client/remote/Session.java @@ -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 chats = new HashMap(); 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); diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index 79315c6c7f..9516d6089a 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -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"); diff --git a/Mage.Common/src/mage/view/DraftClientMessage.java b/Mage.Common/src/mage/view/DraftClientMessage.java index f868c3fd41..5e4c6feb32 100644 --- a/Mage.Common/src/mage/view/DraftClientMessage.java +++ b/Mage.Common/src/mage/view/DraftClientMessage.java @@ -53,4 +53,11 @@ public class DraftClientMessage implements Serializable { this.draftView = draftView; } + public DraftPickView getDraftPickView() { + return draftPickView; + } + + public DraftView getDraftView() { + return draftView; + } } diff --git a/Mage.Common/src/mage/view/DraftPickView.java b/Mage.Common/src/mage/view/DraftPickView.java index f1c98330b0..5020154ddd 100644 --- a/Mage.Common/src/mage/view/DraftPickView.java +++ b/Mage.Common/src/mage/view/DraftPickView.java @@ -28,17 +28,21 @@ package mage.view; +import java.io.Serializable; +import mage.game.draft.DraftPlayer; + /** * * @author BetaSteward_at_googlemail.com */ -public class DraftPickView { +public class DraftPickView implements Serializable { protected CardsView booster; protected CardsView picks; - public DraftPickView() { - + public DraftPickView(DraftPlayer player) { + this.booster = new CardsView(player.getBooster()); + this.picks = new CardsView(player.getDeck().getSideboard()); } public CardsView getBooster() { diff --git a/Mage.Common/src/mage/view/DraftView.java b/Mage.Common/src/mage/view/DraftView.java index ebb0dc13fa..4d5ee79ea5 100644 --- a/Mage.Common/src/mage/view/DraftView.java +++ b/Mage.Common/src/mage/view/DraftView.java @@ -28,6 +28,7 @@ package mage.view; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import mage.game.draft.Draft; @@ -36,7 +37,7 @@ import mage.game.draft.Draft; * * @author BetaSteward_at_googlemail.com */ -public class DraftView { +public class DraftView implements Serializable { private List players = new ArrayList(); diff --git a/Mage.Common/src/mage/view/RoundView.java b/Mage.Common/src/mage/view/RoundView.java index 1c60ee211b..20d35e3eb1 100644 --- a/Mage.Common/src/mage/view/RoundView.java +++ b/Mage.Common/src/mage/view/RoundView.java @@ -28,13 +28,14 @@ package mage.view; +import java.io.Serializable; import mage.game.tournament.Round; /** * * @author BetaSteward_at_googlemail.com */ -public class RoundView { +public class RoundView implements Serializable { public RoundView(Round round) { diff --git a/Mage.Common/src/mage/view/TournamentPlayerView.java b/Mage.Common/src/mage/view/TournamentPlayerView.java index 084dff7b9a..2e8fdb0915 100644 --- a/Mage.Common/src/mage/view/TournamentPlayerView.java +++ b/Mage.Common/src/mage/view/TournamentPlayerView.java @@ -28,10 +28,12 @@ package mage.view; +import java.io.Serializable; + /** * * @author BetaSteward_at_googlemail.com */ -public class TournamentPlayerView { +public class TournamentPlayerView implements Serializable { } diff --git a/Mage.Common/src/mage/view/TournamentView.java b/Mage.Common/src/mage/view/TournamentView.java index 2a44b1f42d..a783896593 100644 --- a/Mage.Common/src/mage/view/TournamentView.java +++ b/Mage.Common/src/mage/view/TournamentView.java @@ -28,6 +28,7 @@ package mage.view; +import java.io.Serializable; import java.util.ArrayList; import java.util.List; import mage.game.tournament.Tournament; @@ -36,7 +37,7 @@ import mage.game.tournament.Tournament; * * @author BetaSteward_at_googlemail.com */ -public class TournamentView { +public class TournamentView implements Serializable { List rounds = new ArrayList(); diff --git a/Mage.Server.Plugins/Mage.Draft.8PlayerBooster/pom.xml b/Mage.Server.Plugins/Mage.Draft.8PlayerBooster/pom.xml new file mode 100644 index 0000000000..14d00806cc --- /dev/null +++ b/Mage.Server.Plugins/Mage.Draft.8PlayerBooster/pom.xml @@ -0,0 +1,49 @@ + + + 4.0.0 + + + org.mage + mage-root + 0.5.1 + + + Mage-Draft-8PlayerBooster + jar + Mage Draft 8 Player Booster + + + + ${project.groupId} + Mage + ${project.version} + + + + + src + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + maven-resources-plugin + + UTF-8 + + + + + + mage-draft-8playerbooster + + + + diff --git a/Mage.Server.Plugins/Mage.Draft.8PlayerBooster/src/mage/draft/BoosterDraft.java b/Mage.Server.Plugins/Mage.Draft.8PlayerBooster/src/mage/draft/BoosterDraft.java new file mode 100644 index 0000000000..f88ca485db --- /dev/null +++ b/Mage.Server.Plugins/Mage.Draft.8PlayerBooster/src/mage/draft/BoosterDraft.java @@ -0,0 +1,59 @@ +/* + * 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.draft; + +import mage.game.draft.DraftImpl; +import mage.game.draft.DraftOptions; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class BoosterDraft extends DraftImpl { + + public BoosterDraft(DraftOptions options) { + super(options); + } + + @Override + public void start() { + while (boosterNum < sets.size()) { + openBooster(); + while (pickCards()) { + if (boosterNum % 2 == 1) + passLeft(); + else + passRight(); + fireUpdatePlayersEvent(); + } + } + startTournament(); + } + +} diff --git a/Mage.Server.Plugins/pom.xml b/Mage.Server.Plugins/pom.xml index cdf3442c05..7b390eaef2 100644 --- a/Mage.Server.Plugins/pom.xml +++ b/Mage.Server.Plugins/pom.xml @@ -1,6 +1,5 @@ - + 4.0.0 @@ -23,6 +22,7 @@ Mage.Player.AI Mage.Player.AIMinimax Mage.Player.Human - + Mage.Draft.8PlayerBooster + - + \ No newline at end of file diff --git a/Mage.Server/config/config.xml b/Mage.Server/config/config.xml index df6998b9b9..6afc3b6d8a 100644 --- a/Mage.Server/config/config.xml +++ b/Mage.Server/config/config.xml @@ -12,6 +12,9 @@ + + + diff --git a/Mage.Server/plugins/mage-draft-8playerbooster.jar b/Mage.Server/plugins/mage-draft-8playerbooster.jar new file mode 100644 index 0000000000..861bd06e77 Binary files /dev/null and b/Mage.Server/plugins/mage-draft-8playerbooster.jar differ diff --git a/Mage.Server/plugins/mage-player-ai.jar b/Mage.Server/plugins/mage-player-ai.jar index f3f37a9fbc..679b14deeb 100644 Binary files a/Mage.Server/plugins/mage-player-ai.jar and b/Mage.Server/plugins/mage-player-ai.jar differ diff --git a/Mage.Server/plugins/mage-player-human.jar b/Mage.Server/plugins/mage-player-human.jar index 6050acc5de..53e260222e 100644 Binary files a/Mage.Server/plugins/mage-player-human.jar and b/Mage.Server/plugins/mage-player-human.jar differ diff --git a/Mage.Server/src/main/java/mage/server/Main.java b/Mage.Server/src/main/java/mage/server/Main.java index 9cec754fa9..f1cf016905 100644 --- a/Mage.Server/src/main/java/mage/server/Main.java +++ b/Mage.Server/src/main/java/mage/server/Main.java @@ -37,6 +37,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import mage.game.match.MatchType; import mage.server.game.DeckValidatorFactory; +import mage.server.game.DraftFactory; import mage.server.game.GameFactory; import mage.server.game.PlayerFactory; import mage.server.util.ConfigSettings; @@ -72,6 +73,9 @@ public class Main { for (GamePlugin plugin: config.getGameTypes()) { GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin)); } + for (Plugin plugin: config.getDraftTypes()) { + DraftFactory.getInstance().addDraftType(plugin.getName(), loadPlugin(plugin)); + } for (Plugin plugin: config.getPlayerTypes()) { PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin)); } diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index 5dec0724d0..c020dc3ca5 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -103,6 +103,10 @@ public class Session { fireCallback(new ClientCallback("sideboard", new TableClientMessage(deck, tableId))); } + public void construct(final Deck deck, final UUID tableId) { + fireCallback(new ClientCallback("construct", new TableClientMessage(deck, tableId))); + } + public void watchGame(final UUID gameId) { fireCallback(new ClientCallback("watchGame", gameId)); } diff --git a/Mage.Server/src/main/java/mage/server/game/DraftController.java b/Mage.Server/src/main/java/mage/server/game/DraftController.java index 9e47bfe8f5..6811a81be4 100644 --- a/Mage.Server/src/main/java/mage/server/game/DraftController.java +++ b/Mage.Server/src/main/java/mage/server/game/DraftController.java @@ -93,7 +93,7 @@ public class DraftController { public void event(PlayerQueryEvent event) { switch (event.getQueryType()) { case PICK_CARD: - pickCard(event.getPlayerId()); + pickCard(event.getPlayerId(), event.getMax()); break; } } @@ -130,6 +130,7 @@ public class DraftController { return; } } + draft.start(); } private boolean allJoined() { @@ -186,9 +187,9 @@ public class DraftController { } } - private synchronized void pickCard(UUID playerId) { + private synchronized void pickCard(UUID playerId, int timeout) { if (draftSessions.containsKey(playerId)) - draftSessions.get(playerId).pickCard(getDraftPickView(playerId)); + draftSessions.get(playerId).pickCard(getDraftPickView(playerId), timeout); } private DraftView getDraftView() { @@ -196,7 +197,7 @@ public class DraftController { } private DraftPickView getDraftPickView(UUID playerId) { - return new DraftPickView(); + return new DraftPickView(draft.getPlayer(playerId)); } } diff --git a/Mage.Server/src/main/java/mage/server/game/DraftSession.java b/Mage.Server/src/main/java/mage/server/game/DraftSession.java index c8fb939eed..385109b5fa 100644 --- a/Mage.Server/src/main/java/mage/server/game/DraftSession.java +++ b/Mage.Server/src/main/java/mage/server/game/DraftSession.java @@ -110,9 +110,9 @@ public class DraftSession { } } - public void pickCard(final DraftPickView draftPickView) { + public void pickCard(final DraftPickView draftPickView, int timeout) { if (!killed) { - setupTimeout(20); + setupTimeout(timeout); Session session = SessionManager.getInstance().getSession(sessionId); if (session != null) session.fireCallback(new ClientCallback("draftPick", new DraftClientMessage(draftPickView))); diff --git a/Mage.Server/src/main/java/mage/server/game/TableController.java b/Mage.Server/src/main/java/mage/server/game/TableController.java index 610e5af271..9cbefa2713 100644 --- a/Mage.Server/src/main/java/mage/server/game/TableController.java +++ b/Mage.Server/src/main/java/mage/server/game/TableController.java @@ -46,6 +46,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; +import mage.Constants.RangeOfInfluence; import mage.Constants.TableState; import mage.cards.decks.Deck; import mage.cards.decks.DeckCardLists; @@ -212,7 +213,13 @@ public class TableController { } private Player createPlayer(String name, String playerType) { - Player player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange()); + Player player; + if (options == null) { + player = PlayerFactory.getInstance().createPlayer(playerType, name, RangeOfInfluence.ALL); + } + else { + player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange()); + } logger.info("Player created " + player.getId()); return player; } @@ -245,7 +252,6 @@ public class TableController { public synchronized void startDraft(UUID sessionId) { if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) { - draft.start(); table.initDraft(); DraftManager.getInstance().createDraftSession(draft, sessionPlayerMap, table.getId()); SessionManager sessionManager = SessionManager.getInstance(); @@ -274,6 +280,16 @@ public class TableController { } } + private void construct(UUID playerId, Deck deck) { + SessionManager sessionManager = SessionManager.getInstance(); + for (Entry entry: sessionPlayerMap.entrySet()) { + if (entry.getValue().equals(playerId)) { + sessionManager.getSession(entry.getKey()).construct(deck, table.getId()); + break; + } + } + } + public void endGame() { UUID choosingPlayerId = match.getChooser(); match.endGame(); diff --git a/Mage.Server/src/main/java/mage/server/util/Config.xsd b/Mage.Server/src/main/java/mage/server/util/Config.xsd index 20c7319dea..ac06d7978d 100644 --- a/Mage.Server/src/main/java/mage/server/util/Config.xsd +++ b/Mage.Server/src/main/java/mage/server/util/Config.xsd @@ -8,11 +8,12 @@ + - + @@ -23,26 +24,40 @@ - - - - - - - + + + + + + + + + + + + + - + - + - + + + + + + + + + @@ -50,7 +65,7 @@ - + diff --git a/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java b/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java index d0aba9c981..06a0cf19f7 100644 --- a/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java +++ b/Mage.Server/src/main/java/mage/server/util/ConfigSettings.java @@ -92,6 +92,10 @@ public class ConfigSettings { return config.getGameTypes().getGameType(); } + public List getDraftTypes() { + return config.getDraftTypes().getDraftType(); + } + public List getDeckTypes() { return config.getDeckTypes().getDeckType(); } diff --git a/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd b/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd index 142e7f1a74..c9a949dd56 100644 --- a/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd +++ b/Mage.Server/src/main/xml-resources/jaxb/Config/Config.xsd @@ -8,6 +8,7 @@ + @@ -53,6 +54,14 @@ + + + + + + + + diff --git a/Mage/src/mage/game/draft/DraftImpl.java b/Mage/src/mage/game/draft/DraftImpl.java index b51584e256..b92a6def9c 100644 --- a/Mage/src/mage/game/draft/DraftImpl.java +++ b/Mage/src/mage/game/draft/DraftImpl.java @@ -50,7 +50,7 @@ import mage.players.PlayerList; * * @author BetaSteward_at_googlemail.com */ -public class DraftImpl> implements Draft { +public abstract class DraftImpl> implements Draft { protected final UUID id; protected Map players = new HashMap(); @@ -74,8 +74,8 @@ public class DraftImpl> implements Draft { @Override public void addPlayer(Player player) { DraftPlayer draftPlayer = new DraftPlayer(player); - players.put(draftPlayer.getId(), draftPlayer); - table.add(draftPlayer.getId()); + players.put(player.getId(), draftPlayer); + table.add(player.getId()); } @Override @@ -139,7 +139,7 @@ public class DraftImpl> implements Draft { } protected void openBooster() { - if (sets.size() < boosterNum) { + if (boosterNum < sets.size()) { for (DraftPlayer player: players.values()) { player.setBooster(sets.get(boosterNum).createBooster()); } @@ -151,8 +151,8 @@ public class DraftImpl> implements Draft { for (DraftPlayer player: players.values()) { if (player.getBooster().size() == 0) return false; - player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this); player.setPicking(); + player.getPlayer().pickCard(player.getBooster(), player.getDeck(), this); } while (!donePicking()) { try { @@ -173,21 +173,6 @@ public class DraftImpl> implements Draft { return true; } - @Override - public void start() { - while (boosterNum < sets.size()) { - openBooster(); - while (pickCards()) { - if (boosterNum % 2 == 1) - passLeft(); - else - passRight(); - fireUpdatePlayersEvent(); - } - } - startTournament(); - } - @Override public void addTableEventListener(Listener listener) { tableEventSource.addListener(listener); @@ -205,7 +190,7 @@ public class DraftImpl> implements Draft { @Override public void firePickCardEvent(UUID playerId) { - playerQueryEventSource.pickCard(playerId, "Pick card", players.get(playerId).booster); + playerQueryEventSource.pickCard(playerId, "Pick card", players.get(playerId).booster, 20); } @Override @@ -214,6 +199,7 @@ public class DraftImpl> implements Draft { for (Card card: player.booster) { if (card.getId().equals(cardId)) { player.addPick(card); + player.booster.remove(card); break; } } diff --git a/Mage/src/mage/game/draft/DraftOptions.java b/Mage/src/mage/game/draft/DraftOptions.java index d973c32c0d..9f62a4043c 100644 --- a/Mage/src/mage/game/draft/DraftOptions.java +++ b/Mage/src/mage/game/draft/DraftOptions.java @@ -41,7 +41,7 @@ public class DraftOptions implements Serializable { protected String name; protected String draftType; - protected List sets; + protected List sets = new ArrayList(); protected List playerTypes = new ArrayList(); protected TimingOption timing; diff --git a/Mage/src/mage/game/events/PlayerQueryEvent.java b/Mage/src/mage/game/events/PlayerQueryEvent.java index 4a7dfa295e..87365361be 100644 --- a/Mage/src/mage/game/events/PlayerQueryEvent.java +++ b/Mage/src/mage/game/events/PlayerQueryEvent.java @@ -76,12 +76,13 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri this.max = max; } - private PlayerQueryEvent(UUID playerId, String message, List booster, QueryType queryType) { + private PlayerQueryEvent(UUID playerId, String message, List booster, QueryType queryType, int time) { super(playerId); this.queryType = queryType; this.message = message; this.playerId = playerId; this.booster = booster; + this.max = time; } public static PlayerQueryEvent askEvent(UUID playerId, String message) { @@ -127,8 +128,8 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri return new PlayerQueryEvent(playerId, message, null, null, null, cards, QueryType.LOOK, 0, 0, false); } - public static PlayerQueryEvent pickCard(UUID playerId, String message, List booster) { - return new PlayerQueryEvent(playerId, message, booster, QueryType.PICK_CARD); + public static PlayerQueryEvent pickCard(UUID playerId, String message, List booster, int time) { + return new PlayerQueryEvent(playerId, message, booster, QueryType.PICK_CARD, time); } public String getMessage() { diff --git a/Mage/src/mage/game/events/PlayerQueryEventSource.java b/Mage/src/mage/game/events/PlayerQueryEventSource.java index 0052211c0b..23f429be67 100644 --- a/Mage/src/mage/game/events/PlayerQueryEventSource.java +++ b/Mage/src/mage/game/events/PlayerQueryEventSource.java @@ -95,8 +95,8 @@ public class PlayerQueryEventSource implements EventSource, Se dispatcher.fireEvent(PlayerQueryEvent.playXManaEvent(playerId, message)); } - public void pickCard(UUID playerId, String message, List booster) { - dispatcher.fireEvent(PlayerQueryEvent.pickCard(playerId, message, booster)); + public void pickCard(UUID playerId, String message, List booster, int time) { + dispatcher.fireEvent(PlayerQueryEvent.pickCard(playerId, message, booster, time)); } }