From 33d29bcdaccd3dc973b65067be14bde369dd7b22 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Tue, 28 Dec 2010 13:32:25 +0300 Subject: [PATCH 1/2] fixed bug in pvp phase stops (now based on uuid, not player's name) --- .../mage/client/dialog/JoinTableDialog.java | 1 - .../main/java/mage/client/remote/Client.java | 2 ++ .../java/mage/client/util/GameManager.java | 14 ++++++++++++ .../java/mage/client/util/PhaseManager.java | 22 +++++++++++++------ 4 files changed, 31 insertions(+), 8 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java index bd6cc42bf6..8b7fe1c5e7 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/JoinTableDialog.java @@ -138,7 +138,6 @@ public class JoinTableDialog extends MageDialog { private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed Session session = MageFrame.getSession(); try { - PhaseManager.getInstance().setName(this.newPlayerPanel.getPlayerName()); joined = session.joinTable(roomId, tableId, this.newPlayerPanel.getPlayerName(), Sets.loadDeck(this.newPlayerPanel.getDeckFile())); } catch (Exception ex) { handleError(ex); 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 23623b818e..d5ee82df5c 100644 --- a/Mage.Client/src/main/java/mage/client/remote/Client.java +++ b/Mage.Client/src/main/java/mage/client/remote/Client.java @@ -36,6 +36,7 @@ import javax.swing.JOptionPane; import mage.client.MageFrame; import mage.client.chat.ChatPanel; import mage.client.plugins.impl.Plugins; +import mage.client.util.GameManager; import mage.interfaces.callback.CallbackClient; import mage.interfaces.callback.ClientCallback; import mage.util.Logging; @@ -73,6 +74,7 @@ public class Client implements CallbackClient { try { if (callback.getMethod().equals("startGame")) { UUID[] data = (UUID[]) callback.getData(); + GameManager.getInstance().setCurrentPlayerUUID(data[1]); gameStarted(data[0], data[1]); } else if (callback.getMethod().equals("replayGame")) { diff --git a/Mage.Client/src/main/java/mage/client/util/GameManager.java b/Mage.Client/src/main/java/mage/client/util/GameManager.java index c7950a07fc..047bb4acdc 100644 --- a/Mage.Client/src/main/java/mage/client/util/GameManager.java +++ b/Mage.Client/src/main/java/mage/client/util/GameManager.java @@ -1,5 +1,7 @@ package mage.client.util; +import java.util.UUID; + /** * Controls game state on client side. * @@ -7,15 +9,27 @@ package mage.client.util; */ public class GameManager { private static GameManager fInstance = new GameManager(); + public static GameManager getInstance() { return fInstance; } + public void setStackSize(int stackSize) { this.stackSize = stackSize; } + public int getStackSize() { return stackSize; } + public UUID getCurrentPlayerUUID() { + return currentPlayerUUID; + } + + public void setCurrentPlayerUUID(UUID currentPlayerUUID) { + this.currentPlayerUUID = currentPlayerUUID; + } + private int stackSize; + private UUID currentPlayerUUID; } diff --git a/Mage.Client/src/main/java/mage/client/util/PhaseManager.java b/Mage.Client/src/main/java/mage/client/util/PhaseManager.java index 15e357d3fc..7fee7768b3 100644 --- a/Mage.Client/src/main/java/mage/client/util/PhaseManager.java +++ b/Mage.Client/src/main/java/mage/client/util/PhaseManager.java @@ -2,9 +2,11 @@ package mage.client.util; import mage.client.MageFrame; import mage.view.GameView; +import mage.view.PlayerView; import java.util.HashMap; import java.util.Map; +import java.util.UUID; import java.util.prefs.Preferences; public class PhaseManager { @@ -51,21 +53,27 @@ public class PhaseManager { put("End Turn - play instants and activated abilities.", END_OF_TURN_OTHERS); }}; - private String yourName; - public static PhaseManager getInstance() { return fInstance; } - public void setName(String yourName) { - this.yourName = yourName; - } - public boolean isSkip(GameView gameView, String message) { if (GameManager.getInstance().getStackSize() > 0) { return false; } - Map map = gameView.getActivePlayerName().equals(DEFAULT_PLAYER_NAME) ? mapYou : mapOthers; + UUID activePlayer = null; + Map map = mapOthers; + for (PlayerView playerView : gameView.getPlayers()) { + if (playerView.isActive()) { + activePlayer = playerView.getPlayerId(); + if (activePlayer.equals(GameManager.getInstance().getCurrentPlayerUUID())) { + map = mapYou; + } + } + } + if (activePlayer == null) { + throw new IllegalStateException("No active player found."); + } for (Map.Entry entry : map.entrySet()) { if (message.equals(entry.getKey())) { Preferences prefs = MageFrame.getPreferences(); From 10f365254d9249757ca28ef1067e9561285018a8 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Tue, 28 Dec 2010 15:40:28 +0300 Subject: [PATCH 2/2] MageFrame code cleanup. --- .../src/main/java/mage/client/MageFrame.java | 139 ++++++++++-------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/MageFrame.java b/Mage.Client/src/main/java/mage/client/MageFrame.java index 966e16792a..a832d825ea 100644 --- a/Mage.Client/src/main/java/mage/client/MageFrame.java +++ b/Mage.Client/src/main/java/mage/client/MageFrame.java @@ -138,71 +138,13 @@ public class MageFrame extends javax.swing.JFrame { desktopPane.add(pickNumber, JLayeredPane.POPUP_LAYER); session.getUI().addComponent(MageComponents.DESKTOP_PANE, desktopPane); - 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); - ManaSymbols.loadImages(); - 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(); - } - - 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(); - } - - 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(); - } - + addTooltipContainer(); + setBackground(); + addMageLabel(); + setAppIcon(); + desktopPane.add(ArrowBuilder.getArrowsPanel(), JLayeredPane.DRAG_LAYER); desktopPane.addComponentListener(new ComponentAdapter(){ @@ -273,6 +215,77 @@ public class MageFrame extends javax.swing.JFrame { } }); } + + 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(CardsStorage.getAllCards());