240 lines
7.6 KiB
C#
240 lines
7.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class FishingAlbumPopupPanel : MonoBehaviour
|
|
{
|
|
public static string[] AlbumBg =
|
|
{
|
|
"bg_album_album_white",
|
|
"bg_album_album_blue",
|
|
"bg_album_album_purple",
|
|
"bg_album_album_yellow",
|
|
};
|
|
|
|
public Button btn_close;
|
|
public Button btn_mask;
|
|
public AlbumAttribute albumAttribute;
|
|
public TMP_Text text_progress;
|
|
public RewardItem[] rewards;
|
|
public GameObject pictureItem;
|
|
public Transform content;
|
|
public ScrollRect scrollRect;
|
|
List<Picture> pictureList = new List<Picture>();
|
|
private List<ItemData> dropPackageList;
|
|
List<PictureItem> pictureItems = new List<PictureItem>();
|
|
public List<Album> albumList = new List<Album>();
|
|
public TMP_Text text_page;
|
|
public Button btn_left;
|
|
public Button btn_right;
|
|
public GameObject btn_left_icon;
|
|
public GameObject btn_left_icon_gray;
|
|
public GameObject btn_right_icon;
|
|
public GameObject btn_right_icon_gray;
|
|
|
|
int currentAlbumIndex = 0;
|
|
private void Awake()
|
|
{
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
btn_mask = transform.Find("mask").GetComponent<Button>();
|
|
albumAttribute = transform.Find("root/album").GetComponent<AlbumAttribute>();
|
|
text_progress = transform.Find("root/reward_panel/text_reward").GetComponent<TMP_Text>();
|
|
rewards = new RewardItem[3];
|
|
rewards[0] = transform.Find("root/reward_panel/reward1").GetComponent<RewardItem>();
|
|
rewards[1] = transform.Find("root/reward_panel/reward2").GetComponent<RewardItem>();
|
|
rewards[2] = transform.Find("root/reward_panel/reward3").GetComponent<RewardItem>();
|
|
pictureItem = transform.Find("root/panel_card/ScrollView/Viewport/Content/album_photo").gameObject;
|
|
content = transform.Find("root/panel_card/ScrollView/Viewport/Content").GetComponent<Transform>();
|
|
scrollRect = transform.Find("root/panel_card/ScrollView").GetComponent<ScrollRect>();
|
|
text_page = transform.Find("root/text_page").GetComponent<TMP_Text>();
|
|
btn_left = transform.Find("btn_close/btn_arrow_left").GetComponent<Button>();
|
|
btn_right = transform.Find("btn_close/btn_arrow_right").GetComponent<Button>();
|
|
btn_left_icon = transform.Find("btn_close/btn_arrow_left/icon").gameObject;
|
|
btn_left_icon_gray = transform.Find("btn_close/btn_arrow_left/icon_gray").gameObject;
|
|
btn_right_icon = transform.Find("btn_close/btn_arrow_right/icon").gameObject;
|
|
btn_right_icon_gray = transform.Find("btn_close/btn_arrow_right/icon_gray").gameObject;
|
|
|
|
}
|
|
private void Start()
|
|
{
|
|
pictureItem.SetActive(false);
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
btn_mask.onClick.AddListener(OnClickClose);
|
|
btn_left.onClick.AddListener(OnLeftClick);
|
|
btn_right.onClick.AddListener(OnRightClick);
|
|
}
|
|
private void OnEnable()
|
|
{
|
|
GContext.Publish(new OnEventTriggerGuide(GetType().Name));
|
|
}
|
|
private void OnDisable()
|
|
{
|
|
GContext.Publish(new OnEventTriggerGuide(GetType().Name));
|
|
}
|
|
private void Update()
|
|
{
|
|
//左右滑动屏幕一半距离触发OnLeftClick或OnRightClick
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
OnBeginDrag();
|
|
}
|
|
if (Input.GetMouseButtonUp(0))
|
|
{
|
|
OnEndDrag();
|
|
}
|
|
}
|
|
float beginDragPosX = 0;
|
|
void OnBeginDrag()
|
|
{
|
|
beginDragPosX = Input.mousePosition.x;
|
|
}
|
|
void OnEndDrag()
|
|
{
|
|
//滑动屏幕一半距离触发OnLeftClick或OnRightClick
|
|
if (Mathf.Abs(Input.mousePosition.x - beginDragPosX) > Screen.width / 4)
|
|
{
|
|
if (Input.mousePosition.x > beginDragPosX)
|
|
{
|
|
OnLeftClick();
|
|
}
|
|
else
|
|
{
|
|
OnRightClick();
|
|
}
|
|
}
|
|
}
|
|
|
|
void OnClickClose()
|
|
{
|
|
UIManager.Instance.HideUI(UITypes.FishingAlbumPopupPanel);
|
|
}
|
|
|
|
public void OnLeftClick()
|
|
{
|
|
if (currentAlbumIndex > 0)
|
|
{
|
|
SetData(currentAlbumIndex - 1);
|
|
}
|
|
}
|
|
|
|
public void OnRightClick()
|
|
{
|
|
if (currentAlbumIndex < albumList.Count - 1)
|
|
{
|
|
SetData(currentAlbumIndex + 1);
|
|
}
|
|
}
|
|
|
|
public void SetData(int index)
|
|
{
|
|
currentAlbumIndex = index;
|
|
btn_left_icon.SetActive(index > 0);
|
|
btn_left_icon_gray.SetActive(index <= 0);
|
|
btn_right_icon.SetActive(index < albumList.Count - 1);
|
|
btn_right_icon_gray.SetActive(index >= albumList.Count - 1);
|
|
|
|
text_page.text = $"{index + 1}/{albumList.Count}";
|
|
Album album = albumList[index];
|
|
albumAttribute.Init(album);
|
|
pictureList.Clear();
|
|
foreach (var t in album.PictureList)
|
|
{
|
|
pictureList.Add(GContext.container.Resolve<Tables>().TbPicture[t]);
|
|
}
|
|
|
|
dropPackageList = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropId(album.CollectionReward);
|
|
gameObject.SetActive(true);
|
|
SetItem();
|
|
SetReward();
|
|
}
|
|
|
|
void SetItem()
|
|
{
|
|
int count = pictureItems.Count;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
pictureItems[i].gameObject.SetActive(false);
|
|
}
|
|
|
|
for (int i = 0; i < pictureList.Count; i++)
|
|
{
|
|
if (count <= i)
|
|
{
|
|
var go = Instantiate(pictureItem, content);
|
|
go.SetActive(true);
|
|
go.name = i.ToString();
|
|
go.AddComponent<PictureItem>().SetData(pictureList[i], OnClickPictureItem);
|
|
pictureItems.Add(go.GetComponent<PictureItem>());
|
|
}
|
|
else
|
|
{
|
|
pictureItems[i].gameObject.SetActive(true);
|
|
pictureItems[i].SetData(pictureList[i], OnClickPictureItem);
|
|
}
|
|
}
|
|
RedPointManager.Instance.SetRedPointState("Album" + currentAlbumIndex, false);
|
|
}
|
|
|
|
void SetReward()
|
|
{
|
|
for (int i = 0; i < rewards.Length; i++)
|
|
{
|
|
if (dropPackageList.Count > i)
|
|
{
|
|
rewards[i].SetData(dropPackageList[i]);
|
|
// rewards[i].btn_click.onClick.AddListener(() =>
|
|
// {
|
|
// //TODO
|
|
// });
|
|
}
|
|
else
|
|
{
|
|
rewards[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
int count = pictureList.Count;
|
|
int fishPictureProgress = 0;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (GContext.container.Resolve<AlbumData>().GetPictureProgress(pictureList[i].ID) > 0)
|
|
{
|
|
fishPictureProgress++;
|
|
}
|
|
}
|
|
if (fishPictureProgress >= count)
|
|
{
|
|
for (int i = 0; i < rewards.Length; i++)
|
|
{
|
|
rewards[i].SetReceived(true);
|
|
}
|
|
}
|
|
|
|
text_progress.text = fishPictureProgress >= count
|
|
? LocalizationMgr.GetFormatTextValue("UI_FishingAlbumPanel_101003", count, count)
|
|
: LocalizationMgr.GetFormatTextValue("UI_FishingAlbumPanel_101003", fishPictureProgress, count);
|
|
}
|
|
bool isClick = false;
|
|
async void OnClickPictureItem(PictureItem item)
|
|
{
|
|
if (isClick)
|
|
{
|
|
return;
|
|
}
|
|
isClick = true;
|
|
(await UIManager.Instance.ShowUI(UITypes.AlbumPictureReviewPopupPanel)).GetComponent<AlbumPictureReviewPopupPanel>().SetData(item.pictureAttribute.data);
|
|
isClick = false;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.AlbumPictureReviewPopupPanel);
|
|
}
|
|
}
|
|
|