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

62 lines
1.9 KiB
C#
Raw Normal View History

2024-12-28 23:19:55 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
2025-02-25 13:50:01 +08:00
using BITKit;
using BITKit.Entities;
2024-12-28 23:19:55 +08:00
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;
2025-02-25 13:50:01 +08:00
private readonly IEntitiesService _entitiesService;
2024-12-28 23:19:55 +08:00
2025-02-25 13:50:01 +08:00
public UXLevel(IUXService uxService, IGameMapService gameMapService, IEntitiesService entitiesService) : base(uxService)
2024-12-28 23:19:55 +08:00
{
_gameMapService = gameMapService;
2025-02-25 13:50:01 +08:00
_entitiesService = entitiesService;
2024-12-28 23:19:55 +08:00
}
2025-02-25 13:50:01 +08:00
public override async UniTask EntryAsync()
2024-12-28 23:19:55 +08:00
{
2025-02-25 13:50:01 +08:00
await base.EntryAsync();
_levelContainer.Clear();
foreach (var gameMapData in _entitiesService.QueryComponents<ScriptableGameMapData>())
2024-12-28 23:19:55 +08:00
{
2025-02-25 13:50:01 +08:00
var button = _levelContainer.Create<Button>();
if (gameMapData.Overview is Sprite sprite)
{
button.style.backgroundImage = new(sprite);
2025-02-26 15:34:59 +08:00
}else if (gameMapData.Overview is Texture2D texture2D)
{
button.style.backgroundImage = new(texture2D);
2025-02-25 13:50:01 +08:00
}
2025-02-26 15:34:59 +08:00
button.text = gameMapData.MapName;
2024-12-28 23:19:55 +08:00
button.clicked += () =>
{
2025-02-25 13:50:01 +08:00
_gameMapService.StartMapAsync(gameMapData.MapAddress).Forget();
2024-12-28 23:19:55 +08:00
};
}
2025-02-25 13:50:01 +08:00
2024-12-28 23:19:55 +08:00
}
2025-02-25 13:50:01 +08:00
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;
2024-12-28 23:19:55 +08:00
}
}