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.

371 lines
7.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ====
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "stdafx.h"
  7. #include "EntityHelpDlg.h"
  8. #include "fgdlib/GameData.h"
  9. #include "RichEditCtrlEx.h"
  10. // memdbgon must be the last include file in a .cpp file!!!
  11. #include <tier0/memdbgon.h>
  12. static CEntityHelpDlg *g_pHelpDlg = NULL;
  13. BEGIN_MESSAGE_MAP(CEntityHelpDlg, CDialog)
  14. //{{AFX_MSG_MAP(CEntityHelpDlg)
  15. ON_WM_DESTROY()
  16. ON_WM_CLOSE()
  17. ON_WM_SIZE()
  18. //}}AFX_MSG_MAP
  19. END_MESSAGE_MAP()
  20. //-----------------------------------------------------------------------------
  21. // Purpose:
  22. //-----------------------------------------------------------------------------
  23. void CEntityHelpDlg::ShowEntityHelpDialog(void)
  24. {
  25. if (g_pHelpDlg == NULL)
  26. {
  27. g_pHelpDlg = new CEntityHelpDlg;
  28. g_pHelpDlg->Create(IDD_ENTITY_HELP);
  29. }
  30. if (g_pHelpDlg != NULL)
  31. {
  32. g_pHelpDlg->ShowWindow(SW_SHOW);
  33. }
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. void CEntityHelpDlg::SetEditGameClass(GDclass *pClass)
  39. {
  40. if (g_pHelpDlg != NULL)
  41. {
  42. g_pHelpDlg->UpdateClass(pClass);
  43. }
  44. }
  45. //-----------------------------------------------------------------------------
  46. // Purpose: Constructor.
  47. //-----------------------------------------------------------------------------
  48. CEntityHelpDlg::CEntityHelpDlg(CWnd *pwndParent)
  49. : CDialog(CEntityHelpDlg::IDD, pwndParent)
  50. {
  51. m_pHelpText = NULL;
  52. }
  53. //-----------------------------------------------------------------------------
  54. // Purpose: Destructor.
  55. //-----------------------------------------------------------------------------
  56. CEntityHelpDlg::~CEntityHelpDlg(void)
  57. {
  58. g_pHelpDlg = NULL;
  59. }
  60. //-----------------------------------------------------------------------------
  61. // Purpose:
  62. // Input : pDX -
  63. //-----------------------------------------------------------------------------
  64. void CEntityHelpDlg::DoDataExchange(CDataExchange *pDX)
  65. {
  66. CDialog::DoDataExchange(pDX);
  67. //{{AFX_DATA_MAP(CEntityHelpDlg)
  68. //}}AFX_DATA_MAP
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Purpose:
  72. // Input : pszText -
  73. // Output :
  74. //-----------------------------------------------------------------------------
  75. int CEntityHelpDlg::GetTextWidth(const char *pszText, CDC *pDC)
  76. {
  77. if (pszText != NULL)
  78. {
  79. bool bRelease = false;
  80. if (pDC == NULL)
  81. {
  82. bRelease = true;
  83. pDC = m_pHelpText->GetDC();
  84. }
  85. CGdiObject *pOldFont = pDC->SelectStockObject(DEFAULT_GUI_FONT);
  86. CSize Size = pDC->GetTabbedTextExtent(pszText, strlen(pszText), 0, NULL);
  87. pDC->SelectObject(pOldFont);
  88. if (bRelease)
  89. {
  90. m_pHelpText->ReleaseDC(pDC);
  91. }
  92. return(Size.cx);
  93. }
  94. return(0);
  95. }
  96. //-----------------------------------------------------------------------------
  97. // Purpose:
  98. // Input : pClass -
  99. // Output :
  100. //-----------------------------------------------------------------------------
  101. int CEntityHelpDlg::GetMaxVariableWidth(GDclass *pClass)
  102. {
  103. CDC *pDC = m_pHelpText->GetDC();
  104. int nWidthMax = 0;
  105. int nCount = m_pClass->GetVariableCount();
  106. for (int i = 0; i < nCount; i++)
  107. {
  108. GDinputvariable *pVar = m_pClass->GetVariableAt(i);
  109. int nWidth = GetTextWidth(pVar->GetName(), pDC);
  110. if (nWidth > nWidthMax)
  111. {
  112. nWidthMax = nWidth;
  113. }
  114. }
  115. m_pHelpText->ReleaseDC(pDC);
  116. return(nWidthMax);
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose:
  120. //-----------------------------------------------------------------------------
  121. void CEntityHelpDlg::OnClose(void)
  122. {
  123. DestroyWindow();
  124. }
  125. //-----------------------------------------------------------------------------
  126. // Purpose: Called when our window is being destroyed.
  127. //-----------------------------------------------------------------------------
  128. void CEntityHelpDlg::OnDestroy(void)
  129. {
  130. delete this;
  131. }
  132. //-----------------------------------------------------------------------------
  133. // Purpose:
  134. //-----------------------------------------------------------------------------
  135. BOOL CEntityHelpDlg::OnInitDialog(void)
  136. {
  137. CDialog::OnInitDialog();
  138. m_pHelpText = new CRichEditCtrlEx;
  139. m_pHelpText->SubclassDlgItem(IDC_HELP_TEXT, this);
  140. m_pHelpText->enable();
  141. return(TRUE);
  142. }
  143. //-----------------------------------------------------------------------------
  144. // Purpose:
  145. // Input : pClass -
  146. //-----------------------------------------------------------------------------
  147. void CEntityHelpDlg::UpdateClass(GDclass *pClass)
  148. {
  149. m_pClass = pClass;
  150. UpdateHelp();
  151. m_pHelpText->LineScroll(-64000, -64000);
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose:
  155. //-----------------------------------------------------------------------------
  156. void CEntityHelpDlg::UpdateHelp(void)
  157. {
  158. if (m_pClass != NULL)
  159. {
  160. m_pHelpText->SetWindowText("");
  161. CRTFBuilder b;
  162. b << size(24);
  163. b << bold(true);
  164. b << color(1);
  165. b << m_pClass->GetName();
  166. b << "\n\n";
  167. b << write(*m_pHelpText);
  168. b << size(22);
  169. b << bold(false);
  170. b << m_pClass->GetDescription();
  171. b << "\n\n";
  172. b << write(*m_pHelpText);
  173. //
  174. // Keys section.
  175. //
  176. int nCount = m_pClass->GetVariableCount();
  177. if (nCount > 0)
  178. {
  179. //
  180. // Keys header.
  181. //
  182. b << size(24);
  183. b << bold(true);
  184. b << color(1);
  185. b << "KEYS";
  186. b << "\n\n";
  187. b << write(*m_pHelpText);
  188. //
  189. // Keys.
  190. //
  191. b << size(20);
  192. b << bold(false);
  193. for (int i = 0; i < nCount; i++)
  194. {
  195. GDinputvariable *pVar = m_pClass->GetVariableAt(i);
  196. b << bold(true);
  197. b << pVar->GetLongName();
  198. b << bold(false);
  199. b << " ";
  200. b << italic(true);
  201. b << pVar->GetName();
  202. b << italic(false);
  203. b << " <";
  204. b << pVar->GetTypeText();
  205. b << "> ";
  206. b << pVar->GetDescription();
  207. b << "\n\n";
  208. b << write(*m_pHelpText);
  209. }
  210. }
  211. //
  212. // Inputs section.
  213. //
  214. int nInputCount = m_pClass->GetInputCount();
  215. if (nInputCount > 0)
  216. {
  217. //
  218. // Inputs header.
  219. //
  220. b << "\n";
  221. b << size(24);
  222. b << bold(true);
  223. b << color(1);
  224. b << "INPUTS";
  225. b << "\n\n";
  226. b << write(*m_pHelpText);
  227. //
  228. // Inputs.
  229. //
  230. b << size(20);
  231. for (int i = 0; i < nInputCount; i++)
  232. {
  233. CClassInput *pInput = m_pClass->GetInput(i);
  234. b << bold(true);
  235. b << pInput->GetName();
  236. b << bold(false);
  237. b << " ";
  238. if (pInput->GetType() != iotVoid)
  239. {
  240. b << "<";
  241. b << pInput->GetTypeText();
  242. b << "> ";
  243. }
  244. b << pInput->GetDescription();
  245. b << "\n\n";
  246. b << write(*m_pHelpText);
  247. }
  248. }
  249. //
  250. // Outputs section.
  251. //
  252. int nOutputCount = m_pClass->GetOutputCount();
  253. if (nOutputCount > 0)
  254. {
  255. //
  256. // Outputs header.
  257. //
  258. b << "\n";
  259. b << size(24);
  260. b << bold(true);
  261. b << color(1);
  262. b << "OUTPUTS";
  263. b << "\n\n";
  264. b << write(*m_pHelpText);
  265. //
  266. // Outputs.
  267. //
  268. b << size(20);
  269. for (int i = 0; i < nOutputCount; i++)
  270. {
  271. CClassOutput *pOutput = m_pClass->GetOutput(i);
  272. b << bold(true);
  273. b << pOutput->GetName();
  274. b << bold(false);
  275. b << " ";
  276. if (pOutput->GetType() != iotVoid)
  277. {
  278. b << "<";
  279. b << pOutput->GetTypeText();
  280. b << "> ";
  281. }
  282. b << pOutput->GetDescription();
  283. b << "\n\n";
  284. b << write(*m_pHelpText);
  285. }
  286. }
  287. }
  288. }
  289. //-----------------------------------------------------------------------------
  290. // Purpose:
  291. // Input : nType -
  292. // cx -
  293. // cy -
  294. // Output : afx_msg void
  295. //-----------------------------------------------------------------------------
  296. void CEntityHelpDlg::OnSize( UINT nType, int cx, int cy )
  297. {
  298. CDialog::OnSize(nType, cx, cy);
  299. if (m_pHelpText != NULL)
  300. {
  301. m_pHelpText->SetWindowPos(NULL, 0, 0, cx - 22, cy - 22, SWP_NOMOVE | SWP_NOZORDER);
  302. }
  303. }