summaryrefslogtreecommitdiff
path: root/sdklauncher/ModWizard_Intro.cpp
blob: 3403188c912c6ece5e55d630cb7eaebc75f56012 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================

#include "ModWizard_Intro.h"
#include <vgui_controls/WizardPanel.h>
#include <vgui/ILocalize.h>
#include "ModWizard_GetModInfo.h"
#include "filesystem_tools.h"
#include "SourceAppInfo.h"
#include "steam/steam_api.h"

using namespace vgui;

extern CSteamAPIContext *steamapicontext;

extern char g_engineDir[50];

//-----------------------------------------------------------------------------
// Purpose: Determines whether the specified game is subscribed to
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool IsGameSubscribed( int nSteamAppId )
{
   bool bIsSubscribed = false;

	if ( g_pFullFileSystem != NULL && g_pFullFileSystem->IsSteam() && steamapicontext->SteamApps() )
	{
		// See if specified app is installed
		bIsSubscribed = steamapicontext->SteamApps()->BIsSubscribedApp( nSteamAppId );
	}

	return bIsSubscribed;
}


CModWizardSubPanel_Intro::CModWizardSubPanel_Intro( Panel *parent, const char *panelName )
	: BaseClass( parent, panelName )
{
	m_pModHL2Button = new RadioButton( this, "ModHL2Button", "" );
	m_pModHL2MPButton = new RadioButton( this, "ModHL2MPButton", "" );
	m_pModFromScratchButton = new RadioButton( this, "ModFromScratchButton", "" );
	m_pSourceCodeOnlyButton = new RadioButton( this, "ModSourceCodeOnlyButton", "" );

	LoadControlSettings( "ModWizardSubPanel_Intro.res");

	// We presently don't support SDK scratch configuration using the "orangebox" codebase
	if ( !V_strcmp( g_engineDir, "orangebox" ) )
	{
		m_pModFromScratchButton->SetVisible( false );
	}

	//
	// Enable and select the appropriate mod types 
	//
	if ( !V_strcmp( g_engineDir, "orangebox" ) || !V_strcmp( g_engineDir, "source2007" ) )
	   m_pModHL2Button->SetEnabled( IsGameSubscribed( GetAppSteamAppId( k_App_HL2_EP2 ) ) );
	else
	{
		// do it without nesting.
		if ( ( IsGameSubscribed( GetAppSteamAppId( k_App_HL2 ) ) || IsGameSubscribed( GetAppSteamAppId( k_App_HL2_EP1 ) ) ) )
			m_pModHL2Button->SetEnabled( true );
		else
			m_pModHL2Button->SetEnabled( false );
	}

	m_pModHL2MPButton->SetEnabled( IsGameSubscribed( GetAppSteamAppId( k_App_HL2MP ) ) );

   // De-select all
   m_pModHL2Button->SetSelected( false );
   m_pModHL2MPButton->SetSelected( false );
   m_pModFromScratchButton->SetSelected( false );

   // Select the most common possible option
   if ( m_pModHL2Button->IsEnabled() )
   {
      m_pModHL2Button->SetSelected( true );
   }
   else if ( m_pModHL2MPButton->IsEnabled() )
   {
      m_pModHL2Button->SetSelected( true );
   }
   else if ( m_pModFromScratchButton->IsVisible() )
   {
	  m_pModFromScratchButton->SetSelected( true );
   }
}

WizardSubPanel *CModWizardSubPanel_Intro::GetNextSubPanel()
{
	return dynamic_cast<WizardSubPanel *>(GetWizardPanel()->FindChildByName("CModWizardSubPanel_GetModInfo"));
}

void CModWizardSubPanel_Intro::PerformLayout()
{
	BaseClass::PerformLayout();

	// Update the scratch button text - in orange box, the text is different, but it's the same button.
	if ( !V_strcmp( g_engineDir, "source2007" ) )
		SetDialogVariable( "ScratchLabel", g_pVGuiLocalize->Find( "#StartFromTemplate" ) );
	else
		SetDialogVariable( "ScratchLabel", g_pVGuiLocalize->Find( "#StartFromScratch" ) );

	GetWizardPanel()->SetFinishButtonEnabled(false);
}

void CModWizardSubPanel_Intro::OnDisplayAsNext()
{
	GetWizardPanel()->SetTitle( "#ModWizard_Intro_Title", true );
}


ModType_t CModWizardSubPanel_Intro::GetModType()
{
	if ( m_pModHL2Button && m_pModHL2Button->IsSelected() )
	{
		return ModType_HL2;
	}
	else if ( m_pModHL2MPButton && m_pModHL2MPButton->IsSelected() )
	{
		return ModType_HL2_Multiplayer;
	}
	else if ( m_pSourceCodeOnlyButton && m_pSourceCodeOnlyButton->IsSelected() )
	{
		return ModType_SourceCodeOnly;
	}
	else
	{
		return ModType_FromScratch;
	}
}


bool CModWizardSubPanel_Intro::OnNextButton()
{
	// If we're only installing the source code, then we don't care about the game directory.
	bool bShowModName = true;
	if ( GetModType() == ModType_SourceCodeOnly )
		bShowModName = false;

	CModWizardSubPanel_GetModInfo *pNextPanel = dynamic_cast<CModWizardSubPanel_GetModInfo*>(GetWizardPanel()->FindChildByName("CModWizardSubPanel_GetModInfo"));
	if ( pNextPanel )
	{
		if ( pNextPanel->m_pModName )
			pNextPanel->m_pModName->SetVisible( bShowModName );
		
		if ( pNextPanel->m_pModNameInfoLabel )
			pNextPanel->m_pModNameInfoLabel->SetVisible( bShowModName );
	
		pNextPanel->m_ModType = GetModType();
	}

	return true;
}