1
This commit is contained in:
@@ -13,12 +13,18 @@ using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.UIElements;
|
||||
using System.Linq;
|
||||
using BITKit.Entities;
|
||||
using BITKit.Mod;
|
||||
using Net.BITKit.Localization;
|
||||
using YooAsset;
|
||||
using IUXDialogue = Net.Project.B.UX.IUXDialogue;
|
||||
|
||||
namespace Net.Like.Xue.Tokyo.UX
|
||||
{
|
||||
public class UXEscMenu : UIToolKitPanel,IDisposable
|
||||
{
|
||||
private readonly IEntitiesService _entitiesService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IDialogueService _dialogueService;
|
||||
private readonly IGameMapService _gameMapService;
|
||||
private readonly IUXDialogue _uxDialogue;
|
||||
@@ -29,35 +35,90 @@ namespace Net.Like.Xue.Tokyo.UX
|
||||
private readonly IUXKeyMap<InputAction> _uxKeyMap;
|
||||
|
||||
private readonly ConcurrentDictionary<int, IDialogueData> _dialogues = new();
|
||||
|
||||
[UXBindPath("dialogue-container")]
|
||||
private VisualElement _dialogueContainer;
|
||||
[UXBindPath("return-button")]
|
||||
private Button _returnButton;
|
||||
[UXBindPath("exit-button")]
|
||||
private Button _exitButton;
|
||||
[UXBindPath("log-label")]
|
||||
private Label _logLabel;
|
||||
|
||||
private VisualTreeAsset _template;
|
||||
|
||||
|
||||
public UXEscMenu(IUXService uxService, IUXDialogue uxDialogue, IGameMapService gameMapService, IUXKeyMap<InputAction> uxKeyMap, IDialogueService dialogueService) : base(uxService)
|
||||
public UXEscMenu(IUXService uxService, IUXDialogue uxDialogue, IGameMapService gameMapService, IUXKeyMap<InputAction> uxKeyMap, IDialogueService dialogueService, ILocalizationService localizationService, IEntitiesService entitiesService) : base(uxService)
|
||||
{
|
||||
_uxDialogue = uxDialogue;
|
||||
_gameMapService = gameMapService;
|
||||
_uxKeyMap = uxKeyMap;
|
||||
_dialogueService = dialogueService;
|
||||
_localizationService = localizationService;
|
||||
_entitiesService = entitiesService;
|
||||
|
||||
_uxDialogue.OnSubtitle += OnSubtitle;
|
||||
|
||||
OnInitiated += Initiated;
|
||||
OnInitiatedAsync += InitiatedAsync;
|
||||
|
||||
_dialogueService.OnDialogueStart += OnDialogueStart;
|
||||
|
||||
|
||||
}
|
||||
|
||||
private async UniTask InitiatedAsync()
|
||||
{
|
||||
_template =await ModService.LoadAsset<VisualTreeAsset>("ui_esc_menu_dialogue-template");
|
||||
_dialogueContainer.Clear();
|
||||
}
|
||||
|
||||
private UniTask OnDialogueStart(IDialogueData arg)
|
||||
{
|
||||
_dialogues.TryAdd(arg.Identity, arg);
|
||||
|
||||
_logLabel.text = string.Join("\n", _dialogues.Values.Select(x => x.Text));
|
||||
|
||||
var actorName = arg.ActorIdentity.ToString();
|
||||
|
||||
try
|
||||
{
|
||||
if (arg.ActorIdentity != 0)
|
||||
{
|
||||
foreach (var idComponent in _entitiesService.QueryComponents<IdComponent>())
|
||||
{
|
||||
if (idComponent.Id == arg.ActorIdentity)
|
||||
{
|
||||
actorName = idComponent.Name;
|
||||
throw new OperationCanceledException();
|
||||
}
|
||||
}
|
||||
}
|
||||
actorName = _entitiesService.QueryComponents<IdComponent, LocalPlayerComponent>()[0].Item1.Name;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
var container = _dialogueContainer.Create(_template);
|
||||
|
||||
container.Get<Label>().text = actorName;
|
||||
|
||||
container = container.Get<VisualElement>();
|
||||
|
||||
container.Clear();
|
||||
|
||||
|
||||
foreach (var dictionary in _localizationService.LocalizedStrings.Values)
|
||||
{
|
||||
if (dictionary.TryGetValue(arg.Text, out var text))
|
||||
{
|
||||
container.Create<Label>().text = text;
|
||||
}
|
||||
else
|
||||
{
|
||||
container.Create<Label>().text = arg.Text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return UniTask.CompletedTask;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user