u32 CUIMpTradeWnd::GetPresetCost(ETradePreset idx) { const preset_items& v = GetPreset(idx); preset_items::const_iterator it = v.begin(); preset_items::const_iterator it_e = v.end(); u32 result = 0; for(;it!=it_e;++it) { const _preset_item& _one = *it; u32 _item_cost = m_item_mngr->GetItemCost(_one.sect_name, GetRank() ); if(_one.addon_names[0].c_str()) _item_cost += m_item_mngr->GetItemCost(_one.addon_names[0], GetRank() ); if(_one.addon_names[1].c_str()) _item_cost += m_item_mngr->GetItemCost(_one.addon_names[1], GetRank() ); if(_one.addon_names[2].c_str()) _item_cost += m_item_mngr->GetItemCost(_one.addon_names[2], GetRank() ); _item_cost *= _one.count; result += _item_cost; } return result; }
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); } } } } } }
void CUIMpTradeWnd::DumpPreset(ETradePreset idx) { const preset_items& v = GetPreset(idx); preset_items::const_iterator it = v.begin(); preset_items::const_iterator it_e = v.end(); Msg("dump preset [%d]", idx); for(;it!=it_e;++it) { const _preset_item& _one = *it; Msg("[%s]-[%d]", _one.sect_name.c_str(), _one.count); if(_one.addon_names[0].c_str()) Msg(" [%s]",_one.addon_names[0].c_str()); if(_one.addon_names[1].c_str()) Msg(" [%s]",_one.addon_names[1].c_str()); if(_one.addon_names[2].c_str()) Msg(" [%s]",_one.addon_names[2].c_str()); } }
void CUIMpTradeWnd::UpdateMoneyIndicator() { if(m_bIgnoreMoneyAndRank) { m_static_player_money->SetText ("---"); }else { u32 _cost = 0; string128 buff; sprintf_s (buff, "%d", m_money); m_static_player_money->SetText (buff); //update preset money for(u32 i=_preset_idx_last; i<=_preset_idx_3; ++i) { CUIStatic* st = m_static_preset_money[i]; _cost = GetPresetCost((ETradePreset)i); sprintf_s (buff, "%d", _cost); st->SetText (buff); bool b_has_enought_money = _cost<=GetMoneyAmount(); u32 clr = (b_has_enought_money)?m_text_color_money_positive:m_text_color_money_negative; st->SetTextColor (clr); const preset_items& v = GetPreset((ETradePreset)i); m_btns_preset[i]->Enable (b_has_enought_money && v.size()!=0); } } if( !(Device.dwFrame%30) ) { u32 _cost = 0; string128 buff; StorePreset (_preset_idx_temp, true, false, false); _cost = GetPresetCost(_preset_idx_temp); sprintf_s (buff, "%d", _cost); m_static_curr_items_money->SetText(buff); } }