Setting from new table dialog are saved and restored from java prefs when the client is started.

This commit is contained in:
LevelX2 2013-04-03 21:24:18 +02:00
parent fb539cd177
commit 6a9a245c15
3 changed files with 73 additions and 1 deletions

View file

@ -67,7 +67,6 @@ public class NewTableDialog extends MageDialog {
/** Creates new form NewTableDialog */ /** Creates new form NewTableDialog */
public NewTableDialog() { public NewTableDialog() {
initComponents(); initComponents();
txtName.setText("Game");
player1Panel.showLevel(false); player1Panel.showLevel(false);
this.spnNumWins.setModel(new SpinnerNumberModel(1, 1, 5, 1)); this.spnNumWins.setModel(new SpinnerNumberModel(1, 1, 5, 1));
} }
@ -308,6 +307,8 @@ public class NewTableDialog extends MageDialog {
options.setAttackOption((MultiplayerAttackOption) this.cbAttackOption.getSelectedItem()); options.setAttackOption((MultiplayerAttackOption) this.cbAttackOption.getSelectedItem());
options.setRange((RangeOfInfluence) this.cbRange.getSelectedItem()); options.setRange((RangeOfInfluence) this.cbRange.getSelectedItem());
options.setWinsNeeded((Integer)this.spnNumWins.getValue()); options.setWinsNeeded((Integer)this.spnNumWins.getValue());
saveGameSettingsToPrefs(options, this.player1Panel.getDeckFile());
table = session.createTable(roomId, options); table = session.createTable(roomId, options);
if (table == null) { if (table == null) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Error creating table.", "Error", JOptionPane.ERROR_MESSAGE);
@ -411,6 +412,9 @@ public class NewTableDialog extends MageDialog {
selectLimitedByDefault(); selectLimitedByDefault();
cbRange.setModel(new DefaultComboBoxModel(RangeOfInfluence.values())); cbRange.setModel(new DefaultComboBoxModel(RangeOfInfluence.values()));
cbAttackOption.setModel(new DefaultComboBoxModel(MultiplayerAttackOption.values())); cbAttackOption.setModel(new DefaultComboBoxModel(MultiplayerAttackOption.values()));
setGameSettingsFromPrefs();
this.roomId = roomId; this.roomId = roomId;
this.setModal(true); this.setModal(true);
setGameOptions(); setGameOptions();
@ -436,6 +440,58 @@ public class NewTableDialog extends MageDialog {
} }
} }
/**
* set the table settings from java prefs
*/
private void setGameSettingsFromPrefs () {
txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NAME, "Game"));
String gameTypeName = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_GAME_TYPE, "Two Player Duel");
for (GameTypeView gtv : session.getGameTypes()) {
if (gtv.getName().equals(gameTypeName)) {
cbGameType.setSelectedItem(gtv);
break;
}
}
cbDeckType.setSelectedItem(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_DECK_TYPE, "Limited"));
String deckFile = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_DECK_FILE, null);
if (deckFile != null) {
this.player1Panel.setDeckFile(deckFile);
}
this.spnNumWins.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_OF_WINS, "2")));
this.spnNumPlayers.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_PLAYERS, "2")));
int range = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_RANGE, "1"));
for (RangeOfInfluence roi :RangeOfInfluence.values()) {
if (roi.getRange() == range) {
this.cbRange.setSelectedItem(roi);
break;
}
}
String attackOption = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_ATTACK_OPTION, "Attack Multiple Players");
for (MultiplayerAttackOption mao :MultiplayerAttackOption.values()) {
if (mao.toString().equals(attackOption)) {
this.cbAttackOption.setSelectedItem(mao);
break;
}
}
}
/**
* Save the settings to java prefs to reload it next time the dialog will be created
*
* @param options
* @param deckFile
*/
private void saveGameSettingsToPrefs(MatchOptions options, String deckFile) {
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NAME, options.getName());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_DECK_TYPE, options.getDeckType());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_GAME_TYPE, options.getGameType());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_OF_WINS, Integer.toString(options.getWinsNeeded()));
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_DECK_FILE, deckFile);
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_PLAYERS, spnNumPlayers.getValue().toString());
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_RANGE, Integer.toString(options.getRange().getRange()));
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_ATTACK_OPTION, options.getAttackOption().toString());
}
// 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;

View file

@ -81,6 +81,17 @@ public class PreferencesDialog extends javax.swing.JDialog {
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_1 = "gamepanelDividerLocation1"; public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_1 = "gamepanelDividerLocation1";
public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2"; public static final String KEY_GAMEPANEL_DIVIDER_LOCATION_2 = "gamepanelDividerLocation2";
// default setting for new table dialog
public static final String KEY_NEW_TABLE_NAME = "newTableName";
public static final String KEY_NEW_TABLE_DECK_TYPE = "newTableDeckType";
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_DECK_FILE = "newTableDeckFile";
public static final String KEY_NEW_TABLE_RANGE = "newTableRange";
public static final String KEY_NEW_TABLE_ATTACK_OPTION = "newTableAttackOption";
public static final String KEY_NEW_TABLE_NUMBER_PLAYERS = "newTableNumberPlayers";
// used to save and restore the settings for the cardArea (draft, sideboarding, deck builder)
public static final String KEY_DRAFT_VIEW = "draftView"; public static final String KEY_DRAFT_VIEW = "draftView";
public static final String KEY_DRAFT_PILES_TOGGLE = "draftPilesToggle"; public static final String KEY_DRAFT_PILES_TOGGLE = "draftPilesToggle";
public static final String KEY_DRAFT_SORT_BY = "draftSortBy"; public static final String KEY_DRAFT_SORT_BY = "draftSortBy";

View file

@ -102,6 +102,11 @@ public class NewPlayerPanel extends javax.swing.JPanel {
return this.txtPlayerDeck.getText(); return this.txtPlayerDeck.getText();
} }
public void setDeckFile(String deckFile) {
this.txtPlayerDeck.setText(deckFile);
}
public int getLevel() { public int getLevel() {
return Integer.valueOf((String)this.cbLevel.getSelectedItem()); return Integer.valueOf((String)this.cbLevel.getSelectedItem());
} }