UnitSettingsDlg.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. //===========================================================================//
  2. // Copyright (C) Microsoft Corporation. All rights reserved. //
  3. //===========================================================================//
  4. // UnitSettingsDlg.cpp : implementation file
  5. //
  6. #include "stdafx.h"
  7. #include "resource.h"
  8. #include "UnitSettingsDlg.h"
  9. #include "EditorObjects.h"
  10. #include "EditorObjectMgr.h"
  11. #include "EditorInterface.h" // just for the undo manager
  12. /////////////////////////////////////////////////////////////////////////////
  13. // UnitSettingsDlg dialog
  14. UnitSettingsDlg::UnitSettingsDlg( EList< Unit*, Unit* >& newList/*=NULL*/, ActionUndoMgr &undoMgr)
  15. : CDialog(UnitSettingsDlg::IDD), units( newList )
  16. {
  17. //{{AFX_DATA_INIT(UnitSettingsDlg)
  18. m_Alignment = -1;
  19. m_SquadEdit = _T("");
  20. m_SelfRepairBehavior = -1;
  21. //}}AFX_DATA_INIT
  22. pUndoMgr = &undoMgr;
  23. pAction = NULL;
  24. }
  25. void UnitSettingsDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(UnitSettingsDlg)
  29. DDX_Control(pDX, IDC_VARIANT, m_Variant);
  30. DDX_Control(pDX, IDC_PILOT, m_Pilot);
  31. DDX_Control(pDX, IDC_MECH, m_Mech);
  32. DDX_Control(pDX, IDC_GROUP, m_Group);
  33. DDX_Radio(pDX, IDC_ALIGN1, m_Alignment);
  34. DDX_Text(pDX, IDC_SQUAD_EDIT, m_SquadEdit);
  35. DDX_Radio(pDX, IDC_SELF_REPAIR1, m_SelfRepairBehavior);
  36. //}}AFX_DATA_MAP
  37. }
  38. BEGIN_MESSAGE_MAP(UnitSettingsDlg, CDialog)
  39. //{{AFX_MSG_MAP(UnitSettingsDlg)
  40. ON_CBN_SELCHANGE(IDC_GROUP, OnSelchangeGroup)
  41. ON_BN_CLICKED(IDC_HIGHILIGHT2EDIT, OnHighilight2edit)
  42. ON_EN_CHANGE(IDC_HIGHLIGHT1, OnChangeHighlight1)
  43. ON_BN_CLICKED(IDC_HIGHLIGHT1EDIT, OnHighlight1edit)
  44. ON_EN_CHANGE(IDC_HIGHLIGHT2, OnChangeHighlight2)
  45. ON_EN_CHANGE(IDC_BASE, OnChangeBase)
  46. ON_BN_CLICKED(IDC_BASEEDIT, OnBaseedit)
  47. ON_WM_CTLCOLOR()
  48. ON_CBN_SELCHANGE(IDC_MECH, OnSelchangeMech)
  49. //}}AFX_MSG_MAP
  50. ON_CONTROL_RANGE( BN_CLICKED, IDC_ALIGN1, IDC_ALIGN1 + 8, OnAlign1)
  51. END_MESSAGE_MAP()
  52. /////////////////////////////////////////////////////////////////////////////
  53. // UnitSettingsDlg message handlers
  54. void UnitSettingsDlg::OnSelchangeGroup()
  55. {
  56. m_Mech.ResetContent();
  57. int group = m_Group.GetCurSel();
  58. group = m_Group.GetItemData( group );
  59. const char* MechNames[256];
  60. int count = 256;
  61. EditorObjectMgr::instance()->getBuildingNamesInGroup( group, MechNames, count );
  62. for ( int i = 0; i < count; ++i )
  63. {
  64. m_Mech.AddString( MechNames[i] );
  65. }
  66. m_Mech.SetCurSel( 0 );
  67. }
  68. void UnitSettingsDlg::OnHighilight2edit()
  69. {
  70. CWnd* pWnd = GetDlgItem( IDC_HIGHLIGHT2 );
  71. DoColorBox( pWnd );
  72. }
  73. void UnitSettingsDlg::OnChangeHighlight1()
  74. {
  75. // TODO: If this is a RICHEDIT control, the control will not
  76. // send this notification unless you override the CDialog::OnInitDialog()
  77. // function and call CRichEditCtrl().SetEventMask()
  78. // with the ENM_CHANGE flag ORed into the mask.
  79. CString text;
  80. GetDlgItem( IDC_HIGHLIGHT1 )->GetWindowText( text );
  81. bool bChanged = false;
  82. int i = 0;
  83. if ( text.GetLength() > 1 && (text[0] == '0' && (text[1] == 'x' || text[i] == 'X' )) )
  84. i = 2;
  85. for ( ; i < text.GetLength(); ++i )
  86. {
  87. if ( !isxdigit( text[i] ) )
  88. {
  89. text.Remove( text[i] );
  90. bChanged = true;
  91. }
  92. }
  93. if ( bChanged )
  94. GetDlgItem( IDC_HIGHLIGHT1 )->SetWindowText( text );
  95. GetDlgItem( IDC_HIGHLIGHT1 )->RedrawWindow( );
  96. }
  97. void UnitSettingsDlg::OnHighlight1edit()
  98. {
  99. CWnd* pWnd = GetDlgItem( IDC_HIGHLIGHT1 );
  100. DoColorBox( pWnd );
  101. }
  102. void UnitSettingsDlg::OnChangeHighlight2()
  103. {
  104. CString text;
  105. GetDlgItem( IDC_HIGHLIGHT2 )->GetWindowText( text );
  106. bool bChanged = false;
  107. int i = 0;
  108. if ( text.GetLength() > 1 && (text[0] == '0' && (text[1] == 'x' || text[i] == 'X' )) )
  109. i = 2;
  110. for ( ; i < text.GetLength(); ++i )
  111. {
  112. if ( !isxdigit( text[i] ) )
  113. {
  114. text.Remove( text[i] );
  115. bChanged = true;
  116. }
  117. }
  118. if ( bChanged )
  119. GetDlgItem( IDC_HIGHLIGHT2 )->SetWindowText( text );
  120. GetDlgItem( IDC_HIGHLIGHT2 )->RedrawWindow( );
  121. }
  122. void UnitSettingsDlg::OnChangeBase()
  123. {
  124. CString text;
  125. GetDlgItem( IDC_BASE )->GetWindowText( text );
  126. bool bChanged = false;
  127. int i = 0;
  128. if ( text.GetLength() > 1 && (text[0] == '0' && (text[1] == 'x' || text[i] == 'X' )) )
  129. i = 2;
  130. for ( ; i < text.GetLength(); ++i )
  131. {
  132. if ( !isxdigit( text[i] ) )
  133. {
  134. text.Remove( text[i] );
  135. bChanged = true;
  136. }
  137. }
  138. if ( bChanged )
  139. GetDlgItem( IDC_BASE )->SetWindowText( text );
  140. GetDlgItem( IDC_BASE )->RedrawWindow( );
  141. }
  142. void UnitSettingsDlg::OnBaseedit()
  143. {
  144. CWnd* pWnd = GetDlgItem( IDC_BASE );
  145. DoColorBox( pWnd );
  146. }
  147. void UnitSettingsDlg::DoColorBox( CWnd* pWnd )
  148. {
  149. if ( pWnd )
  150. {
  151. CString tmpStr;
  152. pWnd->GetWindowText( tmpStr );
  153. tmpStr.Replace( "0x", "" );
  154. long base;
  155. sscanf( tmpStr, "%x", &base );
  156. base &= 0x00ffffff;
  157. CColorDialog dlg( reverseRGB(base), NULL, this );
  158. if (IDOK == dlg.DoModal() )
  159. {
  160. base = reverseRGB( dlg.GetColor() );
  161. tmpStr.Format( "0x%x", base );
  162. pWnd->SetWindowText( tmpStr );
  163. }
  164. }
  165. }
  166. void UnitSettingsDlg::applyChanges()
  167. {
  168. // get the type info from the dlg box
  169. int index = m_Group.GetCurSel( );
  170. if ( index != -1 )
  171. {
  172. int group = m_Group.GetItemData( index );
  173. int indexInGroup = m_Mech.GetCurSel( );
  174. if ( indexInGroup != -1 )
  175. {
  176. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  177. {
  178. (*iter)->setAppearance( group, indexInGroup );
  179. }
  180. int variant = m_Variant.GetCurSel();
  181. if ( variant != -1 )
  182. {
  183. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  184. {
  185. (*iter)->setVariant( variant );
  186. }
  187. }
  188. }
  189. }
  190. //set pilots
  191. index = m_Pilot.GetCurSel();
  192. if ( index != -1 )
  193. {
  194. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  195. {
  196. CString txt;
  197. m_Pilot.GetLBText( index, txt );
  198. (*iter)->getPilot()->setName( txt );
  199. }
  200. }
  201. // now set the alignment
  202. UpdateData( true );
  203. index = m_Alignment;
  204. if ( index != -1 )
  205. {
  206. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  207. {
  208. (*iter)->setAlignment( index );
  209. }
  210. }
  211. if ( !(m_SquadEdit.IsEmpty()) )
  212. {
  213. index = _ttol(m_SquadEdit.GetBuffer(0));
  214. if (1 != units.Count())
  215. {
  216. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  217. {
  218. (*iter)->setSquad( index );
  219. }
  220. }
  221. else
  222. {
  223. pFirstPossibility->setSquad( index );
  224. }
  225. }
  226. bool bSelfRepairBehavior = true;
  227. if (0 != m_SelfRepairBehavior)
  228. {
  229. bSelfRepairBehavior = false;
  230. }
  231. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  232. {
  233. (*iter)->setSelfRepairBehaviorEnabled(bSelfRepairBehavior);
  234. }
  235. unsigned long base=0, color1=0, color2=0;
  236. bool bBase = false;
  237. bool bColor1 = false;
  238. bool bColor2 = false;
  239. // now figure out the colors
  240. CWnd* pWnd = GetDlgItem( IDC_BASE );
  241. if ( pWnd )
  242. {
  243. CString tmpStr;
  244. pWnd->GetWindowText( tmpStr );
  245. if ( tmpStr.GetLength() )
  246. {
  247. bBase = true;
  248. tmpStr.Replace( "0x", "" );
  249. sscanf( tmpStr, "%x", &base );
  250. base |= 0xff000000;
  251. }
  252. }
  253. pWnd = GetDlgItem( IDC_HIGHLIGHT1 );
  254. if ( pWnd )
  255. {
  256. CString tmpStr;
  257. pWnd->GetWindowText( tmpStr );
  258. if ( tmpStr.GetLength() )
  259. {
  260. bColor1 = true;
  261. tmpStr.Replace( "0x", "" );
  262. sscanf( tmpStr, "%x", &color1 );
  263. color1 |= 0xff000000;
  264. }
  265. }
  266. pWnd = GetDlgItem( IDC_HIGHLIGHT2 );
  267. if ( pWnd )
  268. {
  269. CString tmpStr;
  270. pWnd->GetWindowText( tmpStr );
  271. if ( tmpStr.GetLength() )
  272. {
  273. bColor2 = true;
  274. tmpStr.Replace( "0x", "" );
  275. sscanf( tmpStr, "%x", &color2 );
  276. color2 |= 0xff000000;
  277. }
  278. }
  279. if ( bBase && bColor1 && bColor2 )
  280. {
  281. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  282. {
  283. (*iter)->setColors( base, color1, color2 );
  284. }
  285. }
  286. }
  287. void UnitSettingsDlg::OnOK()
  288. {
  289. if (NULL != pUndoMgr)
  290. {
  291. pUndoMgr->AddAction(pAction);
  292. }
  293. else
  294. {
  295. delete pAction;
  296. }
  297. pAction = NULL;
  298. applyChanges();
  299. CDialog::OnOK();
  300. }
  301. BOOL UnitSettingsDlg::OnInitDialog()
  302. {
  303. CDialog::OnInitDialog();
  304. pAction = new ModifyBuildingAction;
  305. UNIT_LIST::EIterator iter;
  306. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  307. {
  308. pAction->addBuildingInfo(*(*iter));
  309. }
  310. updateMemberVariables();
  311. if (1 != units.Count())
  312. {
  313. pFirstPossibility = NULL;
  314. }
  315. else
  316. {
  317. pFirstPossibility = (*(units.Begin()));
  318. }
  319. updatePossibiltyControls();
  320. return TRUE; // return TRUE unless you set the focus to a control
  321. // EXCEPTION: OCX Property Pages should return FALSE
  322. }
  323. void UnitSettingsDlg::updatePossibiltyControls()
  324. {
  325. updateMemberVariables();
  326. }
  327. HBRUSH UnitSettingsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  328. {
  329. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  330. if ( GetDlgItem( IDC_BASE )->m_hWnd == pWnd->m_hWnd )
  331. {
  332. CString tmpStr;
  333. pWnd->GetWindowText( tmpStr );
  334. tmpStr.Replace( "0x", "" );
  335. long base;
  336. sscanf( tmpStr, "%x", &base );
  337. base &= 0x00ffffff;
  338. base = reverseRGB( base );
  339. if ( baseBrush.m_hObject )
  340. baseBrush.DeleteObject();
  341. baseBrush.CreateSolidBrush( base );
  342. pDC->SetBkColor( base );
  343. if ( ((base & 0xff) + ( (base & 0xff00)>>8 ) + ( (base & 0xff0000)>>16 ))/3 < 85 )
  344. pDC->SetTextColor( 0x00ffffff );
  345. return (HBRUSH)baseBrush.m_hObject;
  346. }
  347. if ( GetDlgItem( IDC_HIGHLIGHT1 )->m_hWnd == pWnd->m_hWnd )
  348. {
  349. CString tmpStr;
  350. pWnd->GetWindowText( tmpStr );
  351. tmpStr.Replace( "0x", "" );
  352. long base;
  353. sscanf( tmpStr, "%x", &base );
  354. base &= 0x00ffffff;
  355. base = reverseRGB( base );
  356. if ( brush1.m_hObject )
  357. brush1.DeleteObject();
  358. brush1.CreateSolidBrush( base );
  359. pDC->SetBkColor( base );
  360. if ( ((base & 0xff) + ( (base & 0xff00)>>8 ) + ( (base & 0xff0000)>>16 ))/3 < 85 )
  361. pDC->SetTextColor( 0x00ffffff );
  362. return (HBRUSH)brush1.m_hObject;
  363. }
  364. if ( GetDlgItem( IDC_HIGHLIGHT2 )->m_hWnd == pWnd->m_hWnd )
  365. {
  366. CString tmpStr;
  367. pWnd->GetWindowText( tmpStr );
  368. tmpStr.Replace( "0x", "" );
  369. long base;
  370. sscanf( tmpStr, "%x", &base );
  371. base &= 0x00ffffff;
  372. base = reverseRGB( base );
  373. if ( brush2.m_hObject )
  374. brush2.DeleteObject();
  375. brush2.CreateSolidBrush( base );
  376. pDC->SetBkColor( base );
  377. if ( ((base & 0xff) + ( (base & 0xff00)>>8 ) + ( (base & 0xff0000)>>16 ))/3 < 85 )
  378. pDC->SetTextColor( 0x00ffffff );
  379. return (HBRUSH)brush2.m_hObject;
  380. }
  381. // TODO: Return a different brush if the default is not desired
  382. return hbr;
  383. }
  384. void UnitSettingsDlg::OnSelchangeMech()
  385. {
  386. m_Variant.ResetContent();
  387. int group = m_Group.GetCurSel();
  388. group = m_Group.GetItemData( group );
  389. int indexInGroup = m_Mech.GetCurSel();
  390. int varCount = EditorObjectMgr::instance()->getNumberOfVariants( group, indexInGroup );
  391. const char** VariantNames = 0;
  392. if (0 < varCount)
  393. {
  394. VariantNames = new const char*[varCount];
  395. EditorObjectMgr::instance()->getVariantNames( group, indexInGroup, VariantNames, varCount );
  396. for ( int v = 0; v < varCount; ++v )
  397. {
  398. m_Variant.AddString( VariantNames[v] );
  399. }
  400. delete VariantNames;
  401. VariantNames = 0;
  402. m_Variant.SetCurSel( 0 );
  403. }
  404. }
  405. int UnitSettingsDlg::getPossibilityIndex()
  406. {
  407. if (!pFirstPossibility) { gosASSERT(false); return -1; }
  408. const Unit * pUnit = (*(units.Begin()));
  409. if (pUnit == pFirstPossibility)
  410. {
  411. return 0;
  412. }
  413. int i;
  414. for (i = 0; i < (int)pFirstPossibility->pAlternativeInstances->Count(); i++)
  415. {
  416. if (pUnit == &(*(pFirstPossibility->pAlternativeInstances->Iterator(i))))
  417. {
  418. return i + 1;
  419. }
  420. }
  421. return -1;
  422. }
  423. void UnitSettingsDlg::updateMemberVariables()
  424. {
  425. // now need to check all of the colors
  426. unsigned long tmpBase, tmpHighlight1, tmpHighlight2;
  427. unsigned long base, highlight1, highlight2;
  428. bool bBase = true;
  429. bool bHighlight = true;
  430. bool bHighlight2 = true;
  431. Unit* pUnit = units.GetHead();
  432. m_Alignment = pUnit->getAlignment();
  433. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  434. {
  435. if ( (*iter)->getAlignment() != m_Alignment )
  436. {
  437. m_Alignment = -1;
  438. break;
  439. }
  440. }
  441. m_SelfRepairBehavior = 0;
  442. if (true != pUnit->getSelfRepairBehaviorEnabled())
  443. {
  444. m_SelfRepairBehavior = 1;
  445. }
  446. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  447. {
  448. if ( (*iter)->getSelfRepairBehaviorEnabled() != pUnit->getSelfRepairBehaviorEnabled() )
  449. {
  450. m_SelfRepairBehavior = -1;
  451. break;
  452. }
  453. }
  454. unsigned long tmpSquadNum = pUnit->getSquad();
  455. m_SquadEdit.Format("%lu", tmpSquadNum);
  456. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  457. {
  458. if ( (*iter)->getSquad() != tmpSquadNum )
  459. {
  460. m_SquadEdit.Empty();
  461. break;
  462. }
  463. }
  464. UpdateData( false );
  465. pUnit->getColors( base, highlight1, highlight2 );
  466. char pBase[256];
  467. char pH1[256];
  468. char pH2[256];
  469. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  470. {
  471. (*iter)->getColors( tmpBase, tmpHighlight1, tmpHighlight2 );
  472. if ( tmpBase != base )
  473. bBase = false;
  474. if ( tmpHighlight1 != highlight1 )
  475. bHighlight = false;
  476. if ( tmpHighlight2 != highlight2 )
  477. bHighlight2 = false;
  478. }
  479. base &= 0x00ffffff;
  480. highlight1 &= 0x00ffffff;
  481. highlight2 &= 0x00ffffff;
  482. sprintf( pBase, "0x%6x", base );
  483. sprintf( pH1, "0x%6x", highlight1 );
  484. sprintf( pH2, "0x%6x", highlight2 );
  485. if ( bBase )
  486. {
  487. GetDlgItem( IDC_BASE )->SetWindowText( pBase );
  488. }
  489. if ( bHighlight )
  490. GetDlgItem( IDC_HIGHLIGHT1 )->SetWindowText( pH1 );
  491. if ( bHighlight2 )
  492. GetDlgItem( IDC_HIGHLIGHT2 )->SetWindowText( pH2 );
  493. EditorObjectMgr* pMgr = EditorObjectMgr::instance();
  494. int groupCount = pMgr->getUnitGroupCount();
  495. const char** pGroups = new const char*[groupCount];
  496. int* groupIDs = new int[groupCount];
  497. m_Group.ResetContent();
  498. pMgr->getUnitGroupNames(pGroups, groupIDs, groupCount);
  499. for ( int i = 0; i < groupCount; ++i )
  500. {
  501. m_Group.AddString( pGroups[i] );
  502. m_Group.SetItemData( i, groupIDs[i] );
  503. }
  504. delete [] pGroups;
  505. delete [] groupIDs;
  506. // make sure all the units we are editing are in the same group
  507. int group = units.GetHead()->getGroup();
  508. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  509. {
  510. if ( (*iter)->getGroup() != group )
  511. {
  512. group = -1;
  513. break;
  514. }
  515. }
  516. if ( group != -1 ) // we found a valid group
  517. {
  518. const char* pGroupName = pMgr->getGroupName( group );
  519. int index = m_Group.FindString( -1, pGroupName );
  520. m_Group.SetCurSel( index );
  521. // OK, now fill in the index....
  522. const char* MechNames[256];
  523. int count = 256;
  524. m_Mech.ResetContent();
  525. pMgr->getBuildingNamesInGroup( group, MechNames, count );
  526. for ( int i = 0; i < count; ++i )
  527. {
  528. m_Mech.AddString( MechNames[i] );
  529. }
  530. // ok, now determine if all of the mechs are the same.
  531. int indexInGroup = units.GetHead()->getIndexInGroup();
  532. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  533. {
  534. if ( (*iter)->getIndexInGroup() != indexInGroup )
  535. {
  536. indexInGroup = -1;
  537. break;
  538. }
  539. }
  540. if ( indexInGroup != -1 )
  541. {
  542. const char* pName = units.GetHead()->getDisplayName();
  543. index = m_Mech.FindString( -1, pName );
  544. if ( index != -1 )
  545. {
  546. m_Mech.SetCurSel( index );
  547. // now we need to find the variant
  548. m_Variant.ResetContent();
  549. int varCount = EditorObjectMgr::instance()->getNumberOfVariants( group, indexInGroup );
  550. const char** VariantNames = 0;
  551. if (0 < varCount)
  552. {
  553. VariantNames = new const char*[varCount];
  554. EditorObjectMgr::instance()->getVariantNames( group, indexInGroup, VariantNames, varCount );
  555. for ( int v = 0; v < varCount; ++v )
  556. {
  557. m_Variant.AddString( VariantNames[v] );
  558. }
  559. delete VariantNames;
  560. VariantNames = 0;
  561. // OK, now see if they all have the same variant name
  562. int variant = units.GetHead()->getVariant();
  563. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  564. {
  565. if ( (*iter)->getVariant() != variant )
  566. {
  567. variant = -1;
  568. break;
  569. }
  570. }
  571. if ( variant != -1 )
  572. m_Variant.SetCurSel( variant );
  573. }
  574. }
  575. }
  576. }
  577. Pilot::PilotInfo* pInfo = Pilot::s_BadPilots;
  578. long* count = &Pilot::badCount;
  579. if ( (m_Alignment == 0) || (!EditorData::instance->IsSinglePlayer()) )
  580. {
  581. pInfo = Pilot::s_GoodPilots;
  582. count = &Pilot::goodCount;
  583. }
  584. else if ( m_Alignment == -1 )
  585. pInfo = 0;
  586. if ( pInfo )
  587. {
  588. m_Pilot.ResetContent();
  589. for ( int i = 0; i < *count; i++ )
  590. {
  591. m_Pilot.AddString( pInfo[i].name );
  592. m_Pilot.SetItemDataPtr(i, (void *)pInfo[i].fileName);
  593. }
  594. }
  595. Pilot* pPilot = pUnit->getPilot();
  596. const char* defaultPilot = pPilot->info->fileName;
  597. for ( iter = units.Begin(); !iter.IsDone(); iter++ )
  598. {
  599. pPilot = (*iter)->getPilot();
  600. const char* tmpName = pPilot->info->fileName;
  601. if ( stricmp( tmpName, defaultPilot ) != 0 )
  602. {
  603. defaultPilot = 0;
  604. break;
  605. }
  606. }
  607. if ( defaultPilot )
  608. {
  609. int index;
  610. for (index = 0; index < m_Pilot.GetCount(); index++)
  611. {
  612. char *fileName = (char *)m_Pilot.GetItemDataPtr(index);
  613. if (0 == strcmp(fileName, defaultPilot))
  614. {
  615. break;
  616. }
  617. }
  618. if (!(index < m_Pilot.GetCount()))
  619. {
  620. index = -1;
  621. }
  622. m_Pilot.SetCurSel( index );
  623. }
  624. }
  625. void UnitSettingsDlg::OnCancel()
  626. {
  627. pAction->undo();
  628. delete pAction;
  629. pAction = NULL;
  630. CDialog::OnCancel();
  631. }
  632. void UnitSettingsDlg::OnAlign1( UINT whichID )
  633. {
  634. UpdateData();
  635. Pilot::PilotInfo* pInfo = Pilot::s_BadPilots;
  636. long* count = &Pilot::badCount;
  637. if ( m_Alignment == 0 )
  638. {
  639. pInfo = Pilot::s_GoodPilots;
  640. count = &Pilot::goodCount;
  641. }
  642. else if ( m_Alignment == -1 )
  643. pInfo = 0;
  644. if ( pInfo )
  645. {
  646. m_Pilot.ResetContent();
  647. for ( int i = 0; i < *count; i++ )
  648. {
  649. m_Pilot.AddString( pInfo[i].name );
  650. }
  651. }
  652. Unit * pUnit = (*(units.Begin()));
  653. Pilot* pPilot = pUnit->getPilot();
  654. const char* defaultPilot = pPilot->getName();
  655. for ( UNIT_LIST::EIterator iter = units.Begin(); !iter.IsDone(); iter++ )
  656. {
  657. pPilot = (*iter)->getPilot();
  658. const char* tmpName = pPilot->getName();
  659. if ( stricmp( tmpName, defaultPilot ) != 0 )
  660. {
  661. defaultPilot = 0;
  662. break;
  663. }
  664. }
  665. if ( defaultPilot )
  666. {
  667. int index = m_Pilot.FindString( -1, defaultPilot );
  668. m_Pilot.SetCurSel( index );
  669. }
  670. }