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