init
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class MenuFormContext : UIContext
|
||||
{
|
||||
public string TitleText { get; set; }
|
||||
|
||||
public string StartButtonText { get; set; }
|
||||
|
||||
public string SettingsButtonText { get; set; }
|
||||
|
||||
public string ExitButtonText { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using GeometryTD.Procedure;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TestMenuFormContext : UIContext
|
||||
{
|
||||
public RunNodeType CurrentNodeType { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.Procedure;
|
||||
using GameFramework.Event;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class MenuFormController : UIFormControllerCommonBase<MenuFormContext, MenuForm>
|
||||
{
|
||||
private MenuFormUseCase _useCase;
|
||||
|
||||
protected override UIFormType UIFormTypeId => UIFormType.MenuForm;
|
||||
|
||||
protected override void RefreshUI(MenuForm form, MenuFormContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Subscribe(MenuStartRequestedEventArgs.EventId, OnStartRequested);
|
||||
GameEntry.Event.Subscribe(MenuSettingsRequestedEventArgs.EventId, OnSettingsRequested);
|
||||
GameEntry.Event.Subscribe(MenuExitRequestedEventArgs.EventId, OnExitRequested);
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(MenuStartRequestedEventArgs.EventId, OnStartRequested);
|
||||
GameEntry.Event.Unsubscribe(MenuSettingsRequestedEventArgs.EventId, OnSettingsRequested);
|
||||
GameEntry.Event.Unsubscribe(MenuExitRequestedEventArgs.EventId, OnExitRequested);
|
||||
}
|
||||
|
||||
public override int? OpenUI(object userData = null)
|
||||
{
|
||||
if (userData is MenuFormContext context)
|
||||
{
|
||||
return OpenUIInternal(context);
|
||||
}
|
||||
|
||||
if (userData is MenuFormRawData rawDataFromUserData)
|
||||
{
|
||||
return OpenUI(rawDataFromUserData);
|
||||
}
|
||||
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("MenuFormController.OpenUI() userData type is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_useCase == null)
|
||||
{
|
||||
Log.Error("MenuFormController.OpenUI() useCase is null.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return OpenUI(_useCase.CreateInitialModel());
|
||||
}
|
||||
|
||||
public int? OpenUI(MenuFormRawData rawData)
|
||||
{
|
||||
return OpenUIInternal(BuildContext(rawData));
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
{
|
||||
if (!(useCase is MenuFormUseCase menuFormUseCase))
|
||||
{
|
||||
Log.Error("MenuFormController.BindUseCase() useCase is invalid.");
|
||||
return;
|
||||
}
|
||||
|
||||
_useCase = menuFormUseCase;
|
||||
}
|
||||
|
||||
private void OnStartRequested(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!IsCurrentFormEvent(sender) || !(e is MenuStartRequestedEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameEntry.Procedure.CurrentProcedure is ProcedureMenu procedureMenu)
|
||||
{
|
||||
procedureMenu.GameStart = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("MenuFormController received start request outside ProcedureMenu.");
|
||||
}
|
||||
|
||||
private void OnSettingsRequested(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!IsCurrentFormEvent(sender) || !(e is MenuSettingsRequestedEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("Menu settings button click is TODO.");
|
||||
}
|
||||
|
||||
private void OnExitRequested(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!IsCurrentFormEvent(sender) || !(e is MenuExitRequestedEventArgs))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UnityGameFramework.Runtime.GameEntry.Shutdown(ShutdownType.Quit);
|
||||
}
|
||||
|
||||
private bool IsCurrentFormEvent(object sender)
|
||||
{
|
||||
return Form != null && ReferenceEquals(sender, Form);
|
||||
}
|
||||
|
||||
private static MenuFormContext BuildContext(MenuFormRawData rawData)
|
||||
{
|
||||
return new MenuFormContext
|
||||
{
|
||||
TitleText = rawData?.TitleText ?? string.Empty,
|
||||
StartButtonText = rawData?.StartButtonText ?? string.Empty,
|
||||
SettingsButtonText = rawData?.SettingsButtonText ?? string.Empty,
|
||||
ExitButtonText = rawData?.ExitButtonText ?? string.Empty
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Definition;
|
||||
using GeometryTD.Procedure;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TestMenuFormController : UIFormControllerCommonBase<TestMenuFormContext, TestMenuForm>
|
||||
{
|
||||
protected override UIFormType UIFormTypeId => UIFormType.TestMenuForm;
|
||||
|
||||
protected override void RefreshUI(TestMenuForm form, TestMenuFormContext context)
|
||||
{
|
||||
form.RefreshUI(context);
|
||||
}
|
||||
|
||||
protected override void SubscribeCustomEvents()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void UnsubscribeCustomEvents()
|
||||
{
|
||||
}
|
||||
|
||||
public override int? OpenUI(object userData = null)
|
||||
{
|
||||
if (userData is TestMenuFormContext context)
|
||||
{
|
||||
return OpenUIInternal(context);
|
||||
}
|
||||
|
||||
if (userData != null)
|
||||
{
|
||||
Log.Warning("TestMenuFormController.OpenUI() userData type is invalid.");
|
||||
return null;
|
||||
}
|
||||
|
||||
return OpenUIInternal(BuildDefaultContext());
|
||||
}
|
||||
|
||||
public override void BindUseCase(IUIUseCase useCase)
|
||||
{
|
||||
if (useCase != null)
|
||||
{
|
||||
Log.Warning("TestMenuFormController does not use a use case.");
|
||||
}
|
||||
}
|
||||
|
||||
private static TestMenuFormContext BuildDefaultContext()
|
||||
{
|
||||
return new TestMenuFormContext
|
||||
{
|
||||
CurrentNodeType = RunNodeType.None
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class MenuFormRawData
|
||||
{
|
||||
public string TitleText { get; set; }
|
||||
|
||||
public string StartButtonText { get; set; }
|
||||
|
||||
public string SettingsButtonText { get; set; }
|
||||
|
||||
public string ExitButtonText { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class MenuFormUseCase : IUIUseCase
|
||||
{
|
||||
public MenuFormRawData CreateInitialModel()
|
||||
{
|
||||
return new MenuFormRawData
|
||||
{
|
||||
TitleText = "GeometryTD",
|
||||
StartButtonText = "Start",
|
||||
SettingsButtonText = "Settings",
|
||||
ExitButtonText = "Exit"
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
using GeometryTD.CustomEvent;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class MenuForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private TMP_Text _titleText;
|
||||
[SerializeField] private TMP_Text _startButtonText;
|
||||
[SerializeField] private TMP_Text _settingsButtonText;
|
||||
[SerializeField] private TMP_Text _exitButtonText;
|
||||
|
||||
private MenuFormContext _context;
|
||||
|
||||
public void RefreshUI(MenuFormContext context)
|
||||
{
|
||||
_context = context;
|
||||
if (_context == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
SetText(_titleText, _context.TitleText);
|
||||
SetText(_startButtonText, _context.StartButtonText);
|
||||
SetText(_settingsButtonText, _context.SettingsButtonText);
|
||||
SetText(_exitButtonText, _context.ExitButtonText);
|
||||
}
|
||||
|
||||
public void OnStartButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuStartRequestedEventArgs.Create());
|
||||
}
|
||||
|
||||
public void OnSettingsButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuSettingsRequestedEventArgs.Create());
|
||||
}
|
||||
|
||||
public void OnExitButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, MenuExitRequestedEventArgs.Create());
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is MenuFormContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("MenuForm requires MenuFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_context = null;
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
private static void SetText(TMP_Text textComponent, string value)
|
||||
{
|
||||
if (textComponent == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
textComponent.text = value ?? string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
using GeometryTD.CustomEvent;
|
||||
using GeometryTD.Procedure;
|
||||
using UnityEngine;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.UI
|
||||
{
|
||||
public class TestMenuForm : UGuiForm
|
||||
{
|
||||
[SerializeField] private GameObject combatButtonObject;
|
||||
[SerializeField] private GameObject eventButtonObject;
|
||||
[SerializeField] private GameObject shopButtonObject;
|
||||
|
||||
private TestMenuFormContext _context;
|
||||
|
||||
public void RefreshUI(TestMenuFormContext context)
|
||||
{
|
||||
_context = context;
|
||||
if (_context == null)
|
||||
{
|
||||
SetButtonVisible(combatButtonObject, false);
|
||||
SetButtonVisible(eventButtonObject, false);
|
||||
SetButtonVisible(shopButtonObject, false);
|
||||
return;
|
||||
}
|
||||
|
||||
SetButtonVisible(
|
||||
combatButtonObject,
|
||||
_context.CurrentNodeType == RunNodeType.Combat || _context.CurrentNodeType == RunNodeType.BossCombat);
|
||||
SetButtonVisible(eventButtonObject, _context.CurrentNodeType == RunNodeType.Event);
|
||||
SetButtonVisible(shopButtonObject, _context.CurrentNodeType == RunNodeType.Shop);
|
||||
}
|
||||
|
||||
public void OnCombatButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, TestMenuNodeClickEventArgs.Create(TestMenuNodeType.Combat));
|
||||
}
|
||||
|
||||
public void OnEventButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, TestMenuNodeClickEventArgs.Create(TestMenuNodeType.Event));
|
||||
}
|
||||
|
||||
public void OnShopButtonClick()
|
||||
{
|
||||
GameEntry.Event.Fire(this, TestMenuNodeClickEventArgs.Create(TestMenuNodeType.Shop));
|
||||
}
|
||||
|
||||
protected override void OnOpen(object userData)
|
||||
{
|
||||
base.OnOpen(userData);
|
||||
|
||||
if (userData is TestMenuFormContext context)
|
||||
{
|
||||
RefreshUI(context);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Warning("TestMenuForm requires TestMenuFormContext as userData.");
|
||||
}
|
||||
|
||||
protected override void OnClose(bool isShutdown, object userData)
|
||||
{
|
||||
_context = null;
|
||||
SetButtonVisible(combatButtonObject, false);
|
||||
SetButtonVisible(eventButtonObject, false);
|
||||
SetButtonVisible(shopButtonObject, false);
|
||||
|
||||
base.OnClose(isShutdown, userData);
|
||||
}
|
||||
|
||||
private static void SetButtonVisible(GameObject buttonObject, bool visible)
|
||||
{
|
||||
if (buttonObject != null)
|
||||
{
|
||||
buttonObject.SetActive(visible);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user