//----------------------------------------------------------------------------- // Purpose: Create a new control in the context panel // Input: name: class name of control to create // controlKeys: keyvalues of settings for the panel. // name OR controlKeys should be set, not both. // x,y position relative to base panel // Output: Panel *newPanel, NULL if failed to create new control. //----------------------------------------------------------------------------- Panel *BuildGroup::NewControl( const char *name, int x, int y) { Assert (name); Panel *newPanel = NULL; // returns NULL on failure newPanel = static_cast<EditablePanel *>(m_pParentPanel)->CreateControlByName(name); if (newPanel) { // panel successfully created newPanel->SetParent(m_pParentPanel); newPanel->SetBuildGroup(this); newPanel->SetPos(x, y); char newFieldName[255]; GetNewFieldName(newFieldName, sizeof(newFieldName), newPanel); newPanel->SetName(newFieldName); newPanel->AddActionSignalTarget(m_pParentPanel); newPanel->SetBuildModeEditable(true); newPanel->SetBuildModeDeletable(true); // make sure it gets freed newPanel->SetAutoDelete(true); } return newPanel; }
//----------------------------------------------------------------------------- // Purpose: Create a new control in the context panel // Input: controlKeys: keyvalues of settings for the panel only works when applying initial settings. // Output: Panel *newPanel, NULL if failed to create new control. //----------------------------------------------------------------------------- Panel *BuildGroup::NewControl( KeyValues *controlKeys, int x, int y) { Assert (controlKeys); Panel *newPanel = nullptr; if (controlKeys) { // Warning( "Creating new control \"%s\" of type \"%s\"\n", controlKeys->GetString( "fieldName" ), controlKeys->GetString( "ControlName" ) ); KeyValues *keyVal = new KeyValues("ControlFactory", "ControlName", controlKeys->GetString("ControlName")); m_pBuildContext->RequestInfo(keyVal); // returns NULL on failure newPanel = (Panel *)keyVal->GetPtr("PanelPtr"); keyVal->deleteThis(); } else { return nullptr; } if (newPanel) { // panel successfully created newPanel->SetParent(m_pParentPanel); newPanel->SetBuildGroup(this); newPanel->SetPos(x, y); newPanel->SetName(controlKeys->GetName()); // name before applysettings :) newPanel->ApplySettings(controlKeys); newPanel->AddActionSignalTarget(m_pParentPanel); newPanel->SetBuildModeEditable(true); newPanel->SetBuildModeDeletable(true); // make sure it gets freed newPanel->SetAutoDelete(true); } return newPanel; }