DlgPlayerControls.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  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. // DlgPlayerControls.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. // CDlgPlayerControls dialog
  23. CDlgPlayerControls::CDlgPlayerControls(CControls &ctrlControls, CWnd* pParent /*=NULL*/)
  24. : CDialog(CDlgPlayerControls::IDD, pParent), m_ctrlControls(_pGame->gm_ctrlControlsExtra)
  25. {
  26. // make copy of the controls, we will change them
  27. m_ctrlControls = ctrlControls;
  28. //{{AFX_DATA_INIT(CDlgPlayerControls)
  29. m_bInvertControler = FALSE;
  30. m_iRelativeAbsoluteType = -1;
  31. m_strPressNewButton = _T("");
  32. //}}AFX_DATA_INIT
  33. }
  34. void CDlgPlayerControls::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. INDEX iSelectedAxis = -1;
  38. BOOL bEnableControls;
  39. // if list control window is created
  40. if( IsWindow(m_listAxisActions.m_hWnd))
  41. {
  42. // if dialog is recieving data
  43. if( pDX->m_bSaveAndValidate == FALSE)
  44. {
  45. iSelectedAxis = m_listAxisActions.GetNextItem( -1, LVNI_SELECTED);
  46. if( iSelectedAxis != -1)
  47. {
  48. // enable combo control
  49. m_comboControlerAxis.EnableWindow();
  50. // get curently mounted controler description
  51. CTString strControlerName = m_listAxisActions.GetItemText( iSelectedAxis, 1);
  52. // find in combo currently selected mounted axis
  53. int iComboEntry = m_comboControlerAxis.FindStringExact( -1, strControlerName);
  54. // and select it
  55. m_comboControlerAxis.SetCurSel( iComboEntry);
  56. // if axis none is selected, disable sensitivity and other additional controls for axis
  57. if( m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_iAxisAction == AXIS_NONE)
  58. {
  59. // disable controls for defining controler's attributes
  60. bEnableControls = FALSE;
  61. }
  62. else
  63. {
  64. // enable controls for defining controler's attributes
  65. bEnableControls = TRUE;
  66. // and get sensitivity slider state
  67. m_sliderControlerSensitivity.SetPos(
  68. m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_fSensitivity /
  69. (100/SENSITIVITY_SLIDER_POSITIONS) );
  70. // get state of invert axis check box
  71. m_bInvertControler = m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_bInvert;
  72. // get radio value (relative/absolute type of controler)
  73. if( m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_bRelativeControler)
  74. {
  75. m_iRelativeAbsoluteType = 0;
  76. }
  77. else
  78. {
  79. m_iRelativeAbsoluteType = 1;
  80. }
  81. }
  82. }
  83. else
  84. {
  85. // disable combo control
  86. m_comboControlerAxis.EnableWindow( FALSE);
  87. // disable controls for defining controler's attributes
  88. bEnableControls = FALSE;
  89. }
  90. m_sliderControlerSensitivity.EnableWindow( bEnableControls);
  91. GetDlgItem( IDC_INVERT_CONTROLER)->EnableWindow( bEnableControls);
  92. GetDlgItem( IDC_RELATIVE_ABSOLUTE_TYPE)->EnableWindow( bEnableControls);
  93. GetDlgItem( IDC_CONTROLER_SENSITIVITY)->EnableWindow( bEnableControls);
  94. GetDlgItem( IDC_ABSOLUTE_RADIO)->EnableWindow(bEnableControls);
  95. GetDlgItem( IDC_CONTROLER_TYPE_T)->EnableWindow(bEnableControls);
  96. GetDlgItem( IDC_CONTROLER_SENSITIVITY_T)->EnableWindow(bEnableControls);
  97. }
  98. }
  99. //{{AFX_DATA_MAP(CDlgPlayerControls)
  100. DDX_Control(pDX, IDC_AXIS_ACTIONS_LIST, m_listAxisActions);
  101. DDX_Control(pDX, IDC_BUTTON_ACTIONS_LIST, m_listButtonActions);
  102. DDX_Control(pDX, IDC_EDIT_SECOND_CONTROL, m_editSecondControl);
  103. DDX_Control(pDX, IDC_EDIT_FIRST_CONTROL, m_editFirstControl);
  104. DDX_Control(pDX, IDC_CONTROLER_SENSITIVITY, m_sliderControlerSensitivity);
  105. DDX_Control(pDX, IDC_CONTROLER_AXIS, m_comboControlerAxis);
  106. DDX_Check(pDX, IDC_INVERT_CONTROLER, m_bInvertControler);
  107. DDX_Radio(pDX, IDC_RELATIVE_ABSOLUTE_TYPE, m_iRelativeAbsoluteType);
  108. DDX_Text(pDX, IDC_PRESS_MESSAGE, m_strPressNewButton);
  109. //}}AFX_DATA_MAP
  110. // if dialog is giving data
  111. if( pDX->m_bSaveAndValidate != FALSE)
  112. {
  113. iSelectedAxis = m_listAxisActions.GetNextItem( -1, LVNI_SELECTED);
  114. // if there is valid selection
  115. if( iSelectedAxis != -1)
  116. {
  117. // apply check box
  118. m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_bInvert = m_bInvertControler;
  119. // apply relative/absolute radio
  120. if( m_iRelativeAbsoluteType == 0)
  121. {
  122. m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_bRelativeControler = TRUE;
  123. }
  124. else
  125. {
  126. m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_bRelativeControler = FALSE;
  127. }
  128. // apply sensitivity slider value
  129. m_ctrlControls.ctrl_aaAxisActions[ iSelectedAxis].aa_fSensitivity =
  130. m_sliderControlerSensitivity.GetPos() * (100/SENSITIVITY_SLIDER_POSITIONS);
  131. }
  132. }
  133. }
  134. BEGIN_MESSAGE_MAP(CDlgPlayerControls, CDialog)
  135. //{{AFX_MSG_MAP(CDlgPlayerControls)
  136. ON_EN_SETFOCUS(IDC_EDIT_FIRST_CONTROL, OnSetfocusEditFirstControl)
  137. ON_EN_SETFOCUS(IDC_EDIT_SECOND_CONTROL, OnSetfocusEditSecondControl)
  138. ON_BN_CLICKED(ID_FIRST_CONTROL_NONE, OnFirstControlNone)
  139. ON_BN_CLICKED(ID_SECOND_CONTROL_NONE, OnSecondControlNone)
  140. ON_BN_CLICKED(ID_DEFAULT, OnDefault)
  141. ON_CBN_SELCHANGE(IDC_CONTROLER_AXIS, OnSelchangeControlerAxis)
  142. ON_BN_CLICKED(ID_MOVE_CONTROL_UP, OnMoveControlUp)
  143. ON_BN_CLICKED(ID_MOVE_CONTROL_DOWN, OnMoveControlDown)
  144. ON_BN_CLICKED(ID_BUTTON_ACTION_ADD, OnButtonActionAdd)
  145. ON_BN_CLICKED(ID_BUTTON_ACTION_EDIT, OnButtonActionEdit)
  146. ON_BN_CLICKED(ID_BUTTON_ACTION_REMOVE, OnButtonActionRemove)
  147. //}}AFX_MSG_MAP
  148. END_MESSAGE_MAP()
  149. /////////////////////////////////////////////////////////////////////////////
  150. // CDlgPlayerControls message handlers
  151. void CDlgPlayerControls::FillActionsList(void)
  152. {
  153. // get selected item
  154. INDEX iDefaultSelected = m_listButtonActions.GetNextItem( -1, LVNI_SELECTED);
  155. // empty list containing actions
  156. m_listButtonActions.DeleteAllItems();
  157. // one item to serve for all actions and mounted buttons
  158. LV_ITEM itItem;
  159. // all items will be of text type
  160. itItem.mask = LVIF_TEXT;
  161. // index for automatic counting of added items
  162. INDEX ctItemsAdded = 0;
  163. // now add all button actions
  164. FOREACHINLIST( CButtonAction, ba_lnNode, m_ctrlControls.ctrl_lhButtonActions, itButtonAction)
  165. {
  166. // macro for adding single button action into list control
  167. itItem.iItem = ctItemsAdded;
  168. itItem.iSubItem = 0;
  169. itItem.pszText = (char *)(const char *) itButtonAction->ba_strName;
  170. m_listButtonActions.InsertItem( &itItem);
  171. itItem.iSubItem = 1;
  172. itItem.pszText = (char *)(const char *)_pInput->GetButtonName( itButtonAction->ba_iFirstKey);
  173. m_listButtonActions.SetItem( &itItem);
  174. itItem.iSubItem = 2;
  175. itItem.pszText = (char *)(const char *)_pInput->GetButtonName( itButtonAction->ba_iSecondKey);
  176. m_listButtonActions.SetItem( &itItem);
  177. ctItemsAdded++;
  178. }
  179. // try to select same item that was selected before refresh list
  180. if( iDefaultSelected != -1)
  181. {
  182. // select wanted item
  183. m_listButtonActions.SetItemState( iDefaultSelected,
  184. LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  185. m_listButtonActions.EnsureVisible( iDefaultSelected, FALSE);
  186. }
  187. }
  188. void CDlgPlayerControls::FillAxisList(void)
  189. {
  190. // get selected item
  191. INDEX iDefaultSelected = m_listAxisActions.GetNextItem( -1, LVNI_SELECTED);
  192. // empty list containing actions
  193. m_listAxisActions.DeleteAllItems();
  194. // one item to serve for all actions and mounted buttons
  195. LV_ITEM itItem;
  196. // all items will be of text type
  197. itItem.mask = LVIF_TEXT;
  198. // now add all axis actions
  199. for(INDEX iAxis = 0; iAxis<AXIS_ACTIONS_CT; iAxis++) {
  200. itItem.iItem = iAxis;
  201. itItem.iSubItem = 0;
  202. itItem.pszText = (char*)(const char*)_pGame->gm_astrAxisNames[iAxis];
  203. m_listAxisActions.InsertItem( &itItem);
  204. itItem.iSubItem = 1;
  205. itItem.pszText = (char *)(const char *)_pInput->GetAxisName(
  206. m_ctrlControls.ctrl_aaAxisActions[iAxis].aa_iAxisAction);
  207. m_listAxisActions.SetItem( &itItem);
  208. }
  209. // try to select same item that was selected before refresh list
  210. if( iDefaultSelected != -1)
  211. {
  212. m_listAxisActions.SetItemState( iDefaultSelected,
  213. LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  214. m_listAxisActions.EnsureVisible( iDefaultSelected, FALSE);
  215. }
  216. }
  217. // percentage of action's list control window width used for action names
  218. #define BUTTON_ACTION_NAME_PERCENTAGE 50
  219. #define AXIS_ACTION_NAME_PERCENTAGE 50
  220. BOOL CDlgPlayerControls::OnInitDialog()
  221. {
  222. CDialog::OnInitDialog();
  223. // initialize controler sensitivity
  224. m_sliderControlerSensitivity.SetRange( 1, SENSITIVITY_SLIDER_POSITIONS);
  225. m_sliderControlerSensitivity.SetTicFreq( 1);
  226. // get action list control's width in pixels
  227. CRect rectListControl;
  228. m_listButtonActions.GetClientRect( rectListControl);
  229. // insert column for action names
  230. INDEX iMainColumnWidth = rectListControl.Width()*BUTTON_ACTION_NAME_PERCENTAGE/100;
  231. m_listButtonActions.InsertColumn( 0, "Button action", LVCFMT_LEFT, iMainColumnWidth);
  232. // insert first control column
  233. INDEX iFirstSubColumnWidth = (rectListControl.Width()*(100-BUTTON_ACTION_NAME_PERCENTAGE)/2)/100;
  234. m_listButtonActions.InsertColumn( 1, "First", LVCFMT_LEFT, iFirstSubColumnWidth);
  235. // insert second control column
  236. INDEX iSecondSubColumnWidth =
  237. rectListControl.Width()-iMainColumnWidth-iFirstSubColumnWidth - 16;
  238. m_listButtonActions.InsertColumn( 2, "Second", LVCFMT_LEFT, iSecondSubColumnWidth);
  239. // add all actions into actions list
  240. FillActionsList();
  241. // get axis action list control's width in pixels
  242. m_listAxisActions.GetClientRect( rectListControl);
  243. // insert column for axis action names
  244. iMainColumnWidth = rectListControl.Width()*AXIS_ACTION_NAME_PERCENTAGE/100;
  245. m_listAxisActions.InsertColumn( 0, "Axis action", LVCFMT_LEFT, iMainColumnWidth);
  246. // insert mounting controls column
  247. INDEX iAxisMouterNameWidth = rectListControl.Width()*(100-AXIS_ACTION_NAME_PERCENTAGE)/100-1;
  248. m_listAxisActions.InsertColumn( 1, "Current controler", LVCFMT_LEFT, iAxisMouterNameWidth);
  249. // add all available axis into axis list
  250. FillAxisList();
  251. // for all possible axis mounting controlers
  252. for( INDEX iAxis=0; iAxis<_pInput->GetAvailableAxisCount(); iAxis++)
  253. {
  254. m_comboControlerAxis.AddString( _pInput->GetAxisName( iAxis));
  255. }
  256. return TRUE;
  257. }
  258. void CDlgPlayerControls::SetFirstAndSecondButtonNames(void)
  259. {
  260. BOOL bEnablePressKeyControls;
  261. CButtonAction *pbaCurrent = GetSelectedButtonAction();
  262. if( pbaCurrent != NULL)
  263. {
  264. // type first currently mounted button's name
  265. m_editFirstControl.SetWindowText( (char *)(const char *)
  266. _pInput->GetButtonName( pbaCurrent->ba_iFirstKey) );
  267. // type second currently mounted button's name
  268. m_editSecondControl.SetWindowText( (char *)(const char *)
  269. _pInput->GetButtonName( pbaCurrent->ba_iSecondKey) );
  270. // enable edit key and "none" controls
  271. bEnablePressKeyControls = TRUE;
  272. }
  273. else
  274. {
  275. bEnablePressKeyControls = FALSE;
  276. }
  277. // enable/disable press key controls (edit boxes and "none" buttons)
  278. m_editFirstControl.EnableWindow( bEnablePressKeyControls);
  279. m_editSecondControl.EnableWindow( bEnablePressKeyControls);
  280. GetDlgItem( ID_FIRST_CONTROL_NONE)->EnableWindow( bEnablePressKeyControls);
  281. GetDlgItem( ID_SECOND_CONTROL_NONE)->EnableWindow( bEnablePressKeyControls);
  282. }
  283. void CDlgPlayerControls::ActivatePressKey( char *strFirstOrSecond)
  284. {
  285. // get selected action
  286. m_iSelectedAction = m_listButtonActions.GetNextItem( -1, LVNI_SELECTED);
  287. // if there is valid selection
  288. if( m_iSelectedAction == -1)
  289. {
  290. // activate actions list
  291. m_listButtonActions.SetFocus();
  292. return;
  293. }
  294. // leave left mouse button !
  295. while( (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0) NOTHING;
  296. char achrMessage[ 256];
  297. // prepare message
  298. sprintf( achrMessage, "Press new %s button for action:\n\"%s\"", strFirstOrSecond,
  299. m_listButtonActions.GetItemText( m_iSelectedAction, 0));
  300. // set message string to dialog
  301. m_strPressNewButton = achrMessage;
  302. // activate string in text control
  303. UpdateData( FALSE);
  304. // enable application
  305. AfxGetMainWnd()->EnableWindow();
  306. AfxGetMainWnd()->SetActiveWindow();
  307. // enable direct input
  308. _pInput->EnableInput(m_hWnd);
  309. // initial reading of all available inputs
  310. _pInput->GetInput(FALSE);
  311. // as long as direct input is enabled
  312. while( _pInput->IsInputEnabled())
  313. {
  314. // for all possible buttons
  315. for( INDEX iButton=0; iButton<_pInput->GetAvailableButtonsCount(); iButton++)
  316. {
  317. // if pressed
  318. if( _pInput->GetButtonState( iButton)
  319. || (iButton==KID_MOUSE1 && (GetAsyncKeyState(VK_LBUTTON) & 0x8000) != 0)
  320. || (iButton==KID_MOUSE2 && (GetAsyncKeyState(VK_RBUTTON) & 0x8000) != 0)
  321. || (iButton==KID_MOUSE3 && (GetAsyncKeyState(VK_MBUTTON) & 0x8000) != 0))
  322. {
  323. // disable direct input
  324. _pInput->DisableInput();
  325. // if new button is mounted allready, set owner's action mounting to "key none"
  326. FOREACHINLIST( CButtonAction, ba_lnNode, m_ctrlControls.ctrl_lhButtonActions, itButtonAction)
  327. {
  328. if( itButtonAction->ba_iFirstKey == iButton) itButtonAction->ba_iFirstKey = KID_NONE;
  329. if( itButtonAction->ba_iSecondKey == iButton) itButtonAction->ba_iSecondKey = KID_NONE;
  330. }
  331. CButtonAction *pbaCurrent = GetSelectedButtonAction();
  332. if( pbaCurrent != NULL)
  333. {
  334. if( strFirstOrSecond == CTString("first") )
  335. {
  336. pbaCurrent->ba_iFirstKey = iButton;
  337. }
  338. else
  339. {
  340. pbaCurrent->ba_iSecondKey = iButton;
  341. }
  342. }
  343. // refresh list control
  344. FillActionsList();
  345. // refresh first button edit control
  346. SetFirstAndSecondButtonNames();
  347. // disable application
  348. AfxGetMainWnd()->EnableWindow( FALSE);
  349. // activate dialog
  350. SetActiveWindow();
  351. EnableWindow();
  352. // activate actions list
  353. m_listButtonActions.SetFocus();
  354. // prevent reselecting edit control
  355. MSG message;
  356. // peek and remove all mouse messages from message queue
  357. while( PeekMessage( &message, m_hWnd, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE)) NOTHING;
  358. // peek and remove all keyboard messages from message queue
  359. while( PeekMessage( &message, m_hWnd, WM_KEYFIRST, WM_KEYLAST, PM_REMOVE)) NOTHING;
  360. }
  361. }
  362. }
  363. ASSERT( !_pInput->IsInputEnabled());
  364. // try to select same item that was selected before key binding
  365. if( m_iSelectedAction != -1)
  366. {
  367. m_listButtonActions.SetItemState( m_iSelectedAction,
  368. LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  369. m_listButtonActions.EnsureVisible( m_iSelectedAction, FALSE);
  370. }
  371. // delete press button message
  372. m_strPressNewButton = "";
  373. // notice change
  374. UpdateData( FALSE);
  375. }
  376. void CDlgPlayerControls::OnSetfocusEditFirstControl()
  377. {
  378. // activates press key behaviour (rather complicated one) for first button
  379. ActivatePressKey( "first");
  380. }
  381. void CDlgPlayerControls::OnSetfocusEditSecondControl()
  382. {
  383. // activates press key behaviour (rather complicated one) for second button
  384. ActivatePressKey( "second");
  385. }
  386. CButtonAction *CDlgPlayerControls::GetSelectedButtonAction()
  387. {
  388. // get selected action
  389. m_iSelectedAction = m_listButtonActions.GetNextItem( -1, LVNI_SELECTED);
  390. // if there is valid selection
  391. if( m_iSelectedAction != -1)
  392. {
  393. INDEX iCurrent = 0;
  394. FOREACHINLIST( CButtonAction, ba_lnNode, m_ctrlControls.ctrl_lhButtonActions, itButtonAction)
  395. {
  396. if( iCurrent == m_iSelectedAction) return itButtonAction;
  397. iCurrent++;
  398. }
  399. }
  400. return NULL;
  401. }
  402. void CDlgPlayerControls::OnFirstControlNone()
  403. {
  404. CButtonAction *pbaCurrent = GetSelectedButtonAction();
  405. if( pbaCurrent != NULL)
  406. {
  407. // set none action key
  408. pbaCurrent->ba_iFirstKey = KID_NONE;
  409. // refresh list control
  410. FillActionsList();
  411. // refresh first button edit control
  412. SetFirstAndSecondButtonNames();
  413. // activate actions list
  414. m_listButtonActions.SetFocus();
  415. }
  416. }
  417. void CDlgPlayerControls::OnSecondControlNone()
  418. {
  419. CButtonAction *pbaCurrent = GetSelectedButtonAction();
  420. if( pbaCurrent != NULL)
  421. {
  422. // set none action key
  423. pbaCurrent->ba_iSecondKey = KID_NONE;
  424. // refresh list control
  425. FillActionsList();
  426. // refresh first button edit control
  427. SetFirstAndSecondButtonNames();
  428. // activate actions list
  429. m_listButtonActions.SetFocus();
  430. }
  431. }
  432. void CDlgPlayerControls::OnDefault()
  433. {
  434. // switch controls to default
  435. m_ctrlControls.SwitchToDefaults();
  436. // refresh list control
  437. FillActionsList();
  438. // refresh first button edit control
  439. SetFirstAndSecondButtonNames();
  440. // activate actions list
  441. m_listButtonActions.SetFocus();
  442. // refresh axis list
  443. FillAxisList();
  444. // set axis attributes
  445. UpdateData( FALSE);
  446. }
  447. void CDlgPlayerControls::OnSelchangeControlerAxis()
  448. {
  449. // get newly selected controler axis
  450. INDEX iNewControler = m_comboControlerAxis.GetCurSel();
  451. // must be valid
  452. ASSERT( iNewControler != CB_ERR);
  453. // get selected item
  454. INDEX iActiveAxis = m_listAxisActions.GetNextItem( -1, LVNI_SELECTED);
  455. // change mounting controler for selected axis
  456. m_ctrlControls.ctrl_aaAxisActions[ iActiveAxis].aa_iAxisAction = iNewControler;
  457. // refresh axis list control
  458. FillAxisList();
  459. // pickup current values of controler attributes
  460. UpdateData( TRUE);
  461. // refresh axis-conected controls (dialog recives data)
  462. UpdateData( FALSE);
  463. }
  464. void CDlgPlayerControls::OnMoveControlUp()
  465. {
  466. // get selected item
  467. INDEX iSelectedButton = m_listButtonActions.GetNextItem( -1, LVNI_SELECTED);
  468. if( iSelectedButton == 0) return;
  469. // find member to move up
  470. INDEX iCurrent = 0;
  471. CButtonAction *pbaButtonToMove = NULL;
  472. {FOREACHINLIST( CButtonAction, ba_lnNode, m_ctrlControls.ctrl_lhButtonActions, itButtonAction)
  473. {
  474. if( iCurrent == iSelectedButton)
  475. {
  476. // remove it from list
  477. itButtonAction->ba_lnNode.Remove();
  478. pbaButtonToMove = &itButtonAction.Current();
  479. break;
  480. }
  481. iCurrent++;
  482. }}
  483. ASSERT( pbaButtonToMove != NULL);
  484. // insert removed member again but before its predcessor
  485. iCurrent = 0;
  486. {FOREACHINLIST( CButtonAction, ba_lnNode, m_ctrlControls.ctrl_lhButtonActions, itButtonAction)
  487. {
  488. if( iCurrent == (iSelectedButton-1) )
  489. {
  490. itButtonAction->ba_lnNode.AddBefore( pbaButtonToMove->ba_lnNode);
  491. break;
  492. }
  493. iCurrent++;
  494. }}
  495. // refresh list control
  496. FillActionsList();
  497. // get no of items
  498. INDEX iButtonsCt = m_listButtonActions.GetItemCount();
  499. // get no of items
  500. for( INDEX iListItem=0; iListItem<iButtonsCt; iListItem++)
  501. {
  502. m_listButtonActions.SetItemState( iListItem, 0, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  503. }
  504. // select wanted item
  505. m_listButtonActions.SetItemState( iSelectedButton-1,
  506. LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  507. m_listButtonActions.EnsureVisible( iSelectedButton-1, FALSE);
  508. m_listButtonActions.SetFocus();
  509. }
  510. void CDlgPlayerControls::OnMoveControlDown()
  511. {
  512. // get no of items
  513. INDEX iButtonsCt = m_listButtonActions.GetItemCount();
  514. // get selected item
  515. INDEX iSelectedButton = m_listButtonActions.GetNextItem( -1, LVNI_SELECTED);
  516. if( iSelectedButton >= (iButtonsCt-1) ) return;
  517. // find member to move down
  518. INDEX iCurrent = 0;
  519. CButtonAction *pbaButtonToMove = NULL;
  520. {FOREACHINLIST( CButtonAction, ba_lnNode, m_ctrlControls.ctrl_lhButtonActions, itButtonAction)
  521. {
  522. if( iCurrent == iSelectedButton)
  523. {
  524. // remove it from list
  525. itButtonAction->ba_lnNode.Remove();
  526. pbaButtonToMove = &itButtonAction.Current();
  527. break;
  528. }
  529. iCurrent++;
  530. }}
  531. ASSERT( pbaButtonToMove != NULL);
  532. // insert removed member again but before its predcessor
  533. iCurrent = 0;
  534. {FOREACHINLIST( CButtonAction, ba_lnNode, m_ctrlControls.ctrl_lhButtonActions, itButtonAction)
  535. {
  536. if( iCurrent == (iSelectedButton) )
  537. {
  538. itButtonAction->ba_lnNode.AddAfter( pbaButtonToMove->ba_lnNode);
  539. break;
  540. }
  541. iCurrent++;
  542. }}
  543. // refresh list control
  544. FillActionsList();
  545. // get no of items
  546. for( INDEX iListItem=0; iListItem<iButtonsCt; iListItem++)
  547. {
  548. m_listButtonActions.SetItemState( iListItem, 0, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  549. }
  550. // select wanted item
  551. m_listButtonActions.SetItemState( iSelectedButton+1,
  552. LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED, LVIS_FOCUSED|LVIS_SELECTED|LVIS_DROPHILITED);
  553. m_listButtonActions.EnsureVisible( iSelectedButton+1, FALSE);
  554. m_listButtonActions.SetFocus();
  555. }
  556. void CDlgPlayerControls::OnButtonActionAdd()
  557. {
  558. m_listButtonActions.OnButtonActionAdd();
  559. }
  560. void CDlgPlayerControls::OnButtonActionEdit()
  561. {
  562. m_listButtonActions.OnButtonActionEdit();
  563. }
  564. void CDlgPlayerControls::OnButtonActionRemove()
  565. {
  566. m_listButtonActions.OnButtonActionRemove();
  567. }