DlgPlayerSettings.cpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. /* Copyright (c) 2002-2012 Croteam Ltd.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of version 2 of the GNU General Public License as published by
  4. the Free Software Foundation
  5. This program is distributed in the hope that it will be useful,
  6. but WITHOUT ANY WARRANTY; without even the implied warranty of
  7. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  8. GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along
  10. with this program; if not, write to the Free Software Foundation, Inc.,
  11. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */
  12. // DlgPlayerSettings.cpp : implementation file
  13. //
  14. #include "stdafx.h"
  15. #ifdef _DEBUG
  16. #undef new
  17. #define new DEBUG_NEW
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CDlgPlayerSettings dialog
  23. CDlgPlayerSettings::CDlgPlayerSettings(CWnd* pParent /*=NULL*/)
  24. : CDialog(CDlgPlayerSettings::IDD, pParent)
  25. {
  26. //{{AFX_DATA_INIT(CDlgPlayerSettings)
  27. //}}AFX_DATA_INIT
  28. }
  29. void CDlgPlayerSettings::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(CDlgPlayerSettings)
  33. DDX_Control(pDX, IDC_AVAILABLE_CONTROLS, m_listAvailableControls);
  34. DDX_Control(pDX, IDC_AVAILABLE_PLAYERS, m_listAvailablePlayers);
  35. //}}AFX_DATA_MAP
  36. // if dialog is giving data
  37. if( pDX->m_bSaveAndValidate != FALSE)
  38. {
  39. // get selected player
  40. INDEX iSelectedPlayer = m_listAvailablePlayers.GetCurSel();
  41. ASSERT( iSelectedPlayer != LB_ERR);
  42. // remember selected player
  43. _pGame->gm_iWEDSinglePlayer = iSelectedPlayer;
  44. // get selected controls
  45. INDEX iSelectedControls = m_listAvailableControls.GetCurSel();
  46. ASSERT( iSelectedControls != LB_ERR);
  47. // remember selected controls
  48. // _pGame->gm_apiPlayerInfo[iSelectedPlayer].pi_iControls = iSelectedControls;
  49. }
  50. }
  51. BEGIN_MESSAGE_MAP(CDlgPlayerSettings, CDialog)
  52. //{{AFX_MSG_MAP(CDlgPlayerSettings)
  53. ON_BN_CLICKED(IDC_PLAYER_APPEARANCE, OnPlayerAppearance)
  54. ON_BN_CLICKED(IDC_EDIT_CONTROLS, OnEditControls)
  55. ON_BN_CLICKED(IDC_RENAME_CONTROLS, OnRenameControls)
  56. ON_BN_CLICKED(IDC_RENAME_PLAYER, OnRenamePlayer)
  57. //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CDlgPlayerSettings message handlers
  61. void CDlgPlayerSettings::OnPlayerAppearance()
  62. {
  63. return;
  64. /*
  65. CPlayerInfo plPlayerInfo;
  66. // get selected player
  67. INDEX iSelectedPlayer = m_listAvailablePlayers.GetCurSel();
  68. ASSERT( iSelectedPlayer != LB_ERR);
  69. CTFileName fnPlayerName;
  70. fnPlayerName.PrintF( "%sPlayers\\Player%d.plr", iSelectedPlayer);
  71. try
  72. {
  73. // load it from the file
  74. plPlayerInfo.Load_t( fnPlayerName);
  75. // call player appearance dialog
  76. CDlgPlayerAppearance dlgPlayerAppearance( plPlayerInfo.pi_pcPlayerCharacter);
  77. // if user wants to change player's appearance
  78. if( dlgPlayerAppearance.DoModal() == IDOK)
  79. {
  80. // set new appearance
  81. plPlayerInfo.pi_pcPlayerCharacter = dlgPlayerAppearance.m_pcPlayerCharacter;
  82. // and save new player's attributes
  83. plPlayerInfo.Save_t( fnPlayerName);
  84. // reload players and controls
  85. _pGame->LoadPlayersAndControls();
  86. }
  87. }
  88. catch (char *strError)
  89. {
  90. AfxMessageBox( strError);
  91. }
  92. */
  93. }
  94. void CDlgPlayerSettings::InitPlayersAndControlsLists(void)
  95. {
  96. if( !::IsWindow( m_listAvailablePlayers.m_hWnd)) return;
  97. m_listAvailablePlayers.ResetContent();
  98. m_listAvailableControls.ResetContent();
  99. // fill players and controls lists
  100. for( INDEX iPC=0; iPC<8; iPC++)
  101. {
  102. CTString strPlayer = _pGame->gm_apcPlayers[ iPC].pc_strName;
  103. m_listAvailablePlayers.AddString( strPlayer);
  104. //CTString strControls = _pGame->gm_actrlControls[ iPC].ctrl_strName;
  105. m_listAvailableControls.AddString( "dummy");
  106. }
  107. m_listAvailableControls.SetCurSel( 0);
  108. m_listAvailablePlayers.SetCurSel( 0);
  109. }
  110. BOOL CDlgPlayerSettings::OnInitDialog()
  111. {
  112. CDialog::OnInitDialog();
  113. InitPlayersAndControlsLists();
  114. return TRUE;
  115. }
  116. void CDlgPlayerSettings::OnEditControls()
  117. {
  118. CControls &ctrlControls = _pGame->gm_ctrlControlsExtra;
  119. // try to
  120. try
  121. {
  122. // get selected controls
  123. INDEX iSelectedControls = m_listAvailableControls.GetCurSel();
  124. ASSERT( iSelectedControls != LB_ERR);
  125. CTFileName fnControlsName;
  126. fnControlsName.PrintF( "Controls\\Controls%d.ctl", iSelectedControls);
  127. // load it from the file
  128. ctrlControls.Load_t( fnControlsName);
  129. // call controls dialog
  130. CDlgPlayerControls dlgControls( ctrlControls);
  131. // if user wants to change controls
  132. if( dlgControls.DoModal() == IDOK)
  133. {
  134. // set new controls
  135. ctrlControls = dlgControls.m_ctrlControls;
  136. // depending on axis attributes and type (rotation or translation), calculates axis
  137. // influence factors for all axis actions
  138. ctrlControls.CalculateInfluencesForAllAxis();
  139. // save new controls
  140. ctrlControls.Save_t( fnControlsName);
  141. // reload players and controls
  142. _pGame->LoadPlayersAndControls();
  143. }
  144. }
  145. catch (char *strError)
  146. {
  147. AfxMessageBox( strError);
  148. return;
  149. }
  150. }
  151. void CDlgPlayerSettings::OnRenameControls()
  152. {
  153. CDlgRenameControls dlgRename;
  154. // get selected controls
  155. INDEX iSelectedControls = m_listAvailableControls.GetCurSel();
  156. ASSERT( iSelectedControls != LB_ERR);
  157. // CTString strName = _pGame->gm_actrlControls[ iSelectedControls].ctrl_strName;
  158. dlgRename.m_strName = "dummy";
  159. // if new file properly edited and ok pressed
  160. if( (dlgRename.DoModal() == IDOK) &&
  161. (strlen( dlgRename.m_strName) != 0) )
  162. {
  163. // _pGame->gm_actrlControls[ iSelectedControls].ctrl_strName = dlgRename.m_strName;
  164. // save players and controls
  165. _pGame->SavePlayersAndControls();
  166. InitPlayersAndControlsLists();
  167. }
  168. }
  169. void CDlgPlayerSettings::OnRenamePlayer()
  170. {
  171. CDlgRenameControls dlgRename;
  172. // get selected controls
  173. INDEX iSelectedPlayer = m_listAvailablePlayers.GetCurSel();
  174. ASSERT( iSelectedPlayer != LB_ERR);
  175. CTString strName = _pGame->gm_apcPlayers[ iSelectedPlayer].pc_strName;
  176. dlgRename.m_strName = strName;
  177. // if new file properly edited and ok pressed
  178. if( (dlgRename.DoModal() == IDOK) &&
  179. (strlen( dlgRename.m_strName) != 0) )
  180. {
  181. _pGame->gm_apcPlayers[ iSelectedPlayer].pc_strName = dlgRename.m_strName;
  182. // save players and controls
  183. _pGame->SavePlayersAndControls();
  184. InitPlayersAndControlsLists();
  185. }
  186. }