123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- 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 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;
- //UI_UpLevelSlide slider1 = UI_UpLevelSlide.Proxy(_ui.m_slideUpLevel);
- //slider1.m_progressBar.fillAmount = volumn;
- ////tidyData(_nowCountCanUpLevel);
- ////ReferViewInfo();
- //UI_UpLevelSlide.ProxyEnd();
- }
- protected override void OnShown()
- {
- base.OnShown();
- _cardData = (CardData)this.viewData;
- AddEffect();
- ClearItemsCountList();
-
- 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;
- int needExp = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, setLevel).needExp; //需要升级到的经验值
- needExp = needExp - _cardData.exp; //缺的经验值
-
- //先计算出可以升满的最高级别
- for (int i = 0; i < upgradeCardItemsArr.Length; i++)
- {
- 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;
- for (int i = _cardData.lv; i < setLevel; i++)
- {
- int needLevelExp = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, i).needExp;
- if (_cardData.exp + CumulativeExp >= needLevelExp)
- _nowCountCanUpLevel += 1;
- else
- break;
- }
- }
- //清理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()
- {
- 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);
- CardLvlCfg cardLvCfg = CardLvlCfgArray.Instance.GetCfgByrarityAndcardLvl(_cardData.itemCfg.rarity, _cardData.lv);
- ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(upgradeCardItemsArr[index]);
- listItem.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
- 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 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();
- _ui.m_list.numItems = upgradeCardItemsArr.Length;
- }
- private async void OnClickBtnUse()
- {
- bool result = await CardSProxy.UpgradeCardLvl(_cardData.id, itemsCount);
- if (result)
- {
- this.Hide();
- LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.CI_PAI, 2);
- }
- }
- private void OnClickBtnReduce()
- {
- _nowCountCanUpLevel -= 1;
- if (_nowCountCanUpLevel < _cardData.lv)
- _nowCountCanUpLevel = _cardData.lv;
- tidyData(_nowCountCanUpLevel);
- ReferViewInfo();
- }
- private void OnClickBtnAdd()
- {
- _nowCountCanUpLevel += 1;
- if (_nowCountCanUpLevel > _countCanUpMaxLevel)
- _nowCountCanUpLevel = _countCanUpMaxLevel;
- tidyData(_nowCountCanUpLevel);
- ReferViewInfo();
- }
- }
- }
|