EditStringTwiddlerDialog.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. // EditStringTwiddlerDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "editstringtwiddlerdialog.h"
  23. #include "editstringdialog.h"
  24. #include "stringtwiddler.h"
  25. #include "stringpickermaindialog.h"
  26. #ifdef _DEBUG
  27. #define new DEBUG_NEW
  28. #undef THIS_FILE
  29. static char THIS_FILE[] = __FILE__;
  30. #endif
  31. /////////////////////////////////////////////////////////////////////////////
  32. //
  33. // EditStringTwiddlerDialogClass
  34. //
  35. /////////////////////////////////////////////////////////////////////////////
  36. EditStringTwiddlerDialogClass::EditStringTwiddlerDialogClass (CWnd *pParent /*=NULL*/) :
  37. StringObject (NULL),
  38. CDialog (EditStringTwiddlerDialogClass::IDD, pParent)
  39. {
  40. //{{AFX_DATA_INIT(EditStringTwiddlerDialogClass)
  41. // NOTE: the ClassWizard will add member initialization here
  42. //}}AFX_DATA_INIT
  43. return ;
  44. }
  45. /////////////////////////////////////////////////////////////////////////////
  46. //
  47. // DoDataExchange
  48. //
  49. /////////////////////////////////////////////////////////////////////////////
  50. void
  51. EditStringTwiddlerDialogClass::DoDataExchange (CDataExchange *pDX)
  52. {
  53. CDialog::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(EditStringTwiddlerDialogClass)
  55. DDX_Control(pDX, IDC_LISTCTRL, ListCtrl);
  56. //}}AFX_DATA_MAP
  57. return ;
  58. }
  59. BEGIN_MESSAGE_MAP(EditStringTwiddlerDialogClass, CDialog)
  60. //{{AFX_MSG_MAP(EditStringTwiddlerDialogClass)
  61. ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
  62. ON_NOTIFY(LVN_KEYDOWN, IDC_LISTCTRL, OnKeydownListctrl)
  63. //}}AFX_MSG_MAP
  64. END_MESSAGE_MAP()
  65. /////////////////////////////////////////////////////////////////////////////
  66. //
  67. // OnInitDialog
  68. //
  69. /////////////////////////////////////////////////////////////////////////////
  70. BOOL
  71. EditStringTwiddlerDialogClass::OnInitDialog (void)
  72. {
  73. CDialog::OnInitDialog ();
  74. //
  75. // Configure the list control
  76. //
  77. ListCtrl.InsertColumn (0, "String ID");
  78. //
  79. // Size the column
  80. //
  81. CRect rect;
  82. ListCtrl.GetClientRect (&rect);
  83. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL) + 2;
  84. ListCtrl.SetColumnWidth (0, rect.Width ());
  85. //
  86. // Fill in the text control
  87. //
  88. if (StringObject != NULL) {
  89. SetDlgItemText (IDC_CODEID_EDIT, StringObject->Get_ID_Desc ());
  90. //
  91. // Add the list of strings to the database
  92. //
  93. for (int index = 0; index < StringObject->Get_String_Count (); index ++) {
  94. Insert_String (StringObject->Get_String (index));
  95. }
  96. } else {
  97. SetDlgItemText (IDC_CODEID_EDIT, "IDS_");
  98. }
  99. //
  100. // Select the CODE ID so the user can enter a valid ID
  101. //
  102. ::SetFocus (::GetDlgItem (m_hWnd, IDC_CODEID_EDIT));
  103. SendDlgItemMessage (IDC_CODEID_EDIT, EM_SETSEL, (WPARAM)0, (LPARAM)-1);
  104. return FALSE;
  105. }
  106. /////////////////////////////////////////////////////////////////////////////
  107. //
  108. // Insert_String
  109. //
  110. /////////////////////////////////////////////////////////////////////////////
  111. void
  112. EditStringTwiddlerDialogClass::Insert_String (int string_id)
  113. {
  114. //
  115. // Lookup the object for this ID
  116. //
  117. TDBObjClass *object = TranslateDBClass::Find_Object (string_id);
  118. if (object != NULL) {
  119. const StringClass &text = object->Get_ID_Desc ();
  120. //
  121. // Add an entry to the list for this string
  122. //
  123. int item_index = ListCtrl.InsertItem (0xFF, text);
  124. if (item_index != -1) {
  125. ListCtrl.SetItemData (item_index, string_id);
  126. }
  127. }
  128. return ;
  129. }
  130. /////////////////////////////////////////////////////////////////////////////
  131. //
  132. // OnAddButton
  133. //
  134. /////////////////////////////////////////////////////////////////////////////
  135. void
  136. EditStringTwiddlerDialogClass::OnAddButton (void)
  137. {
  138. //
  139. // Show the dialog to the user so they can pick a string
  140. //
  141. StringPickerMainDialogClass dialog (this);
  142. if (dialog.DoModal () == IDOK) {
  143. //
  144. // Add this string to our list
  145. //
  146. Insert_String (dialog.Get_String_ID ());
  147. }
  148. return ;
  149. }
  150. /////////////////////////////////////////////////////////////////////////////
  151. //
  152. // OnOK
  153. //
  154. /////////////////////////////////////////////////////////////////////////////
  155. void
  156. EditStringTwiddlerDialogClass::OnOK (void)
  157. {
  158. //
  159. // Get the strind ID the user entered
  160. //
  161. CString string_id;
  162. GetDlgItemText (IDC_CODEID_EDIT, string_id);
  163. //
  164. // Is this a valid ID?
  165. //
  166. if (Validate_String_ID (m_hWnd, string_id)) {
  167. //
  168. // Create a new twiddler (if necessary)
  169. //
  170. if (StringObject == NULL) {
  171. StringObject = new StringTwiddlerClass;
  172. }
  173. //
  174. // Configure the twiddler
  175. //
  176. StringObject->Reset_String_List ();
  177. StringObject->Set_ID_Desc (string_id);
  178. //
  179. // Add the list of strings to the twiddler
  180. //
  181. int count = ListCtrl.GetItemCount ();
  182. for (int index = 0; index < count; index ++) {
  183. int string_id = (int)ListCtrl.GetItemData (index);
  184. StringObject->Add_String (string_id);
  185. }
  186. CDialog::OnOK ();
  187. }
  188. return ;
  189. }
  190. /////////////////////////////////////////////////////////////////////////////
  191. //
  192. // OnKeydownListctrl
  193. //
  194. /////////////////////////////////////////////////////////////////////////////
  195. void
  196. EditStringTwiddlerDialogClass::OnKeydownListctrl (NMHDR *pNMHDR, LRESULT *pResult)
  197. {
  198. LV_KEYDOWN *pLVKeyDown = (LV_KEYDOWN*)pNMHDR;
  199. *pResult = 0;
  200. if (pLVKeyDown->wVKey == VK_DELETE) {
  201. //
  202. // Delete all the selected items (except for the last item)
  203. //
  204. int index = -1;
  205. while ((index = ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL)) >= 0) {
  206. ListCtrl.DeleteItem (index);
  207. }
  208. }
  209. return ;
  210. }