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