LevelSettingsDialog.cpp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. // LevelSettingsDialog.cpp : implementation file
  19. //
  20. #include "stdafx.h"
  21. #include "leveledit.h"
  22. #include "levelsettingsdialog.h"
  23. #include "combat.h"
  24. #include "scriptmgr.h"
  25. #include "editscript.h"
  26. #include "mapmgr.h"
  27. #ifdef _DEBUG
  28. #define new DEBUG_NEW
  29. #undef THIS_FILE
  30. static char THIS_FILE[] = __FILE__;
  31. #endif
  32. /////////////////////////////////////////////////////////////////////////////
  33. //
  34. // LevelSettingsDialogClass
  35. //
  36. /////////////////////////////////////////////////////////////////////////////
  37. LevelSettingsDialogClass::LevelSettingsDialogClass(CWnd* pParent /*=NULL*/)
  38. : CDialog(LevelSettingsDialogClass::IDD, pParent)
  39. {
  40. //{{AFX_DATA_INIT(LevelSettingsDialogClass)
  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. LevelSettingsDialogClass::DoDataExchange (CDataExchange *pDX)
  52. {
  53. CDialog::DoDataExchange(pDX);
  54. //{{AFX_DATA_MAP(LevelSettingsDialogClass)
  55. DDX_Control(pDX, IDC_RESTART_SCRIPT_COMBO, RestartScriptCombo);
  56. DDX_Control(pDX, IDC_RESPAWN_SCRIPT_COMBO, RespawnScriptCombo);
  57. DDX_Control(pDX, IDC_MAP_SCALEY_SPIN, MapScaleYSpin);
  58. DDX_Control(pDX, IDC_MAP_SCALEX_SPIN, MapScaleXSpin);
  59. DDX_Control(pDX, IDC_MAP_PIXEL_OFFSETY_SPIN, MapOffsetYSpin);
  60. DDX_Control(pDX, IDC_MAP_PIXEL_OFFSETX_SPIN, MapOffsetXSpin);
  61. //}}AFX_DATA_MAP
  62. return ;
  63. }
  64. BEGIN_MESSAGE_MAP(LevelSettingsDialogClass, CDialog)
  65. //{{AFX_MSG_MAP(LevelSettingsDialogClass)
  66. //}}AFX_MSG_MAP
  67. END_MESSAGE_MAP()
  68. /////////////////////////////////////////////////////////////////////////////
  69. //
  70. // OnInitDialog
  71. //
  72. /////////////////////////////////////////////////////////////////////////////
  73. BOOL
  74. LevelSettingsDialogClass::OnInitDialog (void)
  75. {
  76. CDialog::OnInitDialog ();
  77. //
  78. // Populate the script controls
  79. //
  80. Fill_Script_Combobox (IDC_RESTART_SCRIPT_COMBO, CombatManager::Get_Start_Script ());
  81. Fill_Script_Combobox (IDC_RESPAWN_SCRIPT_COMBO, CombatManager::Get_Respawn_Script ());
  82. //
  83. // Get the rectangle where we'll create the file picker
  84. //
  85. CRect rect;
  86. ::GetWindowRect (::GetDlgItem (m_hWnd, IDC_MAP_FILENAME_EDIT), &rect);
  87. ScreenToClient (&rect);
  88. //
  89. // Destroy the old window
  90. //
  91. ::DestroyWindow (::GetDlgItem (m_hWnd, IDC_MAP_FILENAME_EDIT));
  92. //
  93. // Create and initialize the picker
  94. //
  95. FilePicker.Create_Picker (WS_CHILD | WS_TABSTOP | WS_VISIBLE, rect, this, IDC_MAP_FILENAME_EDIT);
  96. FilePicker.Set_Filter_String ("Texture Files (*.tga)|*.tga|All Files (*.*)|*.*||");
  97. //
  98. // Put the default filename into the picker control
  99. //
  100. FilePicker.SetWindowText (MapMgrClass::Get_Map_Texture_Pathname ());
  101. FilePicker.Set_Asset_Tree_Only (true);
  102. //
  103. // Get the rectangle where we'll create the file picker
  104. //
  105. ::GetWindowRect (::GetDlgItem (m_hWnd, IDC_MAP_TITLE_EDIT), &rect);
  106. ScreenToClient (&rect);
  107. ::DestroyWindow (::GetDlgItem (m_hWnd, IDC_MAP_TITLE_EDIT));
  108. //
  109. // Create and initialize the string picker
  110. //
  111. StringPicker.Create_Picker (WS_CHILD | WS_TABSTOP | WS_VISIBLE, rect, this, IDC_MAP_TITLE_EDIT);
  112. StringPicker.Set_Entry (MapMgrClass::Get_Map_Title ());
  113. //
  114. // Configure the float controls
  115. //
  116. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_MAP_PIXEL_OFFSETX_EDIT));
  117. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_MAP_PIXEL_OFFSETY_EDIT));
  118. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_MAP_SCALEX_EDIT));
  119. ::Make_Edit_Float_Ctrl (::GetDlgItem (m_hWnd, IDC_MAP_SCALEY_EDIT));
  120. //
  121. // Set the float control ranges
  122. //
  123. MapScaleXSpin.SetRange32 (-1000000, 1000000);
  124. MapScaleYSpin.SetRange32 (-1000000, 1000000);
  125. MapOffsetXSpin.SetRange32 (-1000000, 1000000);
  126. MapOffsetYSpin.SetRange32 (-1000000, 1000000);
  127. //
  128. // Set the default values for the control
  129. //
  130. ::SetDlgItemFloat (m_hWnd, IDC_MAP_SCALEX_EDIT, MapMgrClass::Get_Map_Scale ().X);
  131. ::SetDlgItemFloat (m_hWnd, IDC_MAP_SCALEY_EDIT, MapMgrClass::Get_Map_Scale ().Y);
  132. ::SetDlgItemFloat (m_hWnd, IDC_MAP_PIXEL_OFFSETX_EDIT, MapMgrClass::Get_Map_Center ().X);
  133. ::SetDlgItemFloat (m_hWnd, IDC_MAP_PIXEL_OFFSETY_EDIT, MapMgrClass::Get_Map_Center ().Y);
  134. SendDlgItemMessage (IDC_ALLOW_VTOL_CHECK, BM_SETCHECK, MapMgrClass::Are_VTOL_Vehicles_Enabled ());
  135. return TRUE;
  136. }
  137. /////////////////////////////////////////////////////////////////////////////
  138. //
  139. // OnOK
  140. //
  141. /////////////////////////////////////////////////////////////////////////////
  142. void
  143. LevelSettingsDialogClass::OnOK (void)
  144. {
  145. //
  146. // Store the currently selected restart script
  147. //
  148. int index = RestartScriptCombo.GetCurSel ();
  149. if (index != CB_ERR) {
  150. CString script_name;
  151. RestartScriptCombo.GetLBText (index, script_name);
  152. CombatManager::Set_Start_Script (script_name);
  153. } else {
  154. CombatManager::Set_Start_Script ("");
  155. }
  156. //
  157. // Store the currently selected respawn script
  158. //
  159. index = RespawnScriptCombo.GetCurSel ();
  160. if (index != CB_ERR) {
  161. CString script_name;
  162. RespawnScriptCombo.GetLBText (index, script_name);
  163. CombatManager::Set_Respawn_Script (script_name);
  164. } else {
  165. CombatManager::Set_Respawn_Script ("");
  166. }
  167. //
  168. // Set the map title
  169. //
  170. MapMgrClass::Set_Map_Title (StringPicker.Get_Entry ());
  171. //
  172. // Set the map filename
  173. //
  174. CString map_filename;
  175. FilePicker.GetWindowText (map_filename);
  176. MapMgrClass::Set_Map_Texture (map_filename);
  177. Vector2 offset;
  178. Vector2 scale;
  179. //
  180. // Set the default values for the control
  181. //
  182. scale.X = ::GetDlgItemFloat (m_hWnd, IDC_MAP_SCALEX_EDIT, true);
  183. scale.Y = ::GetDlgItemFloat (m_hWnd, IDC_MAP_SCALEY_EDIT, true);
  184. offset.X = ::GetDlgItemFloat (m_hWnd, IDC_MAP_PIXEL_OFFSETX_EDIT, true);
  185. offset.Y = ::GetDlgItemFloat (m_hWnd, IDC_MAP_PIXEL_OFFSETY_EDIT, true);
  186. MapMgrClass::Set_Map_Scale (scale);
  187. MapMgrClass::Set_Map_Center (offset);
  188. MapMgrClass::Cloud_All_Cells ();
  189. bool vtol_on = (SendDlgItemMessage (IDC_ALLOW_VTOL_CHECK, BM_GETCHECK) == 1);
  190. MapMgrClass::Enable_VTOL_Vehicles (vtol_on);
  191. CDialog::OnOK ();
  192. return ;
  193. }
  194. /////////////////////////////////////////////////////////////////////////////
  195. //
  196. // Fill_Script_Combobox
  197. //
  198. /////////////////////////////////////////////////////////////////////////////
  199. void
  200. LevelSettingsDialogClass::Fill_Script_Combobox (int ctrl_id, const char *default_name)
  201. {
  202. //
  203. // Add the total list of scripts to the combobox
  204. //
  205. for (int index = 0; index < ScriptMgrClass::Get_Count (); index ++) {
  206. EditScriptClass *script = ScriptMgrClass::Get_Script (index);
  207. if (script != NULL) {
  208. //
  209. // Add this script to the combobox
  210. //
  211. int item_index = SendDlgItemMessage (ctrl_id, CB_ADDSTRING, 0, (LPARAM)script->Get_Name ());
  212. SendDlgItemMessage (ctrl_id, CB_SETITEMDATA, (WPARAM)item_index, (LPARAM)script);
  213. //
  214. // Select this script if it is the default
  215. //
  216. if (::lstrcmpi (default_name, script->Get_Name ()) == 0) {
  217. SendDlgItemMessage (ctrl_id, CB_SETCURSEL, (WPARAM)item_index);
  218. }
  219. }
  220. }
  221. return ;
  222. }