using System.Collections; using System.Collections.Generic; using System.Linq; using BITKit; using BITKit.Entities; using BITKit.Mod; using BITKit.UX; using Cysharp.Threading.Tasks; using Microsoft.Extensions.Logging; using Project.B.Map; using Project.B.Player; using Unity.Mathematics; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UIElements; namespace Net.Project.B.UX { public class UXMapSelector : UIToolKitPanel, IUXMapSelector { private readonly IEntitiesService _entitiesService; private readonly IUXKeyMap _uxKeyMap; private readonly ILogger _logger; private readonly IGameMapService _gameMapService; protected override string DocumentPath => "ui_map_selector"; public override bool AllowCursor => true; [UXBindPath("map-name")] private Label _mapNameLabel; [UXBindPath("map-description")] private Label _mapDescriptionLabel; [UXBindPath("map-container")] private VisualElement _mapContainer; [UXBindPath("background-image")] private VisualElement _backgroundImage; public UXMapSelector(IUXService uxService, IGameMapService gameMapService, ILogger logger, IUXKeyMap uxKeyMap, IEntitiesService entitiesService) : base(uxService) { _gameMapService = gameMapService; _logger = logger; _uxKeyMap = uxKeyMap; _entitiesService = entitiesService; } protected override void OnPanelEntry() { base.OnPanelEntry(); _backgroundImage.transform.scale = new Vector3(1.2f, 1.2f, 1.2f); InputActionGroup.RegisterCallback(_uxKeyMap.InventoryKey, OnReturn); InputActionGroup.RegisterCallback(_uxKeyMap.CancelKey, OnReturn); } private void OnReturn(InputAction.CallbackContext obj) { if (obj is { performed: true }) { UXService.Return(); } } protected override void OnPanelExit() { base.OnPanelExit(); InputActionGroup.UnRegisterCallback(_uxKeyMap.InventoryKey, OnReturn); InputActionGroup.UnRegisterCallback(_uxKeyMap.CancelKey, OnReturn); } public override async UniTask EntryAsync() { await base.EntryAsync(); _mapContainer.Clear(); var maps = _entitiesService.QueryComponents().ToArray(); foreach (var gameMapData in maps.OrderBy(x=>x.MapName)) { var button = _mapContainer.Create