📄 clientmanager.java
字号:
/*
* Light And Shadow. A Persistent Universe based on Robert Jordan's Wheel of Time Books.
* Copyright (C) 2001-2002 WOTLAS Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package wotlas.client;
import wotlas.client.gui.*;
import wotlas.client.screen.*;
import wotlas.common.message.account.*;
import wotlas.common.message.description.*;
import wotlas.common.*;
import wotlas.libs.net.*;
import wotlas.libs.net.connection.*;
import wotlas.libs.graphics2D.FontFactory;
import wotlas.libs.sound.SoundLibrary;
import wotlas.libs.wizard.*;
import wotlas.utils.*;
import wotlas.libs.aswing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import javax.swing.event.*;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.*;
/** The main small windows of the game : welcome, accounts, login, recover, delete.
* The ClientManager is here to link the different GUIs between them. It also
* possesses the client player profiles and server configs.
*
* @author Petrus, Diego
* @see wotlas.client.gui.JIntroWizard
*/
public class ClientManager extends JIntroWizard implements ActionListener {
/*------------------------------------------------------------------------------------*/
/** Available steps for this Client Manager
*/
final static public int FIRST_INIT = -1;
final static public int MAIN_SCREEN = 0;
final static public int ACCOUNT_LOGIN_SCREEN = 1;
final static public int DELETE_ACCOUNT_SCREEN = 2;
final static public int RECOVER_ACCOUNT_SCREEN = 3;
final static public int ACCOUNT_CREATION_SCREEN = 10;
final static public int ACCOUNT_INFO_SCREEN = 11;
final static public int DATAMANAGER_DISPLAY = 20;
/*------------------------------------------------------------------------------------*/
/** Do we have to remember passwords ? i.e. save them to disk. (default is true).
*/
private static boolean rememberPasswords = true;
/*------------------------------------------------------------------------------------*/
/** Our ProfileConfigList file.
*/
private ProfileConfigList profileConfigList;
/** Current profileConfig
*/
private ProfileConfig currentProfileConfig;
/** Our ServerConfigManager file.
*/
private ServerConfigManager serverConfigManager;
/** Current serverConfig
*/
private ServerConfig currentServerConfig;
/** Index of current screen shown
*/
private int indexScreen;
/** Number of tries to reach wotlas *web* server
*/
private short nbTry;
/** pictures of buttons
*/
private ImageIcon im_okup, im_okdo, im_okun;
private ImageIcon im_cancelup, im_canceldo, im_cancelun;
private ImageIcon im_newup, im_newdo;
private ImageIcon im_loadup, im_loaddo, im_loadun;
private ImageIcon im_recoverup, im_recoverdo, im_recoverun;
private ImageIcon im_delup, im_deldo, im_delun;
private ImageIcon im_exitup, im_exitdo;
private ImageIcon im_aboutup, im_aboutdo;
private ImageIcon im_helpup, im_helpdo;
private ImageIcon im_optionsup, im_optionsdo;
/** Default font
*/
private Font f;
/** Do we have to login the user automatically if his password is in memory ?
* Automatic login makes that the password prompt doesn't displays if
* there is already a password in memory.
*
* This option is used only when we need to reconnect because the client
* account has moved to another server.
*/
private boolean automaticLogin;
/*------------------------------------------------------------------------------------*/
/** To set if we have to remember passwords or not
*/
static public void setRememberPasswords( boolean remember ) {
rememberPasswords = remember;
}
/** do we have to remember passwords ?
*/
static public boolean getRememberPasswords() {
return rememberPasswords;
}
/*------------------------------------------------------------------------------------*/
/** Constructor. Loads/create the different config files but does not display anything.
*/
public ClientManager( ResourceManager rManager ) {
super();
automaticLogin = false;
// 1 - We load the ProfileConfigList
profileConfigList = ProfileConfigList.load();
if ( profileConfigList == null ) {
Debug.signal( Debug.NOTICE, this, "no client's profile found : creating a new one..." );
profileConfigList = new ProfileConfigList();
}
else
Debug.signal( Debug.NOTICE, null, "Client Configs loaded with success !" );
if(!rememberPasswords) {
profileConfigList.deletePasswords(); // make sure we don't save any password here
profileConfigList.save();
}
// 2 - We load the ServerConfigManager
serverConfigManager = new ServerConfigManager( rManager );
serverConfigManager.setRemoteServerConfigHomeURL( ClientDirector.getRemoteServerConfigHomeURL() );
Debug.signal( Debug.NOTICE, null, "Server config Manager started with success !" );
// 3 - We get the font we are going to use...
f = FontFactory.getDefaultFontFactory().getFont("Lucida Blackletter");
}
/*------------------------------------------------------------------------------------*/
/** To get the Profile Config.
* @return the Profile Config
*/
public ProfileConfigList getProfileConfigList() {
return profileConfigList;
}
/** To get the current Profile Config.
* @return the ProfilesConfig
*/
public ProfileConfig getCurrentProfileConfig() {
return currentProfileConfig;
}
/*------------------------------------------------------------------------------------*/
/** To get the ServerConfigManager.
*
* @return the ServerConfigManager
*/
public ServerConfigManager getServerConfigManager() {
return serverConfigManager;
}
/*------------------------------------------------------------------------------------*/
/** To set automatic login or not.
* Automatic login makes that the password prompt doesn't displays if
* there is already a password in memory.
*
* This option is used only when we need to reconnect because the client
* account has moved to another server.
*/
public void setAutomaticLogin( boolean automaticLogin ) {
this.automaticLogin = automaticLogin;
}
/** Are we using automatic login or not ?
*/
public boolean getAutomaticLogin() {
return automaticLogin;
}
/*------------------------------------------------------------------------------------*/
/** Starts the Wizard at the beginning of the game
*/
public void start(int state) {
JPanel leftPanel;
JPanel rightPanel;
JScrollPane scrollPane;
ALabel label1;
ALabel label2;
ALabel label3;
ALabel label4;
ALabel label5;
JLabel imgLabel1;
JLabel imgLabel2;
final ATextField tfield1;
final ATextField atf_login;
final ATextField atf_key;
final APasswordField pfield1;
final APasswordField pfield2;
final JButton b_ok;
final JButton b_load;
final JButton b_help;
final JButton b_about;
final JButton b_option;
final JButton b_cancel;
final JButton b_newProfile;
final JButton b_delProfile;
final JButton b_exitProfile;
final JButton b_recoverProfile;
final JTable profilesTable;
final JTable serversTable ;
indexScreen = state;
switch(state) {
// ********************
// *** First Screen ***
// ********************
case FIRST_INIT:
// We try to contact the wotlas web server...
nbTry=1;
Timer timer = new Timer(5000,this);
timer.start();
serverConfigManager.getLatestConfigFiles(this);
timer.stop();
if( !serverConfigManager.hasRemoteServersInfo() )
JOptionPane.showMessageDialog( this, "We failed to contact the wotlas web server. So we could not update\n"+
"our servers addresses. If this is not the first time you start wotlas on\n"+
"your computer, you can try to connect with the previous server config\n"+
"files. Otherwise please restart wotlas later.\n\n"+
"Note also that wotlas is not firewall/proxy friendly. See our FAQ for\n"+
"more details ( from the help section or 'wotlas.html' local file ).",
"Warning", JOptionPane.WARNING_MESSAGE);
else // Wotlas News
new JHTMLWindow( this, "Wotlas News", ClientDirector.getRemoteServerConfigHomeURL()+"news.html",
320, 400, false, ClientDirector.getResourceManager() );
// Load images of buttons
im_cancelup = ClientDirector.getResourceManager().getImageIcon("cancel-up.gif");
im_canceldo = ClientDirector.getResourceManager().getImageIcon("cancel-do.gif");
im_cancelun = ClientDirector.getResourceManager().getImageIcon("cancel-un.gif");
im_okup = ClientDirector.getResourceManager().getImageIcon("ok-up.gif");
im_okdo = ClientDirector.getResourceManager().getImageIcon("ok-do.gif");
im_okun = ClientDirector.getResourceManager().getImageIcon("ok-un.gif");
im_recoverup = ClientDirector.getResourceManager().getImageIcon("recover-up.gif");
im_recoverdo = ClientDirector.getResourceManager().getImageIcon("recover-do.gif");
im_recoverun = ClientDirector.getResourceManager().getImageIcon("recover-un.gif");
im_delup = ClientDirector.getResourceManager().getImageIcon("delete-up.gif");
im_deldo = ClientDirector.getResourceManager().getImageIcon("delete-do.gif");
im_delun = ClientDirector.getResourceManager().getImageIcon("delete-un.gif");
im_exitup = ClientDirector.getResourceManager().getImageIcon("exit-up.gif");
im_exitdo = ClientDirector.getResourceManager().getImageIcon("exit-do.gif");
im_loadup = ClientDirector.getResourceManager().getImageIcon("load-up.gif");
im_loaddo = ClientDirector.getResourceManager().getImageIcon("load-do.gif");
im_loadun = ClientDirector.getResourceManager().getImageIcon("load-un.gif");
im_newup = ClientDirector.getResourceManager().getImageIcon("new-up.gif");
im_newdo = ClientDirector.getResourceManager().getImageIcon("new-do.gif");
im_aboutup = ClientDirector.getResourceManager().getImageIcon("about-up.gif");
im_aboutdo = ClientDirector.getResourceManager().getImageIcon("about-do.gif");
im_helpup = ClientDirector.getResourceManager().getImageIcon("help-up.gif");
im_helpdo = ClientDirector.getResourceManager().getImageIcon("help-do.gif");
im_optionsup = ClientDirector.getResourceManager().getImageIcon("options-up.gif");
im_optionsdo = ClientDirector.getResourceManager().getImageIcon("options-do.gif");
indexScreen = MAIN_SCREEN;
state = MAIN_SCREEN;
// Hide the Log Window ?
if( !ClientDirector.getClientConfiguration().getDisplayLogWindow() )
// ADD by DIEGO : REMOVE by DIEGO if( !ClientDirector.SHOW_DEBUG )
ClientDirector.getLogStream().setVisible( false );
// Test if an account exists
if ( profileConfigList.size()==0 ) {
start(ACCOUNT_CREATION_SCREEN);
return;
}
case MAIN_SCREEN:
setTitle("Wotlas - Account selection...");
SoundLibrary.getMusicPlayer().stopMusic();
// Create panels
leftPanel = new JPanel();
leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.Y_AXIS));
rightPanel = new JPanel();
rightPanel.setLayout(new FlowLayout(FlowLayout.CENTER, getRightWidth(), 5));
// Create buttons
b_about = new JButton(im_aboutup);
b_about.setRolloverIcon(im_aboutdo);
b_about.setPressedIcon(im_aboutdo);
b_about.setBorderPainted(false);
b_about.setContentAreaFilled(false);
b_about.setFocusPainted(false);
b_option = new JButton(im_optionsup);
b_option.setRolloverIcon(im_optionsdo);
b_option.setPressedIcon(im_optionsdo);
b_option.setBorderPainted(false);
b_option.setContentAreaFilled(false);
b_option.setFocusPainted(false);
b_ok = new JButton(im_okup);
b_ok.setRolloverIcon(im_okdo);
b_ok.setPressedIcon(im_okdo);
b_ok.setDisabledIcon(im_okun);
b_ok.setBorderPainted(false);
b_ok.setContentAreaFilled(false);
b_ok.setFocusPainted(false);
b_cancel = new JButton(im_cancelup);
b_cancel.setRolloverIcon(im_canceldo);
b_cancel.setPressedIcon(im_canceldo);
b_cancel.setDisabledIcon(im_cancelun);
b_cancel.setBorderPainted(false);
b_cancel.setContentAreaFilled(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -