⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chwlistd.cpp

📁 Windows上的MUD客户端程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:

		ChWorldListEdit		editDlg( strOldName, GetDesc(), GetHost(),
										GetPort(), GetType(), GetLoginType(),
										GetUsername(), GetPassword(),
										GetHomePage() );
		int					iResult;

		iResult = editDlg.DoModal();

		if (IDOK == iResult)
		{
			string	strNewName( editDlg.GetName() );
			string	strNewUsername( editDlg.GetUsername() );

			ASSERT( variableLogin != editDlg.GetLoginType() );

			if ((strOldName == strNewName) &&
				(strOldUsername == strNewUsername))
			{
				Add( true, strOldName, editDlg.GetDesc(), editDlg.GetHost(),
						editDlg.GetPort(), editDlg.GetType(),
						editDlg.GetLoginType(), editDlg.GetUsername(),
						editDlg.GetPassword(), editDlg.GetHomePage() );
			}
			else
			{
				int		iIndex;
											// Delete the old item

				if (LB_ERR != (iIndex = m_listWorlds.GetCurSel()))
				{
					Delete( iIndex );
				}
											// Add a new item (new name)

				Add( false, strNewName, editDlg.GetDesc(),
						editDlg.GetHost(), editDlg.GetPort(),
						editDlg.GetType(), editDlg.GetLoginType(),
						editDlg.GetUsername(), editDlg.GetPassword(),
						editDlg.GetHomePage() );
			}
		}
	}

	UpdateButtons();
}


void ChWorldListDlg::OnSelchangeWorldList()
{
	if (SyncDataFields())
	{
		UpdateData( false );
	}
}


/*----------------------------------------------------------------------------
	ChWorldListEdit class
----------------------------------------------------------------------------*/

ChWorldListEdit::ChWorldListEdit( CWnd* pParent ) :
					CDialog( ChWorldListEdit::IDD, pParent ),
					m_boolNew( true ),
					m_type( otherType ),
					m_loginType( unamePwLogin )
{
	//{{AFX_DATA_INIT(ChWorldListEdit)
	m_strName = _T("");
	m_strType = _T("");
	m_strDesc = _T("");
	m_strHost = _T("");
	m_sPort = 0;
	m_strUsername = _T("");
	m_strPassword = _T("");
	m_iLoginStyle = 0;
	m_strHomePage = _T("");
	//}}AFX_DATA_INIT
}


ChWorldListEdit::ChWorldListEdit( const string& strName, const string& strDesc,
									const string& strHost, chint16 sPort,
									ChWorldType type, ChLoginType loginType,
									const string& strUsername,
									const string& strPassword,
									const string& strHomePage, CWnd* pParent ) :
					CDialog( ChWorldListEdit::IDD, pParent ),
					m_boolNew( false ),
					m_strName( strName ),
					m_strDesc( strDesc ),
					m_strHost( strHost ),
					m_sPort( sPort ),
					m_type( type ),
					m_loginType( loginType ),
					m_strUsername( strUsername ),
					m_strPassword( strPassword ),
					m_strHomePage( strHomePage )
{
}


void ChWorldListEdit::DoDataExchange( CDataExchange* pDX )
{
	CDialog::DoDataExchange( pDX );

	//{{AFX_DATA_MAP(ChWorldListEdit)
	DDX_Control(pDX, IDC_LIST_WEB_PAGE, m_editHomePage);
	DDX_Control(pDX, IDC_RADIO_LOGIN_MUD, m_radioMudLogin);
	DDX_Control(pDX, IDC_RADIO_LOGIN_CONNECT, m_radioConnectLogin);
	DDX_Control(pDX, IDC_WORLD_LIST_TYPE, m_comboTypes);
	DDX_Control(pDX, IDC_STATIC_MESSAGE, m_staticMessage);
	DDX_Control(pDX, IDC_LIST_USERNAME, m_editUsername);
	DDX_Control(pDX, IDC_LIST_PASSWORD, m_editPassword);
	DDX_Control(pDX, IDOK, m_btnOkay);
	DDX_Control(pDX, IDC_LIST_PORT, m_editPort);
	DDX_Control(pDX, IDC_LIST_NAME, m_editName);
	DDX_Control(pDX, IDC_LIST_HOST, m_editHost);
	DDX_Control(pDX, IDC_LIST_DESC, m_editDesc);
	DDX_Text(pDX, IDC_LIST_NAME, m_strName);
	DDX_CBString(pDX, IDC_WORLD_LIST_TYPE, m_strType);
	DDX_Text(pDX, IDC_LIST_DESC, m_strDesc);
	DDX_Text(pDX, IDC_LIST_HOST, m_strHost);
	DDX_Text(pDX, IDC_LIST_PORT, m_sPort);
	DDX_Text(pDX, IDC_LIST_USERNAME, m_strUsername);
	DDX_Text(pDX, IDC_LIST_PASSWORD, m_strPassword);
	DDX_Radio(pDX, IDC_RADIO_LOGIN_MUD, m_iLoginStyle);
	DDX_Text(pDX, IDC_LIST_WEB_PAGE, m_strHomePage);
	//}}AFX_DATA_MAP

	if (pDX->m_bSaveAndValidate)
	{
		if (m_strType.GetLength())
		{
			m_type.Set( m_strType );
		}

		if (0 == m_iLoginStyle)
		{
			m_loginType = unamePwLogin;
		}
		else
		{
			m_loginType = connectLogin;
		}
	}
	else
	{
		switch( m_loginType )
		{
			case connectLogin:
			{
				m_iLoginStyle = 1;
				break;
			}

			case unamePwLogin:
			default:
			{
				m_iLoginStyle = 0;
				break;
			}
		}

		if (m_type == undefinedType)
		{
			m_comboTypes.SetCurSel( -1 );
		}
		else
		{
			m_comboTypes.SelectString( -1, m_type.GetName() );
		}
	}
}


void ChWorldListEdit::UpdateButtons()
{
	bool		boolEnable = false;
	bool		boolEnableLoginType = true;

	UpdateData();

	if (m_strName.GetLength() && m_strHost.GetLength() &&
			m_sPort > 0)
	{
		if (m_comboTypes.GetCurSel() != LB_ERR)
		{
			boolEnable = true;
		}
	}

	m_btnOkay.EnableWindow( boolEnable );

	if ("" == m_strType)
	{
		m_iLoginStyle = 0;
		boolEnableLoginType = false;
	}
	else
	{
		switch( m_type.GetLoginType() )
		{
			case variableLogin:
			{
				boolEnableLoginType = true;
				break;
			}

			case unamePwLogin:
			{
				m_iLoginStyle = 0;
				boolEnableLoginType = false;
				break;
			}

			case connectLogin:
			{
				m_iLoginStyle = 1;
				boolEnableLoginType = false;
				break;
			}
		}
	}

	UpdateData( false );

	m_radioMudLogin.EnableWindow( boolEnableLoginType );
	m_radioConnectLogin.EnableWindow( boolEnableLoginType );
}


void ChWorldListEdit::UpdateWarningMessage()
{
	string		strOldMessage;
	string		strMessage;
	int			iUsernameLen;
	int			iPasswordLen;

	UpdateData();

	iUsernameLen = m_strUsername.GetLength();
	iPasswordLen = m_strPassword.GetLength();

	if (iUsernameLen || iPasswordLen)
	{
		if (!GetType().IsValidType())
		{
			LOADSTRING( IDS_WARNING_WORLD_TYPE_MISSING, strMessage );
		}
		else
		{
			if (0 == iPasswordLen)
			{
				if (connectLogin == GetLoginType())
				{
					LOADSTRING( IDS_WARNING_MUSH_TYPE, strMessage );
				}
				else
				{
					LOADSTRING( IDS_WARNING_NO_PASSWORD, strMessage );
				}
			}
		}
	}

	m_staticMessage.GetWindowText( strOldMessage );
	if (strOldMessage != strMessage)
	{
		m_staticMessage.SetWindowText( strMessage );
	}
}


void ChWorldListEdit::RemoveIllegalChars( CEdit& edit )
{
	int		iStart;
	int		iEnd;
	string	strText;
	int		iLoc;
	bool	boolChanged = false;

	edit.GetSel( iStart, iEnd );
	edit.GetWindowText( strText );

	while (-1 != (iLoc = strText.Find( WORLD_NAME_SEPARATOR )))
	{
		strText = strText.Left( iLoc ) + strText.Mid( iLoc + 1 );
		iStart--;
		boolChanged = true;
	}

	if (boolChanged)
	{
		edit.SetWindowText( strText );
		edit.SetSel( iStart, iStart );
	}
}


BEGIN_MESSAGE_MAP( ChWorldListEdit, CDialog )
	//{{AFX_MSG_MAP(ChWorldListEdit)
	ON_EN_CHANGE(IDC_LIST_NAME, OnChangeListName)
	ON_EN_CHANGE(IDC_LIST_HOST, OnChangeListHost)
	ON_EN_CHANGE(IDC_LIST_PORT, OnChangeListPort)
	ON_CBN_SELCHANGE(IDC_WORLD_LIST_TYPE, OnSelchangeListType)
	ON_EN_CHANGE(IDC_LIST_PASSWORD, OnChangeListPassword)
	ON_EN_CHANGE(IDC_LIST_USERNAME, OnChangeListUsername)
	ON_BN_CLICKED(IDC_RADIO_LOGIN_CONNECT, OnRadioLoginConnect)
	ON_BN_CLICKED(IDC_RADIO_LOGIN_MUD, OnRadioLoginMud)
	ON_EN_UPDATE(IDC_LIST_NAME, OnUpdateListName)
	ON_EN_UPDATE(IDC_LIST_USERNAME, OnUpdateListUsername)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/*----------------------------------------------------------------------------
	ChWorldListEdit message handlers
----------------------------------------------------------------------------*/

bool ChWorldListEdit::OnInitDialog()
{
	CDialog::OnInitDialog();
	CenterWindow();

	m_editName.LimitText( 30 );
	m_editHost.LimitText( 255 );
	m_editPort.LimitText( 5 );
	m_editHomePage.LimitText( 1024 );
	m_editDesc.LimitText( 1024 );
	m_editUsername.LimitText( 30 );
	m_editPassword.LimitText( 30 );

	ChWorldType::FillTypeList( &m_comboTypes );

	if (IsNew())
	{
		m_editName.SetFocus();
	}
	else
	{
		m_editHost.SetFocus();
		m_editHost.SetSel( 0, -1 );
	}
											/* Update data again since we've
												added the entries to the Types
												combo box */
	UpdateData( false );
	UpdateButtons();

	return false;
}


void ChWorldListEdit::OnUpdateListName() 
{
	RemoveIllegalChars( m_editName );
}


void ChWorldListEdit::OnChangeListName() 
{
	UpdateButtons();
}

void ChWorldListEdit::OnChangeListHost() 
{
	UpdateButtons();
}

void ChWorldListEdit::OnChangeListPort() 
{
	UpdateButtons();
}

void ChWorldListEdit::OnSelchangeListType() 
{
	UpdateButtons();
	UpdateWarningMessage();
}


void ChWorldListEdit::OnUpdateListUsername() 
{
	RemoveIllegalChars( m_editUsername );
}


void ChWorldListEdit::OnChangeListUsername() 
{
	UpdateWarningMessage();
}

void ChWorldListEdit::OnChangeListPassword() 
{
	UpdateWarningMessage();
}


void ChWorldListEdit::OnRadioLoginConnect() 
{
	UpdateWarningMessage();
}


void ChWorldListEdit::OnRadioLoginMud() 
{
	UpdateWarningMessage();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -