Skip to content

Commit e546d6f

Browse files
UI improvements for player name input (#2274)
Co-authored-by: Measurity <[email protected]>
1 parent 42820de commit e546d6f

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

NitroxClient/MonoBehaviours/Gui/MainMenu/ServerJoin/JoinServerBackend.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList;
1010
using NitroxModel.Core;
1111
using NitroxModel.DataStructures.Util;
12+
using NitroxModel.Helper;
1213
using NitroxModel.MultiplayerSession;
1314
using NitroxModel_Subnautica.DataStructures;
14-
using NitroxModel.Helper;
1515
using UnityEngine;
1616

1717
namespace NitroxClient.MonoBehaviours.Gui.MainMenu.ServerJoin;
@@ -56,12 +56,14 @@ private static void SessionConnectionStateChangedHandler(IMultiplayerSessionConn
5656
Log.InGame(Language.main.Get("Nitrox_WaitingPassword"));
5757
MainMenuEnterPasswordPanel.ResetLastEnteredPassword();
5858
MainMenuRightSide.main.OpenGroup(MainMenuEnterPasswordPanel.NAME);
59+
MainMenuEnterPasswordPanel.Instance.FocusPasswordField();
5960
break;
6061
}
6162

6263
Log.Info("Waiting for user input");
6364
Log.InGame(Language.main.Get("Nitrox_WaitingUserInput"));
6465
MainMenuRightSide.main.OpenGroup(MainMenuJoinServerPanel.NAME);
66+
MainMenuJoinServerPanel.Instance.FocusNameInputField();
6567
break;
6668

6769
case MultiplayerSessionConnectionStage.SESSION_RESERVED:

NitroxClient/MonoBehaviours/Gui/MainMenu/ServerJoin/MainMenuEnterPasswordPanel.cs

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections;
23
using System.Linq;
34
using FMODUnity;
45
using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList;
@@ -15,6 +16,8 @@ public class MainMenuEnterPasswordPanel : MonoBehaviour, uGUI_INavigableIconGrid
1516
{
1617
public const string NAME = "MultiplayerEnterPassword";
1718

19+
public static MainMenuEnterPasswordPanel Instance { get; private set; }
20+
1821
private TMP_InputField passwordInput;
1922
private mGUI_Change_Legend_On_Select legendChange;
2023

@@ -27,6 +30,8 @@ public class MainMenuEnterPasswordPanel : MonoBehaviour, uGUI_INavigableIconGrid
2730

2831
public void Setup(GameObject savedGamesRef)
2932
{
33+
Instance = this;
34+
3035
GameObject multiplayerButtonRef = savedGamesRef.RequireGameObject("Scroll View/Viewport/SavedGameAreaContent/NewGame");
3136
GameObject generalTextRef = multiplayerButtonRef.GetComponentInChildren<TextMeshProUGUI>().gameObject;
3237
GameObject inputFieldRef = GameObject.Find("/Menu canvas/Panel/MainMenu/RightSide/Home/EmailBox/InputField");
@@ -37,7 +42,7 @@ public void Setup(GameObject savedGamesRef)
3742
passwordInput = passwordInputGameObject.GetComponent<TMP_InputField>();
3843
passwordInput.characterValidation = TMP_InputField.CharacterValidation.None;
3944
passwordInput.onSubmit = new TMP_InputField.SubmitEvent();
40-
passwordInput.onSubmit.AddListener(_ => { SelectItemInDirection(0, 1); });
45+
passwordInput.onSubmit.AddListener(_ => OnConfirmButtonClicked());
4146
passwordInput.placeholder.GetComponent<TranslationLiveUpdate>().translationKey = Language.main.Get("Nitrox_JoinServerPlaceholder");
4247
GameObject passwordInputDesc = Instantiate(generalTextRef, passwordInputGameObject.transform, false);
4348
passwordInputDesc.transform.localPosition = new Vector3(-200, 0, 0);
@@ -66,10 +71,24 @@ public void Setup(GameObject savedGamesRef)
6671
legendChange.legendButtonConfiguration = confirmButtonButton.GetComponent<mGUI_Change_Legend_On_Select>().legendButtonConfiguration.Take(1).ToArray();
6772
}
6873

74+
public void FocusPasswordField()
75+
{
76+
StartCoroutine(Coroutine());
77+
78+
IEnumerator Coroutine()
79+
{
80+
passwordInput.Select();
81+
EventSystem.current.SetSelectedGameObject(passwordInput.gameObject);
82+
yield return null;
83+
passwordInput.MoveToEndOfLine(false, true);
84+
}
85+
}
86+
6987
private void OnConfirmButtonClicked()
7088
{
7189
lastEnteredPassword = passwordInput.text;
7290
MainMenuRightSide.main.OpenGroup(MainMenuJoinServerPanel.NAME);
91+
MainMenuJoinServerPanel.Instance.FocusNameInputField();
7392
}
7493

7594
private static void OnCancelClick()

NitroxClient/MonoBehaviours/Gui/MainMenu/ServerJoin/MainMenuJoinServerPanel.cs

+14
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ private IEnumerator AsyncSetup(GameObject savedGamesRef)
6565
playerNameInputField.textComponent.fontSizeMax = 21;
6666
playerNameInputField.textComponent.GetComponent<RectTransform>().sizeDelta = new Vector2(-20, 42);
6767
playerNameInputField.characterLimit = 25; // See this.OnJoinClick()
68+
playerNameInputField.onFocusSelectAll = false;
69+
playerNameInputField.onSubmit.AddListener(_ => OnJoinClick());
70+
playerNameInputField.onSubmit.AddListener(_ => DeselectAllItems());
6871
playerNameInputField.ActivateInputField();
6972

7073
//Prepares player color picker
@@ -133,6 +136,17 @@ public void UpdatePlayerPanelValues(string playerName, Vector3 hsb)
133136
colorPicker.SetHSB(hsb);
134137
}
135138

139+
public void FocusNameInputField()
140+
{
141+
StartCoroutine(Coroutine());
142+
IEnumerator Coroutine()
143+
{
144+
SelectFirstItem();
145+
yield return new WaitForEndOfFrame();
146+
playerNameInputField.MoveToEndOfLine(false, true);
147+
}
148+
}
149+
136150
public bool OnButtonDown(GameInput.Button button)
137151
{
138152
if (button != GameInput.Button.UISubmit || !selectedItem)

0 commit comments

Comments
 (0)