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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "dme_controls/AttributeBoolChoicePanel.h"
#include "tier1/KeyValues.h"
#include "vgui_controls/ComboBox.h"
#include "datamodel/dmelement.h"
#include "movieobjects/dmeeditortypedictionary.h"
#include "datamodel/dmelementfactoryhelper.h"
#include "dme_controls/inotifyui.h"
#include "dme_controls/dmecontrols.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Expose DmeEditorAttributeInfo to the scene database
//-----------------------------------------------------------------------------
IMPLEMENT_ELEMENT_FACTORY( DmeEditorBoolChoicesInfo, CDmeEditorBoolChoicesInfo );
//-----------------------------------------------------------------------------
// Constructor, destructor
//-----------------------------------------------------------------------------
void CDmeEditorBoolChoicesInfo::OnConstruction()
{
// Add a true + false method, default
CreateChoice( "false" );
CreateChoice( "true" );
}
void CDmeEditorBoolChoicesInfo::OnDestruction()
{
}
//-----------------------------------------------------------------------------
// Add a choice
//-----------------------------------------------------------------------------
void CDmeEditorBoolChoicesInfo::SetFalseChoice( const char *pChoiceString )
{
m_Choices[0]->SetValue<CUtlString>( "string", pChoiceString );
}
void CDmeEditorBoolChoicesInfo::SetTrueChoice( const char *pChoiceString )
{
m_Choices[1]->SetValue<CUtlString>( "string", pChoiceString );
}
//-----------------------------------------------------------------------------
// Gets the choices
//-----------------------------------------------------------------------------
const char *CDmeEditorBoolChoicesInfo::GetFalseChoiceString( ) const
{
return GetChoiceString( 0 );
}
const char *CDmeEditorBoolChoicesInfo::GetTrueChoiceString( ) const
{
return GetChoiceString( 1 );
}
//-----------------------------------------------------------------------------
//
// Constructor
//
//-----------------------------------------------------------------------------
CAttributeBoolChoicePanel::CAttributeBoolChoicePanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
BaseClass( parent, info )
{
}
//-----------------------------------------------------------------------------
// Derived classes can re-implement this to fill the combo box however they like
//-----------------------------------------------------------------------------
void CAttributeBoolChoicePanel::PopulateComboBox( vgui::ComboBox *pComboBox )
{
pComboBox->DeleteAllItems();
CDmeEditorBoolChoicesInfo *pInfo = CastElement<CDmeEditorBoolChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
// Fill in the choices
const char *pFalseChoice = pInfo->GetFalseChoiceString( );
const char *pTrueChoice = pInfo->GetTrueChoiceString( );
// Add the dynamic choices next
if ( pInfo->HasChoiceType() )
{
const char *choices[2];
if ( ElementPropertiesChoices()->GetBoolChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
pFalseChoice = choices[0];
pTrueChoice = choices[1];
}
}
KeyValues *kv = new KeyValues( "entry" );
kv->SetInt( "value", false );
pComboBox->AddItem( pFalseChoice, kv );
kv = new KeyValues( "entry" );
kv->SetInt( "value", true );
pComboBox->AddItem( pTrueChoice, kv );
}
//-----------------------------------------------------------------------------
// Sets the attribute based on the combo box
//-----------------------------------------------------------------------------
void CAttributeBoolChoicePanel::SetAttributeFromComboBox( vgui::ComboBox *pComboBox, KeyValues *pKeyValues )
{
bool bOldValue = GetAttributeValue<bool>();
bool bValue = pKeyValues->GetInt( "value", 0 ) != 0;
if ( bOldValue == bValue )
return;
CUndoScopeGuard guard( NOTIFY_SOURCE_PROPERTIES_TREE, NOTIFY_SETDIRTYFLAG, "Set Attribute Value", "Set Attribute Value" );
SetAttributeValue( bValue );
}
//-----------------------------------------------------------------------------
// Sets the combo box from the attribute
//-----------------------------------------------------------------------------
void CAttributeBoolChoicePanel::SetComboBoxFromAttribute( vgui::ComboBox *pComboBox )
{
CDmeEditorBoolChoicesInfo *pInfo = CastElement<CDmeEditorBoolChoicesInfo>( GetEditorInfo() );
if ( !pInfo )
return;
bool bValue = GetAttributeValue<bool>();
// Check the dynamic choices next
if ( pInfo->HasChoiceType() )
{
const char *choices[2];
if ( ElementPropertiesChoices()->GetBoolChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
{
pComboBox->SetText( choices[ bValue ] );
return;
}
}
pComboBox->SetText( pInfo->GetChoiceString( bValue ) );
}
|