Net.Like.Xue.Tokyo/Assets/Artists/Scripts/UX/UXLevel.cs

52 lines
1.5 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using BITKit.UX;
using Cysharp.Threading.Tasks;
using Project.B.Map;
using UnityEngine;
using UnityEngine.UIElements;
namespace Net.Like.Xue.Tokyo.UX
{
public class UXLevel : UIToolKitPanel
{
private readonly IGameMapService _gameMapService;
public UXLevel(IUXService uxService, IGameMapService gameMapService) : base(uxService)
{
_gameMapService = gameMapService;
OnInitiated += Initiated;
}
protected override string DocumentPath => "ui_level";
public override bool IsWindow => true;
public override bool CloseWhenClickOutside => true;
[UXBindPath("level-container")]
private VisualElement _levelContainer;
private string _confirmMap;
private void Initiated()
{
UXUtils.Inject(this);
foreach (var button in _levelContainer.Children().OfType<Button>())
{
button.clicked += () =>
{
if (string.Equals(_confirmMap, button.viewDataKey))
{
_gameMapService.StartMapAsync(button.viewDataKey).Forget();
_confirmMap = null;
}
else
{
_confirmMap = button.viewDataKey;
}
};
}
}
}
}