163 lines
5.3 KiB
C#
163 lines
5.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using BITKit;
|
|
using BITKit.UX;
|
|
using Cysharp.Threading.Tasks;
|
|
using Net.Project.B.Dialogue;
|
|
using Net.Project.B.UX;
|
|
using Project.B.Map;
|
|
using Project.B.Player;
|
|
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;
|
|
protected override string DocumentPath => "ui_menu_esc";
|
|
public override bool AllowInput => false;
|
|
public override bool AllowCursor => true;
|
|
|
|
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;
|
|
|
|
private VisualTreeAsset _template;
|
|
|
|
|
|
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);
|
|
|
|
|
|
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;
|
|
}
|
|
|
|
private void Initiated()
|
|
{
|
|
_returnButton.clicked += UXService.Return;
|
|
_exitButton.clicked +=()=> _gameMapService.StopMapAsync().Forget();
|
|
}
|
|
|
|
private string OnSubtitle(string arg)
|
|
{
|
|
return arg;
|
|
}
|
|
|
|
protected override void OnPanelEntry()
|
|
{
|
|
base.OnPanelEntry();
|
|
InputActionGroup.RegisterCallback(_uxKeyMap.CancelKey, OnCancel);
|
|
}
|
|
|
|
private void OnCancel(InputAction.CallbackContext obj)
|
|
{
|
|
if(obj.JustPressed() is false)return;
|
|
UXService.Entry<IUXHud>();
|
|
}
|
|
|
|
protected override void OnPanelExit()
|
|
{
|
|
base.OnPanelExit();
|
|
InputActionGroup.UnRegisterCallback(_uxKeyMap.CancelKey, OnCancel);
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
base.Dispose();
|
|
_dialogueService.OnDialogueStart -= OnDialogueStart;
|
|
}
|
|
}
|
|
|
|
|
|
}
|