summaryrefslogtreecommitdiff
path: root/game/client/econ/trading_start_dialog.h
blob: b5308cddef5b806013d34a2590223dab56a50082 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//

#ifndef TRADING_START_DIALOG_H
#define TRADING_START_DIALOG_H
#ifdef _WIN32
#pragma once
#endif

#include "vgui_controls/EditablePanel.h"
#include "vgui_controls/ScrollableEditablePanel.h"
#include "econ_controls.h"
#include "vgui_avatarimage.h"

// Trading Dialog states
enum
{
	TDS_SELECTING_PLAYER,
	TDS_SELECTING_FROM_FRIENDS,
	TDS_SELECTING_FROM_SERVER,
	TDS_SELECTING_FROM_PROFILE,

	TDS_NUM_STATES,
};

// Button that displays the name & avatar image of a potential trade target
class CTradeTargetPanel : public vgui::EditablePanel
{
	DECLARE_CLASS_SIMPLE( CTradeTargetPanel, vgui::EditablePanel );
public:
	CTradeTargetPanel( vgui::Panel *parent, const char *name ) : vgui::EditablePanel( parent, name )
	{
		m_pAvatar = new CAvatarImagePanel( this, "avatar" );
		m_pButton = new CExButton( this, "button", "", parent );
	}
	~CTradeTargetPanel( void )
	{
		m_pAvatar->MarkForDeletion();
		m_pButton->MarkForDeletion();
	}

	void	SetInfo( const CSteamID &steamID, const char *pszName );

	CAvatarImagePanel	*GetAvatar( void ) { return m_pAvatar; }
	CExButton			*GetButton( void ) { return m_pButton; }

private:
	// Embedded panels
	CAvatarImagePanel	*m_pAvatar;
	CExButton			*m_pButton;
};

//-----------------------------------------------------------------------------
// A dialog that allows users to select who they want to trade with.
//-----------------------------------------------------------------------------
class CTradingStartDialog : public vgui::EditablePanel, public CGameEventListener
{
	DECLARE_CLASS_SIMPLE( CTradingStartDialog, vgui::EditablePanel );
public:
	CTradingStartDialog( vgui::Panel *parent );
	~CTradingStartDialog( void );

	virtual void ApplySettings( KeyValues *inResourceData );
	virtual void ApplySchemeSettings( vgui::IScheme *pScheme );
	virtual void PerformLayout( void );
	virtual void OnCommand( const char *command );
	virtual void FireGameEvent( IGameEvent *event );

	void	Close( void );
	void	Reset( void );
	void	UpdateState( void );
	void	SetupSelectFriends( void );
	void	SetupSelectServer( void );
	void	SetupSelectProfile( void );
	void	UpdatePlayerList( void );

	void	SendGiftTo( CSteamID steamID );
	void	StartTradeWith( CSteamID steamID );
	bool	ExtractSteamIDFromURL( char *inputURL );
	void	OnLookupAccountResponse( uint64 iAccountID );
	bool	IsInGiftMode( ) const { return m_bGiftMode; }
	void	SetGift( CEconItemView* pGiftItem );

	MESSAGE_FUNC_PARAMS( OnTextChanged, "TextChanged", data );

private:
	struct trade_partner_info_t
	{
		CSteamID m_steamID;
		CUtlString m_name;
	};
	vgui::EditablePanel				*m_pStatePanels[TDS_NUM_STATES];
	int								m_iCurrentState;
	CExButton						*m_pSelectFromServerButton;
	CExButton						*m_pCancelButton;

	vgui::EditablePanel				*m_pPlayerList;
	vgui::ScrollableEditablePanel	*m_pPlayerListScroller;
	CUtlVector<trade_partner_info_t> m_PlayerInfoList;
	CUtlVector<CTradeTargetPanel*>	m_pPlayerPanels;
	KeyValues						*m_pButtonKV;
	bool							m_bReapplyButtonKVs;
	vgui::Label						*m_pURLFailLabel;
	vgui::Label						*m_pURLSearchingLabel;
	CEconItemView					m_giftItem;
	bool							m_bGiftMode;
};

CTradingStartDialog *OpenTradingStartDialog( vgui::Panel *pParent, CEconItemView* pOptGiftItem = NULL );

#endif // TRADING_START_DIALOG_H