From 4c7b0d50d2c4cf5f40827b19f34f1b01fef12d86 Mon Sep 17 00:00:00 2001 From: spjspj <spjspj4@gmail.com> Date: Thu, 8 Mar 2018 23:31:51 +1100 Subject: [PATCH] Add a 'spectators allowed' option for regular tables (aka non tournaments). --- .../java/mage/client/dialog/NewTableDialog.form | 11 +++++++++++ .../java/mage/client/dialog/NewTableDialog.java | 14 ++++++++++++-- .../mage/client/dialog/PreferencesDialog.java | 1 + .../java/mage/client/table/TablesPanel.java | 7 +++++-- .../src/main/java/mage/view/TableView.java | 8 ++++++++ .../main/java/mage/game/match/MatchOptions.java | 17 ++++++++++++----- 6 files changed, 49 insertions(+), 9 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form index a5a176504e..5f240b931c 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.form @@ -41,6 +41,9 @@ <Component id="lblFreeMulligans" min="-2" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> <Component id="spnFreeMulligans" min="-2" pref="50" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> + <Component id="chkSpectatorsAllowed" min="-2" max="-2" attributes="0"/> + <EmptySpace min="-2" pref="13" max="-2" attributes="0"/> </Group> <Group type="102" attributes="0"> <Component id="txtName" min="-2" pref="178" max="-2" attributes="0"/> @@ -152,6 +155,7 @@ <Component id="spnFreeMulligans" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="lblFreeMulligans" alignment="3" min="-2" max="-2" attributes="0"/> <Component id="chkRollbackTurnsAllowed" alignment="3" min="-2" max="-2" attributes="0"/> + <Component id="chkSpectatorsAllowed" alignment="3" min="-2" max="-2" attributes="0"/> </Group> <Group type="103" groupAlignment="3" attributes="0"> <Component id="cbGameType" alignment="3" min="-2" max="-2" attributes="0"/> @@ -274,6 +278,13 @@ <Property name="toolTipText" type="java.lang.String" value="The number of mulligans a player can use without decreasing the number of drawn cards."/> </Properties> </Component> + <Component class="javax.swing.JCheckBox" name="chkSpectatorsAllowed"> + <Properties> + <Property name="text" type="java.lang.String" value="Spectators allowed"/> + <Property name="toolTipText" type="java.lang.String" value="<HTML>Allow to rollback to the start of previous turns<br>
if all players agree.
"/> + </Properties> + </Component> + <Component class="javax.swing.JSpinner" name="spnFreeMulligans"> </Component> <Component class="javax.swing.JLabel" name="lblNumPlayers"> diff --git a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java index 10413c6787..337475674e 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/NewTableDialog.java @@ -102,6 +102,7 @@ public class NewTableDialog extends MageDialog { lblGameType = new javax.swing.JLabel(); cbGameType = new javax.swing.JComboBox(); chkRollbackTurnsAllowed = new javax.swing.JCheckBox(); + chkSpectatorsAllowed = new javax.swing.JCheckBox(); chkRated = new javax.swing.JCheckBox(); lblFreeMulligans = new javax.swing.JLabel(); spnFreeMulligans = new javax.swing.JSpinner(); @@ -151,6 +152,9 @@ public class NewTableDialog extends MageDialog { chkRollbackTurnsAllowed.setText("Allow rollbacks"); chkRollbackTurnsAllowed.setToolTipText("<HTML>Allow to rollback to the start of previous turns<br>\nif all players agree.\n"); + chkSpectatorsAllowed.setText("Allow Spectators"); + chkSpectatorsAllowed.setToolTipText("<HTML>Allow spectators to watch.\n"); + chkRated.setText("Rated"); chkRated.setToolTipText("Indicates if matches will be rated."); @@ -231,7 +235,9 @@ public class NewTableDialog extends MageDialog { .addGap(13, 13, 13) .addComponent(lblFreeMulligans) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(spnFreeMulligans, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addComponent(spnFreeMulligans, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(13, 13, 13) + .addComponent(chkSpectatorsAllowed)) .addGroup(layout.createSequentialGroup() .addComponent(txtName, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) @@ -325,7 +331,8 @@ public class NewTableDialog extends MageDialog { .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(spnFreeMulligans, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblFreeMulligans) - .addComponent(chkRollbackTurnsAllowed)) + .addComponent(chkRollbackTurnsAllowed) + .addComponent(chkSpectatorsAllowed)) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(cbGameType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(lblGameType))) @@ -401,6 +408,7 @@ public class NewTableDialog extends MageDialog { options.setRange((RangeOfInfluence) this.cbRange.getSelectedItem()); options.setWinsNeeded((Integer) this.spnNumWins.getValue()); options.setRollbackTurnsAllowed(chkRollbackTurnsAllowed.isSelected()); + options.setSpectatorsAllowed(chkSpectatorsAllowed.isSelected()); options.setRated(chkRated.isSelected()); options.setFreeMulligans((Integer) this.spnFreeMulligans.getValue()); options.setPassword(this.txtPassword.getText()); @@ -658,6 +666,7 @@ public class NewTableDialog extends MageDialog { } this.spnNumWins.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_OF_WINS + versionStr, "2"))); this.chkRollbackTurnsAllowed.setSelected(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_ROLLBACK_TURNS_ALLOWED + versionStr, "Yes").equals("Yes")); + this.chkSpectatorsAllowed.setSelected(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_SPECTATORS_ALLOWED + versionStr, "Yes").equals("Yes")); this.chkRated.setSelected(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_RATED + versionStr, "No").equals("Yes")); this.spnFreeMulligans.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_OF_FREE_MULLIGANS + versionStr, "0"))); @@ -739,6 +748,7 @@ public class NewTableDialog extends MageDialog { private javax.swing.JComboBox cbSkillLevel; private javax.swing.JComboBox cbTimeLimit; private javax.swing.JCheckBox chkRollbackTurnsAllowed; + private javax.swing.JCheckBox chkSpectatorsAllowed; private javax.swing.JCheckBox chkRated; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index 831900e297..869694af4f 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -229,6 +229,7 @@ public class PreferencesDialog extends javax.swing.JDialog { public static final String KEY_NEW_TABLE_GAME_TYPE = "newTableGameType"; public static final String KEY_NEW_TABLE_NUMBER_OF_WINS = "newTableNumberOfWins"; public static final String KEY_NEW_TABLE_ROLLBACK_TURNS_ALLOWED = "newTableRollbackTurnsAllowed"; + public static final String KEY_NEW_TABLE_SPECTATORS_ALLOWED = "newTableSpectatorsAllowed"; public static final String KEY_NEW_TABLE_NUMBER_OF_FREE_MULLIGANS = "newTableNumberOfFreeMulligans"; public static final String KEY_NEW_TABLE_DECK_FILE = "newTableDeckFile"; public static final String KEY_NEW_TABLE_RANGE = "newTableRange"; diff --git a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java index 547282f16d..5c11b3c6dc 100644 --- a/Mage.Client/src/main/java/mage/client/table/TablesPanel.java +++ b/Mage.Client/src/main/java/mage/client/table/TablesPanel.java @@ -1444,11 +1444,14 @@ class TableTableModel extends AbstractTableModel { if (tables[arg0].isTournament()) { return "Show"; } else { - owner = tables[arg0].getControllerName(); + owner = tables[arg0].getControllerName(); if (SessionHandler.getSession() != null && owner.equals(SessionHandler.getUserName())) { return ""; } - return "Watch"; + if (tables[arg0].getSpectatorsAllowed()) { + return "Watch"; + } + return ""; } default: return ""; diff --git a/Mage.Common/src/main/java/mage/view/TableView.java b/Mage.Common/src/main/java/mage/view/TableView.java index dd7de79d34..3480328b61 100644 --- a/Mage.Common/src/main/java/mage/view/TableView.java +++ b/Mage.Common/src/main/java/mage/view/TableView.java @@ -65,6 +65,7 @@ public class TableView implements Serializable { private final boolean limited; private final boolean rated; private final boolean passworded; + private final boolean spectatorsAllowed; public TableView(Table table) { this.tableId = table.getId(); @@ -139,6 +140,7 @@ public class TableView implements Serializable { this.limited = table.getMatch().getOptions().isLimited(); this.rated = table.getMatch().getOptions().isRated(); this.passworded = !table.getMatch().getOptions().getPassword().isEmpty(); + this.spectatorsAllowed = table.getMatch().getOptions().isSpectatorsAllowed(); } else { // TOURNAMENT if (table.getTournament().getOptions().getNumberRounds() > 0) { @@ -186,6 +188,7 @@ public class TableView implements Serializable { this.limited = table.getTournament().getOptions().getMatchOptions().isLimited(); this.rated = table.getTournament().getOptions().getMatchOptions().isRated(); this.passworded = !table.getTournament().getOptions().getPassword().isEmpty(); + this.spectatorsAllowed = table.getTournament().getOptions().isWatchingAllowed(); } } @@ -200,6 +203,11 @@ public class TableView implements Serializable { public String getControllerName() { return controllerName; } + + public boolean getSpectatorsAllowed() { + return spectatorsAllowed; + } + public String getGameType() { return gameType; diff --git a/Mage/src/main/java/mage/game/match/MatchOptions.java b/Mage/src/main/java/mage/game/match/MatchOptions.java index 5b1f4a6df9..e0dbb153fa 100644 --- a/Mage/src/main/java/mage/game/match/MatchOptions.java +++ b/Mage/src/main/java/mage/game/match/MatchOptions.java @@ -25,7 +25,6 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ - package mage.game.match; import mage.constants.MatchTimeLimit; @@ -61,6 +60,7 @@ public class MatchOptions implements Serializable { protected String password; protected SkillLevel skillLevel; protected boolean rollbackTurnsAllowed; + protected boolean spectatorsAllowed; protected int quitRatio; protected int edhPowerLevel; protected boolean rated; @@ -79,8 +79,7 @@ public class MatchOptions implements Serializable { this.multiPlayer = false; this.numSeats = 2; }*/ - - public MatchOptions(String name, String gameType, boolean multiPlayer, int numSeats ) { + public MatchOptions(String name, String gameType, boolean multiPlayer, int numSeats) { this.name = name; this.gameType = gameType; this.password = ""; @@ -178,7 +177,7 @@ public class MatchOptions implements Serializable { public MatchTimeLimit getMatchTimeLimit() { return this.matchTimeLimit; } - + public void setMatchTimeLimit(MatchTimeLimit matchTimeLimit) { this.matchTimeLimit = matchTimeLimit; } @@ -207,6 +206,14 @@ public class MatchOptions implements Serializable { this.rollbackTurnsAllowed = rollbackTurnsAllowed; } + public boolean isSpectatorsAllowed() { + return spectatorsAllowed; + } + + public void setSpectatorsAllowed(boolean spectatorsAllowed) { + this.spectatorsAllowed = spectatorsAllowed; + } + public int getQuitRatio() { return quitRatio; } @@ -214,7 +221,7 @@ public class MatchOptions implements Serializable { public void setQuitRatio(int quitRatio) { this.quitRatio = quitRatio; } - + public int getEdhPowerLevel() { return edhPowerLevel; }