SceneSetupDlg.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. ** Command & Conquer Generals(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. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : G *
  23. * *
  24. * $Archive:: /Commando/Code/Tools/max2w3d/SceneSetupDlg.cpp $*
  25. * *
  26. * $Author:: Andre_a $*
  27. * *
  28. * $Modtime:: 10/15/99 3:37p $*
  29. * *
  30. * $Revision:: 2 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. // SceneSetupDlg.cpp : implementation file
  36. //
  37. #include "SceneSetupDlg.h"
  38. #include <Max.h>
  39. #include <assert.h>
  40. static BOOL CALLBACK _thunk_dialog_proc (HWND hWnd, UINT uMsg, WPARAM wAparam, LPARAM lParam);
  41. /////////////////////////////////////////////////////////////////////////////
  42. // SceneSetupDlg dialog
  43. SceneSetupDlg::SceneSetupDlg(Interface *max_interface)
  44. {
  45. m_DamageCount = 0;
  46. m_DamageOffset = -100.0f;
  47. m_LodCount = 0;
  48. m_LodOffset = -100.0f;
  49. m_DamageProc = 3;
  50. m_LodProc = 3;
  51. m_hWnd = NULL;
  52. m_MaxInterface = max_interface;
  53. assert(max_interface != NULL);
  54. }
  55. /////////////////////////////////////////////////////////////////////////////
  56. // SceneSetupDlg Protected Methods
  57. void SceneSetupDlg::SetEditInt (int control_id, int value)
  58. {
  59. char buf[64];
  60. sprintf(buf, "%d", value);
  61. HWND edit = GetDlgItem(m_hWnd, control_id);
  62. assert(edit != NULL);
  63. SetWindowText(edit, buf);
  64. }
  65. void SceneSetupDlg::SetEditFloat (int control_id, float value)
  66. {
  67. char buf[64];
  68. sprintf(buf, "%.0f", value);
  69. HWND edit = GetDlgItem(m_hWnd, control_id);
  70. assert(edit != NULL);
  71. SetWindowText(edit, buf);
  72. }
  73. int SceneSetupDlg::GetEditInt (int control_id)
  74. {
  75. char buf[64];
  76. HWND edit = GetDlgItem(m_hWnd, control_id);
  77. assert(edit != NULL);
  78. GetWindowText(edit, buf, sizeof(buf));
  79. int value = 0;
  80. sscanf(buf, "%d", &value);
  81. return value;
  82. }
  83. float SceneSetupDlg::GetEditFloat (int control_id)
  84. {
  85. char buf[64];
  86. HWND edit = GetDlgItem(m_hWnd, control_id);
  87. assert(edit != NULL);
  88. GetWindowText(edit, buf, sizeof(buf));
  89. float value = 0;
  90. sscanf(buf, "%f", &value);
  91. return value;
  92. }
  93. bool SceneSetupDlg::ValidateEditFloat (int control_id)
  94. {
  95. char buf[64];
  96. HWND edit = GetDlgItem(m_hWnd, control_id);
  97. assert(edit != NULL);
  98. GetWindowText(edit, buf, sizeof(buf));
  99. float value = 0;
  100. if (sscanf(buf, "%f", &value) == 1)
  101. return true;
  102. else
  103. return false;
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // SceneSetupDlg Public Methods
  107. int SceneSetupDlg::DoModal (void)
  108. {
  109. // Put up the dialog box.
  110. BOOL result = DialogBoxParam(AppInstance, MAKEINTRESOURCE(IDD_SCENE_SETUP),
  111. m_MaxInterface->GetMAXHWnd(), (DLGPROC)_thunk_dialog_proc,
  112. (LPARAM)this);
  113. // Return IDOK if the user accepted the new settings.
  114. return (result == 1) ? IDOK : IDCANCEL;
  115. }
  116. /////////////////////////////////////////////////////////////////////////////
  117. // SceneSetupDlg DialogProc
  118. BOOL CALLBACK _thunk_dialog_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  119. {
  120. static SceneSetupDlg *dialog = NULL;
  121. if (uMsg == WM_INITDIALOG)
  122. {
  123. dialog = (SceneSetupDlg*)lParam;
  124. dialog->m_hWnd = hWnd;
  125. }
  126. if (dialog)
  127. return dialog->DialogProc(hWnd, uMsg, wParam, lParam);
  128. else
  129. return 0;
  130. }
  131. BOOL CALLBACK SceneSetupDlg::DialogProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  132. {
  133. int code = HIWORD(wParam);
  134. switch (uMsg)
  135. {
  136. /*******************************************************************
  137. * WM_INITDIALOG
  138. *
  139. * Initialize all of the custom controls for the dialog box
  140. *
  141. *******************************************************************/
  142. case WM_INITDIALOG:
  143. OnInitDialog();
  144. return TRUE;
  145. /*******************************************************************
  146. * WM_COMMAND
  147. *
  148. *
  149. *******************************************************************/
  150. case WM_COMMAND:
  151. switch (LOWORD(wParam))
  152. {
  153. case IDOK:
  154. if (OnOK() == FALSE)
  155. return TRUE;
  156. SetCursor(LoadCursor(NULL, IDC_WAIT));
  157. EndDialog(m_hWnd, 1);
  158. break;
  159. case IDCANCEL:
  160. EndDialog(m_hWnd, 0);
  161. break;
  162. }
  163. return TRUE;
  164. }
  165. return FALSE;
  166. }
  167. /////////////////////////////////////////////////////////////////////////////
  168. // SceneSetupDlg message handlers
  169. void SceneSetupDlg::OnInitDialog()
  170. {
  171. CenterWindow(m_hWnd, m_MaxInterface->GetMAXHWnd());
  172. SetCursor(LoadCursor(NULL, IDC_ARROW));
  173. // Select the appropriate radio buttons.
  174. switch (m_LodProc)
  175. {
  176. case 1:
  177. CheckDlgButton(m_hWnd, IDC_LOD_AS_COPY, BST_CHECKED);
  178. break;
  179. case 2:
  180. CheckDlgButton(m_hWnd, IDC_LOD_AS_INSTANCE, BST_CHECKED);
  181. break;
  182. case 3:
  183. CheckDlgButton(m_hWnd, IDC_LOD_AS_REFERENCE, BST_CHECKED);
  184. break;
  185. }
  186. switch (m_DamageProc)
  187. {
  188. case 1:
  189. CheckDlgButton(m_hWnd, IDC_DAMAGE_AS_COPY, BST_CHECKED);
  190. break;
  191. case 2:
  192. CheckDlgButton(m_hWnd, IDC_DAMAGE_AS_INSTANCE, BST_CHECKED);
  193. break;
  194. case 3:
  195. CheckDlgButton(m_hWnd, IDC_DAMAGE_AS_REFERENCE, BST_CHECKED);
  196. break;
  197. }
  198. // Set the text for the edit boxes.
  199. SetEditInt(IDC_LOD_COUNT, m_LodCount);
  200. SetEditFloat(IDC_LOD_OFFSET, m_LodOffset);
  201. SetEditInt(IDC_DAMAGE_COUNT, m_DamageCount);
  202. SetEditFloat(IDC_DAMAGE_OFFSET, m_DamageOffset);
  203. }
  204. BOOL SceneSetupDlg::OnOK()
  205. {
  206. if (!ValidateEditFloat(IDC_LOD_OFFSET))
  207. {
  208. MessageBox(m_hWnd, "You must enter a valid number for the LOD Offset.",
  209. "Not a Number", MB_OK);
  210. SetFocus(GetDlgItem(m_hWnd, IDC_LOD_OFFSET));
  211. return FALSE;
  212. }
  213. if (!ValidateEditFloat(IDC_DAMAGE_OFFSET))
  214. {
  215. MessageBox(m_hWnd, "You must enter a valid number for the Damage Offset.",
  216. "Not a Number", MB_OK);
  217. SetFocus(GetDlgItem(m_hWnd, IDC_DAMAGE_OFFSET));
  218. return FALSE;
  219. }
  220. // Get the clone procedure the user wants to use.
  221. if (IsDlgButtonChecked(m_hWnd, IDC_LOD_AS_COPY))
  222. m_LodProc = 1;
  223. else if (IsDlgButtonChecked(m_hWnd, IDC_LOD_AS_INSTANCE))
  224. m_LodProc = 2;
  225. else if (IsDlgButtonChecked(m_hWnd, IDC_LOD_AS_REFERENCE))
  226. m_LodProc = 3;
  227. if (IsDlgButtonChecked(m_hWnd, IDC_DAMAGE_AS_COPY))
  228. m_DamageProc = 1;
  229. else if (IsDlgButtonChecked(m_hWnd, IDC_DAMAGE_AS_INSTANCE))
  230. m_DamageProc = 2;
  231. else if (IsDlgButtonChecked(m_hWnd, IDC_DAMAGE_AS_REFERENCE))
  232. m_DamageProc = 3;
  233. // Get the other values the user selected.
  234. m_LodCount = GetEditInt(IDC_LOD_COUNT);
  235. m_LodOffset = GetEditFloat(IDC_LOD_OFFSET);
  236. m_DamageCount = GetEditInt(IDC_DAMAGE_COUNT);
  237. m_DamageOffset = GetEditFloat(IDC_DAMAGE_OFFSET);
  238. return TRUE;
  239. }