Team Fortress 2 Source Code as on 22/4/2020
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.

243 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "scene.h"
  8. #include "vcdfile.h"
  9. #include "project.h"
  10. #include "workspacemanager.h"
  11. #include "workspacebrowser.h"
  12. CScene::CScene( CProject *proj, char const *name ) : m_pOwner( proj )
  13. {
  14. Q_strncpy( m_szName, name, sizeof( m_szName ) );
  15. m_pszComments = NULL;
  16. }
  17. CScene::~CScene()
  18. {
  19. while ( m_Files.Count() > 0 )
  20. {
  21. CVCDFile *f = m_Files[ 0 ];
  22. m_Files.Remove( 0 );
  23. delete f;
  24. }
  25. delete[] m_pszComments;
  26. }
  27. CProject *CScene::GetOwnerProject()
  28. {
  29. return m_pOwner;
  30. }
  31. void CScene::SetComments( char const *comments )
  32. {
  33. delete[] m_pszComments;
  34. m_pszComments = V_strdup( comments );
  35. GetOwnerProject()->SetDirty( true );
  36. }
  37. char const *CScene::GetComments( void ) const
  38. {
  39. return m_pszComments ? m_pszComments : "";
  40. }
  41. char const *CScene::GetName() const
  42. {
  43. return m_szName;
  44. }
  45. int CScene::GetVCDCount() const
  46. {
  47. return m_Files.Count();
  48. }
  49. CVCDFile *CScene::GetVCD( int index )
  50. {
  51. if ( index < 0 || index >= m_Files.Count() )
  52. return NULL;
  53. return m_Files[ index ];
  54. }
  55. void CScene::AddVCD( CVCDFile *vcd )
  56. {
  57. Assert( m_Files.Find( vcd ) == m_Files.InvalidIndex() );
  58. m_Files.AddToTail( vcd );
  59. GetOwnerProject()->SetDirty( true );
  60. }
  61. void CScene::RemoveVCD( CVCDFile *vcd )
  62. {
  63. if ( m_Files.Find( vcd ) == m_Files.InvalidIndex() )
  64. return;
  65. m_Files.FindAndRemove( vcd );
  66. GetOwnerProject()->SetDirty( true );
  67. }
  68. CVCDFile *CScene::FindVCD( char const *filename )
  69. {
  70. int c = GetVCDCount();
  71. CVCDFile *vcd;
  72. for ( int i = 0; i < c; i++ )
  73. {
  74. vcd = GetVCD( i );
  75. if ( !vcd )
  76. continue;
  77. if ( !Q_stricmp( filename, vcd->GetName() ) )
  78. return vcd;
  79. }
  80. return NULL;
  81. }
  82. void CScene::ValidateTree( mxTreeView *tree, mxTreeViewItem* parent )
  83. {
  84. CUtlVector< mxTreeViewItem * > m_KnownItems;
  85. int c = GetVCDCount();
  86. CVCDFile *vcd;
  87. for ( int i = 0; i < c; i++ )
  88. {
  89. vcd = GetVCD( i );
  90. if ( !vcd )
  91. continue;
  92. char sz[ 256 ];
  93. if ( vcd->GetComments() && vcd->GetComments()[0] )
  94. {
  95. Q_snprintf( sz, sizeof( sz ), "%s : %s", vcd->GetName(), vcd->GetComments() );
  96. }
  97. else
  98. {
  99. Q_snprintf( sz, sizeof( sz ), "%s", vcd->GetName() );
  100. }
  101. mxTreeViewItem *spot = vcd->FindItem( tree, parent );
  102. if ( !spot )
  103. {
  104. spot = tree->add( parent, sz );
  105. }
  106. m_KnownItems.AddToTail( spot );
  107. vcd->SetOrdinal( i );
  108. tree->setLabel( spot, sz );
  109. tree->setImages( spot, vcd->GetIconIndex(), vcd->GetIconIndex() );
  110. tree->setUserData( spot, vcd );
  111. //tree->setOpen( spot, vcd->IsExpanded() );
  112. vcd->ValidateTree( tree, spot );
  113. }
  114. mxTreeViewItem *start = tree->getFirstChild( parent );
  115. while ( start )
  116. {
  117. mxTreeViewItem *next = tree->getNextChild( start );
  118. if ( m_KnownItems.Find( start ) == m_KnownItems.InvalidIndex() )
  119. {
  120. tree->remove( start );
  121. }
  122. start = next;
  123. }
  124. tree->sortTree( parent, true, CWorkspaceBrowser::CompareFunc, 0 );
  125. }
  126. bool CScene::IsCheckedOut() const
  127. {
  128. return false;
  129. }
  130. int CScene::GetIconIndex() const
  131. {
  132. /*
  133. if ( IsCheckedOut() )
  134. {
  135. return IMAGE_SCENE_CHECKEDOUT;
  136. }
  137. else
  138. */
  139. {
  140. return IMAGE_SCENE;
  141. }
  142. }
  143. void CScene::Checkout(bool updatestateicons /*= true*/)
  144. {
  145. // Scenes aren't made for checkin / checkout
  146. }
  147. void CScene::Checkin(bool updatestateicons /*= true*/)
  148. {
  149. // Scenes aren't made for checkin / checkout
  150. }
  151. void CScene::MoveChildUp( ITreeItem *child )
  152. {
  153. int c = GetVCDCount();
  154. for ( int i = 1; i < c; i++ )
  155. {
  156. CVCDFile *p = GetVCD( i );
  157. if ( p != child )
  158. continue;
  159. CVCDFile *prev = GetVCD( i - 1 );
  160. // Swap
  161. m_Files[ i - 1 ] = p;
  162. m_Files[ i ] = prev;
  163. return;
  164. }
  165. }
  166. void CScene::MoveChildDown( ITreeItem *child )
  167. {
  168. int c = GetVCDCount();
  169. for ( int i = 0; i < c - 1; i++ )
  170. {
  171. CVCDFile *p = GetVCD( i );
  172. if ( p != child )
  173. continue;
  174. CVCDFile *next = GetVCD( i + 1 );
  175. // Swap
  176. m_Files[ i ] = next;
  177. m_Files[ i + 1 ] = p;
  178. return;
  179. }
  180. }
  181. bool CScene::IsChildFirst( ITreeItem *child )
  182. {
  183. int idx = m_Files.Find( (CVCDFile *)child );
  184. if ( idx == m_Files.InvalidIndex() )
  185. return false;
  186. if ( idx != 0 )
  187. return false;
  188. return true;
  189. }
  190. bool CScene::IsChildLast( ITreeItem *child )
  191. {
  192. int idx = m_Files.Find( (CVCDFile *)child );
  193. if ( idx == m_Files.InvalidIndex() )
  194. return false;
  195. if ( idx != m_Files.Count() - 1 )
  196. return false;
  197. return true;
  198. }