using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class ComposeTicketWin : Window
|
{
|
[SerializeField] ScrollerController cellCtrl;
|
[SerializeField] GameObject containCompose;
|
[SerializeField] GameObject containUnCompose;
|
[SerializeField] GameObject containOneMat;
|
[SerializeField] GameObject containTwoMat;
|
[SerializeField] Text successRateText;
|
[SerializeField] Text _moneyCountText;
|
[SerializeField] GameObject costMoneyObj;
|
[SerializeField] Button composeBtn;
|
[SerializeField] Button allComposeBtn;
|
[SerializeField] UIEffect twoMatComposeEffect;
|
[SerializeField] UIEffect oneMatComposeEffect;
|
[Header("一个固定物品和非固定物品")]
|
[SerializeField] List<ComposeMatCell> oneMatFixedAndUnfixeds = new List<ComposeMatCell>();
|
[Header("非一个固定物品和非固定物品")]
|
[SerializeField] List<ComposeMatCell> twoMatFixedAndUnfixeds = new List<ComposeMatCell>();
|
[Header("合成物品")]
|
[SerializeField] List<ComposeMatCell> makeItems = new List<ComposeMatCell>();
|
|
ComposeWinModel _composeWinModel;
|
ComposeWinModel composeWinModel {
|
get { return _composeWinModel ?? (_composeWinModel = ModelCenter.Instance.GetModel<ComposeWinModel>()); }
|
}
|
|
|
PackModel _playerPack;
|
PackModel playerPack {
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
|
}
|
|
ComposeWinModel.ComposeFirstTypeData firstTypeData;
|
ComposeWinModel.ComposeSecondTypeData secondTypeData;
|
ComposeWinModel.ComposeThirdTypeData thirdTypeData;
|
|
private int curSecondType = 0;
|
private int curThirdType = 0;
|
private int preSecondType = 0;
|
[SerializeField] int initSuccessRate = 10000;
|
ItemCompoundConfig compoundModel = null;
|
private Dictionary<int, List<int>> fixedItemIndexDict = new Dictionary<int, List<int>>();
|
AchievementGuideEffect guidEffect = null;
|
|
protected override void BindController()
|
{
|
cellCtrl.OnRefreshCell += RefreshTypeCell;
|
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;
|
composeWinModel.UpdateSecondTypeEvent += UpdateSecondType;
|
composeWinModel.UpdateThirdTypeEvent += UpdateThirdType;
|
Display();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
cellCtrl.vertical = true;
|
this.transform.SetAsLastSibling();
|
}
|
|
protected override void OnPreClose()
|
{
|
composeWinModel.UpdateSecondTypeEvent -= UpdateSecondType;
|
composeWinModel.UpdateThirdTypeEvent -= UpdateThirdType;
|
DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
#region 新的逻辑
|
private void Display()
|
{
|
composeWinModel.TryGetFirstTypeData((int)ComposeFuncType.Ticket, out firstTypeData);
|
if (firstTypeData == null) return;
|
|
DefaultSelect();
|
CreateTypeCell();
|
JumpIndex();
|
}
|
private void DefaultSelect()
|
{
|
bool isJumpTo = false;
|
var achieveId = AchievementGoto.guideAchievementId;
|
SuccessConfig successConfig = SuccessConfig.Get(achieveId);
|
if (successConfig != null && successConfig.Type == 69)
|
{
|
isJumpTo = true;
|
curSecondType = composeWinModel.secondType;
|
curThirdType = composeWinModel.thirdType;
|
composeWinModel.ResetJumpToModel();
|
}
|
else
|
{
|
if (composeWinModel.secondType != 0)
|
{
|
isJumpTo = true;
|
curSecondType = composeWinModel.secondType;
|
curThirdType = composeWinModel.thirdType;
|
composeWinModel.ResetJumpToModel();
|
}
|
}
|
composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Ticket, curSecondType, curThirdType, out thirdTypeData);
|
if (thirdTypeData != null)
|
{
|
RefreshUI(thirdTypeData.itemCompound);
|
if (isJumpTo)
|
{
|
isJumpTo = false;
|
bool isCanCompose = true;
|
if (!composeWinModel.IsEnoughFixedMat(thirdTypeData.itemCompound))
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("Compose101"));
|
isCanCompose = false;
|
}
|
else if (!composeWinModel.IsEnoughMoney(thirdTypeData.itemCompound))
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("Z1011"));
|
isCanCompose = false;
|
}
|
|
if (isCanCompose)
|
{
|
guidEffect = AchievementGuideEffectPool.Require(1);
|
guidEffect.transform.SetParentEx(composeBtn.transform, Vector3.zero, Quaternion.identity, Vector3.one);
|
}
|
}
|
}
|
else
|
{
|
RefreshUI(null);
|
}
|
}
|
|
private void CreateTypeCell()
|
{
|
if (firstTypeData == null) return;
|
|
cellCtrl.Refresh();
|
foreach (var second in firstTypeData.secondTypeDict.Keys)
|
{
|
cellCtrl.AddCell(ScrollerDataType.Header, second);
|
if (second == curSecondType)
|
{
|
var thirdTypeDict = firstTypeData.secondTypeDict[second].thirdTypeDict;
|
foreach (var third in thirdTypeDict.Keys)
|
{
|
if (third != 0)
|
{
|
cellCtrl.AddCell(ScrollerDataType.Normal, third);
|
}
|
}
|
}
|
}
|
cellCtrl.Restart();
|
composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Ticket, curSecondType, curThirdType, out thirdTypeData);
|
if (thirdTypeData != null)
|
{
|
var fixItemIds = thirdTypeData.itemCompound.itemID;
|
if (fixItemIds != null)
|
{
|
if (fixItemIds.Length < 2)
|
{
|
UpdateUIShow(true, false, true, false);
|
}
|
else
|
{
|
UpdateUIShow(true, false, false, true);
|
}
|
|
}
|
RefreshUI(thirdTypeData.itemCompound);
|
}
|
else
|
{
|
RefreshUI(null);
|
UpdateUIShow(false, true, false, false);
|
}
|
}
|
|
private void UpdateUIShow(params bool[] isShows)
|
{
|
containCompose.SetActive(isShows[0]);
|
containUnCompose.SetActive(isShows[1]);
|
containOneMat.SetActive(isShows[2]);
|
containTwoMat.SetActive(isShows[3]);
|
}
|
|
private void JumpIndex()
|
{
|
if (firstTypeData == null) return;
|
|
var secondTypeDict = firstTypeData.secondTypeDict;
|
if (secondTypeDict.Count >= 1 && curSecondType != 0)
|
{
|
cellCtrl.JumpIndex(GetCurIndex(curSecondType));
|
}
|
}
|
|
private int GetCurIndex(int secondType)
|
{
|
if (firstTypeData == null) return 0;
|
int curIndex = 0;
|
var secondTypeDict = firstTypeData.secondTypeDict;
|
List<int> secondlist = secondTypeDict.Keys.ToList();
|
for (int i = 0; i < secondlist.Count; i++)
|
{
|
if (secondType == secondlist[i])
|
{
|
curIndex = i;
|
break;
|
}
|
}
|
if (curThirdType >= 4)
|
{
|
curIndex = curIndex + curThirdType - 2;
|
}
|
return curIndex;
|
}
|
|
private void RefreshTypeCell(ScrollerDataType type, CellView cell)
|
{
|
switch (type)
|
{
|
case ScrollerDataType.Header:
|
ComposeWinModel.ComposeSecondTypeData _secondTypeData = null;
|
ComposeFirstTypeCell firstTypeCell = cell.GetComponent<ComposeFirstTypeCell>();
|
composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Ticket, cell.index, out _secondTypeData);
|
if (_secondTypeData != null)
|
{
|
var thirdTypeDict = _secondTypeData.thirdTypeDict;
|
foreach (var third in thirdTypeDict.Keys)
|
{
|
firstTypeCell.SetDisplay((int)ComposeFuncType.Ticket, cell.index, third, curSecondType);
|
break;
|
}
|
}
|
break;
|
case ScrollerDataType.Normal:
|
ComposeSecondTypeCell secondTypeCell = cell.GetComponent<ComposeSecondTypeCell>();
|
secondTypeCell.SetDisplay((int)ComposeFuncType.Ticket, curSecondType, cell.index, curThirdType);
|
break;
|
}
|
}
|
|
private void UpdateSecondType(int secondType)
|
{
|
curThirdType = 0;
|
curSecondType = secondType;
|
composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Ticket, secondType, out secondTypeData);
|
OnClickSecondType();
|
CreateTypeCell();
|
JumpIndex();
|
}
|
|
private void OnClickSecondType()
|
{
|
if (secondTypeData == null) return;
|
|
var thirdTypeDict = secondTypeData.thirdTypeDict;
|
if (curThirdType == 0)
|
{
|
foreach (var thirdType in thirdTypeDict.Keys)
|
{
|
if (thirdType != 0)
|
{
|
if (preSecondType == curSecondType)
|
{
|
curSecondType = 0;
|
preSecondType = 0;
|
}
|
else
|
{
|
curThirdType = thirdType;
|
}
|
}
|
break;
|
}
|
}
|
|
if (preSecondType != curSecondType)
|
{
|
preSecondType = curSecondType;
|
if (guidEffect != null)
|
{
|
AchievementGuideEffectPool.Recycle(guidEffect);
|
guidEffect = null;
|
}
|
}
|
}
|
|
private void UpdateThirdType(int thirdType)
|
{
|
composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Ticket, curSecondType, thirdType, out thirdTypeData);
|
curThirdType = thirdType;
|
CreateTypeCell();
|
}
|
|
private void UpdateComposeMat()
|
{
|
int[] makeIds = compoundModel.makeID;
|
for (int i = 0; i < makeItems.Count; i++)
|
{
|
var matCell = makeItems[i];
|
if (makeIds != null && i < makeIds.Length)
|
{
|
matCell.SetDisplay(compoundModel, NeedMatType.MakeItem, false, "", makeIds[i]);
|
}
|
else
|
{
|
matCell.SetDisplay(compoundModel, NeedMatType.MakeItem, true);
|
}
|
}
|
|
int[] fixedIds = compoundModel.itemID;
|
int[] fixedDisplays = compoundModel.itemDisplay;
|
int[] unfixedIds = compoundModel.unfixedItemID;
|
int[] unfixedDisplays = compoundModel.unfixedItemDisplay;
|
if (fixedIds != null && fixedIds.Length < 2)
|
{
|
for (int i = 0; i < oneMatFixedAndUnfixeds.Count; i++)
|
{
|
var matCell = oneMatFixedAndUnfixeds[i];
|
matCell.SetDisplay(compoundModel, NeedMatType.Nothing, true);
|
}
|
|
for (int i = 0; i < fixedDisplays.Length; i++)
|
{
|
var fixedDisplay = fixedDisplays[i];
|
if (fixedDisplay != 0)
|
{
|
var matCell = oneMatFixedAndUnfixeds[fixedDisplay - 1];
|
int fixedId = 0;
|
composeWinModel.TryGetIdByDisplay(NeedMatType.fixedItem, compoundModel, fixedDisplay, out fixedId);
|
matCell.SetDisplay(compoundModel, NeedMatType.fixedItem, false, "", fixedId);
|
}
|
}
|
|
for (int i = 0; i < unfixedDisplays.Length; i++)
|
{
|
var unfixedDisplay = unfixedDisplays[i];
|
if (unfixedDisplay != 0)
|
{
|
var matCell = oneMatFixedAndUnfixeds[unfixedDisplay - 1];
|
matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false);
|
}
|
}
|
}
|
else if (fixedIds != null)
|
{
|
for (int i = 0; i < twoMatFixedAndUnfixeds.Count; i++)
|
{
|
var matCell = twoMatFixedAndUnfixeds[i];
|
matCell.SetDisplay(compoundModel, NeedMatType.Nothing, true);
|
}
|
|
for (int i = 0; i < fixedDisplays.Length; i++)
|
{
|
var fixedDisplay = fixedDisplays[i];
|
if (fixedDisplay != 0)
|
{
|
var matCell = twoMatFixedAndUnfixeds[fixedDisplay - 1];
|
int fixedId = 0;
|
composeWinModel.TryGetIdByDisplay(NeedMatType.fixedItem, compoundModel, fixedDisplay, out fixedId);
|
matCell.SetDisplay(compoundModel, NeedMatType.fixedItem, false, "", fixedId);
|
}
|
}
|
|
for (int i = 0; i < unfixedDisplays.Length; i++)
|
{
|
var unfixedDisplay = unfixedDisplays[i];
|
if (unfixedDisplay != 0)
|
{
|
var matCell = twoMatFixedAndUnfixeds[unfixedDisplay - 1];
|
matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false);
|
}
|
}
|
}
|
|
_moneyCountText.text = ItemLogicUtility.Instance.OnChangeCoinsUnit((ulong)compoundModel.money);
|
}
|
|
private UIEffect GetPlayMatEffect()
|
{
|
if (compoundModel == null) return null;
|
|
int[] fixedIds = compoundModel.itemID;
|
if (fixedIds != null)
|
{
|
if (fixedIds.Length < 2)
|
{
|
return oneMatComposeEffect;
|
}
|
else
|
{
|
return twoMatComposeEffect;
|
}
|
}
|
return null;
|
}
|
#endregion
|
|
private void ResetModel()
|
{
|
curSecondType = 0;
|
curThirdType = 0;
|
compoundModel = null;
|
if (!WindowJumpMgr.Instance.IsJumpState)
|
{
|
preSecondType = 0;
|
}
|
}
|
|
private void RefreshUI(ItemCompoundConfig compoundModel)
|
{
|
this.compoundModel = compoundModel;
|
if (compoundModel == null) return;
|
|
successRateText.text = Language.Get("HallowsWin_Success", StringUtility.Contact(compoundModel.successRate / 100, "%"));
|
composeWinModel.SetCurComposeModel(compoundModel);
|
UpdateComposeMat();
|
}
|
|
private void ClickAllComposeBtn()
|
{
|
fixedItemIndexDict.Clear();
|
if (compoundModel == null) return;
|
|
bool isTrailer = composeWinModel.IsTrailerByLevel(compoundModel);
|
if (isTrailer)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("FuncOpenLv", compoundModel.levelNeed));
|
return;
|
}
|
|
List<int> composeCountlist = new List<int>();
|
var packType = composeWinModel.GetPackTypeByMakerId(compoundModel.makeID);
|
SinglePack singlePack = playerPack.GetSinglePack(packType);
|
int[] fixedIds = compoundModel.itemID;
|
int[] fixedCounts = compoundModel.itemCount;
|
for (int i = 0; i < fixedIds.Length; i++)
|
{
|
int haveCount = playerPack.GetItemCountByID(packType, fixedIds[i]);
|
int canComposeCount = haveCount / fixedCounts[i];
|
composeCountlist.Add(canComposeCount);
|
List<int> itemIndexlist = null;
|
if (singlePack != null)
|
{
|
itemIndexlist = singlePack.GetItemIndexsAppointedCount(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, GetPlayMatEffect(), composeCnt);
|
}
|
|
private void OnClickComposeBtn()
|
{
|
if (compoundModel == null) return;
|
|
bool isTrailer = composeWinModel.IsTrailerByLevel(compoundModel);
|
if (isTrailer)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("FuncOpenLv", compoundModel.levelNeed));
|
return;
|
}
|
SetFixedItemIndexDic();
|
composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, GetPlayMatEffect(), 1);
|
}
|
|
private void SetFixedItemIndexDic()
|
{
|
fixedItemIndexDict.Clear();
|
if (compoundModel == null) return;
|
var packType = composeWinModel.GetPackTypeByMakerId(compoundModel.makeID);
|
SinglePack singlePack = playerPack.GetSinglePack(packType);
|
if (singlePack == null) return;
|
|
int[] fixedIds = compoundModel.itemID;
|
int[] fixedCounts = compoundModel.itemCount;
|
|
for (int i = 0; i < fixedIds.Length; i++)
|
{
|
var itemIndexlist = singlePack.GetItemIndexsAppointedCount(fixedIds[i], fixedCounts[i]);
|
if (itemIndexlist != null)
|
{
|
fixedItemIndexDict.Add(fixedIds[i], itemIndexlist);
|
}
|
}
|
|
|
}
|
|
private void OnComposeAnswer(HA814_tagMCMakeItemAnswer answer)
|
{
|
if (answer.MakeType != (int)MakeType.ItemCompound)
|
return;
|
|
if (answer.Result == 1)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("Compose102"));
|
}
|
else
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("Compose103"));
|
}
|
|
RefreshUI(compoundModel);
|
}
|
}
|
}
|