mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
show completed matches - view replays
This commit is contained in:
parent
8c9db5876e
commit
4a653d55cd
11 changed files with 396 additions and 46 deletions
|
|
@ -106,6 +106,9 @@
|
||||||
<Property name="selected" type="boolean" value="true"/>
|
<Property name="selected" type="boolean" value="true"/>
|
||||||
<Property name="text" type="java.lang.String" value="Show Completed"/>
|
<Property name="text" type="java.lang.String" value="Show Completed"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
<Events>
|
||||||
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="chkShowCompletedActionPerformed"/>
|
||||||
|
</Events>
|
||||||
</Component>
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
|
|
@ -128,7 +131,7 @@
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jLabel2" pref="449" max="32767" attributes="0"/>
|
<Component id="jLabel2" max="32767" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
|
<Component id="jButton1" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace min="-2" pref="440" max="-2" attributes="0"/>
|
<EmptySpace min="-2" pref="440" max="-2" attributes="0"/>
|
||||||
|
|
@ -228,6 +231,7 @@
|
||||||
<Container class="javax.swing.JSplitPane" name="jSplitPane2">
|
<Container class="javax.swing.JSplitPane" name="jSplitPane2">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="orientation" type="int" value="0"/>
|
<Property name="orientation" type="int" value="0"/>
|
||||||
|
<Property name="resizeWeight" type="double" value="0.5"/>
|
||||||
</Properties>
|
</Properties>
|
||||||
|
|
||||||
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
|
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JSplitPaneSupportLayout"/>
|
||||||
|
|
@ -257,6 +261,11 @@
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Container>
|
</Container>
|
||||||
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
|
<Container class="javax.swing.JScrollPane" name="jScrollPane2">
|
||||||
|
<Properties>
|
||||||
|
<Property name="minimumSize" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor">
|
||||||
|
<Dimension value="[23, 0]"/>
|
||||||
|
</Property>
|
||||||
|
</Properties>
|
||||||
<AuxValues>
|
<AuxValues>
|
||||||
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
|
||||||
</AuxValues>
|
</AuxValues>
|
||||||
|
|
@ -270,13 +279,8 @@
|
||||||
<SubComponents>
|
<SubComponents>
|
||||||
<Component class="javax.swing.JTable" name="tableCompleted">
|
<Component class="javax.swing.JTable" name="tableCompleted">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor">
|
<Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
|
||||||
<Table columnCount="4" rowCount="4">
|
<Connection code="this.matchesModel" type="code"/>
|
||||||
<Column editable="true" title="Title 1" type="java.lang.Object"/>
|
|
||||||
<Column editable="true" title="Title 2" type="java.lang.Object"/>
|
|
||||||
<Column editable="true" title="Title 3" type="java.lang.Object"/>
|
|
||||||
<Column editable="true" title="Title 4" type="java.lang.Object"/>
|
|
||||||
</Table>
|
|
||||||
</Property>
|
</Property>
|
||||||
</Properties>
|
</Properties>
|
||||||
</Component>
|
</Component>
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,6 @@ import mage.remote.Session;
|
||||||
import mage.client.util.ButtonColumn;
|
import mage.client.util.ButtonColumn;
|
||||||
import mage.game.match.MatchOptions;
|
import mage.game.match.MatchOptions;
|
||||||
import mage.sets.Sets;
|
import mage.sets.Sets;
|
||||||
import mage.utils.CompressUtil;
|
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -63,6 +62,8 @@ import java.util.*;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import mage.client.util.gui.GuiDisplayUtil;
|
||||||
|
import mage.view.MatchView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -74,12 +75,15 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
private final static Logger logger = Logger.getLogger(TablesPanel.class);
|
private final static Logger logger = Logger.getLogger(TablesPanel.class);
|
||||||
|
|
||||||
private TableTableModel tableModel;
|
private TableTableModel tableModel;
|
||||||
|
private MatchesTableModel matchesModel;
|
||||||
private UUID roomId;
|
private UUID roomId;
|
||||||
private UpdateTablesTask updateTask;
|
private UpdateTablesTask updateTablesTask;
|
||||||
private UpdatePlayersTask updatePlayersTask;
|
private UpdatePlayersTask updatePlayersTask;
|
||||||
|
private UpdateMatchesTask updateMatchesTask;
|
||||||
private JoinTableDialog joinTableDialog;
|
private JoinTableDialog joinTableDialog;
|
||||||
private NewTableDialog newTableDialog;
|
private NewTableDialog newTableDialog;
|
||||||
private NewTournamentDialog newTournamentDialog;
|
private NewTournamentDialog newTournamentDialog;
|
||||||
|
private GameChooser gameChooser;
|
||||||
private Session session;
|
private Session session;
|
||||||
private List<String> messages;
|
private List<String> messages;
|
||||||
private int currentMessage;
|
private int currentMessage;
|
||||||
|
|
@ -88,6 +92,8 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
public TablesPanel() {
|
public TablesPanel() {
|
||||||
|
|
||||||
tableModel = new TableTableModel();
|
tableModel = new TableTableModel();
|
||||||
|
matchesModel = new MatchesTableModel();
|
||||||
|
gameChooser = new GameChooser();
|
||||||
|
|
||||||
initComponents();
|
initComponents();
|
||||||
|
|
||||||
|
|
@ -96,7 +102,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
chatPanel.setOpaque(false);
|
chatPanel.setOpaque(false);
|
||||||
chatPanel.setBorder(null);
|
chatPanel.setBorder(null);
|
||||||
|
|
||||||
Action join = new AbstractAction()
|
Action joinTable = new AbstractAction()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e)
|
public void actionPerformed(ActionEvent e)
|
||||||
|
|
@ -149,7 +155,24 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
ButtonColumn buttonColumn = new ButtonColumn(tableTables, join, 6);
|
Action replayMatch = new AbstractAction()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e)
|
||||||
|
{
|
||||||
|
int modelRow = Integer.valueOf( e.getActionCommand() );
|
||||||
|
List<UUID> games = (List<UUID>)matchesModel.getValueAt(modelRow, 6);
|
||||||
|
if (games.size() == 1) {
|
||||||
|
session.replayGame(games.get(0));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gameChooser.show(games, MageFrame.getDesktop().getMousePosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ButtonColumn buttonColumn1 = new ButtonColumn(tableTables, joinTable, 6);
|
||||||
|
ButtonColumn buttonColumn2 = new ButtonColumn(tableCompleted, replayMatch, 5);
|
||||||
|
|
||||||
jSplitPane1.setOpaque(false);
|
jSplitPane1.setOpaque(false);
|
||||||
jScrollPane1.setOpaque(false);
|
jScrollPane1.setOpaque(false);
|
||||||
|
|
@ -168,7 +191,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
return components;
|
return components;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(Collection<TableView> tables) {
|
public void updateTables(Collection<TableView> tables) {
|
||||||
try {
|
try {
|
||||||
tableModel.loadData(tables);
|
tableModel.loadData(tables);
|
||||||
this.tableTables.repaint();
|
this.tableTables.repaint();
|
||||||
|
|
@ -177,24 +200,45 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startTasks() {
|
public void updateMatches(Collection<MatchView> matches) {
|
||||||
|
try {
|
||||||
|
matchesModel.loadData(matches);
|
||||||
|
this.tableCompleted.repaint();
|
||||||
|
} catch (Exception ex) {
|
||||||
|
hideTables();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startTasks() {
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
if (updateTask == null || updateTask.isDone()) {
|
if (updateTablesTask == null || updateTablesTask.isDone()) {
|
||||||
updateTask = new UpdateTablesTask(session, roomId, this);
|
updateTablesTask = new UpdateTablesTask(session, roomId, this);
|
||||||
updateTask.execute();
|
updateTablesTask.execute();
|
||||||
}
|
}
|
||||||
if (updatePlayersTask == null || updatePlayersTask.isDone()) {
|
if (updatePlayersTask == null || updatePlayersTask.isDone()) {
|
||||||
updatePlayersTask = new UpdatePlayersTask(session, roomId, this.chatPanel);
|
updatePlayersTask = new UpdatePlayersTask(session, roomId, this.chatPanel);
|
||||||
updatePlayersTask.execute();
|
updatePlayersTask.execute();
|
||||||
}
|
}
|
||||||
|
if (this.chkShowCompleted.isSelected()) {
|
||||||
|
if (updateMatchesTask == null || updateMatchesTask.isDone()) {
|
||||||
|
updateMatchesTask = new UpdateMatchesTask(session, roomId, this);
|
||||||
|
updateMatchesTask.execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (updateMatchesTask != null)
|
||||||
|
updateMatchesTask.cancel(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTasks() {
|
public void stopTasks() {
|
||||||
if (updateTask != null)
|
if (updateTablesTask != null)
|
||||||
updateTask.cancel(true);
|
updateTablesTask.cancel(true);
|
||||||
if (updatePlayersTask != null)
|
if (updatePlayersTask != null)
|
||||||
updatePlayersTask.cancel(true);
|
updatePlayersTask.cancel(true);
|
||||||
|
if (updateMatchesTask != null)
|
||||||
|
updateMatchesTask.cancel(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showTables(UUID roomId) {
|
public void showTables(UUID roomId) {
|
||||||
|
|
@ -203,6 +247,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
session = MageFrame.getSession();
|
session = MageFrame.getSession();
|
||||||
if (session != null) {
|
if (session != null) {
|
||||||
btnQuickStart.setVisible(session.isTestMode());
|
btnQuickStart.setVisible(session.isTestMode());
|
||||||
|
gameChooser.init(session);
|
||||||
}
|
}
|
||||||
if (newTableDialog == null) {
|
if (newTableDialog == null) {
|
||||||
newTableDialog = new NewTableDialog();
|
newTableDialog = new NewTableDialog();
|
||||||
|
|
@ -311,6 +356,11 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
|
|
||||||
chkShowCompleted.setSelected(true);
|
chkShowCompleted.setSelected(true);
|
||||||
chkShowCompleted.setText("Show Completed");
|
chkShowCompleted.setText("Show Completed");
|
||||||
|
chkShowCompleted.addActionListener(new java.awt.event.ActionListener() {
|
||||||
|
public void actionPerformed(java.awt.event.ActionEvent evt) {
|
||||||
|
chkShowCompletedActionPerformed(evt);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
|
||||||
jPanel1.setLayout(jPanel1Layout);
|
jPanel1.setLayout(jPanel1Layout);
|
||||||
|
|
@ -342,7 +392,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
jPanel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
|
||||||
jPanel2.setPreferredSize(new java.awt.Dimension(664, 39));
|
jPanel2.setPreferredSize(new java.awt.Dimension(664, 39));
|
||||||
|
|
||||||
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
|
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
|
||||||
jLabel1.setText("Message of the Day:");
|
jLabel1.setText("Message of the Day:");
|
||||||
jLabel1.setAlignmentY(0.3F);
|
jLabel1.setAlignmentY(0.3F);
|
||||||
|
|
||||||
|
|
@ -366,7 +416,7 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
.addContainerGap()
|
.addContainerGap()
|
||||||
.addComponent(jLabel1)
|
.addComponent(jLabel1)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 449, Short.MAX_VALUE)
|
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addGap(440, 440, 440))
|
.addGap(440, 440, 440))
|
||||||
|
|
@ -388,23 +438,16 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
jSplitPane1.setRightComponent(chatPanel);
|
jSplitPane1.setRightComponent(chatPanel);
|
||||||
|
|
||||||
jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
|
jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
|
||||||
|
jSplitPane2.setResizeWeight(0.5);
|
||||||
|
|
||||||
tableTables.setModel(this.tableModel);
|
tableTables.setModel(this.tableModel);
|
||||||
jScrollPane1.setViewportView(tableTables);
|
jScrollPane1.setViewportView(tableTables);
|
||||||
|
|
||||||
jSplitPane2.setLeftComponent(jScrollPane1);
|
jSplitPane2.setLeftComponent(jScrollPane1);
|
||||||
|
|
||||||
tableCompleted.setModel(new javax.swing.table.DefaultTableModel(
|
jScrollPane2.setMinimumSize(new java.awt.Dimension(23, 0));
|
||||||
new Object [][] {
|
|
||||||
{null, null, null, null},
|
tableCompleted.setModel(this.matchesModel);
|
||||||
{null, null, null, null},
|
|
||||||
{null, null, null, null},
|
|
||||||
{null, null, null, null}
|
|
||||||
},
|
|
||||||
new String [] {
|
|
||||||
"Title 1", "Title 2", "Title 3", "Title 4"
|
|
||||||
}
|
|
||||||
));
|
|
||||||
jScrollPane2.setViewportView(tableCompleted);
|
jScrollPane2.setViewportView(tableCompleted);
|
||||||
|
|
||||||
jSplitPane2.setRightComponent(jScrollPane2);
|
jSplitPane2.setRightComponent(jScrollPane2);
|
||||||
|
|
@ -486,6 +529,16 @@ public class TablesPanel extends javax.swing.JPanel {
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_jButton1ActionPerformed
|
}//GEN-LAST:event_jButton1ActionPerformed
|
||||||
|
|
||||||
|
private void chkShowCompletedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkShowCompletedActionPerformed
|
||||||
|
if (this.chkShowCompleted.isSelected()) {
|
||||||
|
this.jSplitPane2.setDividerLocation(-1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.jSplitPane2.setDividerLocation(this.jPanel3.getHeight());
|
||||||
|
}
|
||||||
|
this.startTasks();
|
||||||
|
}//GEN-LAST:event_chkShowCompletedActionPerformed
|
||||||
|
|
||||||
private void handleError(Exception ex) {
|
private void handleError(Exception ex) {
|
||||||
logger.fatal("Error loading deck: ", ex);
|
logger.fatal("Error loading deck: ", ex);
|
||||||
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error loading deck.", "Error", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error loading deck.", "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
@ -622,7 +675,7 @@ class UpdateTablesTask extends SwingWorker<Void, Collection<TableView>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void process(List<Collection<TableView>> view) {
|
protected void process(List<Collection<TableView>> view) {
|
||||||
panel.update(view.get(0));
|
panel.updateTables(view.get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -678,3 +731,147 @@ class UpdatePlayersTask extends SwingWorker<Void, Collection<String>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MatchesTableModel extends AbstractTableModel {
|
||||||
|
private String[] columnNames = new String[]{"Match Name", "Game Type", "Deck Type", "Players", "Result", "Action"};
|
||||||
|
private MatchView[] matches = new MatchView[0];
|
||||||
|
private static final DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
|
||||||
|
|
||||||
|
public void loadData(Collection<MatchView> matches) throws MageRemoteException {
|
||||||
|
this.matches = matches.toArray(new MatchView[0]);
|
||||||
|
this.fireTableDataChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRowCount() {
|
||||||
|
return matches.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return columnNames.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getValueAt(int arg0, int arg1) {
|
||||||
|
switch (arg1) {
|
||||||
|
case 0:
|
||||||
|
return matches[arg0].getName();
|
||||||
|
case 1:
|
||||||
|
return matches[arg0].getGameType();
|
||||||
|
case 2:
|
||||||
|
return matches[arg0].getDeckType();
|
||||||
|
case 3:
|
||||||
|
return matches[arg0].getPlayers();
|
||||||
|
case 4:
|
||||||
|
return matches[arg0].getResult();
|
||||||
|
case 5:
|
||||||
|
return "Replay";
|
||||||
|
case 6:
|
||||||
|
return matches[arg0].getGames();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getColumnName(int columnIndex) {
|
||||||
|
String colName = "";
|
||||||
|
|
||||||
|
if (columnIndex <= getColumnCount())
|
||||||
|
colName = columnNames[columnIndex];
|
||||||
|
|
||||||
|
return colName;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Class getColumnClass(int columnIndex){
|
||||||
|
return String.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isCellEditable(int rowIndex, int columnIndex) {
|
||||||
|
if (columnIndex != 5)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class UpdateMatchesTask extends SwingWorker<Void, Collection<MatchView>> {
|
||||||
|
|
||||||
|
private Session session;
|
||||||
|
private UUID roomId;
|
||||||
|
private TablesPanel panel;
|
||||||
|
|
||||||
|
private final static Logger logger = Logger.getLogger(UpdateTablesTask.class);
|
||||||
|
|
||||||
|
UpdateMatchesTask(Session session, UUID roomId, TablesPanel panel) {
|
||||||
|
this.session = session;
|
||||||
|
this.roomId = roomId;
|
||||||
|
this.panel = panel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Void doInBackground() throws Exception {
|
||||||
|
while (!isCancelled()) {
|
||||||
|
Collection<MatchView> matches = session.getFinishedMatches(roomId);
|
||||||
|
if (matches != null) this.publish(matches);
|
||||||
|
Thread.sleep(5000);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(List<Collection<MatchView>> view) {
|
||||||
|
panel.updateMatches(view.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void done() {
|
||||||
|
try {
|
||||||
|
get();
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
logger.fatal("Update Matches Task error", ex);
|
||||||
|
} catch (ExecutionException ex) {
|
||||||
|
logger.fatal("Update Matches Task error", ex);
|
||||||
|
} catch (CancellationException ex) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class GameChooser extends JPopupMenu {
|
||||||
|
|
||||||
|
private Session session;
|
||||||
|
|
||||||
|
public void init(Session session) {
|
||||||
|
this.session = session;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void show(List<UUID> games, Point p) {
|
||||||
|
if (p == null) return;
|
||||||
|
this.removeAll();
|
||||||
|
for (UUID gameId: games) {
|
||||||
|
this.add(new GameChooserAction(gameId, gameId.toString()));
|
||||||
|
}
|
||||||
|
this.show(MageFrame.getDesktop(), p.x, p.y);
|
||||||
|
GuiDisplayUtil.keepComponentInsideScreen(p.x, p.y, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GameChooserAction extends AbstractAction {
|
||||||
|
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
public GameChooserAction(UUID id, String choice) {
|
||||||
|
this.id = id;
|
||||||
|
putValue(Action.NAME, choice);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
session.replayGame(id);
|
||||||
|
setVisible(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,7 @@ import mage.utils.MageVersion;
|
||||||
import mage.view.DraftPickView;
|
import mage.view.DraftPickView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
|
import mage.view.MatchView;
|
||||||
import mage.view.TournamentView;
|
import mage.view.TournamentView;
|
||||||
import mage.view.UserView;
|
import mage.view.UserView;
|
||||||
|
|
||||||
|
|
@ -68,6 +69,7 @@ public interface MageServer {
|
||||||
public TableView getTable(UUID roomId, UUID tableId) throws MageException;
|
public TableView getTable(UUID roomId, UUID tableId) throws MageException;
|
||||||
public List<TableView> getTables(UUID roomId) throws MageException;
|
public List<TableView> getTables(UUID roomId) throws MageException;
|
||||||
public List<String> getConnectedPlayers(UUID roomId) throws MageException;
|
public List<String> getConnectedPlayers(UUID roomId) throws MageException;
|
||||||
|
public List<MatchView> getFinishedMatches(UUID roomId) throws MageException;
|
||||||
|
|
||||||
//chat methods
|
//chat methods
|
||||||
public void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
|
public void sendChatMessage(UUID chatId, String userName, String message) throws MageException;
|
||||||
|
|
@ -92,7 +94,6 @@ public interface MageServer {
|
||||||
public void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException;
|
public void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException;
|
||||||
public void concedeGame(UUID gameId, String sessionId) throws MageException;
|
public void concedeGame(UUID gameId, String sessionId) throws MageException;
|
||||||
|
|
||||||
|
|
||||||
//tournament methods
|
//tournament methods
|
||||||
public void startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
public void startTournament(String sessionId, UUID roomId, UUID tableId) throws MageException;
|
||||||
public void joinTournament(UUID draftId, String sessionId) throws MageException;
|
public void joinTournament(UUID draftId, String sessionId) throws MageException;
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.utils.CompressUtil;
|
import mage.utils.CompressUtil;
|
||||||
import mage.view.DraftPickView;
|
import mage.view.DraftPickView;
|
||||||
import mage.view.GameTypeView;
|
import mage.view.GameTypeView;
|
||||||
|
import mage.view.MatchView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.TournamentTypeView;
|
import mage.view.TournamentTypeView;
|
||||||
import mage.view.TournamentView;
|
import mage.view.TournamentView;
|
||||||
|
|
@ -342,7 +343,6 @@ public class Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<TableView> getTables(UUID roomId) throws MageRemoteException {
|
public Collection<TableView> getTables(UUID roomId) throws MageRemoteException {
|
||||||
// lock.readLock().lock();
|
|
||||||
try {
|
try {
|
||||||
if (isConnected())
|
if (isConnected())
|
||||||
return server.getTables(roomId);
|
return server.getTables(roomId);
|
||||||
|
|
@ -351,14 +351,24 @@ public class Session {
|
||||||
throw new MageRemoteException();
|
throw new MageRemoteException();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
handleThrowable(t);
|
handleThrowable(t);
|
||||||
// } finally {
|
|
||||||
// lock.readLock().unlock();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<String> getConnectedPlayers(UUID roomId) throws MageRemoteException {
|
public Collection<MatchView> getFinishedMatches(UUID roomId) throws MageRemoteException {
|
||||||
// lock.readLock().lock();
|
try {
|
||||||
|
if (isConnected())
|
||||||
|
return server.getFinishedMatches(roomId);
|
||||||
|
} catch (MageException ex) {
|
||||||
|
handleMageException(ex);
|
||||||
|
throw new MageRemoteException();
|
||||||
|
} catch (Throwable t) {
|
||||||
|
handleThrowable(t);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<String> getConnectedPlayers(UUID roomId) throws MageRemoteException {
|
||||||
try {
|
try {
|
||||||
if (isConnected())
|
if (isConnected())
|
||||||
return server.getConnectedPlayers(roomId);
|
return server.getConnectedPlayers(roomId);
|
||||||
|
|
@ -367,8 +377,6 @@ public class Session {
|
||||||
throw new MageRemoteException();
|
throw new MageRemoteException();
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
handleThrowable(t);
|
handleThrowable(t);
|
||||||
// } finally {
|
|
||||||
// lock.readLock().unlock();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
100
Mage.Common/src/mage/view/MatchView.java
Normal file
100
Mage.Common/src/mage/view/MatchView.java
Normal file
|
|
@ -0,0 +1,100 @@
|
||||||
|
/*
|
||||||
|
* 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.view;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import mage.game.Game;
|
||||||
|
import mage.game.match.Match;
|
||||||
|
import mage.game.match.MatchPlayer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
*/
|
||||||
|
public class MatchView implements Serializable {
|
||||||
|
|
||||||
|
private UUID matchId;
|
||||||
|
private String matchName;
|
||||||
|
private String gameType;
|
||||||
|
private String deckType;
|
||||||
|
|
||||||
|
private List<UUID> games = new ArrayList<UUID>();
|
||||||
|
private String result;
|
||||||
|
private String players;
|
||||||
|
|
||||||
|
public MatchView(Match match) {
|
||||||
|
this.matchId = match.getId();
|
||||||
|
this.matchName = match.getName();
|
||||||
|
this.gameType = match.getOptions().getGameType();
|
||||||
|
this.deckType = match.getOptions().getDeckType();
|
||||||
|
for (Game game: match.getGames()) {
|
||||||
|
games.add(game.getId());
|
||||||
|
}
|
||||||
|
StringBuilder sb1 = new StringBuilder();
|
||||||
|
StringBuilder sb2 = new StringBuilder();
|
||||||
|
for (MatchPlayer player: match.getPlayers()) {
|
||||||
|
sb1.append(player.getPlayer().getName()).append(", ");
|
||||||
|
sb2.append(player.getPlayer().getName()).append(" ").append(player.getWins()).append("-").append(player.getLoses()).append(", ");
|
||||||
|
players = sb1.substring(0, sb1.length() - 2);
|
||||||
|
result = sb2.substring(0, sb2.length() - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public UUID getMatchId() {
|
||||||
|
return matchId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return matchName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGameType() {
|
||||||
|
return gameType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeckType() {
|
||||||
|
return deckType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<UUID> getGames() {
|
||||||
|
return games;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResult() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlayers() {
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -56,6 +56,7 @@ import mage.utils.MageVersion;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
import mage.view.ChatMessage.MessageColor;
|
||||||
import mage.view.DraftPickView;
|
import mage.view.DraftPickView;
|
||||||
import mage.view.GameView;
|
import mage.view.GameView;
|
||||||
|
import mage.view.MatchView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import mage.view.TournamentView;
|
import mage.view.TournamentView;
|
||||||
import mage.view.UserView;
|
import mage.view.UserView;
|
||||||
|
|
@ -224,6 +225,17 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public List<MatchView> getFinishedMatches(UUID roomId) throws MageException {
|
||||||
|
try {
|
||||||
|
return GamesRoomManager.getInstance().getRoom(roomId).getFinished();
|
||||||
|
}
|
||||||
|
catch (Exception ex) {
|
||||||
|
handleException(ex);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public List<String> getConnectedPlayers(UUID roomId) throws MageException {
|
public List<String> getConnectedPlayers(UUID roomId) throws MageException {
|
||||||
try {
|
try {
|
||||||
List<String> players = new ArrayList<String>();
|
List<String> players = new ArrayList<String>();
|
||||||
|
|
|
||||||
|
|
@ -377,9 +377,9 @@ public class TableController {
|
||||||
match.sideboard();
|
match.sideboard();
|
||||||
startGame(choosingPlayerId);
|
startGame(choosingPlayerId);
|
||||||
}
|
}
|
||||||
else {
|
// else {
|
||||||
GamesRoomManager.getInstance().removeTable(table.getId());
|
// GamesRoomManager.getInstance().removeTable(table.getId());
|
||||||
}
|
// }
|
||||||
} catch (GameException ex) {
|
} catch (GameException ex) {
|
||||||
logger.fatal(null, ex);
|
logger.fatal(null, ex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import mage.game.GameException;
|
||||||
import mage.game.match.MatchOptions;
|
import mage.game.match.MatchOptions;
|
||||||
import mage.game.tournament.TournamentOptions;
|
import mage.game.tournament.TournamentOptions;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
|
import mage.view.MatchView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,6 +46,7 @@ import mage.view.TableView;
|
||||||
public interface GamesRoom extends Room {
|
public interface GamesRoom extends Room {
|
||||||
|
|
||||||
public List<TableView> getTables();
|
public List<TableView> getTables();
|
||||||
|
public List<MatchView> getFinished();
|
||||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException;
|
||||||
public boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
public boolean joinTournamentTable(UUID userId, UUID tableId, String name, String playerType, int skill) throws GameException;
|
||||||
public TableView createTable(UUID userId, MatchOptions options);
|
public TableView createTable(UUID userId, MatchOptions options);
|
||||||
|
|
|
||||||
|
|
@ -36,11 +36,13 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import mage.Constants.TableState;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.game.GameException;
|
import mage.game.GameException;
|
||||||
import mage.game.match.MatchOptions;
|
import mage.game.match.MatchOptions;
|
||||||
import mage.game.tournament.TournamentOptions;
|
import mage.game.tournament.TournamentOptions;
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
|
import mage.view.MatchView;
|
||||||
import mage.view.TableView;
|
import mage.view.TableView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
|
@ -58,11 +60,22 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
||||||
public List<TableView> getTables() {
|
public List<TableView> getTables() {
|
||||||
ArrayList<TableView> tableList = new ArrayList<TableView>();
|
ArrayList<TableView> tableList = new ArrayList<TableView>();
|
||||||
for (Table table: tables.values()) {
|
for (Table table: tables.values()) {
|
||||||
tableList.add(new TableView(table));
|
if (table.getState() != TableState.FINISHED)
|
||||||
|
tableList.add(new TableView(table));
|
||||||
}
|
}
|
||||||
return tableList;
|
return tableList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<MatchView> getFinished() {
|
||||||
|
ArrayList<MatchView> matchList = new ArrayList<MatchView>();
|
||||||
|
for (Table table: tables.values()) {
|
||||||
|
if (table.getState() == TableState.FINISHED)
|
||||||
|
matchList.add(new MatchView(table.getMatch()));
|
||||||
|
}
|
||||||
|
return matchList;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
public boolean joinTable(UUID userId, UUID tableId, String name, String playerType, int skill, DeckCardLists deckList) throws MageException {
|
||||||
if (tables.containsKey(tableId)) {
|
if (tables.containsKey(tableId)) {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ import mage.players.Player;
|
||||||
public interface Match {
|
public interface Match {
|
||||||
|
|
||||||
public UUID getId();
|
public UUID getId();
|
||||||
|
public String getName();
|
||||||
public boolean isMatchOver();
|
public boolean isMatchOver();
|
||||||
public List<MatchPlayer> getPlayers();
|
public List<MatchPlayer> getPlayers();
|
||||||
public MatchPlayer getPlayer(UUID playerId);
|
public MatchPlayer getPlayer(UUID playerId);
|
||||||
|
|
@ -59,6 +60,7 @@ public interface Match {
|
||||||
public int getNumGames();
|
public int getNumGames();
|
||||||
public boolean isDoneSideboarding();
|
public boolean isDoneSideboarding();
|
||||||
public UUID getChooser();
|
public UUID getChooser();
|
||||||
|
public MatchOptions getOptions();
|
||||||
|
|
||||||
public void addTableEventListener(Listener<TableEvent> listener);
|
public void addTableEventListener(Listener<TableEvent> listener);
|
||||||
public void fireSideboardEvent(UUID playerId, Deck deck);
|
public void fireSideboardEvent(UUID playerId, Deck deck);
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ public abstract class MatchImpl implements Match {
|
||||||
private static final int SIDEBOARD_TIME = 180;
|
private static final int SIDEBOARD_TIME = 180;
|
||||||
|
|
||||||
protected UUID id = UUID.randomUUID();
|
protected UUID id = UUID.randomUUID();
|
||||||
|
protected String name;
|
||||||
protected List<MatchPlayer> players = new ArrayList<MatchPlayer>();
|
protected List<MatchPlayer> players = new ArrayList<MatchPlayer>();
|
||||||
protected List<Game> games = new ArrayList<Game>();
|
protected List<Game> games = new ArrayList<Game>();
|
||||||
protected MatchOptions options;
|
protected MatchOptions options;
|
||||||
|
|
@ -91,6 +92,16 @@ public abstract class MatchImpl implements Match {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return options.getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MatchOptions getOptions() {
|
||||||
|
return options;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isMatchOver() {
|
public boolean isMatchOver() {
|
||||||
for (MatchPlayer player: players) {
|
for (MatchPlayer player: players) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue