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.

104 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Helper for the CHudElement class to add themselves to the list of hud elements
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "vgui/IVGui.h"
  8. #include "vgui_controls/MessageMap.h"
  9. // memdbgon must be the last include file in a .cpp file!!!
  10. #include "tier0/memdbgon.h"
  11. using namespace vgui;
  12. // Start with empty list
  13. CBuildFactoryHelper *CBuildFactoryHelper::m_sHelpers = NULL;
  14. //-----------------------------------------------------------------------------
  15. // Purpose: Constructs a panel factory
  16. // Input : pfnCreate - fn Ptr to a function which generates a panel
  17. //-----------------------------------------------------------------------------
  18. CBuildFactoryHelper::CBuildFactoryHelper( char const *className, PANELCREATEFUNC func )
  19. {
  20. // Make this fatal
  21. if ( HasFactory( className ) )
  22. {
  23. Error( "CBuildFactoryHelper: Factory for '%s' already exists!!!!\n", className );
  24. }
  25. //List is empty, or element belongs at front, insert here
  26. m_pNext = m_sHelpers;
  27. m_sHelpers = this;
  28. Assert( func );
  29. m_CreateFunc = func;
  30. Assert( className );
  31. m_pClassName = className;
  32. }
  33. //-----------------------------------------------------------------------------
  34. // Purpose: Returns next object in list
  35. // Output : CBuildFactoryHelper
  36. //-----------------------------------------------------------------------------
  37. CBuildFactoryHelper *CBuildFactoryHelper::GetNext( void )
  38. {
  39. return m_pNext;
  40. }
  41. char const *CBuildFactoryHelper::GetClassName() const
  42. {
  43. return m_pClassName;
  44. }
  45. vgui::Panel *CBuildFactoryHelper::CreatePanel()
  46. {
  47. if ( !m_CreateFunc )
  48. return NULL;
  49. return ( *m_CreateFunc )();
  50. }
  51. // private static meethod
  52. bool CBuildFactoryHelper::HasFactory( char const *className )
  53. {
  54. CBuildFactoryHelper *p = m_sHelpers;
  55. while ( p )
  56. {
  57. if ( !Q_stricmp( className, p->GetClassName() ) )
  58. return true;
  59. p = p->GetNext();
  60. }
  61. return false;
  62. }
  63. // static method
  64. vgui::Panel *CBuildFactoryHelper::InstancePanel( char const *className )
  65. {
  66. CBuildFactoryHelper *p = m_sHelpers;
  67. while ( p )
  68. {
  69. if ( !Q_stricmp( className, p->GetClassName() ) )
  70. return p->CreatePanel();
  71. p = p->GetNext();
  72. }
  73. return NULL;
  74. }
  75. // static method
  76. void CBuildFactoryHelper::GetFactoryNames( CUtlVector< char const * >& list )
  77. {
  78. list.RemoveAll();
  79. CBuildFactoryHelper *p = m_sHelpers;
  80. while ( p )
  81. {
  82. list.AddToTail( p->GetClassName() );
  83. p = p->GetNext();
  84. }
  85. }