287 lines
9.6 KiB
C#
287 lines
9.6 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using game;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
|
|
public class HomeBubbleTask : MonoBehaviour
|
|
{
|
|
Button btn_bubble_task;
|
|
Image bg_bar;
|
|
Image bg_bar1;
|
|
Image bg_bar2;
|
|
[HideInInspector]
|
|
public Image bar;
|
|
Image bar1;
|
|
Image bar2;
|
|
RectTransform _rect;
|
|
RectTransform _rect1;
|
|
RectTransform _rect2;
|
|
GameObject info_1;
|
|
GameObject info_2;
|
|
RectTransform bar_rect;
|
|
RectTransform bar_rect_1;
|
|
RectTransform bar_rect_2;
|
|
|
|
RewardItemNew rewardItemBubble;
|
|
RewardItemNew rewardItem_1;
|
|
RewardItemNew rewardItem_2;
|
|
[HideInInspector]
|
|
public TMP_Text text_progress;
|
|
TMP_Text text_time;
|
|
private CollectingTargetReward collectingTarget;
|
|
FishingEventData _fishingEventData;
|
|
Tables _tables;
|
|
|
|
BubbleTaskInfo_2 bubbleTaskInfo;
|
|
|
|
public float barTimer = 0.38f;
|
|
public float animationTimer = 0.667f;
|
|
public float changeDelayTimer = 0.616f;
|
|
float showTime = 0.16f; //显示时间
|
|
private void Awake()
|
|
{
|
|
showTime = animationTimer - changeDelayTimer;
|
|
bubbleTaskInfo = GetComponent<BubbleTaskInfo_2>();
|
|
_fishingEventData = GContext.container.Resolve<FishingEventData>();
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
btn_bubble_task = transform.GetComponent<Button>();
|
|
bg_bar = transform.Find("bg_bar").GetComponent<Image>();
|
|
bg_bar1 = transform.Find("info_1/bg_bar").GetComponent<Image>();
|
|
bg_bar2 = transform.Find("info_2/bg_bar").GetComponent<Image>();
|
|
bar = transform.Find("bg_bar/bar").GetComponent<Image>();
|
|
bar1 = transform.Find("info_1/bg_bar/bar").GetComponent<Image>();
|
|
bar2 = transform.Find("info_2/bg_bar/bar").GetComponent<Image>();
|
|
_rect = transform.Find("bg_bar/bar").GetComponent<RectTransform>();
|
|
bar_rect = transform.Find("bg_bar").GetComponent<RectTransform>();
|
|
info_1 = transform.Find("info_1").gameObject;
|
|
info_2 = transform.Find("info_2").gameObject;
|
|
_rect1 = transform.Find("info_1/bg_bar/bar").GetComponent<RectTransform>();
|
|
_rect2 = transform.Find("info_2/bg_bar/bar").GetComponent<RectTransform>();
|
|
bar_rect_1 = transform.Find("info_1/bg_bar").GetComponent<RectTransform>();
|
|
bar_rect_2 = transform.Find("info_2/bg_bar").GetComponent<RectTransform>();
|
|
|
|
rewardItemBubble = transform.Find("info_1/btn_reward").GetComponent<RewardItemNew>();
|
|
rewardItem_1 = transform.Find("info_2/btn_reward_1").GetComponent<RewardItemNew>();
|
|
rewardItem_2 = transform.Find("info_2/btn_reward_2").GetComponent<RewardItemNew>();
|
|
|
|
text_progress = transform.Find("bg_bar/text_progress").GetComponent<TMP_Text>();
|
|
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
|
|
}
|
|
void Start()
|
|
{
|
|
btn_bubble_task.onClick.AddListener(OnClickTarget);
|
|
}
|
|
|
|
|
|
async void OnClickTarget()
|
|
{
|
|
var collectingTargetInit = _fishingEventData.collectingTargetInit;
|
|
if (collectingTargetInit != null)
|
|
{
|
|
//ExitAutoFishing();
|
|
//退出自动钓鱼
|
|
btn_bubble_task.enabled = false;
|
|
bool isCanEnter = await _fishingEventData.IsDownLoadPkg();
|
|
if (isCanEnter)
|
|
{
|
|
await UIManager.Instance.ShowUI(UITypes.FishingTargetPopupPanel);
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(false, () =>
|
|
{
|
|
_ = UIManager.Instance.ShowUI(UITypes.FishingTargetPopupPanel);
|
|
});
|
|
|
|
}
|
|
btn_bubble_task.enabled = true;
|
|
}
|
|
}
|
|
public void SetCollectingTargetTime(string timeStr)
|
|
{
|
|
text_time.text = timeStr;
|
|
}
|
|
|
|
|
|
public void PlayEventTargetAdd(CollectingTargetReward collecting, int curCount, int endCount)
|
|
{
|
|
//Vector3 startPos = fishingData.image_extra_pos;
|
|
this.collectingTarget = collecting;
|
|
int curValue = curCount;
|
|
|
|
|
|
bar.DOFillAmount(endCount / (float)collectingTarget.TokenRequired, barTimer);
|
|
DOTween.To(() => curValue, x => curValue = x, endCount, barTimer).OnUpdate(() =>
|
|
{
|
|
text_progress.text = $"{curValue}/{collectingTarget.TokenRequired}";
|
|
}).OnComplete(() =>
|
|
{
|
|
//require.transform.localScale = Vector3.one;
|
|
if (_fishingEventData.preCollectingTarget != null)
|
|
{
|
|
TargetUp();
|
|
}
|
|
});
|
|
//进度条增加
|
|
}
|
|
|
|
public void CollectingTargetNext()
|
|
{
|
|
collectingTarget = _fishingEventData.collectingTarget;
|
|
if (collectingTarget != null)
|
|
{
|
|
var collectingTargetInit = _fishingEventData.collectingTargetInit;
|
|
bubbleTaskInfo.SetInfo(collectingTargetInit);
|
|
|
|
if (_fishingEventData.preCollectingTarget != null)
|
|
{
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
List<ItemData> itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(collectingTarget.DropID);
|
|
if (itemData != null && itemData.Count > 0)
|
|
{
|
|
SetCollectingTargetRewardIcon(itemData);
|
|
}
|
|
int curCount = _fishingEventData.GetCurCollectingTarget();
|
|
if (curCount >= collectingTarget.TokenRequired)
|
|
{
|
|
curCount = collectingTarget.TokenRequired;
|
|
text_progress.text = LocalizationMgr.GetText("UI_EventRankPopupPanel_15");
|
|
}
|
|
else
|
|
{
|
|
text_progress.text = $"{curCount}/{collectingTarget.TokenRequired}";
|
|
}
|
|
bar.fillAmount = curCount / (float)collectingTarget.TokenRequired;
|
|
}
|
|
}
|
|
}
|
|
void TargetUp()
|
|
{
|
|
if (_fishingEventData.preCollectingTarget == null || _fishingEventData.preCollectingTarget.Count == 0)
|
|
{
|
|
collectingTarget = _fishingEventData.collectingTarget;
|
|
PlayUpEndAni();
|
|
}
|
|
else
|
|
{
|
|
collectingTarget = _fishingEventData.preCollectingTarget.Dequeue();
|
|
PlayUpAni();
|
|
}
|
|
|
|
}
|
|
|
|
void ChangeReward()
|
|
{
|
|
List<ItemData> itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(collectingTarget.DropID);
|
|
if (itemData is { Count: > 0 })
|
|
{
|
|
//await Awaiters.Seconds(0.1f);
|
|
SetCollectingTargetRewardIcon(itemData);
|
|
}
|
|
}
|
|
|
|
async void PlayUpAni()
|
|
{
|
|
int endCount = collectingTarget.TokenRequired;
|
|
btn_bubble_task.GetComponent<Animation>().Play("bubble_task");
|
|
await Awaiters.Seconds(changeDelayTimer);
|
|
ChangeReward();
|
|
bar.fillAmount = 0;
|
|
await Awaiters.Seconds(showTime);
|
|
if (this == null)
|
|
{
|
|
return;
|
|
}
|
|
bar.DOFillAmount(1, barTimer);
|
|
int curValue = 0;
|
|
DOTween.To(() => curValue, x => curValue = x, endCount, barTimer).OnUpdate(() =>
|
|
{
|
|
text_progress.text = $"{curValue}/{collectingTarget.TokenRequired}";
|
|
})
|
|
.OnComplete(() =>
|
|
{
|
|
TargetUp();
|
|
});
|
|
}
|
|
|
|
async void PlayUpEndAni()
|
|
{
|
|
int endCount = _fishingEventData.GetCurCollectingTarget();
|
|
if (endCount >= collectingTarget.TokenRequired)
|
|
{
|
|
btn_bubble_task.GetComponent<Animation>().Play("bubble_task_final");
|
|
|
|
text_progress.text = LocalizationMgr.GetText("UI_EventRankPopupPanel_15");
|
|
}
|
|
else
|
|
{
|
|
btn_bubble_task.GetComponent<Animation>().Play("bubble_task");
|
|
await Awaiters.Seconds(changeDelayTimer);
|
|
ChangeReward();
|
|
bar.fillAmount = 0;
|
|
await Awaiters.Seconds(showTime);
|
|
if (this == null)
|
|
{
|
|
return;
|
|
}
|
|
bar.DOFillAmount(endCount / (float)collectingTarget.TokenRequired, barTimer);
|
|
int curValue = 0;
|
|
DOTween.To(() => curValue, x => curValue = x, endCount, barTimer).OnUpdate(() =>
|
|
{
|
|
text_progress.text = $"{curValue}/{collectingTarget.TokenRequired}";
|
|
});
|
|
}
|
|
GContext.Publish(new ShowData());
|
|
}
|
|
|
|
int showCount = 0;
|
|
|
|
public void SetCollectingTargetRewardIcon(List<ItemData> itemDatas)
|
|
{
|
|
if (itemDatas != null)
|
|
{
|
|
int count = itemDatas.Count;
|
|
if (showCount != count)
|
|
{
|
|
info_1.SetActive(count == 1);
|
|
info_2.SetActive(count != 1);
|
|
showCount = count;
|
|
if (count == 1)
|
|
{
|
|
bar_rect.sizeDelta = bar_rect_1.sizeDelta;
|
|
bg_bar.sprite = bg_bar1.sprite;
|
|
bar.sprite = bar1.sprite;
|
|
_rect.sizeDelta = _rect1.sizeDelta;
|
|
|
|
}
|
|
else
|
|
{
|
|
bar_rect.sizeDelta = bar_rect_2.sizeDelta;
|
|
bg_bar.sprite = bg_bar2.sprite;
|
|
bar.sprite = bar2.sprite;
|
|
_rect.sizeDelta = _rect2.sizeDelta;
|
|
}
|
|
}
|
|
if (count == 1)
|
|
{
|
|
rewardItemBubble.SetData(itemDatas[0], isCanClick: false);
|
|
}
|
|
else
|
|
{
|
|
rewardItem_1.SetData(itemDatas[0], isCanClick: false);
|
|
rewardItem_2.SetData(itemDatas[1], isCanClick: false);
|
|
}
|
|
}
|
|
}
|
|
}
|