using Snxxz.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using TableConfig;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace Snxxz.UI
|
{
|
public class ComposeTicketWin : Window
|
{
|
[SerializeField]
|
GameObject composeUIShowObj;
|
[SerializeField]
|
GameObject noneComposeObj;
|
|
[SerializeField]
|
ScrollerController cellCtrl;
|
|
[SerializeField]
|
List<GameObject> sourceItemlist = new List<GameObject>();
|
|
[SerializeField]
|
List<GameObject> previewItemlist = new List<GameObject>();
|
|
[SerializeField]
|
Text successRateText;
|
|
[SerializeField]
|
Text _moneyCountText;
|
|
[SerializeField] GameObject costMoneyObj;
|
|
[SerializeField]
|
Button composeBtn;
|
|
[SerializeField] Button allComposeBtn;
|
|
[SerializeField] UIEffect composeEffect;
|
|
ComposeWinModel _composeWinModel;
|
ComposeWinModel composeWinModel
|
{
|
get { return _composeWinModel ?? (_composeWinModel = ModelCenter.Instance.GetModel<ComposeWinModel>()); }
|
}
|
|
ItemTipsModel _itemTipsModel;
|
ItemTipsModel itemTipsModel
|
{
|
get
|
{
|
return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>());
|
}
|
}
|
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
|
|
PackModelInterface _modelInterface;
|
PackModelInterface modelInterface
|
{
|
get { return _modelInterface ?? (_modelInterface = ModelCenter.Instance.GetModel<PackModelInterface>()); }
|
}
|
|
GetItemPathModel ItemPathModel
|
{
|
get { return ModelCenter.Instance.GetModel<GetItemPathModel>(); }
|
}
|
|
private Dictionary<int, Dictionary<int, List<ItemCompoundConfig>>> firstTypeDict = null;
|
private Dictionary<int, List<ItemCompoundConfig>> secondTypeDict = null;
|
private List<ItemCompoundConfig> thirdTypelist = null;
|
|
private int curSecondType = 0;
|
private int curThirdType = 0;
|
private int preSecondType = 0;
|
[SerializeField] int initSuccessRate = 10000;
|
ItemCompoundConfig compoundModel = null;
|
|
SelectEquipModel _selectModel;
|
private Dictionary<int,List<int>> fixedItemIndexDict = new Dictionary<int, List<int>>();
|
|
SelectEquipModel selectModel
|
{
|
get { return _selectModel ?? (_selectModel = ModelCenter.Instance.GetModel<SelectEquipModel>()); }
|
}
|
|
AchievementGuideEffect guidEffect = null;
|
|
protected override void BindController()
|
{
|
cellCtrl.OnRefreshCell += RefreshCell;
|
cellCtrl.vertical = true;
|
cellCtrl.lockType = EnhanceLockType.KeepVertical;
|
composeWinModel.ResetModelEvent += ResetModel;
|
|
}
|
|
protected override void AddListeners()
|
{
|
composeBtn.AddListener(OnClickComposeBtn);
|
allComposeBtn.AddListener(ClickAllComposeBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnComposeAnswer;
|
firstTypeDict = composeWinModel.GetFirstTypeModel((int)ComposeFuncType.Ticket);
|
bool isJumpTo = false;
|
if (AchievementGoto.guideAchievementId != 0)
|
{
|
SuccessConfig successConfig = Config.Instance.Get<SuccessConfig>(AchievementGoto.guideAchievementId);
|
if (successConfig.Type == 69)
|
{
|
isJumpTo = true;
|
curSecondType = composeWinModel.secondType;
|
curThirdType = composeWinModel.thirdType;
|
secondTypeDict = composeWinModel.GetSecondTypeModel((int)ComposeFuncType.Ticket, composeWinModel.secondType);
|
ClickSecondTypeUICtrl();
|
composeWinModel.ResetJumpToModel();
|
}
|
|
}
|
else
|
{
|
if(composeWinModel.secondType != 0)
|
{
|
isJumpTo = true;
|
curSecondType = composeWinModel.secondType;
|
curThirdType = composeWinModel.thirdType;
|
secondTypeDict = composeWinModel.GetSecondTypeModel((int)ComposeFuncType.Ticket,composeWinModel.secondType);
|
ClickSecondTypeUICtrl();
|
composeWinModel.ResetJumpToModel();
|
}
|
}
|
CreateCell();
|
if (curSecondType == 0)
|
{
|
RefreshUI(null);
|
}
|
|
if (compoundModel != null)
|
{
|
RefreshUI(compoundModel);
|
if (isJumpTo)
|
{
|
isJumpTo = false;
|
bool isCanCompose = true;
|
if (!composeWinModel.IsEnoughFixedMat(compoundModel) || !composeWinModel.IsEnoughUnfixedMat(compoundModel))
|
{
|
MessageWin.Inst.ShowFixedTip(Language.Get("Compose101"));
|
isCanCompose = false;
|
}
|
else if (!composeWinModel.IsEnoughMoney(compoundModel))
|
{
|
MessageWin.Inst.ShowFixedTip(Language.Get("Z1011"));
|
isCanCompose = false;
|
}
|
|
if (isCanCompose)
|
{
|
guidEffect = AchievementGuideEffectPool.Require(1);
|
guidEffect.transform.SetParentEx(composeBtn.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
}
|
}
|
}
|
|
protected override void OnAfterOpen()
|
{
|
cellCtrl.vertical = true;
|
this.transform.SetAsLastSibling();
|
}
|
|
protected override void OnPreClose()
|
{
|
DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
|
private void ResetModel()
|
{
|
curSecondType = 0;
|
curThirdType = 0;
|
preSecondType = 0;
|
compoundModel = null;
|
}
|
|
private void CreateCell()
|
{
|
cellCtrl.Refresh();
|
if(firstTypeDict != null)
|
{
|
foreach (int secondType in firstTypeDict.Keys)
|
{
|
cellCtrl.AddCell(ScrollerDataType.Header,secondType);
|
if(secondType == curSecondType)
|
{
|
foreach (int thirdType in firstTypeDict[secondType].Keys)
|
{
|
if (thirdType != 0)
|
{
|
cellCtrl.AddCell(ScrollerDataType.Normal, thirdType);
|
}
|
}
|
}
|
}
|
}
|
cellCtrl.Restart();
|
|
if (secondTypeDict != null)
|
{
|
if (secondTypeDict.Count >= 1 && curSecondType != 0)
|
{
|
cellCtrl.JumpIndex(GetCurIndex(curSecondType));
|
}
|
}
|
}
|
|
private int GetCurIndex(int secondType)
|
{
|
int curIndex = 0;
|
List<int> secondlist = firstTypeDict.Keys.ToList();
|
for (int i = 0; i < secondlist.Count; i++)
|
{
|
if (secondType == secondlist[i])
|
{
|
curIndex = i;
|
break;
|
}
|
}
|
return curIndex;
|
}
|
private void RefreshCell(ScrollerDataType type, CellView cell)
|
{
|
Image icon = cell.transform.Find("BtnIcon").GetComponent<Image>();
|
Text name = cell.transform.Find("BtnText").GetComponent<Text>();
|
Button cellBtn = cell.GetComponent<Button>();
|
cellBtn.RemoveAllListeners();
|
ItemCompoundConfig compoundModel = null;
|
switch (type)
|
{
|
case ScrollerDataType.Header:
|
GameObject arrowIcon = cell.transform.Find("SecondBtn").gameObject;
|
foreach (int thirdType in firstTypeDict[cell.index].Keys)
|
{
|
if (thirdType != 0)
|
{
|
arrowIcon.SetActive(true);
|
}
|
else
|
{
|
arrowIcon.SetActive(false);
|
}
|
|
compoundModel = firstTypeDict[cell.index][thirdType][0];
|
name.text = compoundModel.secondTypeName;
|
if (curSecondType == cell.index)
|
{
|
preSecondType = curSecondType;
|
arrowIcon.transform.localRotation = Quaternion.Euler(0, 0, -90);
|
icon.SetSprite("ComposeFirstClassChoosebtn");
|
secondTypeDict = composeWinModel.GetSecondTypeModel((int)ComposeFuncType.Ticket, curSecondType);
|
//ClickSecondTypeUICtrl();
|
}
|
else
|
{
|
arrowIcon.transform.localRotation = Quaternion.Euler(0, 0,0);
|
icon.SetSprite("ComposeFirstClassNormalbtn");
|
}
|
break;
|
}
|
cellBtn.AddListener(()=> { OnClickSecondType(cell.index); });
|
break;
|
case ScrollerDataType.Normal:
|
compoundModel = secondTypeDict[cell.index][0];
|
name.text = compoundModel.thirdTypeName;
|
if (curThirdType == cell.index)
|
{
|
icon.SetSprite("ChildListBtn_Select");
|
thirdTypelist = composeWinModel.GetThirdTypeModellist(compoundModel.firstType, compoundModel.secondType, cell.index);
|
RefreshUI(compoundModel);
|
}
|
else
|
{
|
icon.SetSprite("ChildListBtn_UnSelect");
|
}
|
cellBtn.AddListener(() => { OnClickThirdType(cell.index); });
|
break;
|
}
|
}
|
|
private void OnClickSecondType(int secondType)
|
{
|
curSecondType = secondType;
|
secondTypeDict = composeWinModel.GetSecondTypeModel((int)ComposeFuncType.Ticket, curSecondType);
|
foreach (var thirdType in secondTypeDict.Keys)
|
{
|
if (thirdType != 0)
|
{
|
if (preSecondType == curSecondType)
|
{
|
curSecondType = 0;
|
preSecondType = 0;
|
}
|
}
|
curThirdType = 0;
|
break;
|
}
|
|
if (preSecondType != curSecondType)
|
{
|
preSecondType = curSecondType;
|
if (guidEffect != null)
|
{
|
AchievementGuideEffectPool.Recycle(guidEffect);
|
guidEffect = null;
|
}
|
}
|
ClickSecondTypeUICtrl();
|
CreateCell();
|
}
|
|
private void ClickSecondTypeUICtrl()
|
{
|
if (secondTypeDict.Count > 1)
|
{
|
RefreshUI(null);
|
}
|
else
|
{
|
if (secondTypeDict.ContainsKey(curThirdType))
|
{
|
RefreshUI(secondTypeDict[curThirdType][0]);
|
}
|
}
|
}
|
|
private void OnClickThirdType(int thirdType)
|
{
|
curThirdType = thirdType;
|
cellCtrl.m_Scorller.RefreshActiveCellViews();
|
}
|
|
private void RefreshUI(ItemCompoundConfig compoundModel)
|
{
|
this.compoundModel = compoundModel;
|
if (compoundModel == null)
|
{
|
noneComposeObj.SetActive(true);
|
composeUIShowObj.SetActive(false);
|
}
|
else
|
{
|
noneComposeObj.SetActive(false);
|
composeUIShowObj.SetActive(true);
|
successRateText.text = Language.Get("HallowsWin_Success", StringUtility.Contact(compoundModel.successRate / 100, "%"));
|
composeWinModel.SetCurComposeModel(compoundModel);
|
ControllerRightUI();
|
}
|
}
|
|
private void ControllerRightUI()
|
{
|
int i = 0;
|
#region 合成物品UI
|
for (i = 0; i < previewItemlist.Count; i++)
|
{
|
int[] makeIds = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.MakeIds);
|
GameObject gridCell = previewItemlist[i].transform.Find("GridCell").gameObject;
|
if (i < makeIds.Length)
|
{
|
RefreshGridCellUI(gridCell, false,makeIds[i],NeedMatType.MakeItem);
|
}
|
else
|
{
|
RefreshGridCellUI(gridCell,true);
|
}
|
}
|
#endregion
|
|
#region 固定道具和不固定道具UI
|
int[] fixedDisplay = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedDisplay);
|
int[] fixedIds = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedIds);
|
int[] fixedCounts = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedCounts);
|
int[] unfixedIds = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.UnfixedIds);
|
int[] unfixedDisplay = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.UnfixedDisplay);
|
|
for (i = 0;i < sourceItemlist.Count; i++)
|
{
|
GameObject gridCell = sourceItemlist[i].transform.Find("GridCell").gameObject;
|
Text putInText = sourceItemlist[i].transform.Find("PutInText").GetComponent<Text>();
|
Button posBtn = sourceItemlist[i].GetComponent<Button>();
|
putInText.gameObject.SetActive(false);
|
RefreshGridCellUI(gridCell, true);
|
posBtn.RemoveAllListeners();
|
}
|
|
for (i = 0; i < fixedDisplay.Length; i++)
|
{
|
if (fixedDisplay[i] != 0)
|
{
|
GameObject matPos = sourceItemlist[fixedDisplay[i] - 1];
|
GameObject gridCell = matPos.transform.Find("GridCell").gameObject;
|
Text putInText = matPos.transform.Find("PutInText").GetComponent<Text>();
|
putInText.gameObject.SetActive(false);
|
RefreshGridCellUI(gridCell,false,fixedIds[i],NeedMatType.fixedItem);
|
}
|
}
|
|
for (i = 0; i < unfixedDisplay.Length; i++)
|
{
|
if (unfixedDisplay[i] != 0)
|
{
|
GameObject matPos = sourceItemlist[unfixedDisplay[i] - 1];
|
GameObject gridCell = matPos.transform.Find("GridCell").gameObject;
|
Text putInText = matPos.transform.Find("PutInText").GetComponent<Text>();
|
Button posBtn = matPos.GetComponent<Button>();
|
putInText.gameObject.SetActive(true);
|
RefreshGridCellUI(gridCell, false);
|
|
posBtn.RemoveAllListeners();
|
posBtn.AddListener(() => {
|
selectModel.SetAddParent(matPos);
|
selectModel.selectItem = SelectItemType.unfixed;
|
WindowCenter.Instance.Open<SelectItemWin>();
|
});
|
}
|
}
|
#endregion
|
|
_moneyCountText.text = modelInterface.OnChangeCoinsUnit((ulong)compoundModel.money);
|
}
|
|
private void RefreshGridCellUI(GameObject gridCell, bool islock, int itemId = -1,NeedMatType matType = NeedMatType.unfixedItem,int itemPlace = -1)
|
{
|
gridCell.SetActive(true);
|
ItemCell itemCell = gridCell.transform.Find("ItemCell").GetComponent<ItemCell>();
|
if (itemCell == null)
|
itemCell = gridCell.transform.Find("ItemCell").gameObject.AddComponent<ItemCell>();
|
|
GameObject gridlock = gridCell.transform.Find("GridLock").gameObject;
|
itemCell.cellBtn.onClick.RemoveAllListeners();
|
if (islock)
|
{
|
gridlock.gameObject.SetActive(true);
|
itemCell.gameObject.SetActive(false);
|
}
|
else
|
{
|
gridlock.gameObject.SetActive(false);
|
itemCell.gameObject.SetActive(true);
|
ItemModel itemModel = playerPack.GetItemModelByIndex(PackType.rptItem,itemPlace);
|
ItemConfig itemConfig = Config.Instance.Get<ItemConfig>(itemId);
|
if (itemModel == null)
|
{
|
if(itemId != -1)
|
{
|
ItemCellModel cellModel = new ItemCellModel(itemId);
|
itemCell.Init(cellModel);
|
itemCell.cellBtn.onClick.AddListener(() =>
|
{
|
if (matType == NeedMatType.fixedItem)
|
{
|
if (itemConfig.GetWay != null && itemConfig.GetWay.Length > 0)
|
{
|
ItemPathModel.SetChinItemModel(itemId);
|
}
|
else
|
{
|
ItemAttrData attrData = new ItemAttrData(itemId, true);
|
itemTipsModel.SetItemTipsModel(attrData);
|
}
|
}
|
else
|
{
|
ItemAttrData attrData = new ItemAttrData(itemId, true);
|
itemTipsModel.SetItemTipsModel(attrData);
|
}
|
}
|
);
|
}
|
else
|
{
|
itemCell.gameObject.SetActive(false);
|
}
|
|
}
|
else
|
{
|
itemCell.Init(itemModel);
|
itemCell.cellBtn.onClick.AddListener(() =>
|
{
|
if (matType == NeedMatType.fixedItem)
|
{
|
if (itemConfig.GetWay != null && itemConfig.GetWay.Length > 0)
|
{
|
ItemPathModel.SetChinItemModel(itemId);
|
}
|
else
|
{
|
itemTipsModel.SetItemTipsModel(PackType.rptItem, itemModel.itemInfo.ItemGUID);
|
}
|
}
|
else
|
{
|
itemTipsModel.SetItemTipsModel(PackType.rptItem, itemModel.itemInfo.ItemGUID);
|
}
|
|
});
|
}
|
|
if(matType == NeedMatType.fixedItem)
|
{
|
int[] fixedIds = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedIds);
|
int[] fixedCounts = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedCounts);
|
itemCell.countText.gameObject.SetActive(true);
|
int haveCount = playerPack.GetItemCountByID(PackType.rptItem,itemId);
|
int i = 0;
|
for(i = 0; i < fixedIds.Length; i++)
|
{
|
if(fixedIds[i] == itemId)
|
{
|
if (haveCount >= fixedCounts[i])
|
{
|
itemCell.countText.text = StringUtility.Contact(UIHelper.GetTextColorByItemColor(TextColType.Green,haveCount.ToString()),
|
"/",fixedCounts[i].ToString());
|
}
|
else
|
{
|
itemCell.countText.text = StringUtility.Contact(UIHelper.GetTextColorByItemColor(TextColType.Red, haveCount.ToString()),
|
"/", fixedCounts[i].ToString());
|
}
|
break;
|
}
|
}
|
|
}
|
else
|
{
|
itemCell.countText.gameObject.SetActive(false);
|
}
|
|
}
|
|
}
|
|
private void ClickAllComposeBtn()
|
{
|
fixedItemIndexDict.Clear();
|
if (compoundModel == null) return;
|
|
List<int> composeCountlist = new List<int>();
|
SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem);
|
int[] fixedIds = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedIds);
|
int[] fixedCounts = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedCounts);
|
for (int i = 0; i < fixedIds.Length; i++)
|
{
|
int haveCount = playerPack.GetItemCountByID(PackType.rptItem, fixedIds[i]);
|
int canComposeCount = haveCount / fixedCounts[i];
|
composeCountlist.Add(canComposeCount);
|
List<int> itemIndexlist = null;
|
if (singlePack != null)
|
{
|
itemIndexlist = singlePack.ItemIndexlist(fixedIds[i], fixedCounts[i] * canComposeCount);
|
}
|
fixedItemIndexDict.Add(fixedIds[i], itemIndexlist);
|
}
|
|
composeCountlist.Sort();
|
int composeCnt = 0;
|
for (int i = composeCountlist[0]; i > -1; i--)
|
{
|
ulong needMoney = (ulong)(i * compoundModel.money);
|
if (UIHelper.GetMoneyCnt(3) >= needMoney)
|
{
|
composeCnt = i;
|
break;
|
}
|
}
|
composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, composeEffect, composeCnt);
|
}
|
|
private void OnClickComposeBtn()
|
{
|
if (compoundModel == null) return;
|
|
SetFixedItemIndexDic();
|
composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict,composeEffect,1);
|
}
|
|
private void SetFixedItemIndexDic()
|
{
|
fixedItemIndexDict.Clear();
|
SinglePackModel singlePack = playerPack.GetSinglePackModel(PackType.rptItem);
|
if (singlePack == null || compoundModel == null) return;
|
|
int minBindCnt = 0;
|
int minNoBindCnt = 0;
|
composeWinModel.GetBindOrNoBindMinCnt(out minBindCnt,out minNoBindCnt);
|
int[] fixedIds = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedIds);
|
int[] fixedCounts = ItemCompoundConfig.GetDisplayArrayByType(compoundModel.id, DisplayItemArray.FixedCounts);
|
|
for (int i = 0; i < fixedIds.Length; i++)
|
{
|
List<int> itemIndexlist = null;
|
if (minBindCnt >= fixedCounts[i])
|
{
|
itemIndexlist = singlePack.ItemIndexlistByIsBind(fixedIds[i],fixedCounts[i], 1);
|
}
|
else if(minNoBindCnt >= fixedCounts[i])
|
{
|
itemIndexlist = singlePack.ItemIndexlistByIsBind(fixedIds[i],fixedCounts[i],0);
|
}
|
else
|
{
|
itemIndexlist = singlePack.ItemIndexlist(fixedIds[i],fixedCounts[i]);
|
}
|
|
if (itemIndexlist != null)
|
{
|
fixedItemIndexDict.Add(fixedIds[i], itemIndexlist);
|
}
|
}
|
|
|
}
|
|
private void OnComposeAnswer(HA814_tagMCMakeItemAnswer answer)
|
{
|
if (answer.MakeType != (int)MakeType.Def_mitItemCompound)
|
return;
|
|
if (answer.Result == 1)
|
{
|
MessageWin.Inst.ShowFixedTip(Language.Get("Compose102"));
|
}
|
else
|
{
|
MessageWin.Inst.ShowFixedTip(Language.Get("Compose103"));
|
}
|
|
RefreshUI(compoundModel);
|
selectModel.ClearSelectModel();
|
}
|
}
|
}
|