Liste der Spielertypen ist setzbar
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@422 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
56797840e2
commit
a15626ac3b
6 changed files with 69 additions and 12 deletions
|
@ -2,6 +2,7 @@ package jrummikub.view;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
|
@ -198,4 +199,10 @@ public class MockSettingsPanel implements ISettingsPanel {
|
||||||
public IEvent getBackEvent() {
|
public IEvent getBackEvent() {
|
||||||
return backEvent;
|
return backEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlayerTypeChoices(List<List<Type>> choices) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package jrummikub.control;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -41,6 +42,7 @@ public class SettingsControl {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
view.getSettingsPanel().enableNetworkMode(false);
|
view.getSettingsPanel().enableNetworkMode(false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -295,6 +297,11 @@ public class SettingsControl {
|
||||||
|
|
||||||
checkSettings();
|
checkSettings();
|
||||||
|
|
||||||
|
List<List<Type>> choices = new ArrayList<List<Type>>();
|
||||||
|
for (int i = 0; i < settings.getPlayerList().size(); i++) {
|
||||||
|
choices.add(Arrays.asList(Type.HUMAN, Type.COMPUTER));
|
||||||
|
}
|
||||||
|
view.getSettingsPanel().setPlayerTypeChoices(choices);
|
||||||
view.getSettingsPanel().setGameSettings(settings);
|
view.getSettingsPanel().setGameSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
package jrummikub.control.network;
|
package jrummikub.control.network;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import jrummikub.control.SettingsControl;
|
import jrummikub.control.SettingsControl;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
|
import jrummikub.model.PlayerSettings.Type;
|
||||||
import jrummikub.view.IGameListPanel.GameData;
|
import jrummikub.view.IGameListPanel.GameData;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
@ -28,6 +30,8 @@ public class NetworkSettingsControl extends SettingsControl {
|
||||||
IView view, GameSettings settings) {
|
IView view, GameSettings settings) {
|
||||||
super(view, settings);
|
super(view, settings);
|
||||||
this.connectionControl = connectionControl;
|
this.connectionControl = connectionControl;
|
||||||
|
/*view.getSettingsPanel().setPlayerTypeChoices(
|
||||||
|
Arrays.asList(Type.NETWORK, Type.COMPUTER));*/
|
||||||
view.getSettingsPanel().enableNetworkMode(true);
|
view.getSettingsPanel().enableNetworkMode(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,8 +18,6 @@ public class PlayerSettings implements Serializable {
|
||||||
/** */
|
/** */
|
||||||
COMPUTER,
|
COMPUTER,
|
||||||
/** */
|
/** */
|
||||||
VACANT,
|
|
||||||
/** */
|
|
||||||
NETWORK
|
NETWORK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package jrummikub.view;
|
package jrummikub.view;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
|
@ -9,6 +10,7 @@ import jrummikub.model.StoneColor;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
|
import jrummikub.util.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The panel for the game setup
|
* The panel for the game setup
|
||||||
|
@ -201,6 +203,8 @@ public interface ISettingsPanel {
|
||||||
public IEvent getSetVariantChildrenEvent();
|
public IEvent getSetVariantChildrenEvent();
|
||||||
|
|
||||||
public IEvent getBackEvent();
|
public IEvent getBackEvent();
|
||||||
|
|
||||||
|
public void setPlayerTypeChoices(List<List<Type>> choices);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specifies the different kinds of settings errors that can be displayed
|
* Specifies the different kinds of settings errors that can be displayed
|
||||||
|
@ -223,5 +227,4 @@ public interface ISettingsPanel {
|
||||||
/** Only computer players added */
|
/** Only computer players added */
|
||||||
COMPUTER_PLAYERS_ONLY_WARNING
|
COMPUTER_PLAYERS_ONLY_WARNING
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -17,14 +17,17 @@ import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Vector;
|
||||||
|
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
|
import javax.swing.DefaultComboBoxModel;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
|
@ -57,10 +60,13 @@ import jrummikub.util.Event2;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.ISettingsPanel;
|
import jrummikub.view.ISettingsPanel;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class SettingsPanel extends JPanel implements ISettingsPanel {
|
class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
|
private List<List<Type>> playerTypeChoices = new ArrayList<List<Type>>();
|
||||||
|
|
||||||
private JTabbedPane tabbedPane;
|
private JTabbedPane tabbedPane;
|
||||||
private JPanel playerSetupPanel;
|
private JPanel playerSetupPanel;
|
||||||
private JPanel playerSettingsViewport;
|
private JPanel playerSettingsViewport;
|
||||||
|
@ -202,6 +208,11 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
return backEvent;
|
return backEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlayerTypeChoices(List<List<Type>> choices) {
|
||||||
|
playerTypeChoices = choices;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setError(SettingsError error) {
|
public void setError(SettingsError error) {
|
||||||
switch (error) {
|
switch (error) {
|
||||||
|
@ -266,7 +277,12 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < gameSettings.getPlayerList().size(); ++i) {
|
for (int i = 0; i < gameSettings.getPlayerList().size(); ++i) {
|
||||||
updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i));
|
List<Type> choices = Collections.emptyList();
|
||||||
|
if (i < playerTypeChoices.size()) {
|
||||||
|
choices = playerTypeChoices.get(i);
|
||||||
|
}
|
||||||
|
updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i),
|
||||||
|
choices);
|
||||||
}
|
}
|
||||||
|
|
||||||
initialMeldThresholdSpinner.setValue(gameSettings
|
initialMeldThresholdSpinner.setValue(gameSettings
|
||||||
|
@ -287,16 +303,20 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
playerSettingsViewport.revalidate();
|
playerSettingsViewport.revalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlayerSettingsPanel(int i, PlayerSettings settings) {
|
private void updatePlayerSettingsPanel(int i, PlayerSettings settings,
|
||||||
|
List<Type> choices) {
|
||||||
if (i < playerSettingsPanels.size()) {
|
if (i < playerSettingsPanels.size()) {
|
||||||
|
playerSettingsPanels.get(i).setChoices(choices);
|
||||||
playerSettingsPanels.get(i).setSettings(settings);
|
playerSettingsPanels.get(i).setSettings(settings);
|
||||||
} else {
|
} else {
|
||||||
addPlayerSettingsPanel(i, settings);
|
addPlayerSettingsPanel(i, settings, choices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPlayerSettingsPanel(int i, PlayerSettings settings) {
|
private void addPlayerSettingsPanel(int i, PlayerSettings settings,
|
||||||
PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings);
|
List<Type> choices) {
|
||||||
|
PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings,
|
||||||
|
choices);
|
||||||
playerSettingsPanels.add(panel);
|
playerSettingsPanels.add(panel);
|
||||||
playerSettingsViewport.add(panel,
|
playerSettingsViewport.add(panel,
|
||||||
playerSettingsViewport.getComponentCount() - 1);
|
playerSettingsViewport.getComponentCount() - 1);
|
||||||
|
@ -659,15 +679,35 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public PlayerSettingsPanel(int playerNumber, PlayerSettings settings) {
|
public PlayerSettingsPanel(int playerNumber, PlayerSettings settings,
|
||||||
|
List<Type> choices) {
|
||||||
setLayout(new GridBagLayout());
|
setLayout(new GridBagLayout());
|
||||||
|
|
||||||
this.playerNumber = playerNumber;
|
this.playerNumber = playerNumber;
|
||||||
createControls(settings);
|
createControls(settings);
|
||||||
|
setChoices(choices);
|
||||||
|
|
||||||
setSettings(settings);
|
setSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setChoices(List<Type> playerTypeChoices) {
|
||||||
|
Vector<String> choices = new Vector<String>();
|
||||||
|
for (Type t : playerTypeChoices) {
|
||||||
|
switch (t) {
|
||||||
|
case COMPUTER:
|
||||||
|
choices.add("Computer");
|
||||||
|
break;
|
||||||
|
case HUMAN:
|
||||||
|
choices.add("Mensch");
|
||||||
|
break;
|
||||||
|
case NETWORK:
|
||||||
|
choices.add("Netzwerk");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
playerType.setModel(new DefaultComboBoxModel(choices));
|
||||||
|
}
|
||||||
|
|
||||||
private void createControls(PlayerSettings settings) {
|
private void createControls(PlayerSettings settings) {
|
||||||
GridBagConstraints c = new GridBagConstraints();
|
GridBagConstraints c = new GridBagConstraints();
|
||||||
GridBagConstraints c2 = new GridBagConstraints();
|
GridBagConstraints c2 = new GridBagConstraints();
|
||||||
|
@ -690,9 +730,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
c2.fill = GridBagConstraints.HORIZONTAL;
|
c2.fill = GridBagConstraints.HORIZONTAL;
|
||||||
add(nameField, c2);
|
add(nameField, c2);
|
||||||
|
|
||||||
String[] choices = { "Mensch", "Computer" };
|
playerType = new JComboBox();
|
||||||
|
|
||||||
playerType = new JComboBox(choices);
|
|
||||||
playerType.addActionListener(new ActionListener() {
|
playerType.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
|
Reference in a new issue