* Fixed a cleanup problem that locked the game at game end. Minor formattings and cleanup additions.

This commit is contained in:
LevelX2 2014-02-11 00:38:10 +01:00
parent e672e63736
commit 753ada0a01
13 changed files with 86 additions and 39 deletions

View file

@ -34,6 +34,24 @@
package mage.client.game;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import javax.swing.JComponent;
import javax.swing.JLayeredPane;
import javax.swing.JScrollPane;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import mage.cards.MagePermanent;
import mage.client.cards.BigCard;
import mage.client.cards.Permanent;
@ -43,16 +61,6 @@ import mage.client.util.Config;
import mage.constants.CardType;
import mage.view.PermanentView;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.*;
import java.util.List;
import java.util.Map.Entry;
/**
*
* @author BetaSteward_at_googlemail.com
@ -103,6 +111,11 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
}
public void cleanUp() {
for (Component c: this.jPanel.getComponents()) {
if (c instanceof Permanent || c instanceof MagePermanent) {
this.jPanel.remove(c);
}
}
permanents.clear();
Plugins.getInstance().sortPermanents(uiComponentsList, permanents.values());
}
@ -225,7 +238,9 @@ public class BattlefieldPanel extends javax.swing.JLayeredPane {
private void groupAttachments(PermanentView permanent) {
MagePermanent perm = permanents.get(permanent.getId());
if (perm == null) return;
if (perm == null) {
return;
}
int position = getPosition(perm);
perm.getLinks().clear();
Rectangle r = perm.getBounds();

View file

@ -136,8 +136,8 @@ public class FeedbackPanel extends javax.swing.JPanel {
case END:
this.btnLeft.setVisible(false);
this.btnRight.setVisible(true);
this.btnRight.setText("OK");
this.helper.setState("", false, "OK", true);
this.btnRight.setText("Close game");
this.helper.setState("", false, "Close game", true);
ArrowBuilder.getBuilder().removeAllArrows(gameId);
endWithTimeout();
break;
@ -283,7 +283,10 @@ public class FeedbackPanel extends javax.swing.JPanel {
if (mode == FeedbackMode.SELECT && (evt.getModifiers() & ActionEvent.CTRL_MASK) == ActionEvent.CTRL_MASK) {
session.sendPlayerInteger(gameId, 0);
} else if (mode == FeedbackMode.END) {
MageFrame.getGame(gameId).hideGame();
GamePanel gamePanel = MageFrame.getGame(gameId);
if (gamePanel != null) {
gamePanel.removeGame();
}
} else {
session.sendPlayerBoolean(gameId, false);
}

View file

@ -69,8 +69,7 @@ public class GamePane extends MagePane {
gamePanel.cleanUp();
}
public void hideGame() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
public void removeGame() {
this.cleanUp();
this.removeFrame();
}

View file

@ -335,7 +335,7 @@ public final class GamePanel extends javax.swing.JPanel {
this.gameChatPanel.clear();
this.gameChatPanel.connect(session.getGameChatId(gameId));
if (!session.joinGame(gameId)) {
hideGame();
removeGame();
}
}
@ -354,7 +354,7 @@ public final class GamePanel extends javax.swing.JPanel {
this.gameChatPanel.clear();
this.gameChatPanel.connect(session.getGameChatId(gameId));
if (!session.watchGame(gameId)) {
hideGame();
removeGame();
}
for (PlayAreaPanel panel : getPlayers().values()) {
panel.setPlayingMode(false);
@ -375,7 +375,7 @@ public final class GamePanel extends javax.swing.JPanel {
this.pnlReplay.setVisible(true);
this.gameChatPanel.clear();
if (!session.startReplay(gameId)) {
hideGame();
removeGame();
}
for (PlayAreaPanel panel : getPlayers().values()) {
panel.setPlayingMode(false);
@ -385,13 +385,13 @@ public final class GamePanel extends javax.swing.JPanel {
/**
* Closes the game and it's resources
*/
public void hideGame() {
public void removeGame() {
Component c = this.getParent();
while (c != null && !(c instanceof GamePane)) {
c = c.getParent();
}
if (c != null) {
((GamePane)c).hideGame();
((GamePane)c).removeGame();
}
}
@ -1328,7 +1328,7 @@ public final class GamePanel extends javax.swing.JPanel {
private void btnStopWatchingActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStopWatchingActionPerformed
if (modalQuestion("Are you sure you want to stop watching?", "Stop watching") == JOptionPane.YES_OPTION) {
session.stopWatching(gameId);
this.hideGame();
this.removeGame();
}
}//GEN-LAST:event_btnStopWatchingActionPerformed
@ -1451,8 +1451,8 @@ public final class GamePanel extends javax.swing.JPanel {
}
class ReplayTask extends SwingWorker<Void, Collection<MatchView>> {
private Session session;
private UUID gameId;
private final Session session;
private final UUID gameId;
private static final Logger logger = Logger.getLogger(ReplayTask.class);

View file

@ -66,7 +66,8 @@ public class PlayAreaPanel extends javax.swing.JPanel {
public static final int PANEL_HEIGHT = 242;
public static final int PANEL_HEIGHT_SMALL = 190;
/** Creates new form PlayAreaPanel */
/** Creates new form PlayAreaPanel
* @param isPlayer */
public PlayAreaPanel(boolean isPlayer) {
initComponents();
setOpaque(false);
@ -225,7 +226,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
public void actionPerformed(ActionEvent e) {
if (JOptionPane.showConfirmDialog(PlayAreaPanel.this, "Are you sure you want to stop watching the game?", "Confirm stop watching game", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
gamePanel.getSession().stopWatching(gameId);
gamePanel.hideGame();
gamePanel.removeGame();
}
}
});

View file

@ -64,10 +64,11 @@ import org.apache.log4j.Logger;
public class CallbackClientImpl implements CallbackClient {
private static final Logger logger = Logger.getLogger(CallbackClientImpl.class);
private UUID clientId;
private MageFrame frame;
private final UUID clientId;
private final MageFrame frame;
private int messageId = 0;
private boolean firstRun;
private int gameInformMessageId = 0;
private final boolean firstRun;
public CallbackClientImpl(MageFrame frame) {
this.clientId = UUID.randomUUID();
@ -165,7 +166,7 @@ public class CallbackClientImpl implements CallbackClient {
}
} else if (callback.getMethod().equals("gameOver")) {
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
if (panel != null) {
panel.endMessage((String) callback.getData(), callback.getMessageId());
}
} else if (callback.getMethod().equals("gameError")) {
@ -238,15 +239,18 @@ public class CallbackClientImpl implements CallbackClient {
}
} else if (callback.getMethod().equals("gameInform")) {
if (callback.getMessageId() > messageId) {
if (callback.getMessageId() > gameInformMessageId) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.inform(message.getMessage(), message.getGameView(), callback.getMessageId());
}
} else {
logger.warn("message out of sequence - ignoring");
logger.warn(new StringBuilder("message out of sequence - ignoring").append("MessageId = ").append(callback.getMessageId()).append(" method = ").append(callback.getMethod()));
//logger.warn("message out of sequence - ignoring");
}
gameInformMessageId = messageId;
} else if (callback.getMethod().equals("gameInformPersonal")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = MageFrame.getGame(callback.getObjectId());