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

86 lines
2.7 KiB
C#
Raw Normal View History

2025-02-28 21:17:03 +08:00
using System;
2024-11-03 16:42:23 +08:00
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
2025-03-10 20:36:11 +08:00
using BITKit;
using BITKit.Entities;
2024-11-03 16:42:23 +08:00
using BITKit.UX;
using Cysharp.Threading.Tasks;
2025-03-10 20:36:11 +08:00
using Net.Project.B.Cosmetics;
2025-03-05 22:28:38 +08:00
using Net.Project.B.UX;
2024-11-03 16:42:23 +08:00
using Project.B.Entities;
using Project.B.Map;
using UnityEngine;
using UnityEngine.UIElements;
using YooAsset;
namespace Net.Like.Xue.Tokyo.UX
{
2025-03-05 22:28:38 +08:00
public class UXMenu : UIToolKitPanel,IUXLobby
2024-11-03 16:42:23 +08:00
{
2025-03-10 20:36:11 +08:00
private readonly IEntitiesService _entitiesService;
2025-02-28 21:17:03 +08:00
private readonly IGameMapService _gameMapService;
2025-03-10 20:36:11 +08:00
private readonly IWrapper<CosmeticsCustomizeComponent> _cosmeticsCustomize;
2024-11-03 16:42:23 +08:00
protected override string DocumentPath => "ux_menu";
public override bool AllowInput => false;
public override bool AllowCursor => true;
2024-12-28 23:19:55 +08:00
[UXBindPath("play-button")]
private Button _playButton;
2025-03-10 20:36:11 +08:00
[UXBindPath("avatar-image")]
private VisualElement _avatarImage;
[UXBindPath("player-name")]
private Label _playerName;
public UXMenu(IUXService uxService, IGameMapService gameMapService, IWrapper<CosmeticsCustomizeComponent> cosmeticsCustomize, IEntitiesService entitiesService) : base(uxService)
2024-12-28 23:19:55 +08:00
{
2025-02-28 21:17:03 +08:00
_gameMapService = gameMapService;
2025-03-10 20:36:11 +08:00
_cosmeticsCustomize = cosmeticsCustomize;
_entitiesService = entitiesService;
2024-12-28 23:19:55 +08:00
OnInitiated += Initiated;
2025-02-28 21:17:03 +08:00
_gameMapService.OnMapChanged += OnMapChanged;
2025-03-10 20:36:11 +08:00
_cosmeticsCustomize.OnValueChanged += OnValueChanged;
}
private void OnValueChanged(CosmeticsCustomizeComponent arg1, CosmeticsCustomizeComponent arg2)
{
var cosmetics = _entitiesService.QueryComponents<ScriptableCosmetics>().ToArray()
.ToDictionary(x => x.ScriptableId, x => x);
foreach (var id in arg2.ComponentIds)
{
if (cosmetics.TryGetValue(id,out var cosmetic))
{
if (cosmetic.CosmeticsClass is CosmeticsModel)
{
_avatarImage.style.backgroundImage = new(cosmetic.Icon);
_playerName.text = cosmetic.Name;
}
}
}
2025-02-28 21:17:03 +08:00
}
private void OnMapChanged(Guid arg1, string arg2)
{
if (string.IsNullOrEmpty(arg2))
{
UXService.Entry(this);
}
2024-12-28 23:19:55 +08:00
}
2025-02-28 21:17:03 +08:00
2024-12-28 23:19:55 +08:00
private void Initiated()
2024-11-03 16:42:23 +08:00
{
UXUtils.Inject(this);
2024-12-28 23:19:55 +08:00
2025-03-05 22:28:38 +08:00
_playButton.clicked += UXService.Entry<IUXMapSelector>;
2024-11-03 16:42:23 +08:00
}
2025-02-28 21:17:03 +08:00
public override void Dispose()
{
base.Dispose();
_gameMapService.OnMapChanged -= OnMapChanged;
}
2024-11-03 16:42:23 +08:00
}
}