hellbound/Assets/Scripts/Game/UI/Windows/MainWindow.cs

68 lines
2.0 KiB
C#

using I2.Loc;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public enum EnumPlayButtonAction
{
ON_CLICK,
ON_DOWN
}
public class MainWindow : ParameterlessWindow
{
[SerializeField] private Button _playButton = null;
[SerializeField] private EnumPlayButtonAction _playButtonAction;
[SerializeField] private Button _shopButton = null;
[SerializeField] private Button _settingsButton = null;
[SerializeField] private LocalizationParamsManager _levelNumberParameter = null;
private BuffSection _buffSection = null;
protected override void OnInit()
{
switch (_playButtonAction)
{
case EnumPlayButtonAction.ON_CLICK:
_playButton.onClick.AddListener(Play);
break;
case EnumPlayButtonAction.ON_DOWN:
var trigger = _playButton.gameObject.AddComponent<EventTrigger>();
var pointerDown = new EventTrigger.Entry { eventID = EventTriggerType.PointerDown };
pointerDown.callback.AddListener(_ => Play());
trigger.triggers.Add(pointerDown);
break;
}
_shopButton.gameObject.SetActive(Settings.SHOP_ENABLE);
_shopButton.onClick.AddListener(() =>
{
var market = new Market("@market/market");
var marketUI = UI.GetOrCreateWindow<MarketUI>();
marketUI.SetMarket(market);
marketUI.Show();
});
_settingsButton.onClick.AddListener(() => UI.ShowWindow<SettingsWindow>());
_buffSection = GetComponentInChildren<BuffSection>();
_buffSection.Init();
}
private void Play()
{
Hide();
G.Instance.Session.LaunchLevel();
}
protected override void OnShowed()
{
SyncLevelNumber();
}
private void SyncLevelNumber()
{
int levelNumber = Save.Progress.Level + 1;
_levelNumberParameter.SetParameterValue("INDEX",levelNumber.ToString());
}
}