430 lines
15 KiB
C#
430 lines
15 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UniRx;
|
|
using UnityEngine.UI;
|
|
|
|
public class AquariumPanel : BasePanel
|
|
{
|
|
Button btn_close;
|
|
Button btn_event;
|
|
Button btn_progress;
|
|
Button btn_fishcard;
|
|
TMP_Text text_level;
|
|
Button btn_questionmark;
|
|
Button btn_sell;
|
|
Button btn_speedup;
|
|
Head head;
|
|
TMP_Text text_name;
|
|
TMP_Text text_title;
|
|
Button btn_close_tips;
|
|
GameObject redpoint;
|
|
AquariumManager AM;
|
|
Tables tables;
|
|
AquariumSlot[] aquariumSlot;
|
|
bool updateBar = true;
|
|
IUIService uIService;
|
|
IAquariumTips aquariumTips;
|
|
AquariumEggTips aquariumEggTips;
|
|
AquariumFishTips aquariumFishTips;
|
|
|
|
AquariumSlot curAquariumSlot;
|
|
|
|
FishingAquariumAct fishingAquariumAct;
|
|
|
|
UIDrag moveCameraPanel;
|
|
bool canDragMove = false;
|
|
public bool CanDragMove => canDragMove;
|
|
MapData mapData;
|
|
|
|
private void Awake()
|
|
{
|
|
GContext.OnEvent<GetUIAsyncEvent>().Subscribe(GetUIAsyncEvent).AddTo(disposables);
|
|
|
|
GContext.OnEvent<ChangeMapDataAsyncEvent>().Subscribe(e =>
|
|
{
|
|
UIManager.Instance.DestroyUI(UITypes.FishcardBenefitPopupPanel);
|
|
GContext.container.Resolve<PlayerData>().SetCurrentMapId(e.mapID);
|
|
OnClickClose();
|
|
e.source?.SetResult(false);
|
|
}).AddTo(disposables);
|
|
transform.SetAsFirstSibling();
|
|
reportService = GContext.container.Resolve<IReportService>();
|
|
eventReport = transform.Find("root/Event_report").GetComponent<EventReport>();
|
|
tables = GContext.container.Resolve<Tables>();
|
|
uIService = GContext.container.Resolve<IUIService>();
|
|
AM = GContext.container.Resolve<AquariumManager>();
|
|
text_name = transform.Find("root/title/bg/text_name").GetComponent<TMP_Text>();
|
|
head = transform.Find("root/title/btn_head").GetComponent<Head>();
|
|
btn_event = transform.Find("root/btn_event").GetComponent<Button>();
|
|
btn_progress = transform.Find("root/btn_progress").GetComponent<Button>();
|
|
btn_fishcard = transform.Find("root/btn_fishcard").GetComponent<Button>();
|
|
btn_close = transform.Find("btn_close").GetComponent<Button>();
|
|
btn_questionmark = transform.Find("root/title/btn_questionmark").GetComponent<Button>();
|
|
text_level = transform.Find("root/btn_fishcard/text_level").GetComponent<TMP_Text>();
|
|
aquariumSlot = transform.Find("root/partner").GetComponentsInChildren<AquariumSlot>();
|
|
text_title = transform.Find("root/title/text_title").GetComponent<TMP_Text>();
|
|
moveCameraPanel = transform.Find("moveCameraPanel").GetComponent<UIDrag>();
|
|
redpoint = transform.Find("root/btn_fishcard/redpoint").gameObject;
|
|
btn_sell = transform.Find("btn_2/btn_sell").GetComponent<Button>();
|
|
btn_speedup = transform.Find("btn_2/btn_speedup").GetComponent<Button>();
|
|
|
|
aquariumEggTips = transform.Find("egg_tips").GetComponent<AquariumEggTips>();
|
|
aquariumFishTips = transform.Find("fish_tips").GetComponent<AquariumFishTips>();
|
|
btn_close_tips = transform.Find("btn_close_tips").GetComponent<Button>();
|
|
SetMoveCameraPanel();
|
|
}
|
|
void SetMoveCameraPanel()
|
|
{
|
|
moveCameraPanel.OnPointerDownCall = () =>
|
|
{
|
|
canDragMove = true;
|
|
};
|
|
moveCameraPanel.OnPointerUpCall = () =>
|
|
{
|
|
canDragMove = false;
|
|
};
|
|
//moveCameraPanel.OnDragCall = (eventData) =>
|
|
//{
|
|
// Debug.Log(" Pointer OnDragCall");
|
|
//};
|
|
}
|
|
void GetUIAsyncEvent(GetUIAsyncEvent data)
|
|
{
|
|
if (data.uIType == UITypes.FishingMapPanel.Name && !data.show)
|
|
{
|
|
SetRed();
|
|
string levelLV = LocalizationMgr.GetText("UI_FishingMapPanel_101006");
|
|
int fishCardLevel = GContext.container.Resolve<PlayerFishData>().GetFishLevelByMap(AM.MapId);
|
|
text_level.text = levelLV + fishCardLevel.ToString();
|
|
}
|
|
}
|
|
protected override void Start()
|
|
{
|
|
var fishingData = GContext.container.Resolve<FishingData>();
|
|
|
|
fishingData.MapId = AM.MapId;
|
|
|
|
updateBar = true;
|
|
base.Start();
|
|
GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("AquariumPanel");
|
|
aquariumEggTips.btn_speedup.onClick.AddListener(OnClickSpeedup);
|
|
aquariumFishTips.btn_speedup.onClick.AddListener(OnClickSpeedup);
|
|
btn_speedup.onClick.AddListener(OnClickSpeedup);
|
|
aquariumFishTips.btn_sell.onClick.AddListener(ShowFishSellingPopupPanel);
|
|
btn_close_tips.onClick.AddListener(CloseTips);
|
|
|
|
btn_event.onClick.AddListener(() => _ = UIManager.Instance.ShowUI(UITypes.EventReportPopupPanel));
|
|
btn_fishcard.onClick.AddListener(async () =>
|
|
await UIManager.Instance.ShowUI(UITypes.FishcardBenefitPopupPanel));
|
|
btn_sell.onClick.AddListener(ShowFishSellingPopupPanel);
|
|
btn_progress.onClick.AddListener(OnClickProgress);
|
|
btn_close.onClick.AddListener(OnClickClose);
|
|
btn_questionmark.onClick.AddListener(async () =>
|
|
await UIManager.Instance.ShowUI(UITypes.AquariumInfoPopupPanel));
|
|
text_name.text = GContext.container.Resolve<IUserService>().DisplayName;
|
|
head.SetData(GContext.container.Resolve<IUserService>().AvatarUrl);
|
|
|
|
mapData = tables.TbMapData.GetOrDefault(AM.MapId);
|
|
text_title.text = LocalizationMgr.GetText(mapData.Name_l10n_key);
|
|
|
|
string levelLV = LocalizationMgr.GetText("UI_FishingMapPanel_101006");
|
|
int fishCardLevel = GContext.container.Resolve<PlayerFishData>().GetFishLevelByMap(AM.MapId);
|
|
text_level.text = levelLV + fishCardLevel.ToString();
|
|
DateTime dateTime = ZZTimeHelper.UtcNow();
|
|
Item item;
|
|
AquariumEgg aquariumEgg;
|
|
bool isShowSell = false;
|
|
bool isShowSpeedup = false;
|
|
for (int i = 0; i < aquariumSlot.Length; i++)
|
|
{
|
|
if (i < AM.Slot)
|
|
{
|
|
AquariumSlotData slotData = AM.data.slotDatas[i];
|
|
if (slotData.startTime.AddHours(slotData.hatchTime - slotData.accelerationHatch) > dateTime)
|
|
{
|
|
aquariumEgg = tables.TbAquariumEgg.GetOrDefault(slotData.eggId);
|
|
//还没孵化
|
|
uIService.SetImageSprite(aquariumSlot[i].icon_egg, aquariumEgg.Icon);
|
|
}
|
|
|
|
item = tables.TbItem.GetOrDefault(slotData.fishItemID);
|
|
PlayerFishData.SetFishIcon(aquariumSlot[i].icon_fish, item);//鱼头像
|
|
uIService.SetImageSprite(aquariumSlot[i].icon_rate, "icon_fish_rate_tag_" + item.Quality);
|
|
aquariumSlot[i].InitSlot(i, slotData, OnClickSlot, OnFishStateChange);
|
|
if (aquariumSlot[i].slotState == 2 || aquariumSlot[i].slotState == 3)
|
|
{
|
|
isShowSell = true;
|
|
}
|
|
if (aquariumSlot[i].slotState < 3)
|
|
{
|
|
isShowSpeedup = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
aquariumSlot[i].gameObject.SetActive(false);
|
|
}
|
|
}
|
|
btn_sell.gameObject.SetActive(isShowSell);
|
|
btn_speedup.gameObject.SetActive(isShowSpeedup);
|
|
AM.CheckInHome();
|
|
NextReport();
|
|
SetRed();
|
|
}
|
|
void SetRed()
|
|
{
|
|
bool isRedPoint = GContext.container.Resolve<PlayerFishData>().GetMapRed(mapData.FishList);
|
|
redpoint.SetActive(isRedPoint);
|
|
}
|
|
public void OnUpdate(DateTime dateTime)
|
|
{
|
|
if (!updateBar)
|
|
{
|
|
return;
|
|
}
|
|
for (int i = 0; i < AM.Slot; i++)
|
|
{
|
|
aquariumSlot[i].UpdateBar(dateTime);
|
|
}
|
|
if (aquariumTips != null && curAquariumSlot != null && curAquariumSlot.slotState < 3)
|
|
{
|
|
aquariumTips.UpdateBar(dateTime);
|
|
}
|
|
}
|
|
public void Init(FishingAquariumAct fishingAquariumAct)
|
|
{
|
|
this.fishingAquariumAct = fishingAquariumAct;
|
|
}
|
|
|
|
async void ShowFishSellingPopupPanel()
|
|
{
|
|
GameObject go = await UIManager.Instance.ShowUI(UITypes.FishSellingPopupPanel);
|
|
FishSellingPopupPanel fishSellingPopupPanel = go.GetComponent<FishSellingPopupPanel>();
|
|
fishSellingPopupPanel.Init(OnSellFish);
|
|
aquariumFishTips.gameObject.SetActive(false);
|
|
}
|
|
|
|
async void OnSellFish()
|
|
{
|
|
GameObject go = await UIManager.Instance.ShowUI(UITypes.AquariumReportPopupPanel);
|
|
AquariumReportPopupPanel aquariumReportPopupPanel = go.GetComponent<AquariumReportPopupPanel>();
|
|
aquariumReportPopupPanel.InitData(fishingAquariumAct);
|
|
OnFishStateChange();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 鱼当前状态倒计时结束
|
|
/// 售卖鱼刷新
|
|
/// </summary>
|
|
void OnFishStateChange()
|
|
{
|
|
bool isShowSell = false;
|
|
bool isShowSpeedup = false;
|
|
List<int> addFish = new List<int>();
|
|
List<int> removeFish = new List<int>();
|
|
for (int i = 0; i < AM.Slot; i++)
|
|
{
|
|
if (aquariumSlot[i].slotState > 3)
|
|
{
|
|
continue;
|
|
}
|
|
int oldState = aquariumSlot[i].slotState;
|
|
aquariumSlot[i].SetState();
|
|
if (oldState != aquariumSlot[i].slotState)
|
|
{
|
|
if (oldState == 1 && (aquariumSlot[i].slotState == 2 || aquariumSlot[i].slotState == 3))
|
|
{
|
|
//添加鱼
|
|
addFish.Add(i);
|
|
}
|
|
else if (aquariumSlot[i].slotState == 4)
|
|
{
|
|
//删除鱼
|
|
removeFish.Add(i);
|
|
}
|
|
}
|
|
if (aquariumSlot[i].slotState == 2 || aquariumSlot[i].slotState == 3)
|
|
{
|
|
isShowSell = true;
|
|
}
|
|
if (aquariumSlot[i].slotState < 3)
|
|
{
|
|
isShowSpeedup = true;
|
|
}
|
|
}
|
|
btn_sell.gameObject.SetActive(isShowSell);
|
|
btn_speedup.gameObject.SetActive(isShowSpeedup);
|
|
//修改显示的鱼
|
|
if (removeFish.Count > 0 || addFish.Count > 0)
|
|
{
|
|
if (aquariumTips != null && curAquariumSlot != null)
|
|
{
|
|
bool isShow = aquariumTips.UpdateBar(ZZTimeHelper.UtcNow());
|
|
if (!isShow)
|
|
{
|
|
CloseTips();
|
|
}
|
|
}
|
|
ChangeFishEvent changeFishEvent = new ChangeFishEvent();
|
|
changeFishEvent.addFish = addFish;
|
|
changeFishEvent.removeFish = removeFish;
|
|
FishingAquariumAct.eventAggregator.Publish(changeFishEvent);
|
|
}
|
|
}
|
|
void CloseTips()
|
|
{
|
|
if (curAquariumSlot != null && aquariumTips != null)
|
|
{
|
|
curAquariumSlot.selected.SetActive(false);
|
|
aquariumTips.SetActive(false);
|
|
btn_close_tips.gameObject.SetActive(false);
|
|
curAquariumSlot = null;
|
|
aquariumTips = null;
|
|
}
|
|
fishingAquariumAct.StopFollowFishCamera();
|
|
}
|
|
|
|
public void OnClickFish(int index)
|
|
{
|
|
if (index < aquariumSlot.Length)
|
|
{
|
|
OnClickSlot(aquariumSlot[index]);
|
|
}
|
|
}
|
|
|
|
void OnClickSlot(AquariumSlot aquariumSlot)
|
|
{
|
|
if (curAquariumSlot != null && aquariumTips != null)
|
|
{
|
|
if (curAquariumSlot == aquariumSlot)
|
|
{
|
|
CloseTips();
|
|
return;
|
|
}
|
|
curAquariumSlot.selected.SetActive(false);
|
|
aquariumTips.SetActive(false);
|
|
}
|
|
curAquariumSlot = aquariumSlot;
|
|
curAquariumSlot.selected.SetActive(true);
|
|
AquariumSlotData slotData = aquariumSlot.slotData;
|
|
DateTime dateTime = ZZTimeHelper.UtcNow();
|
|
bool isEgg = false;
|
|
if (slotData.FishHatchTime() > dateTime)
|
|
{
|
|
//还没孵化
|
|
isEgg = true;
|
|
aquariumTips = aquariumEggTips;
|
|
}
|
|
else
|
|
{
|
|
//已经孵化
|
|
aquariumTips = aquariumFishTips;
|
|
}
|
|
if (curAquariumSlot.slotState < 4)
|
|
{
|
|
fishingAquariumAct.FollowFishCamera(slotData, isEgg);
|
|
}
|
|
aquariumTips.SetActive(true);
|
|
aquariumTips.SetData(curAquariumSlot);
|
|
btn_close_tips.gameObject.SetActive(true);
|
|
}
|
|
async void OnClickSpeedup()
|
|
{
|
|
DateTime dateTime = ZZTimeHelper.UtcNow();
|
|
|
|
if (aquariumTips != null && curAquariumSlot != null && curAquariumSlot.slotState < 3)
|
|
{
|
|
bool isShow = aquariumTips.UpdateBar(dateTime);
|
|
if (!isShow)
|
|
{
|
|
CloseTips();
|
|
return;
|
|
}
|
|
}
|
|
var go = await UIManager.Instance.ShowUI(UITypes.SpeedupPopupPanel);
|
|
if (go != null)
|
|
{
|
|
//判断是否置灰
|
|
bool isAd = AM.data.adCount < tables.TbAquariumConfig.AdMaxTime;
|
|
SpeedupPopupPanel speedupPopupPanel = go.GetComponent<SpeedupPopupPanel>();
|
|
string adContent = LocalizationMgr.GetFormatTextValue("UI_AquariumPanel_44", tables.TbAquariumConfig.AdMaxTime - AM.data.adCount, tables.TbAquariumConfig.AdMaxTime);
|
|
if (isAd)
|
|
{
|
|
speedupPopupPanel.SetData(OnAdsSucceed, StartSpeedUp, adContent);
|
|
}
|
|
else
|
|
{
|
|
speedupPopupPanel.SetData(null, null, adContent);
|
|
}
|
|
}
|
|
}
|
|
void StartSpeedUp(bool isGuide)
|
|
{
|
|
updateBar = false;
|
|
//加速成功
|
|
AM.Speedup(isGuide);
|
|
}
|
|
void OnAdsSucceed()
|
|
{
|
|
updateBar = true;
|
|
if (aquariumTips != null && curAquariumSlot != null && curAquariumSlot.slotState < 3)
|
|
{
|
|
bool isShow = aquariumTips.UpdateBar(ZZTimeHelper.UtcNow());
|
|
if (!isShow)
|
|
{
|
|
CloseTips();
|
|
}
|
|
}
|
|
OnFishStateChange();
|
|
}
|
|
|
|
async void OnClickProgress()
|
|
{
|
|
await UIManager.Instance.ShowUI(UITypes.PlayerGradePanel);
|
|
GContext.Publish(new HideHomePanelEvent());
|
|
GContext.Publish(new ChangeTabEvent() { index = 1 });
|
|
}
|
|
void OnClickClose()
|
|
{
|
|
FishingAquariumAct.CloudType = 4;
|
|
GContext.Publish(new UnloadActToNextAct(transitionPanel: UITypes.AquariumCloudPanel, time: 0.75f));
|
|
}
|
|
|
|
EventReport eventReport;
|
|
IReportService reportService;
|
|
bool isEnable = true;
|
|
|
|
private void OnDisable()
|
|
{
|
|
isEnable = false;
|
|
}
|
|
|
|
async void PlayEventReport(ReportData reportEvent)
|
|
{
|
|
eventReport.gameObject.SetActive(true);
|
|
eventReport.SetData(reportEvent.playFabId, reportEvent.content, reportEvent.type);
|
|
await Awaiters.Seconds(4f);
|
|
if (!isEnable)
|
|
{
|
|
return;
|
|
}
|
|
eventReport.gameObject.SetActive(false);
|
|
|
|
NextReport();
|
|
}
|
|
void NextReport()
|
|
{
|
|
var data = reportService.GetAquariumReportData();
|
|
if (data != null)
|
|
{
|
|
PlayEventReport(data);
|
|
}
|
|
}
|
|
}
|