2023-03-29 02:13:49 +03:00
|
|
|
using System.Collections;
|
2022-12-07 12:13:57 +02:00
|
|
|
using System.Collections.Generic;
|
2022-12-03 20:40:43 +02:00
|
|
|
using TMPro;
|
2022-12-07 12:13:57 +02:00
|
|
|
using Unity.Services.Lobbies.Models;
|
2022-12-03 20:40:43 +02:00
|
|
|
using UnityEngine;
|
|
|
|
|
public class OnlineClientMenu : BaseMenu
|
|
|
|
|
{
|
|
|
|
|
[SerializeField] private NetworkManagerLobby _networkManager = default;
|
2022-12-04 19:19:07 +02:00
|
|
|
[SerializeField] private OnlineHostMenu _onlineHostMenu = default;
|
2023-03-29 02:13:49 +03:00
|
|
|
[SerializeField] private OnlineLobbiesSearchMenu _onlineLobbiesSearchMenu = default;
|
2023-10-03 13:38:22 +03:00
|
|
|
[SerializeField] private BaseMenu _roomIdMenu = default;
|
2022-12-07 12:13:57 +02:00
|
|
|
[SerializeField] private OnlineSetupMenu _onlineSetupMenu = default;
|
2023-10-03 13:38:22 +03:00
|
|
|
[SerializeField] private TextMeshProUGUI _lobbyIdInputField = default;
|
2023-03-29 02:13:49 +03:00
|
|
|
[SerializeField] private TMP_InputField _lobbyIdChangeInputField = default;
|
|
|
|
|
[SerializeField] private InputManager _inputManager = default;
|
|
|
|
|
[SerializeField] private PromptsInput _searchPrompts = default;
|
|
|
|
|
[SerializeField] private PromptsInput _idPrompts = default;
|
2022-12-07 12:13:57 +02:00
|
|
|
[SerializeField] private GameObject _joiningLobbyGroup = default;
|
|
|
|
|
[SerializeField] private GameObject _lobbyJoinGroup = default;
|
2022-12-03 20:40:43 +02:00
|
|
|
|
|
|
|
|
|
2023-03-29 02:13:49 +03:00
|
|
|
public async void SearchLobbies()
|
2022-12-03 20:40:43 +02:00
|
|
|
{
|
2022-12-07 12:13:57 +02:00
|
|
|
_joiningLobbyGroup.SetActive(true);
|
|
|
|
|
_lobbyJoinGroup.SetActive(false);
|
|
|
|
|
string lobbyId = _lobbyIdInputField.text;
|
2023-03-29 02:13:49 +03:00
|
|
|
if (lobbyId != "")
|
2023-02-02 02:10:38 +02:00
|
|
|
{
|
2023-03-29 02:13:49 +03:00
|
|
|
Lobby lobby = await _networkManager.JoinLobbyByCode(_onlineSetupMenu.DemonData, lobbyId);
|
|
|
|
|
if (lobby == null)
|
|
|
|
|
{
|
|
|
|
|
_joiningLobbyGroup.SetActive(false);
|
|
|
|
|
_lobbyJoinGroup.SetActive(true);
|
|
|
|
|
Hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
List<DemonData> demonDatas = new List<DemonData>();
|
|
|
|
|
foreach (var player in lobby.Players)
|
|
|
|
|
{
|
|
|
|
|
demonDatas.Add(new DemonData()
|
|
|
|
|
{
|
|
|
|
|
demonName = player.Data["DemonName"].Value,
|
|
|
|
|
character = int.Parse(player.Data["Character"].Value),
|
|
|
|
|
assist = int.Parse(player.Data["Assist"].Value),
|
|
|
|
|
color = int.Parse(player.Data["Color"].Value)
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-02-02 02:10:38 +02:00
|
|
|
_joiningLobbyGroup.SetActive(false);
|
|
|
|
|
_lobbyJoinGroup.SetActive(true);
|
2023-03-29 02:13:49 +03:00
|
|
|
_onlineHostMenu.OpenAsClient(demonDatas.ToArray(), lobbyId);
|
|
|
|
|
OpenMenuHideCurrent(_onlineHostMenu);
|
2023-02-02 02:10:38 +02:00
|
|
|
}
|
2023-03-29 02:13:49 +03:00
|
|
|
else
|
2022-12-07 12:13:57 +02:00
|
|
|
{
|
2023-03-29 02:13:49 +03:00
|
|
|
Lobby[] lobbies = await _networkManager.SearchLobbies();
|
|
|
|
|
if (lobbies == null)
|
2022-12-07 12:13:57 +02:00
|
|
|
{
|
2023-03-29 02:13:49 +03:00
|
|
|
_lobbyIdInputField.text = "";
|
|
|
|
|
_joiningLobbyGroup.SetActive(false);
|
|
|
|
|
_lobbyJoinGroup.SetActive(true);
|
|
|
|
|
Hide();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_onlineLobbiesSearchMenu.SetLobbies(lobbies);
|
|
|
|
|
OpenMenuHideCurrent(_onlineLobbiesSearchMenu);
|
|
|
|
|
_joiningLobbyGroup.SetActive(false);
|
|
|
|
|
_lobbyJoinGroup.SetActive(true);
|
2022-12-07 12:13:57 +02:00
|
|
|
}
|
2022-12-03 20:40:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleClientConnected()
|
|
|
|
|
{
|
2022-12-04 19:19:07 +02:00
|
|
|
_onlineHostMenu.Show();
|
2022-12-03 21:02:38 +02:00
|
|
|
gameObject.SetActive(false);
|
2022-12-03 20:40:43 +02:00
|
|
|
}
|
2023-03-29 02:13:49 +03:00
|
|
|
public void OpenChangeId()
|
|
|
|
|
{
|
|
|
|
|
_lobbyIdChangeInputField.text = _lobbyIdInputField.text;
|
2023-10-03 13:38:22 +03:00
|
|
|
_roomIdMenu.Show();
|
2023-03-29 02:13:49 +03:00
|
|
|
_lobbyIdChangeInputField.Select();
|
2023-08-29 17:42:32 +03:00
|
|
|
_inputManager.SetPrompts(_idPrompts);
|
2023-03-29 02:13:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void CloseChangeId()
|
|
|
|
|
{
|
|
|
|
|
_lobbyIdInputField.text = _lobbyIdChangeInputField.text;
|
2023-10-03 13:38:22 +03:00
|
|
|
_roomIdMenu.Hide();
|
2023-08-29 17:42:32 +03:00
|
|
|
_inputManager.SetPrompts(_searchPrompts);
|
2023-03-29 02:13:49 +03:00
|
|
|
StartCoroutine(SelectOption());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator SelectOption()
|
|
|
|
|
{
|
|
|
|
|
yield return null;
|
|
|
|
|
if (_startingOption != null)
|
|
|
|
|
{
|
|
|
|
|
_startingOption.Select();
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-12-03 20:40:43 +02:00
|
|
|
}
|