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.

195 lines
5.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. //=============================================================================
  4. // Valve includes
  5. #include "itemtest/itemtest_controls.h"
  6. #include "vgui_controls/CheckButton.h"
  7. #include "vgui_controls/ComboBox.h"
  8. #include "vgui_controls/MenuItem.h"
  9. #include "vgui_controls/PanelListPanel.h"
  10. #include "tier1/fmtstr.h"
  11. // Last include
  12. #include <tier0/memdbgon.h>
  13. //-----------------------------------------------------------------------------
  14. //
  15. //-----------------------------------------------------------------------------
  16. CGlobalSubPanel::CGlobalSubPanel( vgui::Panel *pParent, const char *pszName, const char *pszNextName )
  17. : BaseClass( pParent, pszName, pszNextName )
  18. {
  19. {
  20. vgui::Label *pNameLabel = new vgui::Label( this, "nameLabel", "#nameLabel" );
  21. m_pNameTextEntry = new vgui::TextEntry( this, "nameTextEntry" );
  22. m_pNameTextEntry->AddActionSignalTarget( this );
  23. m_pPanelListPanel->AddItem( pNameLabel, m_pNameTextEntry );
  24. }
  25. AddStatusPanels( "name" );
  26. {
  27. vgui::Label *pClassLabel = new vgui::Label( this, "classLabel", "#classLabel" );
  28. m_pClassComboBox = new vgui::ComboBox( this, "classComboBox", CItemUploadTF::GetClassCount(), false );
  29. m_pClassComboBox->AddItem( "#none", NULL );
  30. for ( int i = 0; i < CItemUploadTF::GetClassCount(); ++i )
  31. {
  32. m_pClassComboBox->AddItem( CItemUploadTF::GetClassString( i ), NULL );
  33. }
  34. m_pClassComboBox->SilentActivateItemByRow( 0 );
  35. m_pClassComboBox->AddActionSignalTarget( this );
  36. m_pPanelListPanel->AddItem( pClassLabel, m_pClassComboBox );
  37. }
  38. AddStatusPanels( "class" );
  39. {
  40. vgui::Label *pAutoSkinLabel = new vgui::Label( this, "autoSkinLabel", "#autoSkinLabel" );
  41. m_pAutoSkinCheckButton = new vgui::CheckButton( this, "autoSkinCheckButton", "#autoSkinCheckButtonText" );
  42. m_pAutoSkinCheckButton->AddActionSignalTarget( this );
  43. m_pPanelListPanel->AddItem( pAutoSkinLabel, m_pAutoSkinCheckButton );
  44. }
  45. AddStatusPanels( "autoSkin" );
  46. {
  47. vgui::Label *pSteamLabel = new vgui::Label( this, "steamLabel", "#steamLabel" );
  48. m_pSteamTextEntry = new vgui::TextEntry( this, "steamTextEntry" );
  49. m_pSteamTextEntry->SetEditable( false );
  50. m_pPanelListPanel->AddItem( pSteamLabel, m_pSteamTextEntry );
  51. }
  52. AddStatusPanels( "steam" );
  53. UpdateStatus();
  54. }
  55. //-----------------------------------------------------------------------------
  56. //
  57. //-----------------------------------------------------------------------------
  58. void CGlobalSubPanel::UpdateGUI()
  59. {
  60. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  61. if ( !pItemUploadWizard )
  62. return;
  63. m_pNameTextEntry->SetText( pItemUploadWizard->Asset().GetName() );
  64. const char *pszSteamId = pItemUploadWizard->Asset().GetSteamId();
  65. if ( CItemUpload::GetDevMode() && ( !pszSteamId || *pszSteamId == '\0' ) )
  66. {
  67. m_pSteamTextEntry->SetText( "<dev mode>" );
  68. }
  69. else
  70. {
  71. m_pSteamTextEntry->SetText( pszSteamId );
  72. }
  73. vgui::Menu *pMenu = m_pClassComboBox->GetMenu();
  74. if ( pMenu )
  75. {
  76. bool bFound = false;
  77. const char *pszClass = pItemUploadWizard->Asset().GetClass();
  78. for ( int i = 0; i < pMenu->GetItemCount(); ++i )
  79. {
  80. vgui::MenuItem *pMenuItem = pMenu->GetMenuItem( i );
  81. if ( !pMenuItem )
  82. continue;
  83. if ( !V_stricmp( pszClass, pMenuItem->GetName() ) )
  84. {
  85. m_pClassComboBox->ActivateItemByRow( i );
  86. bFound = true;
  87. break;
  88. }
  89. }
  90. if ( !bFound )
  91. {
  92. m_pClassComboBox->ActivateItemByRow( 0 );
  93. }
  94. }
  95. m_pAutoSkinCheckButton->SetSelected( pItemUploadWizard->Asset().SkinToBipHead() );
  96. UpdateStatus();
  97. }
  98. //-----------------------------------------------------------------------------
  99. //
  100. //-----------------------------------------------------------------------------
  101. bool CGlobalSubPanel::UpdateStatus()
  102. {
  103. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  104. if ( !pItemUploadWizard )
  105. return false;
  106. CAssetTF &asset = pItemUploadWizard->Asset();
  107. SetStatus( asset.IsNameValid(), "name" );
  108. SetStatus( asset.IsClassValid(), "class" );
  109. SetStatus( true, "autoSkin" );
  110. SetStatus( asset.IsSteamIdValid(), "steam" );
  111. return BaseClass::UpdateStatus();
  112. }
  113. //-----------------------------------------------------------------------------
  114. //
  115. //-----------------------------------------------------------------------------
  116. void CGlobalSubPanel::OnTextChanged( vgui::Panel *pPanel )
  117. {
  118. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  119. if ( !pItemUploadWizard )
  120. return;
  121. char szBuf[ BUFSIZ ];
  122. if ( pPanel == m_pNameTextEntry )
  123. {
  124. m_pNameTextEntry->GetText( szBuf, ARRAYSIZE( szBuf ) );
  125. if ( !V_strcmp( pItemUploadWizard->Asset().GetName(), szBuf ) )
  126. return;
  127. pItemUploadWizard->Asset().SetName( szBuf );
  128. UpdateStatus();
  129. }
  130. else if ( pPanel == m_pClassComboBox )
  131. {
  132. m_pClassComboBox->GetText( szBuf, ARRAYSIZE( szBuf ) );
  133. if ( !V_strcmp( pItemUploadWizard->Asset().GetClass(), szBuf ) )
  134. return;
  135. pItemUploadWizard->Asset().SetClass( szBuf );
  136. UpdateStatus();
  137. }
  138. }
  139. //-----------------------------------------------------------------------------
  140. //
  141. //-----------------------------------------------------------------------------
  142. void CGlobalSubPanel::OnCheckButtonChecked( vgui::Panel *pPanel )
  143. {
  144. CItemUploadWizard *pItemUploadWizard = dynamic_cast< CItemUploadWizard * >( GetWizardPanel() );
  145. if ( !pItemUploadWizard )
  146. return;
  147. if ( pPanel != m_pAutoSkinCheckButton )
  148. return;
  149. pItemUploadWizard->Asset().SetSkinToBipHead( m_pAutoSkinCheckButton->IsSelected() );
  150. }