This commit is contained in:
CortexCore
2025-01-12 11:13:19 +08:00
parent 01e7e4e35e
commit 01b3d1be43
26 changed files with 387 additions and 336 deletions

View File

@@ -5,6 +5,7 @@ using UnityEngine;
using UnityEngine.UIElements;
using UnityEngine.InputSystem;
using BITKit.Mod;
using Cysharp.Threading.Tasks;
using Object = UnityEngine.Object;
namespace BITKit.UX.Internal
@@ -111,7 +112,7 @@ namespace BITKit.UX
private readonly IUXService _uxService;
private VisualElement _root;
private VisualElement _container;
private bool _isInitialized = false;
private readonly UniTaskCompletionSource _waitUntilInitialized = new();
public UXContextMenu(IUXService uxService)
{
_uxService = uxService;
@@ -144,11 +145,14 @@ namespace BITKit.UX
{
Close();
});
_isInitialized = true;
_waitUntilInitialized.TrySetResult();
Close();
}
public void Create(ContextMenuBuilder builder)
public async void Create(ContextMenuBuilder builder)
{
await _waitUntilInitialized.Task;
var pos = Mouse.current.position.ReadValue();
pos.y = Screen.height - pos.y;
pos = RuntimePanelUtils.ScreenToPanel(_root.panel, pos);
@@ -166,9 +170,9 @@ namespace BITKit.UX
}
builder.OnExecuted += Close;
}
private void Close()
private async void Close()
{
if(_isInitialized is false)return;
await _waitUntilInitialized.Task;
_container.Clear();
_root.SetActive(false);
}