Fixed load warnings panels and everything

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@579 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Jannis Harder 2011-06-22 06:14:41 +02:00
parent 86eeace673
commit 443e99450b
4 changed files with 57 additions and 81 deletions

View file

@ -42,7 +42,7 @@ public class ApplicationControl {
saveControl = new SaveControl(view); saveControl = new SaveControl(view);
addQuitGameHandlers(); addQuitGameHandlers();
addSaveLoadHandlers();
addNewNetworkGameHandler(); addNewNetworkGameHandler();
saveControl.getLoadEvent().add( saveControl.getLoadEvent().add(
@ -65,11 +65,40 @@ public class ApplicationControl {
}); });
} }
private void addSaveLoadHandlers() {
view.getLoadEvent().add(new IListener() {
@Override
public void handle() {
if (!isGameRunning()) {
abortControls();
startApplication();
view.load();
return;
}
view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
abortControls();
startApplication();
view.showQuitWarningPanel(false);
view.load();
tempConnection.remove();
}
});
}
});
}
private void addNewNetworkGameHandler() { private void addNewNetworkGameHandler() {
view.getNetworkGameEvent().add(new IListener() { view.getNetworkGameEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
if (gameControl == null) { if (!isGameRunning()) {
abortControls(); abortControls();
createLoginControl(true); createLoginControl(true);
} else { } else {
@ -101,10 +130,7 @@ public class ApplicationControl {
view.getQuitEvent().add(new IListener() { view.getQuitEvent().add(new IListener() {
@Override @Override
public void handle() { public void handle() {
if (networkControl != null) { if (!isGameRunning()) {
return;
}
if (gameControl == null) {
System.exit(0); System.exit(0);
} else { } else {
showQuitWarning(); showQuitWarning();
@ -151,6 +177,15 @@ public class ApplicationControl {
}); });
} }
/**
* Checks if a game is currently running
* @return true when a game is running
*/
public boolean isGameRunning() {
return gameControl != null || networkControl != null
&& networkControl.isGameRunning();
}
/** /**
* Create a new network login control * Create a new network login control
*/ */
@ -282,9 +317,6 @@ public class ApplicationControl {
* @return whether the server could be started * @return whether the server could be started
*/ */
public boolean startDedicatedServer(String password) { public boolean startDedicatedServer(String password) {
if (password == "") {
password = "jrummikub";
}
if (server == null) { if (server == null) {
DedicatedServer newServer = new DedicatedServer(password); DedicatedServer newServer = new DedicatedServer(password);
ServerStatus status = newServer.start(); ServerStatus status = newServer.start();

View file

@ -27,7 +27,6 @@ public class SaveControl {
private IRoundState roundState; private IRoundState roundState;
private Event3<GameSettings, GameState, IRoundState> loadEvent = new Event3<GameSettings, GameState, IRoundState>(); private Event3<GameSettings, GameState, IRoundState> loadEvent = new Event3<GameSettings, GameState, IRoundState>();
private Event loadErrorEvent = new Event(); private Event loadErrorEvent = new Event();
private Connection tempConnection;
/** /**
* Creates a new SaveControl * Creates a new SaveControl
@ -42,34 +41,6 @@ public class SaveControl {
save(file); save(file);
} }
}); });
view.getLoadEvent().add(new IListener() {
@Override
public void handle() {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_GAME);
view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
view.showQuitWarningPanel(false);
view.load();
tempConnection.remove();
}
});
}
});
view.getQuitWarningPanel().getCancelEvent().add(new IListener() {
@Override
public void handle() {
view.showQuitWarningPanel(false);
if (tempConnection != null) {
tempConnection.remove();
tempConnection = null;
}
}
});
view.getLoadFileEvent().add(new IListener1<File>() { view.getLoadFileEvent().add(new IListener1<File>() {
@Override @Override
public void handle(final File file) { public void handle(final File file) {

View file

@ -27,7 +27,6 @@ public class NetworkControl {
private IConnectionControl connectionControl; private IConnectionControl connectionControl;
private IView view; private IView view;
private List<Connection> connections = new ArrayList<Connection>(); private List<Connection> connections = new ArrayList<Connection>();
Connection tempConnection;
private Event stopNetworkEvent = new Event(); private Event stopNetworkEvent = new Event();
private Event backToLoginEvent = new Event(); private Event backToLoginEvent = new Event();
@ -63,41 +62,10 @@ public class NetworkControl {
addConnectionSetupListeners(loginData, view); addConnectionSetupListeners(loginData, view);
addConnectionControlListeners(view); addConnectionControlListeners(view);
connections.add(view.getQuitEvent().add(new IListener() {
@Override
public void handle() {
if (gameControl == null) {
System.exit(0);
} else {
view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS);
view.showQuitWarningPanel(true);
tempConnection = view.getQuitWarningPanel().getQuitEvent()
.add(new IListener() {
@Override
public void handle() {
System.exit(0);
}
});
}
}
}));
addViewEventListeners(); addViewEventListeners();
} }
private void addViewEventListeners() { private void addViewEventListeners() {
connections.add(view.getQuitWarningPanel().getCancelEvent()
.add(new IListener() {
@Override
public void handle() {
view.showQuitWarningPanel(false);
if (tempConnection != null) {
tempConnection.remove();
tempConnection = null;
}
}
}));
connections.add(view.getGameListPanel().getJoinEvent() connections.add(view.getGameListPanel().getJoinEvent()
.add(new IListener1<GameData>() { .add(new IListener1<GameData>() {
@Override @Override
@ -378,4 +346,7 @@ public class NetworkControl {
gameControl.startGame(); gameControl.startGame();
} }
public boolean isGameRunning() {
return gameControl != null;
}
} }

View file

@ -34,6 +34,7 @@ class LoginPanel extends JPanel implements ILoginPanel {
private JTextField passwordField; private JTextField passwordField;
private JTextField channelNameField; private JTextField channelNameField;
private JButton startDedicatedServerButton; private JButton startDedicatedServerButton;
private static final String DEFAULT_PASSWORD = "jrummikub";
LoginPanel() { LoginPanel() {
setLayout(new GridBagLayout()); setLayout(new GridBagLayout());
@ -50,7 +51,8 @@ class LoginPanel extends JPanel implements ILoginPanel {
startDedicatedServerButton.addActionListener(new ActionListener() { startDedicatedServerButton.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
useDedicatedServer.emit(passwordField.getText()); useDedicatedServer.emit(passwordField.getText().isEmpty() ? DEFAULT_PASSWORD
: passwordField.getText());
} }
}); });
@ -144,7 +146,7 @@ class LoginPanel extends JPanel implements ILoginPanel {
private void login() { private void login() {
loginEvent.emit(new LoginData(userNameField.getText(), serverNameField loginEvent.emit(new LoginData(userNameField.getText(), serverNameField
.getText(), passwordField.getText().isEmpty() ? "jrummikub" .getText(), passwordField.getText().isEmpty() ? DEFAULT_PASSWORD
: passwordField.getText(), channelNameField.getText())); : passwordField.getText(), channelNameField.getText()));
} }