16
16
import java.awt.BorderLayout;
17
17
import java.awt.CardLayout;
18
18
import java.awt.Color;
19
import java.awt.Component;
19
20
import java.awt.Dimension;
20
21
import java.awt.Font;
21
22
import java.awt.Graphics;
25
26
import java.awt.image.BufferedImage;
26
27
import java.io.File;
27
28
import java.io.IOException;
28
import java.io.InputStream;
29
29
import java.net.InetSocketAddress;
30
30
import java.net.MalformedURLException;
31
31
import java.net.URL;
41
41
import javax.swing.JLayeredPane;
42
42
import javax.swing.JOptionPane;
43
43
import javax.swing.JPanel;
44
import javax.swing.JPasswordField;
45
44
import javax.swing.JProgressBar;
46
45
import javax.swing.JScrollPane;
47
46
import javax.swing.JTextArea;
48
import javax.swing.JTextField;
49
47
import javax.swing.OverlayLayout;
50
48
import javax.swing.UIManager;
51
49
import net.sf.goodgame.client.game.GameClient;
94
92
private LobbyList lobbyList;
95
93
private GameList gameList;
96
94
private JPanel userActions;
97
private String LOGGEDIN_PANEL = "LIP";
98
private String NOTLOGGEDIN_PANEL = "NLIP";
95
private String NOT_LOGGED_IN_LOOK = "NL";
99
96
private String LOBBY_LOOK = "LL";
100
97
private String GAME_LOOK = "GL";
101
98
private Player myPlayer;
162
160
lobbyChatBox = new ChatBox("Null", io.getOutgoingConnection(), false);
164
162
userList = new UserListGUI(privateChatController, io.getOutgoingConnection());
165
JButton loginbutton = new TranslucentJButton("Login", 0.8f);
166
loginbutton.setActionCommand("login");
167
loginbutton.addActionListener(new ActionListener() {
169
public void actionPerformed(ActionEvent e) {
170
getLoginInformation();
174
JButton registerbutton = new TranslucentJButton("Register", 0.8f);
175
registerbutton.addActionListener(new ActionListener() {
177
public void actionPerformed(ActionEvent e) {
182
164
JButton logoutButton = new TranslucentJButton("Logout", 0.8f);
183
165
logoutButton.addActionListener(new ActionListener() {
199
181
userActions = new TranslucentJPanel(0.0f);
200
CardLayout cardlayout = new CardLayout();
201
userActions.setLayout(cardlayout);
203
JPanel notloggedinPanel = new JPanel();
204
notloggedinPanel.setOpaque(false);
205
notloggedinPanel.add(loginbutton);
206
notloggedinPanel.add(registerbutton);
208
JPanel loggedinPanel = new JPanel();
209
loggedinPanel.setOpaque(false);
210
loggedinPanel.add(logoutButton);
211
loggedinPanel.add(friends);
212
// loggedinPanel.add(editmyinfoButton);
213
userActions.add(notloggedinPanel, NOTLOGGEDIN_PANEL);
214
userActions.add(loggedinPanel, LOGGEDIN_PANEL);
183
userActions.add(logoutButton);
184
userActions.add(friends);
216
186
userList.getComponent().add(userActions, BorderLayout.SOUTH);
217
187
userList.getComponent().setPreferredSize(new Dimension(200, bottom.getSize().height));
253
223
guiLayout = new CardLayout();
254
224
setLayout(guiLayout);
255
225
add(lobbyLook, LOBBY_LOOK);
256
guiLayout.show(this, LOBBY_LOOK);
227
Component notLoggedInLook = new LoginPanel(this,io).getComponent();
228
add(notLoggedInLook,NOT_LOGGED_IN_LOOK);
230
guiLayout.show(this, NOT_LOGGED_IN_LOOK);
257
231
io.getIncomingConnection().setPrivateChatController(privateChatController);
258
232
io.getIncomingConnection().setChatListener(lobbyChatBox);
259
233
io.getIncomingConnection().setGameClient(null);
361
335
public void login(String name, UserType type) {
336
if(type == UserType.guest) return;
362
337
myPlayer = new Player(name);
364
if (type.equals(UserType.guest)) {
365
((CardLayout) userActions.getLayout()).show(userActions, NOTLOGGEDIN_PANEL);
367
friendsList = new FriendsList();
368
io.getIncomingConnection().setFriendsListener(friendsList);
369
friendsListGUI.setFriendsList(friendsList);
370
((CardLayout) userActions.getLayout()).show(userActions, LOGGEDIN_PANEL);
339
friendsList = new FriendsList();
340
io.getIncomingConnection().setFriendsListener(friendsList);
341
friendsListGUI.setFriendsList(friendsList);
342
CardLayout layout = this.guiLayout;
343
layout.show(this, LOBBY_LOOK);
375
346
public UserType getMyType() {
379
350
public FriendsList getFriendsList() {
380
351
return friendsList;
385
private void getLoginInformation() {
388
Object[] message = new Object[4];
389
message[0] = "Username";
390
message[1] = new JTextField();
391
message[2] = "Password";
392
message[3] = new JPasswordField();
394
String[] options = {"OK", "Cancel"};
396
int result = JOptionPane.showOptionDialog(this, message, "Login",
397
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
398
if (result == JOptionPane.OK_OPTION) {
399
username = ((JTextField) message[1]).getText();
400
password = new String(((JPasswordField) message[3]).getPassword());
401
io.getOutgoingConnection().login(username, password);
405
354
private void logout() {
406
355
io.getOutgoingConnection().logout();
356
guiLayout.show(this,NOT_LOGGED_IN_LOOK);
574
524
getRootPane().getLayeredPane().add(loadingbox, JLayeredPane.MODAL_LAYER);
577
private void register() {
579
String username = "";
581
String password1 = "";
582
String password2 = "";
585
Object[] message = new Object[9];
586
message[0] = "user name:";
587
message[1] = new JTextField(username);
588
message[2] = "email:";
589
message[3] = new JTextField(email);
590
message[4] = "password:";
591
message[5] = new JPasswordField(password1);
592
message[6] = "retype password:";
593
message[7] = new JPasswordField(password2);
600
int result = JOptionPane.showOptionDialog(
601
this, // the parent that the dialog blocks
602
message, // the dialog message array
603
"Register", // the title of the dialog window
604
JOptionPane.OK_CANCEL_OPTION, // option type
605
JOptionPane.QUESTION_MESSAGE, // message type
606
null, // optional icon, use null to use the default icon
607
options, // options string array, will be made into buttons
608
options[0] // option that should be made into a default button
611
if (result == JOptionPane.OK_OPTION) {
613
username = ((JTextField) message[1]).getText();
614
email = ((JTextField) message[3]).getText();
615
password1 = new String(((JPasswordField) message[5]).getPassword());
616
password2 = new String(((JPasswordField) message[7]).getPassword());
617
if (!password1.equals(password2)) {
618
this.showError("Passwords do not match");
620
io.getOutgoingConnection().register(username, password1, email);
624
528
public static URL getCodeBase() {