86 lines
2.7 KiB
C#
86 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading;
|
|
using BITKit;
|
|
using BITKit.Entities;
|
|
using BITKit.UX;
|
|
using Cysharp.Threading.Tasks;
|
|
using Net.Project.B.Cosmetics;
|
|
using Net.Project.B.UX;
|
|
using Project.B.Entities;
|
|
using Project.B.Map;
|
|
using UnityEngine;
|
|
using UnityEngine.UIElements;
|
|
using YooAsset;
|
|
|
|
namespace Net.Like.Xue.Tokyo.UX
|
|
{
|
|
public class UXMenu : UIToolKitPanel,IUXLobby
|
|
{
|
|
private readonly IEntitiesService _entitiesService;
|
|
private readonly IGameMapService _gameMapService;
|
|
private readonly IWrapper<CosmeticsCustomizeComponent> _cosmeticsCustomize;
|
|
protected override string DocumentPath => "ux_menu";
|
|
public override bool AllowInput => false;
|
|
public override bool AllowCursor => true;
|
|
[UXBindPath("play-button")]
|
|
private Button _playButton;
|
|
[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)
|
|
{
|
|
_gameMapService = gameMapService;
|
|
_cosmeticsCustomize = cosmeticsCustomize;
|
|
_entitiesService = entitiesService;
|
|
OnInitiated += Initiated;
|
|
|
|
_gameMapService.OnMapChanged += OnMapChanged;
|
|
|
|
_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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnMapChanged(Guid arg1, string arg2)
|
|
{
|
|
if (string.IsNullOrEmpty(arg2))
|
|
{
|
|
UXService.Entry(this);
|
|
}
|
|
}
|
|
|
|
private void Initiated()
|
|
{
|
|
UXUtils.Inject(this);
|
|
|
|
_playButton.clicked += UXService.Entry<IUXMapSelector>;
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
base.Dispose();
|
|
|
|
_gameMapService.OnMapChanged -= OnMapChanged;
|
|
}
|
|
}
|
|
}
|