EditConversationDialog.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. // EditConversationDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "editconversationdialog.h"
  23. #include "conversation.h"
  24. #include "translatedb.h"
  25. #include "translateobj.h"
  26. #include "editconversationremarkdialog.h"
  27. #include "playertype.h"
  28. #include "orator.h"
  29. #include "oratortypes.h"
  30. #include "utils.h"
  31. #ifdef _DEBUG
  32. #define new DEBUG_NEW
  33. #undef THIS_FILE
  34. static char THIS_FILE[] = __FILE__;
  35. #endif
  36. /////////////////////////////////////////////////////////////////////////////
  37. // Constants
  38. /////////////////////////////////////////////////////////////////////////////
  39. enum
  40. {
  41. COL_ORATOR = 0,
  42. COL_REMARK
  43. };
  44. static const int ORATOR_MAX = 6;
  45. typedef struct
  46. {
  47. int button_id;
  48. int combo_id;
  49. int check_id;
  50. int icon_id;
  51. } ORATOR_UI_INFO;
  52. const ORATOR_UI_INFO ORATOR_CTRLS[ORATOR_MAX] =
  53. {
  54. { IDC_ORATOR1_CHECK, IDC_ORATOR1_COMBO, IDC_ORATOR1_VISBLE_CHECK, IDI_ORATOR1 },
  55. { IDC_ORATOR2_CHECK, IDC_ORATOR2_COMBO, IDC_ORATOR2_VISBLE_CHECK, IDI_ORATOR2 },
  56. { IDC_ORATOR3_CHECK, IDC_ORATOR3_COMBO, IDC_ORATOR3_VISBLE_CHECK, IDI_ORATOR3 },
  57. { IDC_ORATOR4_CHECK, IDC_ORATOR4_COMBO, IDC_ORATOR4_VISBLE_CHECK, IDI_ORATOR4 },
  58. { IDC_ORATOR5_CHECK, IDC_ORATOR5_COMBO, IDC_ORATOR5_VISBLE_CHECK, IDI_ORATOR5 },
  59. { IDC_ORATOR6_CHECK, IDC_ORATOR6_COMBO, IDC_ORATOR6_VISBLE_CHECK, IDI_ORATOR6 },
  60. };
  61. /////////////////////////////////////////////////////////////////////////////
  62. //
  63. // EditConversationDialogClass
  64. //
  65. /////////////////////////////////////////////////////////////////////////////
  66. EditConversationDialogClass::EditConversationDialogClass(CWnd* pParent /*=NULL*/)
  67. : m_Conversation (NULL),
  68. CDialog(EditConversationDialogClass::IDD, pParent)
  69. {
  70. //{{AFX_DATA_INIT(EditConversationDialogClass)
  71. // NOTE: the ClassWizard will add member initialization here
  72. //}}AFX_DATA_INIT
  73. return ;
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. //
  77. // ~EditConversationDialogClass
  78. //
  79. /////////////////////////////////////////////////////////////////////////////
  80. EditConversationDialogClass::~EditConversationDialogClass (void)
  81. {
  82. REF_PTR_RELEASE (m_Conversation);
  83. return ;
  84. }
  85. /////////////////////////////////////////////////////////////////////////////
  86. //
  87. // DoDataExchange
  88. //
  89. /////////////////////////////////////////////////////////////////////////////
  90. void
  91. EditConversationDialogClass::DoDataExchange (CDataExchange *pDX)
  92. {
  93. CDialog::DoDataExchange(pDX);
  94. //{{AFX_DATA_MAP(EditConversationDialogClass)
  95. DDX_Control(pDX, IDC_REMARK_LIST, m_ListCtrl);
  96. //}}AFX_DATA_MAP
  97. return ;
  98. }
  99. BEGIN_MESSAGE_MAP(EditConversationDialogClass, CDialog)
  100. //{{AFX_MSG_MAP(EditConversationDialogClass)
  101. ON_NOTIFY(NM_DBLCLK, IDC_REMARK_LIST, OnDblclkRemarkList)
  102. ON_NOTIFY(LVN_KEYDOWN, IDC_REMARK_LIST, OnKeydownRemarkList)
  103. ON_BN_CLICKED(IDC_ADD, OnAdd)
  104. ON_BN_CLICKED(IDC_INSERT, OnInsert)
  105. ON_NOTIFY(LVN_ITEMCHANGED, IDC_REMARK_LIST, OnItemchangedRemarkList)
  106. ON_NOTIFY(LVN_DELETEITEM, IDC_REMARK_LIST, OnDeleteitemRemarkList)
  107. //}}AFX_MSG_MAP
  108. END_MESSAGE_MAP()
  109. /////////////////////////////////////////////////////////////////////////////
  110. //
  111. // OnInitDialog
  112. //
  113. /////////////////////////////////////////////////////////////////////////////
  114. BOOL
  115. EditConversationDialogClass::OnInitDialog (void)
  116. {
  117. CDialog::OnInitDialog ();
  118. //
  119. // Create a new conversation if we don't already have one to edit
  120. //
  121. if (m_Conversation == NULL) {
  122. m_Conversation = new ConversationClass;
  123. OratorClass orator;
  124. m_Conversation->Add_Orator (orator);
  125. }
  126. //
  127. // Configure the state combo box
  128. //
  129. SendDlgItemMessage (IDC_STATE_COMBO, CB_ADDSTRING, 0, (LPARAM)"Idle");
  130. SendDlgItemMessage (IDC_STATE_COMBO, CB_ADDSTRING, 0, (LPARAM)"Idle (Secondary)");
  131. SendDlgItemMessage (IDC_STATE_COMBO, CB_ADDSTRING, 0, (LPARAM)"Search");
  132. SendDlgItemMessage (IDC_STATE_COMBO, CB_ADDSTRING, 0, (LPARAM)"Combat");
  133. SendDlgItemMessage (IDC_STATE_COMBO, CB_SETCURSEL, (WPARAM)m_Conversation->Get_AI_State ());
  134. //
  135. // Configure the orator controls
  136. //
  137. for (int index = 0; index < ORATOR_MAX; index ++) {
  138. //
  139. // Put the icon into the button control
  140. //
  141. HICON icon = ::LoadIcon (::AfxGetResourceHandle (), MAKEINTRESOURCE (ORATOR_CTRLS[index].icon_id));
  142. SendDlgItemMessage (ORATOR_CTRLS[index].button_id, BM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
  143. //
  144. // Put the "visible" icon into the checkbox control
  145. //
  146. icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_EYE2), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
  147. SendDlgItemMessage (ORATOR_CTRLS[index].check_id, BM_SETIMAGE, IMAGE_ICON, (LPARAM)icon);
  148. SendDlgItemMessage (ORATOR_CTRLS[index].check_id, BM_SETCHECK, (WPARAM)TRUE);
  149. //
  150. // Configure the orator type combo-box
  151. //
  152. int type_count = OratorTypeClass::Get_Count ();
  153. for (int type_index = 0; type_index < type_count; type_index ++) {
  154. //
  155. // Lookup information about this orator type
  156. //
  157. const char *type_name = OratorTypeClass::Get_Description (type_index);
  158. int type_id = OratorTypeClass::Get_ID (type_index);
  159. int combobox_id = ORATOR_CTRLS[index].combo_id;
  160. //
  161. // Add this orator type to the combobox
  162. //
  163. int item_index = SendDlgItemMessage (combobox_id, CB_ADDSTRING, 0, (LPARAM)type_name);
  164. SendDlgItemMessage (combobox_id, CB_SETITEMDATA, (WPARAM)item_index, (LPARAM)type_id);
  165. }
  166. //
  167. // Select the first item by default
  168. //
  169. SendDlgItemMessage (ORATOR_CTRLS[index].combo_id, CB_SETCURSEL, (WPARAM)0);
  170. }
  171. //
  172. // Configure the orator controls
  173. //
  174. bool is_locked = true;
  175. int orator_count = m_Conversation->Get_Orator_Count ();
  176. for (index = 0; index < orator_count; index ++) {
  177. OratorClass *orator = m_Conversation->Get_Orator (index);
  178. //
  179. // Check the checkbox control and enable the combobox control
  180. //
  181. SendDlgItemMessage (ORATOR_CTRLS[index].button_id, BM_SETCHECK, (WPARAM)TRUE);
  182. SendDlgItemMessage (ORATOR_CTRLS[index].check_id, BM_SETCHECK, (WPARAM)(!orator->Is_Invisible ()));
  183. ::EnableWindow (::GetDlgItem (m_hWnd, ORATOR_CTRLS[index].combo_id), TRUE);
  184. ::EnableWindow (::GetDlgItem (m_hWnd, ORATOR_CTRLS[index].check_id), TRUE);
  185. //
  186. // Select the current orator type in the combobox
  187. //
  188. int orator_type = orator->Get_Orator_Type ();
  189. int item_index = Find_Combobox_Entry (orator_type);
  190. if (item_index >= 0) {
  191. SendDlgItemMessage (ORATOR_CTRLS[index].combo_id, CB_SETCURSEL, (WPARAM)item_index);
  192. }
  193. //
  194. // If any of the orator types disagree, then don't lock the controls
  195. //
  196. if (orator_type != m_Conversation->Get_Orator (0)->Get_Orator_Type ()) {
  197. is_locked = false;
  198. }
  199. }
  200. //
  201. // Configure the "lock" checkbox
  202. //
  203. HICON lock_icon = (HICON)::LoadImage (::AfxGetResourceHandle (), MAKEINTRESOURCE (IDI_LOCK), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
  204. SendDlgItemMessage (IDC_LOCKED_CHECK, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)lock_icon);
  205. SendDlgItemMessage (IDC_LOCKED_CHECK, BM_SETCHECK, (WPARAM)is_locked);
  206. //
  207. // Set the check state of the "Is Innate" and "Is Key" checkboxes
  208. //
  209. SendDlgItemMessage (IDC_INNATE_CHECK, BM_SETCHECK, (WPARAM)m_Conversation->Is_Innate ());
  210. SendDlgItemMessage (IDC_KEY_CONVESATION_CHECK, BM_SETCHECK, (WPARAM)m_Conversation->Is_Key ());
  211. //
  212. // Configure the columns
  213. //
  214. m_ListCtrl.InsertColumn (COL_ORATOR, "Orator");
  215. m_ListCtrl.InsertColumn (COL_REMARK, "Remark");
  216. m_ListCtrl.SetExtendedStyle (m_ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
  217. //
  218. // Choose an appropriate size for the columns
  219. //
  220. CRect rect;
  221. m_ListCtrl.GetClientRect (&rect);
  222. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL) + 2;
  223. m_ListCtrl.SetColumnWidth (COL_ORATOR, rect.Width () / 4);
  224. m_ListCtrl.SetColumnWidth (COL_REMARK, (rect.Width () * 3) / 4);
  225. //
  226. // Fill in the conversation's name into the appropriate control
  227. //
  228. SetDlgItemText (IDC_CONVERSATION_NAME, m_Conversation->Get_Name ());
  229. //
  230. // Add all the remark's to the list control
  231. //
  232. int count = m_Conversation->Get_Remark_Count ();
  233. for (index = 0; index < count; index ++) {
  234. ConversationRemarkClass remark;
  235. if (m_Conversation->Get_Remark_Info (index, remark)) {
  236. Add_Entry (remark);
  237. }
  238. }
  239. return TRUE;
  240. }
  241. /////////////////////////////////////////////////////////////////////////////
  242. //
  243. // OnDblclkRemarkList
  244. //
  245. /////////////////////////////////////////////////////////////////////////////
  246. void
  247. EditConversationDialogClass::OnDblclkRemarkList
  248. (
  249. NMHDR * pNMHDR,
  250. LRESULT* pResult
  251. )
  252. {
  253. (*pResult) = 0;
  254. //
  255. // Determine which entry the user double-clicked on
  256. //
  257. int sel_index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  258. if (sel_index != -1) {
  259. //
  260. // Lookup the information about this entry
  261. //
  262. ConversationRemarkClass *remark = Get_Entry_Data (sel_index);
  263. //
  264. // Make a bitmask of the orators that are configured
  265. //
  266. int orator_bitmask = 0;
  267. for (int index = 0; index < ORATOR_MAX; index ++) {
  268. if (SendDlgItemMessage (ORATOR_CTRLS[index].button_id, BM_GETCHECK) == 1) {
  269. orator_bitmask |= (1 << index);
  270. }
  271. }
  272. //
  273. // Show a dialog to the user that will let them choose an orator and
  274. // a remark
  275. //
  276. EditConversationRemarkDialogClass dialog (this);
  277. dialog.Set_Remark (*remark);
  278. dialog.Set_Orator_Bitmask (orator_bitmask);
  279. if (dialog.DoModal () == IDOK) {
  280. //
  281. // Get the new values from the dialog
  282. //
  283. (*remark) = dialog.Get_Remark ();
  284. //
  285. // Update the orator id in the list control
  286. //
  287. CString orator_text;
  288. orator_text.Format ("%d", remark->Get_Orator_ID () + 1);
  289. m_ListCtrl.SetItemText (sel_index, COL_ORATOR, orator_text);
  290. //
  291. // Update the text entry in the list control
  292. //
  293. TDBObjClass *translate_obj = TranslateDBClass::Find_Object (remark->Get_Text_ID ());
  294. if (translate_obj != NULL) {
  295. m_ListCtrl.SetItemText (sel_index, COL_REMARK, translate_obj->Get_English_String ());
  296. }
  297. }
  298. }
  299. return ;
  300. }
  301. /////////////////////////////////////////////////////////////////////////////
  302. //
  303. // OnKeydownRemarkList
  304. //
  305. /////////////////////////////////////////////////////////////////////////////
  306. void
  307. EditConversationDialogClass::OnKeydownRemarkList
  308. (
  309. NMHDR * pNMHDR,
  310. LRESULT * pResult
  311. )
  312. {
  313. LV_KEYDOWN* pLVKeyDow = (LV_KEYDOWN*)pNMHDR;
  314. (*pResult) = 0;
  315. if (pLVKeyDow->wVKey == VK_DELETE) {
  316. //
  317. // Delete all the selected items
  318. //
  319. int index = -1;
  320. while ((index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL)) >= 0) {
  321. m_ListCtrl.DeleteItem (index);
  322. }
  323. }
  324. return ;
  325. }
  326. /////////////////////////////////////////////////////////////////////////////
  327. //
  328. // OnOK
  329. //
  330. /////////////////////////////////////////////////////////////////////////////
  331. void
  332. EditConversationDialogClass::OnOK (void)
  333. {
  334. CDialog::OnOK ();
  335. //
  336. // Read the state this conversation is active for
  337. //
  338. int ai_state = SendDlgItemMessage (IDC_STATE_COMBO, CB_GETCURSEL);
  339. if (ai_state != CB_ERR) {
  340. m_Conversation->Set_AI_State (SoldierAIState(ai_state));
  341. }
  342. //
  343. // Pass the name onto the conversation
  344. //
  345. CString name;
  346. GetDlgItemText (IDC_CONVERSATION_NAME, name);
  347. m_Conversation->Set_Name (name);
  348. //
  349. // Start fresh
  350. //
  351. m_Conversation->Clear_Remarks ();
  352. m_Conversation->Clear_Orators ();
  353. //
  354. // Get all the conversations from the list control and add them to the
  355. // conversation manager
  356. //
  357. for (int index = 0; index < m_ListCtrl.GetItemCount (); index ++) {
  358. ConversationRemarkClass *remark = Get_Entry_Data (index);
  359. m_Conversation->Add_Remark (*remark);
  360. }
  361. //
  362. // Build a list of orators for the conversation
  363. //
  364. for (index = 0; index < ORATOR_MAX; index ++) {
  365. //
  366. // Is this orator configured?
  367. //
  368. if (SendDlgItemMessage (ORATOR_CTRLS[index].button_id, BM_GETCHECK) == 1) {
  369. bool is_invisible = (SendDlgItemMessage (ORATOR_CTRLS[index].check_id, BM_GETCHECK) != 1);
  370. //
  371. // Add the orator to the conversation
  372. //
  373. OratorClass orator;
  374. orator.Set_ID (index);
  375. orator.Set_Orator_Type (Get_Orator_Type (index));
  376. orator.Set_Is_Invisible (is_invisible);
  377. m_Conversation->Add_Orator (orator);
  378. }
  379. }
  380. //
  381. // Get the ID of the object to look at (if any)
  382. //
  383. int obj_id = GetDlgItemInt (IDC_OBJECT_ID);
  384. m_Conversation->Set_Look_At_Obj_ID (obj_id);
  385. //
  386. // Read the users "innate" selection
  387. //
  388. bool is_innate = bool(SendDlgItemMessage (IDC_INNATE_CHECK, BM_GETCHECK) == 1);
  389. m_Conversation->Set_Is_Innate (is_innate);
  390. bool is_key = bool(SendDlgItemMessage (IDC_KEY_CONVESATION_CHECK, BM_GETCHECK) == 1);
  391. m_Conversation->Set_Is_Key (is_key);
  392. return ;
  393. }
  394. /////////////////////////////////////////////////////////////////////////////
  395. //
  396. // OnAdd
  397. //
  398. /////////////////////////////////////////////////////////////////////////////
  399. void
  400. EditConversationDialogClass::OnAdd (void)
  401. {
  402. //
  403. // Make a bitmask of the orators that are configured
  404. //
  405. int orator_bitmask = 0;
  406. for (int index = 0; index < ORATOR_MAX; index ++) {
  407. if (SendDlgItemMessage (ORATOR_CTRLS[index].button_id, BM_GETCHECK) == 1) {
  408. orator_bitmask |= (1 << index);
  409. }
  410. }
  411. EditConversationRemarkDialogClass dialog (this);
  412. dialog.Set_Orator_Bitmask (orator_bitmask);
  413. if (dialog.DoModal () == IDOK) {
  414. //
  415. // Insert a new entry into the list control
  416. //
  417. Add_Entry (dialog.Get_Remark ());
  418. }
  419. return ;
  420. }
  421. /////////////////////////////////////////////////////////////////////////////
  422. //
  423. // Set_Conversation
  424. //
  425. /////////////////////////////////////////////////////////////////////////////
  426. void
  427. EditConversationDialogClass::Set_Conversation (ConversationClass *conversation)
  428. {
  429. REF_PTR_SET (m_Conversation, conversation);
  430. return ;
  431. }
  432. /////////////////////////////////////////////////////////////////////////////
  433. //
  434. // Get_Entry_Data
  435. //
  436. /////////////////////////////////////////////////////////////////////////////
  437. ConversationRemarkClass *
  438. EditConversationDialogClass::Get_Entry_Data (int index)
  439. {
  440. return (ConversationRemarkClass *)m_ListCtrl.GetItemData (index);
  441. }
  442. /////////////////////////////////////////////////////////////////////////////
  443. //
  444. // Add_Entry
  445. //
  446. /////////////////////////////////////////////////////////////////////////////
  447. void
  448. EditConversationDialogClass::Add_Entry (const ConversationRemarkClass &remark, int insert_index)
  449. {
  450. //
  451. // Insert this item into the list control
  452. //
  453. CString orator_text;
  454. orator_text.Format ("%d", remark.Get_Orator_ID () + 1);
  455. int item_index = m_ListCtrl.InsertItem (insert_index, orator_text);
  456. if (item_index >= 0) {
  457. //
  458. // Lookup the text to display for this remark
  459. //
  460. TDBObjClass *translate_obj = TranslateDBClass::Find_Object (remark.Get_Text_ID ());
  461. if (translate_obj != NULL) {
  462. m_ListCtrl.SetItemText (item_index, COL_REMARK, translate_obj->Get_English_String ());
  463. //
  464. // Allocate a remark object to associate with this entry in the list control
  465. //
  466. ConversationRemarkClass *associated_remark = new ConversationRemarkClass (remark);
  467. m_ListCtrl.SetItemData (item_index, (DWORD)associated_remark);
  468. }
  469. }
  470. return ;
  471. }
  472. /////////////////////////////////////////////////////////////////////////////
  473. //
  474. // OnInsert
  475. //
  476. /////////////////////////////////////////////////////////////////////////////
  477. void
  478. EditConversationDialogClass::OnInsert (void)
  479. {
  480. int sel_index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  481. if (sel_index != -1) {
  482. //
  483. // Make a bitmask of the orators that are configured
  484. //
  485. int orator_bitmask = 0;
  486. for (int index = 0; index < ORATOR_MAX; index ++) {
  487. if (SendDlgItemMessage (ORATOR_CTRLS[index].button_id, BM_GETCHECK) == 1) {
  488. orator_bitmask |= (1 << index);
  489. }
  490. }
  491. EditConversationRemarkDialogClass dialog (this);
  492. dialog.Set_Orator_Bitmask (orator_bitmask);
  493. if (dialog.DoModal () == IDOK) {
  494. //
  495. // Insert the new entry into the appropriate place in the list
  496. //
  497. Add_Entry (dialog.Get_Remark (), sel_index);
  498. }
  499. }
  500. return ;
  501. }
  502. /////////////////////////////////////////////////////////////////////////////
  503. //
  504. // OnItemchangedRemarkList
  505. //
  506. /////////////////////////////////////////////////////////////////////////////
  507. void
  508. EditConversationDialogClass::OnItemchangedRemarkList
  509. (
  510. NMHDR * pNMHDR,
  511. LRESULT * pResult
  512. )
  513. {
  514. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  515. (*pResult) = 0;
  516. Update_Button_States ();
  517. return ;
  518. }
  519. /////////////////////////////////////////////////////////////////////////////
  520. //
  521. // Update_Button_States
  522. //
  523. /////////////////////////////////////////////////////////////////////////////
  524. void
  525. EditConversationDialogClass::Update_Button_States (void)
  526. {
  527. int sel_index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  528. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_INSERT), static_cast<bool>(sel_index != -1));
  529. return ;
  530. }
  531. /////////////////////////////////////////////////////////////////////////////
  532. //
  533. // OnCommand
  534. //
  535. /////////////////////////////////////////////////////////////////////////////
  536. BOOL
  537. EditConversationDialogClass::OnCommand
  538. (
  539. WPARAM wParam,
  540. LPARAM lParam
  541. )
  542. {
  543. switch (LOWORD (wParam)) {
  544. case IDC_ORATOR1_CHECK:
  545. case IDC_ORATOR2_CHECK:
  546. case IDC_ORATOR3_CHECK:
  547. case IDC_ORATOR4_CHECK:
  548. case IDC_ORATOR5_CHECK:
  549. case IDC_ORATOR6_CHECK:
  550. {
  551. Update_Enable_State (LOWORD (wParam) - IDC_ORATOR1_CHECK);
  552. Update_Remarks (LOWORD (wParam) - IDC_ORATOR1_CHECK);
  553. }
  554. break;
  555. case IDC_ORATOR1_COMBO:
  556. case IDC_ORATOR2_COMBO:
  557. case IDC_ORATOR3_COMBO:
  558. case IDC_ORATOR4_COMBO:
  559. case IDC_ORATOR5_COMBO:
  560. case IDC_ORATOR6_COMBO:
  561. {
  562. if (HIWORD (wParam) == CBN_SELCHANGE) {
  563. Update_Player_Type_Combos (LOWORD (wParam) - IDC_ORATOR1_COMBO);
  564. }
  565. }
  566. break;
  567. }
  568. return CDialog::OnCommand (wParam, lParam);
  569. }
  570. /////////////////////////////////////////////////////////////////////////////
  571. //
  572. // Update_Remarks
  573. //
  574. /////////////////////////////////////////////////////////////////////////////
  575. void
  576. EditConversationDialogClass::Update_Remarks (int orator_index)
  577. {
  578. BOOL is_checked = (SendDlgItemMessage (ORATOR_CTRLS[orator_index].button_id, BM_GETCHECK) == 1);
  579. if (is_checked == false) {
  580. //
  581. // Remove any remarks made by the specified orator
  582. //
  583. int item_count = m_ListCtrl.GetItemCount ();
  584. for (int index = 0; index < item_count; index ++) {
  585. ConversationRemarkClass *remark = Get_Entry_Data (index);
  586. //
  587. // Remove this entry if it was made by the orator in question
  588. //
  589. if (remark != NULL && remark->Get_Orator_ID () == orator_index) {
  590. m_ListCtrl.DeleteItem (index);
  591. index --;
  592. item_count --;
  593. }
  594. }
  595. }
  596. return ;
  597. }
  598. /////////////////////////////////////////////////////////////////////////////
  599. //
  600. // Update_Enable_State
  601. //
  602. /////////////////////////////////////////////////////////////////////////////
  603. void
  604. EditConversationDialogClass::Update_Enable_State (int orator_index)
  605. {
  606. BOOL is_checked = (SendDlgItemMessage (ORATOR_CTRLS[orator_index].button_id, BM_GETCHECK) == 1);
  607. ::EnableWindow (::GetDlgItem (m_hWnd, ORATOR_CTRLS[orator_index].combo_id), is_checked);
  608. ::EnableWindow (::GetDlgItem (m_hWnd, ORATOR_CTRLS[orator_index].check_id), is_checked);
  609. return ;
  610. }
  611. /////////////////////////////////////////////////////////////////////////////
  612. //
  613. // Update_Player_Type_Combos
  614. //
  615. /////////////////////////////////////////////////////////////////////////////
  616. void
  617. EditConversationDialogClass::Update_Player_Type_Combos (int orator_index)
  618. {
  619. BOOL is_locked = (SendDlgItemMessage (IDC_LOCKED_CHECK, BM_GETCHECK) == 1);
  620. if (is_locked) {
  621. //
  622. // Get the current selection
  623. //
  624. int curr_sel = SendDlgItemMessage (ORATOR_CTRLS[orator_index].combo_id, CB_GETCURSEL);
  625. //
  626. // Update all the combo boxes to reflect the current selection
  627. //
  628. for (int index = 0; index < ORATOR_MAX; index ++) {
  629. SendDlgItemMessage (ORATOR_CTRLS[index].combo_id, CB_SETCURSEL, (WPARAM)curr_sel);
  630. }
  631. }
  632. return ;
  633. }
  634. /////////////////////////////////////////////////////////////////////////////
  635. //
  636. // Get_Orator_Type
  637. //
  638. /////////////////////////////////////////////////////////////////////////////
  639. int
  640. EditConversationDialogClass::Get_Orator_Type (int orator_index)
  641. {
  642. int retval = -1;
  643. //
  644. // Get the current selection
  645. //
  646. int curr_sel = SendDlgItemMessage (ORATOR_CTRLS[orator_index].combo_id, CB_GETCURSEL);
  647. if (curr_sel >= 0) {
  648. retval = SendDlgItemMessage (ORATOR_CTRLS[orator_index].combo_id, CB_GETITEMDATA, (WPARAM)curr_sel);
  649. }
  650. return retval;
  651. }
  652. /////////////////////////////////////////////////////////////////////////////
  653. //
  654. // OnDeleteitemRemarkList
  655. //
  656. /////////////////////////////////////////////////////////////////////////////
  657. void
  658. EditConversationDialogClass::OnDeleteitemRemarkList
  659. (
  660. NMHDR * pNMHDR,
  661. LRESULT * pResult
  662. )
  663. {
  664. NM_LISTVIEW *pNMListView = (NM_LISTVIEW *)pNMHDR;
  665. (*pResult) = 0;
  666. //
  667. // Lookup the associated remark object
  668. //
  669. ConversationRemarkClass *remark = NULL;
  670. remark = (ConversationRemarkClass *)m_ListCtrl.GetItemData (pNMListView->iItem);
  671. //
  672. // Free the object
  673. //
  674. SAFE_DELETE (remark);
  675. m_ListCtrl.SetItemData (pNMListView->iItem, 0);
  676. return ;
  677. }
  678. /////////////////////////////////////////////////////////////////////////////
  679. //
  680. // Find_Combobox_Entry
  681. //
  682. /////////////////////////////////////////////////////////////////////////////
  683. int
  684. EditConversationDialogClass::Find_Combobox_Entry (int orator_type)
  685. {
  686. int retval = -1;
  687. //
  688. // Loop over all the entries in the combobox until we've found
  689. // the one that's associated with the given orator type
  690. //
  691. int count = SendDlgItemMessage (IDC_ORATOR1_COMBO, CB_GETCOUNT);
  692. for (int index = 0; index < count; index ++) {
  693. //
  694. // Is this the orator we are looking for?
  695. //
  696. int item_data = SendDlgItemMessage (IDC_ORATOR1_COMBO, CB_GETITEMDATA, (WPARAM)index);
  697. if (item_data == orator_type) {
  698. retval = index;
  699. break;
  700. }
  701. }
  702. return retval;
  703. }