165 lines
5.2 KiB
C#
165 lines
5.2 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using PinballUncountable;
|
|
using TMPro;
|
|
using DG.Tweening;
|
|
using UniRx;
|
|
|
|
public class PinballUncountablePanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button btnClose, btnInfo, btnPack;
|
|
[SerializeField] private GeneralMultiplierButton btnMultiplier;
|
|
[SerializeField] private TMP_Text textTicketCount;
|
|
[SerializeField] private PinballUncountableProgressBarView progressBar;
|
|
[SerializeField] private BingoTimer timer;
|
|
[SerializeField] private PinballUncountableGuidancePanel guidancePanel;
|
|
|
|
private void Awake()
|
|
{
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
btnClose.onClick.AddListener(OnClickClose);
|
|
btnPack.onClick.AddListener(OpenPack);
|
|
btnInfo.onClick.AddListener(OnClickInfo);
|
|
btnMultiplier.Init(manager);
|
|
_currentTicketCount = manager.GetTicketCount();
|
|
SetTicketCount(_currentTicketCount);
|
|
var idx = manager.TableContext.GetRewardIndexFromScore(manager.Score);
|
|
var rewardsData = manager.TableContext.GetRewardsData(manager.InflationRate, manager.Score);
|
|
progressBar.Init(idx, rewardsData);
|
|
manager.EventAggregator.GetEvent<PinballUncountable.EventTicketUpdate>()
|
|
.Subscribe(_ => UpdateTicketCount())
|
|
.AddTo(this);
|
|
manager.EventAggregator.GetEvent<PinballUncountable.EventInsufficientTicket>()
|
|
.Subscribe(OnInsufficientTicket)
|
|
.AddTo(this);
|
|
timer.Init(manager.TableContext.GetTimerContext());
|
|
// manager.EventAggregator.GetEvent<EventInitGuide>().Subscribe(TryStartGuide).AddTo(this);
|
|
}
|
|
|
|
// private void Start()
|
|
// {
|
|
// GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide("PinballUncountable01", curPanelName: gameObject.name);
|
|
// }
|
|
|
|
private void OnClickClose()
|
|
{
|
|
GContext.Publish(new game.UnloadActToNextAct());
|
|
UIManager.Instance.DestroyUI(UITypes.PinballUncountablePanel);
|
|
}
|
|
|
|
private async void OpenPack()
|
|
{
|
|
try
|
|
{
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
var packData = manager.TableContext.GetNormalPackData();
|
|
if (packData == null)
|
|
return;
|
|
if (await EventNeoNormalPackPanel.TryShowAsync(packData))
|
|
manager.EventAggregator.Publish(new EventBlockCanvasInteraction { DoLeaveFirstAlone = false });
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private async void OnClickInfo()
|
|
{
|
|
try
|
|
{
|
|
await UIManager.Instance.ShowUINotLoading(UITypes.PinballUncountableInfoPanel);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void OnInsufficientTicket(PinballUncountable.EventInsufficientTicket _)
|
|
{
|
|
btnMultiplier.SetToCurrentMax();
|
|
btnMultiplier.ShowMax();
|
|
OpenPack();
|
|
}
|
|
|
|
|
|
#region Ticket Count Text
|
|
private int _currentTicketCount;
|
|
private void UpdateTicketCount()
|
|
{
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
DOTween.Kill(this);
|
|
DOTween.To(() => _currentTicketCount, v => _currentTicketCount = v, manager.GetTicketCount(), 0.5f)
|
|
.OnUpdate(() => SetTicketCount(_currentTicketCount))
|
|
.SetId(this);
|
|
}
|
|
|
|
private void SetTicketCount(int ticketCount)
|
|
{
|
|
textTicketCount.text = ticketCount.ToString();
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
var minMultiplier = manager.GetMultiplierArray()[0];
|
|
textTicketCount.color = ticketCount < minMultiplier ? Color.red : Color.white;
|
|
}
|
|
#endregion
|
|
|
|
#region Guide
|
|
public void TryStartGuide(EventInitGuide e)
|
|
{
|
|
Debug.Log("[PinballUncountable] Panel TryStartGuide.");
|
|
var needGuide = GContext.container.Resolve<GuideDataCenter>().InspectTriggerGuide(gameObject.name);
|
|
if (needGuide)
|
|
{
|
|
Debug.Log("[PinballUncountable] Panel TryStartGuide: Need guide.");
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
guidancePanel.Init(e.TargetNode);
|
|
manager.EventAggregator.Publish(new EventBlockCanvasInteraction());
|
|
GContext.OnEvent<AddIndexEvent>().Subscribe(OnAddIndex).AddTo(this);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("[PinballUncountable] Panel TryStartGuide: No need guide.");
|
|
}
|
|
}
|
|
|
|
private void EndGuide()
|
|
{
|
|
var manager = GContext.container.Resolve<Manager>();
|
|
guidancePanel.Hide();
|
|
manager.EventAggregator.Publish(new EventUnblockCanvasInteraction());
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
// private void Update()
|
|
// {
|
|
// if (Input.GetKeyDown(KeyCode.G))
|
|
// {
|
|
// StartGuide();
|
|
// }
|
|
// if (Input.GetKeyDown(KeyCode.H))
|
|
// {
|
|
// EndGuide();
|
|
// }
|
|
// }
|
|
#endif
|
|
|
|
private void OnAddIndex(AddIndexEvent e)
|
|
{
|
|
switch (e.guideSubIndex)
|
|
{
|
|
case 1:
|
|
Debug.Log("[PinballUncountable] OnAddIndex: 1");
|
|
EndGuide();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|