本文整理汇总了C++中ComboBox::GetActiveItemUserData方法的典型用法代码示例。如果您正苦于以下问题:C++ ComboBox::GetActiveItemUserData方法的具体用法?C++ ComboBox::GetActiveItemUserData怎么用?C++ ComboBox::GetActiveItemUserData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComboBox
的用法示例。
在下文中一共展示了ComboBox::GetActiveItemUserData方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnTextChanged
//-----------------------------------------------------------------------------
// Purpose: Handles changes to combo boxes
//-----------------------------------------------------------------------------
void CMOMSpectatorMenu::OnTextChanged(KeyValues *data)
{
Panel *panel = reinterpret_cast<Panel *>(data->GetPtr("panel"));
ComboBox *box = dynamic_cast<ComboBox *>(panel);
if (box == m_pConfigSettings) // don't change the text in the config setting combo
{
m_pConfigSettings->SetText("#Spec_Options");
}
else if (box == m_pPlayerList)
{
KeyValues *kv = box->GetActiveItemUserData();
if (kv && GameResources())
{
const char *player = kv->GetString("player");
int currentPlayerNum = GetSpectatorTarget();
const char *currentPlayerName = GameResources()->GetPlayerName(currentPlayerNum);
if (!FStrEq(currentPlayerName, player))
{
char command[128];
Q_snprintf(command, sizeof(command), "spec_player \"%s\"", player);
engine->ClientCmd(command);
}
}
}
}
示例2: OnCommand
void CGECreateServer::OnCommand( const char *command )
{
if ( !Q_stricmp(command, "play") )
{
CUtlVector<char*> commands;
// Pull the values from our controls and apply them to commands and save off the choices
for ( KeyValues *kv = m_kvCmdMap->GetFirstTrueSubKey(); kv; kv = kv->GetNextTrueSubKey() )
{
KeyValues *kv_value = m_kvCmdValues->FindKey( kv->GetName(), true );
char *cmd = new char[128];
try {
if ( !Q_stricmp(kv->GetString("type"), "CHOICE") )
{
ComboBox *panel = dynamic_cast<ComboBox*>( FindChildByName(kv->GetName()) );
const char *cmd_value = panel->GetActiveItemUserData()->GetName();
kv_value->SetStringValue( cmd_value );
if ( !Q_stricmp(cmd_value, RANDOM_VALUE) )
{
int idx = GERandom<int>( panel->GetItemCount()-1 ) + 1;
idx = panel->GetItemIDFromRow( idx );
cmd_value = panel->GetItemUserData( idx )->GetName();
}
Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value );
commands.AddToTail( cmd );
}
else if ( !Q_stricmp(kv->GetString("type"), "TEXT") )
{
char cmd_value[64];
TextEntry *panel = dynamic_cast<TextEntry*>( FindChildByName(kv->GetName()) );
panel->GetText( cmd_value, 64 );
// We don't allow blank values... use default instead
if ( !cmd_value[0] )
Q_strncpy( cmd_value, kv->GetString("default",""), 64 );
kv_value->SetStringValue( cmd_value );
Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), cmd_value );
commands.AddToTail( cmd );
}
else if ( !Q_stricmp(kv->GetString("type"), "BOOL") )
{
CheckButton *panel = dynamic_cast<CheckButton*>( FindChildByName(kv->GetName()) );
if ( panel->IsSelected() ) {
kv_value->SetStringValue( "1" );
Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("on_val","1") );
} else {
kv_value->SetStringValue( "0" );
Q_snprintf( cmd, 128, "%s \"%s\"", kv->GetString("cmd"), kv->GetString("off_val","0") );
}
commands.AddToTail( cmd );
}
else
{
delete [] cmd;
}
} catch (...) {
delete [] cmd;
}
}
// Apply the commands
for ( int i=0; i < commands.Count(); i++ )
engine->ClientCmd_Unrestricted( commands[i] );
// Save our last used settings to our custom file
m_kvCmdValues->SaveToFile( filesystem, COMMAND_MAP_VAL, "MOD" );
// Cleanup
commands.PurgeAndDeleteElements();
}
SetVisible( false );
}