using FairyGUI; using UI.Card; using System.Collections; using UnityEngine; using System; using System.Collections.Generic; using UI.CommonGame; using ET; namespace GFGGame { public class CardUpLevelView : BaseWindow { private UI_CardUpLevelUI _ui; private EffectUI _effectUI1; private EffectUI _effectUI2; private int[] upgradeCardItemsArr = GlobalCfgArray.globalCfg.upgradeCardItemsArr; private CardData _cardData; private List itemsCount; private Dictionary _listItemChose = new Dictionary(); private List _listItemObj = new List(); private int _countCanUpMaxLevel = 0; private int _nowCountCanUpLevel = 0; private long _goldsHasNum = 0; private int _cumulativeGold = 0; public override void Dispose() { EffectUIPool.Recycle(_effectUI1); _effectUI1 = null; EffectUIPool.Recycle(_effectUI2); _effectUI2 = null; if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); _ui = UI_CardUpLevelUI.Create(); this.viewCom = _ui.target; this.viewCom.Center(); this.modal = true; viewAnimationType = EnumViewAnimationType.ZOOM_CENTER; _ui.m_btnUse.onClick.Add(OnClickBtnUse); _ui.m_btnReduce.onClick.Add(OnClickBtnReduce); _ui.m_btnAdd.onClick.Add(OnClickBtnAdd); _ui.m_list.itemRenderer = RenderListItem; _ui.m_slideUpLevel.onChanged.Add(OnChangeUpLevel); } private void OnChangeUpLevel() { float volumn = (float)_ui.m_slideUpLevel.value / 100; _nowCountCanUpLevel = _cardData.lv + (int)(volumn * (_countCanUpMaxLevel - _cardData.lv)); tidyData(_nowCountCanUpLevel); ReferViewInfo(); } private void ReferSlide() { _ui.m_slideUpLevel.value = (float)(_nowCountCanUpLevel - _cardData.lv ) / (_countCanUpMaxLevel - _cardData.lv)*100; } protected override void OnShown() { base.OnShown(); _cardData = (CardData)this.viewData; AddEffect(); ClearItemsCountList(); _ui.m_slideUpLevel.value = 0; int cfgMaxLevel = CardLvlCfgArray.Instance.GetCfgsByrarity(_cardData.itemCfg.rarity).Count - 1; tidyData(cfgMaxLevel); _countCanUpMaxLevel = _nowCountCanUpLevel; tidyData(_cardData.lv); ReferViewInfo(); } private void tidyData(int setLevel) { _nowCountCanUpLevel = 0; _goldsHasNum = 0; _cumulativeGold = 0; int CumulativeExp = 0; long needExp = 0; long allNeedLevelExp = 0; if (setLevel > 0){ for (int i = _cardData.lv; i < setLevel; i++) { allNeedLevelExp += CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, i).needExp; } needExp = allNeedLevelExp - _cardData.exp; //缺的经验值 } //先计算出可以升满的最高级别 for (int i = 0; i < upgradeCardItemsArr.Length; i++) { if (!_listItemChose.ContainsKey(i) || _listItemChose[i] == 1) { int itemId = upgradeCardItemsArr[i]; ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(itemId); int num = 0; if(setLevel> _cardData.lv) num = (int)Math.Ceiling((needExp - CumulativeExp) / (decimal)itemCfg.cardUpLvExp); //需要购买的数量 long itemNum = Math.Min(num, ItemDataManager.GetItemNum(itemId)); //物品可购买数量 int[] cardUpLvGolds = ItemCfgArray.Instance.GetCfg(upgradeCardItemsArr[i]).cardUpLvGoldsArr[_cardData.itemCfg.rarity - 1]; _goldsHasNum = ItemDataManager.GetItemNum(cardUpLvGolds[0]); int goldNum = (int)Math.Floor((_goldsHasNum - _cumulativeGold) / (decimal)cardUpLvGolds[1]);//货币可购买数量 int sumNum = (int)Math.Min(goldNum, itemNum); itemsCount[i] = sumNum; CumulativeExp = CumulativeExp + (sumNum * itemCfg.cardUpLvExp); _cumulativeGold = _cumulativeGold + (sumNum * cardUpLvGolds[1]); } } _nowCountCanUpLevel = _cardData.lv; allNeedLevelExp = _cardData.exp + CumulativeExp; for (int i = _cardData.lv; i < setLevel; i++) { int needLevelExp = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, i).needExp; allNeedLevelExp -= needLevelExp; if (allNeedLevelExp >= 0) _nowCountCanUpLevel += 1; else break; } } //清理itemsCount private void ClearItemsCountList() { if (itemsCount == null) { itemsCount = new List(); } itemsCount.Clear(); for (int i = 0; i < upgradeCardItemsArr.Length; i++) { itemsCount.Add(0); } } protected override void OnHide() { base.OnHide(); } private void AddEffect() { //边框左上角特效 _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up"); //边框右下角特效 _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down"); } private void RenderListItem(int index, GObject obj) { UI_ComItem listItem = UI_ComItem.Proxy(obj); _listItemObj.Add(obj); CardLvlCfg cardLvCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, _cardData.lv); ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(upgradeCardItemsArr[index]); listItem.m_ButtonType.selectedIndex = 4; if (!_listItemChose.ContainsKey(index)) _listItemChose.Add(index,1); listItem.m_ImgpinkGot.visible = (_listItemChose[index] != 0); listItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg); if (listItem.target.data == null) listItem.target.onClick.Add(OnListItemClick); listItem.target.data = index; listItem.m_CountType.selectedIndex = 1; listItem.m_txtDecomCount.text = itemsCount[index].ToString(); listItem.m_txtDecomHasCount.text = "/" + ItemDataManager.GetItemNum(itemCfg.id).ToString(); UI_ComItem.ProxyEnd(); } private void OnListItemClick(EventContext context) { int index = (int)(context.sender as GObject).data; UI_ComItem listItem = UI_ComItem.Proxy(_listItemObj[index]); if (_listItemChose[index] == 0) _listItemChose[index] = 1; else _listItemChose[index] = 0; listItem.m_ImgpinkGot.visible = (_listItemChose[index] != 0); UI_ComItem.ProxyEnd(); ClearItemsCountList(); tidyData(_nowCountCanUpLevel); ReferViewInfo(); ReferSlide(); } private void ReferViewInfo() { _ui.m_txtChooseLevel.SetVar("value1", _nowCountCanUpLevel.ToString()).FlushVars(); _ui.m_txtChooseLevel.SetVar("value2", _countCanUpMaxLevel.ToString()).FlushVars(); _ui.m_txtCost.SetVar("value1", _cumulativeGold.ToString()).FlushVars(); _ui.m_txtCost.SetVar("value2", _goldsHasNum.ToString()).FlushVars(); _listItemObj.Clear(); _ui.m_list.numItems = upgradeCardItemsArr.Length; } private async void OnClickBtnUse() { bool result = await CardSProxy.UpgradeCardLvl(_cardData.id, itemsCount); if (result) { this.Hide(); if (_cardData.lv - _nowCountCanUpLevel >= 1) { ViewManager.Show(new object[] { _cardData.scores, "lv", _nowCountCanUpLevel, _cardData.lv, _cardData.id }); } LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.CI_PAI, 2); } } private void OnClickBtnReduce() { _nowCountCanUpLevel -= 1; if (_nowCountCanUpLevel < _cardData.lv) _nowCountCanUpLevel = _cardData.lv; tidyData(_nowCountCanUpLevel); ReferViewInfo(); ReferSlide(); } private void OnClickBtnAdd() { _nowCountCanUpLevel += 1; if (_nowCountCanUpLevel > _countCanUpMaxLevel) _nowCountCanUpLevel = _countCanUpMaxLevel; tidyData(_nowCountCanUpLevel); ReferViewInfo(); ReferSlide(); } } }