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.

171 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "buysubmenu.h"
  9. #include <KeyValues.h>
  10. #include <vgui_controls/WizardPanel.h>
  11. #include <filesystem.h>
  12. #include <game/client/iviewport.h>
  13. #include <cdll_client_int.h>
  14. #include "mouseoverpanelbutton.h"
  15. // #include "cs_gamerules.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. using namespace vgui;
  19. //-----------------------------------------------------------------------------
  20. // Purpose: Constructor
  21. //-----------------------------------------------------------------------------
  22. CBuySubMenu::CBuySubMenu(vgui::Panel *parent, const char *name) : WizardSubPanel(parent, name)
  23. {
  24. m_NextPanel = NULL;
  25. m_pFirstButton = NULL;
  26. SetProportional(true);
  27. m_pPanel = new EditablePanel( this, "ItemInfo" );// info window about these items
  28. m_pPanel->SetProportional( true );
  29. }
  30. //-----------------------------------------------------------------------------
  31. // Purpose: Destructor
  32. //-----------------------------------------------------------------------------
  33. CBuySubMenu::~CBuySubMenu()
  34. {
  35. }
  36. //-----------------------------------------------------------------------------
  37. // Purpose: magic override to allow vgui to create mouse over buttons for us
  38. //-----------------------------------------------------------------------------
  39. Panel *CBuySubMenu::CreateControlByName( const char *controlName )
  40. {
  41. if( !Q_stricmp( "MouseOverPanelButton", controlName ) )
  42. {
  43. MouseOverPanelButton *newButton = CreateNewMouseOverPanelButton( m_pPanel );
  44. if( !m_pFirstButton )
  45. {
  46. m_pFirstButton = newButton;
  47. }
  48. return newButton;
  49. }
  50. else
  51. {
  52. return BaseClass::CreateControlByName( controlName );
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. // Purpose: Make the first buttons page get displayed when the menu becomes visible
  57. //-----------------------------------------------------------------------------
  58. void CBuySubMenu::SetVisible( bool state )
  59. {
  60. BaseClass::SetVisible( state );
  61. for( int i = 0; i< GetChildCount(); i++ ) // get all the buy buttons to performlayout
  62. {
  63. MouseOverPanelButton *buyButton = dynamic_cast<MouseOverPanelButton *>(GetChild(i));
  64. if ( buyButton )
  65. {
  66. if( buyButton == m_pFirstButton && state == true )
  67. buyButton->ShowPage();
  68. else
  69. buyButton->HidePage();
  70. buyButton->InvalidateLayout();
  71. }
  72. }
  73. }
  74. CBuySubMenu* CBuySubMenu::CreateNewSubMenu()
  75. {
  76. return new CBuySubMenu( this );
  77. }
  78. MouseOverPanelButton* CBuySubMenu::CreateNewMouseOverPanelButton(EditablePanel *panel)
  79. {
  80. return new MouseOverPanelButton(this, NULL, panel);
  81. }
  82. //-----------------------------------------------------------------------------
  83. // Purpose: Called when the user picks a class
  84. //-----------------------------------------------------------------------------
  85. void CBuySubMenu::OnCommand( const char *command)
  86. {
  87. if ( Q_strstr( command, ".res" ) ) // if its a .res file then its a new menu
  88. {
  89. int i;
  90. // check the cache
  91. for ( i = 0; i < m_SubMenus.Count(); i++ )
  92. {
  93. if ( !Q_stricmp( m_SubMenus[i].filename, command ) )
  94. {
  95. m_NextPanel = m_SubMenus[i].panel;
  96. Assert( m_NextPanel );
  97. m_NextPanel->InvalidateLayout(); // force it to reset it prices
  98. break;
  99. }
  100. }
  101. if ( i == m_SubMenus.Count() )
  102. {
  103. // not there, add a new entry
  104. SubMenuEntry_t newEntry;
  105. memset( &newEntry, 0x0, sizeof( newEntry ) );
  106. CBuySubMenu *newMenu = CreateNewSubMenu();
  107. newMenu->LoadControlSettings( command );
  108. m_NextPanel = newMenu;
  109. Q_strncpy( newEntry.filename, command, sizeof( newEntry.filename ) );
  110. newEntry.panel = newMenu;
  111. m_SubMenus.AddToTail( newEntry );
  112. }
  113. GetWizardPanel()->OnNextButton();
  114. }
  115. else
  116. {
  117. GetWizardPanel()->Close();
  118. gViewPortInterface->ShowBackGround( false );
  119. if ( Q_stricmp( command, "vguicancel" ) != 0 )
  120. engine->ClientCmd( command );
  121. BaseClass::OnCommand(command);
  122. }
  123. }
  124. //-----------------------------------------------------------------------------
  125. // Purpose: Causes the panel to delete itself when it closes
  126. //-----------------------------------------------------------------------------
  127. void CBuySubMenu::DeleteSubPanels()
  128. {
  129. if ( m_NextPanel )
  130. {
  131. m_NextPanel->SetVisible( false );
  132. m_NextPanel = NULL;
  133. }
  134. m_pFirstButton = NULL;
  135. }
  136. //-----------------------------------------------------------------------------
  137. // Purpose: return the next panel to show
  138. //-----------------------------------------------------------------------------
  139. vgui::WizardSubPanel *CBuySubMenu::GetNextSubPanel()
  140. {
  141. return m_NextPanel;
  142. }