KeyMappingDlg.cpp
上传用户:royluo
上传日期:2007-01-05
资源大小:1584k
文件大小:7k
源码类别:

游戏

开发平台:

Visual C++

  1. /*****************************************************************************
  2. *                                                                             
  3. *   KeyMappingDlg.cpp
  4. *                                                                             
  5. *   Electrical Engineering Faculty - Software Lab                             
  6. *   Spring semester 1998                                                      
  7. *                                                                             
  8. *   Tanks game                                                                
  9. *                                                                             
  10. *   Module description: Implements the key setting dialog that enables the user
  11. *                       to specify the tanks control keys.
  12. *                       
  13. *                                                                             
  14. *   Authors: Eran Yariv - 28484475                                           
  15. *            Moshe Zur  - 24070856                                           
  16. *                                                                            
  17. *                                                                            
  18. *   Date: 23/09/98                                                           
  19. *                                                                            
  20. ******************************************************************************/
  21. #include "stdafx.h"
  22. #include "tanks.h"
  23. #include "KeyMappingDlg.h"
  24. #ifdef _DEBUG
  25. #define new DEBUG_NEW
  26. #undef THIS_FILE
  27. static char THIS_FILE[] = __FILE__;
  28. #endif
  29. /////////////////////////////////////////////////////////////////////////////
  30. // CKeyMappingDlg dialog
  31. // Default Ctor
  32. CKeyMappingDlg::CKeyMappingDlg(CKeysTable* pKeys, CWnd* pParent)
  33. : CDialog(CKeyMappingDlg::IDD, pParent), m_pKeys(pKeys),
  34.     m_Right(pKeys, CManouverSet::TURN_RIGHT), 
  35.     m_Left(pKeys, CManouverSet::TURN_LEFT), 
  36.     m_Shell(pKeys, CManouverSet::FIRE_SHELL), 
  37.     m_Bullet(pKeys, CManouverSet::FIRE_BULLET),
  38.     m_Mine(pKeys, CManouverSet::DROP_MINE), 
  39.     m_Backward(pKeys, CManouverSet::BACKWARD), 
  40.     m_Aerial(pKeys, CManouverSet::AERIAL_SUPPORT), 
  41.     m_Forward(pKeys, CManouverSet::FORWARD)
  42. {
  43. //{{AFX_DATA_INIT(CKeyMappingDlg)
  44. //}}AFX_DATA_INIT
  45. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  46. m_hIcon = TANKS_APP->LoadIcon(IDR_MAINFRAME);
  47. }
  48. void CKeyMappingDlg::DoDataExchange(CDataExchange* pDX)
  49. {
  50. CDialog::DoDataExchange(pDX);
  51. //{{AFX_DATA_MAP(CKeyMappingDlg)
  52. DDX_Control(pDX, IDC_EDIT_TURN_RIGHT, m_Right);
  53. DDX_Control(pDX, IDC_EDIT_TURN_LEFT, m_Left);
  54. DDX_Control(pDX, IDC_EDIT_FIRE_SHELL, m_Shell);
  55. DDX_Control(pDX, IDC_EDIT_FIRE_BULLET, m_Bullet);
  56. DDX_Control(pDX, IDC_EDIT_DROP_MINE, m_Mine);
  57. DDX_Control(pDX, IDC_EDIT_BACKWARD, m_Backward);
  58. DDX_Control(pDX, IDC_EDIT_AERIAL_SUPPORT, m_Aerial);
  59. DDX_Control(pDX, IDC_EDIT_FORWARD, m_Forward);
  60. DDX_Control(pDX, IDOK, m_ctrOK);
  61. DDX_Control(pDX, IDCANCEL, m_ctrCancel);
  62. DDX_Control(pDX, IDC_BUTTON_DEFAULT_SETTINGS, m_ctrDefault);
  63. //}}AFX_DATA_MAP
  64. }
  65. BEGIN_MESSAGE_MAP(CKeyMappingDlg, CDialog)
  66. //{{AFX_MSG_MAP(CKeyMappingDlg)
  67. ON_BN_CLICKED(IDC_BUTTON_DEFAULT_SETTINGS, OnButtonDefaultSettings)
  68. ON_EN_SETFOCUS(IDC_EDIT_AERIAL_SUPPORT, OnSetfocusEditAerialSupport)
  69. ON_EN_SETFOCUS(IDC_EDIT_BACKWARD, OnSetfocusEditBackward)
  70. ON_EN_SETFOCUS(IDC_EDIT_DROP_MINE, OnSetfocusEditDropMine)
  71. ON_EN_SETFOCUS(IDC_EDIT_FIRE_BULLET, OnSetfocusEditFireBullet)
  72. ON_EN_SETFOCUS(IDC_EDIT_FIRE_SHELL, OnSetfocusEditFireShell)
  73. ON_EN_SETFOCUS(IDC_EDIT_FORWARD, OnSetfocusEditForward)
  74. ON_EN_SETFOCUS(IDC_EDIT_TURN_LEFT, OnSetfocusEditTurnLeft)
  75. ON_EN_SETFOCUS(IDC_EDIT_TURN_RIGHT, OnSetfocusEditTurnRight)
  76. ON_WM_LBUTTONDOWN()
  77. ON_WM_PAINT()
  78. //}}AFX_MSG_MAP
  79. END_MESSAGE_MAP()
  80. /////////////////////////////////////////////////////////////////////////////
  81. // CKeyMappingDlg message handlers
  82. BOOL CKeyMappingDlg::OnInitDialog()
  83. {
  84. CDialog::OnInitDialog();
  85. /*
  86. // Add "About..." menu item to system menu.
  87. // IDM_ABOUTBOX must be in the system command range.
  88. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  89. ASSERT(IDM_ABOUTBOX < 0xF000);
  90. CMenu* pSysMenu = GetSystemMenu(FALSE);
  91. if (pSysMenu != NULL)
  92. {
  93. CString strAboutMenu;
  94. strAboutMenu.LoadString(IDS_ABOUTBOX);
  95. if (!strAboutMenu.IsEmpty())
  96. {
  97. pSysMenu->AppendMenu(MF_SEPARATOR);
  98. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99. }
  100. }
  101. // Set the icon for this dialog.  The framework does this automatically
  102. //  when the application's main window is not a dialog
  103. SetIcon(m_hIcon, TRUE); // Set big icon
  104. SetIcon(m_hIcon, FALSE); // Set small icon
  105. */
  106. // Init edit boxes with current keys setting:
  107.     UpdateAllCEdit ();
  108. m_ctrCancel.LoadAVI(IDR_AVI_CANCEL);
  109. m_ctrOK.LoadAVI(IDR_AVI_OK);
  110. m_ctrDefault.LoadAVI(IDR_AVI_DEFAULT);
  111. return TRUE;  // return TRUE  unless you set the focus to a control
  112. }
  113. void CKeyMappingDlg::OnOK() 
  114. {
  115. // UpdateData(TRUE);
  116.     CDialog::OnOK();
  117. }
  118. void CKeyMappingDlg::UpdateAllCEdit()
  119. {
  120.     m_Right.UpdateText();
  121.     m_Left.UpdateText();
  122.     m_Shell.UpdateText();
  123.     m_Bullet.UpdateText();
  124.     m_Mine.UpdateText();
  125.     m_Backward.UpdateText();
  126.     m_Aerial.UpdateText();
  127.     m_Forward.UpdateText();
  128.     /*
  129.     for (int i = 0; i < CManouverSet::MAX_MANOUVER_BIT; i++)
  130.     {
  131.         CString cstr;
  132.             // Get key's caption:
  133.         BOOL KeyIsValid = KeyToString(m_pKeys->GetKey(i), cstr);
  134.         ASSERT (KeyIsValid);
  135.             // Set edit control:
  136.         GetDlgItem(IDC_EDIT_TURN_RIGHT + i) -> SetWindowText(cstr);
  137.     }
  138.     */
  139. }
  140. void CKeyMappingDlg::OnButtonDefaultSettings() 
  141. {
  142. // Reset all controls to default
  143. m_pKeys->RestoreDefault();
  144.     UpdateAllCEdit();
  145. }
  146. void CKeyMappingDlg::OnSetfocusEditAerialSupport() 
  147. {
  148.     m_Aerial.PostMessage(WM_LBUTTONDBLCLK,0,0);
  149. }
  150. void CKeyMappingDlg::OnSetfocusEditBackward() 
  151. {
  152.     m_Backward.PostMessage(WM_LBUTTONDBLCLK,0,0);
  153. }
  154. void CKeyMappingDlg::OnSetfocusEditDropMine() 
  155. {
  156.     m_Mine.PostMessage(WM_LBUTTONDBLCLK,0,0);
  157. }
  158. void CKeyMappingDlg::OnSetfocusEditFireBullet() 
  159. {
  160.     m_Bullet.PostMessage(WM_LBUTTONDBLCLK,0,0);
  161. }
  162. void CKeyMappingDlg::OnSetfocusEditFireShell() 
  163. {
  164.     m_Shell.PostMessage(WM_LBUTTONDBLCLK,0,0);
  165. }
  166. void CKeyMappingDlg::OnSetfocusEditForward() 
  167. {
  168.     m_Forward.PostMessage(WM_LBUTTONDBLCLK,0,0);
  169. }
  170. void CKeyMappingDlg::OnSetfocusEditTurnLeft() 
  171. {
  172.     m_Left.PostMessage(WM_LBUTTONDBLCLK,0,0);
  173. }
  174. void CKeyMappingDlg::OnSetfocusEditTurnRight() 
  175. {
  176.     m_Right.PostMessage(WM_LBUTTONDBLCLK,0,0);
  177. }