CInventoryItemPtr CInventory::GetItemById(const idStr& id, const idStr& categoryName, bool createCategory) { // Do we have a specific category to search in? if (!categoryName.IsEmpty()) { // We have a category name, look it up CInventoryCategoryPtr category = GetCategory(categoryName); if (category == NULL && createCategory) { // Special case, the caller requested to create this category if not found category = CreateCategory(categoryName); } // Let the category search for the item, may return NULL return (category != NULL) ? category->GetItemById(id) : CInventoryItemPtr(); } // No specific category specified, look in all categories for (int i = 0; i < m_Category.Num(); i++) { CInventoryItemPtr foundItem = m_Category[i]->GetItemById(id); if (foundItem != NULL) { // Found the item return foundItem; } } return CInventoryItemPtr(); // nothing found }
void DialogEntityDefEditor::SetInherit( idStr &inherit ) { CWaitCursor wc; for( int i = 0; i < keyValsList.GetCount(); i++ ) { CPropertyItem *pItem = ( CPropertyItem * )keyValsList.GetItemDataPtr( i ); if( pItem ) { if( pItem->m_propName[0] == '*' ) { delete pItem; keyValsList.DeleteString( i ); i--; } } } CString spawnclass; // Fill up the rest of the box with inherited info if( !inherit.IsEmpty() ) { const idDecl *temp = declManager->FindType( DECL_ENTITYDEF, inherit, false ); const idDeclEntityDef *parent = static_cast<const idDeclEntityDef *>( temp ); if( parent ) { size_t numPairs = parent->dict.Size(); for( unsigned int i = 0; i < numPairs; i++ ) { const idKeyValue *keyVal = parent->dict.GetKeyVal( i ); if( keyVal ) { if( spawnclass.IsEmpty() && keyVal->GetKey() == "spawnclass" ) { spawnclass = keyVal->GetValue(); } else { CString key = keyVal->GetKey(); key = "*" + key; keyValsList.AddPropItem( new CPropertyItem( key, keyVal->GetValue().c_str(), PIT_EDIT, "" ) ); } } } } } }
CInventoryCategoryPtr CInventory::CreateCategory(const idStr& categoryName, int* index) { if (categoryName.IsEmpty()) return CInventoryCategoryPtr(); // empty category name // Try to lookup the category, maybe it exists already CInventoryCategoryPtr rc = GetCategory(categoryName, index); if (rc != NULL) return rc; // Category already exists // Try to allocate a new category with a link back to <this> Inventory rc = CInventoryCategoryPtr(new CInventoryCategory(this, categoryName)); // Add the new Category to our list int i = m_Category.AddUnique(rc); // Should we return an index? if (index != NULL) { *index = i; } return rc; }
void CInventory::PutItem(const CInventoryItemPtr& item, const idStr& categoryName) { if (item == NULL) return; CInventoryCategoryPtr category; // Check if it is the default group or not. if (categoryName.IsEmpty()) { // category is empty, assign the item to the default group category = m_Category[0]; } else { // Try to find the category with the given name category = GetCategory(categoryName); // If not found, create it if (category == NULL) { category = CreateCategory(categoryName); } } // Pack the item into the category category->PutItemFront(item); // Objective callback for non-loot items: // non-loot item passes in inv_name and individual item count, SuperGroupVal of 1 gameLocal.m_MissionData->InventoryCallback( item->GetItemEntity(), item->GetName(), item->GetCount(), 1, true ); }
int CInventory::GetCategoryItemIndex(const idStr& itemName, int* itemIndex) { // Set the returned index to -1 if applicable if (itemIndex != NULL) *itemIndex = -1; if (itemName.IsEmpty()) return -1; for (int i = 0; i < m_Category.Num(); i++) { // Try to find the item within the category int n = m_Category[i]->GetItemIndex(itemName); if (n != -1) { // Found, set the item index if desired if (itemIndex != NULL) *itemIndex = n; // Return the category index return i; } } return -1; // not found }
CInventoryCategoryPtr CInventory::GetCategory(const idStr& categoryName, int* index) { // If the groupname is empty we look for the default group if (categoryName.IsEmpty()) { return GetCategory(TDM_INVENTORY_DEFAULT_GROUP); } // Traverse the categories and find the one matching <CategoryName> for (int i = 0; i < m_Category.Num(); i++) { if (m_Category[i]->GetName() == categoryName) { if (index != NULL) { *index = i; } return m_Category[i]; } } return CInventoryCategoryPtr(); // not found }