2024-11-03 16:42:23 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BITKit;
|
2024-11-20 11:36:36 +08:00
|
|
|
using BITKit.Mod;
|
2024-11-03 16:42:23 +08:00
|
|
|
using BITKit.UX;
|
|
|
|
using BITKit.WorldNode;
|
|
|
|
using Cysharp.Threading.Tasks;
|
|
|
|
using Net.Project.B.Interaction;
|
2024-11-20 11:36:36 +08:00
|
|
|
using Net.Project.B.Quest;
|
2024-11-03 16:42:23 +08:00
|
|
|
using Project.B.Map;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.UIElements;
|
|
|
|
|
|
|
|
namespace Net.Like.Xue.Tokyo.UX
|
|
|
|
{
|
|
|
|
public class UXHud : UIToolKitPanel
|
|
|
|
{
|
|
|
|
private readonly IGameMapService _gameMapService;
|
|
|
|
private readonly IWorldInteractionService _interactionService;
|
|
|
|
private readonly WorldInfoNodeService _worldInfoNodeService;
|
2024-11-20 11:36:36 +08:00
|
|
|
private readonly IQuestService _questService;
|
|
|
|
public UXHud(IUXService uxService, IGameMapService gameMapService, IWorldInteractionService interactionService, WorldInfoNodeService worldInfoNodeService, IQuestService questService) : base(uxService)
|
2024-11-03 16:42:23 +08:00
|
|
|
{
|
|
|
|
_gameMapService = gameMapService;
|
|
|
|
_interactionService = interactionService;
|
|
|
|
_worldInfoNodeService = worldInfoNodeService;
|
2024-11-20 11:36:36 +08:00
|
|
|
_questService = questService;
|
2024-11-03 16:42:23 +08:00
|
|
|
|
|
|
|
_gameMapService.OnMapChanged += OnMapChanged;
|
|
|
|
|
|
|
|
_interactionService.OnInteraction += OnInteraction;
|
2024-11-20 11:36:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
2024-11-03 16:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2024-11-20 11:36:36 +08:00
|
|
|
[UXBindPath("time-slider")]
|
|
|
|
private Slider _timeSlider;
|
|
|
|
[UXBindPath("quest-container")]
|
|
|
|
private VisualElement _questContainer;
|
2024-11-03 16:42:23 +08:00
|
|
|
|
|
|
|
private Camera _minimapCamera;
|
|
|
|
private Camera _mainCamera;
|
2024-11-20 11:36:36 +08:00
|
|
|
|
|
|
|
private VisualTreeAsset _questTemplate;
|
|
|
|
|
|
|
|
private readonly Queue<(IQuestData questData, QuestState oldQuestState, QuestState newQuestState)> _questQueue =
|
|
|
|
new();
|
|
|
|
|
2024-11-03 16:42:23 +08:00
|
|
|
public override async UniTask EntryAsync()
|
|
|
|
{
|
|
|
|
await base.EntryAsync();
|
|
|
|
UXUtils.Inject(this);
|
|
|
|
|
|
|
|
_interactionTips.SetActive(false);
|
|
|
|
|
|
|
|
_minimapContainer.RegisterCallback<MouseDownEvent>(x =>
|
|
|
|
{
|
|
|
|
UXService.Entry<UXMap>();
|
|
|
|
});
|
2024-11-20 11:36:36 +08:00
|
|
|
|
|
|
|
_timeSlider.RegisterValueChangedCallback(x => { Data.Set("Time", x.newValue); });
|
|
|
|
_questContainer.Clear();
|
|
|
|
|
|
|
|
_questTemplate =await ModService.LoadAsset<VisualTreeAsset>("ux_quest_template");
|
|
|
|
|
|
|
|
_timeSlider.value = Data.Get<float>("Time");
|
2024-11-03 16:42:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnTick(float deltaTime)
|
|
|
|
{
|
|
|
|
base.OnTick(deltaTime);
|
|
|
|
|
|
|
|
if(RootVisualElement is null)return;
|
|
|
|
if (!_minimapCamera)
|
|
|
|
{
|
|
|
|
_minimapCamera = GameObject.Find("minimap_camera")?.GetComponent<Camera>();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!_mainCamera)
|
|
|
|
{
|
|
|
|
_mainCamera = Camera.main;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var point = _minimapCamera.WorldToViewportPoint(_mainCamera.transform.position);
|
|
|
|
|
|
|
|
_miniPlayer.style.left = _minimapContainer.layout.width * point.x - _miniPlayer.layout.width / 2;
|
2024-11-13 17:47:45 +08:00
|
|
|
_miniPlayer.style.top = _minimapContainer.layout.height * (1-point.y) - _miniPlayer.layout.height / 2;
|
2024-11-20 11:36:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2024-11-03 16:42:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|