vampire-like/Assets/GameMain/Scripts/Presentation/Main/Hud/HudController.cs

73 lines
2.0 KiB
C#

using Cysharp.Threading.Tasks;
using SepCore.Definition;
using SepCore.InputModule;
using UnityGameFramework.Runtime;
namespace SepCore.UI
{
public class HudController : UIControllerBase<HudContext, HudForm>
{
protected override UIFormType UIFormType => UIFormType.HudForm;
protected override void RefreshUI(HudForm form, HudContext context)
{
form.RefreshUI(context);
}
protected override void SubscribeCustomEvents()
{
GameEntry.InputModule.DeviceKindChanged += OnDeviceKindChanged;
}
protected override void UnsubscribeCustomEvents()
{
GameEntry.InputModule.DeviceKindChanged -= OnDeviceKindChanged;
}
private static HudContext BuildHudContext()
{
return new HudContext
{
MovePrompt = BuildPromptContext(InputActionId.Move)
};
}
private static string BuildPromptContext(InputActionId actionId)
{
if (GameEntry.InputModule == null || !GameEntry.InputModule.TryGetPrompt(actionId, out InputPrompt prompt))
{
return null;
}
return InputPromptTextUtility.BuildTmpText(prompt);
}
public override async UniTask OpenUIAsync(object userData = null, float timeout = 30f)
{
if (userData != null)
{
Log.Warning("HudController.OpenUIAsync() userData type is invalid.");
return;
}
await OpenFormAsync(BuildHudContext(), timeout);
}
public override void BindUseCase(IUIUseCase useCase)
{
Log.Info("HudFormController doesn't need UseCase");
}
private void OnDeviceKindChanged(InputDeviceKind deviceKind)
{
if (Context == null || Form == null)
{
return;
}
Context.MovePrompt = BuildPromptContext(InputActionId.Move);
Form.RefreshMovePrompt(Context.MovePrompt);
}
}
}