mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 11:32:00 -08:00
* new Table - Save and restore number and type of players.
This commit is contained in:
parent
17df6bfff0
commit
8ed26a1fe8
3 changed files with 37 additions and 5 deletions
|
|
@ -30,7 +30,9 @@ package mage.client.dialog;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.ListIterator;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
|
@ -63,6 +65,7 @@ public class NewTableDialog extends MageDialog {
|
||||||
private UUID roomId;
|
private UUID roomId;
|
||||||
private Session session;
|
private Session session;
|
||||||
private List<TablePlayerPanel> players = new ArrayList<TablePlayerPanel>();
|
private List<TablePlayerPanel> players = new ArrayList<TablePlayerPanel>();
|
||||||
|
private List<String> prefPlayerTypes = new ArrayList<String>();
|
||||||
|
|
||||||
private static final String LIMITED = "Limited";
|
private static final String LIMITED = "Limited";
|
||||||
|
|
||||||
|
|
@ -376,18 +379,26 @@ public class NewTableDialog extends MageDialog {
|
||||||
|
|
||||||
private void setGameOptions() {
|
private void setGameOptions() {
|
||||||
GameTypeView gameType = (GameTypeView) cbGameType.getSelectedItem();
|
GameTypeView gameType = (GameTypeView) cbGameType.getSelectedItem();
|
||||||
|
int oldValue = (Integer) this.spnNumPlayers.getValue();
|
||||||
this.spnNumPlayers.setModel(new SpinnerNumberModel(gameType.getMinPlayers(), gameType.getMinPlayers(), gameType.getMaxPlayers(), 1));
|
this.spnNumPlayers.setModel(new SpinnerNumberModel(gameType.getMinPlayers(), gameType.getMinPlayers(), gameType.getMaxPlayers(), 1));
|
||||||
this.spnNumPlayers.setEnabled(gameType.getMinPlayers() != gameType.getMaxPlayers());
|
this.spnNumPlayers.setEnabled(gameType.getMinPlayers() != gameType.getMaxPlayers());
|
||||||
|
if (oldValue >= gameType.getMinPlayers() && oldValue <= gameType.getMaxPlayers()){
|
||||||
|
this.spnNumPlayers.setValue(oldValue);
|
||||||
|
}
|
||||||
this.cbAttackOption.setEnabled(gameType.isUseAttackOption());
|
this.cbAttackOption.setEnabled(gameType.isUseAttackOption());
|
||||||
this.cbRange.setEnabled(gameType.isUseRange());
|
this.cbRange.setEnabled(gameType.isUseRange());
|
||||||
createPlayers(gameType.getMinPlayers() - 1);
|
createPlayers((Integer) spnNumPlayers.getValue() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createPlayers(int numPlayers) {
|
private void createPlayers(int numPlayers) {
|
||||||
if (numPlayers > players.size()) {
|
if (numPlayers > players.size()) {
|
||||||
while (players.size() != numPlayers) {
|
while (players.size() != numPlayers) {
|
||||||
TablePlayerPanel playerPanel = new TablePlayerPanel();
|
TablePlayerPanel playerPanel = new TablePlayerPanel();
|
||||||
playerPanel.init(players.size() + 2);
|
String playerType = "Human";
|
||||||
|
if (prefPlayerTypes.size() >= players.size() && players.size() > 0) {
|
||||||
|
playerType = prefPlayerTypes.get(players.size() - 1);
|
||||||
|
}
|
||||||
|
playerPanel.init(players.size() + 2, playerType);
|
||||||
players.add(playerPanel);
|
players.add(playerPanel);
|
||||||
playerPanel.addPlayerTypeEventListener(
|
playerPanel.addPlayerTypeEventListener(
|
||||||
new Listener<Event> () {
|
new Listener<Event> () {
|
||||||
|
|
@ -466,6 +477,13 @@ public class NewTableDialog extends MageDialog {
|
||||||
*/
|
*/
|
||||||
private void setGameSettingsFromPrefs () {
|
private void setGameSettingsFromPrefs () {
|
||||||
txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NAME, "Game"));
|
txtName.setText(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NAME, "Game"));
|
||||||
|
|
||||||
|
String playerTypes = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_PLAYER_TYPES, "Human");
|
||||||
|
prefPlayerTypes.clear();
|
||||||
|
prefPlayerTypes.addAll(Arrays.asList(playerTypes.split(",")));
|
||||||
|
this.spnNumPlayers.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_PLAYERS, "2")));
|
||||||
|
|
||||||
|
|
||||||
String gameTypeName = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_GAME_TYPE, "Two Player Duel");
|
String gameTypeName = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_GAME_TYPE, "Two Player Duel");
|
||||||
for (GameTypeView gtv : session.getGameTypes()) {
|
for (GameTypeView gtv : session.getGameTypes()) {
|
||||||
if (gtv.getName().equals(gameTypeName)) {
|
if (gtv.getName().equals(gameTypeName)) {
|
||||||
|
|
@ -486,7 +504,6 @@ public class NewTableDialog extends MageDialog {
|
||||||
this.player1Panel.setDeckFile(deckFile);
|
this.player1Panel.setDeckFile(deckFile);
|
||||||
}
|
}
|
||||||
this.spnNumWins.setValue(Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_OF_WINS, "2")));
|
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"));
|
int range = Integer.parseInt(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_NEW_TABLE_RANGE, "1"));
|
||||||
for (RangeOfInfluence roi :RangeOfInfluence.values()) {
|
for (RangeOfInfluence roi :RangeOfInfluence.values()) {
|
||||||
if (roi.getRange() == range) {
|
if (roi.getRange() == range) {
|
||||||
|
|
@ -519,6 +536,16 @@ public class NewTableDialog extends MageDialog {
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_NUMBER_PLAYERS, spnNumPlayers.getValue().toString());
|
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_RANGE, Integer.toString(options.getRange().getRange()));
|
||||||
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_ATTACK_OPTION, options.getAttackOption().toString());
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_ATTACK_OPTION, options.getAttackOption().toString());
|
||||||
|
StringBuilder playerTypesString = new StringBuilder();
|
||||||
|
ListIterator iterator = players.listIterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
if (playerTypesString.length()>0) {
|
||||||
|
playerTypesString.append(",");
|
||||||
|
}
|
||||||
|
TablePlayerPanel tpp = (TablePlayerPanel) iterator.next();
|
||||||
|
playerTypesString.append(tpp.getPlayerType());
|
||||||
|
}
|
||||||
|
PreferencesDialog.saveValue(PreferencesDialog.KEY_NEW_TABLE_PLAYER_TYPES, playerTypesString.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
|
|
|
||||||
|
|
@ -124,6 +124,7 @@ public class PreferencesDialog extends javax.swing.JDialog {
|
||||||
public static final String KEY_NEW_TABLE_RANGE = "newTableRange";
|
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_ATTACK_OPTION = "newTableAttackOption";
|
||||||
public static final String KEY_NEW_TABLE_NUMBER_PLAYERS = "newTableNumberPlayers";
|
public static final String KEY_NEW_TABLE_NUMBER_PLAYERS = "newTableNumberPlayers";
|
||||||
|
public static final String KEY_NEW_TABLE_PLAYER_TYPES = "newTablePlayerTypes";
|
||||||
|
|
||||||
// pref setting for new tournament dialog
|
// pref setting for new tournament dialog
|
||||||
public static final String KEY_NEW_TOURNAMENT_NAME = "newTournamentName";
|
public static final String KEY_NEW_TOURNAMENT_NAME = "newTournamentName";
|
||||||
|
|
|
||||||
|
|
@ -61,18 +61,22 @@ public class TablePlayerPanel extends javax.swing.JPanel {
|
||||||
this.newPlayerPanel.setVisible(false);
|
this.newPlayerPanel.setVisible(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(int playerNum) {
|
public void init(int playerNum, String playerType) {
|
||||||
session = MageFrame.getSession();
|
session = MageFrame.getSession();
|
||||||
cbPlayerType.setModel(new DefaultComboBoxModel(session.getPlayerTypes()));
|
cbPlayerType.setModel(new DefaultComboBoxModel(session.getPlayerTypes()));
|
||||||
this.lblPlayerNum.setText("Player " + playerNum);
|
this.lblPlayerNum.setText("Player " + playerNum);
|
||||||
if (Config.defaultOtherPlayerIndex != null) {
|
if (Config.defaultOtherPlayerIndex != null) {
|
||||||
if (Integer.valueOf(Config.defaultOtherPlayerIndex) >= cbPlayerType.getItemCount())
|
if (Integer.valueOf(Config.defaultOtherPlayerIndex) >= cbPlayerType.getItemCount()) {
|
||||||
cbPlayerType.setSelectedIndex(cbPlayerType.getItemCount() - 1);
|
cbPlayerType.setSelectedIndex(cbPlayerType.getItemCount() - 1);
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
Integer index = Integer.parseInt(Config.defaultOtherPlayerIndex);
|
Integer index = Integer.parseInt(Config.defaultOtherPlayerIndex);
|
||||||
cbPlayerType.setSelectedIndex(index);
|
cbPlayerType.setSelectedIndex(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (playerType != null) {
|
||||||
|
this.cbPlayerType.setSelectedItem(playerType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean joinTable(UUID roomId, UUID tableId) throws FileNotFoundException, IOException, ClassNotFoundException {
|
public boolean joinTable(UUID roomId, UUID tableId) throws FileNotFoundException, IOException, ClassNotFoundException {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue