Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

297 lines
8.4 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implements the entity/prefab placement tool.
  4. //
  5. //=============================================================================//
  6. #include "stdafx.h"
  7. #include "hammer.h"
  8. #include "entitysprinkledlg.h"
  9. #include "mapdoc.h"
  10. #include "KeyValues.h"
  11. #include "toolmanager.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include <tier0/memdbgon.h>
  14. // CEntitySprinkleDlg dialog
  15. IMPLEMENT_DYNAMIC(CEntitySprinkleDlg, CPropertyPage)
  16. //-----------------------------------------------------------------------------
  17. // Purpose:
  18. // Input :
  19. // Output :
  20. //-----------------------------------------------------------------------------
  21. CEntitySprinkleDlg::CEntitySprinkleDlg()
  22. : CDialog(CEntitySprinkleDlg::IDD)
  23. {
  24. }
  25. //-----------------------------------------------------------------------------
  26. // Purpose:
  27. // Input :
  28. // Output :
  29. //-----------------------------------------------------------------------------
  30. CEntitySprinkleDlg::~CEntitySprinkleDlg()
  31. {
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose:
  35. // Input :
  36. // Output :
  37. //-----------------------------------------------------------------------------
  38. void CEntitySprinkleDlg::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. DDX_Control(pDX, IDC_SPRINKLE_MODE, m_SprinkleModeControl);
  42. DDX_Control(pDX, IDC_SPRINKLE_DENSITY, m_SprinkleDensityControl);
  43. DDX_Control(pDX, IDC_SPRINKLE_GRID_OFFSET_X, m_GridOffsetXControl);
  44. DDX_Control(pDX, IDC_SPRINKLE_GRID_OFFSET_Y, m_GridOffsetYControl);
  45. DDX_Control(pDX, IDC_SPRINKLE_GRID_SIZE_X, m_GridSizeXControl);
  46. DDX_Control(pDX, IDC_SPRINKLE_GRID_SIZE_Y, m_GridSizeYControl);
  47. DDX_Control(pDX, IDC_SPRINKLE_TYPE, m_SprinkleTypeControl);
  48. DDX_Control(pDX, IDC_SPRINKLE_DENSITY_DISPLAY, m_SprinkleDensityDisplayControl);
  49. DDX_Control(pDX, IDC_SPRINKLE_DEFINITION_GRID_SIZE, m_DefinitionGridSizeControl);
  50. DDX_Control(pDX, IDC_SPRINKLE_RANDOM_YAW, m_RandomYawControl);
  51. }
  52. BEGIN_MESSAGE_MAP(CEntitySprinkleDlg, CDialog)
  53. ON_CBN_SELCHANGE(IDC_SPRINKLE_MODE, &CEntitySprinkleDlg::OnCbnSelchangeSprinkleMode)
  54. ON_BN_CLICKED(IDC_SPRINKLE_USE_GRID, &CEntitySprinkleDlg::OnBnClickedSprinkleUseGrid)
  55. ON_BN_CLICKED(IDC_SPRINKLE_DEFINITION_GRID_SIZE, &CEntitySprinkleDlg::OnBnClickedSprinkleDefinitionGridSize)
  56. ON_NOTIFY(NM_CUSTOMDRAW, IDC_SPRINKLE_DENSITY, &CEntitySprinkleDlg::OnNMCustomdrawSprinkleDensity)
  57. ON_WM_CLOSE()
  58. END_MESSAGE_MAP()
  59. //-----------------------------------------------------------------------------
  60. // Purpose:
  61. // Input :
  62. // Output :
  63. //-----------------------------------------------------------------------------
  64. void CEntitySprinkleDlg::OnCbnSelchangeSprinkleMode()
  65. {
  66. // TODO: Add your control notification handler code here
  67. }
  68. //-----------------------------------------------------------------------------
  69. // Purpose:
  70. // Input :
  71. // Output :
  72. //-----------------------------------------------------------------------------
  73. BOOL CEntitySprinkleDlg::OnInitDialog()
  74. {
  75. CDialog::OnInitDialog();
  76. m_SprinkleModeControl.AddString( "Additive" );
  77. m_SprinkleModeControl.AddString( "Subtractive" );
  78. m_SprinkleModeControl.AddString( "Replace" );
  79. m_SprinkleModeControl.AddString( "Overwrite" );
  80. m_SprinkleModeControl.SetCurSel( 0 );
  81. m_SprinkleDensityControl.SetRange( 0, 100 );
  82. m_SprinkleDensityControl.SetTicFreq( 10 );
  83. m_SprinkleDensityControl.SetLineSize( 10 );
  84. m_SprinkleDensityControl.SetPageSize( 10 );
  85. m_SprinkleDensityControl.SetPos( 25 );
  86. m_DefinitionGridSizeControl.SetCheck( BST_CHECKED );
  87. OnBnClickedSprinkleUseGrid();
  88. OnBnClickedSprinkleDefinitionGridSize();
  89. return TRUE; // return TRUE unless you set the focus to a control
  90. }
  91. //-----------------------------------------------------------------------------
  92. // Purpose:
  93. // Input :
  94. // Output :
  95. //-----------------------------------------------------------------------------
  96. void CEntitySprinkleDlg::OnBnClickedSprinkleUseGrid()
  97. {
  98. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  99. if ( !pDoc )
  100. {
  101. return;
  102. }
  103. char temp[ 128 ];
  104. sprintf( temp, "%d", pDoc->GetGridSpacing() );
  105. m_GridSizeXControl.SetWindowText( temp );
  106. m_GridSizeYControl.SetWindowText( temp );
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. // Input :
  111. // Output :
  112. //-----------------------------------------------------------------------------
  113. void CEntitySprinkleDlg::SetSprinkleTypes( KeyValues *pSprinkleInfo )
  114. {
  115. int nSelection = m_SprinkleTypeControl.GetCurSel();
  116. int nCount = m_SprinkleTypeControl.GetCount();
  117. m_SprinkleTypeControl.ResetContent();
  118. for ( KeyValues *pSub = pSprinkleInfo->GetFirstSubKey() ; pSub != NULL; pSub = pSub->GetNextKey() )
  119. {
  120. int nIndex = m_SprinkleTypeControl.AddString( pSub->GetName() );
  121. m_SprinkleTypeControl.SetItemDataPtr( nIndex, pSub );
  122. }
  123. if ( nCount == 0 )
  124. {
  125. m_SprinkleTypeControl.SetCurSel( 0 );
  126. }
  127. else
  128. {
  129. m_SprinkleTypeControl.SetCurSel( nSelection );
  130. }
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Purpose:
  134. // Input :
  135. // Output :
  136. //-----------------------------------------------------------------------------
  137. void CEntitySprinkleDlg::GetGridSize( float &flGridXSize, float &flGridYSize )
  138. {
  139. CString Text;
  140. m_GridSizeXControl.GetWindowText( Text );
  141. flGridXSize = atof( Text );
  142. m_GridSizeYControl.GetWindowText( Text );
  143. flGridYSize = atof( Text );
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Purpose:
  147. // Input :
  148. // Output :
  149. //-----------------------------------------------------------------------------
  150. KeyValues *CEntitySprinkleDlg::GetSprinkleType( )
  151. {
  152. int nIndex = m_SprinkleTypeControl.GetCurSel();
  153. if ( nIndex == CB_ERR )
  154. {
  155. return NULL;
  156. }
  157. return ( KeyValues * )( m_SprinkleTypeControl.GetItemDataPtr( nIndex ) );
  158. }
  159. //-----------------------------------------------------------------------------
  160. // Purpose:
  161. // Input :
  162. // Output :
  163. //-----------------------------------------------------------------------------
  164. int CEntitySprinkleDlg::GetSprinkleMode( )
  165. {
  166. return m_SprinkleModeControl.GetCurSel();
  167. }
  168. //-----------------------------------------------------------------------------
  169. // Purpose:
  170. // Input :
  171. // Output :
  172. //-----------------------------------------------------------------------------
  173. int CEntitySprinkleDlg::GetSprinkleDensity( )
  174. {
  175. return m_SprinkleDensityControl.GetPos();
  176. }
  177. //-----------------------------------------------------------------------------
  178. // Purpose:
  179. // Input :
  180. // Output :
  181. //-----------------------------------------------------------------------------
  182. void CEntitySprinkleDlg::OnBnClickedSprinkleDefinitionGridSize()
  183. {
  184. if ( m_DefinitionGridSizeControl.GetCheck() == BST_CHECKED )
  185. {
  186. m_GridSizeXControl.EnableWindow( FALSE );
  187. m_GridSizeYControl.EnableWindow( FALSE );
  188. }
  189. else
  190. {
  191. m_GridSizeXControl.EnableWindow( TRUE );
  192. m_GridSizeYControl.EnableWindow( TRUE );
  193. }
  194. }
  195. //-----------------------------------------------------------------------------
  196. // Purpose:
  197. // Input :
  198. // Output :
  199. //-----------------------------------------------------------------------------
  200. void CEntitySprinkleDlg::OnNMCustomdrawSprinkleDensity(NMHDR *pNMHDR, LRESULT *pResult)
  201. {
  202. // LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
  203. char temp[ 128 ];
  204. sprintf( temp, "%d%%", m_SprinkleDensityControl.GetPos() );
  205. m_SprinkleDensityDisplayControl.SetWindowText( temp );
  206. *pResult = 0;
  207. }
  208. //-----------------------------------------------------------------------------
  209. // Purpose:
  210. // Input :
  211. // Output :
  212. //-----------------------------------------------------------------------------
  213. bool CEntitySprinkleDlg::UseDefinitionGridSize( )
  214. {
  215. return ( m_DefinitionGridSizeControl.GetCheck() == BST_CHECKED );
  216. }
  217. //-----------------------------------------------------------------------------
  218. // Purpose:
  219. // Input :
  220. // Output :
  221. //-----------------------------------------------------------------------------
  222. void CEntitySprinkleDlg::OnClose()
  223. {
  224. ToolManager()->SetTool( TOOL_PICK_ENTITY );
  225. CDialog::OnClose();
  226. }
  227. //-----------------------------------------------------------------------------
  228. // Purpose:
  229. // Input :
  230. // Output :
  231. //-----------------------------------------------------------------------------
  232. bool CEntitySprinkleDlg::UseRandomYaw( )
  233. {
  234. return ( m_RandomYawControl.GetCheck() == BST_CHECKED );
  235. }
  236. // memdbgon must be the last include file in a .cpp file!!!
  237. #include <tier0/memdbgoff.h>