using vnxbqy.UI;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class ComposeWingsWin : 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>();
|
|
[Header("合成物品目标特效")]
|
[SerializeField] List<UIEffect> composeTargetEffects = new List<UIEffect>();
|
|
[SerializeField]
|
Button helpBtn;
|
|
[SerializeField]
|
Button composeBtn;
|
|
[SerializeField] GameObject composeItemSelectObj;
|
|
[SerializeField] UIEffect oneMatEffect;
|
[SerializeField] UIEffect twoMatEffect;
|
[SerializeField] UIEffect threeMatEffect;
|
[SerializeField] UIEffect successEffect;
|
[SerializeField] UIEffect failMatEffect;
|
|
ComposeWinModel composeWinModel { get { return ModelCenter.Instance.GetModel<ComposeWinModel>(); } }
|
ComposeWinModel.ComposeFirstTypeData firstTypeData;
|
ComposeWinModel.ComposeSecondTypeData secondTypeData;
|
ComposeWinModel.ComposeThirdTypeData thirdTypeData;
|
Dictionary<int, List<int>> fixedItemIndexDict = new Dictionary<int, List<int>>();
|
|
private int curSecondType = 0;
|
private int curThirdType = 0;
|
private int preSecondType = 0;
|
private int preThirdType = 0;
|
ItemCompoundConfig compoundModel = null;
|
|
SelectEquipModel selectModel { get { return ModelCenter.Instance.GetModel<SelectEquipModel>(); } }
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
|
AchievementGuideEffect guidEffect = null;
|
|
protected override void BindController()
|
{
|
cellCtrl.OnRefreshCell += RefreshTypeCell;
|
|
cellCtrl.lockType = EnhanceLockType.KeepVertical;
|
composeWinModel.ResetModelEvent += ResetModel;
|
|
}
|
|
protected override void AddListeners()
|
{
|
composeBtn.AddListener(OnClickComposeBtn);
|
}
|
|
protected override void OnPreOpen()
|
{
|
composeWinModel.UpdateSecondTypeEvent += UpdateSecondType;
|
composeWinModel.UpdateThirdTypeEvent += UpdateThirdType;
|
composeWinModel.UpdateReduceEvent += UpdateReduce;
|
selectModel.UpdateSelectEvent += UpdateSelect;
|
DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent += OnComposeAnswer;
|
UIEventTrigger.Get(helpBtn.gameObject).OnDown = OnClickHelpBtn;
|
UIEventTrigger.Get(helpBtn.gameObject).OnUp = OnDownUp;
|
Display();
|
}
|
|
protected override void OnAfterOpen()
|
{
|
cellCtrl.vertical = true;
|
this.transform.SetAsLastSibling();
|
}
|
|
protected override void OnPreClose()
|
{
|
DTCA814_tagMCMakeItemAnswer.MakeItemAnswerEvent -= OnComposeAnswer;
|
composeWinModel.UpdateReduceEvent -= UpdateReduce;
|
composeWinModel.UpdateSecondTypeEvent -= UpdateSecondType;
|
composeWinModel.UpdateThirdTypeEvent -= UpdateThirdType;
|
selectModel.UpdateSelectEvent -= UpdateSelect;
|
}
|
|
protected override void OnAfterClose()
|
{
|
|
}
|
|
#region 新的逻辑
|
private void Display()
|
{
|
composeWinModel.TryGetFirstTypeData((int)ComposeFuncType.Wings, 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.Wings, 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.Wings, curSecondType, curThirdType, out thirdTypeData);
|
if (thirdTypeData != null)
|
{
|
noneComposeObj.SetActive(false);
|
composeUIShowObj.SetActive(true);
|
RefreshUI(thirdTypeData.itemCompound);
|
}
|
else
|
{
|
RefreshUI(null);
|
noneComposeObj.SetActive(true);
|
composeUIShowObj.SetActive(false);
|
}
|
}
|
|
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.Wings, cell.index, out _secondTypeData);
|
if (_secondTypeData != null)
|
{
|
var thirdTypeDict = _secondTypeData.thirdTypeDict;
|
foreach (var third in thirdTypeDict.Keys)
|
{
|
firstTypeCell.SetDisplay((int)ComposeFuncType.Wings, cell.index, third, curSecondType);
|
break;
|
}
|
}
|
break;
|
case ScrollerDataType.Normal:
|
ComposeSecondTypeCell secondTypeCell = cell.GetComponent<ComposeSecondTypeCell>();
|
secondTypeCell.SetDisplay((int)ComposeFuncType.Wings, curSecondType, cell.index, curThirdType);
|
break;
|
}
|
}
|
|
private void UpdateSecondType(int secondType)
|
{
|
curThirdType = 0;
|
curSecondType = secondType;
|
composeWinModel.TryGetSecondTypeData((int)ComposeFuncType.Wings, secondType, out secondTypeData);
|
OnClickSecondType();
|
CreateTypeCell();
|
JumpIndex();
|
}
|
|
private void OnClickSecondType()
|
{
|
if (secondTypeData == null) return;
|
|
var thirdTypeDict = secondTypeData.thirdTypeDict;
|
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;
|
selectModel.ClearSelectModel();
|
if (guidEffect != null)
|
{
|
AchievementGuideEffectPool.Recycle(guidEffect);
|
guidEffect = null;
|
}
|
}
|
}
|
|
private void UpdateThirdType(int thirdType)
|
{
|
composeWinModel.TryGetThirdTypeData((int)ComposeFuncType.Wings, curSecondType, thirdType, out thirdTypeData);
|
curThirdType = thirdType;
|
OnClickThirdType();
|
CreateTypeCell();
|
}
|
|
private void OnClickThirdType()
|
{
|
if (thirdTypeData == null) return;
|
|
if (preThirdType != curThirdType)
|
{
|
preThirdType = curThirdType;
|
}
|
selectModel.ClearSelectModel();
|
}
|
|
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[] 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, UIHelper.ReplaceNewLine(Language.Get("ComposeWin_PutInText_1")));
|
}
|
}
|
}
|
|
private void UpdateSelect(ComposeMatCell matCell, int itemIndex, SelectItemType selectType)
|
{
|
switch (selectType)
|
{
|
case SelectItemType.unfixed:
|
matCell.SetDisplay(compoundModel, NeedMatType.unfixedItem, false, "", 0, itemIndex);
|
break;
|
}
|
}
|
|
private void UpdateReduce(ComposeMatCell matCell, NeedMatType matType)
|
{
|
switch (matType)
|
{
|
case NeedMatType.unfixedItem:
|
matCell.SetDisplay(compoundModel, matType, false,
|
UIHelper.ReplaceNewLine(Language.Get("ComposeWin_PutInText_1")));
|
break;
|
}
|
}
|
|
#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;
|
|
composeWinModel.SetCurComposeModel(compoundModel);
|
UpdateComposeMat();
|
composeItemSelectObj.SetActive(compoundModel.secondType < 4);
|
}
|
|
private void OnClickComposeBtn()
|
{
|
if (compoundModel == null) return;
|
|
bool isTrailer = composeWinModel.IsTrailerByLevel(compoundModel);
|
if (isTrailer)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("FuncOpenLv", compoundModel.levelNeed));
|
return;
|
}
|
|
SetFixedMatIndex();
|
composeWinModel.SendComposeRequest(compoundModel, fixedItemIndexDict, GetPlayMatEffect(), 1);
|
}
|
|
private void SetFixedMatIndex()
|
{
|
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++)
|
{
|
List<int> itemIndexlist = singlePack.GetItemIndexsAppointedCount(fixedIds[i], fixedCounts[i]);
|
if (itemIndexlist != null)
|
{
|
fixedItemIndexDict.Add(fixedIds[i], itemIndexlist);
|
}
|
}
|
}
|
|
private UIEffect GetPlayMatEffect()
|
{
|
if (compoundModel == null) return null;
|
|
int[] fixedIds = compoundModel.itemID;
|
int matTypeCnt = compoundModel.unfixedItemCount + fixedIds.Length;
|
switch (matTypeCnt)
|
{
|
case 1:
|
return oneMatEffect;
|
case 2:
|
return twoMatEffect;
|
case 3:
|
return threeMatEffect;
|
}
|
return null;
|
}
|
|
private void OnComposeAnswer(HA814_tagMCMakeItemAnswer answer)
|
{
|
if (answer.MakeType != (int)MakeType.ItemCompound)
|
return;
|
|
if (answer.Result == 1)
|
{
|
successEffect.Play();
|
int[] makeIds = compoundModel.makeID;
|
for (int i = 0; i < composeTargetEffects.Count; i++)
|
{
|
var targetEffect = composeTargetEffects[i];
|
if (i < makeIds.Length)
|
{
|
if (makeIds[i] == answer.MakeItemID)
|
{
|
targetEffect.Play();
|
break;
|
}
|
}
|
}
|
}
|
else
|
{
|
failMatEffect.Play();
|
}
|
|
RefreshUI(compoundModel);
|
selectModel.ClearSelectModel();
|
}
|
|
private void OnDownUp(GameObject go)
|
{
|
WindowCenter.Instance.Close<ComposeHelpWin>();
|
}
|
|
private void OnClickHelpBtn(GameObject go)
|
{
|
if (compoundModel != null)
|
{
|
WindowCenter.Instance.Open<ComposeHelpWin>();
|
}
|
}
|
|
}
|
}
|