68 lines
2.4 KiB
C#
68 lines
2.4 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scripts.UI.JigsawPuzzle
|
|
{
|
|
public class JigsawPuzzleRewardPanel : BasePanel
|
|
{
|
|
private Image p_img_picture;
|
|
private Button btn_play;
|
|
private RewardItemNew[] rewards;
|
|
|
|
private Action _closeCallback;
|
|
|
|
private void Awake()
|
|
{
|
|
btn_play = gameObject.FindChildGameObject(nameof(btn_play)).GetComponentInChildren<Button>();
|
|
btn_play.onClick.AddListener(OnClick_btn_play);
|
|
p_img_picture = gameObject.FindChildGameObject(nameof(p_img_picture)).GetComponent<Image>();
|
|
rewards = this.gameObject.GetComponentsInChildren<RewardItemNew>(false);
|
|
foreach (RewardItemNew item in rewards)
|
|
{
|
|
item?.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
public void SetData(EventJigsawPuzzlePicture pictureConfig, Action closeCallback = null)
|
|
{
|
|
_closeCallback = closeCallback;
|
|
ShowUI(pictureConfig);
|
|
}
|
|
|
|
private void ShowUI(EventJigsawPuzzlePicture pictureConfig)
|
|
{
|
|
if (pictureConfig == null) return;
|
|
var data = GContext.container.Resolve<JigsawPuzzleManager>()?.Data;
|
|
var itemDatas = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdLureInflation(data?.InflationRate, pictureConfig.DropID);
|
|
if (itemDatas == null) return;
|
|
for (int i = 0; i < itemDatas.Count && i < rewards.Length; i++)
|
|
{
|
|
if (itemDatas[i] == null) continue;
|
|
rewards[i].SetData(itemDatas[i]);
|
|
rewards[i].gameObject.SetActive(true);
|
|
}
|
|
_ = GContext.container.Resolve<IUIService>().SetImageSprite(p_img_picture, pictureConfig.PictureName);
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
_closeCallback?.Invoke();
|
|
btn_play.onClick.RemoveAllListeners();
|
|
base.OnDestroy();
|
|
}
|
|
|
|
private async void OnClick_btn_play()
|
|
{
|
|
btn_play.gameObject.SetActive(false);
|
|
for (int i = 1; i < rewards.Length; i++)
|
|
{
|
|
_ = rewards[i].ParticleAttractor();
|
|
}
|
|
await rewards[0].ParticleAttractor();
|
|
UIManager.Instance.DestroyUI(UITypes.EventJigsawPuzzleRewardPopupPanel);
|
|
}
|
|
}
|
|
} |