Added possibility to show tournament panel and watch tournament games (if allowed at tournament start) for spectators .

This commit is contained in:
LevelX2 2013-07-16 17:39:02 +02:00
parent 001f8ec1e6
commit 9838dea551
24 changed files with 520 additions and 311 deletions

View file

@ -594,6 +594,13 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
public void showTournament(UUID tournamentId) {
try {
for(Component component :desktopPane.getComponents()) {
if (component instanceof TournamentPane &&
((TournamentPane) component).getTournamentId().equals(tournamentId)) {
setActive((TournamentPane) component);
return;
}
}
TournamentPane tournamentPane = new TournamentPane();
desktopPane.add(tournamentPane, JLayeredPane.DEFAULT_LAYER);
tournamentPane.setMaximum(true);

View file

@ -24,7 +24,17 @@
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="1" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnNumPlayers" min="-2" pref="45" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlDraftOptions" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="cbAllowSpectators" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" pref="9" max="-2" attributes="0"/>
</Group>
<Component id="jPanel1" alignment="0" max="32767" attributes="0"/>
<Component id="pnlPacks" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0">
@ -33,50 +43,47 @@
<EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnNumPlayers" min="-2" pref="45" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="pnlDraftOptions" min="-2" max="-2" attributes="0"/>
</Group>
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Group type="103" groupAlignment="1" max="-2" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lblName" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtName" min="-2" pref="233" max="-2" attributes="0"/>
<Component id="txtName" min="-2" pref="205" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lbTimeLimit" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbTimeLimit" pref="115" max="32767" attributes="1"/>
<Component id="cbTimeLimit" max="32767" attributes="1"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbTournamentType" max="32767" attributes="0"/>
<Component id="cbTournamentType" min="-2" pref="295" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="lblConstructionTime" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="lblConstructionTime" min="-2" pref="141" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="spnConstructTime" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Component id="lblFreeMulligans" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnFreeMulligans" min="-2" pref="40" max="-2" attributes="0"/>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="spnFreeMulligans" min="-2" pref="41" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="lblNumWins" min="-2" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
<Component id="spnNumWins" min="-2" pref="41" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnNumWins" min="-2" pref="50" max="-2" attributes="0"/>
</Group>
</Group>
</Group>
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
</Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
</Group>
@ -106,14 +113,23 @@
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="pnlPacks" pref="66" max="32767" attributes="0"/>
<Component id="pnlPacks" pref="67" max="32767" attributes="0"/>
<EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0">
<Component id="spnNumPlayers" alignment="0" pref="29" max="32767" attributes="1"/>
<Component id="pnlDraftOptions" max="32767" attributes="1"/>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="21" max="32767" attributes="0"/>
</Group>
<Group type="102" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="spnNumPlayers" pref="23" max="32767" attributes="1"/>
<Component id="pnlDraftOptions" max="32767" attributes="1"/>
</Group>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
@ -121,6 +137,12 @@
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
<Group type="102" attributes="0">
<Component id="cbAllowSpectators" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
</Group>
</Group>
</Group>
</DimensionLayout>
</Layout>
@ -201,6 +223,55 @@
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumPlayersStateChanged"/>
</Events>
</Component>
<Container class="javax.swing.JPanel" name="pnlDraftOptions">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel6" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbDraftTiming" min="-2" pref="107" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel6" min="-2" max="-2" attributes="0"/>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group>
<Component id="cbDraftTiming" alignment="0" max="32767" attributes="1"/>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="text" type="java.lang.String" value="Timing:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbDraftTiming">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
<Component class="javax.swing.JCheckBox" name="cbAllowSpectators">
<Properties>
<Property name="text" type="java.lang.String" value="Allow spectators"/>
</Properties>
</Component>
<Component class="javax.swing.JButton" name="btnOk">
<Properties>
<Property name="text" type="java.lang.String" value="OK"/>
@ -223,20 +294,15 @@
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0">
<Component id="pnlOtherPlayers" alignment="0" max="32767" attributes="0"/>
<Group type="102" alignment="0" attributes="0">
<Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<EmptySpace pref="483" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
<Group type="102" alignment="0" attributes="0">
<Group type="102" attributes="0">
<Component id="jLabel4" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="txtPlayer1Name" max="32767" attributes="0"/>
</Group>
</Group>
<EmptySpace min="-2" max="-2" attributes="0"/>
</Group>
<Component id="pnlOtherPlayers" alignment="0" max="32767" attributes="0"/>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
@ -291,48 +357,5 @@
<Property name="text" type="java.lang.String" value="Packs"/>
</Properties>
</Component>
<Container class="javax.swing.JPanel" name="pnlDraftOptions">
<Layout>
<DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0">
<EmptySpace max="-2" attributes="0"/>
<Component id="jLabel6" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="cbDraftTiming" min="-2" pref="107" max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
<DimensionLayout dim="1">
<Group type="103" groupAlignment="0" attributes="0">
<Group type="103" alignment="0" groupAlignment="3" attributes="0">
<Component id="cbDraftTiming" alignment="3" max="32767" attributes="1"/>
<Component id="jLabel6" alignment="3" min="-2" max="-2" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
</Layout>
<SubComponents>
<Component class="javax.swing.JLabel" name="jLabel6">
<Properties>
<Property name="text" type="java.lang.String" value="Timing:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="cbDraftTiming">
<Properties>
<Property name="model" type="javax.swing.ComboBoxModel" editor="org.netbeans.modules.form.editors2.ComboBoxModelEditor">
<StringArray count="4">
<StringItem index="0" value="Item 1"/>
<StringItem index="1" value="Item 2"/>
<StringItem index="2" value="Item 3"/>
<StringItem index="3" value="Item 4"/>
</StringArray>
</Property>
</Properties>
</Component>
</SubComponents>
</Container>
</SubComponents>
</Form>

View file

@ -91,6 +91,7 @@ public class NewTournamentDialog extends MageDialog {
cbTournamentType.setModel(new DefaultComboBoxModel(session.getTournamentTypes().toArray()));
cbTimeLimit.setModel(new DefaultComboBoxModel(MatchTimeLimit.values()));
cbDraftTiming.setModel(new DefaultComboBoxModel(DraftOptions.TimingOption.values()));
cbAllowSpectators.setSelected(true);
this.setModal(true);
setTournamentOptions();
this.setLocation(150, 100);
@ -121,6 +122,10 @@ public class NewTournamentDialog extends MageDialog {
pnlPacks = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
spnNumPlayers = new javax.swing.JSpinner();
pnlDraftOptions = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
cbDraftTiming = new javax.swing.JComboBox();
cbAllowSpectators = new javax.swing.JCheckBox();
btnOk = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
@ -129,9 +134,6 @@ public class NewTournamentDialog extends MageDialog {
txtPlayer1Name = new javax.swing.JTextField();
pnlOtherPlayers = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
pnlDraftOptions = new javax.swing.JPanel();
jLabel6 = new javax.swing.JLabel();
cbDraftTiming = new javax.swing.JComboBox();
setTitle("New Tournament");
@ -170,6 +172,31 @@ public class NewTournamentDialog extends MageDialog {
}
});
jLabel6.setText("Timing:");
cbDraftTiming.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
javax.swing.GroupLayout pnlDraftOptionsLayout = new javax.swing.GroupLayout(pnlDraftOptions);
pnlDraftOptions.setLayout(pnlDraftOptionsLayout);
pnlDraftOptionsLayout.setHorizontalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbDraftTiming, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pnlDraftOptionsLayout.setVerticalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createSequentialGroup()
.addComponent(jLabel6)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(cbDraftTiming)
);
cbAllowSpectators.setText("Allow spectators");
btnOk.setText("OK");
btnOk.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -198,16 +225,13 @@ public class NewTournamentDialog extends MageDialog {
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 483, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtPlayer1Name)))
.addContainerGap())
.addComponent(txtPlayer1Name))
.addComponent(pnlOtherPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -224,79 +248,61 @@ public class NewTournamentDialog extends MageDialog {
jLabel5.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
jLabel5.setText("Packs");
jLabel6.setText("Timing:");
cbDraftTiming.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
javax.swing.GroupLayout pnlDraftOptionsLayout = new javax.swing.GroupLayout(pnlDraftOptions);
pnlDraftOptions.setLayout(pnlDraftOptionsLayout);
pnlDraftOptionsLayout.setHorizontalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel6)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbDraftTiming, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pnlDraftOptionsLayout.setVerticalGroup(
pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(pnlDraftOptionsLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cbDraftTiming)
.addComponent(jLabel6))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cbAllowSpectators)
.addGap(9, 9, 9))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(pnlPacks, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(btnOk)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(lblName)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbTimeLimit)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbTimeLimit, 0, 115, Short.MAX_VALUE))
.addComponent(cbTimeLimit, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cbTournamentType, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(cbTournamentType, javax.swing.GroupLayout.PREFERRED_SIZE, 295, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblConstructionTime)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnConstructTime, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(lblConstructionTime, javax.swing.GroupLayout.PREFERRED_SIZE, 141, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(spnConstructTime, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lblFreeMulligans)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnFreeMulligans, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(spnFreeMulligans, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblNumWins)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE))))))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(spnNumWins, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))))
.addComponent(jLabel5))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
@ -321,18 +327,27 @@ public class NewTournamentDialog extends MageDialog {
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)
.addComponent(pnlPacks, javax.swing.GroupLayout.DEFAULT_SIZE, 67, Short.MAX_VALUE)
.addGap(11, 11, 11)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 25, Short.MAX_VALUE)
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 21, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(spnNumPlayers, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
.addComponent(pnlDraftOptions, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(14, 14, 14)))
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnOk)
.addComponent(btnCancel)))
.addGroup(layout.createSequentialGroup()
.addComponent(cbAllowSpectators)
.addGap(0, 0, Short.MAX_VALUE))))
);
pack();
@ -347,6 +362,7 @@ public class NewTournamentDialog extends MageDialog {
TournamentOptions tOptions = new TournamentOptions(this.txtName.getText());
tOptions.setTournamentType(tournamentType.getName());
tOptions.getPlayerTypes().add("Human");
tOptions.setWatchingAllowed(cbAllowSpectators.isSelected());
for (TournamentPlayerPanel player: players) {
tOptions.getPlayerTypes().add((String) player.getPlayerType().getSelectedItem());
}
@ -520,6 +536,7 @@ public class NewTournamentDialog extends MageDialog {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btnOk;
private javax.swing.JCheckBox cbAllowSpectators;
private javax.swing.JComboBox cbDraftTiming;
private javax.swing.JComboBox cbTimeLimit;
private javax.swing.JComboBox cbTournamentType;

View file

@ -28,6 +28,9 @@
package mage.client.remote;
import java.util.UUID;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import mage.Constants;
import mage.cards.decks.Deck;
import mage.client.MageFrame;
@ -42,11 +45,16 @@ import mage.client.util.object.SaveObjectUtil;
import mage.interfaces.callback.CallbackClient;
import mage.interfaces.callback.ClientCallback;
import mage.utils.CompressUtil;
import mage.view.*;
import mage.view.AbilityPickerView;
import mage.view.ChatMessage;
import mage.view.DeckView;
import mage.view.DraftClientMessage;
import mage.view.DraftView;
import mage.view.GameClientMessage;
import mage.view.GameView;
import mage.view.TableClientMessage;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.util.UUID;
/**
*
@ -93,12 +101,15 @@ public class CallbackClientImpl implements CallbackClient {
else if (callback.getMethod().equals("replayGame")) {
replayGame(callback.getObjectId());
}
else if (callback.getMethod().equals("showTournament")) {
showTournament((UUID) callback.getObjectId());
}
else if (callback.getMethod().equals("watchGame")) {
watchGame((UUID) callback.getObjectId());
}
else if (callback.getMethod().equals("chatMessage")) {
ChatMessage message = (ChatMessage) callback.getData();
ChatPanel panel = frame.getChat(callback.getObjectId());
ChatPanel panel = MageFrame.getChat(callback.getObjectId());
if (panel != null) {
if (message.getMessage().equals(Constants.MSG_TIP_HOT_KEYS_CODE) && panel.getConnectedChat() != null) {
panel.getConnectedChat().receiveMessage("[Tips] ", "You may use hot keys to play faster: " + "" +
@ -128,29 +139,31 @@ public class CallbackClientImpl implements CallbackClient {
joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
}
else if (callback.getMethod().equals("replayInit")) {
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.init((GameView) callback.getData());
}
}
else if (callback.getMethod().equals("replayDone")) {
GamePanel panel = frame.getGame(callback.getObjectId());
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.endMessage((String) callback.getData());
}
}
else if (callback.getMethod().equals("replayUpdate")) {
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.updateGame((GameView) callback.getData());
}
}
else if (callback.getMethod().equals("gameInit")) {
GamePanel panel = frame.getGame(callback.getObjectId());
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.init((GameView) callback.getData());
}
}
else if (callback.getMethod().equals("gameOver")) {
GamePanel panel = frame.getGame(callback.getObjectId());
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.endMessage((String) callback.getData());
}
@ -160,77 +173,88 @@ public class CallbackClientImpl implements CallbackClient {
}
else if (callback.getMethod().equals("gameAsk")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.ask(message.getMessage(), message.getGameView());
}
}
else if (callback.getMethod().equals("gameTarget")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.pickTarget(message.getMessage(), message.getCardsView(), message.getGameView(), message.getTargets(), message.isFlag(), message.getOptions());
}
}
else if (callback.getMethod().equals("gameSelect")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.select(message.getMessage(), message.getGameView());
}
}
else if (callback.getMethod().equals("gameChooseAbility")) {
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.pickAbility((AbilityPickerView) callback.getData());
}
}
else if (callback.getMethod().equals("gameChoosePile")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.pickPile(message.getMessage(), message.getPile1(), message.getPile2());
}
}
else if (callback.getMethod().equals("gameChoose")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.getChoice(message.getMessage(), message.getStrings());
}
}
else if (callback.getMethod().equals("gamePlayMana")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.playMana(message.getMessage(), message.getGameView());
}
}
else if (callback.getMethod().equals("gamePlayXMana")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.playXMana(message.getMessage(), message.getGameView());
}
}
else if (callback.getMethod().equals("gameSelectAmount")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.getAmount(message.getMin(), message.getMax(), message.getMessage());
}
}
else if (callback.getMethod().equals("gameUpdate")) {
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.updateGame((GameView) callback.getData());
}
}
else if (callback.getMethod().equals("gameInform")) {
if (callback.getMessageId() > messageId) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null)
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
panel.inform(message.getMessage(), message.getGameView());
}
}
else {
logger.warn("message out of sequence - ignoring");
}
}
else if (callback.getMethod().equals("gameInformPersonal")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) {
JOptionPane.showMessageDialog(panel, message.getMessage(), "Game message",
JOptionPane.INFORMATION_MESSAGE);
@ -240,11 +264,13 @@ public class CallbackClientImpl implements CallbackClient {
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();
Deck deck = DeckUtil.construct(deckView);
if (message.getFlag())
if (message.getFlag()) {
construct(deck, message.getTableId(), message.getTime());
else
}
else {
sideboard(deck, message.getTableId(), message.getTime());
}
}
else if (callback.getMethod().equals("construct")) {
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();
@ -252,21 +278,24 @@ public class CallbackClientImpl implements CallbackClient {
construct(deck, message.getTableId(), message.getTime());
}
else if (callback.getMethod().equals("draftOver")) {
DraftPanel panel = frame.getDraft(callback.getObjectId());
if (panel != null)
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) {
panel.hideDraft();
}
}
else if (callback.getMethod().equals("draftPick")) {
DraftClientMessage message = (DraftClientMessage) callback.getData();
DraftPanel panel = frame.getDraft(callback.getObjectId());
if (panel != null)
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) {
panel.loadBooster(message.getDraftPickView());
}
}
else if (callback.getMethod().equals("draftUpdate")) {
DraftPanel panel = frame.getDraft(callback.getObjectId());
if (panel != null)
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) {
panel.updateDraft((DraftView) callback.getData());
}
}
else if (callback.getMethod().equals("draftInform")) {
if (callback.getMessageId() > messageId) {
DraftClientMessage message = (DraftClientMessage) callback.getData();
@ -277,10 +306,11 @@ public class CallbackClientImpl implements CallbackClient {
}
else if (callback.getMethod().equals("draftInit")) {
DraftClientMessage message = (DraftClientMessage) callback.getData();
DraftPanel panel = frame.getDraft(callback.getObjectId());
if (panel != null)
DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) {
panel.loadBooster(message.getDraftPickView());
}
}
else if (callback.getMethod().equals("tournamentInit")) {
}
@ -340,6 +370,21 @@ public class CallbackClientImpl implements CallbackClient {
}
}
/**
* Shows the tournament info panel for a tournament
*
* @param tournamentId
*/
protected void showTournament(UUID tournamentId) {
try {
frame.showTournament(tournamentId);
logger.info("Showing tournament " + tournamentId);
}
catch (Exception ex) {
handleException(ex);
}
}
protected void watchGame(UUID gameId) {
try {
frame.watchGame(gameId);
@ -349,7 +394,6 @@ public class CallbackClientImpl implements CallbackClient {
handleException(ex);
}
}
protected void replayGame(UUID gameId) {
try {
frame.replayGame(gameId);

View file

@ -59,6 +59,7 @@ import mage.client.dialog.TableWaitingDialog;
import mage.client.util.ButtonColumn;
import mage.client.util.gui.GuiDisplayUtil;
import mage.constants.MatchTimeLimit;
import static mage.constants.TableState.DUELING;
import mage.game.match.MatchOptions;
import mage.remote.MageRemoteException;
import mage.remote.Session;
@ -123,11 +124,11 @@ public class TablesPanel extends javax.swing.JPanel {
int modelRow = Integer.valueOf( e.getActionCommand() );
UUID tableId = (UUID)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 3);
UUID gameId = (UUID)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 2);
String state = (String)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN);
String action = (String)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN);
boolean isTournament = (Boolean)tableModel.getValueAt(modelRow, TableTableModel.ACTION_COLUMN + 1);
String owner = (String)tableModel.getValueAt(modelRow, 1);
if (state.equals("Join")) {
if (action.equals("Join")) {
if (owner.equals(session.getUserName())) {
try {
JDesktopPane desktopPane = (JDesktopPane)MageFrame.getUI().getComponent(MageComponents.DESKTOP_PANE);
@ -158,16 +159,21 @@ public class TablesPanel extends javax.swing.JPanel {
logger.info("Joining table " + tableId);
joinTableDialog.showDialog(roomId, tableId);
}
} else if (state.equals("Remove")) {
} else if (action.equals("Remove")) {
if (JOptionPane.showConfirmDialog(null, "Are you sure you want to remove table?", "Removing table", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
session.removeTable(roomId, tableId);
}
} else if (state.equals("Watch")) {
} else if (action.equals("Show")) {
if (isTournament) {
logger.info("Showing tournament table " + tableId);
session.watchTable(roomId, tableId);
}
} else if (action.equals("Watch")) {
if (!isTournament) {
logger.info("Watching table " + tableId);
session.watchTable(roomId, tableId);
}
} else if (state.equals("Replay")) {
} else if (action.equals("Replay")) {
logger.info("Replaying game " + gameId);
// no replay because of memory leaks
// session.replayGame(gameId);
@ -181,6 +187,7 @@ public class TablesPanel extends javax.swing.JPanel {
public void actionPerformed(ActionEvent e)
{
int modelRow = Integer.valueOf( e.getActionCommand() );
if (matchesModel.getValueAt(modelRow, MatchesTableModel.ACTION_COLUMN) instanceof List) {
List<UUID> games = (List<UUID>)matchesModel.getValueAt(modelRow, MatchesTableModel.ACTION_COLUMN);
if (games.size() == 1) {
session.replayGame(games.get(0));
@ -189,6 +196,9 @@ public class TablesPanel extends javax.swing.JPanel {
gameChooser.show(games, MageFrame.getDesktop().getMousePosition());
}
}
// MageFrame.getDesktop().showTournament(tournamentId);
}
};
@ -655,29 +665,27 @@ class TableTableModel extends AbstractTableModel {
return timeFormatter.format(tables[arg0].getCreateTime());
case 9:
switch (tables[arg0].getTableState()) {
case WAITING:
String owner = tables[arg0].getControllerName();
if (session != null && owner.equals(session.getUserName())) {
return "Remove";
}
return "Join";
case CONSTRUCTING:
if (tables[arg0].isTournament()) {
return "Show";
}
case DUELING:
if (tables[arg0].isTournament()) {
return "Show";
} else {
owner = tables[arg0].getControllerName();
if (session != null && owner.equals(session.getUserName())) {
return "Remove";
}
if (tables[arg0].isTournament()) {
return "None";
} else {
return "Watch";
}
case FINISHED:
owner = tables[arg0].getControllerName();
if (session != null && owner.equals(session.getUserName())) {
return "Remove";
}
return "None";
default:
return "";
}

View file

@ -58,6 +58,13 @@ public class TournamentPane extends MagePane {
tournamentPanel.hideTournament();
}
public UUID getTournamentId() {
if (this.tournamentPanel == null) {
return null;
}
return tournamentPanel.getTournamentId();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is

View file

@ -155,7 +155,7 @@
<Component class="javax.swing.JButton" name="btnCloseWindow">
<Properties>
<Property name="text" type="java.lang.String" value="Close Window"/>
<Property name="horizontalAlignment" type="int" value="4"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnCloseWindowActionPerformed"/>

View file

@ -63,11 +63,11 @@ public class TournamentPanel extends javax.swing.JPanel {
private static final Logger logger = Logger.getLogger(TournamentPanel.class);
private UUID tournamentId;
private boolean firstInitDone = false;
private Session session;
private TournamentPlayersTableModel playersModel;
private TournamentMatchesTableModel matchesModel;
private UpdateTournamentTask updateTask;
private boolean titleSet = false;
private DateFormat df;
/** Creates new form TournamentPanel */
@ -92,10 +92,15 @@ public class TournamentPanel extends javax.swing.JPanel {
int modelRow = Integer.valueOf( e.getActionCommand() );
UUID gameId = UUID.fromString((String)tableMatches.getValueAt(modelRow, 3));
String state = (String)tableMatches.getValueAt(modelRow, 4);
if (state.equals("Finished")) {
logger.info("Replaying game " + gameId);
session.replayGame(gameId);
String actionText = (String)tableMatches.getValueAt(modelRow, 6);
UUID tableId = UUID.fromString((String)matchesModel.getValueAt(modelRow, 7));
// if (state.equals("Finished") && action.equals("Replay")) {
// logger.info("Replaying game " + gameId);
// session.replayGame(gameId);
// }
if (state.equals("Dueling") && actionText.equals("Watch")) {
logger.info("Watching game " + gameId);
session.watchTournamentTable(tableId);
}
}
};
@ -121,6 +126,10 @@ public class TournamentPanel extends javax.swing.JPanel {
}
}
public UUID getTournamentId() {
return tournamentId;
}
public void hideTournament() {
stopTasks();
this.chatPanel1.disconnect();
@ -135,7 +144,7 @@ public class TournamentPanel extends javax.swing.JPanel {
public void update(TournamentView tournament) {
if (!titleSet) {
if (!firstInitDone) {
Component c = this.getParent();
while (c != null && !(c instanceof TournamentPane)) {
c = c.getParent();
@ -143,20 +152,17 @@ public class TournamentPanel extends javax.swing.JPanel {
if (c != null) {
((TournamentPane)c).setTitle("Tournament [" + tournament.getTournamentName() +"]");
}
titleSet = true;
}
txtName.setText(tournament.getTournamentName());
txtType.setText(tournament.getTournamentType());
txtStartTime.setText(df.format(tournament.getStartTime()));
if (tournament.getEndTime() != null) {
txtEndTime.setText(df.format(tournament.getEndTime()));
btnCloseWindow.setVisible(true);
} else {
txtEndTime.setText("running...");
btnCloseWindow.setVisible(false);
firstInitDone = true;
}
if (txtEndTime.getText().equals("running...") && tournament.getEndTime() != null) {
txtEndTime.setText(df.format(tournament.getEndTime()));
}
playersModel.loadData(tournament);
@ -241,7 +247,7 @@ public class TournamentPanel extends javax.swing.JPanel {
txtEndTime.setFocusable(false);
btnCloseWindow.setText("Close Window");
btnCloseWindow.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
btnCloseWindow.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnCloseWindow.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCloseWindowActionPerformed(evt);
@ -331,7 +337,7 @@ public class TournamentPanel extends javax.swing.JPanel {
.addGroup(layout.createSequentialGroup()
.addComponent(actionPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 489, Short.MAX_VALUE))
.addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
@ -422,9 +428,11 @@ class TournamentPlayersTableModel extends AbstractTableModel {
class TournamentMatchesTableModel extends AbstractTableModel {
private String[] columnNames = new String[]{"Round Number", "Players", "Match Id", "Game Id", "State", "Result", "Action"};
private TournamentGameView[] games = new TournamentGameView[0];
private boolean watchingAllowed;
public void loadData(TournamentView tournament) {
List<TournamentGameView> views = new ArrayList<TournamentGameView>();
watchingAllowed = tournament.isWatchingAllowed();
for (RoundView round: tournament.getRounds()) {
for (TournamentGameView game: round.getGames()) {
views.add(game);
@ -460,10 +468,15 @@ class TournamentMatchesTableModel extends AbstractTableModel {
case 5:
return games[arg0].getResult();
case 6:
if (games[arg0].getState().equals("Finished")) {
return "Replay";
// if (games[arg0].getState().equals("Finished")) {
// return "Replay";
// }
if (watchingAllowed && games[arg0].getState().equals("Dueling")) {
return "Watch";
}
return "";
case 7:
return games[arg0].getTableId().toString();
}
return "";
}

View file

@ -77,6 +77,7 @@ public interface MageServer {
boolean submitDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
void updateDeck(String sessionId, UUID tableId, DeckCardLists deckList) throws MageException, GameException;
boolean watchTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
boolean watchTournamentTable(String sessionId, UUID tableId) throws MageException;
void leaveTable(String sessionId, UUID roomId, UUID tableId) throws MageException;
void swapSeats(String sessionId, UUID roomId, UUID tableId, int seatNum1, int seatNum2) throws MageException;
void removeTable(String sessionId, UUID roomId, UUID tableId) throws MageException;

View file

@ -406,6 +406,21 @@ public class SessionImpl implements Session {
return false;
}
@Override
public boolean watchTournamentTable(UUID tableId) {
try {
if (isConnected()) {
server.watchTournamentTable(sessionId, tableId);
return true;
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {
handleThrowable(t);
}
return false;
}
@Override
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) {
try {

View file

@ -67,6 +67,8 @@ public interface PlayerActions {
boolean watchTable(UUID roomId, UUID tableId);
boolean watchTournamentTable(UUID tableId);
boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList);
TableView getTable(UUID roomId, UUID tableId);

View file

@ -47,6 +47,7 @@ public class TournamentGameView implements Serializable {
private String state;
private String result;
private String players;
private UUID tableId;
TournamentGameView(int roundNum, TournamentPairing pair, Game game) {
this.roundNum = roundNum;
@ -61,6 +62,7 @@ public class TournamentGameView implements Serializable {
this.state = "Dueling";
this.result = "";
}
this.tableId = pair.getTableId();
}
public int getRoundNum() {
@ -86,4 +88,9 @@ public class TournamentGameView implements Serializable {
public String getPlayers() {
return this.players;
}
public UUID getTableId() {
return tableId;
}
}

View file

@ -49,6 +49,7 @@ public class TournamentView implements Serializable {
private Date startTime;
private Date endTime;
private boolean watchingAllowed;
private List<RoundView> rounds = new ArrayList<RoundView>();
private List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>();
@ -59,6 +60,7 @@ public class TournamentView implements Serializable {
tournamentType = tournament.getOptions().getTournamentType();
startTime = tournament.getStartTime();
endTime = tournament.getEndTime();
watchingAllowed = tournament.getOptions().isWatchingAllowed();
for (TournamentPlayer player: tournament.getPlayers()) {
players.add(new TournamentPlayerView(player));
@ -77,11 +79,18 @@ public class TournamentView implements Serializable {
}
public Date getStartTime() {
return startTime;
return new Date(startTime.getTime());
}
public Date getEndTime() {
return endTime;
if (endTime == null) {
return null;
}
return new Date(endTime.getTime());
}
public boolean isWatchingAllowed() {
return watchingAllowed;
}
public List<TournamentPlayerView> getPlayers() {

View file

@ -1439,10 +1439,13 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
rememberPick(card, RateCard.rateCard(card, null));
}
chosenColors = chooseDeckColorsIfPossible();
log.warn(this.getName() + " after choose Deck Colors.");
}
deck = buildDeck(new ArrayList<Card>(deck.getSideboard()), chosenColors);
log.warn(this.getName() + " after build deck.");
}
tournament.submitDeck(playerId, deck);
log.warn(this.getName() + " after submit deck.");
}
public Card pickBestCard(List<Card> cards, List<ColoredManaSymbol> chosenColors) {
@ -1599,6 +1602,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
* 3. get card colors as chosen starting from most rated card
*/
protected List<ColoredManaSymbol> chooseDeckColorsIfPossible() {
log.warn(this.getName() + " choose Deck Colors.");
if (pickedCards.size() > 2) {
// sort by score and color mana symbol count in descending order
Collections.sort(pickedCards, new Comparator<PickedCard>() {

View file

@ -640,6 +640,17 @@ public class MageServerImpl implements MageServer {
});
}
@Override
public boolean watchTournamentTable(final String sessionId, final UUID tableId) throws MageException {
return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() {
@Override
public Boolean execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
return TableManager.getInstance().watchTable(userId, tableId);
}
});
}
@Override
public void watchGame(final UUID gameId, final String sessionId) throws MageException {
execute("watchGame", sessionId, new Action() {

View file

@ -257,6 +257,13 @@ public class TableController {
}
public boolean watchTable(UUID userId) {
if (table.isTournament()) {
UserManager.getInstance().getUser(userId).showTournament(table.getTournament().getId());
return true;
} else {
if (table.isTournamentSubTable() && !table.getTournament().getOptions().isWatchingAllowed()) {
return false;
}
if (table.getState() != TableState.DUELING) {
return false;
}
@ -266,6 +273,8 @@ public class TableController {
}
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
return true;
}
}
public boolean replayTable(UUID userId) {
@ -464,7 +473,6 @@ public class TableController {
public void endGame() {
// get player that chooses who goes first
UUID choosingPlayerId = match.getChooser();
logger.warn("endGame() " + match.getPlayers().toString());
match.endGame();
table.endGame();
// Saving of games caused memory leaks - so save is deactivated

View file

@ -305,7 +305,7 @@ public class TableManager {
List<UUID> toRemove = new ArrayList<UUID>();
for (Table table : tables.values()) {
if (!table.getState().equals(TableState.FINISHED)) {
// remove all tables created more than expire_time ago
// remove all not finished tables created more than expire_time ago
long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
if (diff >= EXPIRE_TIME) {
logger.info("Table expired: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing...");
@ -319,8 +319,8 @@ public class TableManager {
if (player != null && player.isHuman()) {
canBeRemoved = false;
}
// tournament sub tables may not be removed, will be done by the tournament itself
if(table.isTournamentSubTable()){
// tournament sub tables may not be removed as long the tournament is not finished
if(table.isTournamentSubTable() && table.getTournament().getEndTime() == null) {
canBeRemoved = false;
}
}

View file

@ -156,6 +156,10 @@ public class User {
fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time)));
}
public void showTournament(final UUID tournamentId) {
fireCallback(new ClientCallback("showTournament", tournamentId));
}
public void watchGame(final UUID gameId) {
fireCallback(new ClientCallback("watchGame", gameId));
}

View file

@ -309,6 +309,10 @@ public class GameController implements GameCallback {
}
public void watch(UUID userId) {
if (userPlayerMap.get(userId) != null) {
// You can't watch a game if you already a player in it
return;
}
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
GameWatcher gameWatcher = new GameWatcher(userId, game);

View file

@ -197,12 +197,14 @@ public class TournamentController {
TableManager tableManager = TableManager.getInstance();
Table table = tableManager.createTable(GamesRoomManager.getInstance().getMainRoomId(), matchOptions);
table.setTournamentSubTable(true);
table.setTournament(tournament);
TournamentPlayer player1 = pair.getPlayer1();
TournamentPlayer player2 = pair.getPlayer2();
tableManager.addPlayer(getPlayerSessionId(player1.getPlayer().getId()), table.getId(), player1.getPlayer(), player1.getPlayerType(), player1.getDeck());
tableManager.addPlayer(getPlayerSessionId(player2.getPlayer().getId()), table.getId(), player2.getPlayer(), player2.getPlayerType(), player2.getDeck());
tableManager.startMatch(null, table.getId());
pair.setMatch(tableManager.getMatch(table.getId()));
pair.setTableId(table.getId());
player1.setState(TournamentPlayerState.DUELING);
player2.setState(TournamentPlayerState.DUELING);
} catch (GameException ex) {

View file

@ -138,7 +138,7 @@ public class Table implements Serializable {
}
public Date getCreateTime() {
return createTime;
return new Date(createTime.getTime());
}
public boolean isTournament() {
@ -223,6 +223,10 @@ public class Table implements Serializable {
return tournament;
}
public void setTournament(Tournament tournament) {
this.tournament = tournament;
}
public String getControllerName() {
return controllerName;
}

View file

@ -33,7 +33,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.cards.decks.Deck;
import mage.constants.TournamentPlayerState;
import mage.game.events.*;
import mage.game.events.TableEvent.EventType;
import mage.game.match.Match;
@ -309,12 +308,15 @@ public abstract class TournamentImpl implements Tournament {
@Override
public Date getStartTime() {
return startTime;
return new Date(startTime.getTime());
}
@Override
public Date getEndTime() {
return endTime;
if (endTime == null) {
return null;
}
return new Date(endTime.getTime());
}
}

View file

@ -39,12 +39,12 @@ import mage.game.match.MatchOptions;
*/
public class TournamentOptions implements Serializable {
protected String name;
protected String tournamentType;
protected List<String> playerTypes = new ArrayList<String>();
protected MatchOptions matchOptions = new MatchOptions("", "Two Player Duel");
protected LimitedOptions limitedOptions;
protected boolean watchingAllowed = true;
public TournamentOptions(String name) {
this.name = name;
@ -78,4 +78,12 @@ public class TournamentOptions implements Serializable {
return limitedOptions;
}
public boolean isWatchingAllowed() {
return watchingAllowed;
}
public void setWatchingAllowed(boolean watchingAllowed) {
this.watchingAllowed = watchingAllowed;
}
}

View file

@ -28,9 +28,8 @@
package mage.game.tournament;
import mage.game.match.Match;
import java.util.UUID;
import mage.game.match.Match;
/**
*
@ -38,10 +37,11 @@ import java.util.UUID;
*/
public class TournamentPairing {
UUID id = UUID.randomUUID();
Match match;
TournamentPlayer player1;
TournamentPlayer player2;
private UUID id = UUID.randomUUID();
private UUID tableId;
private Match match;
private TournamentPlayer player1;
private TournamentPlayer player2;
public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) {
this.player1 = player1;
@ -86,4 +86,13 @@ public class TournamentPairing {
player2.setEliminated();
}
}
public UUID getTableId() {
return tableId;
}
public void setTableId(UUID tableId) {
this.tableId = tableId;
}
}