118 lines
3.8 KiB
C#
118 lines
3.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Security.Policy;
|
|
using BITFALL.Game;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using BITKit;
|
|
using BITKit.Game;
|
|
using BITKit.IO;
|
|
using BITKit.Mod;
|
|
using BITKit.SceneManagement;
|
|
using BITKit.UX;
|
|
using INetClient = BITKit.INetClient;
|
|
using Cysharp.Threading.Tasks;
|
|
using UnityEngine.InputSystem.Interactions;
|
|
using UnityEngine.UIElements;
|
|
|
|
namespace BITFALL.UX
|
|
{
|
|
public class UXMenu : UIToolKitPanel
|
|
{
|
|
[Header(Constant.Header.Services)]
|
|
[SerializeReference, SubclassSelector] private IReference[] mapTags;
|
|
|
|
[Header(Constant.Header.Providers)]
|
|
[SerializeReference, SubclassSelector] private ISceneService SceneService;
|
|
|
|
[Header(Constant.Header.Components)]
|
|
[SerializeField] private UXButton playButton;
|
|
[SerializeField] private UXButton stopButton;
|
|
[SerializeField] private UXButton exitButton;
|
|
[SerializeField] private UXDropdown mapDropdown;
|
|
|
|
[Header(Constant.Header.Providers)]
|
|
[SerializeReference,SubclassSelector] private IGameService gameService;
|
|
|
|
[Header(Constant.Header.Input)]
|
|
[SerializeField] private InputActionReference returnAction;
|
|
[SerializeField] private InputActionReference inventoryAction;
|
|
|
|
|
|
[UXBindPath("newHost-container")]
|
|
private VisualElement newHostContainer;
|
|
[UXBindPath("inGame-container")]
|
|
private VisualElement inGameContainer;
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
SceneService.OnLoadScene +=(_)=> OnConnected();
|
|
SceneService.OnUnloadScene +=(_)=>
|
|
{
|
|
Entry();
|
|
OnDisconnected();
|
|
};
|
|
OnDisconnected();
|
|
|
|
ModService.OnModLoaded += UpdateMapList;
|
|
ModService.OnModUnLoaded += UpdateMapList;
|
|
|
|
UpdateMapList(null);
|
|
}
|
|
|
|
private async void UpdateMapList(object _)
|
|
{
|
|
await UniTask.Delay(300);
|
|
if (destroyCancellationToken.IsCancellationRequested) return;
|
|
var tags = mapTags.Select(x => x.Value).ToArray();
|
|
mapDropdown.visualElement.choices = SceneService.GetScenes(tags).ToList();
|
|
mapDropdown.visualElement.RegisterValueChangedCallback(x =>
|
|
{
|
|
gameService.ExpectMap = x.newValue;
|
|
});
|
|
mapDropdown.visualElement.SetValueWithoutNotify(gameService.ExpectMap);
|
|
//BIT4Log.Log<UXMenu>($"UpdateMapList:{string.Join("\n",mapDropdown.visualElement.choices)}");
|
|
}
|
|
|
|
protected override void OnPanelEntry()
|
|
{
|
|
base.OnPanelEntry();
|
|
inputActionGroup.RegisterCallback(returnAction, OnReturn);
|
|
inputActionGroup.RegisterCallback(inventoryAction, OnReturn);
|
|
}
|
|
|
|
protected override void OnPanelExit()
|
|
{
|
|
base.OnPanelExit();
|
|
inputActionGroup.UnRegisterCallback(returnAction, OnReturn);
|
|
inputActionGroup.UnRegisterCallback(inventoryAction, OnReturn);
|
|
}
|
|
|
|
|
|
private void OnConnected()
|
|
{
|
|
newHostContainer.SetActive(false);
|
|
stopButton.SetActive(true);
|
|
exitButton.SetActive(false);
|
|
inGameContainer.SetActive(true);
|
|
}
|
|
private void OnDisconnected()
|
|
{
|
|
newHostContainer.SetActive(true);
|
|
stopButton.SetActive(false);
|
|
exitButton.SetActive(true);
|
|
inGameContainer.SetActive(false);
|
|
}
|
|
private static void OnReturn(InputAction.CallbackContext context)
|
|
{
|
|
if (context is {interaction:PressInteraction,performed:true})
|
|
{
|
|
UXService.Entry<UXHud>();
|
|
}
|
|
}
|
|
}
|
|
} |