Display open games correctly
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@433 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
f6b1c638a1
commit
4879b7b93e
7 changed files with 56 additions and 25 deletions
|
@ -262,7 +262,7 @@ public abstract class AbstractSettingsControl {
|
||||||
String name = player1.getName();
|
String name = player1.getName();
|
||||||
Type type = player1.getType();
|
Type type = player1.getType();
|
||||||
|
|
||||||
if (type == Type.NETWORK) {
|
if (type == Type.VACANT) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package jrummikub.control.network;
|
package jrummikub.control.network;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
|
import jrummikub.util.GameData;
|
||||||
import jrummikub.view.ISettingsPanel.SettingsMode;
|
import jrummikub.view.ISettingsPanel.SettingsMode;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
public class GameOfferControl {
|
public class GameOfferControl {
|
||||||
|
private GameData gameData;
|
||||||
private ConnectionControl connectionControl;
|
private ConnectionControl connectionControl;
|
||||||
private GameSettings settings;
|
private GameSettings settings;
|
||||||
private IView view;
|
private IView view;
|
||||||
|
@ -14,15 +18,22 @@ public class GameOfferControl {
|
||||||
this.connectionControl = connectionControl;
|
this.connectionControl = connectionControl;
|
||||||
this.settings = settings;
|
this.settings = settings;
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
|
||||||
|
gameData = new GameData(UUID.randomUUID(), settings);
|
||||||
|
|
||||||
view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_OFFER);
|
view.getSettingsPanel().setSettingsMode(SettingsMode.NETWORK_OFFER);
|
||||||
view.getSettingsPanel().enableAddPlayerButton(false);
|
view.getSettingsPanel().enableAddPlayerButton(false);
|
||||||
view.getSettingsPanel().setGameSettings(settings);
|
view.getSettingsPanel().setGameSettings(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startGameOffer() {
|
public void startGameOffer() {
|
||||||
|
connectionControl.offerGame(gameData);
|
||||||
|
|
||||||
view.showSettingsPanel(true);
|
view.showSettingsPanel(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void abort() {
|
||||||
|
connectionControl.withdrawGame(gameData.getGameID());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ public class NetworkControl {
|
||||||
* Creates a new network control
|
* Creates a new network control
|
||||||
*
|
*
|
||||||
* @param loginData
|
* @param loginData
|
||||||
* user's login data
|
* user's login data
|
||||||
* @param view
|
* @param view
|
||||||
* for events and handlers
|
* for events and handlers
|
||||||
*/
|
*/
|
||||||
public NetworkControl(final LoginData loginData, final IView view) {
|
public NetworkControl(final LoginData loginData, final IView view) {
|
||||||
this.view = view;
|
this.view = view;
|
||||||
|
@ -75,21 +75,19 @@ public class NetworkControl {
|
||||||
* Adds the listeners for connection control events
|
* Adds the listeners for connection control events
|
||||||
*
|
*
|
||||||
* @param loginData
|
* @param loginData
|
||||||
* player's login data
|
* player's login data
|
||||||
* @param view
|
* @param view
|
||||||
* view for events
|
* view for events
|
||||||
*/
|
*/
|
||||||
public void addConnectionControlListeners(final LoginData loginData,
|
public void addConnectionControlListeners(final LoginData loginData,
|
||||||
final IView view) {
|
final IView view) {
|
||||||
connections.add(connectionControl.getConnectedEvent().add(
|
connections.add(connectionControl.getConnectedEvent().add(new IListener() {
|
||||||
new IListener() {
|
@Override
|
||||||
@Override
|
public void handle() {
|
||||||
public void handle() {
|
view.getGameListPanel().setChannelName(loginData.getChannelName());
|
||||||
view.getGameListPanel().setChannelName(
|
view.showGameListPanel(true);
|
||||||
loginData.getChannelName());
|
}
|
||||||
view.showGameListPanel(true);
|
}));
|
||||||
}
|
|
||||||
}));
|
|
||||||
|
|
||||||
connections.add(connectionControl.getConnectionFailedEvent().add(
|
connections.add(connectionControl.getConnectionFailedEvent().add(
|
||||||
new IListener() {
|
new IListener() {
|
||||||
|
@ -144,8 +142,16 @@ public class NetworkControl {
|
||||||
for (Connection c : connections) {
|
for (Connection c : connections) {
|
||||||
c.remove();
|
c.remove();
|
||||||
}
|
}
|
||||||
connectionControl.disconnect();
|
|
||||||
view.showGameListPanel(false);
|
view.showGameListPanel(false);
|
||||||
|
|
||||||
|
if (settingsControl != null) {
|
||||||
|
settingsControl.abort();
|
||||||
|
}
|
||||||
|
if (gameOfferControl != null) {
|
||||||
|
gameOfferControl.abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
connectionControl.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -99,7 +99,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl {
|
||||||
choices.add(Collections.singletonList(Type.HUMAN));
|
choices.add(Collections.singletonList(Type.HUMAN));
|
||||||
enableRemoveButtons.add(false);
|
enableRemoveButtons.add(false);
|
||||||
} else {
|
} else {
|
||||||
choices.add(Arrays.asList(Type.NETWORK, Type.COMPUTER));
|
choices.add(Arrays.asList(Type.VACANT, Type.COMPUTER));
|
||||||
enableRemoveButtons.add(settings.getPlayerList().size() > 2);
|
enableRemoveButtons.add(settings.getPlayerList().size() > 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,7 +119,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl {
|
||||||
|
|
||||||
settings.getPlayerList().get(i).setType(type);
|
settings.getPlayerList().get(i).setType(type);
|
||||||
|
|
||||||
if (type == Type.NETWORK) {
|
if (type == Type.VACANT) {
|
||||||
settings.getPlayerList().get(i).setName("Offen");
|
settings.getPlayerList().get(i).setName("Offen");
|
||||||
} else if (oldType != Type.COMPUTER && type == Type.COMPUTER) {
|
} else if (oldType != Type.COMPUTER && type == Type.COMPUTER) {
|
||||||
// Find unused player name
|
// Find unused player name
|
||||||
|
@ -158,7 +158,7 @@ public class NetworkSettingsControl extends AbstractSettingsControl {
|
||||||
|
|
||||||
PlayerSettings playerSettings = new PlayerSettings("Offen",
|
PlayerSettings playerSettings = new PlayerSettings("Offen",
|
||||||
findUnusedColor());
|
findUnusedColor());
|
||||||
playerSettings.setType(Type.NETWORK);
|
playerSettings.setType(Type.VACANT);
|
||||||
settings.getPlayerList().add(playerSettings);
|
settings.getPlayerList().add(playerSettings);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
|
@ -16,7 +16,9 @@ public class PlayerSettings implements Serializable {
|
||||||
/** */
|
/** */
|
||||||
COMPUTER,
|
COMPUTER,
|
||||||
/** */
|
/** */
|
||||||
NETWORK
|
NETWORK,
|
||||||
|
/** */
|
||||||
|
VACANT
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final long serialVersionUID = 1963640115089275992L;
|
private static final long serialVersionUID = 1963640115089275992L;
|
||||||
|
|
|
@ -21,6 +21,8 @@ import javax.swing.border.CompoundBorder;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.border.LineBorder;
|
import javax.swing.border.LineBorder;
|
||||||
|
|
||||||
|
import jrummikub.model.PlayerSettings;
|
||||||
|
import jrummikub.model.PlayerSettings.Type;
|
||||||
import jrummikub.util.Event;
|
import jrummikub.util.Event;
|
||||||
import jrummikub.util.Event1;
|
import jrummikub.util.Event1;
|
||||||
import jrummikub.util.GameData;
|
import jrummikub.util.GameData;
|
||||||
|
@ -188,13 +190,21 @@ class GameListPanel extends JPanel implements IGameListPanel {
|
||||||
int index, boolean isSelected, boolean cellHasFocus) {
|
int index, boolean isSelected, boolean cellHasFocus) {
|
||||||
String host = "", playerCount = "";
|
String host = "", playerCount = "";
|
||||||
|
|
||||||
if (value instanceof GameData && ((GameData)value).getGameSettings() != null) {
|
if (value instanceof GameData
|
||||||
|
&& ((GameData) value).getGameSettings() != null) {
|
||||||
GameData gameData = (GameData) value;
|
GameData gameData = (GameData) value;
|
||||||
|
|
||||||
host = gameData.getHost();
|
host = gameData.getHost();
|
||||||
/*playerCount = gameData.getCurrentPlayerCount() + "/"
|
int total = gameData.getGameSettings().getPlayerList().size();
|
||||||
+ gameData.getMaxPlayerCount();*/
|
int occupied = total;
|
||||||
playerCount = String.valueOf(gameData.getGameSettings().getPlayerList().size());
|
|
||||||
|
for (PlayerSettings player : gameData.getGameSettings().getPlayerList()) {
|
||||||
|
if (player.getType() == Type.VACANT) {
|
||||||
|
occupied--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
playerCount = occupied + "/" + total;
|
||||||
} else {
|
} else {
|
||||||
host = String.valueOf(value);
|
host = String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
|
@ -275,6 +275,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
@Override
|
@Override
|
||||||
public void enableStartGameButton(boolean enable) {
|
public void enableStartGameButton(boolean enable) {
|
||||||
startButton.setEnabled(enable);
|
startButton.setEnabled(enable);
|
||||||
|
offerButton.setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -861,6 +862,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
case HUMAN:
|
case HUMAN:
|
||||||
return "Mensch";
|
return "Mensch";
|
||||||
case NETWORK:
|
case NETWORK:
|
||||||
|
case VACANT:
|
||||||
return "Netzwerk";
|
return "Netzwerk";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue