Skip to content

Commit

Permalink
Renaming few MainMenu files to reflect behavior/SN naming conventions
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannify committed Jun 24, 2023
1 parent a828b8f commit a0c0f46
Show file tree
Hide file tree
Showing 11 changed files with 107 additions and 110 deletions.
2 changes: 1 addition & 1 deletion NitroxClient/GameLogic/Settings/NitroxSettingsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private void MakeSettings()
AddSetting("Nitrox_StreamerSettings", new Setting("Nitrox_HideIp", NitroxPrefs.HideIp, hide =>
{
NitroxPrefs.HideIp.Value = hide;
MainMenuMultiplayerPanel.Main.RefreshServerEntries();
MainMenuServerListPanel.Main.RefreshServerEntries();
}));
}

Expand Down
2 changes: 1 addition & 1 deletion NitroxClient/MonoBehaviours/Discord/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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.");
Expand Down
8 changes: 4 additions & 4 deletions NitroxClient/MonoBehaviours/Gui/MainMenu/JoinServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private void Hide()
private void Update()
{
if (multiplayerSession.CurrentState.CurrentStage != MultiplayerSessionConnectionStage.AWAITING_RESERVATION_CREDENTIALS ||
gameObject.GetComponent<MainMenuNotification>())
gameObject.GetComponent<JoinServerNotification>())
{
return;
}
Expand Down Expand Up @@ -243,16 +243,16 @@ private void SessionConnectionStateChangedHandler(IMultiplayerSessionConnectionS

private void NotifyUser(string notificationMessage, Action continuationAction = null)
{
if (gameObject.GetComponent<MainMenuNotification>())
if (gameObject.GetComponent<JoinServerNotification>())
{
return;
}

MainMenuNotification notificationDialog = gameObject.AddComponent<MainMenuNotification>();
JoinServerNotification notificationDialog = gameObject.AddComponent<JoinServerNotification>();
notificationDialog.ShowNotification(notificationMessage, () =>
{
continuationAction?.Invoke();
Destroy(gameObject.GetComponent<MainMenuNotification>(), 0.0001f);
Destroy(gameObject.GetComponent<JoinServerNotification>(), 0.0001f);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace NitroxClient.MonoBehaviours.Gui.MainMenu
{
//I'd like to see about skinning this behavior with the notification window that appears at the bottom of the screen during certain story events in the game.
public class MainMenuNotification : MonoBehaviour
public class JoinServerNotification : MonoBehaviour
{
private bool awaitingAcknowledgement;
private Action continuationAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private void SaveServer()
}

int serverPort = int.Parse(serverPortText);
MainMenuMultiplayerPanel.Main.CreateServerButton(serverNameText, serverHostText, serverPort);
MainMenuServerListPanel.Main.CreateServerButton(serverNameText, serverHostText, serverPort);
ServerList.Instance.Add(new ServerList.Entry(serverNameText, serverHostText, serverPort));
ServerList.Instance.Save();
OnBack();
Expand Down Expand Up @@ -163,11 +163,11 @@ public void SelectItem(object item)
}
else
{
selectedItem.transform.GetChild(0).GetComponent<Image>().sprite = MainMenuMultiplayerPanel.SelectedSprite;
selectedItem.transform.GetChild(0).GetComponent<Image>().sprite = MainMenuServerListPanel.SelectedSprite;
}

selectedItem.GetComponentsInChildren<TextMeshProUGUI>().ForEach(txt => txt.color = Color.black);
RuntimeManager.PlayOneShot(MainMenuMultiplayerPanel.HoverSound.path);
RuntimeManager.PlayOneShot(MainMenuServerListPanel.HoverSound.path);
}

public void DeselectItem()
Expand All @@ -184,7 +184,7 @@ public void DeselectItem()
}
else
{
selectedItem.transform.GetChild(0).GetComponent<Image>().sprite = MainMenuMultiplayerPanel.NormalSprite;
selectedItem.transform.GetChild(0).GetComponent<Image>().sprite = MainMenuServerListPanel.NormalSprite;
}

selectedItem.GetComponentsInChildren<TextMeshProUGUI>().ForEach(txt => txt.color = Color.white);
Expand Down
85 changes: 0 additions & 85 deletions NitroxClient/MonoBehaviours/Gui/MainMenu/MainMenuMods.cs

This file was deleted.

18 changes: 9 additions & 9 deletions NitroxClient/MonoBehaviours/Gui/MainMenu/MainMenuServerButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,33 +55,33 @@ public void RequestDelete()
ServerList.Instance.RemoveAt(transform.GetSiblingIndex() - 1);
ServerList.Instance.Save();

int scrollIndex = MainMenuMultiplayerPanel.Main.GetSelectedIndex();
if (GameInput.IsPrimaryDeviceGamepad() && !MainMenuMultiplayerPanel.Main.SelectItemInYDirection(scrollIndex, 1))
int scrollIndex = MainMenuServerListPanel.Main.GetSelectedIndex();
if (GameInput.IsPrimaryDeviceGamepad() && !MainMenuServerListPanel.Main.SelectItemInYDirection(scrollIndex, 1))
{
MainMenuMultiplayerPanel.Main.SelectItemInYDirection(scrollIndex, -1);
MainMenuServerListPanel.Main.SelectItemInYDirection(scrollIndex, -1);
}

Destroy(gameObject);
}

public async void OnJoinButtonClicked()
{
if (MainMenuMultiplayerPanel.Main.IsJoining)
if (MainMenuServerListPanel.Main.IsJoining)
{
// Do not attempt to join multiple servers.
return;
}

MainMenuMultiplayerPanel.Main.IsJoining = true;
MainMenuServerListPanel.Main.IsJoining = true;

await OpenJoinServerMenuAsync(joinIp, joinPort).ContinueWith(_ => { MainMenuMultiplayerPanel.Main.IsJoining = false; });
await OpenJoinServerMenuAsync(joinIp, joinPort).ContinueWith(_ => { MainMenuServerListPanel.Main.IsJoining = false; });
}

public static async System.Threading.Tasks.Task OpenJoinServerMenuAsync(string serverIp, int serverPort)
{
if (!MainMenuMultiplayerPanel.Main)
if (!MainMenuServerListPanel.Main)
{
Log.Error("MainMenuMultiplayerPanel is not instantiated although OpenJoinServerMenuAsync is called.");
Log.Error("MainMenuServerListPanel is not instantiated although OpenJoinServerMenuAsync is called.");
return;
}

Expand All @@ -92,7 +92,7 @@ public static async System.Threading.Tasks.Task OpenJoinServerMenuAsync(string s
return;
}

await MainMenuMultiplayerPanel.Main.JoinServer.ShowAsync(endpoint.Address.ToString(), endpoint.Port);
await MainMenuServerListPanel.Main.JoinServer.ShowAsync(endpoint.Address.ToString(), endpoint.Port);
}

private static IPEndPoint ResolveIPEndPoint(string serverIp, int serverPort)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

namespace NitroxClient.MonoBehaviours.Gui.MainMenu;

public class MainMenuMultiplayerPanel : MonoBehaviour, uGUI_INavigableIconGrid, uGUI_IButtonReceiver
public class MainMenuServerListPanel : MonoBehaviour, uGUI_INavigableIconGrid, uGUI_IButtonReceiver
{
public static MainMenuMultiplayerPanel Main;
public static MainMenuServerListPanel Main;
public static Sprite NormalSprite;
public static Sprite SelectedSprite;
public static FMODAsset HoverSound;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using NitroxClient.MonoBehaviours.Discord;
using NitroxClient.Unity.Helper;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

namespace NitroxClient.MonoBehaviours.Gui.MainMenu;

public class NitroxMainMenuModifications : MonoBehaviour
{
private MainMenuRightSide rightSide;

private void OnEnable()
{
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
}

private void OnDisable()
{
SceneManager.sceneLoaded -= SceneManager_sceneLoaded;
}

private void SceneManager_sceneLoaded(Scene scene, LoadSceneMode loadMode)
{
if (scene.name == "XMenu")
{
rightSide = MainMenuRightSide.main;
MultiplayerMenuMods();
DiscordClient.InitializeRPMenu();
}
}

private void MultiplayerMenuMods()
{
GameObject startButton = GameObjectHelper.RequireGameObject("Menu canvas/Panel/MainMenu/PrimaryOptions/MenuButtons/ButtonPlay");
GameObject showLoadedMultiplayer = Instantiate(startButton, startButton.transform.parent);
showLoadedMultiplayer.name = "ButtonMultiplayer";
showLoadedMultiplayer.transform.SetSiblingIndex(3);

TextMeshProUGUI buttonText = showLoadedMultiplayer.RequireGameObject("Circle/Bar/Text").GetComponent<TextMeshProUGUI>();
buttonText.text = Language.main.Get("Nitrox_Multiplayer");
buttonText.GetComponent<TranslationLiveUpdate>().translationKey = "Nitrox_Multiplayer";

Button showLoadedMultiplayerButton = showLoadedMultiplayer.GetComponent<Button>();
showLoadedMultiplayerButton.onClick.RemoveAllListeners();
showLoadedMultiplayerButton.onClick.AddListener(ShowMultiplayerServerList);

GameObject savedGamesRef = rightSide.gameObject.RequireGameObject("SavedGames");

GameObject CloneMainMenuLoadPanel(string panelName, string translationKey)
{
GameObject menuPanel = Instantiate(savedGamesRef, rightSide.transform);
menuPanel.name = panelName;
Transform header = menuPanel.RequireTransform("Header");
header.GetComponent<TextMeshProUGUI>().text = Language.main.Get(translationKey);
header.GetComponent<TranslationLiveUpdate>().translationKey = translationKey;
Destroy(menuPanel.RequireGameObject("Scroll View/Viewport/SavedGameAreaContent/NewGame"));
Destroy(menuPanel.GetComponent<MainMenuLoadPanel>());
Destroy(menuPanel.GetComponentInChildren<MainMenuLoadMenu>());

rightSide.groups.Add(menuPanel.GetComponent<MainMenuGroup>());
return menuPanel;
}

GameObject serverList = CloneMainMenuLoadPanel("MultiplayerServerList", "Nitrox_Multiplayer");
serverList.AddComponent<MainMenuServerListPanel>().Setup(savedGamesRef);

GameObject serverCreate = CloneMainMenuLoadPanel("MultiplayerCreateServer", "Nitrox_AddServer");
serverCreate.AddComponent<MainMenuCreateServerPanel>().Setup(savedGamesRef);

#if RELEASE
// Remove singleplayer button because SP is broken when Nitrox is injected. TODO: Allow SP to work and co-exist with Nitrox MP in the future
startButton.SetActive(false);
#endif
}

private void ShowMultiplayerServerList()
{
rightSide.OpenGroup("MultiplayerServerList");
}
}
2 changes: 1 addition & 1 deletion NitroxClient/MonoBehaviours/NitroxBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ private void Awake()
DontDestroyOnLoad(gameObject);
Instance = this;
gameObject.AddComponent<SceneCleanerPreserve>();
gameObject.AddComponent<MainMenuMods>();
gameObject.AddComponent<NitroxMainMenuModifications>();
gameObject.AddComponent<DiscordClient>();

#if DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public static void Prefix(string target)
{
// Don't stop the client if the client is trying to connect (in the case: target = "Join Server")
// We can detect that the Join Server tab is still available because the gameobject is activated only when the tab is opened
if (MainMenuMultiplayerPanel.Main.JoinServer.gameObject.activeSelf && !target.Equals(MainMenuMultiplayerPanel.Main.JoinServer.MenuName))
if (MainMenuServerListPanel.Main.JoinServer.gameObject.activeSelf && !target.Equals(MainMenuServerListPanel.Main.JoinServer.MenuName))
{
MainMenuMultiplayerPanel.Main.JoinServer.StopMultiplayerClient();
MainMenuServerListPanel.Main.JoinServer.StopMultiplayerClient();
}
}

Expand Down

0 comments on commit a0c0f46

Please sign in to comment.