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.

168 lines
3.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. //
  8. //-----------------------------------------------------------------------------
  9. // $Log: $
  10. //
  11. // $NoKeywords: $
  12. //=============================================================================//
  13. #include "stdafx.h"
  14. #include "hammer.h"
  15. #include "ReplaceTexDlg.h"
  16. #include "MainFrm.h"
  17. #include "GlobalFunctions.h"
  18. #include "TextureBrowser.h"
  19. #include "TextureSystem.h"
  20. #include "mapdoc.h"
  21. // memdbgon must be the last include file in a .cpp file!!!
  22. #include <tier0/memdbgon.h>
  23. CReplaceTexDlg::CReplaceTexDlg(int nSelected, CWnd* pParent /*=NULL*/)
  24. : CDialog(CReplaceTexDlg::IDD, pParent)
  25. {
  26. //{{AFX_DATA_INIT(CReplaceTexDlg)
  27. m_iSearchAll = nSelected ? FALSE : TRUE;
  28. m_strFind = _T("");
  29. m_strReplace = _T("");
  30. m_iAction = 0;
  31. m_bMarkOnly = FALSE;
  32. m_bHidden = FALSE;
  33. m_bRescaleTextureCoordinates = false;
  34. //}}AFX_DATA_INIT
  35. m_nSelected = nSelected;
  36. }
  37. void CReplaceTexDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CReplaceTexDlg)
  41. DDX_Control(pDX, IDC_FIND, m_cFind);
  42. DDX_Control(pDX, IDC_REPLACE, m_cReplace);
  43. DDX_Control(pDX, IDC_REPLACEPIC, m_cReplacePic);
  44. DDX_Control(pDX, IDC_FINDPIC, m_cFindPic);
  45. DDX_Radio(pDX, IDC_INMARKED, m_iSearchAll);
  46. DDX_Text(pDX, IDC_FIND, m_strFind);
  47. DDX_Text(pDX, IDC_REPLACE, m_strReplace);
  48. DDX_Radio(pDX, IDC_ACTION, m_iAction);
  49. DDX_Check(pDX, IDC_MARKONLY, m_bMarkOnly);
  50. DDX_Check(pDX, IDC_HIDDEN, m_bHidden);
  51. DDX_Check(pDX, IDC_RESCALETEXTURECOORDINATES, m_bRescaleTextureCoordinates);
  52. //}}AFX_DATA_MAP
  53. }
  54. BEGIN_MESSAGE_MAP(CReplaceTexDlg, CDialog)
  55. //{{AFX_MSG_MAP(CReplaceTexDlg)
  56. ON_BN_CLICKED(IDC_BROWSEREPLACE, OnBrowsereplace)
  57. ON_BN_CLICKED(IDC_BROWSEFIND, OnBrowsefind)
  58. ON_EN_UPDATE(IDC_FIND, OnUpdateFind)
  59. ON_EN_UPDATE(IDC_REPLACE, OnUpdateReplace)
  60. //}}AFX_MSG_MAP
  61. END_MESSAGE_MAP()
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CReplaceTexDlg message handlers
  64. void CReplaceTexDlg::BrowseTex(int iEdit)
  65. {
  66. CString strTex;
  67. CWnd *pWnd = GetDlgItem(iEdit);
  68. pWnd->GetWindowText(strTex);
  69. CTextureBrowser *pBrowser = new CTextureBrowser(GetMainWnd());
  70. pBrowser->SetUsed(iEdit == IDC_FIND);
  71. pBrowser->SetInitialTexture(strTex);
  72. if (pBrowser->DoModal() == IDOK)
  73. {
  74. IEditorTexture *pTex = g_Textures.FindActiveTexture(pBrowser->m_cTextureWindow.szCurTexture);
  75. char szName[MAX_PATH];
  76. if (pTex != NULL)
  77. {
  78. pTex->GetShortName(szName);
  79. }
  80. else
  81. {
  82. szName[0] = '\0';
  83. }
  84. pWnd->SetWindowText(szName);
  85. }
  86. delete pBrowser;
  87. }
  88. void CReplaceTexDlg::OnBrowsereplace()
  89. {
  90. BrowseTex(IDC_REPLACE);
  91. }
  92. void CReplaceTexDlg::OnBrowsefind()
  93. {
  94. BrowseTex(IDC_FIND);
  95. }
  96. //
  97. // find/replace text string updates:
  98. //
  99. void CReplaceTexDlg::OnUpdateFind()
  100. {
  101. // get texture window and set texture in there
  102. CString strTex;
  103. m_cFind.GetWindowText(strTex);
  104. IEditorTexture *pTex = g_Textures.FindActiveTexture(strTex);
  105. m_cFindPic.SetTexture(pTex);
  106. }
  107. void CReplaceTexDlg::OnUpdateReplace()
  108. {
  109. // get texture window and set texture in there
  110. CString strTex;
  111. m_cReplace.GetWindowText(strTex);
  112. IEditorTexture *pTex = g_Textures.FindActiveTexture(strTex);
  113. m_cReplacePic.SetTexture(pTex);
  114. }
  115. BOOL CReplaceTexDlg::OnInitDialog()
  116. {
  117. CDialog::OnInitDialog();
  118. if(!m_nSelected)
  119. {
  120. CWnd *pWnd = GetDlgItem(IDC_INMARKED);
  121. pWnd->EnableWindow(FALSE);
  122. }
  123. OnUpdateFind();
  124. return TRUE;
  125. }
  126. void CReplaceTexDlg::DoReplaceTextures()
  127. {
  128. CMapDoc *pDoc = CMapDoc::GetActiveMapDoc();
  129. if ( pDoc )
  130. {
  131. pDoc->ReplaceTextures(
  132. m_strFind,
  133. m_strReplace,
  134. m_iSearchAll,
  135. m_iAction | ( m_bMarkOnly ? 0x100 : 0 ),
  136. m_bHidden,
  137. (m_bRescaleTextureCoordinates != 0)
  138. );
  139. }
  140. }