102 lines
3.1 KiB
C#
102 lines
3.1 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 IUXDialogue = Net.Project.B.UX.IUXDialogue;
|
||
|
|
||
|
namespace Net.Like.Xue.Tokyo.UX
|
||
|
{
|
||
|
public class UXEscMenu : UIToolKitPanel,IDisposable
|
||
|
{
|
||
|
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("return-button")]
|
||
|
private Button _returnButton;
|
||
|
[UXBindPath("exit-button")]
|
||
|
private Button _exitButton;
|
||
|
[UXBindPath("log-label")]
|
||
|
private Label _logLabel;
|
||
|
|
||
|
|
||
|
public UXEscMenu(IUXService uxService, IUXDialogue uxDialogue, IGameMapService gameMapService, IUXKeyMap<InputAction> uxKeyMap, IDialogueService dialogueService) : base(uxService)
|
||
|
{
|
||
|
_uxDialogue = uxDialogue;
|
||
|
_gameMapService = gameMapService;
|
||
|
_uxKeyMap = uxKeyMap;
|
||
|
_dialogueService = dialogueService;
|
||
|
|
||
|
_uxDialogue.OnSubtitle += OnSubtitle;
|
||
|
|
||
|
OnInitiated += Initiated;
|
||
|
|
||
|
_dialogueService.OnDialogueStart += OnDialogueStart;
|
||
|
}
|
||
|
|
||
|
private UniTask OnDialogueStart(IDialogueData arg)
|
||
|
{
|
||
|
_dialogues.TryAdd(arg.Identity, arg);
|
||
|
|
||
|
_logLabel.text = string.Join("\n", _dialogues.Values.Select(x => x.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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|