using System; using System.Collections; using System.Linq; using FMODUnity; using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList; using NitroxClient.Unity.Helper; using NitroxModel.DataStructures.Util; using TMPro; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace NitroxClient.MonoBehaviours.Gui.MainMenu.ServerJoin; public class MainMenuEnterPasswordPanel : MonoBehaviour, uGUI_INavigableIconGrid, uGUI_IButtonReceiver { public const string NAME = "MultiplayerEnterPassword"; public static MainMenuEnterPasswordPanel Instance { get; private set; } private TMP_InputField passwordInput; private mGUI_Change_Legend_On_Select legendChange; private GameObject selectedItem; private GameObject[] selectableItems; private static string lastEnteredPassword; public static Optional LastEnteredPassword => lastEnteredPassword != null ? Optional.Of(lastEnteredPassword) : Optional.Empty; public static void ResetLastEnteredPassword() => lastEnteredPassword = null; public void Setup(GameObject savedGamesRef) { Instance = this; GameObject multiplayerButtonRef = savedGamesRef.RequireGameObject("Scroll View/Viewport/SavedGameAreaContent/NewGame"); GameObject generalTextRef = multiplayerButtonRef.GetComponentInChildren().gameObject; GameObject inputFieldRef = GameObject.Find("/Menu canvas/Panel/MainMenu/RightSide/Home/EmailBox/InputField"); GameObject passwordInputGameObject = Instantiate(inputFieldRef, transform, false); passwordInputGameObject.transform.localPosition = new Vector3(-160, 300, 0); passwordInputGameObject.GetComponent().sizeDelta = new Vector2(300, 40); passwordInput = passwordInputGameObject.GetComponent(); passwordInput.characterValidation = TMP_InputField.CharacterValidation.None; passwordInput.onSubmit = new TMP_InputField.SubmitEvent(); passwordInput.onSubmit.AddListener(_ => OnConfirmButtonClicked()); passwordInput.placeholder.GetComponent().translationKey = Language.main.Get("Nitrox_JoinServerPlaceholder"); GameObject passwordInputDesc = Instantiate(generalTextRef, passwordInputGameObject.transform, false); passwordInputDesc.transform.localPosition = new Vector3(-200, 0, 0); passwordInputDesc.GetComponent().text = Language.main.Get("Nitrox_JoinServerPassword"); GameObject confirmButton = Instantiate(multiplayerButtonRef, transform, false); confirmButton.transform.localPosition = new Vector3(-200, 90, 0); confirmButton.transform.GetChild(0).GetComponent().sizeDelta = new Vector2(200, 40); confirmButton.GetComponentInChildren().text = Language.main.Get("Nitrox_Confirm"); Button confirmButtonButton = confirmButton.RequireTransform("NewGameButton").GetComponent