Example #1
0
void CClient::Cmd_EditItem( CObjBase *pObj, int iSelect )
{
	ADDTOCALLSTACK("CClient::Cmd_EditItem");
	// ARGS:
	//   iSelect == -1 = setup.
	//   m_Targ_Text = what are we doing to it ?
	//
	if ( !pObj )
		return;

	CContainer *pContainer = dynamic_cast<CContainer *>(pObj);
	if ( !pContainer )
	{
		addGumpDialogProps(pObj->GetUID());
		return;
	}

	if ( iSelect == 0 )		// cancelled
		return;

	if ( iSelect > 0 )		// we selected an item
	{
		if ( static_cast<size_t>(iSelect) >= COUNTOF(m_tmMenu.m_Item) )
			return;

		if ( m_Targ_Text.IsEmpty() )
			addGumpDialogProps(m_tmMenu.m_Item[static_cast<size_t>(iSelect)]);
		else
			OnTarg_Obj_Set(CGrayUID(m_tmMenu.m_Item[static_cast<size_t>(iSelect)]).ObjFind());
		return;
	}
	
	CMenuItem item[minimum(COUNTOF(m_tmMenu.m_Item), MAX_MENU_ITEMS)];	// Most as we want to display at one time.
	item[0].m_sText.Format("Contents of %s", pObj->GetName());

	size_t count = 0;
	for ( CItem *pItem = pContainer->GetContentHead(); pItem != NULL; pItem = pItem->GetNext() )
	{
		count++;
		m_tmMenu.m_Item[count] = pItem->GetUID();
		item[count].m_sText = pItem->GetName();
		ITEMID_TYPE idi = pItem->GetDispID();
		item[count].m_id = static_cast<WORD>(idi);
		item[count].m_color = 0;

		if ( !pItem->IsType(IT_EQ_MEMORY_OBJ) )
		{
			HUE_TYPE wHue = pItem->GetHue();
			if ( wHue != 0 )
			{
				wHue = (wHue == 1 ? 0x7FF : wHue - 1);
				item[count].m_color = wHue;
			}
		}

		if ( count >= (COUNTOF(item) - 1) )
			break;
	}
	
	ASSERT(count < COUNTOF(item));
	addItemMenu(CLIMODE_MENU_EDIT, item, count, pObj);
}