PresetDependencyTab.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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. // PresetGeneralTab.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "PresetDependencyTab.h"
  23. #include "definition.h"
  24. #include "preset.h"
  25. #include "utils.h"
  26. #include "filemgr.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. //
  34. // PresetDependencyTabClass
  35. //
  36. /////////////////////////////////////////////////////////////////////////////
  37. PresetDependencyTabClass::PresetDependencyTabClass (PresetClass *preset)
  38. : m_Preset (preset),
  39. m_IsReadOnly (false),
  40. DockableFormClass(PresetDependencyTabClass::IDD)
  41. {
  42. //{{AFX_DATA_INIT(PresetDependencyTabClass)
  43. // NOTE: the ClassWizard will add member initialization here
  44. //}}AFX_DATA_INIT
  45. return ;
  46. }
  47. /////////////////////////////////////////////////////////////////////////////
  48. //
  49. // ~PresetDependencyTabClass
  50. //
  51. /////////////////////////////////////////////////////////////////////////////
  52. PresetDependencyTabClass::~PresetDependencyTabClass (void)
  53. {
  54. return ;
  55. }
  56. /////////////////////////////////////////////////////////////////////////////
  57. //
  58. // DoDataExchange
  59. //
  60. /////////////////////////////////////////////////////////////////////////////
  61. void
  62. PresetDependencyTabClass::DoDataExchange (CDataExchange *pDX)
  63. {
  64. DockableFormClass::DoDataExchange(pDX);
  65. //{{AFX_DATA_MAP(PresetDependencyTabClass)
  66. DDX_Control(pDX, IDC_DEPENCY_LIST, m_ListCtrl);
  67. //}}AFX_DATA_MAP
  68. return ;
  69. }
  70. BEGIN_MESSAGE_MAP(PresetDependencyTabClass, DockableFormClass)
  71. //{{AFX_MSG_MAP(PresetDependencyTabClass)
  72. ON_BN_CLICKED(IDC_ADD, OnAdd)
  73. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  74. ON_NOTIFY(LVN_ITEMCHANGED, IDC_DEPENCY_LIST, OnItemchangedDepencyList)
  75. //}}AFX_MSG_MAP
  76. END_MESSAGE_MAP()
  77. /////////////////////////////////////////////////////////////////////////////
  78. // PresetDependencyTabClass diagnostics
  79. #ifdef _DEBUG
  80. void PresetDependencyTabClass::AssertValid() const
  81. {
  82. DockableFormClass::AssertValid();
  83. }
  84. void PresetDependencyTabClass::Dump(CDumpContext& dc) const
  85. {
  86. DockableFormClass::Dump(dc);
  87. }
  88. #endif //_DEBUG
  89. /////////////////////////////////////////////////////////////////////////////
  90. //
  91. // HandleInitDialog
  92. //
  93. /////////////////////////////////////////////////////////////////////////////
  94. void
  95. PresetDependencyTabClass::HandleInitDialog (void)
  96. {
  97. ASSERT (m_Preset != NULL);
  98. //
  99. // Configure the list control
  100. //
  101. m_ListCtrl.InsertColumn (0, "Filename");
  102. CRect rect;
  103. m_ListCtrl.GetClientRect (&rect);
  104. m_ListCtrl.SetColumnWidth (0, rect.Width () - 4);
  105. //
  106. // Get the list of dependencies from the preset
  107. //
  108. STRING_LIST dependencies;
  109. m_Preset->Get_Manual_Dependencies (dependencies);
  110. //
  111. // Add the dependencies to the list control
  112. //
  113. for (int index = 0; index < dependencies.Count (); index ++) {
  114. m_ListCtrl.InsertItem (index, dependencies[index]);
  115. }
  116. //
  117. // Make the controls read-only if necessary
  118. //
  119. if (m_IsReadOnly) {
  120. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_ADD), false);
  121. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_REMOVE), false);
  122. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_DEPENCY_LIST), false);
  123. }
  124. //
  125. // Put the focus into the edit control
  126. //
  127. ::SetFocus (::GetDlgItem (m_hWnd, IDC_DEPENCY_LIST));
  128. Update_Button_State ();
  129. return ;
  130. }
  131. /////////////////////////////////////////////////////////////////////////////
  132. //
  133. // Apply_Changes
  134. //
  135. /////////////////////////////////////////////////////////////////////////////
  136. bool
  137. PresetDependencyTabClass::Apply_Changes (void)
  138. {
  139. //
  140. // Loop over all the filenames in the list control
  141. //
  142. STRING_LIST list;
  143. for (int index = 0; index < m_ListCtrl.GetItemCount (); index ++) {
  144. //
  145. // Add this file to the list of dependencies
  146. //
  147. CString filename = m_ListCtrl.GetItemText (index, 0);
  148. list.Add (filename);
  149. }
  150. //
  151. // Pass the new dependency list onto the preset
  152. //
  153. m_Preset->Set_Manual_Dependencies (list);
  154. return true;
  155. }
  156. /////////////////////////////////////////////////////////////////////////////
  157. //
  158. // Update_Button_State
  159. //
  160. /////////////////////////////////////////////////////////////////////////////
  161. void
  162. PresetDependencyTabClass::Update_Button_State (void)
  163. {
  164. int sel_index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
  165. if (m_IsReadOnly == false) {
  166. ::EnableWindow (::GetDlgItem (m_hWnd, IDC_REMOVE), bool(sel_index >= 0));
  167. }
  168. return ;
  169. }
  170. /////////////////////////////////////////////////////////////////////////////
  171. //
  172. // OnAdd
  173. //
  174. /////////////////////////////////////////////////////////////////////////////
  175. void
  176. PresetDependencyTabClass::OnAdd (void)
  177. {
  178. CFileDialog dialog (TRUE,
  179. ".w3d",
  180. NULL,
  181. OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_EXPLORER,
  182. "All Files|*.*|Westwood 3D Files|*.w3d|Texture Files|*.tga|Sound Files|*.wav;*.mp3||",
  183. this);
  184. //
  185. // Setup the initial directory
  186. //
  187. dialog.m_ofn.lpstrInitialDir = ::Get_File_Mgr ()->Get_Base_Path ();
  188. //
  189. // Let the user pick a file
  190. //
  191. if (dialog.DoModal () == IDOK) {
  192. //
  193. // Is the new path valid?
  194. //
  195. if (::Get_File_Mgr ()->Is_Path_Valid (dialog.GetPathName ())) {
  196. //
  197. // Convert the new asset file path to a relative path and pass it onto the base
  198. //
  199. CString rel_path = ::Get_File_Mgr ()->Make_Relative_Path (dialog.GetPathName ());
  200. m_ListCtrl.InsertItem (0xFF, rel_path);
  201. } else {
  202. //
  203. // Let the user know this path is invalid
  204. //
  205. CString message;
  206. CString title;
  207. message.Format (IDS_INVALID_MODEL_PATH_MSG, (LPCTSTR)::Get_File_Mgr()->Get_Base_Path ());
  208. title.LoadString (IDS_INVALID_MODEL_PATH_TITLE);
  209. ::MessageBox (m_hWnd, message, title, MB_ICONERROR | MB_OK);
  210. }
  211. }
  212. return ;
  213. }
  214. /////////////////////////////////////////////////////////////////////////////
  215. //
  216. // OnRemove
  217. //
  218. /////////////////////////////////////////////////////////////////////////////
  219. void
  220. PresetDependencyTabClass::OnRemove (void)
  221. {
  222. //
  223. // Get the index of the currently selected entry
  224. //
  225. int sel_index = m_ListCtrl.GetNextItem (-1, LVNI_SELECTED | LVNI_ALL);
  226. if (sel_index >= 0) {
  227. //
  228. // Remove this entry from the list control
  229. //
  230. m_ListCtrl.DeleteItem (sel_index);
  231. }
  232. return ;
  233. }
  234. /////////////////////////////////////////////////////////////////////////////
  235. //
  236. // OnItemchangedDepencyList
  237. //
  238. /////////////////////////////////////////////////////////////////////////////
  239. void
  240. PresetDependencyTabClass::OnItemchangedDepencyList
  241. (
  242. NMHDR * pNMHDR,
  243. LRESULT* pResult
  244. )
  245. {
  246. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  247. (*pResult) = 0;
  248. Update_Button_State ();
  249. return ;
  250. }