ChooseModPackageDialog.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. // ChooseModPackageDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "choosemodpackagedialog.h"
  23. #include "assetpackagemgr.h"
  24. #include "newassetpackagedialog.h"
  25. #ifdef _DEBUG
  26. #define new DEBUG_NEW
  27. #undef THIS_FILE
  28. static char THIS_FILE[] = __FILE__;
  29. #endif
  30. /////////////////////////////////////////////////////////////////////////////
  31. //
  32. // ChooseModPackageDialogClass
  33. //
  34. /////////////////////////////////////////////////////////////////////////////
  35. ChooseModPackageDialogClass::ChooseModPackageDialogClass(CWnd* pParent /*=NULL*/)
  36. : CDialog(ChooseModPackageDialogClass::IDD, pParent)
  37. {
  38. //{{AFX_DATA_INIT(ChooseModPackageDialogClass)
  39. // NOTE: the ClassWizard will add member initialization here
  40. //}}AFX_DATA_INIT
  41. return ;
  42. }
  43. /////////////////////////////////////////////////////////////////////////////
  44. //
  45. // DoDataExchange
  46. //
  47. /////////////////////////////////////////////////////////////////////////////
  48. void
  49. ChooseModPackageDialogClass::DoDataExchange (CDataExchange* pDX)
  50. {
  51. CDialog::DoDataExchange(pDX);
  52. //{{AFX_DATA_MAP(ChooseModPackageDialogClass)
  53. DDX_Control(pDX, IDC_MOD_LIST_CTRL, ListCtrl);
  54. //}}AFX_DATA_MAP
  55. }
  56. BEGIN_MESSAGE_MAP(ChooseModPackageDialogClass, CDialog)
  57. //{{AFX_MSG_MAP(ChooseModPackageDialogClass)
  58. ON_BN_CLICKED(IDC_NEW_BUTTON, OnNewButton)
  59. ON_NOTIFY(NM_DBLCLK, IDC_MOD_LIST_CTRL, OnDblclkModListCtrl)
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. //
  64. // OnInitDialog
  65. //
  66. /////////////////////////////////////////////////////////////////////////////
  67. BOOL
  68. ChooseModPackageDialogClass::OnInitDialog (void)
  69. {
  70. CDialog::OnInitDialog ();
  71. //
  72. // Configure the columns
  73. //
  74. ListCtrl.InsertColumn (0, "");
  75. ListCtrl.SetExtendedStyle (ListCtrl.GetExtendedStyle () | LVS_EX_FULLROWSELECT);
  76. //
  77. // Choose an appropriate size for the column
  78. //
  79. CRect rect;
  80. ListCtrl.GetClientRect (&rect);
  81. rect.right -= ::GetSystemMetrics (SM_CXVSCROLL) + 2;
  82. ListCtrl.SetColumnWidth (0, rect.Width ());
  83. //
  84. // Build a list of all the packages that are currently available
  85. //
  86. STRING_LIST package_list;
  87. AssetPackageMgrClass::Build_Package_List (package_list);
  88. //
  89. // Add an entry to the control for each package
  90. //
  91. bool found = false;
  92. for (int index = 0; index < package_list.Count (); index ++) {
  93. int item_index = ListCtrl.InsertItem (index, package_list[index]);
  94. if (item_index >= 0) {
  95. //
  96. // Is this the default entry?
  97. //
  98. if (::lstrcmpi (AssetPackageMgrClass::Get_Current_Package (), package_list[index]) == 0) {
  99. ListCtrl.SetItemState (item_index, LVIS_SELECTED, LVIS_SELECTED);
  100. found = true;
  101. }
  102. }
  103. }
  104. //
  105. // Select the first entry by default
  106. //
  107. if (package_list.Count () > 0 && found) {
  108. ListCtrl.SetItemState (0, LVIS_SELECTED, LVIS_SELECTED);
  109. }
  110. return TRUE;
  111. }
  112. /////////////////////////////////////////////////////////////////////////////
  113. //
  114. // OnOK
  115. //
  116. /////////////////////////////////////////////////////////////////////////////
  117. void
  118. ChooseModPackageDialogClass::OnOK (void)
  119. {
  120. int curr_index = ListCtrl.GetNextItem (-1, LVNI_ALL | LVNI_SELECTED);
  121. if (curr_index >= 0) {
  122. //
  123. // Set the current mod package
  124. //
  125. CString package_name = ListCtrl.GetItemText (curr_index, 0);
  126. AssetPackageMgrClass::Set_Current_Package (package_name);
  127. //
  128. // Close the dialog
  129. //
  130. CDialog::OnOK ();
  131. } else {
  132. //
  133. // Warn the user
  134. //
  135. MessageBox ("You must select (or create) a Mod Package before continuing.", "Invalid Selection", MB_ICONERROR | MB_OK);
  136. }
  137. return ;
  138. }
  139. /////////////////////////////////////////////////////////////////////////////
  140. //
  141. // OnNewButton
  142. //
  143. /////////////////////////////////////////////////////////////////////////////
  144. void
  145. ChooseModPackageDialogClass::OnNewButton (void)
  146. {
  147. //
  148. // Display a dialog to the user allowing them to create a new mod package
  149. //
  150. NewAssetPackageDialogClass dialog (this);
  151. if (dialog.DoModal () == IDOK) {
  152. //
  153. // Create the new asset package
  154. //
  155. AssetPackageMgrClass::Create_Package (dialog.Get_Package_Name ());
  156. //
  157. // Add this package to the list
  158. //
  159. int item_index = ListCtrl.InsertItem (0xFF, dialog.Get_Package_Name ());
  160. if (item_index >= 0) {
  161. //
  162. // Select the new package
  163. //
  164. ListCtrl.SetItemState (item_index, LVIS_SELECTED, LVIS_SELECTED);
  165. }
  166. }
  167. return ;
  168. }
  169. /////////////////////////////////////////////////////////////////////////////
  170. //
  171. // OnDblclkModListCtrl
  172. //
  173. /////////////////////////////////////////////////////////////////////////////
  174. void
  175. ChooseModPackageDialogClass::OnDblclkModListCtrl (NMHDR *pNMHDR, LRESULT *pResult)
  176. {
  177. (*pResult) = 0;
  178. //
  179. // Simulate pressing the OK button
  180. //
  181. SendMessage (WM_COMMAND, MAKELONG (IDOK, BN_CLICKED), 0);
  182. return ;
  183. }