void CUIMpTradeWnd::StorePreset(ETradePreset idx, bool bSilent) { if(!bSilent) { string512 buff; sprintf (buff, "%s [%d]", CStringTable().translate("ui_st_preset_stored_to").c_str(), idx); SetInfoString (buff); } ITEMS_vec_cit it = m_all_items.begin(); ITEMS_vec_cit it_e = m_all_items.end(); preset_items& v = m_preset_storage[idx]; v.clear_not_free (); for(;it!=it_e; ++it) { SBuyItemInfo* iinfo = *it; if( !(iinfo->GetState()==SBuyItemInfo::e_bought || iinfo->GetState()==SBuyItemInfo::e_own) ) continue; u8 addon_state = GetItemAddonsState_ext(iinfo); preset_items::iterator fit = std::find_if(v.begin(), v.end(), preset_eq(iinfo->m_name_sect, addon_state) ); if(fit!=v.end()) continue; u32 cnt = GetItemCount(iinfo->m_name_sect, SBuyItemInfo::e_bought, addon_state); cnt +=GetItemCount(iinfo->m_name_sect, SBuyItemInfo::e_own, addon_state); if(0==cnt) continue; v.resize (v.size()+1); _preset_item& _one = v.back(); _one.sect_name = iinfo->m_name_sect; _one.count = cnt; _one.addon_state = addon_state; if(addon_state&at_scope) _one.addon_names[0] = GetAddonNameSect(iinfo, at_scope); if(addon_state&at_glauncher) _one.addon_names[1] = GetAddonNameSect(iinfo, at_glauncher); if(addon_state&at_silencer) _one.addon_names[2] = GetAddonNameSect(iinfo, at_silencer); } std::sort (v.begin(), v.end(), preset_sorter(m_item_mngr)); }
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); } }
SBuyItemInfo* CUIMpTradeWnd::DetachAddon(SBuyItemInfo* itm, item_addon_type at) { VERIFY (IsAddonAttached(itm,at)); CInventoryItem* item_ = (CInventoryItem*)itm->m_cell_item->m_pData; CWeapon* w = smart_cast<CWeapon*>(item_); R_ASSERT (w); u8 curr_addon_state = w->GetAddonsState(); curr_addon_state &= ~at; shared_str addon_name_sect = GetAddonNameSect(itm, at); w->SetAddonsState (curr_addon_state); SBuyItemInfo* detached_addon = CreateItem(addon_name_sect, SBuyItemInfo::e_own, false); return detached_addon; }
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); } } } } } }