forked from External/mage
* Fixed a cleanup problem that locked the game at game end. Minor formattings and cleanup additions.
This commit is contained in:
parent
e672e63736
commit
753ada0a01
13 changed files with 86 additions and 39 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,7 @@ public class GamePane extends MagePane {
|
|||
gamePanel.cleanUp();
|
||||
}
|
||||
|
||||
public void hideGame() {
|
||||
KeyboardFocusManager.getCurrentKeyboardFocusManager().clearGlobalFocusOwner();
|
||||
public void removeGame() {
|
||||
this.cleanUp();
|
||||
this.removeFrame();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ public class DraftSession {
|
|||
}
|
||||
}
|
||||
|
||||
// not used
|
||||
//
|
||||
public void inform(final String message) {
|
||||
if (!killed) {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
|
|
|
|||
|
|
@ -689,6 +689,7 @@ public class GameController implements GameCallback {
|
|||
@Override
|
||||
public void gameResult(String result) {
|
||||
try {
|
||||
logger.warn("Game Result: " + result);
|
||||
endGame(result);
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("Game Result error", ex);
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.UUID;
|
||||
import mage.game.GameState;
|
||||
import mage.game.match.Match;
|
||||
import mage.view.GameEndView;
|
||||
|
||||
|
|
@ -75,7 +76,16 @@ public class GameWatcher {
|
|||
if (!killed) {
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
if (user != null) {
|
||||
user.fireCallback(new ClientCallback("gameUpdate", game.getId(), getGameView()));
|
||||
logger.warn("before gameUpdate");
|
||||
GameView gameView = getGameView();
|
||||
logger.warn("after View");
|
||||
UUID id = game.getId();
|
||||
logger.warn("after ID");
|
||||
ClientCallback clientCallback = new ClientCallback("gameUpdate", id, gameView);
|
||||
logger.warn("callback obj");
|
||||
user.fireCallback(clientCallback);
|
||||
// user.fireCallback(new ClientCallback("gameUpdate", game.getId(), getGameView()));
|
||||
logger.warn("after gameUpdate");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -126,7 +136,13 @@ public class GameWatcher {
|
|||
}
|
||||
|
||||
public GameView getGameView() {
|
||||
return new GameView(game.getState(), game, this.isPlayer);
|
||||
logger.warn("start getGameView");
|
||||
GameState gameState = game.getState();
|
||||
logger.warn("start afterState");
|
||||
GameView gameView = new GameView(gameState, game, this.isPlayer);
|
||||
// return new GameView(game.getState(), game, this.isPlayer);
|
||||
logger.warn("after getGameView");
|
||||
return gameView;
|
||||
}
|
||||
|
||||
public GameEndView getGameEndView(UUID playerId, Match match) {
|
||||
|
|
|
|||
|
|
@ -59,6 +59,7 @@ public class GameWorker implements Callable {
|
|||
game.start(choosingPlayerId);
|
||||
game.fireUpdatePlayersEvent();
|
||||
result.gameResult(game.getWinner());
|
||||
game.cleanUp();
|
||||
} catch (MageException ex) {
|
||||
logger.fatal("GameWorker error ", ex);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@ public interface Game extends MageItem, Serializable {
|
|||
void pause();
|
||||
boolean isPaused();
|
||||
void end();
|
||||
void cleanUp();
|
||||
/*
|
||||
* Gives back the number of cards the player has after the next mulligan
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -549,6 +549,11 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
start(choosingPlayerId, this.gameOptions != null ? gameOptions : GameOptions.getDefault());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanUp() {
|
||||
gameCards.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start(UUID choosingPlayerId, GameOptions options) {
|
||||
startTime = new Date();
|
||||
|
|
@ -815,8 +820,6 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
for (Player player: state.getPlayers().values()) {
|
||||
player.abort();
|
||||
}
|
||||
// allow gc
|
||||
gameCards.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,11 +38,12 @@ import mage.game.events.GameEvent.EventType;
|
|||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class Step<T extends Step<T>> implements Serializable {
|
||||
|
||||
private PhaseStep type;
|
||||
private boolean hasPriority;
|
||||
private final PhaseStep type;
|
||||
private final boolean hasPriority;
|
||||
protected EventType stepEvent;
|
||||
protected EventType preStepEvent;
|
||||
protected EventType postStepEvent;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue