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.

284 lines
6.4 KiB

  1. // ParticleBrowser.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ParticleBrowser.h"
  5. #include "matsys_controls/particlepicker.h"
  6. #include "matsys_controls/matsyscontrols.h"
  7. #include "vgui_controls/TextEntry.h"
  8. #include "vgui_controls/Splitter.h"
  9. #include "vgui_controls/Button.h"
  10. #include "KeyValues.h"
  11. #include "vgui/KeyCode.h"
  12. #include "texturesystem.h"
  13. #include "HammerVGui.h"
  14. static LPCTSTR pszIniSection = "Particle Browser";
  15. // CParticleBrowser dialog
  16. class CParticleBrowserPanel : public vgui::EditablePanel
  17. {
  18. public:
  19. CParticleBrowserPanel( CParticleBrowser *pBrowser, const char *panelName, vgui::HScheme hScheme ) :
  20. vgui::EditablePanel( NULL, panelName, hScheme )
  21. {
  22. m_pBrowser = pBrowser;
  23. }
  24. virtual void OnSizeChanged(int newWide, int newTall)
  25. {
  26. // call Panel and not EditablePanel OnSizeChanged.
  27. Panel::OnSizeChanged(newWide, newTall);
  28. }
  29. virtual void OnCommand( const char *pCommand )
  30. {
  31. if ( Q_strcmp( pCommand, "OK" ) == 0 )
  32. {
  33. m_pBrowser->EndDialog( IDOK );
  34. }
  35. else if ( Q_strcmp( pCommand, "Cancel" ) == 0 )
  36. {
  37. m_pBrowser->EndDialog( IDCANCEL );
  38. }
  39. }
  40. virtual void OnKeyCodeTyped(vgui::KeyCode code)
  41. {
  42. vgui::EditablePanel::OnKeyCodeTyped( code );
  43. if ( code == KEY_ENTER )
  44. {
  45. m_pBrowser->EndDialog( IDOK );
  46. }
  47. else if ( code == KEY_ESCAPE )
  48. {
  49. m_pBrowser->EndDialog( IDCANCEL );
  50. }
  51. }
  52. virtual void OnMessage(const KeyValues *params, vgui::VPANEL ifromPanel)
  53. {
  54. vgui::EditablePanel::OnMessage( params, ifromPanel );
  55. if ( Q_strcmp( params->GetName(), "ParticleSystemSelectionChanged" ) == 0 )
  56. {
  57. m_pBrowser->UpdateStatusLine();
  58. }
  59. }
  60. CParticleBrowser *m_pBrowser;
  61. };
  62. IMPLEMENT_DYNAMIC(CParticleBrowser, CDialog)
  63. CParticleBrowser::CParticleBrowser(CWnd* pParent /*=NULL*/)
  64. : CDialog(CParticleBrowser::IDD, pParent)
  65. {
  66. m_pPicker = new CParticlePicker( NULL );
  67. m_pStatusLine = new vgui::TextEntry( NULL, "StatusLine" );
  68. m_pButtonOK = new vgui::Button( NULL, "OpenButton", "OK" );
  69. m_pButtonCancel = new vgui::Button( NULL, "CancelButton", "Cancel" );
  70. }
  71. CParticleBrowser::~CParticleBrowser()
  72. {
  73. // CDialog isn't going to clean up its vgui children
  74. delete m_pPicker;
  75. delete m_pStatusLine;
  76. delete m_pButtonOK;
  77. delete m_pButtonCancel;
  78. }
  79. void CParticleBrowser::SetParticleSysName( const char *pParticleSysName )
  80. {
  81. char pTempName[255];
  82. strcpy( pTempName, pParticleSysName );
  83. char * pSelectedParticleSys = strchr( pTempName, '/' );
  84. if( pSelectedParticleSys)
  85. {
  86. pSelectedParticleSys += 1;
  87. Q_FixSlashes( pSelectedParticleSys, '\\' );
  88. }
  89. m_pPicker->SelectParticleSys( pParticleSysName );
  90. m_pPicker->SetInitialSelection( pSelectedParticleSys );
  91. m_pStatusLine->SetText( pParticleSysName );
  92. }
  93. void CParticleBrowser::GetParticleSysName( char *pParticleName, int length )
  94. {
  95. m_pPicker->GetSelectedParticleSysName( pParticleName, length );
  96. Q_FixSlashes( pParticleName, '/' );
  97. }
  98. void CParticleBrowser::UpdateStatusLine()
  99. {
  100. char szParticle[1024];
  101. m_pPicker->GetSelectedParticleSysName( szParticle, sizeof(szParticle) );
  102. m_pStatusLine->SetText( szParticle );
  103. }
  104. void CParticleBrowser::SaveLoadSettings( bool bSave )
  105. {
  106. CString str;
  107. CRect rect;
  108. CWinApp *pApp = AfxGetApp();
  109. if ( bSave )
  110. {
  111. GetWindowRect(rect);
  112. str.Format("%d %d %d %d", rect.left, rect.top, rect.right, rect.bottom);
  113. pApp->WriteProfileString(pszIniSection, "Position", str);
  114. pApp->WriteProfileString(pszIniSection, "Filter", m_pPicker->GetFilter() );
  115. }
  116. else
  117. {
  118. str = pApp->GetProfileString(pszIniSection, "Position");
  119. if (!str.IsEmpty())
  120. {
  121. sscanf(str, "%d %d %d %d", &rect.left, &rect.top, &rect.right, &rect.bottom);
  122. MoveWindow(rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top, FALSE);
  123. Resize();
  124. }
  125. str = pApp->GetProfileString(pszIniSection, "Filter");
  126. if (!str.IsEmpty())
  127. {
  128. m_pPicker->SetFilter( str );
  129. }
  130. }
  131. }
  132. void CParticleBrowser::DoDataExchange(CDataExchange* pDX)
  133. {
  134. CDialog::DoDataExchange(pDX);
  135. }
  136. void CParticleBrowser::Resize()
  137. {
  138. // reposition controls
  139. CRect rect;
  140. GetClientRect(&rect);
  141. m_VGuiWindow.MoveWindow( rect );
  142. m_pPicker->SetBounds( 0,0, rect.Width(), rect.Height() - 32 );
  143. m_pButtonCancel->SetPos( 8, rect.Height() - 30 );
  144. m_pButtonOK->SetPos( 84, rect.Height() - 30 );
  145. m_pStatusLine->SetBounds( 160, rect.Height() - 30, max( 100, rect.Width() - 166 ), 24 );
  146. }
  147. void CParticleBrowser::OnSize(UINT nType, int cx, int cy)
  148. {
  149. if (nType == SIZE_MINIMIZED || !IsWindow(m_VGuiWindow.m_hWnd) )
  150. {
  151. CDialog::OnSize(nType, cx, cy);
  152. return;
  153. }
  154. Resize();
  155. CDialog::OnSize(nType, cx, cy);
  156. }
  157. BOOL CParticleBrowser::OnEraseBkgnd(CDC* pDC)
  158. {
  159. return TRUE;
  160. }
  161. BEGIN_MESSAGE_MAP(CParticleBrowser, CDialog)
  162. ON_WM_SIZE()
  163. ON_WM_DESTROY()
  164. ON_WM_ERASEBKGND()
  165. END_MESSAGE_MAP()
  166. BOOL CParticleBrowser::PreTranslateMessage( MSG* pMsg )
  167. {
  168. // don't filter dialog message
  169. return CWnd::PreTranslateMessage( pMsg );
  170. }
  171. BOOL CParticleBrowser::OnInitDialog()
  172. {
  173. CDialog::OnInitDialog();
  174. m_VGuiWindow.Create( NULL, _T("ParticleViewer"), WS_VISIBLE|WS_CHILD, CRect(0,0,100,100), this, IDD_PARTICLE_BROWSER );
  175. vgui::EditablePanel *pMainPanel = new CParticleBrowserPanel( this, "ParticleBrowerPanel", HammerVGui()->GetHammerScheme() );
  176. m_VGuiWindow.SetParentWindow( &m_VGuiWindow );
  177. m_VGuiWindow.SetMainPanel( pMainPanel );
  178. pMainPanel->MakePopup( false, false );
  179. m_VGuiWindow.SetRepaintInterval( 75 );
  180. m_pPicker->SetParent( pMainPanel );
  181. m_pPicker->AddActionSignalTarget( pMainPanel );
  182. m_pButtonOK->SetParent( pMainPanel );
  183. m_pButtonOK->AddActionSignalTarget( pMainPanel );
  184. m_pButtonOK->SetCommand( "OK" );
  185. m_pButtonCancel->SetParent( pMainPanel );
  186. m_pButtonCancel->AddActionSignalTarget( pMainPanel );
  187. m_pButtonCancel->SetCommand( "Cancel" );
  188. m_pStatusLine->SetParent( pMainPanel );
  189. m_pStatusLine->SetEditable( false );
  190. SaveLoadSettings( false ); // load
  191. m_pPicker->Activate();
  192. return TRUE;
  193. }
  194. void CParticleBrowser::OnDestroy()
  195. {
  196. SaveLoadSettings( true ); // save
  197. // model browser destoys our default cube map, reload it
  198. g_Textures.RebindDefaultCubeMap();
  199. CDialog::OnDestroy();
  200. }
  201. void CParticleBrowser::Show()
  202. {
  203. if (m_pPicker)
  204. {
  205. m_pPicker->SetVisible( true );
  206. }
  207. if (m_pStatusLine)
  208. m_pStatusLine->SetVisible( true );
  209. if (m_pButtonOK)
  210. m_pButtonOK->SetVisible( true );
  211. if (m_pButtonCancel)
  212. m_pButtonCancel->SetVisible( true );
  213. }
  214. void CParticleBrowser::Hide()
  215. {
  216. if (m_pPicker)
  217. m_pPicker->SetVisible( false );
  218. if (m_pStatusLine)
  219. m_pStatusLine->SetVisible( false );
  220. if (m_pButtonOK)
  221. m_pButtonOK->SetVisible( false );
  222. if (m_pButtonCancel)
  223. m_pButtonCancel->SetVisible( false );
  224. }