291 lines
9.0 KiB
C#
291 lines
9.0 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using DG.Tweening;
|
|
using Game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UniRx;
|
|
|
|
public class AquariumReportPopupPanel : MonoBehaviour
|
|
{
|
|
public Button btn_next;
|
|
public TMP_Text text_num;
|
|
public GameObject[] _lights;
|
|
|
|
public RectTransform photoContainer;
|
|
AquariumReportPhoto photoA;
|
|
AquariumReportPhoto photoB;
|
|
AquariumReportPhoto curPhoto;
|
|
AquariumReportPhoto nextPhotoRef;
|
|
float photoWidth;
|
|
|
|
public Transform tabContainer;
|
|
public GameObject tabPrefab;
|
|
List<AquariumSlot> tabSlots = new List<AquariumSlot>();
|
|
|
|
public Button btn_skip;
|
|
bool isAccelerated;
|
|
float showTime = 0.3f;
|
|
float fastShowTime = 0.1f;
|
|
float cashDuration = 0.5f;
|
|
float fastCashDuration = 0.3f;
|
|
float slideDuration = 0.5f;
|
|
float fastSlideDuration = 0.3f;
|
|
public GameObject fx_ui_fishingsettlement_hunt_cash_1;
|
|
public GameObject fx_ui_fishingsettlement_hunt_cash_2;
|
|
|
|
List<AquariumSlotData> aquariumSlotDatas;
|
|
AquariumSlotData curData;
|
|
int curIndex;
|
|
int allCount;
|
|
int gold;
|
|
IDisposable disposable;
|
|
Tables _tables;
|
|
Item item;
|
|
AquariumManager AM;
|
|
FishingAquariumAct aquariumAct;
|
|
Item fishItem;
|
|
bool curPhotoAlreadyLoaded;
|
|
|
|
float CurShowTime => isAccelerated ? fastShowTime : showTime;
|
|
float CurCashDuration => isAccelerated ? fastCashDuration : cashDuration;
|
|
float CurSlideDuration => isAccelerated ? fastSlideDuration : slideDuration;
|
|
|
|
void Awake()
|
|
{
|
|
_tables = GContext.container.Resolve<Tables>();
|
|
item = _tables.TbItem.GetOrDefault(1002);
|
|
|
|
AM = GContext.container.Resolve<AquariumManager>();
|
|
aquariumSlotDatas = AM.sellList;
|
|
allCount = aquariumSlotDatas.Count;
|
|
curIndex = 0;
|
|
|
|
Transform photoAT = photoContainer.Find("photo_A");
|
|
Transform photoBT = photoContainer.Find("photo_B");
|
|
photoA = photoAT.gameObject.GetOrAddComponent<AquariumReportPhoto>();
|
|
photoB = photoBT.gameObject.GetOrAddComponent<AquariumReportPhoto>();
|
|
|
|
Transform iconFishA = photoContainer.Find("icon_fish_A");
|
|
Transform iconFishB = photoContainer.Find("icon_fish_B");
|
|
if (iconFishA != null) iconFishA.position = new Vector3(-50f, 0f, 0f);
|
|
if (iconFishB != null) iconFishB.position = new Vector3(50f, 0f, 0f);
|
|
photoA.Init(iconFishA);
|
|
photoB.Init(iconFishB);
|
|
|
|
photoWidth = photoContainer.rect.width;
|
|
photoAT.localPosition = Vector3.zero;
|
|
photoBT.localPosition = new Vector3(photoWidth, 0, 0);
|
|
curPhoto = photoA;
|
|
nextPhotoRef = photoB;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
photoA.SetBackground(AM.MapId);
|
|
photoB.SetBackground(AM.MapId);
|
|
|
|
btn_next.onClick.AddListener(OnClickClaim);
|
|
btn_next.gameObject.SetActive(false);
|
|
|
|
if (btn_skip != null)
|
|
btn_skip.onClick.AddListener(OnClickSkip);
|
|
|
|
if (fx_ui_fishingsettlement_hunt_cash_1 != null) fx_ui_fishingsettlement_hunt_cash_1.SetActive(false);
|
|
if (fx_ui_fishingsettlement_hunt_cash_2 != null) fx_ui_fishingsettlement_hunt_cash_2.SetActive(false);
|
|
text_num.text = "";
|
|
InitTabs();
|
|
}
|
|
|
|
public void InitData(FishingAquariumAct aquariumAct)
|
|
{
|
|
this.aquariumAct = aquariumAct;
|
|
SetData();
|
|
}
|
|
|
|
void InitTabs()
|
|
{
|
|
if (allCount <= 1)
|
|
{
|
|
if (tabContainer != null)
|
|
tabContainer.gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
tabContainer.gameObject.SetActive(true);
|
|
var uiService = GContext.container.Resolve<IUIService>();
|
|
for (int i = 0; i < allCount; i++)
|
|
{
|
|
GameObject go = Instantiate(tabPrefab, tabContainer);
|
|
go.SetActive(true);
|
|
AquariumSlot slot = go.GetComponent<AquariumSlot>();
|
|
Item tabFishItem = _tables.TbItem.GetOrDefault(aquariumSlotDatas[i].fishItemID);
|
|
PlayerFishData.SetFishIcon(slot.icon_fish, tabFishItem);
|
|
uiService.SetImageSprite(slot.icon_rate, "icon_fish_rate_tag_" + tabFishItem.Quality);
|
|
slot.mask_fish.SetActive(true);
|
|
slot.icon_egg.gameObject.SetActive(false);
|
|
slot.done.SetActive(false);
|
|
slot.icon_hurt.SetActive(false);
|
|
slot.icon_killed.SetActive(false);
|
|
slot.icon_sold.SetActive(false);
|
|
slot.bar.gameObject.SetActive(false);
|
|
tabSlots.Add(slot);
|
|
}
|
|
UpdateTabHighlight(0);
|
|
}
|
|
|
|
void UpdateTabHighlight(int index)
|
|
{
|
|
for (int i = 0; i < tabSlots.Count; i++)
|
|
{
|
|
tabSlots[i].selected.SetActive(i == index);
|
|
tabSlots[i].done.SetActive(i < index);
|
|
}
|
|
}
|
|
|
|
async void SetData()
|
|
{
|
|
curData = aquariumSlotDatas[curIndex];
|
|
fishItem = _tables.TbItem.GetOrDefault(curData.fishItemID);
|
|
UpdateTabHighlight(curIndex);
|
|
|
|
if (!curPhotoAlreadyLoaded)
|
|
await curPhoto.ShowFish(curData, fishItem, aquariumAct);
|
|
else
|
|
curPhotoAlreadyLoaded = false;
|
|
|
|
ReplayPhotoShowFx();
|
|
|
|
float showCount = curData.allCash;
|
|
ItemShow itemShow = _tables.TbItemShow.GetOrDefault(1002);
|
|
int light_index = 1;
|
|
if (itemShow != null)
|
|
{
|
|
light_index = 0;
|
|
showCount = showCount / GContext.container.Resolve<PlayerItemData>().ExtraCoinMag();
|
|
for (int i = itemShow.Count.Count - 1; i >= 0; i--)
|
|
{
|
|
if (showCount > itemShow.Count[i])
|
|
{
|
|
light_index = i + 1;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (light_index >= _lights.Length)
|
|
light_index = _lights.Length - 1;
|
|
for (int i = 0; i < _lights.Length; i++)
|
|
_lights[i].SetActive(i == light_index);
|
|
|
|
int audioName = curIndex % 4 + 1;
|
|
GContext.Publish(new EventUISound($"audio_ui_getreward_{audioName}"));
|
|
|
|
await Awaiters.Seconds(CurShowTime);
|
|
|
|
var progress = 0f;
|
|
int cash = curData.cash;
|
|
DOTween.Kill("AddCash");
|
|
DOTween.To(() => progress, x => progress = x, 1f, CurCashDuration).OnUpdate(() =>
|
|
{
|
|
text_num.text = ConvertTools.GetNumberString2(gold + (int)(cash * progress));
|
|
}).SetId("AddCash");
|
|
await Awaiters.Seconds(CurCashDuration);
|
|
|
|
gold += cash;
|
|
curIndex++;
|
|
|
|
if (curIndex >= allCount)
|
|
{
|
|
OnAllFishDone();
|
|
return;
|
|
}
|
|
|
|
var nextData = aquariumSlotDatas[curIndex];
|
|
var nextFishItem = _tables.TbItem.GetOrDefault(nextData.fishItemID);
|
|
await nextPhotoRef.ShowFish(nextData, nextFishItem, aquariumAct);
|
|
|
|
await SlideToNext();
|
|
|
|
(curPhoto, nextPhotoRef) = (nextPhotoRef, curPhoto);
|
|
nextPhotoRef.transform.localPosition = new Vector3(photoWidth, 0, 0);
|
|
nextPhotoRef.CleanupFish();
|
|
curPhotoAlreadyLoaded = true;
|
|
|
|
SetData();
|
|
}
|
|
|
|
async Task SlideToNext()
|
|
{
|
|
float duration = CurSlideDuration;
|
|
DOTween.Kill("PhotoSlide");
|
|
var seq = DOTween.Sequence().SetId("PhotoSlide");
|
|
seq.Join(curPhoto.transform.DOLocalMoveX(-photoWidth, duration).SetEase(Ease.InOutCubic));
|
|
seq.Join(nextPhotoRef.transform.DOLocalMoveX(0, duration).SetEase(Ease.InOutCubic));
|
|
await seq.AsyncWaitForCompletion();
|
|
}
|
|
|
|
void ReplayPhotoShowFx()
|
|
{
|
|
curPhoto.ReplayPhotoShowFx();
|
|
}
|
|
|
|
void OnClickSkip()
|
|
{
|
|
isAccelerated = true;
|
|
DOTween.timeScale = 3f;
|
|
}
|
|
|
|
async void OnAllFishDone()
|
|
{
|
|
UpdateTabHighlight(allCount);
|
|
|
|
if (btn_skip != null)
|
|
btn_skip.gameObject.SetActive(false);
|
|
|
|
bool hasMutated = false, hasHighQuality = false;
|
|
for (int i = 0; i < aquariumSlotDatas.Count; i++)
|
|
{
|
|
if (aquariumSlotDatas[i].mutants > 0) { hasMutated = true; }
|
|
var fi = _tables.TbItem.GetOrDefault(aquariumSlotDatas[i].fishItemID);
|
|
if (fi.Quality >= 4) hasHighQuality = true;
|
|
}
|
|
if (fx_ui_fishingsettlement_hunt_cash_2 != null) fx_ui_fishingsettlement_hunt_cash_2.SetActive(hasMutated);
|
|
if (fx_ui_fishingsettlement_hunt_cash_1 != null) fx_ui_fishingsettlement_hunt_cash_1.SetActive(!hasMutated && hasHighQuality);
|
|
|
|
await Awaiters.Seconds(1f);
|
|
btn_next.gameObject.SetActive(true);
|
|
}
|
|
|
|
void OnClickClaim() => Close();
|
|
|
|
void Close()
|
|
{
|
|
DOTween.timeScale = 1f;
|
|
UIManager.Instance.DestroyUI(UITypes.AquariumReportPopupPanel);
|
|
if (AM.data.isHome)
|
|
{
|
|
FishingAquariumAct.eventAggregator.Publish(new AquariumEnterMapScene());
|
|
}
|
|
}
|
|
|
|
void OnDisable()
|
|
{
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
DOTween.timeScale = 1f;
|
|
DOTween.Kill("AddCash");
|
|
DOTween.Kill("PhotoSlide");
|
|
photoA?.Cleanup();
|
|
photoB?.Cleanup();
|
|
foreach (var slot in tabSlots)
|
|
{
|
|
if (slot != null) Destroy(slot.gameObject);
|
|
}
|
|
tabSlots.Clear();
|
|
}
|
|
}
|