using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
using LitJson;
|
using System.Collections;
|
|
namespace vnxbqy.UI
|
{
|
public class EquipDevourWin : Window
|
{
|
[SerializeField] ScrollerController gridCtrl;
|
[SerializeField] Button devourBtn;
|
[SerializeField] Button equipColorSelectBtn;
|
[SerializeField] Text equipColorText;
|
[SerializeField] GameObject colorlistObj;
|
[SerializeField] ClickScreenOtherSpace colorSpaceClick;
|
|
[SerializeField] UIEffect equipDevourEffect;
|
[Header("颜色选择列表")]
|
[SerializeField] List<EquipColorSelect> colorSelectlist = new List<EquipColorSelect>();
|
|
[Header("分解装备属性")]
|
[SerializeField] Text decomLvText;
|
[SerializeField] List<GameObject> decomAttrlist = new List<GameObject>();
|
[SerializeField] List<Text> decomAttrNamelist = new List<Text>();
|
[SerializeField] List<Text> decomAttrValuelist = new List<Text>();
|
[SerializeField] List<Text> decomAttrPreviewlist = new List<Text>();
|
[SerializeField] IntensifySmoothSlider expSlider;
|
[SerializeField] Text expNumText;
|
[SerializeField] UIEffect decomEffect;
|
[SerializeField] Button getMatBtn;
|
[SerializeField] Image getMatBgImg;
|
[SerializeField] Image getMatIcon;
|
[SerializeField] Text getMatProgressText;
|
[SerializeField] ButtonEx gotoShenfj;
|
[SerializeField] ItemCell devItemCell;
|
[SerializeField] ItemCell devItemCell2;
|
|
[SerializeField] int singleLineNum = 5;
|
[SerializeField] int sumGridNum = 100;
|
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
List<ItemModel> devourModellist;
|
bool isOpen = true;
|
int getMatCycle = 0;
|
int devItemID;//分解装备获得的材料ID
|
int devItemID2;//红装分解装备获得的材料ID
|
string devourFormula; //分解公式
|
string devourFormula2; //红装分解公式
|
int preViewDevItemCnt; //分解获得的材料数量
|
int preViewDevItemCnt2; //红装分解获得的材料数量
|
protected override void BindController()
|
{
|
colorlistObj.SetActive(true);
|
gridCtrl.OnRefreshCell += RefreshGridCell;
|
}
|
|
protected override void AddListeners()
|
{
|
equipColorSelectBtn.AddListener(ClickColorSelectBtn);
|
devourBtn.AddListener(ClickEquipDecomBtn);
|
colorSpaceClick.AddListener(ClickColorSelectBtn);
|
gotoShenfj.AddListener(() =>
|
{
|
WindowCenter.Instance.Open("EquipShenDecomposeWin");
|
});
|
}
|
|
protected override void OnPreOpen()
|
{
|
if (getMatCycle == 0)
|
{
|
var config = FuncConfigConfig.Get("EquipDecomposeAward");
|
getMatCycle = int.Parse(config.Numerical1);
|
devItemID = int.Parse(config.Numerical4);
|
devourFormula = config.Numerical5;
|
|
//{"5":[3017,"1+itemClass"]}
|
var json = JsonMapper.ToObject(FuncConfigConfig.Get("EquipDecomposeAward2").Numerical1);
|
devItemID2 = int.Parse(json["5"][0].ToString());
|
devourFormula2 = json["5"][1].ToString();
|
}
|
isOpen = true;
|
playerPack.selectDevourlist.Clear();
|
devourModellist = playerPack.GetDevourModellist();
|
|
}
|
|
protected override void OnAfterOpen()
|
{
|
InitUI();
|
this.transform.SetAsLastSibling();
|
|
OnRefreshColor(playerPack.colorType);
|
StartCoroutine(SetJumpIndex(0));
|
|
playerPack.RefreshColorSelectAct += OnRefreshColor;
|
playerPack.itemCntAddEvent += RefreshAddItem;
|
playerPack.itemCntReduceEvent += RefreshReduceItem;
|
playerPack.refrechPackEvent += OnRefreshPack;
|
playerPack.RefreshDecomAttrAct += RefreshDecomAttr;
|
equipDevourEffect.OnComplete += OnCompleteEvent;
|
playerPack.RefreshEquipDecomNumAct += RefreshDecomPreviewAttr;
|
GlobalTimeEvent.Instance.secondEvent += CheckRefreshScroller;
|
}
|
|
protected override void OnPreClose()
|
{
|
equipDevourEffect.OnComplete -= OnCompleteEvent;
|
playerPack.RefreshColorSelectAct -= OnRefreshColor;
|
playerPack.itemCntAddEvent -= RefreshAddItem;
|
playerPack.itemCntReduceEvent -= RefreshReduceItem;
|
playerPack.refrechPackEvent -= OnRefreshPack;
|
playerPack.RefreshDecomAttrAct -= RefreshDecomAttr;
|
playerPack.RefreshEquipDecomNumAct -= RefreshDecomPreviewAttr;
|
GlobalTimeEvent.Instance.secondEvent -= CheckRefreshScroller;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
protected override void OnActived()
|
{
|
base.OnActived();
|
colorlistObj.SetActive(false);
|
}
|
|
private void InitUI()
|
{
|
sumGridNum = Math.Max(100, (int)(devourModellist.Count * 1.5));
|
playerPack.GetSelectDevourList();
|
CreateCell();
|
isOpen = false;
|
RefreshDecomposeAttr();
|
RefreshDecomPreviewAttr();
|
ItemConfig getMatConfig = ItemConfig.Get(2125);
|
if (getMatConfig != null)
|
{
|
getMatBgImg.SetItemBackGround(getMatConfig.ItemColor);
|
getMatIcon.SetSprite(getMatConfig.IconKey);
|
getMatBtn.RemoveAllListeners();
|
getMatBtn.AddListener(() =>
|
{
|
ItemTipUtility.Show(getMatConfig.ID);
|
});
|
}
|
RefreshGeMatProgress();
|
}
|
|
IEnumerator SetJumpIndex(int index)
|
{
|
yield return null;
|
gridCtrl.JumpIndex(index);
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
private void RefreshGeMatProgress()
|
{
|
getMatProgressText.text = Language.Get("EquipDevour_Text5", StringUtility.Contact(playerPack.decomposeProgress, "/", getMatCycle));
|
}
|
|
private void RefreshAddItem(PackType type, int index, int id)
|
{
|
ItemConfig itemConfig = ItemConfig.Get(id);
|
if (type != PackType.Item || (type == PackType.Item && itemConfig.Type != 29 && itemConfig.EquipPlace <= 0)) return;
|
|
devourModellist = playerPack.GetDevourModellist();
|
ItemModel itemModel = playerPack.GetItemByIndex(type, index);
|
playerPack.RefreshGetNewItem(itemModel);
|
//gridCtrl.m_Scorller.RefreshActiveCellViews();
|
m_RefreshScroller = true;
|
}
|
|
private void RefreshReduceItem(PackType type, int index, int id)
|
{
|
ItemConfig itemConfig = ItemConfig.Get(id);
|
if (type != PackType.Item || (type == PackType.Item && itemConfig.Type != 29 && itemConfig.EquipPlace <= 0)) return;
|
|
devourModellist = playerPack.GetDevourModellist();
|
ItemModel itemModel = playerPack.GetItemByIndex(type, index);
|
if (itemModel == null)
|
{
|
for (int i = 0; i < playerPack.selectDevourlist.Count; i++)
|
{
|
if (playerPack.selectDevourlist[i].gridIndex == index)
|
{
|
playerPack.selectDevourlist.RemoveAt(i);
|
break;
|
}
|
}
|
}
|
|
//gridCtrl.m_Scorller.RefreshActiveCellViews();
|
m_RefreshScroller = true;
|
}
|
|
bool m_RefreshScroller = false;
|
void CheckRefreshScroller()
|
{
|
if (m_RefreshScroller)
|
{
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
m_RefreshScroller = false;
|
}
|
}
|
|
private void OnRefreshPack(PackType type)
|
{
|
if (type != PackType.Item) return;
|
playerPack.selectDevourlist.Clear();
|
devourModellist = playerPack.GetDevourModellist();
|
playerPack.GetSelectDevourList();
|
//gridCtrl.m_Scorller.RefreshActiveCellViews();
|
m_RefreshScroller = true;
|
RefreshDecomposeAttr();
|
RefreshDecomPreviewAttr();
|
RefreshGeMatProgress();
|
}
|
|
private void OnRefreshColor(PackModel.EquipColorType type)
|
{
|
for (int i = 0; i < colorSelectlist.Count; i++)
|
{
|
if (colorSelectlist[i].colorType == type)
|
{
|
equipColorText.text = colorSelectlist[i].colorText.text;
|
equipColorText.color = colorSelectlist[i].colorText.color;
|
break;
|
}
|
}
|
if (!isOpen)
|
{
|
colorlistObj.SetActive(false);
|
playerPack.GetSelectDevourList();
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
RefreshDecomposeAttr();
|
RefreshDecomPreviewAttr();
|
RefreshGeMatProgress();
|
}
|
}
|
|
private void CreateCell()
|
{
|
gridCtrl.Refresh();
|
int line = sumGridNum / singleLineNum;
|
for (int i = 0; i < line; i++)
|
{
|
gridCtrl.AddCell(ScrollerDataType.Header, i);
|
}
|
gridCtrl.Restart();
|
}
|
|
private void RefreshGridCell(ScrollerDataType type, CellView cell)
|
{
|
int childLength = cell.transform.childCount;
|
for (int i = 0; i < childLength; i++)
|
{
|
int cellCnt = cell.index * singleLineNum + (i + 1);
|
DevourGridCell gridCell = cell.transform.GetChild(i).GetComponent<DevourGridCell>();
|
if (devourModellist != null)
|
{
|
if (cellCnt <= devourModellist.Count)
|
{
|
ItemModel itemModel = devourModellist[cellCnt - 1];
|
gridCell.SetModel(itemModel);
|
}
|
else
|
{
|
gridCell.SetModel(null);
|
}
|
}
|
else
|
{
|
gridCell.SetModel(null);
|
}
|
}
|
}
|
|
private void ClickColorSelectBtn()
|
{
|
if (colorlistObj.activeInHierarchy)
|
{
|
colorlistObj.SetActive(false);
|
}
|
else
|
{
|
colorlistObj.SetActive(true);
|
}
|
}
|
|
#region 分解属性预览
|
|
private void RefreshDecomAttr()
|
{
|
RefreshDecomposeAttr(true);
|
devourModellist = playerPack.GetDevourModellist();
|
playerPack.GetSelectDevourList();
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
RefreshGeMatProgress();
|
RefreshDecomPreviewAttr();
|
if (playerPack.getItems != null && playerPack.getItems.Length > 0)
|
{
|
WindowCenter.Instance.Open<DecomposeGetItemWin>();
|
}
|
}
|
|
void RefreshDecomposeAttr(bool isRefresh = false)
|
{
|
decomLvText.text = playerPack.decomposeLv.ToString();
|
EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(playerPack.decomposeLv);
|
expNumText.text = StringUtility.Contact(playerPack.decomposeExp, "/", deComposeConfig.UpNeedExp);
|
if (!isRefresh)
|
{
|
expSlider.delay = 0;
|
expSlider.ResetStage();
|
}
|
else
|
{
|
expSlider.delay = 0.1f;
|
|
}
|
expSlider.stage = playerPack.decomposeLv;
|
expSlider.value = (float)Math.Round((double)playerPack.decomposeExp / deComposeConfig.UpNeedExp, 2, MidpointRounding.AwayFromZero);//经验条的初始化和刷新
|
var attrDict = playerPack.GetDecomAttrDictByLv(playerPack.decomposeLv);
|
List<int> attrIdlist = null;
|
List<int> attrValuelist = null;
|
if (attrDict != null)
|
{
|
attrIdlist = attrDict.Keys.ToList();
|
attrValuelist = attrDict.Values.ToList();
|
}
|
for (int i = 0; i < decomAttrlist.Count; i++)
|
{
|
if (attrIdlist != null)
|
{
|
if (i < attrIdlist.Count)
|
{
|
decomAttrlist[i].SetActive(true);
|
decomAttrPreviewlist[i].SetActive(false);
|
PlayerPropertyConfig propertyConfig = PlayerPropertyConfig.Get(attrIdlist[i]);
|
decomAttrNamelist[i].text = StringUtility.Contact(propertyConfig.Name, ":");
|
decomAttrValuelist[i].text = attrValuelist[i].ToString();
|
|
}
|
else
|
{
|
decomAttrlist[i].SetActive(false);
|
}
|
}
|
else
|
{
|
decomAttrlist[i].SetActive(false);
|
}
|
}
|
}
|
|
int equipAddExpPreview = 0;
|
void RefreshDecomPreviewAttr()
|
{
|
equipAddExpPreview = 0;
|
EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(playerPack.decomposeLv);
|
devItemCell.SetActive(false);
|
devItemCell2.SetActive(false);
|
if (playerPack.selectDevourlist.Count > 0)
|
{
|
equipAddExpPreview = GetPreviewExpByDevour();
|
var previewLv = GetPreviewDecomposeLv(playerPack.decomposeLv, 0);
|
var attrDict = playerPack.GetDecomAttrDictByLv(playerPack.decomposeLv);
|
var attrPreviewDict = playerPack.GetDecomAttrDictByLv(previewLv);
|
if (attrDict != null)
|
{
|
int i = 0;
|
foreach (var id in attrDict.Keys)
|
{
|
if (attrPreviewDict != null)
|
{
|
if (attrPreviewDict.ContainsKey(id))
|
{
|
decomAttrPreviewlist[i].SetActive(true);
|
int addAttr = attrPreviewDict[id] - attrDict[id];
|
decomAttrPreviewlist[i].text = StringUtility.Contact("+", addAttr);
|
}
|
}
|
i += 1;
|
}
|
}
|
string previewExp = StringUtility.Contact(playerPack.decomposeExp, "+", equipAddExpPreview);
|
expNumText.text = StringUtility.Contact(UIHelper.AppendColor(TextColType.Green, previewExp, true), "/" + deComposeConfig.UpNeedExp);
|
if (preViewDevItemCnt != 0)
|
{
|
devItemCell.SetActive(true);
|
devItemCell.Init(new ItemCellModel(devItemID, false, (ulong)preViewDevItemCnt));
|
devItemCell.button.AddListener(() => {
|
ItemTipUtility.Show(devItemID);
|
});
|
}
|
|
if (preViewDevItemCnt2 != 0)
|
{
|
devItemCell2.SetActive(true);
|
devItemCell2.Init(new ItemCellModel(devItemID2, false, (ulong)preViewDevItemCnt2));
|
devItemCell2.button.AddListener(() => {
|
ItemTipUtility.Show(devItemID2);
|
});
|
}
|
}
|
else
|
{
|
RefreshDecomposeAttr();
|
}
|
}
|
|
public int GetPreviewDecomposeLv(int decomLv, int sumNeedExp)
|
{
|
EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(decomLv);
|
if (!playerPack.IsMaxDecomLv(decomLv, out decomLv))
|
{
|
if (decomLv == playerPack.decomposeLv)
|
{
|
sumNeedExp += deComposeConfig.UpNeedExp - playerPack.decomposeExp;
|
}
|
else
|
{
|
sumNeedExp += deComposeConfig.UpNeedExp;
|
}
|
|
if (equipAddExpPreview > sumNeedExp)
|
{
|
decomLv += 1;
|
return GetPreviewDecomposeLv(decomLv, sumNeedExp);
|
}
|
}
|
return decomLv;
|
}
|
#endregion
|
|
private void ClickEquipDecomBtn()
|
{
|
if (playerPack.selectDevourlist.Count <= 0)
|
{
|
SysNotifyMgr.Instance.ShowTip("EquipDevour_Text_1");
|
return;
|
}
|
|
var betterEquipCount = GetBetterEquipCount(playerPack.selectDevourlist);
|
if (betterEquipCount > 0)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipResolve_Text_1", betterEquipCount),
|
(bool ok) =>
|
{
|
if (ok)
|
{
|
equipDevourEffect.Play();
|
playerPack.SendEquipdevourQuest(false);
|
}
|
});
|
}
|
else
|
{
|
equipDevourEffect.Play();
|
playerPack.SendEquipdevourQuest(false);
|
}
|
|
}
|
|
private void OnCompleteEvent()
|
{
|
decomEffect.Play();
|
}
|
|
int GetBetterEquipCount(List<ItemModel> itemModels)
|
{
|
if (itemModels.IsNullOrEmpty())
|
{
|
return 0;
|
}
|
|
var count = 0;
|
foreach (var item in itemModels)
|
{
|
if (item.isAuction || ItemLogicUtility.Instance.IsFightUp(item.itemId, item.score) == 1)
|
{
|
count += item.count;
|
}
|
|
}
|
return count;
|
}
|
|
|
int GetPreviewExpByDevour()
|
{
|
int sumExp = 0;
|
preViewDevItemCnt = 0;
|
preViewDevItemCnt2 = 0;
|
for (int i = 0; i < playerPack.selectDevourlist.Count; i++)
|
{
|
int curExp = 0;
|
ItemModel itemModel = playerPack.selectDevourlist[i];
|
if (itemModel.config.EquipPlace == 0)
|
{
|
curExp = itemModel.count * itemModel.config.EffectValueA1;
|
}
|
else
|
{
|
var tagPet = PetEatEquipConfig.GetEquipColorAndEquipClass(itemModel.config.ItemColor, itemModel.config.LV);
|
if (tagPet != null)
|
{
|
curExp = tagPet.Exp;
|
}
|
preViewDevItemCnt += GetDogzScoreById(itemModel);
|
preViewDevItemCnt2 += GetRedEquipDevourItemCnt(itemModel);
|
}
|
sumExp += curExp;
|
}
|
|
int vipLv = PlayerDatas.Instance.baseData.VIPLv;
|
if (vipLv != 0)
|
{
|
int ExpUp = ModelCenter.Instance.GetModel<VipModel>().GetVipPrivilegeCnt(VipPrivilegeType.Minion);
|
float percent = (float)Math.Round((double)ExpUp / 10000, 2);
|
sumExp += Mathf.FloorToInt(sumExp * (float)percent);
|
}
|
return sumExp;
|
}
|
|
|
public int GetDogzScoreById(ItemModel itemModel)
|
{
|
if (itemModel == null)
|
return 0;
|
if (itemModel.config.ItemColor < 4)
|
return 0;
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("itemColor", itemModel.config.ItemColor);
|
Equation.Instance.AddKeyValue("isSuite", itemModel.config.SuiteiD == 0 ? 0 : 1);
|
Equation.Instance.AddKeyValue("itemClass", itemModel.config.LV);
|
return Equation.Instance.Eval<int>(devourFormula);
|
}
|
|
//红装分解可获得的材料数量
|
public int GetRedEquipDevourItemCnt(ItemModel itemModel)
|
{
|
if (itemModel == null)
|
return 0;
|
if (itemModel.config.ItemColor < 5)
|
return 0;
|
Equation.Instance.Clear();
|
Equation.Instance.AddKeyValue("itemColor", itemModel.config.ItemColor);
|
Equation.Instance.AddKeyValue("isSuite", itemModel.config.SuiteiD == 0 ? 0 : 1);
|
Equation.Instance.AddKeyValue("itemClass", itemModel.config.LV);
|
return Equation.Instance.Eval<int>(devourFormula2);
|
}
|
}
|
}
|