EditDialogueDialog.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. // EditDialogueDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "editdialoguedialog.h"
  23. #include "dialogue.h"
  24. #include "translatedb.h"
  25. #include "translateobj.h"
  26. #include "utils.h"
  27. #include "conversationpickerdialog.h"
  28. #include "conversationmgr.h"
  29. #include "conversation.h"
  30. #ifdef _DEBUG
  31. #define new DEBUG_NEW
  32. #undef THIS_FILE
  33. static char THIS_FILE[] = __FILE__;
  34. #endif
  35. /////////////////////////////////////////////////////////////////////////////
  36. // Constants
  37. /////////////////////////////////////////////////////////////////////////////
  38. enum
  39. {
  40. COL_WEIGHT = 0,
  41. COL_TEXT
  42. };
  43. /////////////////////////////////////////////////////////////////////////////
  44. //
  45. // EditDialogueDialogClass
  46. //
  47. /////////////////////////////////////////////////////////////////////////////
  48. EditDialogueDialogClass::EditDialogueDialogClass(CWnd* pParent /*=NULL*/)
  49. : m_Dialogue (NULL),
  50. CDialog(EditDialogueDialogClass::IDD, pParent)
  51. {
  52. //{{AFX_DATA_INIT(EditDialogueDialogClass)
  53. // NOTE: the ClassWizard will add member initialization here
  54. //}}AFX_DATA_INIT
  55. return ;
  56. }
  57. /////////////////////////////////////////////////////////////////////////////
  58. //
  59. // DoDataExchange
  60. //
  61. /////////////////////////////////////////////////////////////////////////////
  62. void
  63. EditDialogueDialogClass::DoDataExchange (CDataExchange *pDX)
  64. {
  65. CDialog::DoDataExchange(pDX);
  66. //{{AFX_DATA_MAP(EditDialogueDialogClass)
  67. DDX_Control(pDX, IDC_SELECTED_WEIGHT_SPIN, m_SelectedWeightSpin);
  68. DDX_Control(pDX, IDC_SILENCE_WEIGHT_SPIN, m_SilenceWeightSpin);
  69. DDX_Control(pDX, IDC_REMARK_LIST, m_ListCtrl);
  70. //}}AFX_DATA_MAP
  71. return ;
  72. }
  73. BEGIN_MESSAGE_MAP(EditDialogueDialogClass, CDialog)
  74. //{{AFX_MSG_MAP(EditDialogueDialogClass)
  75. ON_BN_CLICKED(IDC_ADD, OnAdd)
  76. ON_BN_CLICKED(IDC_DELETE, OnDelete)
  77. ON_NOTIFY(NM_DBLCLK, IDC_REMARK_LIST, OnDblclkOptionList)
  78. ON_NOTIFY(LVN_DELETEITEM, IDC_REMARK_LIST, OnDeleteitemOptionList)
  79. ON_NOTIFY(LVN_ITEMCHANGED, IDC_REMARK_LIST, OnItemchangedRemarkList)
  80. ON_NOTIFY(UDN_DELTAPOS, IDC_SELECTED_WEIGHT_SPIN, OnDeltaposSelectedWeightSpin)
  81. ON_EN_KILLFOCUS(IDC_SELECTED_WEIGHT_EDIT, OnKillfocusSelectedWeightEdit)
  82. ON_WM_VSCROLL()
  83. //}}AFX_MSG_MAP
  84. END_MESSAGE_MAP()
  85. /////////////////////////////////////////////////////////////////////////////
  86. //
  87. // OnInitDialog
  88. //
  89. /////////////////////////////////////////////////////////////////////////////
  90. BOOL
  91. EditDialogueDialogClass::OnInitDialog (void)
  92. {
  93. CDialog::OnInitDialog();
  94. ASSERT (m_Dialogue != NULL);
  95. //
  96. // Configure the list control
  97. //
  98. m_ListCtrl.InsertColumn (COL_WEIGHT, "Weight");
  99. m_ListCtrl.InsertColumn (COL_TEXT, "Text");
  100. m_ListCtrl.SetExtendedStyle (m_ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
  101. //
  102. // Choose a size for the list control's columns
  103. //
  104. CRect rect;
  105. m_ListCtrl.GetClientRect (&rect);
  106. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL);
  107. m_ListCtrl.SetColumnWidth (COL_WEIGHT, rect.Width () / 6);
  108. m_ListCtrl.SetColumnWidth (COL_TEXT, (rect.Width () * 5) / 6);
  109. //
  110. // Insert all of the options into the list control
  111. //
  112. DIALOGUE_OPTION_LIST &option_list = m_Dialogue->Get_Option_List ();
  113. for (int index = 0; index < option_list.Count (); index ++) {
  114. //
  115. // Make a copy of the option and add it to our list
  116. //
  117. DialogueOptionClass *option = new DialogueOptionClass (*(option_list[index]));
  118. Insert_Entry (option);
  119. }
  120. //
  121. // Configure the silence controls
  122. //
  123. m_SilenceWeightSpin.SetRange (0, 100);
  124. m_SilenceWeightSpin.SetPos ((int)m_Dialogue->Get_Silence_Weight ());
  125. SetDlgItemInt (IDC_SILENCE_WEIGHT_EDIT, (int)m_Dialogue->Get_Silence_Weight ());
  126. //
  127. // Configure the other weight controls
  128. //
  129. m_SelectedWeightSpin.SetRange (0, 10000);
  130. m_SelectedWeightSpin.SetPos (0);
  131. //
  132. // Update the enabled state of some of the controls on the dialog
  133. //
  134. Update_Enabled_State ();
  135. return TRUE;
  136. }
  137. /////////////////////////////////////////////////////////////////////////////
  138. //
  139. // OnOK
  140. //
  141. /////////////////////////////////////////////////////////////////////////////
  142. void
  143. EditDialogueDialogClass::OnOK (void)
  144. {
  145. //
  146. // Read the silence configuration
  147. //
  148. int new_weight = GetDlgItemInt (IDC_SILENCE_WEIGHT_EDIT);
  149. m_Dialogue->Set_Silence_Weight (new_weight);
  150. //
  151. // Start with a fresh list of options
  152. //
  153. m_Dialogue->Free_Options ();
  154. DIALOGUE_OPTION_LIST &option_list = m_Dialogue->Get_Option_List ();
  155. //
  156. // Read all the options from the list control
  157. //
  158. int count = m_ListCtrl.GetItemCount ();
  159. for (int index = 0; index < count; index ++) {
  160. //
  161. // Add this option to the dialogue's list
  162. //
  163. DialogueOptionClass *option = (DialogueOptionClass *)m_ListCtrl.GetItemData (index);
  164. if (option != NULL) {
  165. option_list.Add (option);
  166. m_ListCtrl.SetItemData (index, NULL);
  167. }
  168. }
  169. CDialog::OnOK ();
  170. return ;
  171. }
  172. /////////////////////////////////////////////////////////////////////////////
  173. //
  174. // OnAdd
  175. //
  176. /////////////////////////////////////////////////////////////////////////////
  177. void
  178. EditDialogueDialogClass::OnAdd (void)
  179. {
  180. //
  181. // Display a dialog that allows the user to edit this option
  182. //
  183. ConversationPickerDialogClass dialog (this);
  184. if (dialog.DoModal () == IDOK) {
  185. //
  186. // Create a new dialog option
  187. //
  188. DialogueOptionClass *option = new DialogueOptionClass;
  189. option->Set_Weight (1);
  190. option->Set_Conversation_ID (dialog.Get_Conversation ()->Get_ID ());
  191. //
  192. // Add the new option to the list
  193. //
  194. Insert_Entry (option);
  195. }
  196. return ;
  197. }
  198. /////////////////////////////////////////////////////////////////////////////
  199. //
  200. // OnDelete
  201. //
  202. /////////////////////////////////////////////////////////////////////////////
  203. void
  204. EditDialogueDialogClass::OnDelete (void)
  205. {
  206. //
  207. // Remove the currently selected item from the list control
  208. //
  209. int index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  210. if (index >= 0) {
  211. m_ListCtrl.DeleteItem (index);
  212. }
  213. return ;
  214. }
  215. /////////////////////////////////////////////////////////////////////////////
  216. //
  217. // OnDblclkOptionList
  218. //
  219. /////////////////////////////////////////////////////////////////////////////
  220. void
  221. EditDialogueDialogClass::OnDblclkOptionList
  222. (
  223. NMHDR * pNMHDR,
  224. LRESULT * pResult
  225. )
  226. {
  227. //
  228. // Get the currently selected option
  229. //
  230. int index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  231. if (index >= 0) {
  232. DialogueOptionClass *option = (DialogueOptionClass *)m_ListCtrl.GetItemData (index);
  233. if (option != NULL) {
  234. //
  235. // Display a dialog that allows the user to edit this option
  236. //
  237. ConversationPickerDialogClass dialog (this);
  238. ConversationClass *conversation = NULL;
  239. conversation = ConversationMgrClass::Find_Conversation (option->Get_Conversation_ID ());
  240. dialog.Set_Conversation (conversation);
  241. if (dialog.DoModal () == IDOK) {
  242. //
  243. // Update the entry in the list
  244. //
  245. option->Set_Conversation_ID (dialog.Get_Conversation ()->Get_ID ());
  246. Update_Entry (index);
  247. }
  248. REF_PTR_RELEASE (conversation);
  249. }
  250. }
  251. return ;
  252. }
  253. /////////////////////////////////////////////////////////////////////////////
  254. //
  255. // OnDeleteitemOptionList
  256. //
  257. /////////////////////////////////////////////////////////////////////////////
  258. void
  259. EditDialogueDialogClass::OnDeleteitemOptionList
  260. (
  261. NMHDR * pNMHDR,
  262. LRESULT * pResult
  263. )
  264. {
  265. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  266. (*pResult) = 0;
  267. //
  268. // Free the associated DialogueOptionClass object
  269. //
  270. DialogueOptionClass *option = (DialogueOptionClass *)m_ListCtrl.GetItemData (pNMListView->iItem);
  271. if (option != NULL) {
  272. SAFE_DELETE (option);
  273. m_ListCtrl.SetItemData (pNMListView->iItem, NULL);
  274. }
  275. return ;
  276. }
  277. /////////////////////////////////////////////////////////////////////////////
  278. //
  279. // Update_Entry
  280. //
  281. /////////////////////////////////////////////////////////////////////////////
  282. void
  283. EditDialogueDialogClass::Update_Entry (int index)
  284. {
  285. DialogueOptionClass *option = (DialogueOptionClass *)m_ListCtrl.GetItemData (index);
  286. if (option != NULL) {
  287. //
  288. // Update the weight column of the list control
  289. //
  290. CString weight_text;
  291. weight_text.Format ("%d", (int)option->Get_Weight ());
  292. m_ListCtrl.SetItemText (index, COL_WEIGHT, weight_text);
  293. //
  294. // Lookup the string entry in our translation database
  295. //
  296. int conversation_id = option->Get_Conversation_ID ();
  297. ConversationClass *conversation = ConversationMgrClass::Find_Conversation (conversation_id);
  298. if (conversation != NULL) {
  299. //
  300. // Put this text into the appropriate column in the list control
  301. //
  302. m_ListCtrl.SetItemText (index, COL_TEXT, conversation->Get_Name ());
  303. REF_PTR_RELEASE (conversation);
  304. }
  305. }
  306. return ;
  307. }
  308. /////////////////////////////////////////////////////////////////////////////
  309. //
  310. // Insert_Entry
  311. //
  312. /////////////////////////////////////////////////////////////////////////////
  313. void
  314. EditDialogueDialogClass::Insert_Entry (DialogueOptionClass *option)
  315. {
  316. ASSERT (option != NULL);
  317. if (option != NULL) {
  318. CString weight_text;
  319. weight_text.Format ("%d", (int)option->Get_Weight ());
  320. //
  321. // Add this option to the list control
  322. //
  323. int item_index = m_ListCtrl.InsertItem (m_ListCtrl.GetItemCount (), weight_text);
  324. if (item_index >= 0) {
  325. //
  326. // Associate the object with the entry in the list control
  327. //
  328. m_ListCtrl.SetItemData (item_index, (DWORD)option);
  329. //
  330. // Lookup the string entry in our translation database
  331. //
  332. int conversation_id = option->Get_Conversation_ID ();
  333. ConversationClass *conversation = ConversationMgrClass::Find_Conversation (conversation_id);
  334. if (conversation != NULL) {
  335. //
  336. // Put this text into the appropriate column in the list control
  337. //
  338. m_ListCtrl.SetItemText (item_index, COL_TEXT, conversation->Get_Name ());
  339. REF_PTR_RELEASE (conversation);
  340. }
  341. }
  342. }
  343. return ;
  344. }
  345. /////////////////////////////////////////////////////////////////////////////
  346. //
  347. // OnItemchangedRemarkList
  348. //
  349. /////////////////////////////////////////////////////////////////////////////
  350. void
  351. EditDialogueDialogClass::OnItemchangedRemarkList
  352. (
  353. NMHDR * pNMHDR,
  354. LRESULT * pResult
  355. )
  356. {
  357. NM_LISTVIEW *pNMListView = (NM_LISTVIEW *)pNMHDR;
  358. (*pResult) = 0;
  359. if (pNMListView->uChanged & LVIF_STATE) {
  360. Update_Enabled_State ();
  361. //
  362. // Is there a currently selected item?
  363. //
  364. int item_index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
  365. if (item_index >= 0) {
  366. //
  367. // Update the weight of the selected item
  368. //
  369. DialogueOptionClass *option = (DialogueOptionClass *)m_ListCtrl.GetItemData (item_index);
  370. if (option != NULL) {
  371. SetDlgItemInt (IDC_SELECTED_WEIGHT_EDIT, (int)option->Get_Weight ());
  372. }
  373. }
  374. }
  375. return ;
  376. }
  377. /////////////////////////////////////////////////////////////////////////////
  378. //
  379. // Update_Enabled_State
  380. //
  381. /////////////////////////////////////////////////////////////////////////////
  382. void
  383. EditDialogueDialogClass::Update_Enabled_State (void)
  384. {
  385. int item_index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
  386. bool enabled = (item_index >= 0);
  387. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_DELETE), enabled);
  388. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SELECTED_WEIGHT_EDIT), enabled);
  389. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_SELECTED_WEIGHT_SPIN), enabled);
  390. return ;
  391. }
  392. /////////////////////////////////////////////////////////////////////////////
  393. //
  394. // OnDeltaposSelectedWeightSpin
  395. //
  396. /////////////////////////////////////////////////////////////////////////////
  397. void
  398. EditDialogueDialogClass::OnDeltaposSelectedWeightSpin
  399. (
  400. NMHDR *pNMHDR,
  401. LRESULT *pResult
  402. )
  403. {
  404. NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
  405. (*pResult) = 0;
  406. //Update_Current_Weight ();
  407. return ;
  408. }
  409. /////////////////////////////////////////////////////////////////////////////
  410. //
  411. // OnKillfocusSelectedWeightEdit
  412. //
  413. /////////////////////////////////////////////////////////////////////////////
  414. void
  415. EditDialogueDialogClass::OnKillfocusSelectedWeightEdit (void)
  416. {
  417. Update_Current_Weight ();
  418. return ;
  419. }
  420. /////////////////////////////////////////////////////////////////////////////
  421. //
  422. // Update_Current_Weight
  423. //
  424. /////////////////////////////////////////////////////////////////////////////
  425. void
  426. EditDialogueDialogClass::Update_Current_Weight (void)
  427. {
  428. //
  429. // Is there a currently selected item?
  430. //
  431. int item_index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
  432. if (item_index >= 0) {
  433. DialogueOptionClass *option = (DialogueOptionClass *)m_ListCtrl.GetItemData (item_index);
  434. if (option != NULL) {
  435. //
  436. // Get the weight
  437. //
  438. int weight = GetDlgItemInt (IDC_SELECTED_WEIGHT_EDIT);
  439. //
  440. // Update the weight
  441. //
  442. option->Set_Weight ((float)weight);
  443. Update_Entry (item_index);
  444. }
  445. }
  446. return ;
  447. }
  448. /////////////////////////////////////////////////////////////////////////////
  449. //
  450. // OnVScroll
  451. //
  452. /////////////////////////////////////////////////////////////////////////////
  453. void
  454. EditDialogueDialogClass::OnVScroll
  455. (
  456. UINT nSBCode,
  457. UINT nPos,
  458. CScrollBar *pScrollBar
  459. )
  460. {
  461. Update_Current_Weight ();
  462. return ;
  463. }