aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/game_controls/buysubmenu.cpp
blob: 6bee2e5c79bf1bd2abab194192be60749f0368ed (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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#include "cbase.h"
#include "buysubmenu.h"

#include <KeyValues.h>
#include <vgui_controls/WizardPanel.h>
#include <filesystem.h>
#include <game/client/iviewport.h>
#include <cdll_client_int.h>

#include "mouseoverpanelbutton.h"
// #include "cs_gamerules.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

using namespace vgui;

//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CBuySubMenu::CBuySubMenu(vgui::Panel *parent, const char *name) : WizardSubPanel(parent, name)
{
	m_NextPanel = NULL;
	m_pFirstButton = NULL;
	SetProportional(true);
	
	m_pPanel = new EditablePanel( this, "ItemInfo" );// info window about these items
	m_pPanel->SetProportional( true );
}

//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CBuySubMenu::~CBuySubMenu()
{
}

//-----------------------------------------------------------------------------
// Purpose: magic override to allow vgui to create mouse over buttons for us
//-----------------------------------------------------------------------------
Panel *CBuySubMenu::CreateControlByName( const char *controlName )
{
	if( !Q_stricmp( "MouseOverPanelButton", controlName ) )
	{
		MouseOverPanelButton *newButton = CreateNewMouseOverPanelButton( m_pPanel );
		
		if( !m_pFirstButton )
		{
			m_pFirstButton = newButton;
		}
		return newButton;
	}
	else
	{
		return BaseClass::CreateControlByName( controlName );
	}
}

//-----------------------------------------------------------------------------
// Purpose: Make the first buttons page get displayed when the menu becomes visible
//-----------------------------------------------------------------------------
void CBuySubMenu::SetVisible( bool state )
{
	BaseClass::SetVisible( state );

	for( int i = 0; i< GetChildCount(); i++ ) // get all the buy buttons to performlayout
	{
		MouseOverPanelButton *buyButton = dynamic_cast<MouseOverPanelButton *>(GetChild(i));
		if ( buyButton )
		{
			if( buyButton == m_pFirstButton && state == true )
				buyButton->ShowPage();
			else
				buyButton->HidePage();

			buyButton->InvalidateLayout();
		}
	}
}

CBuySubMenu* CBuySubMenu::CreateNewSubMenu()
{
	return new CBuySubMenu( this );
}

MouseOverPanelButton* CBuySubMenu::CreateNewMouseOverPanelButton(EditablePanel *panel)
{ 
	return new MouseOverPanelButton(this, NULL, panel);
}


//-----------------------------------------------------------------------------
// Purpose: Called when the user picks a class
//-----------------------------------------------------------------------------
void CBuySubMenu::OnCommand( const char *command)
{
	if ( Q_strstr( command, ".res" ) ) // if its a .res file then its a new menu
	{ 
		int i;
		// check the cache
		for ( i = 0; i < m_SubMenus.Count(); i++ )
		{
			if ( !Q_stricmp( m_SubMenus[i].filename, command ) )
			{
				m_NextPanel = m_SubMenus[i].panel;
				Assert( m_NextPanel );
				m_NextPanel->InvalidateLayout(); // force it to reset it prices
				break;
			}
		}	

		if ( i == m_SubMenus.Count() )
		{
			// not there, add a new entry
			SubMenuEntry_t newEntry;
			memset( &newEntry, 0x0, sizeof( newEntry ) );

			CBuySubMenu *newMenu = CreateNewSubMenu();
			newMenu->LoadControlSettings( command );
			m_NextPanel = newMenu;
			Q_strncpy( newEntry.filename, command, sizeof( newEntry.filename ) );
			newEntry.panel = newMenu;
			m_SubMenus.AddToTail( newEntry );
		}

		GetWizardPanel()->OnNextButton();
	}
	else 
	{
		GetWizardPanel()->Close();
		gViewPortInterface->ShowBackGround( false );
	
		if ( Q_stricmp( command, "vguicancel" ) != 0 )
			engine->ClientCmd( command );

		BaseClass::OnCommand(command);
	}
}

//-----------------------------------------------------------------------------
// Purpose: Causes the panel to delete itself when it closes
//-----------------------------------------------------------------------------
void CBuySubMenu::DeleteSubPanels()
{
	if ( m_NextPanel )
	{
		m_NextPanel->SetVisible( false );
		m_NextPanel = NULL;
	}

	m_pFirstButton = NULL;
}

//-----------------------------------------------------------------------------
// Purpose: return the next panel to show
//-----------------------------------------------------------------------------
vgui::WizardSubPanel *CBuySubMenu::GetNextSubPanel()
{ 
	return m_NextPanel;
}