www.pudn.com > uoth_src.zip > CharacterDlg.cpp
//----------------------------------------------------------------------------- // // @doc // // @module CharacterDlg.cpp - Character configuration dialog | // // This module contains the definition of the character configuration dialog. // // Copyright (c) 2002 - Descartes Systems Sciences, Inc. // // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // 1. Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // 2. Neither the name of Descartes Systems Sciences, Inc nor the names of // its contributors may be used to endorse or promote products derived // from this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // // @end // // $History: CharacterDlg.cpp $ // //----------------------------------------------------------------------------- #include "stdafx.h" #include "resource.h" #include "CharacterDlg.h" #include "Character.h" #include "uoth.h" // // Externals // extern TCHAR g_szAppName []; //----------------------------------------------------------------------------- // // @mfuncconstructor. // // @parm CCharacter * | pCharacter | Character being edited // or a NULL if a new character is being added. // // @rdesc None. // //----------------------------------------------------------------------------- CCharacterDlg::CCharacterDlg (CCharacter *pCharacter) { m_pCharacter = pCharacter; } //----------------------------------------------------------------------------- // // @mfunc destructor. // // @rdesc None. // //----------------------------------------------------------------------------- CCharacterDlg::~CCharacterDlg() { } //----------------------------------------------------------------------------- // // @mfunc Initialize the dialog // // @parm UINT | uMsg | Message // // @parm WPARAM | wParam | Message w-parameter // // @parm LPARAM | lParam | Message l-parameter // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CCharacterDlg::OnInitDialog (UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { // // Subclass the controls // m_editName = GetDlgItem (IDC_CHARACTER_NAME); m_editName .LimitText (32); // // Center the window // CenterWindow (); // // Populate the name // m_editName .SetWindowText (m_pCharacter ? m_pCharacter ->m_strName : CString (MAKEINTRESOURCE (IDS_NEW_CHARACTER_NAME))); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle the user press Ok // // @parm WORD | wNotifyCode | Command notification code // // @parm WORD | wID | ID of the control // // @parm HWND | hWndCtl | Handle of the control // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CCharacterDlg::OnOk (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // Get the character name // CString strCharacter; m_editName .GetWindowText (strCharacter); // // Check for valid character name // strCharacter .TrimRight (); strCharacter .TrimLeft (); if (!IsValidName (strCharacter)) { CString str (MAKEINTRESOURCE (IDS_ERR_INVALID_CHARACTER_NAME)); ::MessageBox (m_hWnd, str, g_szAppName, MB_OK); return TRUE; } // // Check for duplicate // CCharacter *pCharacter = CCharacter::Find (strCharacter); if (pCharacter != NULL && pCharacter != m_pCharacter) { CString str (MAKEINTRESOURCE (IDS_ERR_DUPLICATE_CHARACTER_NAME)); ::MessageBox (m_hWnd, str, g_szAppName, MB_OK); return TRUE; } // // Add/Modify the character // if (m_pCharacter) m_pCharacter ->m_strName = strCharacter; else m_pCharacter = CCharacter::Add (strCharacter); // // End the dialog // EndDialog (IDOK); return TRUE; } //----------------------------------------------------------------------------- // // @mfunc Handle the user press Ok // // @parm WORD | wNotifyCode | Command notification code // // @parm WORD | wID | ID of the control // // @parm HWND | hWndCtl | Handle of the control // // @parm BOOL & | bHandled | If handled, set to true // // @rdesc Routine results // //----------------------------------------------------------------------------- LRESULT CCharacterDlg::OnCancel (WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled) { // // End the dialog // EndDialog (IDCANCEL); return TRUE; }