177 lines
6.1 KiB
C#
177 lines
6.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.Mod;
|
|
using BITKit.UX;
|
|
using BITKit.UX.Hotkey;
|
|
using BITKit.WorldNode;
|
|
using Cysharp.Threading.Tasks;
|
|
using Net.Project.B.Emoji;
|
|
using Net.Project.B.Interaction;
|
|
using Net.Project.B.Quest;
|
|
using Net.Project.B.UX;
|
|
using Project.B.Entities;
|
|
using Project.B.Map;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace Net.Like.Xue.Tokyo.UX
|
|
{
|
|
public class UXHud : UIToolKitPanel
|
|
{
|
|
private readonly IPlayerFactory _playerFactory;
|
|
private readonly IGameMapService _gameMapService;
|
|
private readonly IWorldInteractionService _interactionService;
|
|
private readonly WorldInfoNodeService _worldInfoNodeService;
|
|
private readonly IQuestService _questService;
|
|
private readonly UXRadialMenu _radialMenu;
|
|
|
|
[Inject]
|
|
private IEmojiService<AnimationClip> _emojiService;
|
|
public UXHud(IUXService uxService, IGameMapService gameMapService, IWorldInteractionService interactionService, WorldInfoNodeService worldInfoNodeService, IQuestService questService, UXRadialMenu radialMenu, IPlayerFactory playerFactory) : base(uxService)
|
|
{
|
|
_gameMapService = gameMapService;
|
|
_interactionService = interactionService;
|
|
_worldInfoNodeService = worldInfoNodeService;
|
|
_questService = questService;
|
|
_radialMenu = radialMenu;
|
|
_playerFactory = playerFactory;
|
|
|
|
_gameMapService.OnMapChanged += OnMapChanged;
|
|
|
|
_interactionService.OnInteraction += OnInteraction;
|
|
|
|
|
|
Data.AddListener<float>("Time",x=>
|
|
{
|
|
_timeSlider?.SetValueWithoutNotify(x);
|
|
});
|
|
|
|
_questService.OnQuestCreatedOrUpdated +=(x,y,z)=>_questQueue.Enqueue(new(x,y,z));
|
|
foreach (var (index,quest) in _questService.Quests)
|
|
{
|
|
_questQueue.Enqueue(new(quest,QuestState.Inactive,quest.CurrentState));
|
|
}
|
|
|
|
_playerFactory.OnEntityCreated += OnEntityCreated;
|
|
}
|
|
|
|
private UniTask OnEntityCreated(string arg1, IEntity arg2)
|
|
{
|
|
arg2.Inject(this);
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
private void OnInteraction(object arg1, IWorldInteractable arg2, WorldInteractionProcess arg3, object arg4)
|
|
{
|
|
switch (arg3)
|
|
{
|
|
case WorldInteractionProcess.Hover:
|
|
_interactionTips.SetActive(true);
|
|
_interactionTips.text = _worldInfoNodeService.WorldInfoNodes.TryGetValue(arg2.Id, out var node) ? node.Name : "互动";
|
|
break;
|
|
default:
|
|
_interactionTips.SetActive(false);
|
|
break;
|
|
}
|
|
}
|
|
|
|
private void OnMapChanged(Guid arg1, string arg2)
|
|
{
|
|
UXService.Entry<UXHud>();
|
|
}
|
|
|
|
protected override string DocumentPath => "ux_hud";
|
|
public override bool AllowInput => true;
|
|
public override bool AllowCursor => false;
|
|
|
|
[UXBindPath("minimap-container")]
|
|
private VisualElement _minimapContainer;
|
|
[UXBindPath("minimap-player")]
|
|
private VisualElement _miniPlayer;
|
|
[UXBindPath("interaction-tips")]
|
|
private Label _interactionTips;
|
|
[UXBindPath("time-slider")]
|
|
private Slider _timeSlider;
|
|
[UXBindPath("quest-container")]
|
|
private VisualElement _questContainer;
|
|
|
|
private Camera _minimapCamera;
|
|
private Camera _mainCamera;
|
|
|
|
private VisualTreeAsset _questTemplate;
|
|
|
|
private readonly Queue<(IQuestData questData, QuestState oldQuestState, QuestState newQuestState)> _questQueue =
|
|
new();
|
|
|
|
public override async UniTask EntryAsync()
|
|
{
|
|
await base.EntryAsync();
|
|
UXUtils.Inject(this);
|
|
|
|
_interactionTips.SetActive(false);
|
|
|
|
_minimapContainer.RegisterCallback<MouseDownEvent>(x =>
|
|
{
|
|
UXService.Entry<UXMap>();
|
|
});
|
|
|
|
_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)
|
|
{
|
|
base.OnTick(deltaTime);
|
|
|
|
if(RootVisualElement is null)return;
|
|
|
|
if (Keyboard.current is { capsLockKey: { wasPressedThisFrame: true } } or {mKey:{wasPressedThisFrame:true}})
|
|
{
|
|
UXService.Entry<UXMap>();
|
|
}else if (Keyboard.current is { f1Key: { wasPressedThisFrame: true } })
|
|
{
|
|
var collection = new HotkeyCollection();
|
|
_radialMenu.HotkeyCollection = collection;
|
|
|
|
foreach (var emojiData in await _emojiService.GetAllEmojis())
|
|
{
|
|
collection.Register(new HotkeyProvider()
|
|
{
|
|
Name = emojiData.Name,
|
|
Description = emojiData.Description,
|
|
Enabled = true,
|
|
OnPerform = () => _emojiService.Play(emojiData),
|
|
});
|
|
}
|
|
|
|
UXService.Entry(_radialMenu);
|
|
}else if (Keyboard.current is { tabKey: { wasPressedThisFrame: true } })
|
|
{
|
|
UXService.Entry<IUXInventory>();
|
|
}
|
|
|
|
|
|
if (_questContainer is not null && _questTemplate!=null)
|
|
{
|
|
while (_questQueue.TryDequeue(out var quest))
|
|
{
|
|
var visualElement = _questContainer.Create(_questTemplate);
|
|
visualElement.Get<Label>(0).text = quest.questData.Name;
|
|
visualElement.Get<Label>(1).text = quest.questData.Description;
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
}
|