summaryrefslogtreecommitdiff
path: root/vgui2/dme_controls/attributesurfacepropertypickerpanel.cpp
blob: 0de786858d8d24236d28cc52353827dfd12cce45 (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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//
//=============================================================================//

#include "dme_controls/AttributeSurfacePropertyPickerPanel.h"
#include "dme_controls/AttributeTextEntry.h"
#include "tier1/KeyValues.h"
#include "filesystem.h"


using namespace vgui;


const char *SURFACEPROP_MANIFEST_FILE = "scripts/surfaceproperties_manifest.txt";


//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CAttributeSurfacePropertyPickerPanel::CAttributeSurfacePropertyPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
	BaseClass( parent, info )
{
}

CAttributeSurfacePropertyPickerPanel::~CAttributeSurfacePropertyPickerPanel()
{
}


//-----------------------------------------------------------------------------
// Reads the surface properties
//-----------------------------------------------------------------------------
void CAttributeSurfacePropertyPickerPanel::AddSurfacePropertiesToList( PickerList_t &list )
{
	KeyValues *manifest = new KeyValues( SURFACEPROP_MANIFEST_FILE );
	if ( manifest->LoadFromFile( g_pFullFileSystem, SURFACEPROP_MANIFEST_FILE, "GAME" ) )
	{
		for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
		{
			if ( Q_stricmp( sub->GetName(), "file" ) )
				continue;
							  
			KeyValues *file = new KeyValues( SURFACEPROP_MANIFEST_FILE );
			if ( file->LoadFromFile( g_pFullFileSystem, sub->GetString(), "GAME" ) )
			{
				for ( KeyValues *pTrav = file; pTrav; pTrav = pTrav->GetNextKey() )
				{
					int i = list.AddToTail();
					list[i].m_pChoiceString = pTrav->GetName();
					list[i].m_pChoiceValue = pTrav->GetName();
				}
			}
			else
			{
				Warning( "Unable to load surface properties file '%s'\n", sub->GetString() );
			}
			file->deleteThis();
		}
	}
	else
	{
		Warning( "Unable to load manifest file '%s'\n", SURFACEPROP_MANIFEST_FILE );
	}

	manifest->deleteThis();
}


//-----------------------------------------------------------------------------
// Called when it's time to show the picker
//-----------------------------------------------------------------------------
void CAttributeSurfacePropertyPickerPanel::ShowPickerDialog()
{
	CPickerFrame *pSurfacePropPickerDialog = new CPickerFrame( this, "Select Surface Property", "Surface Property", "surfacePropertyName" );
	PickerList_t surfacePropList;
	AddSurfacePropertiesToList( surfacePropList );
	pSurfacePropPickerDialog->AddActionSignalTarget( this );
	pSurfacePropPickerDialog->DoModal( surfacePropList );
}


//-----------------------------------------------------------------------------
// Called by the picker dialog if a asset was selected
//-----------------------------------------------------------------------------
void CAttributeSurfacePropertyPickerPanel::OnPicked( KeyValues *pKeyValues )
{
	// Get the asset name back
	const char *pSurfacePropertyName = pKeyValues->GetString( "choice", NULL );
	if ( !pSurfacePropertyName || !pSurfacePropertyName[ 0 ] )
		return;

	// Apply to text panel
	m_pData->SetText( pSurfacePropertyName );
	SetDirty(true);
	if ( IsAutoApply() )
	{
		Apply();
	}
}