266 lines
10 KiB
C#
266 lines
10 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace EventMowForTreasure
|
|
{
|
|
public class EventMowForTreasurePanel : BasePanel
|
|
{
|
|
#region UI_ELEMENTS
|
|
|
|
//top ui
|
|
private Button btn_questionmark;
|
|
private TMP_Text text_time;
|
|
private item_sanddig_tips _itemSanddigTips;
|
|
private EventMowForTreasure_CollectionCell[] _collectionCells;
|
|
|
|
//botom ui
|
|
private EventMowForTreasure_ToolPropCell[] _toolPropCells;
|
|
private Button btn_close;
|
|
private RewardFlyBatchController _batchController;
|
|
private GameObject _rewardGameObject;
|
|
|
|
private GameObject fingerObj;
|
|
private GameObject _maskGameObject;
|
|
#endregion UI_ELEMENTS
|
|
[Header("collection")]
|
|
[SerializeField] private float collectionRewardStartIconSize = 100f;
|
|
[SerializeField] private float collectionRewardTargetIconSize = 100f;
|
|
[Header("guidance")]
|
|
[SerializeField] [Min(1)] private int showGuideTimes = 5;
|
|
[SerializeField] private Vector2 finalRewardGuideOffset = Vector2.zero;
|
|
[Header("finalReward")]
|
|
[SerializeField] private Vector2 finalRewardTipsOffset = Vector2.zero;
|
|
[SerializeField] private float delayHideTips = 0.5f;
|
|
private EventMowForTreasureManager _manager;
|
|
|
|
private EventMowForTreasureManager Manager =>
|
|
_manager ??= GContext.container.Resolve<EventMowForTreasureManager>();
|
|
|
|
private EventMowForTreasureData Data => Manager?.Data;
|
|
private EventMowForTreasureAct Act=>(EventMowForTreasureAct)GContext.container.ResolveAct(Manager.GetCurrentStageAct());
|
|
|
|
private readonly Queue<GameObject> _cacheObjects=new Queue<GameObject>();
|
|
private float _clickGapTime;
|
|
private void Awake()
|
|
{
|
|
//top ui
|
|
btn_questionmark = gameObject.FindChildGameObject(nameof(btn_questionmark)).GetComponent<Button>();
|
|
btn_questionmark.onClick.AddListener(OnClick_btn_questionmark);
|
|
text_time = gameObject.FindChildGameObject(nameof(text_time)).GetComponent<TMP_Text>();
|
|
_collectionCells = gameObject.GetComponentsInChildren<EventMowForTreasure_CollectionCell>();
|
|
_itemSanddigTips = gameObject.GetComponentInChildren<item_sanddig_tips>(true);
|
|
//bottom ui
|
|
_toolPropCells = gameObject.GetComponentsInChildren<EventMowForTreasure_ToolPropCell>();
|
|
btn_close = gameObject.FindChildGameObject("p_panel_btn_close").GetComponent<Button>();
|
|
btn_close.onClick.AddListener(OnClick_btn_close);
|
|
_batchController = gameObject.GetComponentInChildren<RewardFlyBatchController>();
|
|
_rewardGameObject=gameObject.FindChildGameObject("p_reward");
|
|
|
|
fingerObj = gameObject.FindChildGameObject("guide").gameObject;
|
|
_maskGameObject = gameObject.FindChildGameObject("p_mask");
|
|
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(disposables);
|
|
GContext.OnEvent<EventMowForTreasureToolAmountChange>().Subscribe(_ => ShowToolUI()).AddTo(disposables);
|
|
GContext.OnEvent<EventMowForTreasureObstacleBrokeEvent>().Subscribe(OnEventObstacleBroke)
|
|
.AddTo(disposables);
|
|
GContext.OnEvent<EventMowForTreasureGuideRefresh>().Subscribe(OnEventGuideRefresh)
|
|
.AddTo(disposables);
|
|
GContext.OnEvent<EventMowForTreasureObstacleBreakingEvent>().Subscribe(OnEventObstacleBreaking)
|
|
.AddTo(disposables);
|
|
GContext.OnEvent<EndTransition>().Subscribe(OnEndTransition).AddTo(disposables);
|
|
}
|
|
|
|
public void OnEndTransition(EndTransition e)
|
|
{
|
|
ShowFinalRewardTips();
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
Manager.SetRedPoint_chainPack();
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(OnRewardPanelClose).AddTo(disposables);
|
|
InitUI();
|
|
ShowUI();
|
|
ShowFinalRewardTips();
|
|
UpdateTimer(0);
|
|
}
|
|
|
|
private async void ShowFinalRewardTips()
|
|
{
|
|
try
|
|
{
|
|
_itemSanddigTips.gameObject.SetActive(true);
|
|
var pos = Act.GetFinalRewardPosition();
|
|
pos = new Vector2(pos.x + finalRewardTipsOffset.x, pos.y + finalRewardTipsOffset.y);
|
|
var itemDatas= Manager.GetCurrentStageFinalReward();
|
|
_itemSanddigTips.SetData(pos,itemDatas);
|
|
await Awaiters.Seconds(delayHideTips);
|
|
var ani = _itemSanddigTips.GetComponent<Animation>();
|
|
ani?.Play("tips_common_out");
|
|
var length = ani.GetClip("tips_common_out").length;
|
|
await Awaiters.Seconds(length);
|
|
_itemSanddigTips.gameObject.SetActive(false);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if(!Data.IsCompleteGuide) return;
|
|
if(!fingerObj.activeInHierarchy) return;
|
|
if (!Input.GetMouseButtonUp(0)) return;
|
|
_clickGapTime = 0;
|
|
IsShowFinger();
|
|
}
|
|
|
|
protected override void OnDestroy()
|
|
{
|
|
btn_questionmark.onClick.RemoveAllListeners();
|
|
btn_close.onClick.RemoveAllListeners();
|
|
foreach (var cacheObject in _cacheObjects)
|
|
Destroy(cacheObject);
|
|
_cacheObjects.Clear();
|
|
base.OnDestroy();
|
|
}
|
|
|
|
private async void OnClick_btn_close()
|
|
{
|
|
try
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.EventMowForTreasurePanel);
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
//await Awaiters.Seconds(0.5f);
|
|
//Manager.ShowAllBrokeDropItems();
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void OnClick_btn_questionmark()
|
|
{
|
|
UITypes.EventMowForTreasureInfoPopup.SetType(Data.EventMain.InfoPanel);
|
|
_ = UIManager.Instance.ShowUILoad(UITypes.EventMowForTreasureInfoPopup);
|
|
}
|
|
|
|
private void UpdateTimer(long obj)
|
|
{
|
|
var timeStr=ConvertTools.ConvertTime2(Data?.RemainingTime ?? TimeSpan.Zero);
|
|
text_time.text = LocalizationMgr.GetFormatTextValue("UI_COMMON_end",timeStr);
|
|
IsShowFinger();
|
|
}
|
|
|
|
private void OnRewardPanelClose(RewardPanelClose e)
|
|
{
|
|
ShowUI();
|
|
}
|
|
|
|
private void InitUI()
|
|
{
|
|
fingerObj.SetActive(false);
|
|
_maskGameObject.SetActive(false);
|
|
text_time.text = string.Empty;
|
|
_rewardGameObject.SetActive(false);
|
|
foreach (var cell in _collectionCells) cell.gameObject.SetActive(false);
|
|
|
|
foreach (var cell in _toolPropCells) cell.gameObject.SetActive(false);
|
|
}
|
|
|
|
private void ShowUI()
|
|
{
|
|
if (Data?.EventMain == null) return;
|
|
ShowToolUI();
|
|
ShowCollectionUI();
|
|
}
|
|
|
|
private void ShowCollectionUI()
|
|
{
|
|
for (var i = 0; i < _collectionCells.Length; i++)
|
|
{
|
|
var data=Manager.GetCollectionDataAndRewardByIndex(i,out var rewards);
|
|
_collectionCells[i]?.SetData(data,rewards, _batchController, disposables);
|
|
}
|
|
}
|
|
|
|
private void ShowToolUI()
|
|
{
|
|
for (var i = 0; i < _toolPropCells.Length; i++)
|
|
{
|
|
_toolPropCells[i]?.SetData(Manager.GetToolConfigByIndex(i));
|
|
}
|
|
}
|
|
private void IsShowFinger(long _ = 0)
|
|
{
|
|
if(!Data.IsCompleteGuide)return;
|
|
_clickGapTime += 1;
|
|
fingerObj.SetActive(_clickGapTime >= showGuideTimes);
|
|
if(_clickGapTime < showGuideTimes)return;
|
|
|
|
var isFinalReward = false;
|
|
var position=Act?.GetCanObstacleCellPosition(out isFinalReward)??fingerObj.transform.position;
|
|
if (isFinalReward) position = new Vector2(position.x+finalRewardGuideOffset.x,position.y+finalRewardGuideOffset.y);
|
|
fingerObj.transform.position = position;
|
|
}
|
|
private void OnEventGuideRefresh(EventMowForTreasureGuideRefresh refreshEvent)
|
|
{
|
|
_clickGapTime = 0;
|
|
IsShowFinger();
|
|
}
|
|
private void OnEventObstacleBroke(EventMowForTreasureObstacleBrokeEvent data)
|
|
{
|
|
_clickGapTime = 0;
|
|
PlayBrokeRewardFly(data);
|
|
}
|
|
private void OnEventObstacleBreaking(EventMowForTreasureObstacleBreakingEvent data)
|
|
{
|
|
_clickGapTime = 0;
|
|
_maskGameObject.SetActive(!_maskGameObject.activeInHierarchy);
|
|
}
|
|
private async void PlayBrokeRewardFly(EventMowForTreasureObstacleBrokeEvent data)
|
|
{
|
|
try
|
|
{
|
|
if(data?.ItemData==null) return;
|
|
if(!_cacheObjects.TryDequeue(out var newRewardItem))
|
|
newRewardItem = Instantiate(_rewardGameObject);
|
|
newRewardItem.transform.SetParent(this.transform);
|
|
var itemNew= newRewardItem.GetComponentInChildren<RewardItemNew>();
|
|
itemNew.SetData(data.ItemData);
|
|
newRewardItem.transform.position=data.Position;
|
|
newRewardItem.SetActive(true);
|
|
var ani=newRewardItem.GetComponent<Animation>();
|
|
if (!ani)
|
|
{
|
|
newRewardItem.SetActive(false);
|
|
_cacheObjects.Enqueue(newRewardItem);
|
|
return;
|
|
}
|
|
ani.Play();
|
|
//GContext.Publish(new EventUISound("audio_ui_mowfortreasure_land_reward"));
|
|
await Awaiters.Seconds(ani["EventMowForTreasureRewardPanel_show"].length);
|
|
if(!newRewardItem) return;
|
|
await itemNew.ParticleAttractor();
|
|
if(!newRewardItem) return;
|
|
newRewardItem.SetActive(false);
|
|
_cacheObjects.Enqueue(newRewardItem);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
}
|
|
} |