using System.Collections; using System.Linq; using System.Text.RegularExpressions; using FMODUnity; using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList; using NitroxClient.Unity.Helper; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.UI; using UWE; namespace NitroxClient.MonoBehaviours.Gui.MainMenu.ServerJoin; public class MainMenuJoinServerPanel : MonoBehaviour, uGUI_INavigableIconGrid, uGUI_IButtonReceiver, uGUI_IScrollReceiver, uGUI_IAdjustReceiver { public const string NAME = "MultiplayerJoinServer"; public static MainMenuJoinServerPanel Instance { get; private set; } private GameObject playerSettingsPanel; private TextMeshProUGUI header; private uGUI_ColorPicker colorPicker; private MainMenuColorPickerPreview colorPickerPreview; private Slider saturationSlider; private uGUI_InputField playerNameInputField; private GameObject selectedItem; private GameObject[] selectableItems; public void Setup(GameObject savedGamesRef) { Instance = this; Destroy(transform.RequireGameObject("Scroll View")); Destroy(GetComponentInChildren()); header = GetComponentInChildren(); CoroutineHost.StartCoroutine(AsyncSetup(savedGamesRef)); // As JoinServer waits for AsyncSetup to be completed we can't use normal Unity IEnumerator Start() } private IEnumerator AsyncSetup(GameObject savedGamesRef) { AsyncOperationHandle request = AddressablesUtility.LoadAsync("Assets/Prefabs/Base/GeneratorPieces/BaseMoonpoolUpgradeConsole.prefab"); yield return request; GameObject colorPickerPanelPrototype = request.Result.RequireGameObject("EditScreen/Active"); RectTransform parent = GetComponent(); GameObject newGameButtonRef = savedGamesRef.RequireGameObject("Scroll View/Viewport/SavedGameAreaContent/NewGame/NewGameButton"); LegendButtonData[] defaultLegend = newGameButtonRef.GetComponent().legendButtonConfiguration.Take(1).ToArray(); //Create a clone of the RocketBase color picker panel. playerSettingsPanel = Instantiate(colorPickerPanelPrototype, parent); //Prepares name input field GameObject inputField = playerSettingsPanel.RequireGameObject("InputField"); inputField.transform.SetParent(parent); inputField.transform.localPosition = new Vector3(-200, 310, 0); inputField.transform.localScale = Vector3.one; inputField.AddComponent().legendButtonConfiguration = defaultLegend; playerNameInputField = inputField.GetComponent(); ((TextMeshProUGUI)playerNameInputField.placeholder).text = Language.main.Get("Nitrox_EnterName"); playerNameInputField.textComponent.fontSizeMin = 17; playerNameInputField.textComponent.fontSizeMax = 21; playerNameInputField.textComponent.GetComponent().sizeDelta = new Vector2(-20, 42); playerNameInputField.characterLimit = 25; // See this.OnJoinClick() playerNameInputField.onFocusSelectAll = false; playerNameInputField.onSubmit.AddListener(_ => OnJoinClick()); playerNameInputField.onSubmit.AddListener(_ => DeselectAllItems()); playerNameInputField.ActivateInputField(); //Prepares player color picker GameObject colorPickerObject = playerSettingsPanel.RequireGameObject("ColorPicker"); colorPickerObject.transform.SetParent(parent); colorPickerObject.transform.localPosition = new Vector3(-268, 175, 0); colorPickerObject.transform.localScale = new Vector3(1.1f, 0.75f, 1); colorPicker = colorPickerObject.GetComponentInChildren(); colorPicker.pointer.localScale = new Vector3(1f, 1.46f, 1); saturationSlider = colorPicker.saturationSlider; saturationSlider.transform.localPosition = new Vector3(197, 0, 0); colorPickerPreview = colorPicker.gameObject.AddComponent(); colorPickerPreview.Init(colorPicker); GameObject buttonLeft = Instantiate(newGameButtonRef, parent); buttonLeft.GetComponent().sizeDelta = new Vector2(160, 45); buttonLeft.GetComponent().legendButtonConfiguration = defaultLegend; GameObject buttonRight = Instantiate(buttonLeft, parent); //Prepares cancel button buttonLeft.transform.SetParent(parent); buttonLeft.transform.localPosition = new Vector3(-285, 40, 0); buttonLeft.GetComponentInChildren().text = Language.main.Get("Nitrox_Cancel"); Button cancelButton = buttonLeft.GetComponent