mirror of
https://github.com/magefree/mage.git
synced 2025-12-21 11:02:00 -08:00
show Table Waiting dialog on reconnect
This commit is contained in:
parent
161404242f
commit
2ad50b2983
7 changed files with 82 additions and 29 deletions
|
|
@ -526,6 +526,12 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
} catch (PropertyVetoException ex) {}
|
||||
}
|
||||
|
||||
public void showTableWaitingDialog(UUID roomId, UUID tableId, boolean isTournament) {
|
||||
TableWaitingDialog tableWaitingDialog = new TableWaitingDialog();
|
||||
desktopPane.add(tableWaitingDialog, JLayeredPane.MODAL_LAYER);
|
||||
tableWaitingDialog.showDialog(roomId, tableId, isTournament);
|
||||
}
|
||||
|
||||
public static boolean connect(Connection connection) {
|
||||
return session.connect(connection);
|
||||
}
|
||||
|
|
@ -776,7 +782,12 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
|
|||
}//GEN-LAST:event_btnPreferencesActionPerformed
|
||||
|
||||
public void exitApp() {
|
||||
if (session.isConnected()) {
|
||||
if (JOptionPane.showConfirmDialog(this, "You are currently connected. Are you sure you want to disconnect?", "Confirm disconnect", JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
|
||||
return;
|
||||
}
|
||||
session.disconnect(false);
|
||||
}
|
||||
Plugins.getInstance().shutdown();
|
||||
dispose();
|
||||
System.exit(0);
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
}
|
||||
}
|
||||
}
|
||||
else if (callback.getMethod().equals("joinedTable")) {
|
||||
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||
joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
|
||||
}
|
||||
else if (callback.getMethod().equals("replayInit")) {
|
||||
GamePanel panel = frame.getGame(callback.getObjectId());
|
||||
if (panel != null)
|
||||
|
|
@ -264,6 +268,15 @@ public class CallbackClientImpl implements CallbackClient {
|
|||
return clientId;
|
||||
}
|
||||
|
||||
private void joinedTable(UUID roomId, UUID tableId, boolean isTournament) {
|
||||
try {
|
||||
frame.showTableWaitingDialog(roomId, tableId, isTournament);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
handleException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected void gameStarted(final UUID gameId, final UUID playerId) {
|
||||
try {
|
||||
frame.showGame(gameId, playerId);
|
||||
|
|
|
|||
|
|
@ -133,15 +133,11 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
}
|
||||
if (isTournament) {
|
||||
logger.info("Joining tournament " + tableId);
|
||||
if (session.joinTournamentTable(roomId, tableId, session.getUserName(), "Human", 1)) {
|
||||
showTableWaitingDialog(roomId, tableId, true);
|
||||
}
|
||||
session.joinTournamentTable(roomId, tableId, session.getUserName(), "Human", 1);
|
||||
}
|
||||
else {
|
||||
logger.info("Joining table " + tableId);
|
||||
joinTableDialog.showDialog(roomId, tableId);
|
||||
if (joinTableDialog.isJoined())
|
||||
showTableWaitingDialog(roomId, tableId, false);
|
||||
}
|
||||
} else if (state.equals("Watch")) {
|
||||
logger.info("Watching table " + tableId);
|
||||
|
|
@ -265,12 +261,6 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
((TablesPane)c).hideFrame();
|
||||
}
|
||||
|
||||
private void showTableWaitingDialog(UUID roomId, UUID tableId, boolean isTournament) {
|
||||
TableWaitingDialog tableWaitingDialog = new TableWaitingDialog();
|
||||
MageFrame.getDesktop().add(tableWaitingDialog, JLayeredPane.MODAL_LAYER);
|
||||
tableWaitingDialog.showDialog(roomId, tableId, isTournament);
|
||||
}
|
||||
|
||||
/** This method is called from within the constructor to
|
||||
* initialize the form.
|
||||
* WARNING: Do NOT modify this code. The content of this method is
|
||||
|
|
@ -418,9 +408,6 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
|
||||
private void btnNewTournamentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTournamentActionPerformed
|
||||
newTournamentDialog.showDialog(roomId);
|
||||
if (newTournamentDialog.getTable() != null) {
|
||||
showTableWaitingDialog(roomId, newTournamentDialog.getTable().getTableId(), true);
|
||||
}
|
||||
}//GEN-LAST:event_btnNewTournamentActionPerformed
|
||||
|
||||
private void btnQuickStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnQuickStartActionPerformed
|
||||
|
|
@ -444,9 +431,6 @@ public class TablesPanel extends javax.swing.JPanel {
|
|||
|
||||
private void btnNewTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNewTableActionPerformed
|
||||
newTableDialog.showDialog(roomId);
|
||||
if (newTableDialog.getTable() != null) {
|
||||
showTableWaitingDialog(roomId, newTableDialog.getTable().getTableId(), false);
|
||||
}
|
||||
}//GEN-LAST:event_btnNewTableActionPerformed
|
||||
|
||||
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ package mage.view;
|
|||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
|
||||
import mage.cards.Card;
|
||||
import mage.cards.decks.Deck;
|
||||
|
||||
/**
|
||||
|
|
@ -42,10 +41,12 @@ public class TableClientMessage implements Serializable {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private DeckView deck;
|
||||
private UUID roomId;
|
||||
private UUID tableId;
|
||||
private UUID gameId;
|
||||
private UUID playerId;
|
||||
private int time;
|
||||
private boolean flag;
|
||||
|
||||
public TableClientMessage(Deck deck, UUID tableId, int time) {
|
||||
this.deck = new DeckView(deck);
|
||||
|
|
@ -58,6 +59,12 @@ public class TableClientMessage implements Serializable {
|
|||
this.playerId = playerId;
|
||||
}
|
||||
|
||||
public TableClientMessage(UUID roomId, UUID tableId, boolean flag) {
|
||||
this.roomId = roomId;
|
||||
this.tableId = tableId;
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public DeckView getDeck() {
|
||||
return deck;
|
||||
}
|
||||
|
|
@ -66,6 +73,10 @@ public class TableClientMessage implements Serializable {
|
|||
return tableId;
|
||||
}
|
||||
|
||||
public UUID getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
|
||||
public UUID getGameId() {
|
||||
return gameId;
|
||||
}
|
||||
|
|
@ -78,6 +89,10 @@ public class TableClientMessage implements Serializable {
|
|||
return time;
|
||||
}
|
||||
|
||||
public boolean getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void cleanUp() {
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -136,6 +136,9 @@ public class TableController {
|
|||
Player player = createPlayer(name, seat.getPlayerType(), skill);
|
||||
tournament.addPlayer(player, seat.getPlayerType());
|
||||
table.joinTable(player, seat);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
user.addTable(player.getId(), table);
|
||||
user.joinedTable(table.getRoomId(), table.getId(), true);
|
||||
logger.info("player joined " + player.getId());
|
||||
//only add human players to sessionPlayerMap
|
||||
if (seat.getPlayer().isHuman()) {
|
||||
|
|
@ -161,6 +164,9 @@ public class TableController {
|
|||
Player player = createPlayer(name, seat.getPlayerType(), skill);
|
||||
match.addPlayer(player, deck);
|
||||
table.joinTable(player, seat);
|
||||
User user = UserManager.getInstance().getUser(userId);
|
||||
user.addTable(player.getId(), table);
|
||||
user.joinedTable(table.getRoomId(), table.getId(), false);
|
||||
logger.info("player joined " + player.getId());
|
||||
//only add human players to sessionPlayerMap
|
||||
if (seat.getPlayer().isHuman()) {
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import java.util.Map;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.UUID;
|
||||
import mage.cards.decks.Deck;
|
||||
import mage.game.Table;
|
||||
import mage.interfaces.callback.ClientCallback;
|
||||
import mage.server.draft.DraftSession;
|
||||
import mage.server.game.GameManager;
|
||||
|
|
@ -57,6 +58,7 @@ public class User {
|
|||
private Date connectionTime = new Date();
|
||||
private Date lastActivity = new Date();
|
||||
private UserState userState;
|
||||
private Map<UUID, Table> tables = new HashMap<UUID, Table>();
|
||||
private Map<UUID, GameSession> gameSessions = new HashMap<UUID, GameSession>();
|
||||
private Map<UUID, DraftSession> draftSessions = new HashMap<UUID, DraftSession>();
|
||||
private Map<UUID, TournamentSession> tournamentSessions = new HashMap<UUID, TournamentSession>();
|
||||
|
|
@ -110,6 +112,10 @@ public class User {
|
|||
}
|
||||
}
|
||||
|
||||
public void joinedTable(final UUID roomId, final UUID tableId, boolean isTournament) {
|
||||
fireCallback(new ClientCallback("joinedTable", tableId, new TableClientMessage(roomId, tableId, isTournament)));
|
||||
}
|
||||
|
||||
public void gameStarted(final UUID gameId, final UUID playerId) {
|
||||
fireCallback(new ClientCallback("startGame", gameId, new TableClientMessage(gameId, playerId)));
|
||||
}
|
||||
|
|
@ -178,6 +184,9 @@ public class User {
|
|||
entry.getValue().init();
|
||||
entry.getValue().update();
|
||||
}
|
||||
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
||||
joinedTable(entry.getValue().getRoomId(), entry.getValue().getId(), entry.getValue().isTournament());
|
||||
}
|
||||
}
|
||||
|
||||
public void addGame(UUID playerId, GameSession gameSession) {
|
||||
|
|
@ -204,15 +213,29 @@ public class User {
|
|||
tournamentSessions.remove(playerId);
|
||||
}
|
||||
|
||||
public void addTable(UUID playerId, Table table) {
|
||||
tables.put(playerId, table);
|
||||
}
|
||||
|
||||
public void removeTable(UUID playerId) {
|
||||
tables.remove(playerId);
|
||||
}
|
||||
|
||||
public void kill() {
|
||||
for (Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
|
||||
entry.getValue().kill();
|
||||
for (GameSession session: gameSessions.values()) {
|
||||
session.kill();
|
||||
}
|
||||
for (Entry<UUID, DraftSession> entry: draftSessions.entrySet()) {
|
||||
entry.getValue().setKilled();
|
||||
for (DraftSession session: draftSessions.values()) {
|
||||
session.setKilled();
|
||||
}
|
||||
for (TournamentSession session: tournamentSessions.values()) {
|
||||
session.setKilled();
|
||||
}
|
||||
for (Entry<UUID, Table> entry: tables.entrySet()) {
|
||||
entry.getValue().leaveTable(entry.getKey());
|
||||
if (TableManager.getInstance().isTableOwner(entry.getValue().getId(), userId)) {
|
||||
TableManager.getInstance().removeTable(userId, entry.getValue().getId());
|
||||
}
|
||||
for (Entry<UUID, TournamentSession> entry: tournamentSessions.entrySet()) {
|
||||
entry.getValue().setKilled();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -172,7 +172,8 @@ public class Table implements Serializable {
|
|||
|
||||
public void leaveTable(UUID playerId) {
|
||||
for (int i = 0; i < numSeats; i++ ) {
|
||||
if (seats[i].getPlayer().getId().equals(playerId)) {
|
||||
Player player = seats[i].getPlayer();
|
||||
if (player != null && player.getId().equals(playerId)) {
|
||||
seats[i].setPlayer(null);
|
||||
if (state == TableState.STARTING)
|
||||
state = TableState.WAITING;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue