diff --git a/NitroxClient/Debuggers/Drawer/NitroxGUILayout.cs b/NitroxClient/Debuggers/Drawer/NitroxGUILayout.cs
index f62e47700c..c5589155c9 100644
--- a/NitroxClient/Debuggers/Drawer/NitroxGUILayout.cs
+++ b/NitroxClient/Debuggers/Drawer/NitroxGUILayout.cs
@@ -154,7 +154,7 @@ public static float SliderField(float value, float minValue, float maxValue, flo
/// The newly selected enum value.
public static Enum EnumPopup(Enum selected, float buttonWidth = VALUE_WIDTH)
{
- return EnumPopupInternal(selected, buttonWidth);
+ return EnumPopupInternal(selected, buttonWidth);
}
public static T EnumPopup(T selected, float buttonWidth = VALUE_WIDTH) where T : Enum
@@ -183,7 +183,7 @@ bool IsFlagSet(T value, T flag)
return (lValue & lFlag) != 0;
};
- T SetFlags(T value, T flags, bool toggle)
+ object SetFlags(Type type, object value, object flags, bool toggle)
{
long lValue = Convert.ToInt64(value);
long lFlag = Convert.ToInt64(flags);
@@ -201,7 +201,7 @@ T SetFlags(T value, T flags, bool toggle)
lValue = 0;
}
- return (T)Enum.ToObject(typeof(T), lValue);
+ return Enum.ToObject(type, lValue);
};
Enum[] enumValues = Enum.GetValues(enumType).Cast().ToArray();
@@ -215,7 +215,7 @@ T SetFlags(T value, T flags, bool toggle)
bool isFlagSet = IsFlagSet(selected, enumValue);
- selected = SetFlags(selected, enumValue, GUILayout.Toggle(isFlagSet, enumName, "Button", GUILayout.Width(buttonWidth)));
+ selected = (Enum) SetFlags(enumType, selected, enumValue, GUILayout.Toggle(isFlagSet, enumName, "Button", GUILayout.Width(buttonWidth)));
}
}
diff --git a/NitroxClient/Debuggers/Drawer/UnityUI/SelectableDrawer.cs b/NitroxClient/Debuggers/Drawer/UnityUI/SelectableDrawer.cs
index 57e4b19267..08ba4e01e5 100644
--- a/NitroxClient/Debuggers/Drawer/UnityUI/SelectableDrawer.cs
+++ b/NitroxClient/Debuggers/Drawer/UnityUI/SelectableDrawer.cs
@@ -148,28 +148,56 @@ private void DrawTransitionSpriteSwap(Selectable selectable)
{
GUILayout.Label("Highlighted Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
- ImageDrawer.DrawTexture(selectable.spriteState.highlightedSprite.texture);
+ if (selectable.spriteState.highlightedSprite)
+ {
+ ImageDrawer.DrawTexture(selectable.spriteState.highlightedSprite.texture);
+ }
+ else
+ {
+ GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
+ }
}
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Pressed Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
- ImageDrawer.DrawTexture(selectable.spriteState.pressedSprite.texture);
+ if (selectable.spriteState.pressedSprite)
+ {
+ ImageDrawer.DrawTexture(selectable.spriteState.pressedSprite.texture);
+ }
+ else
+ {
+ GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
+ }
}
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Selected Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
- ImageDrawer.DrawTexture(selectable.spriteState.selectedSprite.texture);
+ if (selectable.spriteState.selectedSprite)
+ {
+ ImageDrawer.DrawTexture(selectable.spriteState.selectedSprite.texture);
+ }
+ else
+ {
+ GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
+ }
}
using (new GUILayout.HorizontalScope())
{
GUILayout.Label("Disabled Sprite", NitroxGUILayout.DrawerLabel, GUILayout.Width(NitroxGUILayout.DEFAULT_LABEL_WIDTH));
NitroxGUILayout.Separator();
- ImageDrawer.DrawTexture(selectable.spriteState.disabledSprite.texture);
+ if (selectable.spriteState.disabledSprite)
+ {
+ ImageDrawer.DrawTexture(selectable.spriteState.disabledSprite.texture);
+ }
+ else
+ {
+ GUILayout.Box("Field is null", GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
+ }
}
}
diff --git a/NitroxClient/Debuggers/SceneDebugger.cs b/NitroxClient/Debuggers/SceneDebugger.cs
index 2261ac4a3c..59b03ba090 100644
--- a/NitroxClient/Debuggers/SceneDebugger.cs
+++ b/NitroxClient/Debuggers/SceneDebugger.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
@@ -304,6 +305,16 @@ private void DrawFields(UnityEngine.Object target)
JumpToComponent(component);
}
}
+ else if(fieldValue != null && (field.FieldType.IsArray || typeof(IList).IsAssignableFrom(field.FieldType)))
+ {
+ IList list = (IList)field.GetValue(target);
+ GUILayout.Box($"Length: {list.Count}" , GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
+ }
+ else if(fieldValue != null && (typeof(IDictionary).IsAssignableFrom(field.FieldType)))
+ {
+ IDictionary dict = (IDictionary)field.GetValue(target);
+ GUILayout.Box($"Length: {dict.Count}" , GUILayout.Width(NitroxGUILayout.VALUE_WIDTH));
+ }
else if (drawerManager.TryDrawEditor(fieldValue, out object editedValue))
{
field.SetValue(target, editedValue);
diff --git a/NitroxClient/GameLogic/HUD/PdaTabs/uGUI_PlayerPingEntry.cs b/NitroxClient/GameLogic/HUD/PdaTabs/uGUI_PlayerPingEntry.cs
index 8fe370b3d8..0cff601e28 100644
--- a/NitroxClient/GameLogic/HUD/PdaTabs/uGUI_PlayerPingEntry.cs
+++ b/NitroxClient/GameLogic/HUD/PdaTabs/uGUI_PlayerPingEntry.cs
@@ -186,10 +186,10 @@ public void UpdateButtonsPosition()
private void ClearButtonListeners()
{
- GetToggle(MuteObject).onValueChanged.RemoveAllListeners();
- GetToggle(KickObject).onValueChanged.RemoveAllListeners();
- GetToggle(TeleportToObject).onValueChanged.RemoveAllListeners();
- GetToggle(TeleportToMeObject).onValueChanged.RemoveAllListeners();
+ GetToggle(MuteObject).onValueChanged = new Toggle.ToggleEvent();
+ GetToggle(KickObject).onValueChanged = new Toggle.ToggleEvent();
+ GetToggle(TeleportToObject).onValueChanged = new Toggle.ToggleEvent();
+ GetToggle(TeleportToMeObject).onValueChanged = new Toggle.ToggleEvent();
}
private IEnumerator AssignSprites()
diff --git a/NitroxClient/GameLogic/Settings/NitroxSettingsManager.cs b/NitroxClient/GameLogic/Settings/NitroxSettingsManager.cs
index a90acee3e2..8c357405d0 100644
--- a/NitroxClient/GameLogic/Settings/NitroxSettingsManager.cs
+++ b/NitroxClient/GameLogic/Settings/NitroxSettingsManager.cs
@@ -1,7 +1,7 @@
using System;
using System.Collections.Generic;
using NitroxClient.GameLogic.Bases;
-using NitroxClient.MonoBehaviours.Gui.MainMenu;
+using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList;
using UnityEngine.Events;
namespace NitroxClient.GameLogic.Settings;
@@ -21,9 +21,9 @@ public NitroxSettingsManager()
///
/// Allows to create new settings
- ///
+ ///
/// Available types : TOGGLE, SLIDER, LIST, BUTTON
- ///
+ ///
///
/// Examples :
///
@@ -38,7 +38,7 @@ private void MakeSettings()
AddSetting("Nitrox_StreamerSettings", new Setting("Nitrox_HideIp", NitroxPrefs.HideIp, hide =>
{
NitroxPrefs.HideIp.Value = hide;
- MainMenuMultiplayerPanel.Main.RefreshServerEntries();
+ MainMenuServerListPanel.Main.RefreshServerEntries();
}));
AddSetting("Nitrox_ResyncSettings", new Setting("Nitrox_ResyncBuildings", () =>
diff --git a/NitroxClient/MonoBehaviours/Discord/DiscordClient.cs b/NitroxClient/MonoBehaviours/Discord/DiscordClient.cs
index 98aa019308..c069b98dce 100644
--- a/NitroxClient/MonoBehaviours/Discord/DiscordClient.cs
+++ b/NitroxClient/MonoBehaviours/Discord/DiscordClient.cs
@@ -2,7 +2,7 @@
using System.Linq;
using DiscordGameSDKWrapper;
using NitroxClient.Communication.Abstract;
-using NitroxClient.MonoBehaviours.Gui.MainMenu;
+using NitroxClient.MonoBehaviours.Gui.MainMenu.ServersList;
using NitroxModel;
using NitroxModel.Core;
using NitroxModel.Packets;
@@ -99,7 +99,7 @@ private void ActivityJoin(string secret)
{
Log.Info("[Discord] Joining Server");
- if (SceneManager.GetActiveScene().name != "StartScreen" || !MainMenuMultiplayerPanel.Main)
+ if (SceneManager.GetActiveScene().name != "StartScreen" || !MainMenuServerListPanel.Main)
{
Log.InGame(Language.main.Get("Nitrox_DiscordMultiplayerMenu"));
Log.Warn("[Discord] Can't join a server outside of the main-menu.");
@@ -109,7 +109,8 @@ private void ActivityJoin(string secret)
string[] splitSecret = secret.Split(':');
string ip = string.Join(":", splitSecret.Take(splitSecret.Length - 1));
string port = splitSecret.Last();
- MainMenuMultiplayerPanel.OpenJoinServerMenuAsync(ip, port).ContinueWithHandleError();
+ int portInt = int.Parse(port);
+ MainMenuServerButton.OpenJoinServerMenuAsync(ip, portInt).ContinueWithHandleError();
}
private void ActivityJoinRequest(ref User user)
diff --git a/NitroxClient/MonoBehaviours/Gui/MainMenu/LoadingScreenVersionText.cs b/NitroxClient/MonoBehaviours/Gui/InGame/LoadingScreenVersionText.cs
similarity index 100%
rename from NitroxClient/MonoBehaviours/Gui/MainMenu/LoadingScreenVersionText.cs
rename to NitroxClient/MonoBehaviours/Gui/InGame/LoadingScreenVersionText.cs
diff --git a/NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServer.cs b/NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServer.cs
deleted file mode 100644
index 38c9145aa0..0000000000
--- a/NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServer.cs
+++ /dev/null
@@ -1,380 +0,0 @@
-using System;
-using System.Collections;
-using System.Diagnostics;
-using System.Text.RegularExpressions;
-using System.Threading.Tasks;
-using NitroxClient.Communication.Abstract;
-using NitroxClient.Communication.Exceptions;
-using NitroxClient.Communication.MultiplayerSession;
-using NitroxClient.GameLogic.PlayerLogic.PlayerPreferences;
-using NitroxClient.Unity.Helper;
-using NitroxModel.Core;
-using NitroxModel.DataStructures.Util;
-using NitroxModel.MultiplayerSession;
-using NitroxModel_Subnautica.DataStructures;
-using UnityEngine;
-
-namespace NitroxClient.MonoBehaviours.Gui.MainMenu;
-
-public class JoinServer : MonoBehaviour
-{
- private readonly JoinServerJoinWindow joinWindow = new();
- private PlayerPreferenceManager preferencesManager;
- private PlayerPreference activePlayerPreference;
- private IMultiplayerSession multiplayerSession;
-
- private Rect serverPasswordWindowRect = new(Screen.width / 2 - 250, 200, 500, 200);
-
- private GameObject multiplayerClient;
-
- private string serverIp;
- private int serverPort;
-
- private bool shouldFocus;
- private bool showingPasswordWindow;
- private bool passwordEntered;
- private string serverPassword = string.Empty;
-
- private GameObject joinServerMenu;
- public string MenuName => joinServerMenu.AliveOrNull()?.name ?? throw new Exception("Menu not yet initialized");
-
- public bool InstantLaunch;
-
- public void Setup(GameObject saveGameMenu)
- {
- JoinServerServerList.InitializeServerList(saveGameMenu, out joinServerMenu, out RectTransform joinServerBackground);
- UWE.CoroutineUtils.StartCoroutineSmart(joinWindow.Initialize(joinServerBackground, OnJoinClick, () => OnCancelClick(true)));
-
- DontDestroyOnLoad(gameObject);
- Hide();
- }
-
- public async Task ShowAsync(string ip, int port, bool instantLaunch = false)
- {
- NitroxServiceLocator.BeginNewLifetimeScope();
- multiplayerSession = NitroxServiceLocator.LocateService();
- preferencesManager = NitroxServiceLocator.LocateService();
-
- await joinWindow.IsReady();
-
- gameObject.SetActive(true);
- serverIp = ip;
- serverPort = port;
- InstantLaunch = instantLaunch;
-
- //Set Server IP in info label
- joinWindow.SetIP(serverIp);
-
- //Initialize elements from preferences
- activePlayerPreference = preferencesManager.GetPreference(serverIp);
- joinWindow.SubscribeColorChanged();
-
- // HSV => Hue Saturation Value, HSB => Hue Saturation Brightness
- Color.RGBToHSV(activePlayerPreference.PreferredColor(), out float hue, out _, out float brightness);
- joinWindow.SetHSB(new Vector3(hue, 1f, brightness));
-
- joinWindow.PlayerName = activePlayerPreference.PlayerName;
-
- await StartMultiplayerClientAsync();
- }
-
- private void Hide()
- {
- joinWindow.UnsubscribeColorChanged();
- gameObject.SetActive(false);
- }
-
- private void Update()
- {
- if (multiplayerSession.CurrentState.CurrentStage != MultiplayerSessionConnectionStage.AWAITING_RESERVATION_CREDENTIALS ||
- gameObject.GetComponent())
- {
- return;
- }
-
- if (UnityEngine.Input.GetKeyDown(KeyCode.Return))
- {
- OnJoinClick();
- }
- else if (UnityEngine.Input.GetKeyDown(KeyCode.Escape))
- {
- OnCancelClick(true);
- }
- }
-
- private void OnGUI()
- {
- if (showingPasswordWindow)
- {
- serverPasswordWindowRect = GUILayout.Window(
- GUIUtility.GetControlID(FocusType.Keyboard),
- serverPasswordWindowRect,
- DoServerPasswordWindow,
- Language.main.Get("Nitrox_JoinServerPasswordHeader")
- );
- }
- }
-
- private void OnDestroy()
- {
- joinWindow.UnsubscribeColorChanged();
- }
-
- private void FocusPlayerNameTextBox()
- {
- joinWindow.ActivateInputField();
- }
-
- private async System.Threading.Tasks.Task StartMultiplayerClientAsync()
- {
- if (!multiplayerClient)
- {
- multiplayerClient = new GameObject("Multiplayer Client");
- multiplayerClient.AddComponent();
- multiplayerSession.ConnectionStateChanged += SessionConnectionStateChangedHandler;
- }
-
- try
- {
- await multiplayerSession.ConnectAsync(serverIp, serverPort);
- }
- catch (ClientConnectionFailedException ex)
- {
- Log.ErrorSensitive("Unable to contact the remote server at: {ip}:{port}", serverIp, serverPort);
- Log.InGame($"{Language.main.Get("Nitrox_UnableToConnect")} {serverIp}:{serverPort}");
-
- if (serverIp.Equals("127.0.0.1"))
- {
- if (Process.GetProcessesByName("NitroxServer-Subnautica").Length == 0)
- {
- Log.Error("No server process was found while address was 127.0.0.1");
- Log.InGame(Language.main.Get("Nitrox_StartServer"));
- }
- else
- {
- Log.Error(ex);
- Log.InGame(Language.main.Get("Nitrox_FirewallInterfering"));
- }
- }
-
- OnCancelClick(false);
- }
- }
-
- private void OnCancelClick(bool returnToMpMenu)
- {
- StopMultiplayerClient();
- if (returnToMpMenu)
- {
- MainMenuRightSide.main.OpenGroup("Multiplayer");
- }
-
- Hide();
- }
-
- private void OnJoinClick()
- {
- string playerName = joinWindow.PlayerName;
-
- //https://regex101.com/r/eTWiEs/2/
- if (!Regex.IsMatch(playerName, @"^[a-zA-Z0-9._-]{3,25}$"))
- {
- NotifyUser(Language.main.Get("Nitrox_InvalidUserName"));
- return;
- }
-
- preferencesManager.SetPreference(serverIp, new PlayerPreference(playerName, joinWindow.GetCurrentColor()));
-
- AuthenticationContext authenticationContext = new(playerName, passwordEntered ? Optional.Of(serverPassword) : Optional.Empty);
-
- multiplayerSession.RequestSessionReservation(new PlayerSettings(joinWindow.GetCurrentColor().ToDto()), authenticationContext);
- }
-
- private void SessionConnectionStateChangedHandler(IMultiplayerSessionConnectionState state)
- {
- switch (state.CurrentStage)
- {
- case MultiplayerSessionConnectionStage.ESTABLISHING_SERVER_POLICY:
- Log.Info("Requesting session policy info");
- Log.InGame(Language.main.Get("Nitrox_RequestingSessionPolicy"));
- break;
-
- case MultiplayerSessionConnectionStage.AWAITING_RESERVATION_CREDENTIALS:
- if (multiplayerSession.SessionPolicy.RequiresServerPassword)
- {
- Log.Info("Waiting for server password input");
- Log.InGame(Language.main.Get("Nitrox_WaitingPassword"));
- showingPasswordWindow = true;
- shouldFocus = true;
- }
-
- Log.Info("Waiting for user input");
- Log.InGame(Language.main.Get("Nitrox_WaitingUserInput"));
- MainMenuRightSide.main.OpenGroup("Join Server");
- FocusPlayerNameTextBox();
- if (InstantLaunch)
- {
- OnJoinClick();
- }
- break;
-
- case MultiplayerSessionConnectionStage.SESSION_RESERVED:
- Log.Info("Launching game");
- Log.InGame(Language.main.Get("Nitrox_LaunchGame"));
- multiplayerSession.ConnectionStateChanged -= SessionConnectionStateChangedHandler;
- preferencesManager.Save();
-
-#pragma warning disable CS0618 // God Damn it UWE...
- Multiplayer.SubnauticaLoadingStarted();
- IEnumerator startNewGame = uGUI_MainMenu.main.StartNewGame(GameMode.Survival);
-#pragma warning restore CS0618 // God damn it UWE...
- StartCoroutine(startNewGame);
- LoadingScreenVersionText.Initialize();
-
- break;
-
- case MultiplayerSessionConnectionStage.SESSION_RESERVATION_REJECTED:
- Log.Info("Reservation rejected");
- Log.InGame(Language.main.Get("Nitrox_RejectedSessionPolicy"));
-
- MultiplayerSessionReservationState reservationState = multiplayerSession.Reservation.ReservationState;
-
- string reservationRejectionNotification = reservationState.Describe();
-
- NotifyUser(
- reservationRejectionNotification,
- () =>
- {
- multiplayerSession.Disconnect();
- multiplayerSession.ConnectAsync(serverIp, serverPort);
- });
- break;
-
- case MultiplayerSessionConnectionStage.DISCONNECTED:
- Log.Info(Language.main.Get("Nitrox_DisconnectedSession"));
- break;
- }
- }
-
- private void NotifyUser(string notificationMessage, Action continuationAction = null)
- {
- if (gameObject.GetComponent())
- {
- return;
- }
-
- MainMenuNotification notificationDialog = gameObject.AddComponent();
- notificationDialog.ShowNotification(notificationMessage, () =>
- {
- continuationAction?.Invoke();
- Destroy(gameObject.GetComponent(), 0.0001f);
- });
- }
-
- public void StopMultiplayerClient()
- {
- if (!multiplayerClient)
- {
- return;
- }
-
- Multiplayer.Main.StopCurrentSession();
- Destroy(multiplayerClient);
- multiplayerClient = null;
- if (multiplayerSession != null)
- {
- multiplayerSession.ConnectionStateChanged -= SessionConnectionStateChangedHandler;
- }
- }
-
- private void DoServerPasswordWindow(int windowId)
- {
- GUISkin GetGUISkin() => GUISkinUtils.RegisterDerivedOnce("menus.serverPassword",
- s =>
- {
- s.textField.fontSize = 14;
- s.textField.richText = false;
- s.textField.alignment = TextAnchor.MiddleLeft;
- s.textField.wordWrap = true;
- s.textField.stretchHeight = true;
- s.textField.padding = new RectOffset(10, 10, 5, 5);
-
- s.label.fontSize = 14;
- s.label.alignment = TextAnchor.MiddleRight;
- s.label.stretchHeight = true;
- s.label.fixedWidth = 80; //change this when adding new labels that need more space.
-
- s.button.fontSize = 14;
- s.button.stretchHeight = true;
- });
-
- Event e = Event.current;
- if (e.isKey)
- {
- switch (e.keyCode)
- {
- case KeyCode.Return:
- OnSubmitPasswordButtonClicked();
- break;
- case KeyCode.Escape:
- OnCancelButtonClicked();
- break;
- }
- }
-
- GUISkinUtils.RenderWithSkin(GetGUISkin(),
- () =>
- {
- using (new GUILayout.VerticalScope("Box"))
- {
- using (new GUILayout.HorizontalScope())
- {
- GUILayout.Label(Language.main.Get("Nitrox_JoinServerPassword"));
- GUI.SetNextControlName("serverPasswordField");
- serverPassword = GUILayout.TextField(serverPassword);
- }
-
- if (GUILayout.Button(Language.main.Get("Nitrox_SubmitPassword")))
- {
- HidePasswordWindow();
- OnSubmitPasswordButtonClicked();
- }
-
- if (GUILayout.Button(Language.main.Get("Nitrox_Cancel")))
- {
- HidePasswordWindow();
- OnCancelClick(true);
- }
- }
- });
-
- if (shouldFocus)
- {
- GUI.FocusControl("serverPasswordField");
- shouldFocus = false;
- }
- }
-
- private void OnSubmitPasswordButtonClicked()
- {
- SubmitPassword();
- HidePasswordWindow();
- }
-
- private void SubmitPassword()
- {
- passwordEntered = true;
- }
-
- private void OnCancelButtonClicked()
- {
- multiplayerSession.Disconnect();
- HidePasswordWindow();
- }
-
- private void HidePasswordWindow()
- {
- showingPasswordWindow = false;
- shouldFocus = false;
- }
-}
diff --git a/NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServerJoinWindow.cs b/NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServerJoinWindow.cs
deleted file mode 100644
index df08034663..0000000000
--- a/NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServerJoinWindow.cs
+++ /dev/null
@@ -1,291 +0,0 @@
-using System;
-using System.Collections;
-using System.Threading.Tasks;
-using NitroxClient.GameLogic.PlayerLogic.PlayerModel.Abstract;
-using NitroxClient.GameLogic.PlayerLogic.PlayerModel.ColorSwap;
-using NitroxClient.GameLogic.PlayerLogic.PlayerModel.ColorSwap.Strategy;
-using NitroxClient.GameLogic.Settings;
-using NitroxClient.Unity.Helper;
-using TMPro;
-using UnityEngine;
-using UnityEngine.Events;
-using UnityEngine.ResourceManagement.AsyncOperations;
-using UnityEngine.UI;
-
-namespace NitroxClient.MonoBehaviours.Gui.MainMenu;
-
-public class JoinServerJoinWindow
-{
- private readonly TaskCompletionSource isInitialised = new(false);
-
- private GameObject playerSettingsPanel;
- private uGUI_ColorPicker colorPicker;
- private TextMeshProUGUI lowerDetailText;
- private uGUI_InputField playerNameInputField;
-
- private bool isColorPickerSubscribed;
-
- public string PlayerName
- {
- get => playerNameInputField.text;
- set => playerNameInputField.text = value;
- }
-
- public void ActivateInputField() => playerNameInputField.ActivateInputField();
-
- public void SetIP(string serverIp) => lowerDetailText.text = $"{Language.main.Get("Nitrox_JoinServerIpAddress")}{Environment.NewLine}{(NitroxPrefs.HideIp.Value ? "****" : serverIp)}";
-
- public void SetHSB(Vector3 hsb) => colorPicker.SetHSB(hsb);
-
- public Color GetCurrentColor() => colorPicker.currentColor;
-
- public void SubscribeColorChanged()
- {
- if (isColorPickerSubscribed)
- {
- return;
- }
-
- colorPicker.onColorChange.AddListener(OnColorChange);
-
- isColorPickerSubscribed = true;
- }
-
- public void UnsubscribeColorChanged()
- {
- if (!playerSettingsPanel || !isColorPickerSubscribed)
- {
- return;
- }
-
- colorPicker.onColorChange.RemoveListener(OnColorChange);
- isColorPickerSubscribed = false;
- }
-
- private void OnColorChange(ColorChangeEventData eventData)
- {
- Color selectedColor = eventData.color;
-
- GameObject selectedColorGameObject = playerSettingsPanel.RequireGameObject("BaseTab/SelectedColor");
-
- Image baseTabSelectedColorImage = selectedColorGameObject.GetComponent();
- baseTabSelectedColorImage.color = selectedColor;
- }
-
- //This configures and re-positions the elements on the default "ColorGreyscale" menu to suite our purposes now.
- public IEnumerator Initialize(RectTransform joinServerBackground, UnityAction joinButtonCall, UnityAction cancelButtonCall)
- {
- AsyncOperationHandle request = AddressablesUtility.LoadAsync("Assets/Prefabs/Base/GeneratorPieces/BaseMoonpoolUpgradeConsole.prefab");
- yield return request;
- GameObject colorPickerPanelPrototype = request.Result.RequireGameObject("EditScreen/Active");
-
- InstantiateColorPickerPanelPrototype(colorPickerPanelPrototype, out playerSettingsPanel);
- InitializePlayerSettingsPanelElement(playerSettingsPanel, joinServerBackground);
- InitializeBaseTabElement(playerSettingsPanel, joinServerBackground);
- InitializeLowerDetailElement(playerSettingsPanel, out lowerDetailText);
- InitializePlayerNameInputElement(playerSettingsPanel, out playerNameInputField);
- InitializeColorPickerComponent(playerSettingsPanel, out colorPicker);
- InitializeColorPickerElement(playerSettingsPanel);
- InitializeButtonElements(playerSettingsPanel, joinServerBackground, joinButtonCall, cancelButtonCall);
-
- isInitialised.SetResult(true);
- }
-
- public Task IsReady() => isInitialised.Task;
-
- //Join and Cancel buttons
- private static void InitializeButtonElements(GameObject playerSettingsPanel, RectTransform joinServerBackground, UnityAction joinButtonCall, UnityAction cancelButtonCall)
- {
- GameObject cancelButtonGameObject = playerSettingsPanel.RequireGameObject("Button");
- GameObject joinButtonGameObject = UnityEngine.Object.Instantiate(cancelButtonGameObject, playerSettingsPanel.transform, false);
-
- //Click events
- Button joinButton = joinButtonGameObject.GetComponent