ConversationPickerDialog.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. // ConversationPickerDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "conversationpickerdialog.h"
  23. #include "conversationmgr.h"
  24. #include "conversation.h"
  25. #include "utils.h"
  26. #include "icons.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. //
  34. // ConversationPickerDialogClass
  35. //
  36. /////////////////////////////////////////////////////////////////////////////
  37. ConversationPickerDialogClass::ConversationPickerDialogClass (CWnd *pParent /*=NULL*/)
  38. : Conversation (NULL),
  39. GlobalsRoot (NULL),
  40. LevelsRoot (NULL),
  41. CDialog (ConversationPickerDialogClass::IDD, pParent)
  42. {
  43. //{{AFX_DATA_INIT(ConversationPickerDialogClass)
  44. // NOTE: the ClassWizard will add member initialization here
  45. //}}AFX_DATA_INIT
  46. return ;
  47. }
  48. /////////////////////////////////////////////////////////////////////////////
  49. //
  50. // DoDataExchange
  51. //
  52. /////////////////////////////////////////////////////////////////////////////
  53. void
  54. ConversationPickerDialogClass::DoDataExchange (CDataExchange *pDX)
  55. {
  56. CDialog::DoDataExchange(pDX);
  57. //{{AFX_DATA_MAP(ConversationPickerDialogClass)
  58. DDX_Control(pDX, IDC_CONVERSATION_TREE, m_TreeCtrl);
  59. //}}AFX_DATA_MAP
  60. return ;
  61. }
  62. BEGIN_MESSAGE_MAP(ConversationPickerDialogClass, CDialog)
  63. //{{AFX_MSG_MAP(ConversationPickerDialogClass)
  64. ON_NOTIFY(TVN_SELCHANGED, IDC_CONVERSATION_TREE, OnSelchangedConversationTree)
  65. //}}AFX_MSG_MAP
  66. END_MESSAGE_MAP()
  67. /////////////////////////////////////////////////////////////////////////////
  68. //
  69. // OnSelchangedConversationTree
  70. //
  71. /////////////////////////////////////////////////////////////////////////////
  72. void
  73. ConversationPickerDialogClass::OnSelchangedConversationTree
  74. (
  75. NMHDR * pNMHDR,
  76. LRESULT * pResult
  77. )
  78. {
  79. NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *)pNMHDR;
  80. (*pResult) = 0;
  81. Conversation = NULL;
  82. //
  83. // Lookup the currently selected conversation
  84. //
  85. HTREEITEM selected_item = m_TreeCtrl.GetSelectedItem ();
  86. if (selected_item != NULL) {
  87. Conversation = (ConversationClass *)m_TreeCtrl.GetItemData (selected_item);
  88. }
  89. //
  90. // Update the enable state based on whether or not a conversation was selected
  91. //
  92. ::EnableWindow (::GetDlgItem (m_hWnd, IDOK), (Conversation != NULL));
  93. return ;
  94. }
  95. /////////////////////////////////////////////////////////////////////////////
  96. //
  97. // OnInitDialog
  98. //
  99. /////////////////////////////////////////////////////////////////////////////
  100. BOOL
  101. ConversationPickerDialogClass::OnInitDialog (void)
  102. {
  103. CDialog::OnInitDialog ();
  104. //
  105. // Pass the general use imagelist onto the tree control
  106. //
  107. m_TreeCtrl.SetImageList (::Get_Global_Image_List (), TVSIL_NORMAL);
  108. //
  109. // Insert the folders
  110. //
  111. GlobalsRoot = m_TreeCtrl.InsertItem ("Globals", FOLDER_ICON, FOLDER_ICON);
  112. LevelsRoot = m_TreeCtrl.InsertItem ("Level Specific", FOLDER_ICON, FOLDER_ICON);
  113. //
  114. // Add all the conversations to the tree
  115. //
  116. int count = ConversationMgrClass::Get_Conversation_Count ();
  117. for (int index = 0; index < count; index ++) {
  118. Insert_Entry (ConversationMgrClass::Peek_Conversation (index));
  119. }
  120. //
  121. // Open the globals and levels folders
  122. //
  123. m_TreeCtrl.Expand (GlobalsRoot, TVE_EXPAND);
  124. m_TreeCtrl.Expand (LevelsRoot, TVE_EXPAND);
  125. return TRUE;
  126. }
  127. /////////////////////////////////////////////////////////////////////////////
  128. //
  129. // OnOK
  130. //
  131. /////////////////////////////////////////////////////////////////////////////
  132. void
  133. ConversationPickerDialogClass::OnOK (void)
  134. {
  135. if (Conversation != NULL) {
  136. CDialog::OnOK ();
  137. }
  138. return ;
  139. }
  140. /////////////////////////////////////////////////////////////////////////////
  141. //
  142. // Insert_Entry
  143. //
  144. /////////////////////////////////////////////////////////////////////////////
  145. void
  146. ConversationPickerDialogClass::Insert_Entry (ConversationClass *conversation)
  147. {
  148. //
  149. // Determine which folder this conversation goes under
  150. //
  151. HTREEITEM parent_item = LevelsRoot;
  152. if (conversation->Get_Category_ID () != ConversationMgrClass::CATEGORY_LEVEL) {
  153. parent_item = GlobalsRoot;
  154. }
  155. //
  156. // Insert this item into the tree
  157. //
  158. HTREEITEM tree_item = m_TreeCtrl.InsertItem (conversation->Get_Name (), DIALOGUE_ICON,
  159. DIALOGUE_ICON, parent_item);
  160. if (tree_item != NULL) {
  161. //
  162. // Associate the conversation with the entry in the tree
  163. //
  164. m_TreeCtrl.SetItemData (tree_item, (DWORD)conversation);
  165. m_TreeCtrl.SortChildren (parent_item);
  166. //
  167. // Select this conversation if necessary
  168. //
  169. if (conversation == Conversation) {
  170. m_TreeCtrl.SelectItem (tree_item);
  171. m_TreeCtrl.EnsureVisible (tree_item);
  172. }
  173. }
  174. return ;
  175. }