Files
back_cantanBuilding/Assets/Scripts/Aquarium/UI/FishSellingPopupPanel.cs
2026-05-26 16:15:54 +08:00

120 lines
3.6 KiB
C#

using asap.core;
using GameCore;
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class FishSellingPopupPanel : MonoBehaviour
{
Button btn_close;
Button btn_sure;
Transform content;
GameObject Item;
AquariumManager AM;
List<SellingPopupItem> items = new List<SellingPopupItem>();
Action sellSure;
List<AquariumSlotData> slotDataSureList;
private void Awake()
{
AM = GContext.container.Resolve<AquariumManager>();
btn_close = transform.Find("btn_close").GetComponent<Button>();
btn_sure = transform.Find("root/btn_sure/btn_green").GetComponent<Button>();
content = transform.Find("root/panel_list/ScrollView/Viewport/Content");
Item = content.Find("Item").gameObject;
Item.SetActive(false);
}
private void Start()
{
btn_close.onClick.AddListener(OnClickClose);
btn_sure.onClick.AddListener(OnClickSure);
ShowFish();
}
public void Init(Action sellSure)
{
this.sellSure = sellSure;
}
void ShowFish()
{
List<AquariumSlotData> slotDataList = AM.data.slotDatas;
if (slotDataList == null)
{
return;
}
List<AquariumResultData> aquariumResultDatas = AM.data.aquariumResultDatas;
var time = ZZTimeHelper.UtcNow();
for (int i = 0; i < AM.data.slot; i++)
{
AquariumSlotData slotData = slotDataList[i];
if (slotData.FishHatchTime() < time && !slotData.IsResult())
{
GameObject go = Instantiate(Item, content);
go.SetActive(true);
SellingPopupItem item = go.GetComponent<SellingPopupItem>();
item.SetData(slotData);
items.Add(item);
if (item.bar.IsActive() && slotData.FishGrowthTime() < time)
{
item.checkmark.SetActive(true);
}
else
{
item.checkmark.SetActive(false);
}
}
}
}
async void OnClickSure()
{
slotDataSureList = new List<AquariumSlotData>();
bool isAllMax = true;
for (int i = 0; i < items.Count; i++)
{
if (items[i].IsSell())
{
slotDataSureList.Add(items[i].slotData);
if (!items[i].isMax)
{
isAllMax = false;
}
}
}
if (slotDataSureList.Count > 0)
{
if (isAllMax)
{
Sure();
}
else
{
GameObject go = await UIManager.Instance.ShowUI(UITypes.NoticeConfirmPopupPanel);
var noticeConfirmPopupPanel = go.GetComponent<NoticeConfirmPopupPanel>();
string title = LocalizationMgr.GetText("UI_AquariumPanel_11");
string info = LocalizationMgr.GetText("UI_AquariumPanel_12");
string right_text = LocalizationMgr.GetText("UI_AquariumPanel_13");
string left_text = LocalizationMgr.GetText("UI_COMMON_cancel");
noticeConfirmPopupPanel.Init(2,title, info, onClickRight: Sure, btn_left_text: left_text, btn_right_text: right_text);
}
}
}
void Sure()
{
AM.SellFish(slotDataSureList);
sellSure?.Invoke();
UIManager.Instance.DestroyUI(UITypes.FishSellingPopupPanel);
}
void OnClickClose()
{
UIManager.Instance.DestroyUI(UITypes.FishSellingPopupPanel);
}
}