Пример #1
0
void CUIMpTradeWnd::ResetToOrigin()
{
	// 1-sell all bought items
	// 2-buy all sold items
	
	SBuyItemInfo*	iinfo		= NULL;
	SBuyItemInfo*	tmp_iinfo	= NULL;
	bool			b_ok		= true;

	DeleteHelperItems	();

	do{
		iinfo			= FindItem(SBuyItemInfo::e_bought);
		if(iinfo)
			b_ok		= TryToSellItem(iinfo, true, tmp_iinfo);

		R_ASSERT		(b_ok);
	}while(iinfo);
	
	do{
		iinfo			= FindItem(SBuyItemInfo::e_sold);
		if(iinfo)
			b_ok		= TryToBuyItem(iinfo, bf_normal, NULL);

		R_ASSERT		(b_ok);
	}while(iinfo);
}
Пример #2
0
void CUIMpTradeWnd::ResetToOrigin()
{
	Msg("--ResetToOrigin");
	// 1-sell all bought items
	// 2-buy all sold items
	
	ITEMS_vec_cit it;

	SBuyItemInfo*	iinfo		= NULL;
	SBuyItemInfo*	tmp_iinfo	= NULL;
	bool			b_ok		= true;

	do{
		iinfo			= FindItem(SBuyItemInfo::e_bought);
		if(iinfo)
			b_ok		= TryToSellItem(iinfo, true, tmp_iinfo);

		R_ASSERT		(b_ok);
	}while(iinfo);
	
	do{
		iinfo			= FindItem(SBuyItemInfo::e_sold);
		if(iinfo)
			b_ok		= TryToBuyItem(iinfo, bf_normal, NULL);

		R_ASSERT		(b_ok);
	}while(iinfo);
}
Пример #3
0
void CUIMpTradeWnd::CreateHelperItems (CUIDragDropListEx* list, const CStoreHierarchy::item* shop_level)
{
	for ( xr_vector<shared_str>::const_iterator	
										it		=	shop_level->m_items_in_group.begin();
										it	   !=	shop_level->m_items_in_group.end();
										++it )
	{
		shared_str item_name					=	*it;
		CUIDragDropListEx*	match_list			=	GetMatchedListForItem(item_name);

		if ( match_list == list )
		{
			SBuyItemInfo*	new_item			=	CreateItem(item_name, SBuyItemInfo::e_undefined, false);

			CUIInventoryCellItem* inventory_cell_item;
			if ( (inventory_cell_item = dynamic_cast<CUIInventoryCellItem*>(new_item->m_cell_item)) != NULL )
			{
				inventory_cell_item->SetIsHelper(true);
				inventory_cell_item->UpdateItemText();

				TryToBuyItem						(new_item, bf_normal, NULL);
			}
		}
	}

	for ( u32								i	=	0; 
											i	<	shop_level->ChildCount(); 
										  ++i )
	{
		const CStoreHierarchy::item* child		=	&shop_level->ChildAtIdx(i);
		CreateHelperItems							(list, child);
	}
}
Пример #4
0
void CUIMpTradeWnd::OnBtnRifleSilencerClicked(CUIWindow* w, void* d)
{
	CheckDragItemToDestroy				();
	CUIDragDropListEx*	res			= m_list[e_rifle];
	CUICellItem* ci					= (res->ItemsCount())?res->GetItemIdx(0):NULL;
	if(!ci)	
		return;

	SBuyItemInfo* pitem				= FindItem(ci);
	if(IsAddonAttached(pitem, at_silencer))
	{//detach
		SellItemAddons				(pitem,at_silencer);
	}else
	if(CanAttachAddon(pitem, at_silencer))
	{//attach
		shared_str addon_name		= GetAddonNameSect(pitem,at_silencer);

		if ( NULL==m_store_hierarchy->FindItem(addon_name) )
			return;
						
		SBuyItemInfo* addon_item	= CreateItem(addon_name, SBuyItemInfo::e_undefined, false);
		bool b_res_addon			= TryToBuyItem(addon_item, bf_normal, pitem );
		if(!b_res_addon)
			DestroyItem				(addon_item);
	}
}
Пример #5
0
void CUIMpTradeWnd::OnBtnPistolAmmoClicked(CUIWindow* w, void* d)
{
	CheckDragItemToDestroy				();
	CUIDragDropListEx*	res		= m_list[e_pistol];
	CUICellItem* ci				= (res->ItemsCount())?res->GetItemIdx(0):NULL;
	if(!ci)	
		return;

	CInventoryItem* ii			= (CInventoryItem*)ci->m_pData;
	CWeapon*		wpn			= smart_cast<CWeapon*>(ii);
	R_ASSERT		(wpn);

	u32 ammo_idx				= (pInput->iGetAsyncKeyState(DIK_LSHIFT))?1:0;
	
	if(wpn->m_ammoTypes.size() < ammo_idx+1)	return;
	const shared_str& ammo_name	= wpn->m_ammoTypes[ammo_idx];

	if ( NULL==m_store_hierarchy->FindItem(ammo_name) )
		return;

	SBuyItemInfo* pitem			= CreateItem		(ammo_name, SBuyItemInfo::e_undefined, false);
	bool b_res					= TryToBuyItem		(pitem, bf_normal, NULL );
	if(!b_res)
		DestroyItem				(pitem);
}
Пример #6
0
void CUIMpTradeWnd::OnBtnRifleAmmo2Clicked(CUIWindow* w, void* d)
{
	CheckDragItemToDestroy				();
	CUIDragDropListEx*	res		= m_list[e_rifle];
	CUICellItem* ci				= (res->ItemsCount())?res->GetItemIdx(0):NULL;
	if(!ci)	
		return;

	CInventoryItem* ii			= (CInventoryItem*)ci->m_pData;
	CWeaponMagazinedWGrenade* wpn = smart_cast<CWeaponMagazinedWGrenade*>(ii);
	if(!wpn)		
		return;

	u32 ammo_idx				= 0;
	
	const shared_str& ammo_name	= wpn->m_ammoTypes2[ammo_idx];

	if ( NULL==m_store_hierarchy->FindItem(ammo_name) )
		return;

	SBuyItemInfo* pitem			= CreateItem		(ammo_name, SBuyItemInfo::e_undefined, false);
	bool b_res					= TryToBuyItem		(pitem, bf_normal, NULL);
	if(!b_res)
		DestroyItem				(pitem);
}
Пример #7
0
void CUIMpTradeWnd::ApplyPreset(ETradePreset idx)
{
	Msg("--ApplyPreset [%d]",idx);

	SellAll								();

	const preset_items&		v			=  GetPreset(idx);
	preset_items::const_iterator it		= v.begin();
	preset_items::const_iterator it_e	= v.end();

	for(;it!=it_e;++it)
	{
		const _preset_item& _one		= *it;
		u32 _cnt						= GetItemCount(_one.sect_name, SBuyItemInfo::e_own);
		for(u32 i=_cnt; i<_one.count; ++i)
		{
			SBuyItemInfo* pitem				= CreateItem(_one.sect_name, SBuyItemInfo::e_undefined, false);

			bool b_res						= TryToBuyItem(pitem, bf_normal, NULL );
			if(!b_res)
			{
				DestroyItem					(pitem);
			}else
			{
				if(_one.addon_state)
				{
					for(u32 i=0; i<3; ++i)
					{
						item_addon_type at		= (i==0)?at_scope : ((i==1)?at_glauncher : at_silencer);
						
						if(!(_one.addon_state&at) )	
							continue;

						shared_str addon_name	= GetAddonNameSect(pitem, at);
						
						SBuyItemInfo* addon_item = CreateItem(addon_name, SBuyItemInfo::e_undefined, false);
						bool b_res_addon		 = TryToBuyItem(addon_item, /*(idx==_preset_idx_origin)?bf_own_item:*/bf_normal, pitem );
						if(!b_res_addon)
							DestroyItem			(addon_item);
					}
				}
			}
		}
	}
}
Пример #8
0
void CUIMpTradeWnd::CreateHelperItems (xr_vector<shared_str>& ammo_types)
{
	for ( xr_vector<shared_str>::iterator it	=	ammo_types.begin(); 
										  it   !=	ammo_types.end();
										++it )
	{
		const shared_str&	ammo_name			=	*it;
		if ( !m_store_hierarchy->FindItem			(ammo_name) )
		{
			continue;
		}

		SBuyItemInfo*		ammo_item			=	CreateItem(ammo_name, SBuyItemInfo::e_undefined, false);
		ammo_item->m_cell_item->SetIsHelper			(true);
		TryToBuyItem								(ammo_item, bf_normal, NULL);
	}
}
Пример #9
0
bool CUIMpTradeWnd::OnItemLButtonClick(CUICellItem* itm)
{
	CUIDragDropListEx*	owner_list		=	itm->OwnerList();
	SBuyItemInfo*		iinfo 			=	FindItem(itm);

	if ( !CanBuyOrSellInList(owner_list) )
	{
		return								false;
	}	

	const shared_str&	buy_item_name	=	 iinfo->m_name_sect;

	SBuyItemInfo* pitem					=	CreateItem(buy_item_name, SBuyItemInfo::e_undefined, false);
	bool b_res							=	TryToBuyItem(pitem, bf_normal, NULL );
	if( !b_res )
	{
		DestroyItem							(pitem);
	}

	return									true;
}