274 lines
9.6 KiB
C#
274 lines
9.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FishingAlbumPanel : BasePanel
|
|
{
|
|
//赛季名称
|
|
public TMP_Text text_season_name;
|
|
public Button btn_questionmark;
|
|
|
|
public Button btn_bottom;
|
|
|
|
public Button btn_close;
|
|
|
|
//兑换按钮
|
|
public Button btn_exchange;
|
|
|
|
//赛季背景
|
|
public Image bg_season;
|
|
|
|
//赛季图标
|
|
public Image icon_season;
|
|
|
|
//收集进度Text
|
|
public TMP_Text text_progress;
|
|
public Image bar;
|
|
//剩余时间Text
|
|
public TMP_Text text_time;
|
|
|
|
//奖励数组
|
|
public RewardItem[] rewards;
|
|
|
|
public GameObject albumItem;
|
|
List<AlbumItem> albumItems = new List<AlbumItem>();
|
|
public Transform content;
|
|
private Theme theme;
|
|
List<Album> albumList = new List<Album>();
|
|
private FishingAlbumPopupPanel fishingAlbumPopupPanel;
|
|
List<ItemData> dropPackageList;
|
|
public GameObject AlbumInfoPopupPanel;
|
|
public Button btn_close_inif;
|
|
public Button btn_close_inif_mask;
|
|
#if UNITY_EDITOR
|
|
private void Reset()
|
|
{
|
|
Awake();
|
|
}
|
|
#endif
|
|
private void Awake()
|
|
{
|
|
text_season_name = transform.Find("root/title/text_title").GetComponent<TMP_Text>();
|
|
btn_questionmark = transform.Find("root/title/btn_questionmark").GetComponent<Button>();
|
|
btn_bottom = transform.Find("root/btn_close/bg_bottom").GetComponent<Button>();
|
|
btn_close = transform.Find("root/btn_close").GetComponent<Button>();
|
|
btn_exchange = transform.Find("root/btn_reward").GetComponent<Button>();
|
|
bg_season = transform.Find("root/bg_title").GetComponent<Image>();
|
|
icon_season = transform.Find("root/bg_title/icon_integral").GetComponent<Image>();
|
|
text_progress = transform.Find("root/bg_title/bg_bar/text_progress").GetComponent<TMP_Text>();
|
|
bar = transform.Find("root/bg_title/bg_bar/bar").GetComponent<Image>();
|
|
text_time = transform.Find("root/bg_title/time/text_time").GetComponent<TMP_Text>();
|
|
rewards = new RewardItem[3];
|
|
rewards[0] = transform.Find("root/bg_title/reward_panel/reward1").GetComponent<RewardItem>();
|
|
rewards[1] = transform.Find("root/bg_title/reward_panel/reward2").GetComponent<RewardItem>();
|
|
rewards[2] = transform.Find("root/bg_title/reward_panel/reward3").GetComponent<RewardItem>();
|
|
content = transform.Find("root/panel_card/ScrollView/Viewport/Content").GetComponent<Transform>();
|
|
AlbumInfoPopupPanel = transform.Find("AlbumInfoPopupPanel").gameObject;
|
|
btn_close_inif = transform.Find("AlbumInfoPopupPanel/btn_close").GetComponent<Button>();
|
|
btn_close_inif_mask = transform.Find("AlbumInfoPopupPanel/mask").GetComponent<Button>();
|
|
albumItem = transform.Find("root/panel_card/ScrollView/Viewport/Content/album").gameObject;
|
|
theme = GContext.container.Resolve<AlbumData>().theme ?? GContext.container.Resolve<Tables>().TbTheme.DataList[0];
|
|
|
|
for (int i = 0; i < theme.AlbumList.Count; i++)
|
|
{
|
|
albumList.Add(GContext.container.Resolve<Tables>().TbAlbum[theme.AlbumList[i]]);
|
|
}
|
|
|
|
dropPackageList = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(theme.CollectionReward);
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(_ => SetProgress()).AddTo(disposables);
|
|
AlbumInfoPopupPanel.SetActive(false);
|
|
albumItem.SetActive(false);
|
|
btn_questionmark.onClick.AddListener(() => AlbumInfoPopupPanel.SetActive(true));
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
btn_bottom.onClick.AddListener(OnClickClose);
|
|
btn_exchange.onClick.AddListener(OnClickExchange);
|
|
btn_close_inif.onClick.AddListener(() => AlbumInfoPopupPanel.SetActive(false));
|
|
btn_close_inif_mask.onClick.AddListener(() => AlbumInfoPopupPanel.SetActive(false));
|
|
text_season_name.text = LocalizationMgr.GetText(theme.Title_l10n_key);
|
|
// bg_season.sprite = ResourceManager.Instance.GetSprite(theme.Season_bg);
|
|
// icon_season.sprite = ResourceManager.Instance.GetSprite(theme.Season_icon);
|
|
for (int i = 0; i < albumList.Count; i++)
|
|
{
|
|
var go = Instantiate(albumItem, content);
|
|
go.SetActive(true);
|
|
go.name = i.ToString();
|
|
go.AddComponent<AlbumItem>();
|
|
albumItems.Add(go.GetComponent<AlbumItem>());
|
|
}
|
|
|
|
for (int i = 0; i < rewards.Length; i++)
|
|
{
|
|
if (dropPackageList.Count > i)
|
|
{
|
|
rewards[i].SetData(dropPackageList[i]);
|
|
}
|
|
else
|
|
{
|
|
rewards[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
SetTime();
|
|
SetProgress();
|
|
GContext.Publish(new OnEventTriggerGuide(GetType().Name));
|
|
}
|
|
void SetAlbumItem()
|
|
{
|
|
for (int i = 0; i < albumItems.Count; i++)
|
|
{
|
|
albumItems[i].SetData(i, albumList[i], OnClickAlbumItem);
|
|
}
|
|
}
|
|
bool isShowing = false;
|
|
async void OnClickAlbumItem(AlbumItem item)
|
|
{
|
|
if (isShowing)
|
|
{
|
|
return;
|
|
}
|
|
if (fishingAlbumPopupPanel == null)
|
|
{
|
|
isShowing = true;
|
|
GameObject panel = await UIManager.Instance.GetUIAsync(UITypes.FishingAlbumPopupPanel);
|
|
fishingAlbumPopupPanel = panel.GetComponent<FishingAlbumPopupPanel>();
|
|
fishingAlbumPopupPanel.albumList = albumList;
|
|
isShowing = false;
|
|
}
|
|
|
|
fishingAlbumPopupPanel.SetData(item.index);
|
|
}
|
|
|
|
void OnClickClose()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.FishingAlbumPanel);
|
|
}
|
|
|
|
async void OnClickExchange()
|
|
{
|
|
btn_exchange.enabled = false;
|
|
await UIManager.Instance.ShowUI(UITypes.AlbumExchangePopupPanel);
|
|
btn_exchange.enabled = true;
|
|
}
|
|
|
|
//设置赛季倒计时
|
|
void SetTime()
|
|
{
|
|
DateTime endTime = GContext.container.Resolve<AlbumData>().GetAlbumEndTime();
|
|
TimeSpan data = endTime - ZZTimeHelper.UtcNow().UtcNowOffset();
|
|
text_time.text = LocalizationMgr.GetFormatTextValue("UI_FishingAlbumPanel_101002",
|
|
data.TotalDays.ToString("00") + "d" + data.Hours.ToString("00") + "h");
|
|
// $"剩余时间{data.TotalDays:00}天{data.Hours:00}小时";
|
|
}
|
|
|
|
//设置收集进度
|
|
void SetProgress()
|
|
{
|
|
SetAlbumItem();
|
|
|
|
int count = albumList.Count;
|
|
int fishAlbumProgress = 0;
|
|
int allAlbumProgress = 0;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//if ( Instance.Album.GetAlbumProgress(albumList[i].PictureList) >= albumList[i].PictureList.Count)
|
|
//{
|
|
// fishAlbumProgress++;
|
|
//}
|
|
fishAlbumProgress += GContext.container.Resolve<AlbumData>().GetAlbumProgress(albumList[i].PictureList);
|
|
allAlbumProgress += albumList[i].PictureList.Count;
|
|
}
|
|
if (fishAlbumProgress >= allAlbumProgress)
|
|
{
|
|
for (int i = 0; i < rewards.Length; i++)
|
|
{
|
|
rewards[i].SetReceived(true);
|
|
}
|
|
}
|
|
|
|
text_progress.text = $"{fishAlbumProgress}/{allAlbumProgress}";
|
|
if (bar)
|
|
bar.fillAmount = (float)fishAlbumProgress / allAlbumProgress;
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
RestartShowHomeUIEvent restartShowHomeUIEvent = new RestartShowHomeUIEvent();
|
|
GContext.Publish(restartShowHomeUIEvent);
|
|
}
|
|
protected override void OnDestroy()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.FishingAlbumPopupPanel);
|
|
UIManager.Instance.DestroyUI(UITypes.AlbumExchangePopupPanel);
|
|
base.OnDestroy();
|
|
}
|
|
}
|
|
|
|
public class AlbumItem : MonoBehaviour
|
|
{
|
|
public Button btn_click;
|
|
Action<AlbumItem> action;
|
|
public int index;
|
|
public AlbumAttribute albumAttribute;
|
|
public GameObject done;
|
|
public UIRedPoint red;
|
|
private void Awake()
|
|
{
|
|
albumAttribute = transform.GetComponent<AlbumAttribute>();
|
|
btn_click = transform.GetComponent<Button>();
|
|
done = albumAttribute.bar.transform.Find("done").gameObject;
|
|
red = transform.Find("redpoint").GetComponent<UIRedPoint>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
btn_click.onClick.AddListener(OnClick);
|
|
GContext.container.Resolve<AlbumData>().SetAlubmRed(RedPointName.Home_Album_ID, false);
|
|
}
|
|
|
|
public void SetData(int _index, Album _data, Action<AlbumItem> _action)
|
|
{
|
|
red.SetKey("Album" + _index);
|
|
|
|
index = _index;
|
|
action = _action;
|
|
albumAttribute.Init(_data);
|
|
int count = GContext.container.Resolve<AlbumData>().GetAlbumProgress(albumAttribute.data.PictureList);
|
|
for (int i = 0; i < albumAttribute.data.PictureList.Count; i++)
|
|
{
|
|
if (GContext.container.Resolve<AlbumData>().IsNewPicture(albumAttribute.data.PictureList[i]))
|
|
{
|
|
RedPointManager.Instance.SetRedPointState("Album" + index, true);
|
|
break;
|
|
}
|
|
}
|
|
if (count >= albumAttribute.data.PictureList.Count)
|
|
{
|
|
albumAttribute.bar.fillAmount = 1;
|
|
albumAttribute.text_progress.text = "";
|
|
done.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
done.SetActive(false);
|
|
albumAttribute.bar.fillAmount = (float)count / albumAttribute.data.PictureList.Count;
|
|
albumAttribute.text_progress.text =
|
|
$"{GContext.container.Resolve<AlbumData>().GetAlbumProgress(albumAttribute.data.PictureList)}/{albumAttribute.data.PictureList.Count}";
|
|
}
|
|
}
|
|
|
|
public void OnClick()
|
|
{
|
|
action?.Invoke(this);
|
|
}
|
|
}
|