PresetDialogueTab.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. // PresetDialogueTab.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "presetdialoguetab.h"
  23. #include "definition.h"
  24. #include "preset.h"
  25. #include "utils.h"
  26. #include "dialogue.h"
  27. #include "combatchunkid.h"
  28. #include "soldier.h"
  29. #include "translateobj.h"
  30. #include "translatedb.h"
  31. #include "editdialoguedialog.h"
  32. #include "conversationmgr.h"
  33. #include "conversation.h"
  34. #ifdef _DEBUG
  35. #define new DEBUG_NEW
  36. #undef THIS_FILE
  37. static char THIS_FILE[] = __FILE__;
  38. #endif
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Constants
  41. /////////////////////////////////////////////////////////////////////////////
  42. enum
  43. {
  44. COL_EVENT = 0,
  45. COL_TEXT
  46. };
  47. /////////////////////////////////////////////////////////////////////////////
  48. //
  49. // PresetDialogueTabClass
  50. //
  51. /////////////////////////////////////////////////////////////////////////////
  52. PresetDialogueTabClass::PresetDialogueTabClass (PresetClass *preset)
  53. : m_Definition (NULL),
  54. m_DialogueList (NULL),
  55. m_IsReadOnly (false),
  56. DockableFormClass(PresetDialogueTabClass::IDD)
  57. {
  58. //{{AFX_DATA_INIT(PresetDialogueTabClass)
  59. // NOTE: the ClassWizard will add member initialization here
  60. //}}AFX_DATA_INIT
  61. //
  62. // Dig the soldier game object definition out from the preset
  63. //
  64. if (preset != NULL) {
  65. DefinitionClass *definition = preset->Get_Definition ();
  66. if (definition != NULL && definition->Get_Class_ID () == CLASSID_GAME_OBJECT_DEF_SOLDIER) {
  67. m_Definition = (SoldierGameObjDef *)definition;
  68. }
  69. }
  70. return ;
  71. }
  72. /////////////////////////////////////////////////////////////////////////////
  73. //
  74. // ~PresetDialogueTabClass
  75. //
  76. /////////////////////////////////////////////////////////////////////////////
  77. PresetDialogueTabClass::~PresetDialogueTabClass (void)
  78. {
  79. SAFE_DELETE_ARRAY (m_DialogueList);
  80. return ;
  81. }
  82. /////////////////////////////////////////////////////////////////////////////
  83. //
  84. // DoDataExchange
  85. //
  86. /////////////////////////////////////////////////////////////////////////////
  87. void
  88. PresetDialogueTabClass::DoDataExchange (CDataExchange *pDX)
  89. {
  90. DockableFormClass::DoDataExchange(pDX);
  91. //{{AFX_DATA_MAP(PresetDialogueTabClass)
  92. DDX_Control(pDX, IDC_DIALOGUE_LIST, m_ListCtrl);
  93. //}}AFX_DATA_MAP
  94. return ;
  95. }
  96. BEGIN_MESSAGE_MAP(PresetDialogueTabClass, DockableFormClass)
  97. //{{AFX_MSG_MAP(PresetDialogueTabClass)
  98. ON_NOTIFY(NM_DBLCLK, IDC_DIALOGUE_LIST, OnDblclkDialogueList)
  99. //}}AFX_MSG_MAP
  100. END_MESSAGE_MAP()
  101. /////////////////////////////////////////////////////////////////////////////
  102. // PresetDialogueTabClass diagnostics
  103. #ifdef _DEBUG
  104. void PresetDialogueTabClass::AssertValid() const
  105. {
  106. DockableFormClass::AssertValid();
  107. }
  108. void PresetDialogueTabClass::Dump(CDumpContext& dc) const
  109. {
  110. DockableFormClass::Dump(dc);
  111. }
  112. #endif //_DEBUG
  113. /////////////////////////////////////////////////////////////////////////////
  114. //
  115. // HandleInitDialog
  116. //
  117. /////////////////////////////////////////////////////////////////////////////
  118. void
  119. PresetDialogueTabClass::HandleInitDialog (void)
  120. {
  121. ASSERT (m_Definition != NULL);
  122. //
  123. // Configure the list control
  124. //
  125. m_ListCtrl.InsertColumn (COL_EVENT, "Event");
  126. m_ListCtrl.InsertColumn (COL_TEXT, "Text");
  127. m_ListCtrl.SetExtendedStyle (m_ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
  128. //
  129. // Choose a size for the list control's columns
  130. //
  131. CRect rect;
  132. m_ListCtrl.GetClientRect (&rect);
  133. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL);
  134. m_ListCtrl.SetColumnWidth (COL_EVENT, rect.Width () / 2);
  135. m_ListCtrl.SetColumnWidth (COL_TEXT, rect.Width () / 2);
  136. //
  137. // Allocate our own copy of the dialog list
  138. //
  139. m_DialogueList = new DialogueClass[DIALOG_MAX];
  140. //
  141. // Get the list of dialogues from the definition
  142. //
  143. DialogueClass *dialog_list = m_Definition->Get_Dialog_List ();
  144. for (int index = 0; index < DIALOG_MAX; index ++) {
  145. //
  146. // Copy this dialog from the definition's list to our own internal list
  147. //
  148. m_DialogueList[index] = dialog_list[index];
  149. //
  150. // Add an entry to the list control for this dialogue
  151. //
  152. int item_index = m_ListCtrl.InsertItem (index, DIALOG_EVENT_NAMES[index]);
  153. if (item_index >= 0) {
  154. Update_Entry (item_index);
  155. }
  156. }
  157. //
  158. // Make the controls read-only if necessary
  159. //
  160. if (m_IsReadOnly) {
  161. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_DIALOGUE_LIST), false);
  162. }
  163. //
  164. // Put the focus into the list control
  165. //
  166. ::SetFocus (::GetDlgItem (m_hWnd, IDC_DIALOGUE_LIST));
  167. return ;
  168. }
  169. /////////////////////////////////////////////////////////////////////////////
  170. //
  171. // Apply_Changes
  172. //
  173. /////////////////////////////////////////////////////////////////////////////
  174. bool
  175. PresetDialogueTabClass::Apply_Changes (void)
  176. {
  177. DialogueClass *dialog_list = m_Definition->Get_Dialog_List ();
  178. //
  179. // Copy the changes into the definition's dialog list
  180. //
  181. for (int index = 0; index < DIALOG_MAX; index ++) {
  182. dialog_list[index] = m_DialogueList[index];
  183. }
  184. return true;
  185. }
  186. /////////////////////////////////////////////////////////////////////////////
  187. //
  188. // OnDblclkDialogueList
  189. //
  190. /////////////////////////////////////////////////////////////////////////////
  191. void
  192. PresetDialogueTabClass::OnDblclkDialogueList
  193. (
  194. NMHDR * pNMHDR,
  195. LRESULT * pResult
  196. )
  197. {
  198. (*pResult) = 0;
  199. //
  200. // Get the index of the currently selected entry
  201. //
  202. int index = m_ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  203. if (index >= 0 && index < DIALOG_MAX) {
  204. //
  205. // Show a dialog to the user that will allow them to edit this entry
  206. //
  207. EditDialogueDialogClass dialog (this);
  208. dialog.Set_Dialogue (&m_DialogueList[index]);
  209. if (dialog.DoModal () == IDOK) {
  210. Update_Entry (index);
  211. InvalidateRect (NULL, TRUE);
  212. //UpdateWindow ();
  213. }
  214. }
  215. return ;
  216. }
  217. /////////////////////////////////////////////////////////////////////////////
  218. //
  219. // Update_Entry
  220. //
  221. /////////////////////////////////////////////////////////////////////////////
  222. void
  223. PresetDialogueTabClass::Update_Entry (int index)
  224. {
  225. //
  226. // Just pick the first remark in the list
  227. //
  228. DIALOGUE_OPTION_LIST &option_list = m_DialogueList[index].Get_Option_List ();
  229. if (option_list.Count () > 0) {
  230. //
  231. // Lookup the string entry in our translation database
  232. //
  233. int conversation_id = option_list[0]->Get_Conversation_ID ();
  234. ConversationClass *conversation = ConversationMgrClass::Find_Conversation (conversation_id);
  235. if (conversation != NULL) {
  236. //
  237. // Put this text into the appropriate column in the list control
  238. //
  239. m_ListCtrl.SetItemText (index, COL_TEXT, conversation->Get_Name ());
  240. REF_PTR_RELEASE (conversation);
  241. }
  242. } else {
  243. m_ListCtrl.SetItemText (index, COL_TEXT, "");
  244. }
  245. return ;
  246. }