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.

156 lines
4.6 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "ModWizard_Intro.h"
  7. #include <vgui_controls/WizardPanel.h>
  8. #include <vgui/ILocalize.h>
  9. #include "ModWizard_GetModInfo.h"
  10. #include "filesystem_tools.h"
  11. #include "SourceAppInfo.h"
  12. #include "steam/steam_api.h"
  13. using namespace vgui;
  14. extern CSteamAPIContext *steamapicontext;
  15. extern char g_engineDir[50];
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Determines whether the specified game is subscribed to
  18. // Output : Returns true on success, false on failure.
  19. //-----------------------------------------------------------------------------
  20. bool IsGameSubscribed( int nSteamAppId )
  21. {
  22. bool bIsSubscribed = false;
  23. if ( g_pFullFileSystem != NULL && g_pFullFileSystem->IsSteam() && steamapicontext->SteamApps() )
  24. {
  25. // See if specified app is installed
  26. bIsSubscribed = steamapicontext->SteamApps()->BIsSubscribedApp( nSteamAppId );
  27. }
  28. return bIsSubscribed;
  29. }
  30. CModWizardSubPanel_Intro::CModWizardSubPanel_Intro( Panel *parent, const char *panelName )
  31. : BaseClass( parent, panelName )
  32. {
  33. m_pModHL2Button = new RadioButton( this, "ModHL2Button", "" );
  34. m_pModHL2MPButton = new RadioButton( this, "ModHL2MPButton", "" );
  35. m_pModFromScratchButton = new RadioButton( this, "ModFromScratchButton", "" );
  36. m_pSourceCodeOnlyButton = new RadioButton( this, "ModSourceCodeOnlyButton", "" );
  37. LoadControlSettings( "ModWizardSubPanel_Intro.res");
  38. // We presently don't support SDK scratch configuration using the "orangebox" codebase
  39. if ( !V_strcmp( g_engineDir, "orangebox" ) )
  40. {
  41. m_pModFromScratchButton->SetVisible( false );
  42. }
  43. //
  44. // Enable and select the appropriate mod types
  45. //
  46. if ( !V_strcmp( g_engineDir, "orangebox" ) || !V_strcmp( g_engineDir, "source2007" ) )
  47. m_pModHL2Button->SetEnabled( IsGameSubscribed( GetAppSteamAppId( k_App_HL2_EP2 ) ) );
  48. else
  49. {
  50. // do it without nesting.
  51. if ( ( IsGameSubscribed( GetAppSteamAppId( k_App_HL2 ) ) || IsGameSubscribed( GetAppSteamAppId( k_App_HL2_EP1 ) ) ) )
  52. m_pModHL2Button->SetEnabled( true );
  53. else
  54. m_pModHL2Button->SetEnabled( false );
  55. }
  56. m_pModHL2MPButton->SetEnabled( IsGameSubscribed( GetAppSteamAppId( k_App_HL2MP ) ) );
  57. // De-select all
  58. m_pModHL2Button->SetSelected( false );
  59. m_pModHL2MPButton->SetSelected( false );
  60. m_pModFromScratchButton->SetSelected( false );
  61. // Select the most common possible option
  62. if ( m_pModHL2Button->IsEnabled() )
  63. {
  64. m_pModHL2Button->SetSelected( true );
  65. }
  66. else if ( m_pModHL2MPButton->IsEnabled() )
  67. {
  68. m_pModHL2Button->SetSelected( true );
  69. }
  70. else if ( m_pModFromScratchButton->IsVisible() )
  71. {
  72. m_pModFromScratchButton->SetSelected( true );
  73. }
  74. }
  75. WizardSubPanel *CModWizardSubPanel_Intro::GetNextSubPanel()
  76. {
  77. return dynamic_cast<WizardSubPanel *>(GetWizardPanel()->FindChildByName("CModWizardSubPanel_GetModInfo"));
  78. }
  79. void CModWizardSubPanel_Intro::PerformLayout()
  80. {
  81. BaseClass::PerformLayout();
  82. // Update the scratch button text - in orange box, the text is different, but it's the same button.
  83. if ( !V_strcmp( g_engineDir, "source2007" ) )
  84. SetDialogVariable( "ScratchLabel", g_pVGuiLocalize->Find( "#StartFromTemplate" ) );
  85. else
  86. SetDialogVariable( "ScratchLabel", g_pVGuiLocalize->Find( "#StartFromScratch" ) );
  87. GetWizardPanel()->SetFinishButtonEnabled(false);
  88. }
  89. void CModWizardSubPanel_Intro::OnDisplayAsNext()
  90. {
  91. GetWizardPanel()->SetTitle( "#ModWizard_Intro_Title", true );
  92. }
  93. ModType_t CModWizardSubPanel_Intro::GetModType()
  94. {
  95. if ( m_pModHL2Button && m_pModHL2Button->IsSelected() )
  96. {
  97. return ModType_HL2;
  98. }
  99. else if ( m_pModHL2MPButton && m_pModHL2MPButton->IsSelected() )
  100. {
  101. return ModType_HL2_Multiplayer;
  102. }
  103. else if ( m_pSourceCodeOnlyButton && m_pSourceCodeOnlyButton->IsSelected() )
  104. {
  105. return ModType_SourceCodeOnly;
  106. }
  107. else
  108. {
  109. return ModType_FromScratch;
  110. }
  111. }
  112. bool CModWizardSubPanel_Intro::OnNextButton()
  113. {
  114. // If we're only installing the source code, then we don't care about the game directory.
  115. bool bShowModName = true;
  116. if ( GetModType() == ModType_SourceCodeOnly )
  117. bShowModName = false;
  118. CModWizardSubPanel_GetModInfo *pNextPanel = dynamic_cast<CModWizardSubPanel_GetModInfo*>(GetWizardPanel()->FindChildByName("CModWizardSubPanel_GetModInfo"));
  119. if ( pNextPanel )
  120. {
  121. if ( pNextPanel->m_pModName )
  122. pNextPanel->m_pModName->SetVisible( bShowModName );
  123. if ( pNextPanel->m_pModNameInfoLabel )
  124. pNextPanel->m_pModNameInfoLabel->SetVisible( bShowModName );
  125. pNextPanel->m_ModType = GetModType();
  126. }
  127. return true;
  128. }