using vnxbqy.UI;
|
using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class ComposeToolsWin : Window
|
{
|
[SerializeField]
|
GameObject composeUIShowObj;
|
[SerializeField]
|
GameObject noneComposeObj;
|
|
[SerializeField]
|
ScrollerController cellCtrl;
|
|
[Header("固定物品和非固定物品")]
|
[SerializeField] List<ComposeMatCell> fixedAndUnfixeds = new List<ComposeMatCell>();
|
[Header("合成物品")]
|
[SerializeField] List<ComposeMatCell> makeItems = new List<ComposeMatCell>();
|
|
ComposeWinModel.ComposeFirstTypeData firstTypeData;
|
ComposeWinModel.ComposeSecondTypeData secondTypeData;
|
ComposeWinModel.ComposeThirdTypeData thirdTypeData;
|
|
[SerializeField]
|
Text successRateText;
|
|
[SerializeField]
|
Button composeAllBtn;
|
|
[SerializeField]
|
Button composeBtn;
|
|
[SerializeField] UIEffect composeEffect;
|
|
ComposeWinModel _composeWinModel;
|
ComposeWinModel composeWinModel {
|
get { return _composeWinModel ?? (_composeWinModel = ModelCenter.Instance.GetModel<ComposeWinModel>()); }
|
}
|
|
private int curSecondType = 0;
|
private int curThirdType = 0;
|
private int preSecondType = 0;
|
private int preThirdType = 0;
|
[SerializeField] int initSuccessRate = 10000;
|
ItemCompoundConfig compoundModel = null;
|
|
private Dictionary<int, List<int>> fixedItemIndexDict = new Dictionary<int, List<int>>();
|
|
PackModel _playerPack;
|
PackModel playerPack {
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); }
|
}
|
|
AchievementGuideEffect guidEffect = null;
|
bool isJumpTo;
|
protected override void BindController()
|
{
|
cellCtrl.OnRefreshCell += RefreshTypeCell;
|
cellCtrl.lockType = EnhanceLockType.KeepVertical;
|
composeWinModel.ResetModelEvent += ResetModel;
|
|
}
|
|
protected override void AddListeners()
|
{
|
composeBtn.AddListener(OnClickComposeBtn);
|
composeAllBtn.AddListener(OnClickComposeAllBtn);
|
}
|
protected override void OnPreOpen()
|
{
|
DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnComposeAnswer;
|
composeWinModel.UpdateSecondTypeEvent += UpdateSecondType;
|
composeWinModel.UpdateThirdTypeEvent += UpdateThirdType;
|
Display();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
this.transform.SetAsLastSibling();
|
}
|
|
protected override void OnPreClose()
|
{
|
DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer;
|
composeWinModel.UpdateSecondTypeEvent -= UpdateSecondType;
|
composeWinModel.UpdateThirdTypeEvent -= UpdateThirdType;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
#region 新的逻辑
|
private void Display()
|
{
|
composeWinModel.TryGetFirstTypeData((int)ComposeFuncType.Item, 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();
|
}
|
else
|
{
|
if (composeWinModel.composeToolRed.state == RedPointState.Simple)
|
{
|
foreach (var second in composeWinModel.secondTypeRedDict.Keys)
|
{
|
if (composeWinModel.secondTypeRedDict[second].state == RedPointState.Simple)
|
{
|
foreach (var third in composeWinModel.thirdTypeRedDict.Keys)
|
{
|
if (composeWinModel.thirdTypeRedDict[third].state == RedPointState.Simple)
|
{
|
isJumpTo = true;
|
curSecondType = second / 100 % 100;
|
curThirdType = int.Parse(third) % 100;
|
composeWinModel.ResetJumpToModel();
|
break;
|
}
|
}
|
break;
|
}
|
}
|
}
|
}
|
|
}
|
composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Item, curSecondType, curThirdType, out thirdTypeData);
|
if (thirdTypeData != null)
|
{
|
preSecondType = curSecondType;
|
preThirdType = curThirdType;
|
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)
|
{
|
var thirdTypeDatas = thirdTypeDict[third];
|
if (third != 0)
|
{
|
cellCtrl.AddCell(ScrollerDataType.Normal, third);
|
}
|
}
|
}
|
}
|
cellCtrl.Restart();
|
|
composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Item, curSecondType, curThirdType, out thirdTypeData);
|
if (thirdTypeData != null)
|
{
|
noneComposeObj.SetActive(false);
|
composeUIShowObj.SetActive(true);
|
RefreshUI(thirdTypeData.itemCompound);
|
}
|
else
|
{
|
noneComposeObj.SetActive(true);
|
composeUIShowObj.SetActive(false);
|
RefreshUI(null);
|
}
|
}
|
|
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)
|
{
|
RedpointBehaviour behaviour = cell.transform.Find("RedPoint").GetComponent<RedpointBehaviour>();
|
switch (type)
|
{
|
case ScrollerDataType.Header:
|
ComposeWinModel.ComposeSecondTypeData _secondTypeData = null;
|
ComposeFirstTypeCell firstTypeCell = cell.GetComponent<ComposeFirstTypeCell>();
|
composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Item, cell.index, out _secondTypeData);
|
if (_secondTypeData != null)
|
{
|
var thirdTypeDict = _secondTypeData.thirdTypeDict;
|
foreach (var third in thirdTypeDict.Keys)
|
{
|
firstTypeCell.SetDisplay((int)ComposeFuncType.Item, cell.index, third, curSecondType);
|
break;
|
}
|
}
|
break;
|
case ScrollerDataType.Normal:
|
ComposeSecondTypeCell secondTypeCell = cell.GetComponent<ComposeSecondTypeCell>();
|
secondTypeCell.SetDisplay((int)ComposeFuncType.Item, curSecondType, cell.index, curThirdType);
|
break;
|
}
|
}
|
|
private void UpdateSecondType(int secondType)
|
{
|
curThirdType = 0;
|
curSecondType = secondType;
|
composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Item, 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;
|
}
|
}
|
break;
|
}
|
}
|
|
if (preSecondType != curSecondType)
|
{
|
preSecondType = curSecondType;
|
if (guidEffect != null)
|
{
|
AchievementGuideEffectPool.Recycle(guidEffect);
|
guidEffect = null;
|
}
|
}
|
}
|
|
private void UpdateThirdType(int thirdType)
|
{
|
composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Item, curSecondType, thirdType, out thirdTypeData);
|
curThirdType = thirdType;
|
OnClickThirdType();
|
CreateTypeCell();
|
}
|
|
private void OnClickThirdType()
|
{
|
if (thirdTypeData == null) return;
|
|
if (preThirdType != curThirdType)
|
{
|
preThirdType = curThirdType;
|
}
|
}
|
|
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.Nothing, true);
|
}
|
}
|
|
int[] fixedIds = compoundModel.itemID;
|
int[] fixedDisplays = compoundModel.itemDisplay;
|
int[] unfixedIds = compoundModel.unfixedItemID;
|
int[] unfixedDisplays = compoundModel.unfixedItemDisplay;
|
for (int i = 0; i < fixedAndUnfixeds.Count; i++)
|
{
|
var matCell = fixedAndUnfixeds[i];
|
matCell.SetDisplay(compoundModel, NeedMatType.Nothing, true);
|
}
|
|
for (int i = 0; i < fixedDisplays.Length; i++)
|
{
|
var fixedDisplay = fixedDisplays[i];
|
if (fixedDisplay != 0)
|
{
|
var matCell = fixedAndUnfixeds[fixedDisplay - 1];
|
int fixedId = fixedIds[i];
|
matCell.SetDisplay(compoundModel, NeedMatType.fixedItem, false, "", fixedId);
|
}
|
}
|
|
for (int i = 0; i < unfixedDisplays.Length; i++)
|
{
|
var unfixedDisplay = unfixedDisplays[i];
|
if (unfixedDisplay != 0)
|
{
|
var matCell = fixedAndUnfixeds[unfixedDisplay - 1];
|
matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false);
|
}
|
}
|
}
|
#endregion
|
|
private void ResetModel()
|
{
|
curSecondType = 0;
|
curThirdType = 0;
|
compoundModel = null;
|
if (!WindowJumpMgr.Instance.IsJumpState)
|
{
|
preSecondType = 0;
|
preThirdType = 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);
|
composeWinModel.composeBtnRed.state = composeWinModel.secondTypeRedDict[compoundModel.firstType * 100 + compoundModel.secondType].state;
|
UpdateComposeMat();
|
}
|
|
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, composeEffect, 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 OnClickComposeAllBtn()
|
{
|
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>();
|
fixedItemIndexDict.Clear();
|
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();
|
composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, composeEffect, composeCountlist[0]);
|
}
|
|
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);
|
}
|
}
|
}
|