1
This commit is contained in:
@@ -15,6 +15,7 @@ using Net.Project.B.Quest;
|
||||
using Net.Project.B.UX;
|
||||
using Project.B.Entities;
|
||||
using Project.B.Map;
|
||||
using Project.B.Player;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
@@ -22,7 +23,7 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace Net.Like.Xue.Tokyo.UX
|
||||
{
|
||||
public class UXHud : UIToolKitPanel
|
||||
public class UXHud : UIToolKitPanel,IUXHud
|
||||
{
|
||||
private readonly IEntitiesService _entitiesService;
|
||||
private readonly IPlayerFactory _playerFactory;
|
||||
@@ -30,10 +31,11 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
private readonly IWorldInteractionService _interactionService;
|
||||
private readonly IQuestService _questService;
|
||||
private readonly UXRadialMenu _radialMenu;
|
||||
private readonly IUXKeyMap<InputAction> _uxKeyMap;
|
||||
|
||||
[Inject]
|
||||
private IEmojiService<AnimationClip> _emojiService;
|
||||
public UXHud(IUXService uxService, IGameMapService gameMapService, IWorldInteractionService interactionService, IQuestService questService, UXRadialMenu radialMenu, IPlayerFactory playerFactory, IEntitiesService entitiesService) : base(uxService)
|
||||
public UXHud(IUXService uxService, IGameMapService gameMapService, IWorldInteractionService interactionService, IQuestService questService, UXRadialMenu radialMenu, IPlayerFactory playerFactory, IEntitiesService entitiesService, IUXKeyMap<InputAction> uxKeyMap) : base(uxService)
|
||||
{
|
||||
_gameMapService = gameMapService;
|
||||
_interactionService = interactionService;
|
||||
@@ -41,6 +43,7 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
_radialMenu = radialMenu;
|
||||
_playerFactory = playerFactory;
|
||||
_entitiesService = entitiesService;
|
||||
_uxKeyMap = uxKeyMap;
|
||||
|
||||
_gameMapService.OnMapChanged += OnMapChanged;
|
||||
|
||||
@@ -59,6 +62,18 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
}
|
||||
|
||||
_playerFactory.OnEntityCreated += OnEntityCreated;
|
||||
|
||||
OnInitiatedAsync += InitiatedAsync;
|
||||
}
|
||||
|
||||
private async UniTask InitiatedAsync()
|
||||
{
|
||||
_timeSlider.RegisterValueChangedCallback(x => { Data.Set("Time", x.newValue); });
|
||||
_questContainer.Clear();
|
||||
|
||||
_questTemplate =await ModService.LoadAsset<VisualTreeAsset>("ux_quest_template");
|
||||
|
||||
_timeSlider.value = Data.Get<float>("Time");
|
||||
}
|
||||
|
||||
private UniTask OnEntityCreated(string arg1, IEntity arg2)
|
||||
@@ -73,7 +88,7 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
{
|
||||
case WorldInteractionProcess.Hover:
|
||||
_interactionTips.SetActive(true);
|
||||
if (_entitiesService.Entities.TryGetValue(arg2.Id, out var entity) &&
|
||||
if (_entitiesService.Entities.TryGetValue( arg2.WorldObject.As<GameObject>().GetInstanceID(), out var entity) &&
|
||||
entity.ServiceProvider.GetService<WorldInfoNode>() is { } infoNode && string.IsNullOrEmpty(infoNode.Name) is false)
|
||||
{
|
||||
_interactionTips.text = infoNode.Name;
|
||||
@@ -92,7 +107,7 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
|
||||
private void OnMapChanged(Guid arg1, string arg2)
|
||||
{
|
||||
UXService.Entry<UXHud>();
|
||||
UXService.Entry<IUXHud>();
|
||||
}
|
||||
|
||||
protected override string DocumentPath => "ux_hud";
|
||||
@@ -119,17 +134,9 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
public override async UniTask EntryAsync()
|
||||
{
|
||||
await base.EntryAsync();
|
||||
UXUtils.Inject(this);
|
||||
|
||||
_interactionTips.SetActive(false);
|
||||
|
||||
|
||||
_timeSlider.RegisterValueChangedCallback(x => { Data.Set("Time", x.newValue); });
|
||||
_questContainer.Clear();
|
||||
|
||||
_questTemplate =await ModService.LoadAsset<VisualTreeAsset>("ux_quest_template");
|
||||
|
||||
_timeSlider.value = Data.Get<float>("Time");
|
||||
|
||||
}
|
||||
|
||||
public override async void OnTick(float deltaTime)
|
||||
@@ -156,11 +163,7 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
OnPerform = () => _emojiService.Play(emojiData),
|
||||
});
|
||||
}
|
||||
|
||||
UXService.Entry(_radialMenu);
|
||||
}else if (Keyboard.current is { tabKey: { wasPressedThisFrame: true } })
|
||||
{
|
||||
UXService.Entry<IUXInventory>();
|
||||
}
|
||||
|
||||
|
||||
@@ -188,6 +191,32 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void OnPanelEntry()
|
||||
{
|
||||
base.OnPanelEntry();
|
||||
InputActionGroup.RegisterCallback(_uxKeyMap.CancelKey, OnCancel);
|
||||
InputActionGroup.RegisterCallback(_uxKeyMap.InventoryKey,OnInventory);
|
||||
}
|
||||
|
||||
private void OnInventory(InputAction.CallbackContext obj)
|
||||
{
|
||||
if(obj.JustPressed() is false)return;
|
||||
UXService.Entry<IUXInventory>();
|
||||
}
|
||||
|
||||
private void OnCancel(InputAction.CallbackContext obj)
|
||||
{
|
||||
if (obj.JustPressed() is false) return;
|
||||
UXService.Entry<UXEscMenu>();
|
||||
}
|
||||
|
||||
protected override void OnPanelExit()
|
||||
{
|
||||
base.OnPanelExit();
|
||||
InputActionGroup.UnRegisterCallback(_uxKeyMap.CancelKey, OnCancel);
|
||||
InputActionGroup.UnRegisterCallback(_uxKeyMap.InventoryKey, OnInventory);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user