| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 | 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<int> itemsCount;        private Dictionary<int,int> _listItemChose = new Dictionary<int, int>();        private List<GObject> _listItemObj = new List<GObject>();        private int _countCanUpMaxLevel = 0;        private int _nowCountCanUpLevel = 0;        private int _oldCanUpLevel = 0;        private long _goldsHasNum = 0;        private int _cumulativeGold = 0;        private int _cfgMaxLevel = 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);        }        protected override void OnShown()        {            base.OnShown();            //防止引导检测之前触发点击事件            GRoot.inst.touchable = false;            _cardData = (CardData)this.viewData;            AddEffect();            ClearItemsCountList();            _oldCanUpLevel = _cardData.lv;                        _cfgMaxLevel = CardLvlCfgArray.Instance.GetCfgsByrarity(_cardData.itemCfg.rarity).Count;            tidyData(_cfgMaxLevel, "Max");            _ui.m_slideUpLevel.value = 100;            tidyData(_countCanUpMaxLevel);  //  _cardData.lv              ReferViewInfo();            Timers.inst.AddUpdate(CheckGuide);        }        private void tidyData(int setLevel,string tidyType = "")        {            _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++)            {                int[] cardUpLvGolds = ItemCfgArray.Instance.GetCfg(upgradeCardItemsArr[i]).cardUpLvGoldsArr[_cardData.itemCfg.rarity - 1];                _goldsHasNum = ItemDataManager.GetItemNum(cardUpLvGolds[0]);                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 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]);                }            }            if(tidyType == "Max")                _countCanUpMaxLevel = _cardData.lv;            else                _nowCountCanUpLevel = _cardData.lv;            allNeedLevelExp = _cardData.exp + CumulativeExp;            int lvLimit = RoleLevelCfgArray.Instance.GetCfg(RoleDataManager.lvl).cardLeverLimit;            for (int i = _cardData.lv; i < setLevel; i++)            {                int needLevelExp = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, i).needExp;                allNeedLevelExp -= needLevelExp;                if (allNeedLevelExp >= 0)                {                    if (tidyType == "Max") {                         if (_countCanUpMaxLevel < lvLimit)                            _countCanUpMaxLevel += 1;                    }                    else {                        if (_nowCountCanUpLevel < lvLimit)                             _nowCountCanUpLevel += 1;                    }                }                else                    break;            }        }        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;        }        //清理itemsCount        private void ClearItemsCountList()        {            if (itemsCount == null)            {                itemsCount = new List<int>();            }            itemsCount.Clear();            for (int i = 0; i < upgradeCardItemsArr.Length; i++)            {                itemsCount.Add(0);            }        }        protected override void OnHide()        {            GRoot.inst.touchable = true;            base.OnHide();            Timers.inst.Remove(CheckGuide);        }        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(_cfgMaxLevel, "Max");            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 - _oldCanUpLevel >= 1)                {                    ViewManager.Show<CardUpView>(new object[] { _cardData.scores, "lv", _oldCanUpLevel, _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();        }        private void CheckGuide(object param)        {            GRoot.inst.touchable = true;            if (GuideDataManager.IsGuideFinish(ConstGuideId.UP_CARD_LV) <= 0)            {                UpdateToCheckGuide(null);            }            else            {                Timers.inst.Remove(CheckGuide);            }        }        protected override void UpdateToCheckGuide(object param)        {            if (!ViewManager.CheckIsTopView(this.viewCom)) return;            GuideController.TryGuide(_ui.m_btnUse, ConstGuideId.UP_CARD_LV, 5, "");        }    }}
 |