using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
using System.Collections;
|
|
namespace Snxxz.UI
|
{
|
public class RoleElixirTipWin : MonoBehaviour
|
{
|
[SerializeField] ScrollerController ctrl;
|
[SerializeField] CanvasGroup canvas;
|
[SerializeField] SortMakeDrugTable drugTable;
|
[SerializeField] Transform tableArrow;
|
[SerializeField] Button selectBtn;
|
PlayerPackModel _playerPack;
|
PlayerPackModel playerPack
|
{
|
get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
|
}
|
BlastFurnaceModel blastModel { get { return ModelCenter.Instance.GetModel<BlastFurnaceModel>(); } }
|
|
List<AttrFruitConfig> fruitlist;
|
public static int makeUseId = 0;
|
[SerializeField] float offest = 50;
|
int presentIndex = 0;
|
private void Awake()
|
{
|
selectBtn.AddListener(ClickDrugSelect);
|
}
|
|
private void OnEnable()
|
{
|
blastModel.sortDruglist.Clear();
|
ctrl.OnRefreshCell += RefreshMakeDrugCell;
|
drugTable.onSortCloseEvent += CloseDrugSort;
|
drugTable.onSelectSortEvent += CreateCell;
|
ctrl.lockType = EnhanceLockType.KeepVertical;
|
canvas.alpha = 0;
|
presentIndex = 0;
|
drugTable.gameObject.SetActive(false);
|
drugTable.SetDefault();
|
CreateCell();
|
CheckJumpToModel();
|
ModelCenter.Instance.GetModel<BlastFurnaceModel>().IsMakeDrugWin = true;
|
CloseDrugSort();
|
}
|
|
private void OnDisable()
|
{
|
drugTable.onSortCloseEvent -= CloseDrugSort;
|
ctrl.OnRefreshCell -= RefreshMakeDrugCell;
|
drugTable.onSelectSortEvent -= CreateCell;
|
ModelCenter.Instance.GetModel<BlastFurnaceModel>().IsMakeDrugWin = false;
|
}
|
|
private void ClickDrugSelect()
|
{
|
tableArrow.localRotation = Quaternion.Euler(0, 0, 0);
|
if (!drugTable.gameObject.activeInHierarchy)
|
{
|
drugTable.gameObject.SetActive(true);
|
}
|
}
|
|
private void CloseDrugSort()
|
{
|
tableArrow.localRotation = Quaternion.Euler(0, 0, 180);
|
}
|
|
private void CheckJumpToModel()
|
{
|
if(AchievementGoto.guideAchievementId != 0)
|
{
|
SuccessConfig successConfig = SuccessConfig.Get(AchievementGoto.guideAchievementId);
|
if(successConfig.Type == 94 && successConfig.Jump == (int)JumpUIType.MakeDrug)
|
{
|
bool isCanUse = false;
|
for (int i = 0; i < fruitlist.Count; i++)
|
{
|
if(successConfig.Condition != null && successConfig.Condition.Length > 0)
|
{
|
if (fruitlist[i].ID == successConfig.Condition[0])
|
{
|
int haveCnt = playerPack.GetItemCountByID(PackType.Item, fruitlist[i].ID);
|
if(haveCnt > 0)
|
{
|
isCanUse = true;
|
}
|
presentIndex = i;
|
ctrl.JumpIndex(i);
|
ctrl.m_Scorller.RefreshActiveCellViews();
|
break;
|
}
|
}
|
|
}
|
if(!isCanUse)
|
{
|
ServerTipDetails.DisplayNormalTip(Language.Get("RoleElixir3"));
|
}
|
AchievementGoto.guideAchievementId = 0;
|
}
|
else
|
{
|
for (int i = 0; i < fruitlist.Count; i++)
|
{
|
int haveCnt = playerPack.GetItemCountByID(PackType.Item, fruitlist[i].ID);
|
if (haveCnt > 0)
|
{
|
presentIndex = i;
|
ctrl.JumpIndex(i);
|
ctrl.m_Scorller.RefreshActiveCellViews();
|
break;
|
}
|
}
|
}
|
}
|
else
|
{
|
if(makeUseId != 0)
|
{
|
for (int i = 0; i < fruitlist.Count; i++)
|
{
|
if (fruitlist[i].ID == makeUseId)
|
{
|
presentIndex = i;
|
ctrl.JumpIndex(i);
|
ctrl.m_Scorller.RefreshActiveCellViews();
|
break;
|
}
|
}
|
makeUseId = 0;
|
}
|
else
|
{
|
ctrl.JumpIndex(0);
|
}
|
}
|
|
StartCoroutine(SetOffestPos());
|
}
|
|
private IEnumerator SetOffestPos()
|
{
|
yield return null;
|
if (presentIndex != 0)
|
{
|
ctrl.JumpIndex(-offest, 0, EnhancedUI.EnhancedScroller.EnhancedScroller.TweenType.immediate);
|
}
|
canvas.alpha = 1;
|
}
|
|
private void CreateCell()
|
{
|
fruitlist = playerPack.GetDrugOrderByCnt();
|
ctrl.Refresh();
|
for (int i = 0; i < fruitlist.Count; i++)
|
{
|
int[] recipeLvs = fruitlist[i].RecipeLv;
|
if(recipeLvs != null)
|
{
|
for(int j= 0; j < recipeLvs.Length; j++)
|
{
|
if(blastModel.sortDruglist.Contains(recipeLvs[j]))
|
{
|
ctrl.AddCell(ScrollerDataType.Header, i);
|
break;
|
}
|
}
|
}
|
|
}
|
ctrl.Restart();
|
|
}
|
|
private void RefreshMakeDrugCell(ScrollerDataType type, CellView cell)
|
{
|
AttrFruitConfig fruitConfig = fruitlist[cell.index];
|
MakeDrugCell drugCell = cell.GetComponent<MakeDrugCell>();
|
drugCell.InitModel(fruitConfig.ID);
|
}
|
|
}
|
}
|