* Saved table spectator setting to preferences.

This commit is contained in:
LevelX2 2018-03-17 00:46:12 +01:00
parent 8bc3efff07
commit 9c0d0a0153
2 changed files with 36 additions and 30 deletions

View file

@ -27,6 +27,12 @@
*/
package mage.client.dialog;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import javax.swing.*;
import mage.cards.decks.importer.DeckImporterUtil;
import mage.client.MageFrame;
import mage.client.SessionHandler;
@ -45,13 +51,6 @@ import mage.view.GameTypeView;
import mage.view.TableView;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* @author BetaSteward_at_googlemail.com
*/
@ -623,17 +622,22 @@ public class NewTableDialog extends MageDialog {
* set the table settings from java prefs
*/
int currentSettingVersion = 0;
private void setGameSettingsFromPrefs(int version) {
currentSettingVersion = version;
String versionStr = "";
if (currentSettingVersion == 1) {
versionStr = "1";
btnPreviousConfiguration1.requestFocus();
} else if (currentSettingVersion == 2) {
versionStr = "2";
btnPreviousConfiguration2.requestFocus();
} else {
btnPreviousConfiguration2.getParent().requestFocus();
switch (currentSettingVersion) {
case 1:
versionStr = "1";
btnPreviousConfiguration1.requestFocus();
break;
case 2:
versionStr = "2";
btnPreviousConfiguration2.requestFocus();
break;
default:
btnPreviousConfiguration2.getParent().requestFocus();
break;
}
txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NAME + versionStr, "Game"));
txtPassword.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_PASSWORD + versionStr, ""));
@ -724,6 +728,7 @@ public class NewTableDialog extends MageDialog {
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_RANGE + versionStr, Integer.toString(options.getRange().getRange()));
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_ATTACK_OPTION + versionStr, options.getAttackOption().toString());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_SKILL_LEVEL + versionStr, options.getSkillLevel().toString());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_SPECTATORS_ALLOWED + versionStr, options.isSpectatorsAllowed() ? "Yes" : "No");
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_QUIT_RATIO + versionStr, Integer.toString(options.getQuitRatio()));
StringBuilder playerTypesString = new StringBuilder();
for (Object player : players) {

View file

@ -35,11 +35,13 @@ package mage.client.dialog;
import java.awt.*;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import mage.cards.decks.Deck;
import mage.cards.decks.importer.DeckImporterUtil;
import mage.cards.repository.ExpansionInfo;
@ -589,9 +591,9 @@ public class NewTournamentDialog extends MageDialog {
} else {
for (JPanel panel : packPanels) {
JComboBox combo = findComboInComponent(panel);
if(combo != null) {
if (combo != null) {
tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) combo.getSelectedItem()).getCode());
}else{
} else {
logger.error("Can't find combo component in " + panel.toString());
}
}
@ -764,7 +766,6 @@ public class NewTournamentDialog extends MageDialog {
this.spnNumPlayers.setModel(new SpinnerNumberModel(numPlayers, tournamentType.getMinPlayers(), tournamentType.getMaxPlayers(), 1));
this.spnNumPlayers.setEnabled(tournamentType.getMinPlayers() != tournamentType.getMaxPlayers());
createPlayers((Integer) spnNumPlayers.getValue() - 1);
this.spnNumSeats.setModel(new SpinnerNumberModel(2, 2, tournamentType.getMaxPlayers(), 1));
if (tournamentType.isLimited()) {
@ -926,7 +927,7 @@ public class NewTournamentDialog extends MageDialog {
public void actionPerformed(java.awt.event.ActionEvent evt) {
// search combo box near button (must be only one combo in panel)
JButton button = (JButton)evt.getSource();
JButton button = (JButton) evt.getSource();
JComboBox combo = findComboInComponent(button.getParent());
if (combo != null) {
@ -941,12 +942,12 @@ public class NewTournamentDialog extends MageDialog {
this.repaint();
}
private JComboBox findComboInComponent(Container panel){
private JComboBox findComboInComponent(Container panel) {
// search combo box near button (must be only one combo in panel)
JComboBox combo = null;
for(Component comp: panel.getComponents()){
if (comp instanceof JComboBox){
combo = (JComboBox)comp;
for (Component comp : panel.getComponents()) {
if (comp instanceof JComboBox) {
combo = (JComboBox) comp;
break;
}
}
@ -955,21 +956,21 @@ public class NewTournamentDialog extends MageDialog {
private void packActionPerformed(java.awt.event.ActionEvent evt) {
// fill all bottom combobox with same value
JComboBox curentCombo = (JComboBox)evt.getSource();
JComboBox curentCombo = (JComboBox) evt.getSource();
int newValue = curentCombo.getSelectedIndex();
// search start index
int startIndex = 0;
for(int i = 0; i < packPanels.size(); i++){
for (int i = 0; i < packPanels.size(); i++) {
JComboBox pack = findComboInComponent(packPanels.get(i));
if (pack.equals(curentCombo)){
if (pack.equals(curentCombo)) {
startIndex = i + 1;
break;
}
}
// change all from start index
for(int i = startIndex; i < packPanels.size(); i++){
for (int i = startIndex; i < packPanels.size(); i++) {
JComboBox pack = findComboInComponent(packPanels.get(i));
pack.setSelectedIndex(newValue);
}
@ -1128,7 +1129,7 @@ public class NewTournamentDialog extends MageDialog {
break;
}
}
}else{
} else {
logger.error("Can't find combo component in " + panel.toString());
}
}