177 lines
6.8 KiB
C#
177 lines
6.8 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class SelectPicturePopupPanel : MonoBehaviour
|
|
{
|
|
List<AlbumExchange> exhangeList = new List<AlbumExchange>();
|
|
public AlbumExchangePopupPanel albumExchangePopupPanel;
|
|
public Button btn_close_sub;
|
|
public Button btn_close_sub1;
|
|
public TMP_Text text_title;//UI_SelectPicturePopupPanel_1
|
|
PanelScroll scrollRect;
|
|
float itemHigh;
|
|
public GameObject pictureItem;
|
|
public Toggle toggle_all;
|
|
public TMP_Text text_check;
|
|
public Button btn_exchange;
|
|
List<ExchangePictureItemData> exchangePictureItemDatas = new List<ExchangePictureItemData>();
|
|
List<ExchangePictureItemGroupData> exchangePictureItemGroupDatas = new List<ExchangePictureItemGroupData>();
|
|
List<Picture> pictureList;
|
|
//选中卡牌
|
|
Dictionary<int, int> selectPicture = new Dictionary<int, int>();
|
|
private int selectIndex = -1;
|
|
private float _CD = 3600;
|
|
private void Awake()
|
|
{
|
|
btn_close_sub = transform.Find("mask").GetComponent<Button>();
|
|
btn_close_sub1 = transform.Find("btn_close").GetComponent<Button>();
|
|
text_title = transform.Find("root/text_title").GetComponent<TMP_Text>();
|
|
scrollRect = transform.Find("root/panel_card/ScrollView").GetComponent<PanelScroll>();
|
|
pictureItem = transform.Find("root/panel_card/ScrollView/Viewport/Content/Item").gameObject;
|
|
toggle_all = transform.Find("root/autoselect/checkpoint").GetComponent<Toggle>();
|
|
text_check = transform.Find("root/autoselect/text_check").GetComponent<TMP_Text>();
|
|
btn_exchange = transform.Find("root/btn_sure/btn_green").GetComponent<Button>();
|
|
pictureItem.SetActive(false);
|
|
List<int> exchangeIdList = GContext.container.Resolve<AlbumData>().theme.ExchangeList;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
{
|
|
AlbumExchange albumExchange = GContext.container.Resolve<Tables>().GetAlbumExchange(exchangeIdList[i]);
|
|
exhangeList.Add(albumExchange);
|
|
}
|
|
itemHigh = pictureItem.GetComponent<RectTransform>().sizeDelta.y;
|
|
}
|
|
private void Start()
|
|
{
|
|
btn_close_sub.onClick.AddListener(() => { gameObject.SetActive(false); });
|
|
btn_close_sub1.onClick.AddListener(() => { gameObject.SetActive(false); });
|
|
toggle_all.onValueChanged.AddListener(OnToggleChange);
|
|
btn_exchange.onClick.AddListener(OnClickExchange);
|
|
}
|
|
public void OpenExchangePopupPanel(int index)
|
|
{
|
|
gameObject.SetActive(true);
|
|
selectIndex = index;
|
|
//设置兑换弹窗数据
|
|
SetExchangeItem();
|
|
text_check.text = LocalizationMgr.GetFormatTextValue("UI_SelectPicturePopupPanel_2", exhangeList[selectIndex].PictureRequired);
|
|
//按钮不置灰
|
|
// btn_exchange.interactable = true;
|
|
}
|
|
|
|
void OnToggleChange(bool isOn)
|
|
{
|
|
selectPicture.Clear();
|
|
int count = exchangePictureItemDatas.Count;
|
|
//设置兑换弹窗数据
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
if (i < exhangeList[selectIndex].PictureRequired && isOn)
|
|
{
|
|
selectPicture[i] = exchangePictureItemDatas[i].data.ID;
|
|
}
|
|
|
|
exchangePictureItemDatas[i].isSelect = i < exhangeList[selectIndex].PictureRequired && isOn;
|
|
}
|
|
//刷新列表
|
|
SetTitle();
|
|
scrollRect.Refresh();
|
|
}
|
|
void SetTitle()
|
|
{
|
|
text_title.text = $"{LocalizationMgr.GetText("UI_SelectPicturePopupPanel_1")}({selectPicture.Count}/{exhangeList[selectIndex].PictureRequired})";
|
|
}
|
|
void SetExchangeItem()
|
|
{
|
|
selectPicture.Clear();
|
|
pictureList = new List<Picture>();
|
|
exchangePictureItemDatas.Clear();
|
|
exchangePictureItemGroupDatas.Clear();
|
|
ShowList();
|
|
}
|
|
void ShowList()
|
|
{
|
|
pictureList = GContext.container.Resolve<AlbumData>().GetPictureRepeatList();
|
|
//Quality从小到大排序
|
|
pictureList.Sort((a, b) => { return a.Quality.CompareTo(b.Quality); });
|
|
int total = 0;
|
|
|
|
for (int i = 0; i < pictureList.Count; i++)
|
|
{
|
|
var curPictureCount = GContext.container.Resolve<AlbumData>().GetPictureProgress(pictureList[i].ID);
|
|
for (int j = 1; j < curPictureCount; j++)
|
|
{
|
|
|
|
exchangePictureItemDatas.Add(new ExchangePictureItemData(total, pictureList[i]));
|
|
if (total < exhangeList[selectIndex].PictureRequired)
|
|
{
|
|
exchangePictureItemDatas[total].isSelect = true;
|
|
selectPicture[total] = pictureList[i].ID;
|
|
}
|
|
total++;
|
|
}
|
|
}
|
|
for (int i = 0; i < total; i += 3)
|
|
{
|
|
ExchangePictureItemGroupData exchangePictureItemGroupData = new ExchangePictureItemGroupData();
|
|
for (int j = 0; j < 3; j++)
|
|
{
|
|
if (i + j < total)
|
|
{
|
|
exchangePictureItemGroupData.exchangePictureItemDatas.Add(exchangePictureItemDatas[i + j]);
|
|
}
|
|
}
|
|
exchangePictureItemGroupData.action = OnClickPictureItem;
|
|
exchangePictureItemGroupDatas.Add(exchangePictureItemGroupData);
|
|
}
|
|
//滑动列表
|
|
scrollRect.Init<ExchangePictureItemGroup, ExchangePictureItemGroupData>(itemHigh, pictureItem, null, exchangePictureItemGroupDatas);
|
|
SetTitle();
|
|
}
|
|
|
|
void OnClickPictureItem(ExchangePictureItem item)
|
|
{
|
|
item.SetSelected(!item.selected.activeSelf);
|
|
if (item.selected.activeSelf)
|
|
{
|
|
exchangePictureItemDatas[item.index].isSelect = true;
|
|
selectPicture[item.index] = item.pictureAttribute.data.ID;
|
|
}
|
|
else
|
|
{
|
|
exchangePictureItemDatas[item.index].isSelect = false;
|
|
selectPicture.Remove(item.index);
|
|
}
|
|
SetTitle();
|
|
}
|
|
|
|
void OnClickExchange()
|
|
{
|
|
if (selectPicture.Count == exhangeList[selectIndex].PictureRequired)
|
|
{
|
|
//减卡牌数
|
|
GContext.container.Resolve<AlbumData>().RemovePictureProgress(selectPicture);
|
|
|
|
gameObject.SetActive(false);
|
|
//获得奖励
|
|
GContext.container.Resolve<PlayerItemData>().AddItemCount(exhangeList[selectIndex].ItemID, 1);
|
|
GContext.Publish(new game.ShowData());
|
|
//更新兑换按钮状态
|
|
GContext.container.Resolve<AlbumData>().SetExchangeCd(selectIndex, _CD);
|
|
albumExchangePopupPanel.SetTimer(selectIndex, _CD);
|
|
int count = GContext.container.Resolve<AlbumData>().GetPictureRepeatCount();
|
|
albumExchangePopupPanel.text_repetitive_card.text = LocalizationMgr.GetFormatTextValue("UI_AlbumExchangePopupPanel_101002", count);
|
|
}
|
|
else
|
|
{
|
|
ToastPanel.Show(LocalizationMgr.GetText("UI_ToastPanel_9"));
|
|
}
|
|
}
|
|
|
|
}
|