208 lines
6.8 KiB
C#
208 lines
6.8 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UniRx;
|
|
using System;
|
|
using System.Collections;
|
|
using DG.Tweening;
|
|
public class AvatarEvent
|
|
{
|
|
public Transform avatar;
|
|
public GameObject[] fx_fishingrods;
|
|
public RenderTexture rt;
|
|
}
|
|
public class FishingRodBagPanel : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
List<TMP_Text> text_num;
|
|
Button btn_close;
|
|
GameObject item;
|
|
Transform Content;
|
|
List<RodBagItem> rodItems = new List<RodBagItem>();
|
|
private RodBagItem currentEqRodItem;
|
|
PlayerFishData playerFishData;
|
|
IDisposable disposable;
|
|
FishingRodUpSystem upSystem;
|
|
Transform guidance;
|
|
RodBagImprove rodBagImprove;
|
|
|
|
public AnimationCurve easeCurve;
|
|
public AnimationCurve FadeEaseCurve;
|
|
[SerializeField]
|
|
private CanvasGroup cg;
|
|
public IconRodRoot iconRod;
|
|
public RawImage rawImageRod;
|
|
|
|
private void Awake()
|
|
{
|
|
GContext.container.Unregister<FishingRodUpSystem>();
|
|
upSystem = new FishingRodUpSystem();
|
|
UIManager.Instance.panelStack.Push(UITypes.FishingRodBagPanel);
|
|
GContext.container.RegisterInstance(upSystem);
|
|
btn_close = transform.Find("bottom/btn_close").GetComponent<Button>();
|
|
Content = transform.Find("root/ScrollView/Viewport/Content");
|
|
item = transform.Find("root/ScrollView/Viewport/Content/Item").gameObject;
|
|
item.SetActive(false);
|
|
playerFishData = GContext.container.Resolve<PlayerFishData>();
|
|
disposable = upSystem.Subscribe<RefreshRodBagEvent>(Refresh);
|
|
guidance = transform.Find("root/Guidance");
|
|
rodBagImprove = transform.Find("root/benifit").GetComponent<RodBagImprove>();
|
|
|
|
}
|
|
private void Start()
|
|
{
|
|
iconRod.SetRawImage(rawImageRod);
|
|
|
|
AvatarEvent avatarEvent = new AvatarEvent();
|
|
avatarEvent.avatar = iconRod.avatar;
|
|
avatarEvent.fx_fishingrods = iconRod.fx_fishingrods;
|
|
avatarEvent.rt = iconRod.rt;
|
|
upSystem.bagPanel = avatarEvent;
|
|
GContext.Publish(new InGradeAquariumEvent());
|
|
|
|
GContext.Publish(new HideHomePanelEvent());
|
|
btn_close.onClick.AddListener(async () =>
|
|
{
|
|
if (UIManager.Instance.panelStack.Count > 0)
|
|
{
|
|
UIManager.Instance.panelStack.Pop();
|
|
}
|
|
if (UIManager.Instance.panelStack.Count > 0)
|
|
{
|
|
UIType topUI = UIManager.Instance.panelStack.Pop();
|
|
await UIManager.Instance.ShowUI(topUI);
|
|
UIManager.Instance.DestroyUI(UITypes.FishingRodBagPanel);
|
|
}
|
|
else
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.FishingRodBagPanel);
|
|
GContext.Publish(new RestartShowHomeUIEvent());
|
|
}
|
|
GContext.Publish(new ActChangeRodDataEvent(currentEqRodItem.data.config.ID));
|
|
});
|
|
InitRodList();
|
|
SetSelect();
|
|
}
|
|
/// <summary>
|
|
/// 新手引导,但现在没有选中态,延时选中
|
|
/// </summary>
|
|
async void SetSelect()
|
|
{
|
|
int index = currentEqRodItem.data.sort;
|
|
GuideDataCenter guideDataCenter = GContext.container.Resolve<GuideDataCenter>();
|
|
bool isGuide = guideDataCenter.InspectTriggerGuide("FishingRodBagPanel");
|
|
RodItemData rodItemData;
|
|
int shopSelectId = playerFishData.RodSelectedInPack;
|
|
if (isGuide)
|
|
{
|
|
GroupName guideName = guideDataCenter.curGroupDefine.groupName;
|
|
shopSelectId = 30003;
|
|
if (guideName == GroupName.BuyPack01)
|
|
{
|
|
shopSelectId = 40001;
|
|
}
|
|
}
|
|
if (shopSelectId > 0)
|
|
{
|
|
for (int i = 0; i < upSystem.rodItemDatas.Count; i++)
|
|
{
|
|
rodItemData = upSystem.rodItemDatas[i];
|
|
if (rodItemData.config.ID == shopSelectId)
|
|
{
|
|
index = rodItemData.sort;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
await Awaiters.Seconds(0.4f);
|
|
guidance.position = rodItems[index].transform.position;
|
|
}
|
|
void Refresh(RefreshRodBagEvent refreshRodBagEvent)
|
|
{
|
|
rodBagImprove.UpLevel();
|
|
InitRodList();
|
|
}
|
|
void InitRodList()
|
|
{
|
|
GameObject[] gameObjects = iconRod.fx_fishingrods;
|
|
|
|
for (int i = 0; i < gameObjects.Length; i++)
|
|
{
|
|
gameObjects[i].SetActive(i == 2);
|
|
}
|
|
upSystem.InitRodList();
|
|
for (int i = 0; i < text_num.Count; i++)
|
|
{
|
|
int hasCount = upSystem.hasRodID.TryGetValue(i + upSystem.StartQuality, out List<int> rodIDs) ? rodIDs.Count : 0;
|
|
text_num[i].text = $"{hasCount}/{upSystem.allCount[i + upSystem.StartQuality]}";
|
|
}
|
|
Show();
|
|
}
|
|
void Show()
|
|
{
|
|
for (int i = 0; i < upSystem.rodItemDatas.Count; i++)
|
|
{
|
|
RodItemData rodItemData = upSystem.rodItemDatas[i];
|
|
rodItemData.sort = i;
|
|
|
|
RodBagItem rodItem;
|
|
if (i < rodItems.Count)
|
|
{
|
|
rodItem = rodItems[i];
|
|
rodItem.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
GameObject go = Instantiate(item, Content);
|
|
rodItem = go.GetComponent<RodBagItem>();
|
|
rodItems.Add(rodItem);
|
|
}
|
|
rodItem.Init(rodItemData, playerFishData.CheckUpgrade(rodItemData.config) || playerFishData.CheckRodUpLevel(rodItemData.config));
|
|
rodItem.onClick = OnRodItemClick;
|
|
if (rodItemData.config.ID == GContext.container.Resolve<PlayerData>().equipRodID)
|
|
{
|
|
currentEqRodItem = rodItem;
|
|
currentEqRodItem.SetEquipped(playerFishData.CheckRodUpLevel(rodItemData.config));
|
|
}
|
|
}
|
|
StartCoroutine(ShowFish());
|
|
}
|
|
Tween fadeTween;
|
|
IEnumerator ShowFish()
|
|
{
|
|
fadeTween.Kill();
|
|
cg.alpha = 0f;
|
|
fadeTween = cg.DOFadeAlpha(1f, 0.5f).SetEase(FadeEaseCurve);
|
|
|
|
for (int i = 0; i < rodItems.Count; i++)
|
|
{
|
|
rodItems[i].gameObject.SetActive(true);
|
|
|
|
rodItems[i].transform.localScale = Vector3.zero;
|
|
rodItems[i].transform.DOScale(Vector3.one, 0.2f).SetEase(easeCurve);
|
|
|
|
if (i <= 3)
|
|
{
|
|
yield return new WaitForSeconds(0.01f * i);
|
|
}
|
|
else
|
|
yield return new WaitForSeconds(0.04f);
|
|
}
|
|
}
|
|
async void OnRodItemClick(RodBagItem rodItem)
|
|
{
|
|
upSystem.SelectIndex = rodItem.data.sort;
|
|
await UIManager.Instance.ShowUI(UITypes.FishingRodPanel);
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
disposable?.Dispose();
|
|
UIManager.Instance.DestroyUI(UITypes.FishingRodRewardPopupPanel);
|
|
GContext.container.Unregister<FishingRodUpSystem>();
|
|
GContext.Publish(new InGradeAquariumEvent() { type = 1 });
|
|
}
|
|
}
|