DialogTextures.cpp 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052
  1. /*
  2. ===========================================================================
  3. Doom 3 GPL Source Code
  4. Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
  6. Doom 3 Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 Source Code 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. You should have received a copy of the GNU General Public License
  15. along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. #include "../../idlib/precompiled.h"
  21. #pragma hdrstop
  22. #include "qe3.h"
  23. #include "Radiant.h"
  24. #include "WaitDlg.h"
  25. #include "DialogTextures.h"
  26. #include "DialogInfo.h"
  27. #include "EditViewDlg.h"
  28. #ifdef _DEBUG
  29. #define new DEBUG_NEW
  30. #undef THIS_FILE
  31. static char THIS_FILE[] = __FILE__;
  32. #endif
  33. HTREEITEM FindTreeItem(CTreeCtrl *tree, HTREEITEM root, const char *text, HTREEITEM forceParent);
  34. extern void Select_SetKeyVal(const char *key, const char *val);
  35. const char *CDialogTextures::TypeNames[] = {
  36. "None",
  37. "Textures",
  38. "Materials",
  39. "Models",
  40. "Scripts",
  41. "Sounds",
  42. "SoundParent",
  43. "Guis",
  44. "Particles",
  45. "Fx"
  46. };
  47. //
  48. // =======================================================================================================================
  49. // CDialogTextures dialog
  50. // =======================================================================================================================
  51. //
  52. CDialogTextures::CDialogTextures(CWnd *pParent /* =NULL */ ) :
  53. CDialog(CDialogTextures::IDD, pParent) {
  54. setTexture = true;
  55. ignoreCollapse = false;
  56. mode = TEXTURES;
  57. editMaterial = NULL;
  58. editGui = "";
  59. //{{AFX_DATA_INIT(CDialogTextures)
  60. //}}AFX_DATA_INIT
  61. }
  62. /*
  63. =======================================================================================================================
  64. =======================================================================================================================
  65. */
  66. void CDialogTextures::DoDataExchange(CDataExchange *pDX) {
  67. CDialog::DoDataExchange(pDX);
  68. //{{AFX_DATA_MAP(CDialogTextures)
  69. DDX_Control(pDX, IDC_CHECK_HIDEROOT, m_chkHideRoot);
  70. DDX_Control(pDX, IDC_REFRESH, m_btnRefresh);
  71. DDX_Control(pDX, IDC_LOAD, m_btnLoad);
  72. DDX_Control(pDX, IDC_PREVIEW, m_wndPreview);
  73. DDX_Control(pDX, IDC_TREE_TEXTURES, m_treeTextures);
  74. //}}AFX_DATA_MAP
  75. }
  76. BEGIN_MESSAGE_MAP(CDialogTextures, CDialog)
  77. //{{AFX_MSG_MAP(CDialogTextures)
  78. ON_BN_CLICKED(IDC_LOAD, OnLoad)
  79. ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
  80. ON_NOTIFY(NM_CLICK, IDC_TREE_TEXTURES, OnClickTreeTextures)
  81. ON_NOTIFY(TVN_SELCHANGED, IDC_TREE_TEXTURES, OnSelchangedTreeTextures)
  82. ON_NOTIFY(NM_DBLCLK, IDC_TREE_TEXTURES, OnDblclkTreeTextures)
  83. ON_BN_CLICKED(IDC_PREVIEW, OnPreview)
  84. ON_WM_CREATE()
  85. ON_WM_SIZE()
  86. ON_BN_CLICKED(IDC_CHECK_HIDEROOT, OnCheckHideroot)
  87. ON_COMMAND(ID_MATERIAL_EDIT, OnMaterialEdit)
  88. ON_COMMAND(ID_MATERIAL_INFO, OnMaterialInfo)
  89. //}}AFX_MSG_MAP
  90. ON_WM_SETFOCUS()
  91. ON_NOTIFY(NM_RCLICK, IDC_TREE_TEXTURES, OnNMRclickTreeTextures)
  92. END_MESSAGE_MAP()
  93. //
  94. // =======================================================================================================================
  95. // CDialogTextures message handlers
  96. // =======================================================================================================================
  97. //
  98. void CDialogTextures::OnOK() {
  99. //CDialog::OnOK();
  100. }
  101. /*
  102. =======================================================================================================================
  103. =======================================================================================================================
  104. */
  105. BOOL CDialogTextures::OnInitDialog() {
  106. CDialog::OnInitDialog();
  107. m_image.Create(IDB_BITMAP_MATERIAL, 16, 1, RGB(255, 255, 255));
  108. m_treeTextures.SetImageList(&m_image, TVSIL_NORMAL);
  109. // m_wndPreview.SubclassDlgItem(IDC_PREVIEW, this);
  110. m_wndPreview.setDrawable(&m_testDrawable);
  111. BuildTree();
  112. return TRUE; // return TRUE unless you set the focus to a control
  113. // EXCEPTION: OCX Property Pages should return FALSE
  114. }
  115. /*
  116. =======================================================================================================================
  117. =======================================================================================================================
  118. */
  119. bool CDialogTextures::loadTree( HTREEITEM item, const idStr &name, CWaitDlg *dlg ) {
  120. if ( item == NULL ) {
  121. return true;
  122. }
  123. if ( m_treeTextures.ItemHasChildren( item ) ) {
  124. idStr childName;
  125. HTREEITEM nextItem;
  126. HTREEITEM childItem = m_treeTextures.GetChildItem(item);
  127. while ( childItem != NULL ) {
  128. nextItem = m_treeTextures.GetNextItem( childItem, TVGN_NEXT );
  129. childName = name + "/" + (const char *)m_treeTextures.GetItemText( childItem );
  130. if ( m_treeTextures.ItemHasChildren( childItem ) ) {
  131. if ( !loadTree( childItem, childName, dlg ) ) {
  132. return false;
  133. }
  134. } else {
  135. DWORD dw = m_treeTextures.GetItemData( childItem );
  136. if ( dw == TEXTURES || dw == MATERIALS ) {
  137. if ( dw == TEXTURES ) {
  138. childName = "textures/" + childName;
  139. }
  140. dlg->SetText( childName.c_str() );
  141. Texture_ForName( childName );
  142. }
  143. }
  144. if ( dlg->CancelPressed() ) {
  145. return false;
  146. }
  147. childItem = nextItem;
  148. }
  149. }
  150. return true;
  151. }
  152. HTREEITEM CDialogTextures::findItem(const char *name, HTREEITEM item, HTREEITEM *foundItem) {
  153. if (*foundItem || item == NULL) {
  154. return *foundItem;
  155. }
  156. if (m_treeTextures.ItemHasChildren(item)) {
  157. HTREEITEM nextItem;
  158. HTREEITEM childItem = m_treeTextures.GetChildItem(item);
  159. while (childItem != NULL && *foundItem == NULL) {
  160. nextItem = childItem;
  161. if (m_treeTextures.ItemHasChildren(nextItem)) {
  162. findItem(name, nextItem, foundItem);
  163. } else {
  164. DWORD dw = m_treeTextures.GetItemData(nextItem);
  165. if (dw == TEXTURES) {
  166. const char *matName = buildItemName(nextItem, TypeNames[TEXTURES]);
  167. if ( !idStr::Icmpn( name, "textures/", 9 ) && stricmp(name + 9, matName) == 0) {
  168. *foundItem = nextItem;
  169. return *foundItem;
  170. }
  171. } else if (dw == MATERIALS) {
  172. const char *matName = buildItemName(nextItem, TypeNames[MATERIALS]);
  173. if (stricmp(name, matName) == 0) {
  174. *foundItem = nextItem;
  175. return *foundItem;
  176. }
  177. } else if (dw == SOUNDS) {
  178. if (stricmp(name, m_treeTextures.GetItemText(nextItem)) == 0) {
  179. *foundItem = nextItem;
  180. return *foundItem;
  181. }
  182. }
  183. }
  184. childItem = m_treeTextures.GetNextItem(childItem, TVGN_NEXT);
  185. //childItem = nextItem;
  186. }
  187. }
  188. return *foundItem;
  189. }
  190. void CDialogTextures::CollapseChildren(HTREEITEM parent) {
  191. HTREEITEM nextItem;
  192. HTREEITEM childItem = m_treeTextures.GetChildItem(parent);
  193. while (childItem) {
  194. nextItem = m_treeTextures.GetNextItem(childItem, TVGN_NEXT);
  195. if (m_treeTextures.ItemHasChildren(childItem)) {
  196. CollapseChildren(childItem);
  197. m_treeTextures.Expand(childItem, TVE_COLLAPSE);
  198. }
  199. childItem = nextItem;
  200. }
  201. }
  202. void CDialogTextures::SelectCurrentItem(bool collapse, const char *name, int id) {
  203. HTREEITEM root = m_treeTextures.GetRootItem();
  204. idStr qt;
  205. if ((id == TEXTURES) || (id == MATERIALS)) {
  206. HTREEITEM matItem = NULL;
  207. HTREEITEM *matPtr = &matItem;
  208. // FIXME: This is a hack. How should this really work?
  209. if (id == MATERIALS && !idStr::Icmpn( name, "textures/", 9 ) ) {
  210. // Texture_SetTexture calls SelectCurrentItem with id == MATERIALS
  211. id = TEXTURES;
  212. }
  213. setTexture = false;
  214. if (root) {
  215. if (collapse && !ignoreCollapse) {
  216. CollapseChildren(root);
  217. }
  218. HTREEITEM *check = NULL;
  219. qt = TypeNames[id];
  220. qt += "/";
  221. if (id == TEXTURES && !idStr::Icmpn( name, "textures/", 9 ) ) {
  222. // strip off "textures/"
  223. qt += name + 9;
  224. } else {
  225. qt += name;
  226. }
  227. if (quickTree.Get(qt, &check)) {
  228. matItem = *check;
  229. }
  230. if (matItem == NULL) {
  231. matItem = findItem(name, root, matPtr);
  232. }
  233. if (matItem) {
  234. m_treeTextures.SelectItem(matItem);
  235. }
  236. }
  237. setTexture = true;
  238. } else if (id == SOUNDS) {
  239. if (root) {
  240. if (collapse && !ignoreCollapse) {
  241. CollapseChildren(root);
  242. }
  243. HTREEITEM sel = FindTreeItem(&m_treeTextures, root, name, NULL);
  244. if (sel) {
  245. m_treeTextures.SelectItem(sel);
  246. }
  247. }
  248. }
  249. }
  250. void CDialogTextures::OnLoad() {
  251. CWaitCursor cursor;
  252. CWaitDlg dlg;
  253. dlg.AllowCancel( true );
  254. dlg.SetWindowText( "Loading textures..." );
  255. Texture_HideAll();
  256. HTREEITEM item = m_treeTextures.GetSelectedItem();
  257. idStr name = buildItemName( item, TypeNames[TEXTURES] );
  258. if ( !name.Cmpn( TypeNames[MATERIALS], strlen( TypeNames[MATERIALS] ) ) ) {
  259. name = buildItemName( item, TypeNames[MATERIALS] );
  260. }
  261. loadTree( item, name, &dlg );
  262. }
  263. const char *CDialogTextures::buildItemName(HTREEITEM item, const char *rootName) {
  264. itemName = m_treeTextures.GetItemText(item);
  265. // have to build the name back up
  266. HTREEITEM parent = m_treeTextures.GetParentItem(item);
  267. while (true) {
  268. idStr strParent = m_treeTextures.GetItemText(parent);
  269. if ( idStr::Icmp(strParent, rootName) == 0 ) {
  270. break;
  271. }
  272. strParent += "/";
  273. strParent += itemName;
  274. itemName = strParent;
  275. parent = m_treeTextures.GetParentItem(parent);
  276. if (parent == NULL) {
  277. break;
  278. }
  279. }
  280. return itemName;
  281. }
  282. /*
  283. =======================================================================================================================
  284. =======================================================================================================================
  285. */
  286. void CDialogTextures::OnRefresh() {
  287. quickTree.Clear();
  288. addModels( true );
  289. if (mode == TEXTURES) {
  290. idStrList textures(1024);
  291. int count = declManager->GetNumDecls( DECL_MATERIAL );
  292. int i;
  293. const idMaterial *mat;
  294. for (i = 0; i < count; i++) {
  295. mat = declManager->MaterialByIndex(i, false);
  296. if ( mat->IsValid() && mat->TestMaterialFlag(MF_EDITOR_VISIBLE) && !idStr::Icmpn( mat->GetName(), "textures/", 9 ) ) {
  297. textures.Append(mat->GetName());
  298. }
  299. }
  300. declManager->Reload( false );
  301. BuildTree();
  302. count = textures.Num();
  303. for (i = 0; i < count; i++) {
  304. mat = declManager->FindMaterial(textures[i].c_str());
  305. if ( mat ) {
  306. mat->SetMaterialFlag(MF_EDITOR_VISIBLE);
  307. }
  308. }
  309. SelectCurrentItem(false, g_qeglobals.d_texturewin.texdef.name, CDialogTextures::TEXTURES);
  310. } else if (mode == MATERIALS) {
  311. idStrList textures(1024);
  312. int count = declManager->GetNumDecls( DECL_MATERIAL );
  313. int i;
  314. const idMaterial *mat;
  315. for (i = 0; i < count; i++) {
  316. mat = declManager->MaterialByIndex(i, false);
  317. if ( mat->IsValid() && mat->TestMaterialFlag(MF_EDITOR_VISIBLE) && idStr::Icmpn( mat->GetName(), "textures/", 9 ) ) {
  318. textures.Append(mat->GetName());
  319. }
  320. }
  321. declManager->Reload( false );
  322. BuildTree();
  323. count = textures.Num();
  324. for (i = 0; i < count; i++) {
  325. mat = declManager->FindMaterial(textures[i].c_str());
  326. if ( mat ) {
  327. mat->SetMaterialFlag(MF_EDITOR_VISIBLE);
  328. }
  329. }
  330. SelectCurrentItem(false, g_qeglobals.d_texturewin.texdef.name, CDialogTextures::MATERIALS);
  331. } else if (mode == SOUNDS || mode == SOUNDPARENT) {
  332. HTREEITEM root = m_treeTextures.GetRootItem();
  333. HTREEITEM sib = m_treeTextures.GetNextItem(root, TVGN_ROOT);
  334. while (sib) {
  335. idStr str = m_treeTextures.GetItemText(sib);
  336. if (str.Icmp(TypeNames[SOUNDS]) == 0) {
  337. CWaitCursor cursor;
  338. m_treeTextures.DeleteItem(sib);
  339. declManager->Reload( false );
  340. bool rootItems = m_chkHideRoot.GetCheck() == 0;
  341. addSounds(rootItems);
  342. return;
  343. }
  344. sib = m_treeTextures.GetNextSiblingItem(sib);
  345. }
  346. }
  347. }
  348. /*
  349. =======================================================================================================================
  350. =======================================================================================================================
  351. */
  352. HTREEITEM FindTreeItem(CTreeCtrl *tree, HTREEITEM root, const char *text, HTREEITEM forceParent) {
  353. HTREEITEM theItem = NULL;
  354. if (root) {
  355. if ((theItem = tree->GetNextSiblingItem(root)) != NULL) {
  356. theItem = FindTreeItem(tree, theItem, text, NULL);
  357. if (theItem) {
  358. if (forceParent) {
  359. if (tree->GetParentItem(theItem) == forceParent) {
  360. return theItem;
  361. }
  362. } else {
  363. return theItem;
  364. }
  365. }
  366. }
  367. }
  368. if ((theItem = tree->GetChildItem(root)) != NULL) {
  369. theItem = FindTreeItem(tree, theItem, text, NULL);
  370. if (theItem) {
  371. if (forceParent) {
  372. if (tree->GetParentItem(theItem) == forceParent) {
  373. return theItem;
  374. }
  375. } else {
  376. return theItem;
  377. }
  378. }
  379. }
  380. if (text && idStr::Icmp(tree->GetItemText(root), text) == 0 ) {
  381. return root;
  382. }
  383. if (theItem && forceParent) {
  384. if (tree->GetParentItem(theItem) != forceParent) {
  385. theItem = NULL;
  386. }
  387. }
  388. return theItem;
  389. }
  390. /*
  391. =======================================================================================================================
  392. =======================================================================================================================
  393. */
  394. void CDialogTextures::BuildTree() {
  395. CWaitCursor cursor;
  396. m_treeTextures.DeleteAllItems();
  397. bool rootItems = m_chkHideRoot.GetCheck() == 0;
  398. idTimer timer;
  399. timer.Start();
  400. addMaterials( rootItems );
  401. // _D3XP removed
  402. //addModels( rootItems );
  403. addScripts( rootItems );
  404. addSounds( rootItems );
  405. addGuis( rootItems );
  406. addParticles( rootItems );
  407. timer.Stop();
  408. common->Printf( "CDialogTextures::BuildTree() took %.0f milliseconds\n", timer.Milliseconds() );
  409. }
  410. /*
  411. =======================================================================================================================
  412. =======================================================================================================================
  413. */
  414. void CDialogTextures::OnClickTreeTextures(NMHDR *pNMHDR, LRESULT *pResult) {
  415. *pResult = 0;
  416. CPoint pt;
  417. GetCursorPos(&pt);
  418. m_treeTextures.ScreenToClient(&pt);
  419. HTREEITEM item = m_treeTextures.HitTest(pt);
  420. if (item) {
  421. DWORD dw = m_treeTextures.GetItemData(item);
  422. mode = dw;
  423. if (mode == SOUNDS) {
  424. idStr loadName;
  425. if (!m_treeTextures.ItemHasChildren(item)) {
  426. loadName = m_treeTextures.GetItemText(item);
  427. idStr actionName = m_treeTextures.GetItemText(item);
  428. soundSystem->SetMute( false );
  429. g_qeglobals.sw->PlayShaderDirectly(actionName);
  430. } else {
  431. loadName = m_treeTextures.GetItemText(item);
  432. }
  433. } else {
  434. g_qeglobals.sw->StopAllSounds();
  435. }
  436. }
  437. }
  438. /*
  439. =======================================================================================================================
  440. =======================================================================================================================
  441. */
  442. void CDialogTextures::OnSelchangedTreeTextures(NMHDR *pNMHDR, LRESULT *pResult) {
  443. NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW *) pNMHDR;
  444. *pResult = 0;
  445. editMaterial = NULL;
  446. editGui = "";
  447. mediaName = "";
  448. currentFile.Empty();
  449. m_wndPreview.setDrawable(&m_testDrawable);
  450. HTREEITEM item = m_treeTextures.GetSelectedItem();
  451. if (item) {
  452. DWORD dw = m_treeTextures.GetItemData(item);
  453. mode = dw;
  454. if ((dw == TEXTURES) || (dw == MATERIALS)) {
  455. idStr matName = m_treeTextures.GetItemText(item);
  456. // have to build the name back up
  457. HTREEITEM parent = m_treeTextures.GetParentItem(item);
  458. while (true) {
  459. idStr strParent = m_treeTextures.GetItemText(parent);
  460. if ( idStr::Icmp(strParent, TypeNames[dw]) == 0 ) {
  461. break;
  462. }
  463. strParent += "/";
  464. strParent += matName;
  465. matName = strParent;
  466. parent = m_treeTextures.GetParentItem(parent);
  467. if (parent == NULL) {
  468. break;
  469. }
  470. }
  471. if ( dw == TEXTURES ) {
  472. matName = "textures/" + matName;
  473. }
  474. const idMaterial *mat = Texture_ForName(matName);
  475. editMaterial = mat;
  476. m_drawMaterial.setMedia(matName);
  477. m_wndPreview.setDrawable(&m_drawMaterial);
  478. m_wndPreview.RedrawWindow();
  479. ignoreCollapse = true;
  480. Select_SetDefaultTexture(mat, false, setTexture);
  481. ignoreCollapse = false;
  482. } else if (dw == MODELS) {
  483. idStr strParent;
  484. idStr modelName = m_treeTextures.GetItemText(item);
  485. // have to build the name back up
  486. HTREEITEM parent = m_treeTextures.GetParentItem(item);
  487. while (true) {
  488. strParent = m_treeTextures.GetItemText(parent);
  489. if ( idStr::Icmp(strParent, TypeNames[MODELS]) == 0 ) {
  490. break;
  491. }
  492. strParent += "/";
  493. strParent += modelName;
  494. modelName = strParent;
  495. parent = m_treeTextures.GetParentItem(parent);
  496. if (parent == NULL) {
  497. break;
  498. }
  499. }
  500. strParent = "models/";
  501. strParent += modelName;
  502. m_drawModel.setMedia(strParent);
  503. mediaName = strParent;
  504. m_wndPreview.setDrawable(&m_drawModel);
  505. m_drawModel.SetRealTime(0);
  506. m_wndPreview.RedrawWindow();
  507. } else if (dw == SCRIPTS) {
  508. } else if (dw == SOUNDS) {
  509. } else if (dw == PARTICLES) {
  510. idStr strParent;
  511. idStr modelName = m_treeTextures.GetItemText(item);
  512. // have to build the name back up
  513. HTREEITEM parent = m_treeTextures.GetParentItem(item);
  514. while (true) {
  515. strParent = m_treeTextures.GetItemText(parent);
  516. if ( idStr::Icmp(strParent, TypeNames[PARTICLES]) == 0 ) {
  517. break;
  518. }
  519. strParent += "/";
  520. strParent += modelName;
  521. modelName = strParent;
  522. parent = m_treeTextures.GetParentItem(parent);
  523. if (parent == NULL) {
  524. break;
  525. }
  526. }
  527. strParent = modelName;
  528. mediaName = strParent;
  529. mediaName += ".prt";
  530. m_drawModel.setMedia(mediaName);
  531. m_drawModel.SetRealTime(50);
  532. m_wndPreview.setDrawable(&m_drawModel);
  533. m_wndPreview.RedrawWindow();
  534. } else if (dw == GUIS) {
  535. idStr strParent;
  536. idStr modelName = m_treeTextures.GetItemText(item);
  537. // have to build the name back up
  538. HTREEITEM parent = m_treeTextures.GetParentItem(item);
  539. while (true) {
  540. strParent = m_treeTextures.GetItemText(parent);
  541. if ( idStr::Icmp(strParent, TypeNames[GUIS]) == 0 ) {
  542. break;
  543. }
  544. strParent += "/";
  545. strParent += modelName;
  546. modelName = strParent;
  547. parent = m_treeTextures.GetParentItem(parent);
  548. if (parent == NULL) {
  549. break;
  550. }
  551. }
  552. strParent = "guis/";
  553. strParent += modelName;
  554. const idMaterial *mat = declManager->FindMaterial("guisurfs/guipreview");
  555. mat->SetGui(strParent);
  556. editGui = strParent;
  557. m_drawMaterial.setMedia("guisurfs/guipreview");
  558. m_drawMaterial.setScale(4.4f);
  559. m_wndPreview.setDrawable(&m_drawMaterial);
  560. m_wndPreview.RedrawWindow();
  561. }
  562. }
  563. }
  564. /*
  565. =======================================================================================================================
  566. =======================================================================================================================
  567. */
  568. void CDialogTextures::addMaterials( bool rootItems ) {
  569. idStrList textures(1024);
  570. idStrList materials(1024);
  571. textures.SetGranularity( 1024 );
  572. materials.SetGranularity( 1024 );
  573. int count = declManager->GetNumDecls( DECL_MATERIAL );
  574. if ( count > 0 ) {
  575. for ( int i = 0; i < count; i++ ) {
  576. const idMaterial *mat = declManager->MaterialByIndex( i, false );
  577. if ( !rootItems ) {
  578. if ( strchr( mat->GetName(), '/' ) == NULL && strchr( mat->GetName(), '\\' ) == NULL ) {
  579. continue;
  580. }
  581. }
  582. // add everything except the textures/ materials
  583. if ( idStr::Icmpn( mat->GetName(), "textures/", 9 ) == 0 ) {
  584. textures.Append( mat->GetName() );
  585. } else {
  586. materials.Append( mat->GetName() );
  587. }
  588. }
  589. idStrListSortPaths( textures );
  590. addStrList( TypeNames[TEXTURES], textures, TEXTURES );
  591. idStrListSortPaths( materials );
  592. addStrList( TypeNames[MATERIALS], materials, MATERIALS );
  593. }
  594. }
  595. /*
  596. =======================================================================================================================
  597. =======================================================================================================================
  598. */
  599. void CDialogTextures::addParticles( bool rootItems ) {
  600. idStrList list(1024);
  601. int count = declManager->GetNumDecls( DECL_PARTICLE );
  602. if (count > 0) {
  603. for (int i = 0; i < count; i++) {
  604. const idDecl *ips = declManager->DeclByIndex( DECL_PARTICLE, i, false );
  605. if (!rootItems) {
  606. if (strchr(ips->GetName(), '/') == NULL && strchr(ips->GetName(), '\\') == NULL) {
  607. continue;
  608. }
  609. }
  610. list.Append(ips->GetName());
  611. }
  612. idStrListSortPaths( list );
  613. addStrList( TypeNames[PARTICLES], list, PARTICLES );
  614. }
  615. }
  616. /*
  617. =======================================================================================================================
  618. =======================================================================================================================
  619. */
  620. void CDialogTextures::addSounds(bool rootItems) {
  621. int i, j;
  622. idStrList list(1024);
  623. idStrList list2(1024);
  624. HTREEITEM base = m_treeTextures.InsertItem(TypeNames[SOUNDS]);
  625. for(i = 0; i < declManager->GetNumDecls( DECL_SOUND ); i++) {
  626. const idSoundShader *poo = declManager->SoundByIndex(i, false);
  627. list.AddUnique( poo->GetFileName() );
  628. }
  629. idStrListSortPaths( list );
  630. for (i = 0; i < list.Num(); i++) {
  631. HTREEITEM child = m_treeTextures.InsertItem(list[i], base);
  632. m_treeTextures.SetItemData(child, SOUNDPARENT);
  633. m_treeTextures.SetItemImage(child, 0, 1);
  634. list2.Clear();
  635. for (j = 0; j < declManager->GetNumDecls( DECL_SOUND ); j++) {
  636. const idSoundShader *poo = declManager->SoundByIndex(j, false);
  637. if ( idStr::Icmp( list[i], poo->GetFileName() ) == 0 ) {
  638. list2.Append( poo->GetName() );
  639. }
  640. }
  641. idStrListSortPaths( list2 );
  642. for (j = 0; j < list2.Num(); j++) {
  643. HTREEITEM child2 = m_treeTextures.InsertItem( list2[j], child );
  644. m_treeTextures.SetItemData(child2, SOUNDS);
  645. m_treeTextures.SetItemImage(child2, 2, 2);
  646. }
  647. }
  648. }
  649. void CDialogTextures::addStrList( const char *root, const idStrList &list, int id ) {
  650. idStr out, path;
  651. HTREEITEM base = m_treeTextures.GetRootItem();
  652. while (base) {
  653. out = m_treeTextures.GetItemText(base);
  654. if (stricmp(root, out) == 0) {
  655. break;
  656. }
  657. base = m_treeTextures.GetNextSiblingItem(base);
  658. }
  659. if (base == NULL) {
  660. base = m_treeTextures.InsertItem(root);
  661. }
  662. HTREEITEM item = base;
  663. HTREEITEM add;
  664. int count = list.Num();
  665. idStr last, qt;
  666. for (int i = 0; i < count; i++) {
  667. idStr name = list[i];
  668. // now break the name down convert to slashes
  669. name.BackSlashesToSlashes();
  670. name.Strip(' ');
  671. int index;
  672. int len = last.Length();
  673. if (len == 0) {
  674. index = name.Last('/');
  675. if (index >= 0) {
  676. name.Left(index, last);
  677. }
  678. }
  679. else if (idStr::Icmpn(last, name, len) == 0 && name.Last('/') <= len) {
  680. name.Right(name.Length() - len - 1, out);
  681. add = m_treeTextures.InsertItem(out, item);
  682. qt = root;
  683. qt += "/";
  684. qt += name;
  685. quickTree.Set(qt, add);
  686. m_treeTextures.SetItemData(add, id);
  687. m_treeTextures.SetItemImage(add, 2, 2);
  688. continue;
  689. }
  690. else {
  691. last.Empty();
  692. }
  693. index = 0;
  694. item = base;
  695. path = "";
  696. while (index >= 0) {
  697. index = name.Find('/');
  698. if (index >= 0) {
  699. HTREEITEM newItem = NULL;
  700. HTREEITEM *check = NULL;
  701. name.Left( index, out );
  702. path += out;
  703. qt = root;
  704. qt += "/";
  705. qt += path;
  706. if (quickTree.Get(qt, &check)) {
  707. newItem = *check;
  708. }
  709. //HTREEITEM newItem = FindTreeItem(&m_treeTextures, item, name.Left(index, out), item);
  710. if (newItem == NULL) {
  711. newItem = m_treeTextures.InsertItem(out, item);
  712. qt = root;
  713. qt += "/";
  714. qt += path;
  715. quickTree.Set(qt, newItem);
  716. m_treeTextures.SetItemImage(newItem, 0, 1);
  717. }
  718. assert(newItem);
  719. item = newItem;
  720. name.Right( name.Length() - index - 1, out );
  721. name = out;
  722. path += "/";
  723. }
  724. else {
  725. add = m_treeTextures.InsertItem(name, item);
  726. qt = root;
  727. qt += "/";
  728. qt += path;
  729. qt += name;
  730. quickTree.Set(qt, add);
  731. m_treeTextures.SetItemData(add, id);
  732. m_treeTextures.SetItemImage(add, 2, 2);
  733. path = "";
  734. }
  735. }
  736. }
  737. }
  738. /*
  739. =======================================================================================================================
  740. =======================================================================================================================
  741. */
  742. void CDialogTextures::addModels(bool rootItems) {
  743. idFileList *files;
  744. files = fileSystem->ListFilesTree( "models", ".ase|.lwo|.ma", true );
  745. if ( files->GetNumFiles() ) {
  746. addStrList( TypeNames[MODELS], files->GetList(), MODELS );
  747. }
  748. fileSystem->FreeFileList( files );
  749. }
  750. void CDialogTextures::addGuis( bool rootItems ) {
  751. idFileList *files;
  752. files = fileSystem->ListFilesTree( "guis", ".gui", true );
  753. if ( files->GetNumFiles() ) {
  754. addStrList( TypeNames[GUIS], files->GetList(), GUIS );
  755. }
  756. fileSystem->FreeFileList( files );
  757. }
  758. /*
  759. =======================================================================================================================
  760. =======================================================================================================================
  761. */
  762. void CDialogTextures::addScripts(bool rootItems) {
  763. /*
  764. idFileList *files;
  765. files = fileSystem->ListFilesExt( "def", ".script" );
  766. if ( files->GetNumFiles() ) {
  767. addStrList("Scripts", files->GetList(), 3);
  768. }
  769. */
  770. }
  771. /*
  772. =======================================================================================================================
  773. =======================================================================================================================
  774. */
  775. void CDialogTextures::OnDblclkTreeTextures(NMHDR *pNMHDR, LRESULT *pResult) {
  776. CPoint pt;
  777. GetCursorPos(&pt);
  778. m_treeTextures.ScreenToClient(&pt);
  779. HTREEITEM item = m_treeTextures.HitTest(pt);
  780. if (item) {
  781. DWORD dw = m_treeTextures.GetItemData(item);
  782. mode = dw;
  783. if (mode == SOUNDS) {
  784. if (!m_treeTextures.ItemHasChildren(item)) {
  785. idStr shaderName = m_treeTextures.GetItemText(item);
  786. Select_SetKeyVal("s_shader", shaderName);
  787. entity_t *ent = selected_brushes.next->owner;
  788. if (ent) {
  789. g_Inspectors->UpdateEntitySel(ent->eclass);
  790. MessageBeep(MB_OK);
  791. }
  792. }
  793. } else if (mode == MODELS || mode == PARTICLES ) {
  794. if (mediaName.Length()) {
  795. g_Inspectors->entityDlg.UpdateKeyVal("model", mediaName);
  796. }
  797. } else if (mode <= MATERIALS) {
  798. OnLoad();
  799. }
  800. }
  801. *pResult = 0;
  802. }
  803. /*
  804. =======================================================================================================================
  805. =======================================================================================================================
  806. */
  807. void CDialogTextures::OnPreview() {
  808. // TODO: Add your control notification handler code here
  809. }
  810. //void CDialogTextures::OnSave()
  811. //{
  812. /*
  813. CString str;
  814. m_wndEditShader.GetWindowText(str);
  815. if (currentFile.length() && str.GetLength()) {
  816. fileSystem->WriteFile(currentFile, str.GetBuffer(0), str.GetLength());
  817. }
  818. */
  819. //}
  820. int CDialogTextures::OnCreate(LPCREATESTRUCT lpCreateStruct)
  821. {
  822. if (CDialog::OnCreate(lpCreateStruct) == -1)
  823. return -1;
  824. // TODO: Add your specialized creation code here
  825. return 0;
  826. }
  827. void CDialogTextures::OnSize(UINT nType, int cx, int cy)
  828. {
  829. CDialog::OnSize(nType, cx, cy);
  830. if (m_btnLoad.GetSafeHwnd() == NULL) {
  831. return;
  832. }
  833. CRect rect, rect2, rect3;
  834. GetClientRect(rect);
  835. m_btnLoad.GetWindowRect(rect2);
  836. m_btnLoad.SetWindowPos(NULL, rect.left + 4, rect.top + 4, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
  837. m_btnRefresh.SetWindowPos(NULL, rect.left + rect2.Width() + 4, rect.top + 4, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
  838. int right = rect.right - 4 - rect3.Width() - 4;
  839. right = rect3.right - 4 - rect3.Width() - 4;
  840. m_chkHideRoot.GetWindowRect(rect3);
  841. m_chkHideRoot.SetWindowPos(NULL, right - rect3.Width() * 2, rect.top + 4, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
  842. m_chkHideRoot.ShowWindow(SW_HIDE);
  843. int verticalSpace = (rect.Height() - rect2.Height() - 12) / 2;
  844. m_treeTextures.SetWindowPos(NULL, rect.left + 4, rect.top + 8 + rect2.Height(), (rect.Width() - 8), verticalSpace, SWP_SHOWWINDOW);
  845. m_wndPreview.SetWindowPos(NULL, rect.left + 4, rect.top + 12 + rect2.Height() + verticalSpace, (rect.Width() - 8), verticalSpace, SWP_SHOWWINDOW);
  846. RedrawWindow();
  847. }
  848. BOOL CDialogTextures::PreCreateWindow(CREATESTRUCT& cs)
  849. {
  850. return CDialog::PreCreateWindow(cs);
  851. }
  852. void CDialogTextures::OnCheckHideroot()
  853. {
  854. BuildTree();
  855. }
  856. void CDialogTextures::CollapseEditor() {
  857. if (g_qeglobals.d_savedinfo.editorExpanded) {
  858. }
  859. }
  860. void CDialogTextures::OnCancel() {
  861. }
  862. BOOL CDialogTextures::PreTranslateMessage(MSG* pMsg)
  863. {
  864. if (pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_ESCAPE || pMsg->wParam == VK_RETURN)) {
  865. if (pMsg->wParam == VK_ESCAPE) {
  866. g_pParentWnd->GetCamera()->SetFocus();
  867. Select_Deselect();
  868. }
  869. return TRUE;
  870. }
  871. return CDialog::PreTranslateMessage(pMsg);
  872. }
  873. void CDialogTextures::OnSetFocus(CWnd* pOldWnd)
  874. {
  875. CDialog::OnSetFocus(pOldWnd);
  876. RedrawWindow();
  877. }
  878. void CDialogTextures::OnNMRclickTreeTextures(NMHDR *pNMHDR, LRESULT *pResult)
  879. {
  880. *pResult = 0;
  881. CPoint pt;
  882. GetCursorPos(&pt);
  883. m_treeTextures.ScreenToClient(&pt);
  884. HTREEITEM item = m_treeTextures.HitTest(pt);
  885. if (item) {
  886. DWORD dw = m_treeTextures.GetItemData(item);
  887. mode = dw;
  888. if (mode == TEXTURES || mode == MATERIALS || mode == GUIS) {
  889. m_treeTextures.SelectItem(item);
  890. HandlePopup(this, IDR_POPUP_MATERIAL);
  891. }
  892. }
  893. }
  894. void CDialogTextures::OnMaterialEdit() {
  895. CEditViewDlg dlg;
  896. if ((mode == TEXTURES || mode == MATERIALS) && editMaterial) {
  897. dlg.SetMode(CEditViewDlg::MATERIALS);
  898. dlg.SetMaterialInfo(editMaterial->GetName(), editMaterial->GetFileName(), editMaterial->GetLineNum());
  899. dlg.DoModal();
  900. } else if (mode == GUIS && editGui.Length()) {
  901. dlg.SetMode(CEditViewDlg::GUIS);
  902. dlg.SetGuiInfo(editGui);
  903. dlg.DoModal();
  904. }
  905. }
  906. void CDialogTextures::OnMaterialInfo() {
  907. /*
  908. idStr str;
  909. if (editMaterial) {
  910. str = "File: ";
  911. str += editMaterial->getFileName();
  912. str += "\r\nName: ";
  913. str = editMaterial->getName();
  914. ShowInfoDialog(str);
  915. } else if (editGui.Length()) {
  916. str = "File: ";
  917. str += editGui;
  918. ShowInfoDialog(str);
  919. }
  920. */
  921. }