using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Collections;
|
|
namespace Snxxz.UI
|
{
|
public class EquipDevourWin : Window
|
{
|
[SerializeField] ScrollerController gridCtrl;
|
[SerializeField] Button devourBtn;
|
[SerializeField] Button equipColorSelectBtn;
|
[SerializeField] Button equipLvSelectBtn;
|
[SerializeField] Text equipColorText;
|
[SerializeField] Text equipLvText;
|
[SerializeField] GameObject colorlistObj;
|
[SerializeField] GameObject lvlistObj;
|
[SerializeField] Button starSelectBtn;
|
[SerializeField] GameObject selectStarIcon;
|
[SerializeField] ClickScreenOtherSpace colorSpaceClick;
|
[SerializeField] ClickScreenOtherSpace lvSpaceClick;
|
|
[SerializeField] UIEffect equipDevourEffect;
|
[Header("颜色选择列表")]
|
[SerializeField] List<EquipColorSelect> colorSelectlist = new List<EquipColorSelect>();
|
[Header("阶级选择列表")]
|
[SerializeField]
|
List<EquipLvSelect> lvSelectlist = new List<EquipLvSelect>();
|
|
[Header("分解装备属性")]
|
[SerializeField] Text decomLvText;
|
[SerializeField] Text decomPreviewLvText;
|
[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] int singleLineNum = 5;
|
[SerializeField] int sumGridNum = 100;
|
|
PlayerPackModel playerPack { get { return ModelCenter.Instance.GetModel<PlayerPackModel>(); } }
|
ItemTipsModel tipsModel { get { return ModelCenter.Instance.GetModel<ItemTipsModel>(); } }
|
PackModelInterface modelInterface { get { return ModelCenter.Instance.GetModel<PackModelInterface>(); } }
|
|
List<ItemModel> devourModellist;
|
bool isOpen = true;
|
int devourCnt = 0;
|
int getMatCycle = 0;
|
protected override void BindController()
|
{
|
colorlistObj.SetActive(true);
|
lvlistObj.SetActive(true);
|
gridCtrl.OnRefreshCell += RefreshGridCell;
|
}
|
|
protected override void AddListeners()
|
{
|
equipColorSelectBtn.AddListener(ClickColorSelectBtn);
|
equipLvSelectBtn.AddListener(ClickLvSelectBtn);
|
starSelectBtn.AddListener(ClickStarSelectBtn);
|
devourBtn.AddListener(ClickEquipDecomBtn);
|
colorSpaceClick.AddListener(ClickColorSelectBtn);
|
lvSpaceClick.AddListener(ClickLvSelectBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
getMatCycle = int.Parse(FuncConfigConfig.Get("EquipDecomposeAward").Numerical1);
|
devourCnt = 0;
|
isOpen = true;
|
playerPack.selectDevourlist.Clear();
|
devourModellist = playerPack.GetDevourModellist();
|
InitUI();
|
|
}
|
|
protected override void OnAfterOpen()
|
{
|
this.transform.SetAsLastSibling();
|
colorlistObj.SetActive(false);
|
lvlistObj.SetActive(false);
|
RefreshColor(playerPack.colorType);
|
RefreshLv(playerPack.lvType);
|
StartCoroutine(SetJumpIndex(0));
|
|
playerPack.RefreshColorSelectAct += RefreshColor;
|
playerPack.RefreshLvSelectAct += RefreshLv;
|
playerPack.RefreshStarSelectAct += RefreshStar;
|
playerPack.ItemCntAddAct += RefreshAddItem;
|
playerPack.ItemCntReduceAct += RefreshReduceItem;
|
playerPack.RefreshPackAct += RefreshPack;
|
playerPack.RefreshDecomAttrAct += RefreshDecomAttr;
|
equipDevourEffect.OnComplete += OnCompleteEvent;
|
playerPack.RefreshEquipDecomNumAct += RefreshDecomPreviewAttr;
|
}
|
|
protected override void OnPreClose()
|
{
|
equipDevourEffect.OnComplete -= OnCompleteEvent;
|
playerPack.RefreshColorSelectAct -= RefreshColor;
|
playerPack.RefreshLvSelectAct -= RefreshLv;
|
playerPack.ItemCntAddAct -= RefreshAddItem;
|
playerPack.ItemCntReduceAct -= RefreshReduceItem;
|
playerPack.RefreshPackAct -= RefreshPack;
|
playerPack.RefreshStarSelectAct -= RefreshStar;
|
playerPack.RefreshDecomAttrAct -= RefreshDecomAttr;
|
playerPack.RefreshEquipDecomNumAct -= RefreshDecomPreviewAttr;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
private void InitUI()
|
{
|
playerPack.GetSelectDevourList();
|
CreateCell();
|
isOpen = false;
|
RefreshDecomposeAttr();
|
RefreshDecomPreviewAttr();
|
if(playerPack.starType != PlayerPackModel.EquipStarType.None)
|
{
|
selectStarIcon.SetActive(true);
|
}
|
else
|
{
|
selectStarIcon.SetActive(false);
|
}
|
ItemConfig getMatConfig = ItemConfig.Get(2125);
|
if(getMatConfig != null)
|
{
|
getMatBgImg.SetItemBackGround(getMatConfig.ItemColor);
|
getMatIcon.SetSprite(getMatConfig.IconKey);
|
getMatBtn.RemoveAllListeners();
|
getMatBtn.AddListener(()=>
|
{
|
ItemAttrData attrData = new ItemAttrData(getMatConfig.ID,true);
|
tipsModel.SetItemTipsModel(attrData);
|
});
|
}
|
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.GetItemModelByIndex(type,index);
|
playerPack.RefreshGetNewItem(itemModel);
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
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.GetItemModelByIndex(type,index);
|
if(itemModel == null)
|
{
|
for(int i = 0; i < playerPack.selectDevourlist.Count; i++)
|
{
|
if(playerPack.selectDevourlist[i].itemPlace == index)
|
{
|
playerPack.selectDevourlist.RemoveAt(i);
|
break;
|
}
|
}
|
}
|
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
|
private void RefreshPack(PackType type)
|
{
|
if (type != PackType.Item) return;
|
playerPack.selectDevourlist.Clear();
|
devourModellist = playerPack.GetDevourModellist();
|
playerPack.GetSelectDevourList();
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
private void RefreshLv(PlayerPackModel.EquipLvType type)
|
{
|
for (int i = 0; i < lvSelectlist.Count; i++)
|
{
|
if (lvSelectlist[i].lvType == type)
|
{
|
equipLvText.text = lvSelectlist[i].lvText.text;
|
equipLvText.color = lvSelectlist[i].lvText.color;
|
break;
|
}
|
}
|
if (!isOpen)
|
{
|
lvlistObj.SetActive(false);
|
playerPack.GetSelectDevourList();
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
}
|
|
private void RefreshColor(PlayerPackModel.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();
|
}
|
}
|
|
private void RefreshStar(PlayerPackModel.EquipStarType type)
|
{
|
if (!isOpen)
|
{
|
playerPack.GetSelectDevourList();
|
gridCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
}
|
|
private void CreateCell()
|
{
|
devourCnt = 0;
|
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 ClickStarSelectBtn()
|
{
|
if(playerPack.starType != PlayerPackModel.EquipStarType.None)
|
{
|
playerPack.SetStarSelect(PlayerPackModel.EquipStarType.None);
|
selectStarIcon.SetActive(false);
|
}
|
else
|
{
|
playerPack.SetStarSelect(PlayerPackModel.EquipStarType.One);
|
selectStarIcon.SetActive(true);
|
}
|
}
|
|
private void ClickLvSelectBtn()
|
{
|
if (lvlistObj.activeInHierarchy)
|
{
|
lvlistObj.SetActive(false);
|
}
|
else
|
{
|
lvlistObj.SetActive(true);
|
}
|
}
|
|
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>();
|
}
|
}
|
|
public void RefreshDecomposeAttr(bool isRefresh = false)
|
{
|
//decomPreviewLvText.gameObject.SetActive(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);//经验条的初始化和刷新
|
Dictionary<int, int> 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].gameObject.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;
|
public void RefreshDecomPreviewAttr()
|
{
|
equipAddExpPreview = 0;
|
EquipDeComposeConfig deComposeConfig = EquipDeComposeConfig.Get(playerPack.decomposeLv);
|
if (playerPack.selectDevourlist.Count > 0)
|
{
|
int devourCnt = GetRealDevourCnt();
|
equipAddExpPreview = GetPreviewExpByDevour();
|
int previewLv = GetPreviewDecomposeLv(playerPack.decomposeLv, 0);
|
//decomPreviewLvText.gameObject.SetActive(true);
|
//decomPreviewLvText.text = StringUtility.Contact("+", previewLv - playerPack.decomposeLv);
|
Dictionary<int, int> attrDict = playerPack.GetDecomAttrDictByLv(playerPack.decomposeLv);
|
Dictionary<int, int> 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].gameObject.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.AppendStringColor(TextColType.Green,previewExp,true),"/"+ deComposeConfig.UpNeedExp);
|
}
|
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;
|
}
|
int devourCnt = GetRealDevourCnt();
|
int betterEquip = 0;
|
int preciousCnt = 0;
|
int twoStarCnt = 0;
|
bool isContain = playerPack.ContainPreciousItem(realDevourlist, out betterEquip, out preciousCnt);
|
bool isTwoStarEquip = playerPack.ContainTwoStarEquip(realDevourlist,out twoStarCnt);
|
if (isContain || isTwoStarEquip)
|
{
|
if(betterEquip > 0 && preciousCnt > 0)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipResolve_Text_1", betterEquip, preciousCnt),
|
(bool isOk) =>
|
{
|
if (isOk)
|
{
|
equipDevourEffect.Play();
|
SendEquipdevourQuest();
|
}
|
});
|
}
|
else if(twoStarCnt > 0 && preciousCnt > 0)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipResolve_Text_6", twoStarCnt, preciousCnt),
|
(bool isOk) =>
|
{
|
if (isOk)
|
{
|
equipDevourEffect.Play();
|
SendEquipdevourQuest();
|
}
|
});
|
}
|
else if(betterEquip > 0)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipResolve_Text_5", betterEquip),
|
(bool isOk) =>
|
{
|
if (isOk)
|
{
|
equipDevourEffect.Play();
|
SendEquipdevourQuest();
|
}
|
});
|
}
|
else if(preciousCnt > 0)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipResolve_Text_4",preciousCnt),
|
(bool isOk) =>
|
{
|
if (isOk)
|
{
|
equipDevourEffect.Play();
|
SendEquipdevourQuest();
|
}
|
});
|
}
|
else if(twoStarCnt > 0)
|
{
|
ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
|
Language.Get("EquipResolve_Text_7", twoStarCnt),
|
(bool isOk) =>
|
{
|
if (isOk)
|
{
|
equipDevourEffect.Play();
|
SendEquipdevourQuest();
|
}
|
});
|
}
|
|
}
|
else
|
{
|
equipDevourEffect.Play();
|
SendEquipdevourQuest();
|
}
|
|
}
|
|
private void OnCompleteEvent()
|
{
|
decomEffect.Play();
|
}
|
|
public int GetPreviewExpByDevour()
|
{
|
int sumExp = 0;
|
for (int i = 0; i < realDevourlist.Count; i++)
|
{
|
int curExp = 0;
|
ItemModel itemModel = realDevourlist[i];
|
if (itemModel.config.EquipPlace == 0)
|
{
|
curExp = itemModel.count * itemModel.config.EffectValueA1;
|
}
|
else
|
{
|
PetEatEquipConfig tagPet = PetEatEquipConfig.GetEquipColorAndEquipClass(itemModel.config.ItemColor, itemModel.config.LV);
|
if (tagPet != null)
|
{
|
curExp = tagPet.Exp;
|
}
|
}
|
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 void SendEquipdevourQuest()
|
{
|
if (!modelInterface.isPackResetOk || SettingEffectMgr.Instance.isStartDecompose) return;
|
|
playerPack.isAutoDecompose = false;
|
SettingEffectMgr.Instance.isStartDecompose = true;
|
CA32C_tagCMEquipDecompose _petEat = new CA32C_tagCMEquipDecompose();
|
var _petIndex = new ushort[realDevourlist.Count];
|
var idlist = new uint[realDevourlist.Count];
|
for (int i = 0; i < realDevourlist.Count; i++)
|
{
|
_petIndex[i] = (ushort)realDevourlist[i].itemPlace;
|
idlist[i] = (uint)realDevourlist[i].itemId;
|
}
|
_petEat.Count = (byte)_petIndex.Length;
|
_petEat.IndexList = _petIndex;
|
_petEat.ItemIDList = idlist;
|
_petEat.IsAuto = 0;
|
GameNetSystem.Instance.SendInfo(_petEat);
|
}
|
|
List<ItemModel> realDevourlist = new List<ItemModel>();
|
private int GetRealDevourCnt()
|
{
|
realDevourlist.Clear();
|
int devourCnt = 0;
|
for (int i = 0; i < sumGridNum; i++)
|
{
|
if (i < devourModellist.Count)
|
{
|
ItemModel itemModel = devourModellist[i];
|
if(playerPack.selectDevourlist.Contains(itemModel))
|
{
|
devourCnt += itemModel.count;
|
realDevourlist.Add(itemModel);
|
}
|
}
|
}
|
return devourCnt;
|
}
|
}
|
}
|