121 lines
3.9 KiB
C#
121 lines
3.9 KiB
C#
![]() |
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
using BITKit;
|
||
|
using BITKit.Mod;
|
||
|
using BITKit.UX;
|
||
|
using Cysharp.Threading.Tasks;
|
||
|
using Net.Project.B.UX;
|
||
|
using Project.B.Map;
|
||
|
using Project.B.Player;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.InputSystem;
|
||
|
using UnityEngine.UIElements;
|
||
|
|
||
|
namespace Project.B.UX
|
||
|
{
|
||
|
public sealed class UXLobby : UIToolKitPanel,IUXLobby
|
||
|
{
|
||
|
protected override string DocumentPath => "ux_lobby";
|
||
|
public override bool AllowCursor => true;
|
||
|
private readonly IGameMapService _gameMapService;
|
||
|
private readonly IUXKeyMap<InputAction> _uxKeyMap;
|
||
|
|
||
|
[UXBindPath("mod-button")] private Button _modButton;
|
||
|
[UXBindPath("return-button")] private Button _returnButton;
|
||
|
[UXBindPath("host-button")] private Button _hostButton;
|
||
|
[UXBindPath("connect-button")] private Button _connectButton;
|
||
|
[UXBindPath("exit-button")] private Button _exitButton;
|
||
|
[UXBindPath("background-blur")] private VisualElement _backgroundBlur;
|
||
|
[UXBindPath("snapshots-button")] private Button _snapshotsButton;
|
||
|
|
||
|
|
||
|
public UXLobby(IUXService uxService, IUXKeyMap<InputAction> uxKeyMap,
|
||
|
IGameMapService gameMapService) : base(uxService)
|
||
|
{
|
||
|
_uxKeyMap = uxKeyMap;
|
||
|
_gameMapService = gameMapService;
|
||
|
|
||
|
|
||
|
OnInitiatedAsync += InitiatedAsync;
|
||
|
}
|
||
|
|
||
|
private void OnMapChanged(Guid arg1, string arg2)
|
||
|
{
|
||
|
if (string.IsNullOrEmpty(arg2))
|
||
|
{
|
||
|
UXService.Entry(this);
|
||
|
_returnButton.SetActive(false);
|
||
|
_hostButton.SetActive(true);
|
||
|
_connectButton.SetActive(true);
|
||
|
_backgroundBlur.SetActive(false);
|
||
|
_exitButton.text = "退出";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_returnButton.SetActive(true);
|
||
|
_hostButton.SetActive(false);
|
||
|
_connectButton.SetActive(false);
|
||
|
_backgroundBlur.SetActive(true);
|
||
|
_exitButton.text = "断开链接";
|
||
|
}
|
||
|
}
|
||
|
private UniTask InitiatedAsync()
|
||
|
{
|
||
|
_returnButton.clicked += UXService.Entry<IUXHud>;
|
||
|
_hostButton.clicked += () => UXService.Entry<IUXMapSelector>();
|
||
|
_modButton.clicked += UXService.Entry<UXModService>;
|
||
|
_snapshotsButton.clicked += UXService.Entry<IUXSnapshot>;
|
||
|
|
||
|
OnMapChanged(default, null);
|
||
|
|
||
|
_gameMapService.OnMapChanged += OnMapChanged;
|
||
|
|
||
|
_exitButton.clicked += () =>
|
||
|
{
|
||
|
switch (_gameMapService.TaskStatus)
|
||
|
{
|
||
|
case TaskStatus.WaitingForActivation:
|
||
|
case TaskStatus.Created:
|
||
|
BITAppForUnity.Exit();
|
||
|
return;
|
||
|
case TaskStatus.RanToCompletion:
|
||
|
_gameMapService.StopMapAsync().Forget();
|
||
|
return;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
return UniTask.CompletedTask;
|
||
|
}
|
||
|
|
||
|
|
||
|
protected override void OnPanelEntry()
|
||
|
{
|
||
|
base.OnPanelEntry();
|
||
|
InputActionGroup.RegisterCallback(_uxKeyMap.InventoryKey, OnReturn);
|
||
|
InputActionGroup.RegisterCallback(_uxKeyMap.CancelKey,
|
||
|
OnReturn);
|
||
|
}
|
||
|
|
||
|
private void OnReturn(InputAction.CallbackContext obj)
|
||
|
{
|
||
|
if (_gameMapService.TaskStatus is not TaskStatus.RanToCompletion) return;
|
||
|
|
||
|
if (string.IsNullOrEmpty(_gameMapService.CurrentMap))return;
|
||
|
|
||
|
UXService.Entry<IUXHud>();
|
||
|
}
|
||
|
|
||
|
protected override void OnPanelExit()
|
||
|
{
|
||
|
base.OnPanelExit();
|
||
|
InputActionGroup.UnRegisterCallback(_uxKeyMap.InventoryKey, OnReturn);
|
||
|
InputActionGroup.UnRegisterCallback(_uxKeyMap.CancelKey,
|
||
|
OnReturn);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|