244 lines
7.5 KiB
C#
244 lines
7.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using GameCore;
|
|
using TMPro;
|
|
using asap.core;
|
|
using UniRx;
|
|
using EventPartnerGather;
|
|
using EventPartnerGatherRequests;
|
|
using game;
|
|
using UI.PartnerGather;
|
|
|
|
public class EventPartnerStatueMainPanel : MonoBehaviour
|
|
{
|
|
private AutoMatchController _autoMatchController;
|
|
[SerializeField] private EventPartnerStatueSlotView[] slotViewList;
|
|
[SerializeField] private RewardItemNew[] taskRewards;
|
|
[SerializeField] private GameObject[] taskItems, fxTaskItems;
|
|
[SerializeField] private TMP_Text txtTicketCount;
|
|
[SerializeField] private BingoTimer timer;
|
|
[SerializeField] private Button btnClose, btnInfo, btn_add;
|
|
[SerializeField] private EventPartnerStatueMatchTipView matchTipView;
|
|
[SerializeField] private float taskFxDelay;
|
|
|
|
private void Awake()
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
_autoMatchController = new AutoMatchController(arc);
|
|
Init(arc.GetEventPartnerStatueMainPanelData());
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
btnClose.onClick.AddListener(OnClickClose);
|
|
btnInfo.onClick.AddListener(OnClickInfo);
|
|
btn_add.onClick.AddListener(OnClickAdd);
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.EventAggregator.GetEvent<EventPartnerStatueSlotViewData>()
|
|
.Subscribe(OnMatchSuccess).AddTo(this);
|
|
arc.EventAggregator.GetEvent<EventPartnerTicketChangedEvent>()
|
|
.Subscribe(_ => UpdateTicketCount()).AddTo(this);
|
|
GContext.OnEvent<EventForAutoMatchChangeStage>()
|
|
.Subscribe(OnAutoMatchStateChange).AddTo(this);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
_ = _autoMatchController?.TryResumeAutoMatch();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
_autoMatchController?.CancelPollMatchResult();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_autoMatchController?.Dispose();
|
|
_autoMatchController = null;
|
|
}
|
|
|
|
private async void OnAutoMatchStateChange(EventForAutoMatchChangeStage e)
|
|
{
|
|
try
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
if (e.State == AutoMatchState.AutoMatchOn)
|
|
{
|
|
arc.SetAutoMatchEnabled(true);
|
|
arc.SetLastAutoMatchTimeUtc(DateTime.UtcNow);
|
|
var success = await _autoMatchController.StartAutoMatch();
|
|
if (!success)
|
|
{
|
|
arc.SetAutoMatchEnabled(false);
|
|
arc.NotifyAutoMatchFailed("StartFailed");
|
|
}
|
|
}
|
|
else if (e.State == AutoMatchState.AutoMatchOff)
|
|
{
|
|
arc.SetAutoMatchEnabled(false);
|
|
_ = _autoMatchController.StopAutoMatch();
|
|
}
|
|
UpdateSlotViews(arc.GetEventPartnerStatueMainPanelData().SlotViewDataList);
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
Debug.LogError($"[EventPartnerStatueMainPanel] OnAutoMatchStateChange error={ex.Message}");
|
|
}
|
|
}
|
|
|
|
public void Init(EventPartnerStatueMainPanelData data)
|
|
{
|
|
timer.Init(data.TimerContext);
|
|
UpdateTicketCount(data.TicketCount);
|
|
UpdateSlotViews(data.SlotViewDataList);
|
|
for (int i = 0; i < taskItems.Length; i++)
|
|
taskRewards[i].SetData(data.GrandRewardList[i]);
|
|
for (int i = 0; i < taskItems.Length; i++)
|
|
{
|
|
if (i >= data.BuildStatus.Count)
|
|
{
|
|
taskItems[i].SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
taskItems[i].SetActive(data.BuildStatus[i]);
|
|
}
|
|
}
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.RtSystem.Subscribe(OnScore, OnPartnerChange);
|
|
for (int i = 0; i < fxTaskItems.Length; i++)
|
|
fxTaskItems[i].SetActive(false);
|
|
if (data.BuildStatus.Count >= 2 && data.BuildStatus[0] && data.BuildStatus[1])
|
|
{
|
|
taskRewards[0].SetReceived(true);
|
|
taskRewards[1].SetReceived(true);
|
|
}
|
|
}
|
|
|
|
private void OnClickClose()
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct());
|
|
}
|
|
|
|
private void UpdateTicketCount(int count)
|
|
{
|
|
txtTicketCount.text = count.ToString();
|
|
txtTicketCount.color = count < 1 ? Color.red : Color.white;
|
|
}
|
|
|
|
public void UpdateTicketCount()
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
UpdateTicketCount(arc.Model.TicketCount);
|
|
}
|
|
|
|
private async void OnClickInfo()
|
|
{
|
|
try
|
|
{
|
|
await UIManager.Instance.ShowUINotLoading(UITypes.EventPartnerStatueInfoPopupPanel);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.Log($"[EventPartnerStatueMainPanel]{e}");
|
|
}
|
|
}
|
|
|
|
private void OnClickAdd()
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.TableContext.ShowFestPack();
|
|
}
|
|
|
|
private void OnMatchSuccess(EventPartnerStatueSlotViewData e)
|
|
{
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
matchTipView.Show(e.Info.DisplayName, e.Info.AvatarUrl);
|
|
matchTipView.gameObject.SetActive(false);
|
|
matchTipView.gameObject.SetActive(true);
|
|
// slotViewList[e.Index].Init(e);
|
|
UpdateSlotViews(arc.GetEventPartnerStatueMainPanelData().SlotViewDataList);
|
|
}
|
|
|
|
private async void OnScore(EventPartnerGatherScoreEvt e)
|
|
{
|
|
try
|
|
{
|
|
await Awaiters.NextFrame;
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.OnScore(e);
|
|
var data = arc.GetEventPartnerStatueMainPanelData();
|
|
UpdateSlotViews(data.SlotViewDataList);
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
Debug.LogError($"[EventPartnerStatueMainPanel]{ex}");
|
|
}
|
|
}
|
|
|
|
private async void OnPartnerChange(EventPartnerGatherPartnerEvt e)
|
|
{
|
|
try
|
|
{
|
|
await Awaiters.NextFrame;
|
|
var arc = GContext.container.Resolve<EventPartnerStatueArc>();
|
|
arc.OnPartnerChange(e);
|
|
UpdateSlotViews(arc.GetEventPartnerStatueMainPanelData().SlotViewDataList);
|
|
if (e.EvtType != 1) //accept
|
|
return;
|
|
|
|
var slotViewData = new EventPartnerStatueSlotViewData
|
|
{
|
|
Index = e.SlotId,
|
|
IsEmpty = false,
|
|
Info = e.PartnerInfo,
|
|
Stage = 0,
|
|
Progress = 0.0f,
|
|
Reward = arc.TableContext.GetNextRewardFromScore(0),
|
|
ScoreToAdd = 0,
|
|
IsClaimed = false,
|
|
};
|
|
OnMatchSuccess(slotViewData);
|
|
|
|
}
|
|
catch (System.Exception ex)
|
|
{
|
|
Debug.LogError($"[EventPartnerStatueMainPanel]{ex}");
|
|
}
|
|
}
|
|
|
|
private void UpdateSlotViews(EventPartnerStatueSlotViewData[] slotViewDatas)
|
|
{
|
|
for (int i = 0; i < slotViewList.Length; i++)
|
|
slotViewList[i].Init(slotViewDatas[i]);
|
|
}
|
|
|
|
public async void PlayTaskItemFx(int idx)
|
|
{
|
|
try
|
|
{
|
|
if (idx < 0 || idx >= fxTaskItems.Length)
|
|
return;
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(taskFxDelay));
|
|
fxTaskItems[idx].SetActive(true);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
[SerializeField] private int testSlotIdx = 0;
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
PlayTaskItemFx(testSlotIdx);
|
|
}
|
|
}
|
|
#endif
|
|
}
|