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) { public void showTournament(UUID tournamentId) {
try { try {
for(Component component :desktopPane.getComponents()) {
if (component instanceof TournamentPane &&
((TournamentPane) component).getTournamentId().equals(tournamentId)) {
setActive((TournamentPane) component);
return;
}
}
TournamentPane tournamentPane = new TournamentPane(); TournamentPane tournamentPane = new TournamentPane();
desktopPane.add(tournamentPane, JLayeredPane.DEFAULT_LAYER); desktopPane.add(tournamentPane, JLayeredPane.DEFAULT_LAYER);
tournamentPane.setMaximum(true); tournamentPane.setMaximum(true);

View file

@ -24,7 +24,17 @@
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<EmptySpace max="-2" 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="jPanel1" alignment="0" max="32767" attributes="0"/>
<Component id="pnlPacks" alignment="1" max="32767" attributes="0"/> <Component id="pnlPacks" alignment="1" max="32767" attributes="0"/>
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
@ -33,49 +43,46 @@
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="btnCancel" min="-2" max="-2" attributes="0"/> <Component id="btnCancel" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<Group type="102" alignment="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"/>
</Group>
<Component id="jLabel5" alignment="0" min="-2" max="-2" 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"/>
<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"/>
</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"/>
</Group>
</Group>
<EmptySpace type="unrelated" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="0" attributes="0"> <Group type="102" alignment="0" attributes="0">
<Component id="lblConstructionTime" min="-2" max="-2" 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="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" 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" min="-2" pref="295" max="-2" attributes="0"/>
</Group>
</Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="spnConstructTime" min="-2" pref="50" max="-2" attributes="0"/> <Group type="103" groupAlignment="0" attributes="0">
<EmptySpace min="0" pref="0" max="32767" attributes="0"/> <Group type="102" attributes="0">
</Group> <Component id="lblConstructionTime" min="-2" pref="141" max="-2" attributes="0"/>
<Group type="102" alignment="0" attributes="0"> <EmptySpace type="unrelated" max="-2" attributes="0"/>
<Component id="lblFreeMulligans" min="-2" max="-2" attributes="0"/> <Component id="spnConstructTime" min="-2" pref="50" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> </Group>
<Component id="spnFreeMulligans" min="-2" pref="40" max="-2" attributes="0"/> <Group type="102" alignment="0" attributes="0">
<EmptySpace type="unrelated" max="-2" attributes="0"/> <Component id="lblFreeMulligans" min="-2" max="-2" attributes="0"/>
<Component id="lblNumWins" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<EmptySpace max="32767" attributes="0"/> <Component id="spnFreeMulligans" min="-2" pref="41" max="-2" attributes="0"/>
<Component id="spnNumWins" min="-2" pref="41" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
<Component id="lblNumWins" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Component id="spnNumWins" min="-2" pref="50" max="-2" attributes="0"/>
</Group>
</Group>
</Group> </Group>
<Component id="jLabel5" alignment="0" min="-2" max="-2" attributes="0"/>
</Group> </Group>
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
</Group> </Group>
</Group> </Group>
<EmptySpace max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/>
@ -106,19 +113,34 @@
<EmptySpace min="-2" max="-2" attributes="0"/> <EmptySpace min="-2" max="-2" attributes="0"/>
<Component id="jLabel5" min="-2" max="-2" attributes="0"/> <Component id="jLabel5" min="-2" max="-2" attributes="0"/>
<EmptySpace 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"/> <EmptySpace min="-2" pref="11" max="-2" attributes="0"/>
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Component id="spnNumPlayers" alignment="0" pref="29" max="32767" attributes="1"/> <Group type="102" attributes="0">
<Component id="pnlDraftOptions" max="32767" attributes="1"/> <Group type="103" groupAlignment="0" attributes="0">
<Component id="jLabel2" min="-2" max="-2" attributes="0"/> <Group type="102" attributes="0">
</Group> <Component id="jLabel2" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/> <EmptySpace pref="21" max="32767" attributes="0"/>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/> </Group>
<EmptySpace max="-2" attributes="0"/> <Group type="102" attributes="0">
<Group type="103" groupAlignment="3" attributes="0"> <Group type="103" groupAlignment="1" attributes="0">
<Component id="btnOk" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="spnNumPlayers" pref="23" max="32767" attributes="1"/>
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="pnlDraftOptions" max="32767" attributes="1"/>
</Group>
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
</Group>
</Group>
<Component id="jPanel1" min="-2" max="-2" attributes="0"/>
<EmptySpace max="-2" attributes="0"/>
<Group type="103" groupAlignment="3" attributes="0">
<Component id="btnOk" alignment="3" min="-2" max="-2" attributes="0"/>
<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> </Group>
</Group> </Group>
@ -201,6 +223,55 @@
<EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumPlayersStateChanged"/> <EventHandler event="stateChanged" listener="javax.swing.event.ChangeListener" parameters="javax.swing.event.ChangeEvent" handler="spnNumPlayersStateChanged"/>
</Events> </Events>
</Component> </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"> <Component class="javax.swing.JButton" name="btnOk">
<Properties> <Properties>
<Property name="text" type="java.lang.String" value="OK"/> <Property name="text" type="java.lang.String" value="OK"/>
@ -223,20 +294,15 @@
<DimensionLayout dim="0"> <DimensionLayout dim="0">
<Group type="103" groupAlignment="0" attributes="0"> <Group type="103" groupAlignment="0" attributes="0">
<Group type="102" alignment="1" attributes="0"> <Group type="102" alignment="1" attributes="0">
<Group type="103" groupAlignment="1" attributes="0"> <Component id="jLabel3" min="-2" max="-2" attributes="0"/>
<Component id="pnlOtherPlayers" alignment="0" max="32767" attributes="0"/> <EmptySpace 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"/>
</Group>
<Group type="102" alignment="0" 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> </Group>
<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>
<Component id="pnlOtherPlayers" alignment="0" max="32767" attributes="0"/>
</Group> </Group>
</DimensionLayout> </DimensionLayout>
<DimensionLayout dim="1"> <DimensionLayout dim="1">
@ -291,48 +357,5 @@
<Property name="text" type="java.lang.String" value="Packs"/> <Property name="text" type="java.lang.String" value="Packs"/>
</Properties> </Properties>
</Component> </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> </SubComponents>
</Form> </Form>

View file

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

View file

@ -28,6 +28,9 @@
package mage.client.remote; package mage.client.remote;
import java.util.UUID;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import mage.Constants; import mage.Constants;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.client.MageFrame; import mage.client.MageFrame;
@ -42,11 +45,16 @@ import mage.client.util.object.SaveObjectUtil;
import mage.interfaces.callback.CallbackClient; import mage.interfaces.callback.CallbackClient;
import mage.interfaces.callback.ClientCallback; import mage.interfaces.callback.ClientCallback;
import mage.utils.CompressUtil; 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 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")) { else if (callback.getMethod().equals("replayGame")) {
replayGame(callback.getObjectId()); replayGame(callback.getObjectId());
} }
else if (callback.getMethod().equals("showTournament")) {
showTournament((UUID) callback.getObjectId());
}
else if (callback.getMethod().equals("watchGame")) { else if (callback.getMethod().equals("watchGame")) {
watchGame((UUID) callback.getObjectId()); watchGame((UUID) callback.getObjectId());
} }
else if (callback.getMethod().equals("chatMessage")) { else if (callback.getMethod().equals("chatMessage")) {
ChatMessage message = (ChatMessage) callback.getData(); ChatMessage message = (ChatMessage) callback.getData();
ChatPanel panel = frame.getChat(callback.getObjectId()); ChatPanel panel = MageFrame.getChat(callback.getObjectId());
if (panel != null) { if (panel != null) {
if (message.getMessage().equals(Constants.MSG_TIP_HOT_KEYS_CODE) && panel.getConnectedChat() != 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: " + "" + 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()); joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
} }
else if (callback.getMethod().equals("replayInit")) { else if (callback.getMethod().equals("replayInit")) {
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.init((GameView) callback.getData()); panel.init((GameView) callback.getData());
}
} }
else if (callback.getMethod().equals("replayDone")) { else if (callback.getMethod().equals("replayDone")) {
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) { if (panel != null) {
panel.endMessage((String) callback.getData()); panel.endMessage((String) callback.getData());
} }
} }
else if (callback.getMethod().equals("replayUpdate")) { else if (callback.getMethod().equals("replayUpdate")) {
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.updateGame((GameView) callback.getData()); panel.updateGame((GameView) callback.getData());
}
} }
else if (callback.getMethod().equals("gameInit")) { else if (callback.getMethod().equals("gameInit")) {
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) { if (panel != null) {
panel.init((GameView) callback.getData()); panel.init((GameView) callback.getData());
} }
} }
else if (callback.getMethod().equals("gameOver")) { else if (callback.getMethod().equals("gameOver")) {
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) { if (panel != null) {
panel.endMessage((String) callback.getData()); panel.endMessage((String) callback.getData());
} }
@ -160,69 +173,80 @@ public class CallbackClientImpl implements CallbackClient {
} }
else if (callback.getMethod().equals("gameAsk")) { else if (callback.getMethod().equals("gameAsk")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.ask(message.getMessage(), message.getGameView()); panel.ask(message.getMessage(), message.getGameView());
}
} }
else if (callback.getMethod().equals("gameTarget")) { else if (callback.getMethod().equals("gameTarget")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.pickTarget(message.getMessage(), message.getCardsView(), message.getGameView(), message.getTargets(), message.isFlag(), message.getOptions()); panel.pickTarget(message.getMessage(), message.getCardsView(), message.getGameView(), message.getTargets(), message.isFlag(), message.getOptions());
}
} }
else if (callback.getMethod().equals("gameSelect")) { else if (callback.getMethod().equals("gameSelect")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.select(message.getMessage(), message.getGameView()); panel.select(message.getMessage(), message.getGameView());
}
} }
else if (callback.getMethod().equals("gameChooseAbility")) { else if (callback.getMethod().equals("gameChooseAbility")) {
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.pickAbility((AbilityPickerView) callback.getData()); panel.pickAbility((AbilityPickerView) callback.getData());
}
} }
else if (callback.getMethod().equals("gameChoosePile")) { else if (callback.getMethod().equals("gameChoosePile")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.pickPile(message.getMessage(), message.getPile1(), message.getPile2()); panel.pickPile(message.getMessage(), message.getPile1(), message.getPile2());
}
} }
else if (callback.getMethod().equals("gameChoose")) { else if (callback.getMethod().equals("gameChoose")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.getChoice(message.getMessage(), message.getStrings()); panel.getChoice(message.getMessage(), message.getStrings());
}
} }
else if (callback.getMethod().equals("gamePlayMana")) { else if (callback.getMethod().equals("gamePlayMana")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.playMana(message.getMessage(), message.getGameView()); panel.playMana(message.getMessage(), message.getGameView());
}
} }
else if (callback.getMethod().equals("gamePlayXMana")) { else if (callback.getMethod().equals("gamePlayXMana")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.playXMana(message.getMessage(), message.getGameView()); panel.playXMana(message.getMessage(), message.getGameView());
}
} }
else if (callback.getMethod().equals("gameSelectAmount")) { else if (callback.getMethod().equals("gameSelectAmount")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.getAmount(message.getMin(), message.getMax(), message.getMessage()); panel.getAmount(message.getMin(), message.getMax(), message.getMessage());
}
} }
else if (callback.getMethod().equals("gameUpdate")) { else if (callback.getMethod().equals("gameUpdate")) {
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.updateGame((GameView) callback.getData()); panel.updateGame((GameView) callback.getData());
}
} }
else if (callback.getMethod().equals("gameInform")) { else if (callback.getMethod().equals("gameInform")) {
if (callback.getMessageId() > messageId) { if (callback.getMessageId() > messageId) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.inform(message.getMessage(), message.getGameView()); panel.inform(message.getMessage(), message.getGameView());
}
} }
else { else {
logger.warn("message out of sequence - ignoring"); logger.warn("message out of sequence - ignoring");
@ -230,7 +254,7 @@ public class CallbackClientImpl implements CallbackClient {
} }
else if (callback.getMethod().equals("gameInformPersonal")) { else if (callback.getMethod().equals("gameInformPersonal")) {
GameClientMessage message = (GameClientMessage) callback.getData(); GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId()); GamePanel panel = MageFrame.getGame(callback.getObjectId());
if (panel != null) { if (panel != null) {
JOptionPane.showMessageDialog(panel, message.getMessage(), "Game message", JOptionPane.showMessageDialog(panel, message.getMessage(), "Game message",
JOptionPane.INFORMATION_MESSAGE); JOptionPane.INFORMATION_MESSAGE);
@ -240,10 +264,12 @@ public class CallbackClientImpl implements CallbackClient {
TableClientMessage message = (TableClientMessage) callback.getData(); TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck(); DeckView deckView = message.getDeck();
Deck deck = DeckUtil.construct(deckView); Deck deck = DeckUtil.construct(deckView);
if (message.getFlag()) if (message.getFlag()) {
construct(deck, message.getTableId(), message.getTime()); construct(deck, message.getTableId(), message.getTime());
else }
else {
sideboard(deck, message.getTableId(), message.getTime()); sideboard(deck, message.getTableId(), message.getTime());
}
} }
else if (callback.getMethod().equals("construct")) { else if (callback.getMethod().equals("construct")) {
TableClientMessage message = (TableClientMessage) callback.getData(); TableClientMessage message = (TableClientMessage) callback.getData();
@ -252,20 +278,23 @@ public class CallbackClientImpl implements CallbackClient {
construct(deck, message.getTableId(), message.getTime()); construct(deck, message.getTableId(), message.getTime());
} }
else if (callback.getMethod().equals("draftOver")) { else if (callback.getMethod().equals("draftOver")) {
DraftPanel panel = frame.getDraft(callback.getObjectId()); DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.hideDraft(); panel.hideDraft();
}
} }
else if (callback.getMethod().equals("draftPick")) { else if (callback.getMethod().equals("draftPick")) {
DraftClientMessage message = (DraftClientMessage) callback.getData(); DraftClientMessage message = (DraftClientMessage) callback.getData();
DraftPanel panel = frame.getDraft(callback.getObjectId()); DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.loadBooster(message.getDraftPickView()); panel.loadBooster(message.getDraftPickView());
}
} }
else if (callback.getMethod().equals("draftUpdate")) { else if (callback.getMethod().equals("draftUpdate")) {
DraftPanel panel = frame.getDraft(callback.getObjectId()); DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.updateDraft((DraftView) callback.getData()); panel.updateDraft((DraftView) callback.getData());
}
} }
else if (callback.getMethod().equals("draftInform")) { else if (callback.getMethod().equals("draftInform")) {
if (callback.getMessageId() > messageId) { if (callback.getMessageId() > messageId) {
@ -277,9 +306,10 @@ public class CallbackClientImpl implements CallbackClient {
} }
else if (callback.getMethod().equals("draftInit")) { else if (callback.getMethod().equals("draftInit")) {
DraftClientMessage message = (DraftClientMessage) callback.getData(); DraftClientMessage message = (DraftClientMessage) callback.getData();
DraftPanel panel = frame.getDraft(callback.getObjectId()); DraftPanel panel = MageFrame.getDraft(callback.getObjectId());
if (panel != null) if (panel != null) {
panel.loadBooster(message.getDraftPickView()); panel.loadBooster(message.getDraftPickView());
}
} }
else if (callback.getMethod().equals("tournamentInit")) { 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) { protected void watchGame(UUID gameId) {
try { try {
frame.watchGame(gameId); frame.watchGame(gameId);
@ -349,7 +394,6 @@ public class CallbackClientImpl implements CallbackClient {
handleException(ex); handleException(ex);
} }
} }
protected void replayGame(UUID gameId) { protected void replayGame(UUID gameId) {
try { try {
frame.replayGame(gameId); frame.replayGame(gameId);

View file

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

View file

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

View file

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

View file

@ -406,6 +406,21 @@ public class SessionImpl implements Session {
return false; 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 @Override
public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) { public boolean joinTable(UUID roomId, UUID tableId, String playerName, String playerType, int skill, DeckCardLists deckList) {
try { try {

View file

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

View file

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

View file

@ -49,6 +49,7 @@ public class TournamentView implements Serializable {
private Date startTime; private Date startTime;
private Date endTime; private Date endTime;
private boolean watchingAllowed;
private List<RoundView> rounds = new ArrayList<RoundView>(); private List<RoundView> rounds = new ArrayList<RoundView>();
private List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>(); private List<TournamentPlayerView> players = new ArrayList<TournamentPlayerView>();
@ -59,6 +60,7 @@ public class TournamentView implements Serializable {
tournamentType = tournament.getOptions().getTournamentType(); tournamentType = tournament.getOptions().getTournamentType();
startTime = tournament.getStartTime(); startTime = tournament.getStartTime();
endTime = tournament.getEndTime(); endTime = tournament.getEndTime();
watchingAllowed = tournament.getOptions().isWatchingAllowed();
for (TournamentPlayer player: tournament.getPlayers()) { for (TournamentPlayer player: tournament.getPlayers()) {
players.add(new TournamentPlayerView(player)); players.add(new TournamentPlayerView(player));
@ -77,11 +79,18 @@ public class TournamentView implements Serializable {
} }
public Date getStartTime() { public Date getStartTime() {
return startTime; return new Date(startTime.getTime());
} }
public Date getEndTime() { public Date getEndTime() {
return endTime; if (endTime == null) {
return null;
}
return new Date(endTime.getTime());
}
public boolean isWatchingAllowed() {
return watchingAllowed;
} }
public List<TournamentPlayerView> getPlayers() { 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)); rememberPick(card, RateCard.rateCard(card, null));
} }
chosenColors = chooseDeckColorsIfPossible(); chosenColors = chooseDeckColorsIfPossible();
log.warn(this.getName() + " after choose Deck Colors.");
} }
deck = buildDeck(new ArrayList<Card>(deck.getSideboard()), chosenColors); deck = buildDeck(new ArrayList<Card>(deck.getSideboard()), chosenColors);
log.warn(this.getName() + " after build deck.");
} }
tournament.submitDeck(playerId, deck); tournament.submitDeck(playerId, deck);
log.warn(this.getName() + " after submit deck.");
} }
public Card pickBestCard(List<Card> cards, List<ColoredManaSymbol> chosenColors) { 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 * 3. get card colors as chosen starting from most rated card
*/ */
protected List<ColoredManaSymbol> chooseDeckColorsIfPossible() { protected List<ColoredManaSymbol> chooseDeckColorsIfPossible() {
log.warn(this.getName() + " choose Deck Colors.");
if (pickedCards.size() > 2) { if (pickedCards.size() > 2) {
// sort by score and color mana symbol count in descending order // sort by score and color mana symbol count in descending order
Collections.sort(pickedCards, new Comparator<PickedCard>() { 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 @Override
public void watchGame(final UUID gameId, final String sessionId) throws MageException { public void watchGame(final UUID gameId, final String sessionId) throws MageException {
execute("watchGame", sessionId, new Action() { execute("watchGame", sessionId, new Action() {

View file

@ -257,15 +257,24 @@ public class TableController {
} }
public boolean watchTable(UUID userId) { public boolean watchTable(UUID userId) {
if (table.getState() != TableState.DUELING) { if (table.isTournament()) {
return false; 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;
}
// you can't watch your own game
if (userPlayerMap.get(userId) != null) {
return false;
}
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
return true;
} }
// you can't watch your own game
if (userPlayerMap.get(userId) != null) {
return false;
}
UserManager.getInstance().getUser(userId).watchGame(match.getGame().getId());
return true;
} }
public boolean replayTable(UUID userId) { public boolean replayTable(UUID userId) {
@ -464,7 +473,6 @@ public class TableController {
public void endGame() { public void endGame() {
// get player that chooses who goes first // get player that chooses who goes first
UUID choosingPlayerId = match.getChooser(); UUID choosingPlayerId = match.getChooser();
logger.warn("endGame() " + match.getPlayers().toString());
match.endGame(); match.endGame();
table.endGame(); table.endGame();
// Saving of games caused memory leaks - so save is deactivated // 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>(); List<UUID> toRemove = new ArrayList<UUID>();
for (Table table : tables.values()) { for (Table table : tables.values()) {
if (!table.getState().equals(TableState.FINISHED)) { 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; long diff = (now.getTime() - table.getCreateTime().getTime()) / EXPIRE_TIME_UNIT_VALUE;
if (diff >= EXPIRE_TIME) { if (diff >= EXPIRE_TIME) {
logger.info("Table expired: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing..."); logger.info("Table expired: id = " + table.getId() + ", created_by=" + table.getControllerName() + ". Removing...");
@ -319,8 +319,8 @@ public class TableManager {
if (player != null && player.isHuman()) { if (player != null && player.isHuman()) {
canBeRemoved = false; canBeRemoved = false;
} }
// tournament sub tables may not be removed, will be done by the tournament itself // tournament sub tables may not be removed as long the tournament is not finished
if(table.isTournamentSubTable()){ if(table.isTournamentSubTable() && table.getTournament().getEndTime() == null) {
canBeRemoved = false; canBeRemoved = false;
} }
} }

View file

@ -156,6 +156,10 @@ public class User {
fireCallback(new ClientCallback("construct", tableId, new TableClientMessage(deck, tableId, time))); 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) { public void watchGame(final UUID gameId) {
fireCallback(new ClientCallback("watchGame", gameId)); fireCallback(new ClientCallback("watchGame", gameId));
} }

View file

@ -309,6 +309,10 @@ public class GameController implements GameCallback {
} }
public void watch(UUID userId) { 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); User user = UserManager.getInstance().getUser(userId);
if (user != null) { if (user != null) {
GameWatcher gameWatcher = new GameWatcher(userId, game); GameWatcher gameWatcher = new GameWatcher(userId, game);

View file

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

View file

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

View file

@ -33,7 +33,6 @@ import java.util.concurrent.CopyOnWriteArrayList;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.constants.TournamentPlayerState;
import mage.game.events.*; import mage.game.events.*;
import mage.game.events.TableEvent.EventType; import mage.game.events.TableEvent.EventType;
import mage.game.match.Match; import mage.game.match.Match;
@ -309,12 +308,15 @@ public abstract class TournamentImpl implements Tournament {
@Override @Override
public Date getStartTime() { public Date getStartTime() {
return startTime; return new Date(startTime.getTime());
} }
@Override @Override
public Date getEndTime() { 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 { public class TournamentOptions implements Serializable {
protected String name; protected String name;
protected String tournamentType; protected String tournamentType;
protected List<String> playerTypes = new ArrayList<String>(); protected List<String> playerTypes = new ArrayList<String>();
protected MatchOptions matchOptions = new MatchOptions("", "Two Player Duel"); protected MatchOptions matchOptions = new MatchOptions("", "Two Player Duel");
protected LimitedOptions limitedOptions; protected LimitedOptions limitedOptions;
protected boolean watchingAllowed = true;
public TournamentOptions(String name) { public TournamentOptions(String name) {
this.name = name; this.name = name;
@ -78,4 +78,12 @@ public class TournamentOptions implements Serializable {
return limitedOptions; 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; package mage.game.tournament;
import mage.game.match.Match;
import java.util.UUID; import java.util.UUID;
import mage.game.match.Match;
/** /**
* *
@ -38,10 +37,11 @@ import java.util.UUID;
*/ */
public class TournamentPairing { public class TournamentPairing {
UUID id = UUID.randomUUID(); private UUID id = UUID.randomUUID();
Match match; private UUID tableId;
TournamentPlayer player1; private Match match;
TournamentPlayer player2; private TournamentPlayer player1;
private TournamentPlayer player2;
public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) { public TournamentPairing(TournamentPlayer player1, TournamentPlayer player2) {
this.player1 = player1; this.player1 = player1;
@ -86,4 +86,13 @@ public class TournamentPairing {
player2.setEliminated(); player2.setEliminated();
} }
} }
public UUID getTableId() {
return tableId;
}
public void setTableId(UUID tableId) {
this.tableId = tableId;
}
} }