summaryrefslogtreecommitdiff
path: root/vgui2/dme_controls/attributedetailtypepickerpanel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'vgui2/dme_controls/attributedetailtypepickerpanel.cpp')
-rw-r--r--vgui2/dme_controls/attributedetailtypepickerpanel.cpp88
1 files changed, 88 insertions, 0 deletions
diff --git a/vgui2/dme_controls/attributedetailtypepickerpanel.cpp b/vgui2/dme_controls/attributedetailtypepickerpanel.cpp
new file mode 100644
index 0000000..38801fb
--- /dev/null
+++ b/vgui2/dme_controls/attributedetailtypepickerpanel.cpp
@@ -0,0 +1,88 @@
+//========= Copyright Valve Corporation, All rights reserved. ============//
+//
+// Purpose:
+//
+// $NoKeywords: $
+//
+//=============================================================================//
+
+#include "dme_controls/AttributeDetailTypePickerPanel.h"
+#include "dme_controls/AttributeTextEntry.h"
+#include "tier1/KeyValues.h"
+#include "filesystem.h"
+
+
+using namespace vgui;
+
+
+const char *DETAILTYPE_FILE = "detail.vbsp";
+
+
+//-----------------------------------------------------------------------------
+// Constructor
+//-----------------------------------------------------------------------------
+CAttributeDetailTypePickerPanel::CAttributeDetailTypePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
+ BaseClass( parent, info )
+{
+}
+
+CAttributeDetailTypePickerPanel::~CAttributeDetailTypePickerPanel()
+{
+}
+
+
+//-----------------------------------------------------------------------------
+// Reads the detail types
+//-----------------------------------------------------------------------------
+void CAttributeDetailTypePickerPanel::AddDetailTypesToList( PickerList_t &list )
+{
+ KeyValues *pDetailTypes = new KeyValues( DETAILTYPE_FILE );
+ if ( pDetailTypes->LoadFromFile( g_pFullFileSystem, DETAILTYPE_FILE, "GAME" ) )
+ {
+ for ( KeyValues *sub = pDetailTypes->GetFirstTrueSubKey(); sub != NULL; sub = sub->GetNextTrueSubKey() )
+ {
+ int i = list.AddToTail( );
+ list[i].m_pChoiceString = sub->GetName();
+ list[i].m_pChoiceValue = sub->GetName();
+ }
+ }
+ else
+ {
+ Warning( "Unable to load detail prop file '%s'\n", DETAILTYPE_FILE );
+ }
+
+ pDetailTypes->deleteThis();
+}
+
+
+//-----------------------------------------------------------------------------
+// Called when it's time to show the picker
+//-----------------------------------------------------------------------------
+void CAttributeDetailTypePickerPanel::ShowPickerDialog()
+{
+ CPickerFrame *pDetailTypePickerDialog = new CPickerFrame( this, "Select Detail Type", "Detail Type", "detailTypeName" );
+ PickerList_t detailTypeList;
+ AddDetailTypesToList( detailTypeList );
+ pDetailTypePickerDialog->AddActionSignalTarget( this );
+ pDetailTypePickerDialog->DoModal( detailTypeList );
+}
+
+
+//-----------------------------------------------------------------------------
+// Called by the picker dialog if a asset was selected
+//-----------------------------------------------------------------------------
+void CAttributeDetailTypePickerPanel::OnPicked( KeyValues *pKeyValues )
+{
+ // Get the detail type name back
+ const char *pDetailTypeName = pKeyValues->GetString( "choice", NULL );
+ if ( !pDetailTypeName || !pDetailTypeName[ 0 ] )
+ return;
+
+ // Apply to text panel
+ m_pData->SetText( pDetailTypeName );
+ SetDirty(true);
+ if ( IsAutoApply() )
+ {
+ Apply();
+ }
+}