92 lines
2.3 KiB
C#
92 lines
2.3 KiB
C#
using SepCore.Definition;
|
|
using SepCore.Event;
|
|
using UnityEngine.EventSystems;
|
|
using UnityGameFramework.Runtime;
|
|
|
|
namespace SepCore.UI
|
|
{
|
|
public partial class MenuForm
|
|
{
|
|
private bool _listenersBound;
|
|
|
|
public void RefreshUI(MenuContext context)
|
|
{
|
|
EnsureButtonListeners();
|
|
|
|
if (EventSystem.current.currentSelectedGameObject != View.startButton.gameObject)
|
|
{
|
|
EventSystem.current.SetSelectedGameObject(View.startButton.gameObject);
|
|
}
|
|
}
|
|
|
|
#region Lifecycle
|
|
|
|
protected override void OnOpen(object userData)
|
|
{
|
|
base.OnOpen(userData);
|
|
|
|
if (userData is not MenuContext context)
|
|
{
|
|
Log.Error("MenuForm requires MenuContext as userData.");
|
|
return;
|
|
}
|
|
|
|
RefreshUI(context);
|
|
}
|
|
|
|
#endregion
|
|
|
|
private void EnsureButtonListeners()
|
|
{
|
|
if (_listenersBound)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_listenersBound = true;
|
|
|
|
View.startButton.onClick.AddListener(OnStartButtonClick);
|
|
View.fileButton.onClick.AddListener(OnFileButtonClick);
|
|
View.guideButton.onClick.AddListener(OnGuideButtonClick);
|
|
View.settingButton.onClick.AddListener(OnSettingButtonClick);
|
|
View.quitButton.onClick.AddListener(OnQuitButtonClick);
|
|
View.aboutButton.onClick.AddListener(OnAboutButtonClick);
|
|
}
|
|
|
|
private void OnStartButtonClick()
|
|
{
|
|
FireButtonClick(MenuButtonId.StartGame);
|
|
}
|
|
|
|
private void OnFileButtonClick()
|
|
{
|
|
FireButtonClick(MenuButtonId.File);
|
|
}
|
|
|
|
private void OnGuideButtonClick()
|
|
{
|
|
FireButtonClick(MenuButtonId.Guide);
|
|
}
|
|
|
|
private void OnSettingButtonClick()
|
|
{
|
|
FireButtonClick(MenuButtonId.Setting);
|
|
}
|
|
|
|
private void OnQuitButtonClick()
|
|
{
|
|
FireButtonClick(MenuButtonId.Quit);
|
|
}
|
|
|
|
private void OnAboutButtonClick()
|
|
{
|
|
FireButtonClick(MenuButtonId.About);
|
|
}
|
|
|
|
private void FireButtonClick(MenuButtonId button)
|
|
{
|
|
GameEntry.Event.Fire(this, MenuButtonClickEventArgs.Create(button));
|
|
}
|
|
}
|
|
}
|